1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.263 2015/05/11 18:11:42 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, and textbook). In each case the radio buttons
107: 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:
177: my $registered_cleanup;
178: my $modified_urls;
179:
180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
188: my $context = 'domain';
189: my $dom = $env{'request.role.domain'};
190: my $domdesc = &Apache::lonnet::domain($dom,'description');
191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
205: ['phase','actions']);
206: my $phase = 'pickactions';
207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
211: my %domconfig =
212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
216: 'serverstatuses','requestcourses','helpsettings',
217: 'coursedefaults','usersessions','loadbalancing',
218: 'requestauthor','selfenrollment','inststatus'],$dom);
219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
220: 'autoupdate','autocreate','directorysrch','contacts',
221: 'usercreation','selfcreation','usermodification','scantron',
222: 'requestcourses','requestauthor','coursecategories',
223: 'serverstatuses','helpsettings',
224: 'coursedefaults','selfenrollment','usersessions');
225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
230: push(@prefs_order,'loadbalancing');
231: }
232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
235: help => 'Domain_Configuration_Color_Schemes',
236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
246: },
247: 'login' =>
248: { text => 'Log-in page options',
249: help => 'Domain_Configuration_Login_Page',
250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
253: col2 => 'Value'},
254: {col1 => 'Custom HTML in document head',
255: col2 => 'Value'}],
256: print => \&print_login,
257: modify => \&modify_login,
258: },
259: 'defaults' =>
260: { text => 'Default authentication/language/timezone/portal/types',
261: help => 'Domain_Configuration_LangTZAuth',
262: header => [{col1 => 'Setting',
263: col2 => 'Value'},
264: {col1 => 'Institutional user types',
265: col2 => 'Assignable to e-mail usernames'}],
266: print => \&print_defaults,
267: modify => \&modify_defaults,
268: },
269: 'quotas' =>
270: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
271: help => 'Domain_Configuration_Quotas',
272: header => [{col1 => 'User affiliation',
273: col2 => 'Available tools',
274: col3 => 'Quotas, MB; (Authoring requires role)',}],
275: print => \&print_quotas,
276: modify => \&modify_quotas,
277: },
278: 'autoenroll' =>
279: { text => 'Auto-enrollment settings',
280: help => 'Domain_Configuration_Auto_Enrollment',
281: header => [{col1 => 'Configuration setting',
282: col2 => 'Value(s)'}],
283: print => \&print_autoenroll,
284: modify => \&modify_autoenroll,
285: },
286: 'autoupdate' =>
287: { text => 'Auto-update settings',
288: help => 'Domain_Configuration_Auto_Updates',
289: header => [{col1 => 'Setting',
290: col2 => 'Value',},
291: {col1 => 'Setting',
292: col2 => 'Affiliation'},
293: {col1 => 'User population',
294: col2 => 'Updatable user data'}],
295: print => \&print_autoupdate,
296: modify => \&modify_autoupdate,
297: },
298: 'autocreate' =>
299: { text => 'Auto-course creation settings',
300: help => 'Domain_Configuration_Auto_Creation',
301: header => [{col1 => 'Configuration Setting',
302: col2 => 'Value',}],
303: print => \&print_autocreate,
304: modify => \&modify_autocreate,
305: },
306: 'directorysrch' =>
307: { text => 'Institutional directory searches',
308: help => 'Domain_Configuration_InstDirectory_Search',
309: header => [{col1 => 'Setting',
310: col2 => 'Value',}],
311: print => \&print_directorysrch,
312: modify => \&modify_directorysrch,
313: },
314: 'contacts' =>
315: { text => 'Contact Information',
316: help => 'Domain_Configuration_Contact_Info',
317: header => [{col1 => 'Setting',
318: col2 => 'Value',}],
319: print => \&print_contacts,
320: modify => \&modify_contacts,
321: },
322: 'usercreation' =>
323: { text => 'User creation',
324: help => 'Domain_Configuration_User_Creation',
325: header => [{col1 => 'Format rule type',
326: col2 => 'Format rules in force'},
327: {col1 => 'User account creation',
328: col2 => 'Usernames which may be created',},
329: {col1 => 'Context',
330: col2 => 'Assignable authentication types'}],
331: print => \&print_usercreation,
332: modify => \&modify_usercreation,
333: },
334: 'selfcreation' =>
335: { text => 'Users self-creating accounts',
336: help => 'Domain_Configuration_Self_Creation',
337: header => [{col1 => 'Self-creation with institutional username',
338: col2 => 'Enabled?'},
339: {col1 => 'Institutional user type (login/SSO self-creation)',
340: col2 => 'Information user can enter'},
341: {col1 => 'Self-creation with e-mail as username',
342: col2 => 'Settings'}],
343: print => \&print_selfcreation,
344: modify => \&modify_selfcreation,
345: },
346: 'usermodification' =>
347: { text => 'User modification',
348: help => 'Domain_Configuration_User_Modification',
349: header => [{col1 => 'Target user has role',
350: col2 => 'User information updatable in author context'},
351: {col1 => 'Target user has role',
352: col2 => 'User information updatable in course context'}],
353: print => \&print_usermodification,
354: modify => \&modify_usermodification,
355: },
356: 'scantron' =>
357: { text => 'Bubblesheet format file',
358: help => 'Domain_Configuration_Scantron_Format',
359: header => [ {col1 => 'Item',
360: col2 => '',
361: }],
362: print => \&print_scantron,
363: modify => \&modify_scantron,
364: },
365: 'requestcourses' =>
366: {text => 'Request creation of courses',
367: help => 'Domain_Configuration_Request_Courses',
368: header => [{col1 => 'User affiliation',
369: col2 => 'Availability/Processing of requests',},
370: {col1 => 'Setting',
371: col2 => 'Value'},
372: {col1 => 'Available textbooks',
373: col2 => ''},
374: {col1 => 'Available templates',
375: col2 => ''},
376: {col1 => 'Validation (not official courses)',
377: col2 => 'Value'},],
378: print => \&print_quotas,
379: modify => \&modify_quotas,
380: },
381: 'requestauthor' =>
382: {text => 'Request Authoring Space',
383: help => 'Domain_Configuration_Request_Author',
384: header => [{col1 => 'User affiliation',
385: col2 => 'Availability/Processing of requests',},
386: {col1 => 'Setting',
387: col2 => 'Value'}],
388: print => \&print_quotas,
389: modify => \&modify_quotas,
390: },
391: 'coursecategories' =>
392: { text => 'Cataloging of courses/communities',
393: help => 'Domain_Configuration_Cataloging_Courses',
394: header => [{col1 => 'Catalog type/availability',
395: col2 => '',},
396: {col1 => 'Category settings for standard catalog',
397: col2 => '',},
398: {col1 => 'Categories',
399: col2 => '',
400: }],
401: print => \&print_coursecategories,
402: modify => \&modify_coursecategories,
403: },
404: 'serverstatuses' =>
405: {text => 'Access to server status pages',
406: help => 'Domain_Configuration_Server_Status',
407: header => [{col1 => 'Status Page',
408: col2 => 'Other named users',
409: col3 => 'Specific IPs',
410: }],
411: print => \&print_serverstatuses,
412: modify => \&modify_serverstatuses,
413: },
414: 'helpsettings' =>
415: {text => 'Help page settings',
416: help => 'Domain_Configuration_Help_Settings',
417: header => [{col1 => 'Help Settings (logged-in users)',
418: col2 => 'Value'}],
419: print => \&print_helpsettings,
420: modify => \&modify_helpsettings,
421: },
422: 'coursedefaults' =>
423: {text => 'Course/Community defaults',
424: help => 'Domain_Configuration_Course_Defaults',
425: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
426: col2 => 'Value',},
427: {col1 => 'Defaults which can be overridden for each course by a DC',
428: col2 => 'Value',},],
429: print => \&print_coursedefaults,
430: modify => \&modify_coursedefaults,
431: },
432: 'selfenrollment' =>
433: {text => 'Self-enrollment in Course/Community',
434: help => 'Domain_Configuration_Selfenrollment',
435: header => [{col1 => 'Configuration Rights',
436: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
437: {col1 => 'Defaults',
438: col2 => 'Value'},
439: {col1 => 'Self-enrollment validation (optional)',
440: col2 => 'Value'},],
441: print => \&print_selfenrollment,
442: modify => \&modify_selfenrollment,
443: },
444: 'privacy' =>
445: {text => 'User Privacy',
446: help => 'Domain_Configuration_User_Privacy',
447: header => [{col1 => 'Setting',
448: col2 => 'Value',}],
449: print => \&print_privacy,
450: modify => \&modify_privacy,
451: },
452: 'usersessions' =>
453: {text => 'User session hosting/offloading',
454: help => 'Domain_Configuration_User_Sessions',
455: header => [{col1 => 'Domain server',
456: col2 => 'Servers to offload sessions to when busy'},
457: {col1 => 'Hosting of users from other domains',
458: col2 => 'Rules'},
459: {col1 => "Hosting domain's own users elsewhere",
460: col2 => 'Rules'}],
461: print => \&print_usersessions,
462: modify => \&modify_usersessions,
463: },
464: 'loadbalancing' =>
465: {text => 'Dedicated Load Balancer(s)',
466: help => 'Domain_Configuration_Load_Balancing',
467: header => [{col1 => 'Balancers',
468: col2 => 'Default destinations',
469: col3 => 'User affiliation',
470: col4 => 'Overrides'},
471: ],
472: print => \&print_loadbalancing,
473: modify => \&modify_loadbalancing,
474: },
475: );
476: if (keys(%servers) > 1) {
477: $prefs{'login'} = { text => 'Log-in page options',
478: help => 'Domain_Configuration_Login_Page',
479: header => [{col1 => 'Log-in Service',
480: col2 => 'Server Setting',},
481: {col1 => 'Log-in Page Items',
482: col2 => ''},
483: {col1 => 'Log-in Help',
484: col2 => 'Value'},
485: {col1 => 'Custom HTML in document head',
486: col2 => 'Value'}],
487: print => \&print_login,
488: modify => \&modify_login,
489: };
490: }
491:
492: my @roles = ('student','coordinator','author','admin');
493: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
494: &Apache::lonhtmlcommon::add_breadcrumb
495: ({href=>"javascript:changePage(document.$phase,'pickactions')",
496: text=>"Settings to display/modify"});
497: my $confname = $dom.'-domainconfig';
498:
499: if ($phase eq 'process') {
500: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
501: \%prefs,\%domconfig,$confname,\@roles);
502: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
503: $r->rflush();
504: &devalidate_remote_domconfs($dom,$result);
505: }
506: } elsif ($phase eq 'display') {
507: my $js = &recaptcha_js().
508: &toggle_display_js();
509: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
510: my ($othertitle,$usertypes,$types) =
511: &Apache::loncommon::sorted_inst_types($dom);
512: $js .= &lonbalance_targets_js($dom,$types,\%servers,
513: $domconfig{'loadbalancing'}).
514: &new_spares_js().
515: &common_domprefs_js().
516: &Apache::loncommon::javascript_array_indexof();
517: }
518: if (grep(/^requestcourses$/,@actions)) {
519: my $javascript_validations;
520: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
521: $js .= <<END;
522: <script type="text/javascript">
523: $javascript_validations
524: </script>
525: $coursebrowserjs
526: END
527: }
528: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
529: } else {
530: # check if domconfig user exists for the domain.
531: my $servadm = $r->dir_config('lonAdmEMail');
532: my ($configuserok,$author_ok,$switchserver) =
533: &config_check($dom,$confname,$servadm);
534: unless ($configuserok eq 'ok') {
535: &Apache::lonconfigsettings::print_header($r,$phase,$context);
536: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
537: $confname).
538: '<br />'
539: );
540: if ($switchserver) {
541: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
542: '<br />'.
543: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
544: '<br />'.
545: &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).
546: '<br />'.
547: &mt('To do that now, use the following link: [_1]',$switchserver)
548: );
549: } else {
550: $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.').
551: '<br />'.
552: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
553: );
554: }
555: $r->print(&Apache::loncommon::end_page());
556: return OK;
557: }
558: if (keys(%domconfig) == 0) {
559: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
560: my @ids=&Apache::lonnet::current_machine_ids();
561: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
562: my %designhash = &Apache::loncommon::get_domainconf($dom);
563: my @loginimages = ('img','logo','domlogo','login');
564: my $custom_img_count = 0;
565: foreach my $img (@loginimages) {
566: if ($designhash{$dom.'.login.'.$img} ne '') {
567: $custom_img_count ++;
568: }
569: }
570: foreach my $role (@roles) {
571: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
572: $custom_img_count ++;
573: }
574: }
575: if ($custom_img_count > 0) {
576: &Apache::lonconfigsettings::print_header($r,$phase,$context);
577: my $switch_server = &check_switchserver($dom,$confname);
578: $r->print(
579: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
580: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
581: &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 />'.
582: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
583: if ($switch_server) {
584: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
585: }
586: $r->print(&Apache::loncommon::end_page());
587: return OK;
588: }
589: }
590: }
591: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
592: }
593: return OK;
594: }
595:
596: sub process_changes {
597: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
598: my %domconfig;
599: if (ref($values) eq 'HASH') {
600: %domconfig = %{$values};
601: }
602: my $output;
603: if ($action eq 'login') {
604: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
605: } elsif ($action eq 'rolecolors') {
606: $output = &modify_rolecolors($r,$dom,$confname,$roles,
607: $lastactref,%domconfig);
608: } elsif ($action eq 'quotas') {
609: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
610: } elsif ($action eq 'autoenroll') {
611: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
612: } elsif ($action eq 'autoupdate') {
613: $output = &modify_autoupdate($dom,%domconfig);
614: } elsif ($action eq 'autocreate') {
615: $output = &modify_autocreate($dom,%domconfig);
616: } elsif ($action eq 'directorysrch') {
617: $output = &modify_directorysrch($dom,%domconfig);
618: } elsif ($action eq 'usercreation') {
619: $output = &modify_usercreation($dom,%domconfig);
620: } elsif ($action eq 'selfcreation') {
621: $output = &modify_selfcreation($dom,%domconfig);
622: } elsif ($action eq 'usermodification') {
623: $output = &modify_usermodification($dom,%domconfig);
624: } elsif ($action eq 'contacts') {
625: $output = &modify_contacts($dom,$lastactref,%domconfig);
626: } elsif ($action eq 'defaults') {
627: $output = &modify_defaults($dom,$lastactref,%domconfig);
628: } elsif ($action eq 'scantron') {
629: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
630: } elsif ($action eq 'coursecategories') {
631: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
632: } elsif ($action eq 'serverstatuses') {
633: $output = &modify_serverstatuses($dom,%domconfig);
634: } elsif ($action eq 'requestcourses') {
635: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
636: } elsif ($action eq 'requestauthor') {
637: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
638: } elsif ($action eq 'helpsettings') {
639: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
640: } elsif ($action eq 'coursedefaults') {
641: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
642: } elsif ($action eq 'selfenrollment') {
643: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
644: } elsif ($action eq 'usersessions') {
645: $output = &modify_usersessions($dom,$lastactref,%domconfig);
646: } elsif ($action eq 'loadbalancing') {
647: $output = &modify_loadbalancing($dom,%domconfig);
648: }
649: return $output;
650: }
651:
652: sub print_config_box {
653: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
654: my $rowtotal = 0;
655: my $output;
656: if ($action eq 'coursecategories') {
657: $output = &coursecategories_javascript($settings);
658: } elsif ($action eq 'defaults') {
659: $output = &defaults_javascript($settings);
660: }
661: $output .=
662: '<table class="LC_nested_outer">
663: <tr>
664: <th align="left" valign="middle"><span class="LC_nobreak">'.
665: &mt($item->{text}).' '.
666: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
667: '</tr>';
668: $rowtotal ++;
669: my $numheaders = 1;
670: if (ref($item->{'header'}) eq 'ARRAY') {
671: $numheaders = scalar(@{$item->{'header'}});
672: }
673: if ($numheaders > 1) {
674: my $colspan = '';
675: my $rightcolspan = '';
676: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
677: (($action eq 'login') && ($numheaders < 4))) {
678: $colspan = ' colspan="2"';
679: }
680: if ($action eq 'usersessions') {
681: $rightcolspan = ' colspan="3"';
682: }
683: $output .= '
684: <tr>
685: <td>
686: <table class="LC_nested">
687: <tr class="LC_info_row">
688: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
689: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
690: </tr>';
691: $rowtotal ++;
692: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
693: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
694: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
695: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
696: } elsif ($action eq 'coursecategories') {
697: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
698: } elsif ($action eq 'login') {
699: if ($numheaders == 4) {
700: $colspan = ' colspan="2"';
701: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
702: } else {
703: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
704: }
705: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
706: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
707: } elsif ($action eq 'rolecolors') {
708: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
709: }
710: $output .= '
711: </table>
712: </td>
713: </tr>
714: <tr>
715: <td>
716: <table class="LC_nested">
717: <tr class="LC_info_row">
718: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
719: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
720: </tr>';
721: $rowtotal ++;
722: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
723: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
724: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
725: if ($action eq 'coursecategories') {
726: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
727: $colspan = ' colspan="2"';
728: } else {
729: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
730: }
731: $output .= '
732: </table>
733: </td>
734: </tr>
735: <tr>
736: <td>
737: <table class="LC_nested">
738: <tr class="LC_info_row">
739: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
740: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
741: </tr>'."\n";
742: if ($action eq 'coursecategories') {
743: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
744: } else {
745: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
746: }
747: $rowtotal ++;
748: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
749: ($action eq 'defaults')) {
750: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
751: } elsif ($action eq 'login') {
752: if ($numheaders == 4) {
753: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
754: </table>
755: </td>
756: </tr>
757: <tr>
758: <td>
759: <table class="LC_nested">
760: <tr class="LC_info_row">
761: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
762: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
763: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
764: $rowtotal ++;
765: } else {
766: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
767: }
768: $output .= '
769: </table>
770: </td>
771: </tr>
772: <tr>
773: <td>
774: <table class="LC_nested">
775: <tr class="LC_info_row">';
776: if ($numheaders == 4) {
777: $output .= '
778: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
779: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
780: </tr>';
781: } else {
782: $output .= '
783: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
784: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
785: </tr>';
786: }
787: $rowtotal ++;
788: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
789: } elsif ($action eq 'requestcourses') {
790: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
791: $rowtotal ++;
792: $output .= &print_studentcode($settings,\$rowtotal).'
793: </table>
794: </td>
795: </tr>
796: <tr>
797: <td>
798: <table class="LC_nested">
799: <tr class="LC_info_row">
800: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
801: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
802: &textbookcourses_javascript($settings).
803: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
804: </table>
805: </td>
806: </tr>
807: <tr>
808: <td>
809: <table class="LC_nested">
810: <tr class="LC_info_row">
811: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
812: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
813: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
814: </table>
815: </td>
816: </tr>
817: <tr>
818: <td>
819: <table class="LC_nested">
820: <tr class="LC_info_row">
821: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
822: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
823: </tr>'.
824: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
825: } elsif ($action eq 'requestauthor') {
826: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
827: $rowtotal ++;
828: } elsif ($action eq 'rolecolors') {
829: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
830: </table>
831: </td>
832: </tr>
833: <tr>
834: <td>
835: <table class="LC_nested">
836: <tr class="LC_info_row">
837: <td class="LC_left_item"'.$colspan.' valign="top">'.
838: &mt($item->{'header'}->[2]->{'col1'}).'</td>
839: <td class="LC_right_item" valign="top">'.
840: &mt($item->{'header'}->[2]->{'col2'}).'</td>
841: </tr>'.
842: &print_rolecolors($phase,'author',$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.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
851: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
852: </tr>'.
853: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
854: $rowtotal += 2;
855: }
856: } else {
857: $output .= '
858: <tr>
859: <td>
860: <table class="LC_nested">
861: <tr class="LC_info_row">';
862: if (($action eq 'login') || ($action eq 'directorysrch')) {
863: $output .= '
864: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
865: } elsif ($action eq 'serverstatuses') {
866: $output .= '
867: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
868: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
869:
870: } else {
871: $output .= '
872: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
873: }
874: if (defined($item->{'header'}->[0]->{'col3'})) {
875: $output .= '<td class="LC_left_item" valign="top">'.
876: &mt($item->{'header'}->[0]->{'col2'});
877: if ($action eq 'serverstatuses') {
878: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
879: }
880: } else {
881: $output .= '<td class="LC_right_item" valign="top">'.
882: &mt($item->{'header'}->[0]->{'col2'});
883: }
884: $output .= '</td>';
885: if ($item->{'header'}->[0]->{'col3'}) {
886: if (defined($item->{'header'}->[0]->{'col4'})) {
887: $output .= '<td class="LC_left_item" valign="top">'.
888: &mt($item->{'header'}->[0]->{'col3'});
889: } else {
890: $output .= '<td class="LC_right_item" valign="top">'.
891: &mt($item->{'header'}->[0]->{'col3'});
892: }
893: if ($action eq 'serverstatuses') {
894: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
895: }
896: $output .= '</td>';
897: }
898: if ($item->{'header'}->[0]->{'col4'}) {
899: $output .= '<td class="LC_right_item" valign="top">'.
900: &mt($item->{'header'}->[0]->{'col4'});
901: }
902: $output .= '</tr>';
903: $rowtotal ++;
904: if ($action eq 'quotas') {
905: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
906: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
907: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
908: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
909: } elsif ($action eq 'scantron') {
910: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
911: } elsif ($action eq 'helpsettings') {
912: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
913: }
914: }
915: $output .= '
916: </table>
917: </td>
918: </tr>
919: </table><br />';
920: return ($output,$rowtotal);
921: }
922:
923: sub print_login {
924: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
925: my ($css_class,$datatable);
926: my %choices = &login_choices();
927:
928: if ($caller eq 'service') {
929: my %servers = &Apache::lonnet::internet_dom_servers($dom);
930: my $choice = $choices{'disallowlogin'};
931: $css_class = ' class="LC_odd_row"';
932: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
933: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
934: '<th>'.$choices{'server'}.'</th>'.
935: '<th>'.$choices{'serverpath'}.'</th>'.
936: '<th>'.$choices{'custompath'}.'</th>'.
937: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
938: my %disallowed;
939: if (ref($settings) eq 'HASH') {
940: if (ref($settings->{'loginvia'}) eq 'HASH') {
941: %disallowed = %{$settings->{'loginvia'}};
942: }
943: }
944: foreach my $lonhost (sort(keys(%servers))) {
945: my $direct = 'selected="selected"';
946: if (ref($disallowed{$lonhost}) eq 'HASH') {
947: if ($disallowed{$lonhost}{'server'} ne '') {
948: $direct = '';
949: }
950: }
951: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
952: '<td><select name="'.$lonhost.'_server">'.
953: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
954: '</option>';
955: foreach my $hostid (sort(keys(%servers))) {
956: next if ($servers{$hostid} eq $servers{$lonhost});
957: my $selected = '';
958: if (ref($disallowed{$lonhost}) eq 'HASH') {
959: if ($hostid eq $disallowed{$lonhost}{'server'}) {
960: $selected = 'selected="selected"';
961: }
962: }
963: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
964: $servers{$hostid}.'</option>';
965: }
966: $datatable .= '</select></td>'.
967: '<td><select name="'.$lonhost.'_serverpath">';
968: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
969: my $pathname = $path;
970: if ($path eq 'custom') {
971: $pathname = &mt('Custom Path').' ->';
972: }
973: my $selected = '';
974: if (ref($disallowed{$lonhost}) eq 'HASH') {
975: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
976: $selected = 'selected="selected"';
977: }
978: } elsif ($path eq '') {
979: $selected = 'selected="selected"';
980: }
981: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
982: }
983: $datatable .= '</select></td>';
984: my ($custom,$exempt);
985: if (ref($disallowed{$lonhost}) eq 'HASH') {
986: $custom = $disallowed{$lonhost}{'custompath'};
987: $exempt = $disallowed{$lonhost}{'exempt'};
988: }
989: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
990: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
991: '</tr>';
992: }
993: $datatable .= '</table></td></tr>';
994: return $datatable;
995: } elsif ($caller eq 'page') {
996: my %defaultchecked = (
997: 'coursecatalog' => 'on',
998: 'helpdesk' => 'on',
999: 'adminmail' => 'off',
1000: 'newuser' => 'off',
1001: );
1002: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1003: my (%checkedon,%checkedoff);
1004: foreach my $item (@toggles) {
1005: if ($defaultchecked{$item} eq 'on') {
1006: $checkedon{$item} = ' checked="checked" ';
1007: $checkedoff{$item} = ' ';
1008: } elsif ($defaultchecked{$item} eq 'off') {
1009: $checkedoff{$item} = ' checked="checked" ';
1010: $checkedon{$item} = ' ';
1011: }
1012: }
1013: my @images = ('img','logo','domlogo','login');
1014: my @logintext = ('textcol','bgcol');
1015: my @bgs = ('pgbg','mainbg','sidebg');
1016: my @links = ('link','alink','vlink');
1017: my %designhash = &Apache::loncommon::get_domainconf($dom);
1018: my %defaultdesign = %Apache::loncommon::defaultdesign;
1019: my (%is_custom,%designs);
1020: my %defaults = (
1021: font => $defaultdesign{'login.font'},
1022: );
1023: foreach my $item (@images) {
1024: $defaults{$item} = $defaultdesign{'login.'.$item};
1025: $defaults{'showlogo'}{$item} = 1;
1026: }
1027: foreach my $item (@bgs) {
1028: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1029: }
1030: foreach my $item (@logintext) {
1031: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1032: }
1033: foreach my $item (@links) {
1034: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1035: }
1036: if (ref($settings) eq 'HASH') {
1037: foreach my $item (@toggles) {
1038: if ($settings->{$item} eq '1') {
1039: $checkedon{$item} = ' checked="checked" ';
1040: $checkedoff{$item} = ' ';
1041: } elsif ($settings->{$item} eq '0') {
1042: $checkedoff{$item} = ' checked="checked" ';
1043: $checkedon{$item} = ' ';
1044: }
1045: }
1046: foreach my $item (@images) {
1047: if (defined($settings->{$item})) {
1048: $designs{$item} = $settings->{$item};
1049: $is_custom{$item} = 1;
1050: }
1051: if (defined($settings->{'showlogo'}{$item})) {
1052: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1053: }
1054: }
1055: foreach my $item (@logintext) {
1056: if ($settings->{$item} ne '') {
1057: $designs{'logintext'}{$item} = $settings->{$item};
1058: $is_custom{$item} = 1;
1059: }
1060: }
1061: if ($settings->{'font'} ne '') {
1062: $designs{'font'} = $settings->{'font'};
1063: $is_custom{'font'} = 1;
1064: }
1065: foreach my $item (@bgs) {
1066: if ($settings->{$item} ne '') {
1067: $designs{'bgs'}{$item} = $settings->{$item};
1068: $is_custom{$item} = 1;
1069: }
1070: }
1071: foreach my $item (@links) {
1072: if ($settings->{$item} ne '') {
1073: $designs{'links'}{$item} = $settings->{$item};
1074: $is_custom{$item} = 1;
1075: }
1076: }
1077: } else {
1078: if ($designhash{$dom.'.login.font'} ne '') {
1079: $designs{'font'} = $designhash{$dom.'.login.font'};
1080: $is_custom{'font'} = 1;
1081: }
1082: foreach my $item (@images) {
1083: if ($designhash{$dom.'.login.'.$item} ne '') {
1084: $designs{$item} = $designhash{$dom.'.login.'.$item};
1085: $is_custom{$item} = 1;
1086: }
1087: }
1088: foreach my $item (@bgs) {
1089: if ($designhash{$dom.'.login.'.$item} ne '') {
1090: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1091: $is_custom{$item} = 1;
1092: }
1093: }
1094: foreach my $item (@links) {
1095: if ($designhash{$dom.'.login.'.$item} ne '') {
1096: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1097: $is_custom{$item} = 1;
1098: }
1099: }
1100: }
1101: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1102: logo => 'Institution Logo',
1103: domlogo => 'Domain Logo',
1104: login => 'Login box');
1105: my $itemcount = 1;
1106: foreach my $item (@toggles) {
1107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1108: $datatable .=
1109: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1110: '</td><td>'.
1111: '<span class="LC_nobreak"><label><input type="radio" name="'.
1112: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1113: '</label> <label><input type="radio" name="'.$item.'"'.
1114: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1115: '</tr>';
1116: $itemcount ++;
1117: }
1118: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1119: $datatable .= '</tr></table></td></tr>';
1120: } elsif ($caller eq 'help') {
1121: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1122: my $switchserver = &check_switchserver($dom,$confname);
1123: my $itemcount = 1;
1124: $defaulturl = '/adm/loginproblems.html';
1125: $defaulttype = 'default';
1126: %lt = &Apache::lonlocal::texthash (
1127: del => 'Delete?',
1128: rep => 'Replace:',
1129: upl => 'Upload:',
1130: default => 'Default',
1131: custom => 'Custom',
1132: );
1133: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1134: my @currlangs;
1135: if (ref($settings) eq 'HASH') {
1136: if (ref($settings->{'helpurl'}) eq 'HASH') {
1137: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1138: next if ($settings->{'helpurl'}{$key} eq '');
1139: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1140: $type{$key} = 'custom';
1141: unless ($key eq 'nolang') {
1142: push(@currlangs,$key);
1143: }
1144: }
1145: } elsif ($settings->{'helpurl'} ne '') {
1146: $type{'nolang'} = 'custom';
1147: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1148: }
1149: }
1150: foreach my $lang ('nolang',sort(@currlangs)) {
1151: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1152: $datatable .= '<tr'.$css_class.'>';
1153: if ($url{$lang} eq '') {
1154: $url{$lang} = $defaulturl;
1155: }
1156: if ($type{$lang} eq '') {
1157: $type{$lang} = $defaulttype;
1158: }
1159: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1160: if ($lang eq 'nolang') {
1161: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1162: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1163: } else {
1164: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1165: $langchoices{$lang},
1166: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1167: }
1168: $datatable .= '</span></td>'."\n".
1169: '<td class="LC_left_item">';
1170: if ($type{$lang} eq 'custom') {
1171: $datatable .= '<span class="LC_nobreak"><label>'.
1172: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1173: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1174: } else {
1175: $datatable .= $lt{'upl'};
1176: }
1177: $datatable .='<br />';
1178: if ($switchserver) {
1179: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1180: } else {
1181: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1182: }
1183: $datatable .= '</td></tr>';
1184: $itemcount ++;
1185: }
1186: my @addlangs;
1187: foreach my $lang (sort(keys(%langchoices))) {
1188: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1189: push(@addlangs,$lang);
1190: }
1191: if (@addlangs > 0) {
1192: my %toadd;
1193: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1194: $toadd{''} = &mt('Select');
1195: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1196: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1197: &mt('Add log-in help page for a specific language:').' '.
1198: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1199: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1200: if ($switchserver) {
1201: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1202: } else {
1203: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1204: }
1205: $datatable .= '</td></tr>';
1206: $itemcount ++;
1207: }
1208: $datatable .= &captcha_choice('login',$settings,$itemcount);
1209: } elsif ($caller eq 'headtag') {
1210: my %domservers = &Apache::lonnet::get_servers($dom);
1211: my $choice = $choices{'headtag'};
1212: $css_class = ' class="LC_odd_row"';
1213: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1214: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1215: '<th>'.$choices{'current'}.'</th>'.
1216: '<th>'.$choices{'action'}.'</th>'.
1217: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1218: my (%currurls,%currexempt);
1219: if (ref($settings) eq 'HASH') {
1220: if (ref($settings->{'headtag'}) eq 'HASH') {
1221: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1222: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1223: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1224: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1225: }
1226: }
1227: }
1228: }
1229: my %lt = &Apache::lonlocal::texthash(
1230: del => 'Delete?',
1231: rep => 'Replace:',
1232: upl => 'Upload:',
1233: curr => 'View contents',
1234: none => 'None',
1235: );
1236: my $switchserver = &check_switchserver($dom,$confname);
1237: foreach my $lonhost (sort(keys(%domservers))) {
1238: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1239: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1240: if ($currurls{$lonhost}) {
1241: $datatable .= '<td class="LC_right_item"><a href="'.
1242: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1243: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1244: '">'.$lt{'curr'}.'</a></td>'.
1245: '<td><span class="LC_nobreak"><label>'.
1246: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1247: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1248: } else {
1249: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1250: }
1251: $datatable .='<br />';
1252: if ($switchserver) {
1253: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1254: } else {
1255: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1256: }
1257: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1258: }
1259: $datatable .= '</table></td></tr>';
1260: }
1261: return $datatable;
1262: }
1263:
1264: sub login_choices {
1265: my %choices =
1266: &Apache::lonlocal::texthash (
1267: coursecatalog => 'Display Course/Community Catalog link?',
1268: adminmail => "Display Administrator's E-mail Address?",
1269: helpdesk => 'Display "Contact Helpdesk" link',
1270: disallowlogin => "Login page requests redirected",
1271: hostid => "Server",
1272: server => "Redirect to:",
1273: serverpath => "Path",
1274: custompath => "Custom",
1275: exempt => "Exempt IP(s)",
1276: directlogin => "No redirect",
1277: newuser => "Link to create a user account",
1278: img => "Header",
1279: logo => "Main Logo",
1280: domlogo => "Domain Logo",
1281: login => "Log-in Header",
1282: textcol => "Text color",
1283: bgcol => "Box color",
1284: bgs => "Background colors",
1285: links => "Link colors",
1286: font => "Font color",
1287: pgbg => "Header",
1288: mainbg => "Page",
1289: sidebg => "Login box",
1290: link => "Link",
1291: alink => "Active link",
1292: vlink => "Visited link",
1293: headtag => "Custom markup",
1294: action => "Action",
1295: current => "Current",
1296: );
1297: return %choices;
1298: }
1299:
1300: sub print_rolecolors {
1301: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1302: my %choices = &color_font_choices();
1303: my @bgs = ('pgbg','tabbg','sidebg');
1304: my @links = ('link','alink','vlink');
1305: my @images = ('img');
1306: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1307: my %designhash = &Apache::loncommon::get_domainconf($dom);
1308: my %defaultdesign = %Apache::loncommon::defaultdesign;
1309: my (%is_custom,%designs);
1310: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1311: if (ref($settings) eq 'HASH') {
1312: if (ref($settings->{$role}) eq 'HASH') {
1313: if ($settings->{$role}->{'img'} ne '') {
1314: $designs{'img'} = $settings->{$role}->{'img'};
1315: $is_custom{'img'} = 1;
1316: }
1317: if ($settings->{$role}->{'font'} ne '') {
1318: $designs{'font'} = $settings->{$role}->{'font'};
1319: $is_custom{'font'} = 1;
1320: }
1321: if ($settings->{$role}->{'fontmenu'} ne '') {
1322: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1323: $is_custom{'fontmenu'} = 1;
1324: }
1325: foreach my $item (@bgs) {
1326: if ($settings->{$role}->{$item} ne '') {
1327: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1328: $is_custom{$item} = 1;
1329: }
1330: }
1331: foreach my $item (@links) {
1332: if ($settings->{$role}->{$item} ne '') {
1333: $designs{'links'}{$item} = $settings->{$role}->{$item};
1334: $is_custom{$item} = 1;
1335: }
1336: }
1337: }
1338: } else {
1339: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1340: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1341: $is_custom{'img'} = 1;
1342: }
1343: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1344: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1345: $is_custom{'fontmenu'} = 1;
1346: }
1347: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1348: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1349: $is_custom{'font'} = 1;
1350: }
1351: foreach my $item (@bgs) {
1352: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1353: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1354: $is_custom{$item} = 1;
1355:
1356: }
1357: }
1358: foreach my $item (@links) {
1359: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1360: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1361: $is_custom{$item} = 1;
1362: }
1363: }
1364: }
1365: my $itemcount = 1;
1366: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1367: $datatable .= '</tr></table></td></tr>';
1368: return $datatable;
1369: }
1370:
1371: sub role_defaults {
1372: my ($role,$bgs,$links,$images,$logintext) = @_;
1373: my %defaults;
1374: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1375: return %defaults;
1376: }
1377: my %defaultdesign = %Apache::loncommon::defaultdesign;
1378: if ($role eq 'login') {
1379: %defaults = (
1380: font => $defaultdesign{$role.'.font'},
1381: );
1382: if (ref($logintext) eq 'ARRAY') {
1383: foreach my $item (@{$logintext}) {
1384: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1385: }
1386: }
1387: foreach my $item (@{$images}) {
1388: $defaults{'showlogo'}{$item} = 1;
1389: }
1390: } else {
1391: %defaults = (
1392: img => $defaultdesign{$role.'.img'},
1393: font => $defaultdesign{$role.'.font'},
1394: fontmenu => $defaultdesign{$role.'.fontmenu'},
1395: );
1396: }
1397: foreach my $item (@{$bgs}) {
1398: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1399: }
1400: foreach my $item (@{$links}) {
1401: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1402: }
1403: foreach my $item (@{$images}) {
1404: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1405: }
1406: return %defaults;
1407: }
1408:
1409: sub display_color_options {
1410: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1411: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1412: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1413: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1414: my $datatable = '<tr'.$css_class.'>'.
1415: '<td>'.$choices->{'font'}.'</td>';
1416: if (!$is_custom->{'font'}) {
1417: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1418: } else {
1419: $datatable .= '<td> </td>';
1420: }
1421: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1422:
1423: $datatable .= '<td><span class="LC_nobreak">'.
1424: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1425: ' value="'.$current_color.'" /> '.
1426: ' </td></tr>';
1427: unless ($role eq 'login') {
1428: $datatable .= '<tr'.$css_class.'>'.
1429: '<td>'.$choices->{'fontmenu'}.'</td>';
1430: if (!$is_custom->{'fontmenu'}) {
1431: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1432: } else {
1433: $datatable .= '<td> </td>';
1434: }
1435: $current_color = $designs->{'fontmenu'} ?
1436: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1437: $datatable .= '<td><span class="LC_nobreak">'.
1438: '<input class="colorchooser" type="text" size="10" name="'
1439: .$role.'_fontmenu"'.
1440: ' value="'.$current_color.'" /> '.
1441: ' </td></tr>';
1442: }
1443: my $switchserver = &check_switchserver($dom,$confname);
1444: foreach my $img (@{$images}) {
1445: $itemcount ++;
1446: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1447: $datatable .= '<tr'.$css_class.'>'.
1448: '<td>'.$choices->{$img};
1449: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1450: if ($role eq 'login') {
1451: if ($img eq 'login') {
1452: $login_hdr_pick =
1453: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1454: $logincolors =
1455: &login_text_colors($img,$role,$logintext,$phase,$choices,
1456: $designs,$defaults);
1457: } elsif ($img ne 'domlogo') {
1458: $datatable.= &logo_display_options($img,$defaults,$designs);
1459: }
1460: }
1461: $datatable .= '</td>';
1462: if ($designs->{$img} ne '') {
1463: $imgfile = $designs->{$img};
1464: $img_import = ($imgfile =~ m{^/adm/});
1465: } else {
1466: $imgfile = $defaults->{$img};
1467: }
1468: if ($imgfile) {
1469: my ($showfile,$fullsize);
1470: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1471: my $urldir = $1;
1472: my $filename = $2;
1473: my @info = &Apache::lonnet::stat_file($designs->{$img});
1474: if (@info) {
1475: my $thumbfile = 'tn-'.$filename;
1476: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1477: if (@thumb) {
1478: $showfile = $urldir.'/'.$thumbfile;
1479: } else {
1480: $showfile = $imgfile;
1481: }
1482: } else {
1483: $showfile = '';
1484: }
1485: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1486: $showfile = $imgfile;
1487: my $imgdir = $1;
1488: my $filename = $2;
1489: if (-e "$londocroot/$imgdir/tn-".$filename) {
1490: $showfile = "/$imgdir/tn-".$filename;
1491: } else {
1492: my $input = $londocroot.$imgfile;
1493: my $output = "$londocroot/$imgdir/tn-".$filename;
1494: if (!-e $output) {
1495: my ($width,$height) = &thumb_dimensions();
1496: my ($fullwidth,$fullheight) = &check_dimensions($input);
1497: if ($fullwidth ne '' && $fullheight ne '') {
1498: if ($fullwidth > $width && $fullheight > $height) {
1499: my $size = $width.'x'.$height;
1500: system("convert -sample $size $input $output");
1501: $showfile = "/$imgdir/tn-".$filename;
1502: }
1503: }
1504: }
1505: }
1506: }
1507: if ($showfile) {
1508: if ($showfile =~ m{^/(adm|res)/}) {
1509: if ($showfile =~ m{^/res/}) {
1510: my $local_showfile =
1511: &Apache::lonnet::filelocation('',$showfile);
1512: &Apache::lonnet::repcopy($local_showfile);
1513: }
1514: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1515: }
1516: if ($imgfile) {
1517: if ($imgfile =~ m{^/(adm|res)/}) {
1518: if ($imgfile =~ m{^/res/}) {
1519: my $local_imgfile =
1520: &Apache::lonnet::filelocation('',$imgfile);
1521: &Apache::lonnet::repcopy($local_imgfile);
1522: }
1523: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1524: } else {
1525: $fullsize = $imgfile;
1526: }
1527: }
1528: $datatable .= '<td>';
1529: if ($img eq 'login') {
1530: $datatable .= $login_hdr_pick;
1531: }
1532: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1533: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1534: } else {
1535: $datatable .= '<td> </td><td class="LC_left_item">'.
1536: &mt('Upload:').'<br />';
1537: }
1538: } else {
1539: $datatable .= '<td> </td><td class="LC_left_item">'.
1540: &mt('Upload:').'<br />';
1541: }
1542: if ($switchserver) {
1543: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1544: } else {
1545: if ($img ne 'login') { # suppress file selection for Log-in header
1546: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1547: }
1548: }
1549: $datatable .= '</td></tr>';
1550: }
1551: $itemcount ++;
1552: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1553: $datatable .= '<tr'.$css_class.'>'.
1554: '<td>'.$choices->{'bgs'}.'</td>';
1555: my $bgs_def;
1556: foreach my $item (@{$bgs}) {
1557: if (!$is_custom->{$item}) {
1558: $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>';
1559: }
1560: }
1561: if ($bgs_def) {
1562: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1563: } else {
1564: $datatable .= '<td> </td>';
1565: }
1566: $datatable .= '<td class="LC_right_item">'.
1567: '<table border="0"><tr>';
1568:
1569: foreach my $item (@{$bgs}) {
1570: $datatable .= '<td align="center">'.$choices->{$item};
1571: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1572: if ($designs->{'bgs'}{$item}) {
1573: $datatable .= ' ';
1574: }
1575: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1576: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1577: }
1578: $datatable .= '</tr></table></td></tr>';
1579: $itemcount ++;
1580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1581: $datatable .= '<tr'.$css_class.'>'.
1582: '<td>'.$choices->{'links'}.'</td>';
1583: my $links_def;
1584: foreach my $item (@{$links}) {
1585: if (!$is_custom->{$item}) {
1586: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1587: }
1588: }
1589: if ($links_def) {
1590: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1591: } else {
1592: $datatable .= '<td> </td>';
1593: }
1594: $datatable .= '<td class="LC_right_item">'.
1595: '<table border="0"><tr>';
1596: foreach my $item (@{$links}) {
1597: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1598: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1599: if ($designs->{'links'}{$item}) {
1600: $datatable.=' ';
1601: }
1602: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1603: '" /></td>';
1604: }
1605: $$rowtotal += $itemcount;
1606: return $datatable;
1607: }
1608:
1609: sub logo_display_options {
1610: my ($img,$defaults,$designs) = @_;
1611: my $checkedon;
1612: if (ref($defaults) eq 'HASH') {
1613: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1614: if ($defaults->{'showlogo'}{$img}) {
1615: $checkedon = 'checked="checked" ';
1616: }
1617: }
1618: }
1619: if (ref($designs) eq 'HASH') {
1620: if (ref($designs->{'showlogo'}) eq 'HASH') {
1621: if (defined($designs->{'showlogo'}{$img})) {
1622: if ($designs->{'showlogo'}{$img} == 0) {
1623: $checkedon = '';
1624: } elsif ($designs->{'showlogo'}{$img} == 1) {
1625: $checkedon = 'checked="checked" ';
1626: }
1627: }
1628: }
1629: }
1630: return '<br /><label> <input type="checkbox" name="'.
1631: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1632: &mt('show').'</label>'."\n";
1633: }
1634:
1635: sub login_header_options {
1636: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1637: my $output = '';
1638: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1639: $output .= &mt('Text default(s):').'<br />';
1640: if (!$is_custom->{'textcol'}) {
1641: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1642: ' ';
1643: }
1644: if (!$is_custom->{'bgcol'}) {
1645: $output .= $choices->{'bgcol'}.': '.
1646: '<span id="css_'.$role.'_font" style="background-color: '.
1647: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1648: }
1649: $output .= '<br />';
1650: }
1651: $output .='<br />';
1652: return $output;
1653: }
1654:
1655: sub login_text_colors {
1656: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1657: my $color_menu = '<table border="0"><tr>';
1658: foreach my $item (@{$logintext}) {
1659: $color_menu .= '<td align="center">'.$choices->{$item};
1660: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1661: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1662: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1663: }
1664: $color_menu .= '</tr></table><br />';
1665: return $color_menu;
1666: }
1667:
1668: sub image_changes {
1669: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1670: my $output;
1671: if ($img eq 'login') {
1672: # suppress image for Log-in header
1673: } elsif (!$is_custom) {
1674: if ($img ne 'domlogo') {
1675: $output .= &mt('Default image:').'<br />';
1676: } else {
1677: $output .= &mt('Default in use:').'<br />';
1678: }
1679: }
1680: if ($img eq 'login') { # suppress image for Log-in header
1681: $output .= '<td>'.$logincolors;
1682: } else {
1683: if ($img_import) {
1684: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1685: }
1686: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1687: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1688: if ($is_custom) {
1689: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1690: '<input type="checkbox" name="'.
1691: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1692: '</label> '.&mt('Replace:').'</span><br />';
1693: } else {
1694: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1695: }
1696: }
1697: return $output;
1698: }
1699:
1700: sub print_quotas {
1701: my ($dom,$settings,$rowtotal,$action) = @_;
1702: my $context;
1703: if ($action eq 'quotas') {
1704: $context = 'tools';
1705: } else {
1706: $context = $action;
1707: }
1708: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1709: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1710: my $typecount = 0;
1711: my ($css_class,%titles);
1712: if ($context eq 'requestcourses') {
1713: @usertools = ('official','unofficial','community','textbook');
1714: @options =('norequest','approval','validate','autolimit');
1715: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1716: %titles = &courserequest_titles();
1717: } elsif ($context eq 'requestauthor') {
1718: @usertools = ('author');
1719: @options = ('norequest','approval','automatic');
1720: %titles = &authorrequest_titles();
1721: } else {
1722: @usertools = ('aboutme','blog','webdav','portfolio');
1723: %titles = &tool_titles();
1724: }
1725: if (ref($types) eq 'ARRAY') {
1726: foreach my $type (@{$types}) {
1727: my ($currdefquota,$currauthorquota);
1728: unless (($context eq 'requestcourses') ||
1729: ($context eq 'requestauthor')) {
1730: if (ref($settings) eq 'HASH') {
1731: if (ref($settings->{defaultquota}) eq 'HASH') {
1732: $currdefquota = $settings->{defaultquota}->{$type};
1733: } else {
1734: $currdefquota = $settings->{$type};
1735: }
1736: if (ref($settings->{authorquota}) eq 'HASH') {
1737: $currauthorquota = $settings->{authorquota}->{$type};
1738: }
1739: }
1740: }
1741: if (defined($usertypes->{$type})) {
1742: $typecount ++;
1743: $css_class = $typecount%2?' class="LC_odd_row"':'';
1744: $datatable .= '<tr'.$css_class.'>'.
1745: '<td>'.$usertypes->{$type}.'</td>'.
1746: '<td class="LC_left_item">';
1747: if ($context eq 'requestcourses') {
1748: $datatable .= '<table><tr>';
1749: }
1750: my %cell;
1751: foreach my $item (@usertools) {
1752: if ($context eq 'requestcourses') {
1753: my ($curroption,$currlimit);
1754: if (ref($settings) eq 'HASH') {
1755: if (ref($settings->{$item}) eq 'HASH') {
1756: $curroption = $settings->{$item}->{$type};
1757: if ($curroption =~ /^autolimit=(\d*)$/) {
1758: $currlimit = $1;
1759: }
1760: }
1761: }
1762: if (!$curroption) {
1763: $curroption = 'norequest';
1764: }
1765: $datatable .= '<th>'.$titles{$item}.'</th>';
1766: foreach my $option (@options) {
1767: my $val = $option;
1768: if ($option eq 'norequest') {
1769: $val = 0;
1770: }
1771: if ($option eq 'validate') {
1772: my $canvalidate = 0;
1773: if (ref($validations{$item}) eq 'HASH') {
1774: if ($validations{$item}{$type}) {
1775: $canvalidate = 1;
1776: }
1777: }
1778: next if (!$canvalidate);
1779: }
1780: my $checked = '';
1781: if ($option eq $curroption) {
1782: $checked = ' checked="checked"';
1783: } elsif ($option eq 'autolimit') {
1784: if ($curroption =~ /^autolimit/) {
1785: $checked = ' checked="checked"';
1786: }
1787: }
1788: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1789: '<input type="radio" name="crsreq_'.$item.
1790: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1791: $titles{$option}.'</label>';
1792: if ($option eq 'autolimit') {
1793: $cell{$item} .= ' <input type="text" name="crsreq_'.
1794: $item.'_limit_'.$type.'" size="1" '.
1795: 'value="'.$currlimit.'" />';
1796: }
1797: $cell{$item} .= '</span> ';
1798: if ($option eq 'autolimit') {
1799: $cell{$item} .= $titles{'unlimited'};
1800: }
1801: }
1802: } elsif ($context eq 'requestauthor') {
1803: my $curroption;
1804: if (ref($settings) eq 'HASH') {
1805: $curroption = $settings->{$type};
1806: }
1807: if (!$curroption) {
1808: $curroption = 'norequest';
1809: }
1810: foreach my $option (@options) {
1811: my $val = $option;
1812: if ($option eq 'norequest') {
1813: $val = 0;
1814: }
1815: my $checked = '';
1816: if ($option eq $curroption) {
1817: $checked = ' checked="checked"';
1818: }
1819: $datatable .= '<span class="LC_nobreak"><label>'.
1820: '<input type="radio" name="authorreq_'.$type.
1821: '" value="'.$val.'"'.$checked.' />'.
1822: $titles{$option}.'</label></span> ';
1823: }
1824: } else {
1825: my $checked = 'checked="checked" ';
1826: if (ref($settings) eq 'HASH') {
1827: if (ref($settings->{$item}) eq 'HASH') {
1828: if ($settings->{$item}->{$type} == 0) {
1829: $checked = '';
1830: } elsif ($settings->{$item}->{$type} == 1) {
1831: $checked = 'checked="checked" ';
1832: }
1833: }
1834: }
1835: $datatable .= '<span class="LC_nobreak"><label>'.
1836: '<input type="checkbox" name="'.$context.'_'.$item.
1837: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1838: '</label></span> ';
1839: }
1840: }
1841: if ($context eq 'requestcourses') {
1842: $datatable .= '</tr><tr>';
1843: foreach my $item (@usertools) {
1844: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1845: }
1846: $datatable .= '</tr></table>';
1847: }
1848: $datatable .= '</td>';
1849: unless (($context eq 'requestcourses') ||
1850: ($context eq 'requestauthor')) {
1851: $datatable .=
1852: '<td class="LC_right_item">'.
1853: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1854: '<input type="text" name="quota_'.$type.
1855: '" value="'.$currdefquota.
1856: '" size="5" /></span>'.(' ' x 2).
1857: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1858: '<input type="text" name="authorquota_'.$type.
1859: '" value="'.$currauthorquota.
1860: '" size="5" /></span></td>';
1861: }
1862: $datatable .= '</tr>';
1863: }
1864: }
1865: }
1866: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1867: $defaultquota = '20';
1868: $authorquota = '500';
1869: if (ref($settings) eq 'HASH') {
1870: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1871: $defaultquota = $settings->{'defaultquota'}->{'default'};
1872: } elsif (defined($settings->{'default'})) {
1873: $defaultquota = $settings->{'default'};
1874: }
1875: if (ref($settings->{'authorquota'}) eq 'HASH') {
1876: $authorquota = $settings->{'authorquota'}->{'default'};
1877: }
1878: }
1879: }
1880: $typecount ++;
1881: $css_class = $typecount%2?' class="LC_odd_row"':'';
1882: $datatable .= '<tr'.$css_class.'>'.
1883: '<td>'.$othertitle.'</td>'.
1884: '<td class="LC_left_item">';
1885: if ($context eq 'requestcourses') {
1886: $datatable .= '<table><tr>';
1887: }
1888: my %defcell;
1889: foreach my $item (@usertools) {
1890: if ($context eq 'requestcourses') {
1891: my ($curroption,$currlimit);
1892: if (ref($settings) eq 'HASH') {
1893: if (ref($settings->{$item}) eq 'HASH') {
1894: $curroption = $settings->{$item}->{'default'};
1895: if ($curroption =~ /^autolimit=(\d*)$/) {
1896: $currlimit = $1;
1897: }
1898: }
1899: }
1900: if (!$curroption) {
1901: $curroption = 'norequest';
1902: }
1903: $datatable .= '<th>'.$titles{$item}.'</th>';
1904: foreach my $option (@options) {
1905: my $val = $option;
1906: if ($option eq 'norequest') {
1907: $val = 0;
1908: }
1909: if ($option eq 'validate') {
1910: my $canvalidate = 0;
1911: if (ref($validations{$item}) eq 'HASH') {
1912: if ($validations{$item}{'default'}) {
1913: $canvalidate = 1;
1914: }
1915: }
1916: next if (!$canvalidate);
1917: }
1918: my $checked = '';
1919: if ($option eq $curroption) {
1920: $checked = ' checked="checked"';
1921: } elsif ($option eq 'autolimit') {
1922: if ($curroption =~ /^autolimit/) {
1923: $checked = ' checked="checked"';
1924: }
1925: }
1926: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1927: '<input type="radio" name="crsreq_'.$item.
1928: '_default" value="'.$val.'"'.$checked.' />'.
1929: $titles{$option}.'</label>';
1930: if ($option eq 'autolimit') {
1931: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1932: $item.'_limit_default" size="1" '.
1933: 'value="'.$currlimit.'" />';
1934: }
1935: $defcell{$item} .= '</span> ';
1936: if ($option eq 'autolimit') {
1937: $defcell{$item} .= $titles{'unlimited'};
1938: }
1939: }
1940: } elsif ($context eq 'requestauthor') {
1941: my $curroption;
1942: if (ref($settings) eq 'HASH') {
1943: $curroption = $settings->{'default'};
1944: }
1945: if (!$curroption) {
1946: $curroption = 'norequest';
1947: }
1948: foreach my $option (@options) {
1949: my $val = $option;
1950: if ($option eq 'norequest') {
1951: $val = 0;
1952: }
1953: my $checked = '';
1954: if ($option eq $curroption) {
1955: $checked = ' checked="checked"';
1956: }
1957: $datatable .= '<span class="LC_nobreak"><label>'.
1958: '<input type="radio" name="authorreq_default"'.
1959: ' value="'.$val.'"'.$checked.' />'.
1960: $titles{$option}.'</label></span> ';
1961: }
1962: } else {
1963: my $checked = 'checked="checked" ';
1964: if (ref($settings) eq 'HASH') {
1965: if (ref($settings->{$item}) eq 'HASH') {
1966: if ($settings->{$item}->{'default'} == 0) {
1967: $checked = '';
1968: } elsif ($settings->{$item}->{'default'} == 1) {
1969: $checked = 'checked="checked" ';
1970: }
1971: }
1972: }
1973: $datatable .= '<span class="LC_nobreak"><label>'.
1974: '<input type="checkbox" name="'.$context.'_'.$item.
1975: '" value="default" '.$checked.'/>'.$titles{$item}.
1976: '</label></span> ';
1977: }
1978: }
1979: if ($context eq 'requestcourses') {
1980: $datatable .= '</tr><tr>';
1981: foreach my $item (@usertools) {
1982: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1983: }
1984: $datatable .= '</tr></table>';
1985: }
1986: $datatable .= '</td>';
1987: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1988: $datatable .= '<td class="LC_right_item">'.
1989: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1990: '<input type="text" name="defaultquota" value="'.
1991: $defaultquota.'" size="5" /></span>'.(' ' x2).
1992: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1993: '<input type="text" name="authorquota" value="'.
1994: $authorquota.'" size="5" /></span></td>';
1995: }
1996: $datatable .= '</tr>';
1997: $typecount ++;
1998: $css_class = $typecount%2?' class="LC_odd_row"':'';
1999: $datatable .= '<tr'.$css_class.'>'.
2000: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2001: if ($context eq 'requestcourses') {
2002: $datatable .= &mt('(overrides affiliation, if set)').
2003: '</td>'.
2004: '<td class="LC_left_item">'.
2005: '<table><tr>';
2006: } else {
2007: $datatable .= &mt('(overrides affiliation, if checked)').
2008: '</td>'.
2009: '<td class="LC_left_item" colspan="2">'.
2010: '<br />';
2011: }
2012: my %advcell;
2013: foreach my $item (@usertools) {
2014: if ($context eq 'requestcourses') {
2015: my ($curroption,$currlimit);
2016: if (ref($settings) eq 'HASH') {
2017: if (ref($settings->{$item}) eq 'HASH') {
2018: $curroption = $settings->{$item}->{'_LC_adv'};
2019: if ($curroption =~ /^autolimit=(\d*)$/) {
2020: $currlimit = $1;
2021: }
2022: }
2023: }
2024: $datatable .= '<th>'.$titles{$item}.'</th>';
2025: my $checked = '';
2026: if ($curroption eq '') {
2027: $checked = ' checked="checked"';
2028: }
2029: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2030: '<input type="radio" name="crsreq_'.$item.
2031: '__LC_adv" value=""'.$checked.' />'.
2032: &mt('No override set').'</label></span> ';
2033: foreach my $option (@options) {
2034: my $val = $option;
2035: if ($option eq 'norequest') {
2036: $val = 0;
2037: }
2038: if ($option eq 'validate') {
2039: my $canvalidate = 0;
2040: if (ref($validations{$item}) eq 'HASH') {
2041: if ($validations{$item}{'_LC_adv'}) {
2042: $canvalidate = 1;
2043: }
2044: }
2045: next if (!$canvalidate);
2046: }
2047: my $checked = '';
2048: if ($val eq $curroption) {
2049: $checked = ' checked="checked"';
2050: } elsif ($option eq 'autolimit') {
2051: if ($curroption =~ /^autolimit/) {
2052: $checked = ' checked="checked"';
2053: }
2054: }
2055: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2056: '<input type="radio" name="crsreq_'.$item.
2057: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2058: $titles{$option}.'</label>';
2059: if ($option eq 'autolimit') {
2060: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2061: $item.'_limit__LC_adv" size="1" '.
2062: 'value="'.$currlimit.'" />';
2063: }
2064: $advcell{$item} .= '</span> ';
2065: if ($option eq 'autolimit') {
2066: $advcell{$item} .= $titles{'unlimited'};
2067: }
2068: }
2069: } elsif ($context eq 'requestauthor') {
2070: my $curroption;
2071: if (ref($settings) eq 'HASH') {
2072: $curroption = $settings->{'_LC_adv'};
2073: }
2074: my $checked = '';
2075: if ($curroption eq '') {
2076: $checked = ' checked="checked"';
2077: }
2078: $datatable .= '<span class="LC_nobreak"><label>'.
2079: '<input type="radio" name="authorreq__LC_adv"'.
2080: ' value=""'.$checked.' />'.
2081: &mt('No override set').'</label></span> ';
2082: foreach my $option (@options) {
2083: my $val = $option;
2084: if ($option eq 'norequest') {
2085: $val = 0;
2086: }
2087: my $checked = '';
2088: if ($val eq $curroption) {
2089: $checked = ' checked="checked"';
2090: }
2091: $datatable .= '<span class="LC_nobreak"><label>'.
2092: '<input type="radio" name="authorreq__LC_adv"'.
2093: ' value="'.$val.'"'.$checked.' />'.
2094: $titles{$option}.'</label></span> ';
2095: }
2096: } else {
2097: my $checked = 'checked="checked" ';
2098: if (ref($settings) eq 'HASH') {
2099: if (ref($settings->{$item}) eq 'HASH') {
2100: if ($settings->{$item}->{'_LC_adv'} == 0) {
2101: $checked = '';
2102: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2103: $checked = 'checked="checked" ';
2104: }
2105: }
2106: }
2107: $datatable .= '<span class="LC_nobreak"><label>'.
2108: '<input type="checkbox" name="'.$context.'_'.$item.
2109: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2110: '</label></span> ';
2111: }
2112: }
2113: if ($context eq 'requestcourses') {
2114: $datatable .= '</tr><tr>';
2115: foreach my $item (@usertools) {
2116: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2117: }
2118: $datatable .= '</tr></table>';
2119: }
2120: $datatable .= '</td></tr>';
2121: $$rowtotal += $typecount;
2122: return $datatable;
2123: }
2124:
2125: sub print_requestmail {
2126: my ($dom,$action,$settings,$rowtotal) = @_;
2127: my ($now,$datatable,%currapp);
2128: $now = time;
2129: if (ref($settings) eq 'HASH') {
2130: if (ref($settings->{'notify'}) eq 'HASH') {
2131: if ($settings->{'notify'}{'approval'} ne '') {
2132: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2133: }
2134: }
2135: }
2136: my $numinrow = 2;
2137: my $css_class;
2138: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
2139: my $text;
2140: if ($action eq 'requestcourses') {
2141: $text = &mt('Receive notification of course requests requiring approval');
2142: } elsif ($action eq 'requestauthor') {
2143: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2144: } else {
2145: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2146: }
2147: $datatable = '<tr'.$css_class.'>'.
2148: ' <td>'.$text.'</td>'.
2149: ' <td class="LC_left_item">';
2150: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2151: $action.'notifyapproval',%currapp);
2152: if ($numdc > 0) {
2153: $datatable .= $table;
2154: } else {
2155: $datatable .= &mt('There are no active Domain Coordinators');
2156: }
2157: $datatable .='</td></tr>';
2158: return $datatable;
2159: }
2160:
2161: sub print_studentcode {
2162: my ($settings,$rowtotal) = @_;
2163: my $rownum = 0;
2164: my ($output,%current);
2165: my @crstypes = ('official','unofficial','community','textbook');
2166: if (ref($settings) eq 'HASH') {
2167: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2168: foreach my $type (@crstypes) {
2169: $current{$type} = $settings->{'uniquecode'}{$type};
2170: }
2171: }
2172: }
2173: $output .= '<tr>'.
2174: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2175: '<td class="LC_left_item">';
2176: foreach my $type (@crstypes) {
2177: my $check = ' ';
2178: if ($current{$type}) {
2179: $check = ' checked="checked" ';
2180: }
2181: $output .= '<span class="LC_nobreak"><label>'.
2182: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2183: &mt($type).'</label></span>'.(' 'x2).' ';
2184: }
2185: $output .= '</td></tr>';
2186: $$rowtotal ++;
2187: return $output;
2188: }
2189:
2190: sub print_textbookcourses {
2191: my ($dom,$type,$settings,$rowtotal) = @_;
2192: my $rownum = 0;
2193: my $css_class;
2194: my $itemcount = 1;
2195: my $maxnum = 0;
2196: my $bookshash;
2197: if (ref($settings) eq 'HASH') {
2198: $bookshash = $settings->{$type};
2199: }
2200: my %ordered;
2201: if (ref($bookshash) eq 'HASH') {
2202: foreach my $item (keys(%{$bookshash})) {
2203: if (ref($bookshash->{$item}) eq 'HASH') {
2204: my $num = $bookshash->{$item}{'order'};
2205: $ordered{$num} = $item;
2206: }
2207: }
2208: }
2209: my $confname = $dom.'-domainconfig';
2210: my $switchserver = &check_switchserver($dom,$confname);
2211: my $maxnum = scalar(keys(%ordered));
2212: my $datatable;
2213: if (keys(%ordered)) {
2214: my @items = sort { $a <=> $b } keys(%ordered);
2215: for (my $i=0; $i<@items; $i++) {
2216: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2217: my $key = $ordered{$items[$i]};
2218: my %coursehash=&Apache::lonnet::coursedescription($key);
2219: my $coursetitle = $coursehash{'description'};
2220: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2221: if (ref($bookshash->{$key}) eq 'HASH') {
2222: $subject = $bookshash->{$key}->{'subject'};
2223: $title = $bookshash->{$key}->{'title'};
2224: if ($type eq 'textbooks') {
2225: $publisher = $bookshash->{$key}->{'publisher'};
2226: $author = $bookshash->{$key}->{'author'};
2227: $image = $bookshash->{$key}->{'image'};
2228: if ($image ne '') {
2229: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2230: my $imagethumb = "$path/tn-".$imagefile;
2231: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2232: }
2233: }
2234: }
2235: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2236: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2237: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2238: for (my $k=0; $k<=$maxnum; $k++) {
2239: my $vpos = $k+1;
2240: my $selstr;
2241: if ($k == $i) {
2242: $selstr = ' selected="selected" ';
2243: }
2244: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2245: }
2246: $datatable .= '</select>'.(' 'x2).
2247: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2248: &mt('Delete?').'</label></span></td>'.
2249: '<td colspan="2">'.
2250: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2251: (' 'x2).
2252: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2253: if ($type eq 'textbooks') {
2254: $datatable .= (' 'x2).
2255: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2256: (' 'x2).
2257: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2258: (' 'x2).
2259: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2260: if ($image) {
2261: $datatable .= '<span class="LC_nobreak">'.
2262: $imgsrc.
2263: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2264: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2265: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2266: }
2267: if ($switchserver) {
2268: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2269: } else {
2270: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2271: }
2272: }
2273: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2274: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2275: $coursetitle.'</span></td></tr>'."\n";
2276: $itemcount ++;
2277: }
2278: }
2279: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2280: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2281: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2282: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2283: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2284: for (my $k=0; $k<$maxnum+1; $k++) {
2285: my $vpos = $k+1;
2286: my $selstr;
2287: if ($k == $maxnum) {
2288: $selstr = ' selected="selected" ';
2289: }
2290: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2291: }
2292: $datatable .= '</select> '."\n".
2293: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
2294: '<td colspan="2">'.
2295: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2296: (' 'x2).
2297: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2298: (' 'x2);
2299: if ($type eq 'textbooks') {
2300: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2301: (' 'x2).
2302: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2303: (' 'x2).
2304: '<span class="LC_nobreak">'.&mt('Image:').' ';
2305: if ($switchserver) {
2306: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2307: } else {
2308: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2309: }
2310: }
2311: $datatable .= '</span>'."\n".
2312: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2313: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2314: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2315: &Apache::loncommon::selectcourse_link
2316: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
2317: '</span></td>'."\n".
2318: '</tr>'."\n";
2319: $itemcount ++;
2320: return $datatable;
2321: }
2322:
2323: sub textbookcourses_javascript {
2324: my ($settings) = @_;
2325: return unless(ref($settings) eq 'HASH');
2326: my (%ordered,%total,%jstext);
2327: foreach my $type ('textbooks','templates') {
2328: $total{$type} = 0;
2329: if (ref($settings->{$type}) eq 'HASH') {
2330: foreach my $item (keys(%{$settings->{$type}})) {
2331: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2332: my $num = $settings->{$type}->{$item}{'order'};
2333: $ordered{$type}{$num} = $item;
2334: }
2335: }
2336: $total{$type} = scalar(keys(%{$settings->{$type}}));
2337: }
2338: my @jsarray = ();
2339: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2340: push(@jsarray,$ordered{$type}{$item});
2341: }
2342: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2343: }
2344: return <<"ENDSCRIPT";
2345: <script type="text/javascript">
2346: // <![CDATA[
2347: function reorderBooks(form,item,caller) {
2348: var changedVal;
2349: $jstext{'textbooks'};
2350: $jstext{'templates'};
2351: var newpos;
2352: var maxh;
2353: if (caller == 'textbooks') {
2354: newpos = 'textbooks_addbook_pos';
2355: maxh = 1 + $total{'textbooks'};
2356: } else {
2357: newpos = 'templates_addbook_pos';
2358: maxh = 1 + $total{'templates'};
2359: }
2360: var current = new Array;
2361: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2362: if (item == newpos) {
2363: changedVal = newitemVal;
2364: } else {
2365: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2366: current[newitemVal] = newpos;
2367: }
2368: if (caller == 'textbooks') {
2369: for (var i=0; i<textbooks.length; i++) {
2370: var elementName = 'textbooks_'+textbooks[i];
2371: if (elementName != item) {
2372: if (form.elements[elementName]) {
2373: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2374: current[currVal] = elementName;
2375: }
2376: }
2377: }
2378: }
2379: if (caller == 'templates') {
2380: for (var i=0; i<templates.length; i++) {
2381: var elementName = 'templates_'+templates[i];
2382: if (elementName != item) {
2383: if (form.elements[elementName]) {
2384: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2385: current[currVal] = elementName;
2386: }
2387: }
2388: }
2389: }
2390: var oldVal;
2391: for (var j=0; j<maxh; j++) {
2392: if (current[j] == undefined) {
2393: oldVal = j;
2394: }
2395: }
2396: if (oldVal < changedVal) {
2397: for (var k=oldVal+1; k<=changedVal ; k++) {
2398: var elementName = current[k];
2399: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2400: }
2401: } else {
2402: for (var k=changedVal; k<oldVal; k++) {
2403: var elementName = current[k];
2404: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2405: }
2406: }
2407: return;
2408: }
2409:
2410: // ]]>
2411: </script>
2412:
2413: ENDSCRIPT
2414: }
2415:
2416: sub print_autoenroll {
2417: my ($dom,$settings,$rowtotal) = @_;
2418: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2419: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
2420: if (ref($settings) eq 'HASH') {
2421: if (exists($settings->{'run'})) {
2422: if ($settings->{'run'} eq '0') {
2423: $runoff = ' checked="checked" ';
2424: $runon = ' ';
2425: } else {
2426: $runon = ' checked="checked" ';
2427: $runoff = ' ';
2428: }
2429: } else {
2430: if ($autorun) {
2431: $runon = ' checked="checked" ';
2432: $runoff = ' ';
2433: } else {
2434: $runoff = ' checked="checked" ';
2435: $runon = ' ';
2436: }
2437: }
2438: if (exists($settings->{'co-owners'})) {
2439: if ($settings->{'co-owners'} eq '0') {
2440: $coownersoff = ' checked="checked" ';
2441: $coownerson = ' ';
2442: } else {
2443: $coownerson = ' checked="checked" ';
2444: $coownersoff = ' ';
2445: }
2446: } else {
2447: $coownersoff = ' checked="checked" ';
2448: $coownerson = ' ';
2449: }
2450: if (exists($settings->{'sender_domain'})) {
2451: $defdom = $settings->{'sender_domain'};
2452: }
2453: } else {
2454: if ($autorun) {
2455: $runon = ' checked="checked" ';
2456: $runoff = ' ';
2457: } else {
2458: $runoff = ' checked="checked" ';
2459: $runon = ' ';
2460: }
2461: }
2462: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2463: my $notif_sender;
2464: if (ref($settings) eq 'HASH') {
2465: $notif_sender = $settings->{'sender_uname'};
2466: }
2467: my $datatable='<tr class="LC_odd_row">'.
2468: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2469: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2470: '<input type="radio" name="autoenroll_run"'.
2471: $runon.' value="1" />'.&mt('Yes').'</label> '.
2472: '<label><input type="radio" name="autoenroll_run"'.
2473: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2474: '</tr><tr>'.
2475: '<td>'.&mt('Notification messages - sender').
2476: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2477: &mt('username').': '.
2478: '<input type="text" name="sender_uname" value="'.
2479: $notif_sender.'" size="10" /> '.&mt('domain').
2480: ': '.$domform.'</span></td></tr>'.
2481: '<tr class="LC_odd_row">'.
2482: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2483: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2484: '<input type="radio" name="autoassign_coowners"'.
2485: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2486: '<label><input type="radio" name="autoassign_coowners"'.
2487: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2488: '</tr>';
2489: $$rowtotal += 3;
2490: return $datatable;
2491: }
2492:
2493: sub print_autoupdate {
2494: my ($position,$dom,$settings,$rowtotal) = @_;
2495: my $datatable;
2496: if ($position eq 'top') {
2497: my $updateon = ' ';
2498: my $updateoff = ' checked="checked" ';
2499: my $classlistson = ' ';
2500: my $classlistsoff = ' checked="checked" ';
2501: if (ref($settings) eq 'HASH') {
2502: if ($settings->{'run'} eq '1') {
2503: $updateon = $updateoff;
2504: $updateoff = ' ';
2505: }
2506: if ($settings->{'classlists'} eq '1') {
2507: $classlistson = $classlistsoff;
2508: $classlistsoff = ' ';
2509: }
2510: }
2511: my %title = (
2512: run => 'Auto-update active?',
2513: classlists => 'Update information in classlists?',
2514: );
2515: $datatable = '<tr class="LC_odd_row">'.
2516: '<td>'.&mt($title{'run'}).'</td>'.
2517: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2518: '<input type="radio" name="autoupdate_run"'.
2519: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2520: '<label><input type="radio" name="autoupdate_run"'.
2521: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2522: '</tr><tr>'.
2523: '<td>'.&mt($title{'classlists'}).'</td>'.
2524: '<td class="LC_right_item"><span class="LC_nobreak">'.
2525: '<label><input type="radio" name="classlists"'.
2526: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2527: '<label><input type="radio" name="classlists"'.
2528: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2529: '</tr>';
2530: $$rowtotal += 2;
2531: } elsif ($position eq 'middle') {
2532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2533: my $numinrow = 3;
2534: my $locknamesettings;
2535: $datatable .= &insttypes_row($settings,$types,$usertypes,
2536: $dom,$numinrow,$othertitle,
2537: 'lockablenames');
2538: $$rowtotal ++;
2539: } else {
2540: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2541: my @fields = ('lastname','firstname','middlename','generation',
2542: 'permanentemail','id');
2543: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2544: my $numrows = 0;
2545: if (ref($types) eq 'ARRAY') {
2546: if (@{$types} > 0) {
2547: $datatable =
2548: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2549: \@fields,$types,\$numrows);
2550: $$rowtotal += @{$types};
2551: }
2552: }
2553: $datatable .=
2554: &usertype_update_row($settings,{'default' => $othertitle},
2555: \%fieldtitles,\@fields,['default'],
2556: \$numrows);
2557: $$rowtotal ++;
2558: }
2559: return $datatable;
2560: }
2561:
2562: sub print_autocreate {
2563: my ($dom,$settings,$rowtotal) = @_;
2564: my (%createon,%createoff,%currhash);
2565: my @types = ('xml','req');
2566: if (ref($settings) eq 'HASH') {
2567: foreach my $item (@types) {
2568: $createoff{$item} = ' checked="checked" ';
2569: $createon{$item} = ' ';
2570: if (exists($settings->{$item})) {
2571: if ($settings->{$item}) {
2572: $createon{$item} = ' checked="checked" ';
2573: $createoff{$item} = ' ';
2574: }
2575: }
2576: }
2577: if ($settings->{'xmldc'} ne '') {
2578: $currhash{$settings->{'xmldc'}} = 1;
2579: }
2580: } else {
2581: foreach my $item (@types) {
2582: $createoff{$item} = ' checked="checked" ';
2583: $createon{$item} = ' ';
2584: }
2585: }
2586: $$rowtotal += 2;
2587: my $numinrow = 2;
2588: my $datatable='<tr class="LC_odd_row">'.
2589: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2590: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2591: '<input type="radio" name="autocreate_xml"'.
2592: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2593: '<label><input type="radio" name="autocreate_xml"'.
2594: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2595: '</td></tr><tr>'.
2596: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2597: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2598: '<input type="radio" name="autocreate_req"'.
2599: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2600: '<label><input type="radio" name="autocreate_req"'.
2601: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2602: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2603: 'autocreate_xmldc',%currhash);
2604: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
2605: if ($numdc > 1) {
2606: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2607: '</td><td class="LC_left_item">';
2608: } else {
2609: $datatable .= &mt('Course creation processed as:').
2610: '</td><td class="LC_right_item">';
2611: }
2612: $datatable .= $dctable.'</td></tr>';
2613: $$rowtotal += $rows;
2614: return $datatable;
2615: }
2616:
2617: sub print_directorysrch {
2618: my ($dom,$settings,$rowtotal) = @_;
2619: my $srchon = ' ';
2620: my $srchoff = ' checked="checked" ';
2621: my ($exacton,$containson,$beginson);
2622: my $localon = ' ';
2623: my $localoff = ' checked="checked" ';
2624: if (ref($settings) eq 'HASH') {
2625: if ($settings->{'available'} eq '1') {
2626: $srchon = $srchoff;
2627: $srchoff = ' ';
2628: }
2629: if ($settings->{'localonly'} eq '1') {
2630: $localon = $localoff;
2631: $localoff = ' ';
2632: }
2633: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2634: foreach my $type (@{$settings->{'searchtypes'}}) {
2635: if ($type eq 'exact') {
2636: $exacton = ' checked="checked" ';
2637: } elsif ($type eq 'contains') {
2638: $containson = ' checked="checked" ';
2639: } elsif ($type eq 'begins') {
2640: $beginson = ' checked="checked" ';
2641: }
2642: }
2643: } else {
2644: if ($settings->{'searchtypes'} eq 'exact') {
2645: $exacton = ' checked="checked" ';
2646: } elsif ($settings->{'searchtypes'} eq 'contains') {
2647: $containson = ' checked="checked" ';
2648: } elsif ($settings->{'searchtypes'} eq 'specify') {
2649: $exacton = ' checked="checked" ';
2650: $containson = ' checked="checked" ';
2651: }
2652: }
2653: }
2654: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2655: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2656:
2657: my $numinrow = 4;
2658: my $cansrchrow = 0;
2659: my $datatable='<tr class="LC_odd_row">'.
2660: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
2661: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2662: '<input type="radio" name="dirsrch_available"'.
2663: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2664: '<label><input type="radio" name="dirsrch_available"'.
2665: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2666: '</tr><tr>'.
2667: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
2668: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2669: '<input type="radio" name="dirsrch_localonly"'.
2670: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2671: '<label><input type="radio" name="dirsrch_localonly"'.
2672: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
2673: '</tr>';
2674: $$rowtotal += 2;
2675: if (ref($usertypes) eq 'HASH') {
2676: if (keys(%{$usertypes}) > 0) {
2677: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2678: $numinrow,$othertitle,'cansearch');
2679: $cansrchrow = 1;
2680: }
2681: }
2682: if ($cansrchrow) {
2683: $$rowtotal ++;
2684: $datatable .= '<tr>';
2685: } else {
2686: $datatable .= '<tr class="LC_odd_row">';
2687: }
2688: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2689: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2690: foreach my $title (@{$titleorder}) {
2691: if (defined($searchtitles->{$title})) {
2692: my $check = ' ';
2693: if (ref($settings) eq 'HASH') {
2694: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2695: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2696: $check = ' checked="checked" ';
2697: }
2698: }
2699: }
2700: $datatable .= '<td class="LC_left_item">'.
2701: '<span class="LC_nobreak"><label>'.
2702: '<input type="checkbox" name="searchby" '.
2703: 'value="'.$title.'"'.$check.'/>'.
2704: $searchtitles->{$title}.'</label></span></td>';
2705: }
2706: }
2707: $datatable .= '</tr></table></td></tr>';
2708: $$rowtotal ++;
2709: if ($cansrchrow) {
2710: $datatable .= '<tr class="LC_odd_row">';
2711: } else {
2712: $datatable .= '<tr>';
2713: }
2714: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2715: '<td class="LC_left_item" colspan="2">'.
2716: '<span class="LC_nobreak"><label>'.
2717: '<input type="checkbox" name="searchtypes" '.
2718: $exacton.' value="exact" />'.&mt('Exact match').
2719: '</label> '.
2720: '<label><input type="checkbox" name="searchtypes" '.
2721: $beginson.' value="begins" />'.&mt('Begins with').
2722: '</label> '.
2723: '<label><input type="checkbox" name="searchtypes" '.
2724: $containson.' value="contains" />'.&mt('Contains').
2725: '</label></span></td></tr>';
2726: $$rowtotal ++;
2727: return $datatable;
2728: }
2729:
2730: sub print_contacts {
2731: my ($dom,$settings,$rowtotal) = @_;
2732: my $datatable;
2733: my @contacts = ('adminemail','supportemail');
2734: my (%checked,%to,%otheremails,%bccemails);
2735: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2736: 'requestsmail','updatesmail','idconflictsmail');
2737: foreach my $type (@mailings) {
2738: $otheremails{$type} = '';
2739: }
2740: $bccemails{'helpdeskmail'} = '';
2741: if (ref($settings) eq 'HASH') {
2742: foreach my $item (@contacts) {
2743: if (exists($settings->{$item})) {
2744: $to{$item} = $settings->{$item};
2745: }
2746: }
2747: foreach my $type (@mailings) {
2748: if (exists($settings->{$type})) {
2749: if (ref($settings->{$type}) eq 'HASH') {
2750: foreach my $item (@contacts) {
2751: if ($settings->{$type}{$item}) {
2752: $checked{$type}{$item} = ' checked="checked" ';
2753: }
2754: }
2755: $otheremails{$type} = $settings->{$type}{'others'};
2756: if ($type eq 'helpdeskmail') {
2757: $bccemails{$type} = $settings->{$type}{'bcc'};
2758: }
2759: }
2760: } elsif ($type eq 'lonstatusmail') {
2761: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2762: }
2763: }
2764: } else {
2765: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2766: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2767: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2768: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2769: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2770: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2771: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2772: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2773: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2774: }
2775: my ($titles,$short_titles) = &contact_titles();
2776: my $rownum = 0;
2777: my $css_class;
2778: foreach my $item (@contacts) {
2779: $css_class = $rownum%2?' class="LC_odd_row"':'';
2780: $datatable .= '<tr'.$css_class.'>'.
2781: '<td><span class="LC_nobreak">'.$titles->{$item}.
2782: '</span></td><td class="LC_right_item">'.
2783: '<input type="text" name="'.$item.'" value="'.
2784: $to{$item}.'" /></td></tr>';
2785: $rownum ++;
2786: }
2787: foreach my $type (@mailings) {
2788: $css_class = $rownum%2?' class="LC_odd_row"':'';
2789: $datatable .= '<tr'.$css_class.'>'.
2790: '<td><span class="LC_nobreak">'.
2791: $titles->{$type}.': </span></td>'.
2792: '<td class="LC_left_item">'.
2793: '<span class="LC_nobreak">';
2794: foreach my $item (@contacts) {
2795: $datatable .= '<label>'.
2796: '<input type="checkbox" name="'.$type.'"'.
2797: $checked{$type}{$item}.
2798: ' value="'.$item.'" />'.$short_titles->{$item}.
2799: '</label> ';
2800: }
2801: $datatable .= '</span><br />'.&mt('Others').': '.
2802: '<input type="text" name="'.$type.'_others" '.
2803: 'value="'.$otheremails{$type}.'" />';
2804: if ($type eq 'helpdeskmail') {
2805: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2806: '<input type="text" name="'.$type.'_bcc" '.
2807: 'value="'.$bccemails{$type}.'" />';
2808: }
2809: $datatable .= '</td></tr>'."\n";
2810: $rownum ++;
2811: }
2812: my %choices;
2813: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2814: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2815: &mt('LON-CAPA core group - MSU'),600,500));
2816: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2817: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2818: &mt('LON-CAPA core group - MSU'),600,500));
2819: my @toggles = ('reporterrors','reportupdates');
2820: my %defaultchecked = ('reporterrors' => 'on',
2821: 'reportupdates' => 'on');
2822: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2823: \%choices,$rownum);
2824: $datatable .= $reports;
2825: $$rowtotal += $rownum;
2826: return $datatable;
2827: }
2828:
2829: sub print_helpsettings {
2830: my ($dom,$confname,$settings,$rowtotal) = @_;
2831: my ($datatable,$itemcount);
2832: $itemcount = 1;
2833: my (%choices,%defaultchecked,@toggles);
2834: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2835: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2836: &mt('LON-CAPA bug tracker'),600,500));
2837: %defaultchecked = ('submitbugs' => 'on');
2838: @toggles = ('submitbugs',);
2839:
2840: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2841: \%choices,$itemcount);
2842: return $datatable;
2843: }
2844:
2845: sub radiobutton_prefs {
2846: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2847: $additional,$align) = @_;
2848: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2849: (ref($choices) eq 'HASH'));
2850:
2851: my (%checkedon,%checkedoff,$datatable,$css_class);
2852:
2853: foreach my $item (@{$toggles}) {
2854: if ($defaultchecked->{$item} eq 'on') {
2855: $checkedon{$item} = ' checked="checked" ';
2856: $checkedoff{$item} = ' ';
2857: } elsif ($defaultchecked->{$item} eq 'off') {
2858: $checkedoff{$item} = ' checked="checked" ';
2859: $checkedon{$item} = ' ';
2860: }
2861: }
2862: if (ref($settings) eq 'HASH') {
2863: foreach my $item (@{$toggles}) {
2864: if ($settings->{$item} eq '1') {
2865: $checkedon{$item} = ' checked="checked" ';
2866: $checkedoff{$item} = ' ';
2867: } elsif ($settings->{$item} eq '0') {
2868: $checkedoff{$item} = ' checked="checked" ';
2869: $checkedon{$item} = ' ';
2870: }
2871: }
2872: }
2873: if ($onclick) {
2874: $onclick = ' onclick="'.$onclick.'"';
2875: }
2876: foreach my $item (@{$toggles}) {
2877: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2878: $datatable .=
2879: '<tr'.$css_class.'><td valign="top">'.
2880: '<span class="LC_nobreak">'.$choices->{$item}.
2881: '</span></td>';
2882: if ($align eq 'left') {
2883: $datatable .= '<td class="LC_left_item">';
2884: } else {
2885: $datatable .= '<td class="LC_right_item">';
2886: }
2887: $datatable .=
2888: '<span class="LC_nobreak">'.
2889: '<label><input type="radio" name="'.
2890: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
2891: '</label> <label><input type="radio" name="'.$item.'" '.
2892: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2893: '</span>'.$additional.
2894: '</td>'.
2895: '</tr>';
2896: $itemcount ++;
2897: }
2898: return ($datatable,$itemcount);
2899: }
2900:
2901: sub print_coursedefaults {
2902: my ($position,$dom,$settings,$rowtotal) = @_;
2903: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
2904: my $itemcount = 1;
2905: my %choices = &Apache::lonlocal::texthash (
2906: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2907: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
2908: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2909: coursecredits => 'Credits can be specified for courses',
2910: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
2911: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
2912: postsubmit => 'Disable submit button/keypress following student submission',
2913: );
2914: my %staticdefaults = (
2915: anonsurvey_threshold => 10,
2916: uploadquota => 500,
2917: postsubmit => 60,
2918: );
2919: if ($position eq 'top') {
2920: %defaultchecked = (
2921: 'canuse_pdfforms' => 'off',
2922: 'uselcmath' => 'on',
2923: 'usejsme' => 'on',
2924: );
2925: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
2926: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2927: \%choices,$itemcount);
2928: } else {
2929: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2930: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
2931: my $currusecredits = 0;
2932: my $postsubmitclient = 1;
2933: my @types = ('official','unofficial','community','textbook');
2934: if (ref($settings) eq 'HASH') {
2935: $currdefresponder = $settings->{'anonsurvey_threshold'};
2936: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2937: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2938: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2939: }
2940: }
2941: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2942: foreach my $type (@types) {
2943: next if ($type eq 'community');
2944: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
2945: if ($defcredits{$type} ne '') {
2946: $currusecredits = 1;
2947: }
2948: }
2949: }
2950: if (ref($settings->{'postsubmit'}) eq 'HASH') {
2951: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
2952: $postsubmitclient = 0;
2953: foreach my $type (@types) {
2954: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2955: }
2956: } else {
2957: foreach my $type (@types) {
2958: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
2959: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
2960: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
2961: } else {
2962: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2963: }
2964: } else {
2965: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2966: }
2967: }
2968: }
2969: } else {
2970: foreach my $type (@types) {
2971: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2972: }
2973: }
2974: } else {
2975: foreach my $type (@types) {
2976: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2977: }
2978: }
2979: if (!$currdefresponder) {
2980: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
2981: } elsif ($currdefresponder < 1) {
2982: $currdefresponder = 1;
2983: }
2984: foreach my $type (@types) {
2985: if ($curruploadquota{$type} eq '') {
2986: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2987: }
2988: }
2989: $datatable .=
2990: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2991: $choices{'anonsurvey_threshold'}.
2992: '</span></td>'.
2993: '<td class="LC_right_item"><span class="LC_nobreak">'.
2994: '<input type="text" name="anonsurvey_threshold"'.
2995: ' value="'.$currdefresponder.'" size="5" /></span>'.
2996: '</td></tr>'."\n";
2997: $itemcount ++;
2998: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2999: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3000: $choices{'uploadquota'}.
3001: '</span></td>'.
3002: '<td align="right" class="LC_right_item">'.
3003: '<table><tr>';
3004: foreach my $type (@types) {
3005: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3006: '<input type="text" name="uploadquota_'.$type.'"'.
3007: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3008: }
3009: $datatable .= '</tr></table></td></tr>'."\n";
3010: $itemcount ++;
3011: my $onclick = "toggleDisplay(this.form,'credits');";
3012: my $display = 'none';
3013: if ($currusecredits) {
3014: $display = 'block';
3015: }
3016: my $additional = '<div id="credits" style="display: '.$display.'">'.
3017: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3018: foreach my $type (@types) {
3019: next if ($type eq 'community');
3020: $additional .= '<td align="center">'.&mt($type).'<br />'.
3021: '<input type="text" name="'.$type.'_credits"'.
3022: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3023: }
3024: $additional .= '</tr></table></div>'."\n";
3025: %defaultchecked = ('coursecredits' => 'off');
3026: @toggles = ('coursecredits');
3027: my $current = {
3028: 'coursecredits' => $currusecredits,
3029: };
3030: (my $table,$itemcount) =
3031: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3032: \%choices,$itemcount,$onclick,$additional,'left');
3033: $datatable .= $table;
3034: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3035: my $display = 'none';
3036: if ($postsubmitclient) {
3037: $display = 'block';
3038: }
3039: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
3040: &mt('Number of seconds submit is disabled').'<br />'.
3041: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3042: '<table><tr>';
3043: foreach my $type (@types) {
3044: $additional .= '<td align="center">'.&mt($type).'<br />'.
3045: '<input type="text" name="'.$type.'_timeout" value="'.
3046: $deftimeout{$type}.'" size="5" /></td>';
3047: }
3048: $additional .= '</tr></table></div>'."\n";
3049: %defaultchecked = ('postsubmit' => 'on');
3050: @toggles = ('postsubmit');
3051: my $current = {
3052: 'postsubmit' => $postsubmitclient,
3053: };
3054: ($table,$itemcount) =
3055: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3056: \%choices,$itemcount,$onclick,$additional,'left');
3057: $datatable .= $table;
3058: }
3059: $$rowtotal += $itemcount;
3060: return $datatable;
3061: }
3062:
3063: sub print_selfenrollment {
3064: my ($position,$dom,$settings,$rowtotal) = @_;
3065: my ($css_class,$datatable);
3066: my $itemcount = 1;
3067: my @types = ('official','unofficial','community','textbook');
3068: if (($position eq 'top') || ($position eq 'middle')) {
3069: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3070: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3071: my @rows;
3072: my $key;
3073: if ($position eq 'top') {
3074: $key = 'admin';
3075: if (ref($rowsref) eq 'ARRAY') {
3076: @rows = @{$rowsref};
3077: }
3078: } elsif ($position eq 'middle') {
3079: $key = 'default';
3080: @rows = ('types','registered','approval','limit');
3081: }
3082: foreach my $row (@rows) {
3083: if (defined($titlesref->{$row})) {
3084: $itemcount ++;
3085: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3086: $datatable .= '<tr'.$css_class.'>'.
3087: '<td>'.$titlesref->{$row}.'</td>'.
3088: '<td class="LC_left_item">'.
3089: '<table><tr>';
3090: my (%current,%currentcap);
3091: if (ref($settings) eq 'HASH') {
3092: if (ref($settings->{$key}) eq 'HASH') {
3093: foreach my $type (@types) {
3094: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3095: $current{$type} = $settings->{$key}->{$type}->{$row};
3096: }
3097: if (($row eq 'limit') && ($key eq 'default')) {
3098: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3099: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3100: }
3101: }
3102: }
3103: }
3104: }
3105: my %roles = (
3106: '0' => &Apache::lonnet::plaintext('dc'),
3107: );
3108:
3109: foreach my $type (@types) {
3110: unless (($row eq 'registered') && ($key eq 'default')) {
3111: $datatable .= '<th>'.&mt($type).'</th>';
3112: }
3113: }
3114: unless (($row eq 'registered') && ($key eq 'default')) {
3115: $datatable .= '</tr><tr>';
3116: }
3117: foreach my $type (@types) {
3118: if ($type eq 'community') {
3119: $roles{'1'} = &mt('Community personnel');
3120: } else {
3121: $roles{'1'} = &mt('Course personnel');
3122: }
3123: $datatable .= '<td style="vertical-align: top">';
3124: if ($position eq 'top') {
3125: my %checked;
3126: if ($current{$type} eq '0') {
3127: $checked{'0'} = ' checked="checked"';
3128: } else {
3129: $checked{'1'} = ' checked="checked"';
3130: }
3131: foreach my $role ('1','0') {
3132: $datatable .= '<span class="LC_nobreak"><label>'.
3133: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3134: 'value="'.$role.'"'.$checked{$role}.' />'.
3135: $roles{$role}.'</label></span> ';
3136: }
3137: } else {
3138: if ($row eq 'types') {
3139: my %checked;
3140: if ($current{$type} =~ /^(all|dom)$/) {
3141: $checked{$1} = ' checked="checked"';
3142: } else {
3143: $checked{''} = ' checked="checked"';
3144: }
3145: foreach my $val ('','dom','all') {
3146: $datatable .= '<span class="LC_nobreak"><label>'.
3147: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3148: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3149: }
3150: } elsif ($row eq 'registered') {
3151: my %checked;
3152: if ($current{$type} eq '1') {
3153: $checked{'1'} = ' checked="checked"';
3154: } else {
3155: $checked{'0'} = ' checked="checked"';
3156: }
3157: foreach my $val ('0','1') {
3158: $datatable .= '<span class="LC_nobreak"><label>'.
3159: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3160: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3161: }
3162: } elsif ($row eq 'approval') {
3163: my %checked;
3164: if ($current{$type} =~ /^([12])$/) {
3165: $checked{$1} = ' checked="checked"';
3166: } else {
3167: $checked{'0'} = ' checked="checked"';
3168: }
3169: for my $val (0..2) {
3170: $datatable .= '<span class="LC_nobreak"><label>'.
3171: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3172: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3173: }
3174: } elsif ($row eq 'limit') {
3175: my %checked;
3176: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3177: $checked{$1} = ' checked="checked"';
3178: } else {
3179: $checked{'none'} = ' checked="checked"';
3180: }
3181: my $cap;
3182: if ($currentcap{$type} =~ /^\d+$/) {
3183: $cap = $currentcap{$type};
3184: }
3185: foreach my $val ('none','allstudents','selfenrolled') {
3186: $datatable .= '<span class="LC_nobreak"><label>'.
3187: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3188: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3189: }
3190: $datatable .= '<br />'.
3191: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3192: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3193: '</span>';
3194: }
3195: }
3196: $datatable .= '</td>';
3197: }
3198: $datatable .= '</tr>';
3199: }
3200: $datatable .= '</table></td></tr>';
3201: }
3202: } elsif ($position eq 'bottom') {
3203: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3204: }
3205: $$rowtotal += $itemcount;
3206: return $datatable;
3207: }
3208:
3209: sub print_validation_rows {
3210: my ($caller,$dom,$settings,$rowtotal) = @_;
3211: my ($itemsref,$namesref,$fieldsref);
3212: if ($caller eq 'selfenroll') {
3213: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3214: } elsif ($caller eq 'requestcourses') {
3215: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3216: }
3217: my %currvalidation;
3218: if (ref($settings) eq 'HASH') {
3219: if (ref($settings->{'validation'}) eq 'HASH') {
3220: %currvalidation = %{$settings->{'validation'}};
3221: }
3222: }
3223: my $datatable;
3224: my $itemcount = 0;
3225: foreach my $item (@{$itemsref}) {
3226: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3227: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3228: $namesref->{$item}.
3229: '</span></td>'.
3230: '<td class="LC_left_item">';
3231: if (($item eq 'url') || ($item eq 'button')) {
3232: $datatable .= '<span class="LC_nobreak">'.
3233: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3234: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3235: } elsif ($item eq 'fields') {
3236: my @currfields;
3237: if (ref($currvalidation{$item}) eq 'ARRAY') {
3238: @currfields = @{$currvalidation{$item}};
3239: }
3240: foreach my $field (@{$fieldsref}) {
3241: my $check = '';
3242: if (grep(/^\Q$field\E$/,@currfields)) {
3243: $check = ' checked="checked"';
3244: }
3245: $datatable .= '<span class="LC_nobreak"><label>'.
3246: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3247: ' value="'.$field.'"'.$check.' />'.$field.
3248: '</label></span> ';
3249: }
3250: } elsif ($item eq 'markup') {
3251: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3252: $currvalidation{$item}.
3253: '</textarea>';
3254: }
3255: $datatable .= '</td></tr>'."\n";
3256: if (ref($rowtotal)) {
3257: $itemcount ++;
3258: }
3259: }
3260: if ($caller eq 'requestcourses') {
3261: my %currhash;
3262: if (ref($settings) eq 'HASH') {
3263: if (ref($settings->{'validation'}) eq 'HASH') {
3264: if ($settings->{'validation'}{'dc'} ne '') {
3265: $currhash{$settings->{'validation'}{'dc'}} = 1;
3266: }
3267: }
3268: }
3269: my $numinrow = 2;
3270: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3271: 'validationdc',%currhash);
3272: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3273: $datatable .= '</td></tr><tr'.$css_class.'><td>';
3274: if ($numdc > 1) {
3275: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
3276: } else {
3277: $datatable .= &mt('Course creation processed as: ');
3278: }
3279: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3280: $itemcount ++;
3281: }
3282: if (ref($rowtotal)) {
3283: $$rowtotal += $itemcount;
3284: }
3285: return $datatable;
3286: }
3287:
3288: sub print_usersessions {
3289: my ($position,$dom,$settings,$rowtotal) = @_;
3290: my ($css_class,$datatable,%checked,%choices);
3291: my (%by_ip,%by_location,@intdoms);
3292: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
3293:
3294: my @alldoms = &Apache::lonnet::all_domains();
3295: my %serverhomes = %Apache::lonnet::serverhomeIDs;
3296: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3297: my %altids = &id_for_thisdom(%servers);
3298: my $itemcount = 1;
3299: if ($position eq 'top') {
3300: if (keys(%serverhomes) > 1) {
3301: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
3302: my $curroffloadnow;
3303: if (ref($settings) eq 'HASH') {
3304: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3305: $curroffloadnow = $settings->{'offloadnow'};
3306: }
3307: }
3308: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
3309: } else {
3310: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3311: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
3312: }
3313: } else {
3314: if (keys(%by_location) == 0) {
3315: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3316: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
3317: } else {
3318: my %lt = &usersession_titles();
3319: my $numinrow = 5;
3320: my $prefix;
3321: my @types;
3322: if ($position eq 'bottom') {
3323: $prefix = 'remote';
3324: @types = ('version','excludedomain','includedomain');
3325: } else {
3326: $prefix = 'hosted';
3327: @types = ('excludedomain','includedomain');
3328: }
3329: my (%current,%checkedon,%checkedoff);
3330: my @lcversions = &Apache::lonnet::all_loncaparevs();
3331: my @locations = sort(keys(%by_location));
3332: foreach my $type (@types) {
3333: $checkedon{$type} = '';
3334: $checkedoff{$type} = ' checked="checked"';
3335: }
3336: if (ref($settings) eq 'HASH') {
3337: if (ref($settings->{$prefix}) eq 'HASH') {
3338: foreach my $key (keys(%{$settings->{$prefix}})) {
3339: $current{$key} = $settings->{$prefix}{$key};
3340: if ($key eq 'version') {
3341: if ($current{$key} ne '') {
3342: $checkedon{$key} = ' checked="checked"';
3343: $checkedoff{$key} = '';
3344: }
3345: } elsif (ref($current{$key}) eq 'ARRAY') {
3346: $checkedon{$key} = ' checked="checked"';
3347: $checkedoff{$key} = '';
3348: }
3349: }
3350: }
3351: }
3352: foreach my $type (@types) {
3353: next if ($type ne 'version' && !@locations);
3354: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3355: $datatable .= '<tr'.$css_class.'>
3356: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3357: <span class="LC_nobreak">
3358: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3359: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3360: if ($type eq 'version') {
3361: my $selector = '<select name="'.$prefix.'_version">';
3362: foreach my $version (@lcversions) {
3363: my $selected = '';
3364: if ($current{'version'} eq $version) {
3365: $selected = ' selected="selected"';
3366: }
3367: $selector .= ' <option value="'.$version.'"'.
3368: $selected.'>'.$version.'</option>';
3369: }
3370: $selector .= '</select> ';
3371: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3372: } else {
3373: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3374: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3375: ' />'.(' 'x2).
3376: '<input type="button" value="'.&mt('uncheck all').'" '.
3377: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3378: "\n".
3379: '</div><div><table>';
3380: my $rem;
3381: for (my $i=0; $i<@locations; $i++) {
3382: my ($showloc,$value,$checkedtype);
3383: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3384: my $ip = $by_location{$locations[$i]}->[0];
3385: if (ref($by_ip{$ip}) eq 'ARRAY') {
3386: $value = join(':',@{$by_ip{$ip}});
3387: $showloc = join(', ',@{$by_ip{$ip}});
3388: if (ref($current{$type}) eq 'ARRAY') {
3389: foreach my $loc (@{$by_ip{$ip}}) {
3390: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3391: $checkedtype = ' checked="checked"';
3392: last;
3393: }
3394: }
3395: }
3396: }
3397: }
3398: $rem = $i%($numinrow);
3399: if ($rem == 0) {
3400: if ($i > 0) {
3401: $datatable .= '</tr>';
3402: }
3403: $datatable .= '<tr>';
3404: }
3405: $datatable .= '<td class="LC_left_item">'.
3406: '<span class="LC_nobreak"><label>'.
3407: '<input type="checkbox" name="'.$prefix.'_'.$type.
3408: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3409: '</label></span></td>';
3410: }
3411: $rem = @locations%($numinrow);
3412: my $colsleft = $numinrow - $rem;
3413: if ($colsleft > 1 ) {
3414: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3415: ' </td>';
3416: } elsif ($colsleft == 1) {
3417: $datatable .= '<td class="LC_left_item"> </td>';
3418: }
3419: $datatable .= '</tr></table>';
3420: }
3421: $datatable .= '</td></tr>';
3422: $itemcount ++;
3423: }
3424: }
3425: }
3426: $$rowtotal += $itemcount;
3427: return $datatable;
3428: }
3429:
3430: sub build_location_hashes {
3431: my ($intdoms,$by_ip,$by_location) = @_;
3432: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3433: (ref($by_location) eq 'HASH'));
3434: my %iphost = &Apache::lonnet::get_iphost();
3435: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3436: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3437: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3438: foreach my $id (@{$iphost{$primary_ip}}) {
3439: my $intdom = &Apache::lonnet::internet_dom($id);
3440: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3441: push(@{$intdoms},$intdom);
3442: }
3443: }
3444: }
3445: foreach my $ip (keys(%iphost)) {
3446: if (ref($iphost{$ip}) eq 'ARRAY') {
3447: foreach my $id (@{$iphost{$ip}}) {
3448: my $location = &Apache::lonnet::internet_dom($id);
3449: if ($location) {
3450: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3451: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3452: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3453: push(@{$by_ip->{$ip}},$location);
3454: }
3455: } else {
3456: $by_ip->{$ip} = [$location];
3457: }
3458: }
3459: }
3460: }
3461: }
3462: foreach my $ip (sort(keys(%{$by_ip}))) {
3463: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3464: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3465: my $first = $by_ip->{$ip}->[0];
3466: if (ref($by_location->{$first}) eq 'ARRAY') {
3467: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3468: push(@{$by_location->{$first}},$ip);
3469: }
3470: } else {
3471: $by_location->{$first} = [$ip];
3472: }
3473: }
3474: }
3475: return;
3476: }
3477:
3478: sub current_offloads_to {
3479: my ($dom,$settings,$servers) = @_;
3480: my (%spareid,%otherdomconfigs);
3481: if (ref($servers) eq 'HASH') {
3482: foreach my $lonhost (sort(keys(%{$servers}))) {
3483: my $gotspares;
3484: if (ref($settings) eq 'HASH') {
3485: if (ref($settings->{'spares'}) eq 'HASH') {
3486: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3487: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3488: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3489: $gotspares = 1;
3490: }
3491: }
3492: }
3493: unless ($gotspares) {
3494: my $gotspares;
3495: my $serverhomeID =
3496: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3497: my $serverhomedom =
3498: &Apache::lonnet::host_domain($serverhomeID);
3499: if ($serverhomedom ne $dom) {
3500: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3501: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3502: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3503: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3504: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3505: $gotspares = 1;
3506: }
3507: }
3508: } else {
3509: $otherdomconfigs{$serverhomedom} =
3510: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3511: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3512: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3513: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3514: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3515: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3516: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3517: $gotspares = 1;
3518: }
3519: }
3520: }
3521: }
3522: }
3523: }
3524: }
3525: unless ($gotspares) {
3526: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3527: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3528: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3529: } else {
3530: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3531: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3532: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3533: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3534: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3535: } else {
3536: my %what = (
3537: spareid => 1,
3538: );
3539: my ($result,$returnhash) =
3540: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3541: if ($result eq 'ok') {
3542: if (ref($returnhash) eq 'HASH') {
3543: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3544: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3545: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3546: }
3547: }
3548: }
3549: }
3550: }
3551: }
3552: }
3553: }
3554: return %spareid;
3555: }
3556:
3557: sub spares_row {
3558: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
3559: my $css_class;
3560: my $numinrow = 4;
3561: my $itemcount = 1;
3562: my $datatable;
3563: my %typetitles = &sparestype_titles();
3564: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
3565: foreach my $server (sort(keys(%{$servers}))) {
3566: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3567: my ($othercontrol,$serverdom);
3568: if ($serverhome ne $server) {
3569: $serverdom = &Apache::lonnet::host_domain($serverhome);
3570: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3571: } else {
3572: $serverdom = &Apache::lonnet::host_domain($server);
3573: if ($serverdom ne $dom) {
3574: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3575: }
3576: }
3577: next unless (ref($spareid->{$server}) eq 'HASH');
3578: my $checkednow;
3579: if (ref($curroffloadnow) eq 'HASH') {
3580: if ($curroffloadnow->{$server}) {
3581: $checkednow = ' checked="checked"';
3582: }
3583: }
3584: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3585: $datatable .= '<tr'.$css_class.'>
3586: <td rowspan="2">
3587: <span class="LC_nobreak">'.
3588: &mt('[_1] when busy, offloads to:'
3589: ,'<b>'.$server.'</b>').'</span><br />'.
3590: '<span class="LC_nobreak">'."\n".
3591: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
3592: ' '.&mt('Switch active users on next access').'</label></span>'.
3593: "\n";
3594: my (%current,%canselect);
3595: my @choices =
3596: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3597: foreach my $type ('primary','default') {
3598: if (ref($spareid->{$server}) eq 'HASH') {
3599: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3600: my @spares = @{$spareid->{$server}{$type}};
3601: if (@spares > 0) {
3602: if ($othercontrol) {
3603: $current{$type} = join(', ',@spares);
3604: } else {
3605: $current{$type} .= '<table>';
3606: my $numspares = scalar(@spares);
3607: for (my $i=0; $i<@spares; $i++) {
3608: my $rem = $i%($numinrow);
3609: if ($rem == 0) {
3610: if ($i > 0) {
3611: $current{$type} .= '</tr>';
3612: }
3613: $current{$type} .= '<tr>';
3614: }
3615: $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'".');" /> '.
3616: $spareid->{$server}{$type}[$i].
3617: '</label></td>'."\n";
3618: }
3619: my $rem = @spares%($numinrow);
3620: my $colsleft = $numinrow - $rem;
3621: if ($colsleft > 1 ) {
3622: $current{$type} .= '<td colspan="'.$colsleft.
3623: '" class="LC_left_item">'.
3624: ' </td>';
3625: } elsif ($colsleft == 1) {
3626: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
3627: }
3628: $current{$type} .= '</tr></table>';
3629: }
3630: }
3631: }
3632: if ($current{$type} eq '') {
3633: $current{$type} = &mt('None specified');
3634: }
3635: if ($othercontrol) {
3636: if ($type eq 'primary') {
3637: $canselect{$type} = $othercontrol;
3638: }
3639: } else {
3640: $canselect{$type} =
3641: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3642: '<select name="newspare_'.$type.'_'.$server.'" '.
3643: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3644: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3645: if (@choices > 0) {
3646: foreach my $lonhost (@choices) {
3647: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3648: }
3649: }
3650: $canselect{$type} .= '</select>'."\n";
3651: }
3652: } else {
3653: $current{$type} = &mt('Could not be determined');
3654: if ($type eq 'primary') {
3655: $canselect{$type} = $othercontrol;
3656: }
3657: }
3658: if ($type eq 'default') {
3659: $datatable .= '<tr'.$css_class.'>';
3660: }
3661: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3662: '<td>'.$current{$type}.'</td>'."\n".
3663: '<td>'.$canselect{$type}.'</td></tr>'."\n";
3664: }
3665: $itemcount ++;
3666: }
3667: }
3668: $$rowtotal += $itemcount;
3669: return $datatable;
3670: }
3671:
3672: sub possible_newspares {
3673: my ($server,$currspares,$serverhomes,$altids) = @_;
3674: my $serverhostname = &Apache::lonnet::hostname($server);
3675: my %excluded;
3676: if ($serverhostname ne '') {
3677: %excluded = (
3678: $serverhostname => 1,
3679: );
3680: }
3681: if (ref($currspares) eq 'HASH') {
3682: foreach my $type (keys(%{$currspares})) {
3683: if (ref($currspares->{$type}) eq 'ARRAY') {
3684: if (@{$currspares->{$type}} > 0) {
3685: foreach my $curr (@{$currspares->{$type}}) {
3686: my $hostname = &Apache::lonnet::hostname($curr);
3687: $excluded{$hostname} = 1;
3688: }
3689: }
3690: }
3691: }
3692: }
3693: my @choices;
3694: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3695: if (keys(%{$serverhomes}) > 1) {
3696: foreach my $name (sort(keys(%{$serverhomes}))) {
3697: unless ($excluded{$name}) {
3698: if (exists($altids->{$serverhomes->{$name}})) {
3699: push(@choices,$altids->{$serverhomes->{$name}});
3700: } else {
3701: push(@choices,$serverhomes->{$name});
3702: }
3703: }
3704: }
3705: }
3706: }
3707: return sort(@choices);
3708: }
3709:
3710: sub print_loadbalancing {
3711: my ($dom,$settings,$rowtotal) = @_;
3712: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3713: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3714: my $numinrow = 1;
3715: my $datatable;
3716: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3717: my (%currbalancer,%currtargets,%currrules,%existing);
3718: if (ref($settings) eq 'HASH') {
3719: %existing = %{$settings};
3720: }
3721: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3722: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3723: \%currtargets,\%currrules);
3724: } else {
3725: return;
3726: }
3727: my ($othertitle,$usertypes,$types) =
3728: &Apache::loncommon::sorted_inst_types($dom);
3729: my $rownum = 8;
3730: if (ref($types) eq 'ARRAY') {
3731: $rownum += scalar(@{$types});
3732: }
3733: my @css_class = ('LC_odd_row','LC_even_row');
3734: my $balnum = 0;
3735: my $islast;
3736: my (@toshow,$disabledtext);
3737: if (keys(%currbalancer) > 0) {
3738: @toshow = sort(keys(%currbalancer));
3739: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3740: push(@toshow,'');
3741: }
3742: } else {
3743: @toshow = ('');
3744: $disabledtext = &mt('No existing load balancer');
3745: }
3746: foreach my $lonhost (@toshow) {
3747: if ($balnum == scalar(@toshow)-1) {
3748: $islast = 1;
3749: } else {
3750: $islast = 0;
3751: }
3752: my $cssidx = $balnum%2;
3753: my $targets_div_style = 'display: none';
3754: my $disabled_div_style = 'display: block';
3755: my $homedom_div_style = 'display: none';
3756: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3757: '<td rowspan="'.$rownum.'" valign="top">'.
3758: '<p>';
3759: if ($lonhost eq '') {
3760: $datatable .= '<span class="LC_nobreak">';
3761: if (keys(%currbalancer) > 0) {
3762: $datatable .= &mt('Add balancer:');
3763: } else {
3764: $datatable .= &mt('Enable balancer:');
3765: }
3766: $datatable .= ' '.
3767: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3768: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3769: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3770: '<option value="" selected="selected">'.&mt('None').
3771: '</option>'."\n";
3772: foreach my $server (sort(keys(%servers))) {
3773: next if ($currbalancer{$server});
3774: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3775: }
3776: $datatable .=
3777: '</select>'."\n".
3778: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3779: } else {
3780: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3781: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3782: &mt('Stop balancing').'</label>'.
3783: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3784: $targets_div_style = 'display: block';
3785: $disabled_div_style = 'display: none';
3786: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3787: $homedom_div_style = 'display: block';
3788: }
3789: }
3790: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3791: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3792: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3793: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3794: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3795: my @sparestypes = ('primary','default');
3796: my %typetitles = &sparestype_titles();
3797: foreach my $sparetype (@sparestypes) {
3798: my $targettable;
3799: for (my $i=0; $i<$numspares; $i++) {
3800: my $checked;
3801: if (ref($currtargets{$lonhost}) eq 'HASH') {
3802: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3803: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3804: $checked = ' checked="checked"';
3805: }
3806: }
3807: }
3808: my ($chkboxval,$disabled);
3809: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3810: $chkboxval = $spares[$i];
3811: }
3812: if (exists($currbalancer{$spares[$i]})) {
3813: $disabled = ' disabled="disabled"';
3814: }
3815: $targettable .=
3816: '<td><span class="LC_nobreak"><label>'.
3817: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3818: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3819: '</span></label></span></td>';
3820: my $rem = $i%($numinrow);
3821: if ($rem == 0) {
3822: if (($i > 0) && ($i < $numspares-1)) {
3823: $targettable .= '</tr>';
3824: }
3825: if ($i < $numspares-1) {
3826: $targettable .= '<tr>';
3827: }
3828: }
3829: }
3830: if ($targettable ne '') {
3831: my $rem = $numspares%($numinrow);
3832: my $colsleft = $numinrow - $rem;
3833: if ($colsleft > 1 ) {
3834: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3835: ' </td>';
3836: } elsif ($colsleft == 1) {
3837: $targettable .= '<td class="LC_left_item"> </td>';
3838: }
3839: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3840: '<table><tr>'.$targettable.'</tr></table><br />';
3841: }
3842: }
3843: $datatable .= '</div></td></tr>'.
3844: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3845: $othertitle,$usertypes,$types,\%servers,
3846: \%currbalancer,$lonhost,
3847: $targets_div_style,$homedom_div_style,
3848: $css_class[$cssidx],$balnum,$islast);
3849: $$rowtotal += $rownum;
3850: $balnum ++;
3851: }
3852: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3853: return $datatable;
3854: }
3855:
3856: sub get_loadbalancers_config {
3857: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3858: return unless ((ref($servers) eq 'HASH') &&
3859: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3860: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3861: if (keys(%{$existing}) > 0) {
3862: my $oldlonhost;
3863: foreach my $key (sort(keys(%{$existing}))) {
3864: if ($key eq 'lonhost') {
3865: $oldlonhost = $existing->{'lonhost'};
3866: $currbalancer->{$oldlonhost} = 1;
3867: } elsif ($key eq 'targets') {
3868: if ($oldlonhost) {
3869: $currtargets->{$oldlonhost} = $existing->{'targets'};
3870: }
3871: } elsif ($key eq 'rules') {
3872: if ($oldlonhost) {
3873: $currrules->{$oldlonhost} = $existing->{'rules'};
3874: }
3875: } elsif (ref($existing->{$key}) eq 'HASH') {
3876: $currbalancer->{$key} = 1;
3877: $currtargets->{$key} = $existing->{$key}{'targets'};
3878: $currrules->{$key} = $existing->{$key}{'rules'};
3879: }
3880: }
3881: } else {
3882: my ($balancerref,$targetsref) =
3883: &Apache::lonnet::get_lonbalancer_config($servers);
3884: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3885: foreach my $server (sort(keys(%{$balancerref}))) {
3886: $currbalancer->{$server} = 1;
3887: $currtargets->{$server} = $targetsref->{$server};
3888: }
3889: }
3890: }
3891: return;
3892: }
3893:
3894: sub loadbalancing_rules {
3895: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
3896: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3897: $css_class,$balnum,$islast) = @_;
3898: my $output;
3899: my $num = 0;
3900: my ($alltypes,$othertypes,$titles) =
3901: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3902: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3903: foreach my $type (@{$alltypes}) {
3904: $num ++;
3905: my $current;
3906: if (ref($currrules) eq 'HASH') {
3907: $current = $currrules->{$type};
3908: }
3909: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3910: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
3911: $current = '';
3912: }
3913: }
3914: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
3915: $servers,$currbalancer,$lonhost,$dom,
3916: $targets_div_style,$homedom_div_style,
3917: $css_class,$balnum,$num,$islast);
3918: }
3919: }
3920: return $output;
3921: }
3922:
3923: sub loadbalancing_titles {
3924: my ($dom,$intdom,$usertypes,$types) = @_;
3925: my %othertypes = (
3926: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3927: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3928: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3929: '_LC_external' => &mt('Users not from [_1]',$intdom),
3930: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3931: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
3932: );
3933: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
3934: if (ref($types) eq 'ARRAY') {
3935: unshift(@alltypes,@{$types},'default');
3936: }
3937: my %titles;
3938: foreach my $type (@alltypes) {
3939: if ($type =~ /^_LC_/) {
3940: $titles{$type} = $othertypes{$type};
3941: } elsif ($type eq 'default') {
3942: $titles{$type} = &mt('All users from [_1]',$dom);
3943: if (ref($types) eq 'ARRAY') {
3944: if (@{$types} > 0) {
3945: $titles{$type} = &mt('Other users from [_1]',$dom);
3946: }
3947: }
3948: } elsif (ref($usertypes) eq 'HASH') {
3949: $titles{$type} = $usertypes->{$type};
3950: }
3951: }
3952: return (\@alltypes,\%othertypes,\%titles);
3953: }
3954:
3955: sub loadbalance_rule_row {
3956: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3957: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
3958: my @rulenames;
3959: my %ruletitles = &offloadtype_text();
3960: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3961: @rulenames = ('balancer','offloadedto','specific');
3962: } else {
3963: @rulenames = ('default','homeserver');
3964: if ($type eq '_LC_external') {
3965: push(@rulenames,'externalbalancer');
3966: } else {
3967: push(@rulenames,'specific');
3968: }
3969: push(@rulenames,'none');
3970: }
3971: my $style = $targets_div_style;
3972: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3973: $style = $homedom_div_style;
3974: }
3975: my $space;
3976: if ($islast && $num == 1) {
3977: $space = '<div display="inline-block"> </div>';
3978: }
3979: my $output =
3980: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3981: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3982: '<td valaign="top">'.$space.
3983: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
3984: for (my $i=0; $i<@rulenames; $i++) {
3985: my $rule = $rulenames[$i];
3986: my ($checked,$extra);
3987: if ($rulenames[$i] eq 'default') {
3988: $rule = '';
3989: }
3990: if ($rulenames[$i] eq 'specific') {
3991: if (ref($servers) eq 'HASH') {
3992: my $default;
3993: if (($current ne '') && (exists($servers->{$current}))) {
3994: $checked = ' checked="checked"';
3995: }
3996: unless ($checked) {
3997: $default = ' selected="selected"';
3998: }
3999: $extra =
4000: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4001: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4002: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4003: '<option value=""'.$default.'></option>'."\n";
4004: foreach my $server (sort(keys(%{$servers}))) {
4005: if (ref($currbalancer) eq 'HASH') {
4006: next if (exists($currbalancer->{$server}));
4007: }
4008: my $selected;
4009: if ($server eq $current) {
4010: $selected = ' selected="selected"';
4011: }
4012: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
4013: }
4014: $extra .= '</select>';
4015: }
4016: } elsif ($rule eq $current) {
4017: $checked = ' checked="checked"';
4018: }
4019: $output .= '<span class="LC_nobreak"><label>'.
4020: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4021: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4022: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
4023: ')"'.$checked.' /> ';
4024: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4025: $output .= $ruletitles{'particular'};
4026: } else {
4027: $output .= $ruletitles{$rulenames[$i]};
4028: }
4029: $output .= '</label>'.$extra.'</span><br />'."\n";
4030: }
4031: $output .= '</div></td></tr>'."\n";
4032: return $output;
4033: }
4034:
4035: sub offloadtype_text {
4036: my %ruletitles = &Apache::lonlocal::texthash (
4037: 'default' => 'Offloads to default destinations',
4038: 'homeserver' => "Offloads to user's home server",
4039: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4040: 'specific' => 'Offloads to specific server',
4041: 'none' => 'No offload',
4042: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4043: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
4044: 'particular' => 'Session hosted (after re-auth) on server:',
4045: );
4046: return %ruletitles;
4047: }
4048:
4049: sub sparestype_titles {
4050: my %typestitles = &Apache::lonlocal::texthash (
4051: 'primary' => 'primary',
4052: 'default' => 'default',
4053: );
4054: return %typestitles;
4055: }
4056:
4057: sub contact_titles {
4058: my %titles = &Apache::lonlocal::texthash (
4059: 'supportemail' => 'Support E-mail address',
4060: 'adminemail' => 'Default Server Admin E-mail address',
4061: 'errormail' => 'Error reports to be e-mailed to',
4062: 'packagesmail' => 'Package update alerts to be e-mailed to',
4063: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4064: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4065: 'requestsmail' => 'E-mail from course requests requiring approval',
4066: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
4067: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
4068: );
4069: my %short_titles = &Apache::lonlocal::texthash (
4070: adminemail => 'Admin E-mail address',
4071: supportemail => 'Support E-mail',
4072: );
4073: return (\%titles,\%short_titles);
4074: }
4075:
4076: sub tool_titles {
4077: my %titles = &Apache::lonlocal::texthash (
4078: aboutme => 'Personal web page',
4079: blog => 'Blog',
4080: webdav => 'WebDAV',
4081: portfolio => 'Portfolio',
4082: official => 'Official courses (with institutional codes)',
4083: unofficial => 'Unofficial courses',
4084: community => 'Communities',
4085: textbook => 'Textbook courses',
4086: );
4087: return %titles;
4088: }
4089:
4090: sub courserequest_titles {
4091: my %titles = &Apache::lonlocal::texthash (
4092: official => 'Official',
4093: unofficial => 'Unofficial',
4094: community => 'Communities',
4095: textbook => 'Textbook',
4096: norequest => 'Not allowed',
4097: approval => 'Approval by Dom. Coord.',
4098: validate => 'With validation',
4099: autolimit => 'Numerical limit',
4100: unlimited => '(blank for unlimited)',
4101: );
4102: return %titles;
4103: }
4104:
4105: sub authorrequest_titles {
4106: my %titles = &Apache::lonlocal::texthash (
4107: norequest => 'Not allowed',
4108: approval => 'Approval by Dom. Coord.',
4109: automatic => 'Automatic approval',
4110: );
4111: return %titles;
4112: }
4113:
4114: sub courserequest_conditions {
4115: my %conditions = &Apache::lonlocal::texthash (
4116: approval => '(Processing of request subject to approval by Domain Coordinator).',
4117: validate => '(Processing of request subject to institutional validation).',
4118: );
4119: return %conditions;
4120: }
4121:
4122:
4123: sub print_usercreation {
4124: my ($position,$dom,$settings,$rowtotal) = @_;
4125: my $numinrow = 4;
4126: my $datatable;
4127: if ($position eq 'top') {
4128: $$rowtotal ++;
4129: my $rowcount = 0;
4130: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
4131: if (ref($rules) eq 'HASH') {
4132: if (keys(%{$rules}) > 0) {
4133: $datatable .= &user_formats_row('username',$settings,$rules,
4134: $ruleorder,$numinrow,$rowcount);
4135: $$rowtotal ++;
4136: $rowcount ++;
4137: }
4138: }
4139: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4140: if (ref($idrules) eq 'HASH') {
4141: if (keys(%{$idrules}) > 0) {
4142: $datatable .= &user_formats_row('id',$settings,$idrules,
4143: $idruleorder,$numinrow,$rowcount);
4144: $$rowtotal ++;
4145: $rowcount ++;
4146: }
4147: }
4148: if ($rowcount == 0) {
4149: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4150: $$rowtotal ++;
4151: $rowcount ++;
4152: }
4153: } elsif ($position eq 'middle') {
4154: my @creators = ('author','course','requestcrs');
4155: my ($rules,$ruleorder) =
4156: &Apache::lonnet::inst_userrules($dom,'username');
4157: my %lt = &usercreation_types();
4158: my %checked;
4159: if (ref($settings) eq 'HASH') {
4160: if (ref($settings->{'cancreate'}) eq 'HASH') {
4161: foreach my $item (@creators) {
4162: $checked{$item} = $settings->{'cancreate'}{$item};
4163: }
4164: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4165: foreach my $item (@creators) {
4166: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4167: $checked{$item} = 'none';
4168: }
4169: }
4170: }
4171: }
4172: my $rownum = 0;
4173: foreach my $item (@creators) {
4174: $rownum ++;
4175: if ($checked{$item} eq '') {
4176: $checked{$item} = 'any';
4177: }
4178: my $css_class;
4179: if ($rownum%2) {
4180: $css_class = '';
4181: } else {
4182: $css_class = ' class="LC_odd_row" ';
4183: }
4184: $datatable .= '<tr'.$css_class.'>'.
4185: '<td><span class="LC_nobreak">'.$lt{$item}.
4186: '</span></td><td align="right">';
4187: my @options = ('any');
4188: if (ref($rules) eq 'HASH') {
4189: if (keys(%{$rules}) > 0) {
4190: push(@options,('official','unofficial'));
4191: }
4192: }
4193: push(@options,'none');
4194: foreach my $option (@options) {
4195: my $type = 'radio';
4196: my $check = ' ';
4197: if ($checked{$item} eq $option) {
4198: $check = ' checked="checked" ';
4199: }
4200: $datatable .= '<span class="LC_nobreak"><label>'.
4201: '<input type="'.$type.'" name="can_createuser_'.
4202: $item.'" value="'.$option.'"'.$check.'/> '.
4203: $lt{$option}.'</label> </span>';
4204: }
4205: $datatable .= '</td></tr>';
4206: }
4207: } else {
4208: my @contexts = ('author','course','domain');
4209: my @authtypes = ('int','krb4','krb5','loc');
4210: my %checked;
4211: if (ref($settings) eq 'HASH') {
4212: if (ref($settings->{'authtypes'}) eq 'HASH') {
4213: foreach my $item (@contexts) {
4214: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4215: foreach my $auth (@authtypes) {
4216: if ($settings->{'authtypes'}{$item}{$auth}) {
4217: $checked{$item}{$auth} = ' checked="checked" ';
4218: }
4219: }
4220: }
4221: }
4222: }
4223: } else {
4224: foreach my $item (@contexts) {
4225: foreach my $auth (@authtypes) {
4226: $checked{$item}{$auth} = ' checked="checked" ';
4227: }
4228: }
4229: }
4230: my %title = &context_names();
4231: my %authname = &authtype_names();
4232: my $rownum = 0;
4233: my $css_class;
4234: foreach my $item (@contexts) {
4235: if ($rownum%2) {
4236: $css_class = '';
4237: } else {
4238: $css_class = ' class="LC_odd_row" ';
4239: }
4240: $datatable .= '<tr'.$css_class.'>'.
4241: '<td>'.$title{$item}.
4242: '</td><td class="LC_left_item">'.
4243: '<span class="LC_nobreak">';
4244: foreach my $auth (@authtypes) {
4245: $datatable .= '<label>'.
4246: '<input type="checkbox" name="'.$item.'_auth" '.
4247: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4248: $authname{$auth}.'</label> ';
4249: }
4250: $datatable .= '</span></td></tr>';
4251: $rownum ++;
4252: }
4253: $$rowtotal += $rownum;
4254: }
4255: return $datatable;
4256: }
4257:
4258: sub print_selfcreation {
4259: my ($position,$dom,$settings,$rowtotal) = @_;
4260: my (@selfcreate,$createsettings,$processing,$datatable);
4261: if (ref($settings) eq 'HASH') {
4262: if (ref($settings->{'cancreate'}) eq 'HASH') {
4263: $createsettings = $settings->{'cancreate'};
4264: if (ref($createsettings) eq 'HASH') {
4265: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4266: @selfcreate = @{$createsettings->{'selfcreate'}};
4267: } elsif ($createsettings->{'selfcreate'} ne '') {
4268: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4269: @selfcreate = ('email','login','sso');
4270: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4271: @selfcreate = ($createsettings->{'selfcreate'});
4272: }
4273: }
4274: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4275: $processing = $createsettings->{'selfcreateprocessing'};
4276: }
4277: }
4278: }
4279: }
4280: my %radiohash;
4281: my $numinrow = 4;
4282: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4283: if ($position eq 'top') {
4284: my %choices = &Apache::lonlocal::texthash (
4285: cancreate_login => 'Institutional Login',
4286: cancreate_sso => 'Institutional Single Sign On',
4287: );
4288: my @toggles = sort(keys(%choices));
4289: my %defaultchecked = (
4290: 'cancreate_login' => 'off',
4291: 'cancreate_sso' => 'off',
4292: );
4293: my ($onclick,$itemcount);
4294: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4295: \%choices,$itemcount,$onclick);
4296: $$rowtotal += $itemcount;
4297:
4298: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4299:
4300: if (ref($usertypes) eq 'HASH') {
4301: if (keys(%{$usertypes}) > 0) {
4302: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4303: $dom,$numinrow,$othertitle,
4304: 'statustocreate',$$rowtotal);
4305: $$rowtotal ++;
4306: }
4307: }
4308: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4309: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4310: $fieldtitles{'inststatus'} = &mt('Institutional status');
4311: my $rem;
4312: my $numperrow = 2;
4313: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4314: $datatable .= '<tr'.$css_class.'>'.
4315: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
4316: '<td class="LC_left_item">'."\n".
4317: '<table><tr><td>'."\n";
4318: for (my $i=0; $i<@fields; $i++) {
4319: $rem = $i%($numperrow);
4320: if ($rem == 0) {
4321: if ($i > 0) {
4322: $datatable .= '</tr>';
4323: }
4324: $datatable .= '<tr>';
4325: }
4326: my $currval;
4327: if (ref($createsettings) eq 'HASH') {
4328: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4329: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4330: }
4331: }
4332: $datatable .= '<td class="LC_left_item">'.
4333: '<span class="LC_nobreak">'.
4334: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4335: 'value="'.$currval.'" size="10" /> '.
4336: $fieldtitles{$fields[$i]}.'</span></td>';
4337: }
4338: my $colsleft = $numperrow - $rem;
4339: if ($colsleft > 1 ) {
4340: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4341: ' </td>';
4342: } elsif ($colsleft == 1) {
4343: $datatable .= '<td class="LC_left_item"> </td>';
4344: }
4345: $datatable .= '</tr></table></td></tr>';
4346: $$rowtotal ++;
4347: } elsif ($position eq 'middle') {
4348: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4349: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4350: $usertypes->{'default'} = $othertitle;
4351: if (ref($types) eq 'ARRAY') {
4352: push(@{$types},'default');
4353: $usertypes->{'default'} = $othertitle;
4354: foreach my $status (@{$types}) {
4355: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
4356: $numinrow,$$rowtotal,$usertypes);
4357: $$rowtotal ++;
4358: }
4359: }
4360: } else {
4361: my %choices = &Apache::lonlocal::texthash (
4362: cancreate_email => 'E-mail address as username',
4363: );
4364: my @toggles = sort(keys(%choices));
4365: my %defaultchecked = (
4366: 'cancreate_email' => 'off',
4367: );
4368: my $itemcount = 0;
4369: my $display = 'none';
4370: if (grep(/^\Qemail\E$/,@selfcreate)) {
4371: $display = 'block';
4372: }
4373: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4374: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4375: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4376: my $usertypes = {};
4377: my $order = [];
4378: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4379: $usertypes = $domdefaults{'inststatustypes'};
4380: $order = $domdefaults{'inststatusguest'};
4381: }
4382: if (ref($order) eq 'ARRAY') {
4383: push(@{$order},'default');
4384: if (@{$order} > 1) {
4385: $usertypes->{'default'} = &mt('Other users');
4386: $additional .= '<table><tr>';
4387: foreach my $status (@{$order}) {
4388: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4389: }
4390: $additional .= '</tr><tr>';
4391: foreach my $status (@{$order}) {
4392: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
4393: }
4394: $additional .= '</tr></table>';
4395: } else {
4396: $usertypes->{'default'} = &mt('All users');
4397: $additional .= &email_as_username($rowtotal,$processing);
4398: }
4399: }
4400: $additional .= '</div>'."\n";
4401:
4402: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4403: \%choices,$$rowtotal,$onclick,$additional);
4404: $$rowtotal ++;
4405: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
4406: $$rowtotal ++;
4407: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4408: $numinrow = 1;
4409: if (ref($order) eq 'ARRAY') {
4410: foreach my $status (@{$order}) {
4411: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4412: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4413: $$rowtotal ++;
4414: }
4415: }
4416: my ($emailrules,$emailruleorder) =
4417: &Apache::lonnet::inst_userrules($dom,'email');
4418: if (ref($emailrules) eq 'HASH') {
4419: if (keys(%{$emailrules}) > 0) {
4420: $datatable .= &user_formats_row('email',$settings,$emailrules,
4421: $emailruleorder,$numinrow,$$rowtotal);
4422: $$rowtotal ++;
4423: }
4424: }
4425: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
4426: }
4427: return $datatable;
4428: }
4429:
4430: sub email_as_username {
4431: my ($rowtotal,$processing,$type) = @_;
4432: my %choices =
4433: &Apache::lonlocal::texthash (
4434: automatic => 'Automatic approval',
4435: approval => 'Queued for approval',
4436: );
4437: my $output;
4438: foreach my $option ('automatic','approval') {
4439: my $checked;
4440: if (ref($processing) eq 'HASH') {
4441: if ($type eq '') {
4442: if (!exists($processing->{'default'})) {
4443: if ($option eq 'automatic') {
4444: $checked = ' checked="checked"';
4445: }
4446: } else {
4447: if ($processing->{'default'} eq $option) {
4448: $checked = ' checked="checked"';
4449: }
4450: }
4451: } else {
4452: if (!exists($processing->{$type})) {
4453: if ($option eq 'automatic') {
4454: $checked = ' checked="checked"';
4455: }
4456: } else {
4457: if ($processing->{$type} eq $option) {
4458: $checked = ' checked="checked"';
4459: }
4460: }
4461: }
4462: } elsif ($option eq 'automatic') {
4463: $checked = ' checked="checked"';
4464: }
4465: my $name = 'cancreate_emailprocess';
4466: if (($type ne '') && ($type ne 'default')) {
4467: $name .= '_'.$type;
4468: }
4469: $output .= '<span class="LC_nobreak"><label>'.
4470: '<input type="radio" name="'.$name.'"'.
4471: $checked.' value="'.$option.'" />'.
4472: $choices{$option}.'</label></span>';
4473: if ($type eq '') {
4474: $output .= ' ';
4475: } else {
4476: $output .= '<br />';
4477: }
4478: }
4479: $$rowtotal ++;
4480: return $output;
4481: }
4482:
4483: sub captcha_choice {
4484: my ($context,$settings,$itemcount) = @_;
4485: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4486: my %lt = &captcha_phrases();
4487: $keyentry = 'hidden';
4488: if ($context eq 'cancreate') {
4489: $rowname = &mt('CAPTCHA validation');
4490: } elsif ($context eq 'login') {
4491: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4492: }
4493: if (ref($settings) eq 'HASH') {
4494: if ($settings->{'captcha'}) {
4495: $checked{$settings->{'captcha'}} = ' checked="checked"';
4496: } else {
4497: $checked{'original'} = ' checked="checked"';
4498: }
4499: if ($settings->{'captcha'} eq 'recaptcha') {
4500: $pubtext = $lt{'pub'};
4501: $privtext = $lt{'priv'};
4502: $keyentry = 'text';
4503: }
4504: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4505: $currpub = $settings->{'recaptchakeys'}{'public'};
4506: $currpriv = $settings->{'recaptchakeys'}{'private'};
4507: }
4508: } else {
4509: $checked{'original'} = ' checked="checked"';
4510: }
4511: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4512: my $output = '<tr'.$css_class.'>'.
4513: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4514: '<table><tr><td>'."\n";
4515: foreach my $option ('original','recaptcha','notused') {
4516: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4517: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4518: $lt{$option}.'</label></span>';
4519: unless ($option eq 'notused') {
4520: $output .= (' 'x2)."\n";
4521: }
4522: }
4523: #
4524: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4525: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4526: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4527: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4528: #
4529: $output .= '</td></tr>'."\n".
4530: '<tr><td>'."\n".
4531: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4532: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4533: $currpub.'" size="40" /></span><br />'."\n".
4534: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4535: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4536: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4537: '</td></tr>';
4538: return $output;
4539: }
4540:
4541: sub user_formats_row {
4542: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4543: my $output;
4544: my %text = (
4545: 'username' => 'new usernames',
4546: 'id' => 'IDs',
4547: 'email' => 'self-created accounts (e-mail)',
4548: );
4549: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4550: $output = '<tr '.$css_class.'>'.
4551: '<td><span class="LC_nobreak">';
4552: if ($type eq 'email') {
4553: $output .= &mt("Formats disallowed for $text{$type}: ");
4554: } else {
4555: $output .= &mt("Format rules to check for $text{$type}: ");
4556: }
4557: $output .= '</span></td>'.
4558: '<td class="LC_left_item" colspan="2"><table>';
4559: my $rem;
4560: if (ref($ruleorder) eq 'ARRAY') {
4561: for (my $i=0; $i<@{$ruleorder}; $i++) {
4562: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4563: my $rem = $i%($numinrow);
4564: if ($rem == 0) {
4565: if ($i > 0) {
4566: $output .= '</tr>';
4567: }
4568: $output .= '<tr>';
4569: }
4570: my $check = ' ';
4571: if (ref($settings) eq 'HASH') {
4572: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4573: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4574: $check = ' checked="checked" ';
4575: }
4576: }
4577: }
4578: $output .= '<td class="LC_left_item">'.
4579: '<span class="LC_nobreak"><label>'.
4580: '<input type="checkbox" name="'.$type.'_rule" '.
4581: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4582: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4583: }
4584: }
4585: $rem = @{$ruleorder}%($numinrow);
4586: }
4587: my $colsleft = $numinrow - $rem;
4588: if ($colsleft > 1 ) {
4589: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4590: ' </td>';
4591: } elsif ($colsleft == 1) {
4592: $output .= '<td class="LC_left_item"> </td>';
4593: }
4594: $output .= '</tr></table></td></tr>';
4595: return $output;
4596: }
4597:
4598: sub usercreation_types {
4599: my %lt = &Apache::lonlocal::texthash (
4600: author => 'When adding a co-author',
4601: course => 'When adding a user to a course',
4602: requestcrs => 'When requesting a course',
4603: any => 'Any',
4604: official => 'Institutional only ',
4605: unofficial => 'Non-institutional only',
4606: none => 'None',
4607: );
4608: return %lt;
4609: }
4610:
4611: sub selfcreation_types {
4612: my %lt = &Apache::lonlocal::texthash (
4613: selfcreate => 'User creates own account',
4614: any => 'Any',
4615: official => 'Institutional only ',
4616: unofficial => 'Non-institutional only',
4617: email => 'E-mail address',
4618: login => 'Institutional Login',
4619: sso => 'SSO',
4620: );
4621: }
4622:
4623: sub authtype_names {
4624: my %lt = &Apache::lonlocal::texthash(
4625: int => 'Internal',
4626: krb4 => 'Kerberos 4',
4627: krb5 => 'Kerberos 5',
4628: loc => 'Local',
4629: );
4630: return %lt;
4631: }
4632:
4633: sub context_names {
4634: my %context_title = &Apache::lonlocal::texthash(
4635: author => 'Creating users when an Author',
4636: course => 'Creating users when in a course',
4637: domain => 'Creating users when a Domain Coordinator',
4638: );
4639: return %context_title;
4640: }
4641:
4642: sub print_usermodification {
4643: my ($position,$dom,$settings,$rowtotal) = @_;
4644: my $numinrow = 4;
4645: my ($context,$datatable,$rowcount);
4646: if ($position eq 'top') {
4647: $rowcount = 0;
4648: $context = 'author';
4649: foreach my $role ('ca','aa') {
4650: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4651: $numinrow,$rowcount);
4652: $$rowtotal ++;
4653: $rowcount ++;
4654: }
4655: } elsif ($position eq 'bottom') {
4656: $context = 'course';
4657: $rowcount = 0;
4658: foreach my $role ('st','ep','ta','in','cr') {
4659: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4660: $numinrow,$rowcount);
4661: $$rowtotal ++;
4662: $rowcount ++;
4663: }
4664: }
4665: return $datatable;
4666: }
4667:
4668: sub print_defaults {
4669: my ($position,$dom,$settings,$rowtotal) = @_;
4670: my $rownum = 0;
4671: my ($datatable,$css_class);
4672: if ($position eq 'top') {
4673: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4674: 'datelocale_def','portal_def');
4675: my %defaults;
4676: if (ref($settings) eq 'HASH') {
4677: %defaults = %{$settings};
4678: } else {
4679: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4680: foreach my $item (@items) {
4681: $defaults{$item} = $domdefaults{$item};
4682: }
4683: }
4684: my $titles = &defaults_titles($dom);
4685: foreach my $item (@items) {
4686: if ($rownum%2) {
4687: $css_class = '';
4688: } else {
4689: $css_class = ' class="LC_odd_row" ';
4690: }
4691: $datatable .= '<tr'.$css_class.'>'.
4692: '<td><span class="LC_nobreak">'.$titles->{$item}.
4693: '</span></td><td class="LC_right_item" colspan="3">';
4694: if ($item eq 'auth_def') {
4695: my @authtypes = ('internal','krb4','krb5','localauth');
4696: my %shortauth = (
4697: internal => 'int',
4698: krb4 => 'krb4',
4699: krb5 => 'krb5',
4700: localauth => 'loc'
4701: );
4702: my %authnames = &authtype_names();
4703: foreach my $auth (@authtypes) {
4704: my $checked = ' ';
4705: if ($defaults{$item} eq $auth) {
4706: $checked = ' checked="checked" ';
4707: }
4708: $datatable .= '<label><input type="radio" name="'.$item.
4709: '" value="'.$auth.'"'.$checked.'/>'.
4710: $authnames{$shortauth{$auth}}.'</label> ';
4711: }
4712: } elsif ($item eq 'timezone_def') {
4713: my $includeempty = 1;
4714: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4715: } elsif ($item eq 'datelocale_def') {
4716: my $includeempty = 1;
4717: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4718: } elsif ($item eq 'lang_def') {
4719: my $includeempty = 1;
4720: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
4721: } else {
4722: my $size;
4723: if ($item eq 'portal_def') {
4724: $size = ' size="25"';
4725: }
4726: $datatable .= '<input type="text" name="'.$item.'" value="'.
4727: $defaults{$item}.'"'.$size.' />';
4728: }
4729: $datatable .= '</td></tr>';
4730: $rownum ++;
4731: }
4732: } else {
4733: my (%defaults);
4734: if (ref($settings) eq 'HASH') {
4735: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4736: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4737: my $maxnum = @{$settings->{'inststatusorder'}};
4738: for (my $i=0; $i<$maxnum; $i++) {
4739: $css_class = $rownum%2?' class="LC_odd_row"':'';
4740: my $item = $settings->{'inststatusorder'}->[$i];
4741: my $title = $settings->{'inststatustypes'}->{$item};
4742: my $guestok;
4743: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4744: $guestok = 1;
4745: }
4746: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4747: $datatable .= '<tr'.$css_class.'>'.
4748: '<td><span class="LC_nobreak">'.
4749: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4750: for (my $k=0; $k<=$maxnum; $k++) {
4751: my $vpos = $k+1;
4752: my $selstr;
4753: if ($k == $i) {
4754: $selstr = ' selected="selected" ';
4755: }
4756: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4757: }
4758: my ($checkedon,$checkedoff);
4759: $checkedoff = ' checked="checked"';
4760: if ($guestok) {
4761: $checkedon = $checkedoff;
4762: $checkedoff = '';
4763: }
4764: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4765: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4766: &mt('delete').'</span></td>'.
4767: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4768: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4769: '</span></td>'.
4770: '<td class="LC_right_item"><span class="LC_nobreak">'.
4771: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4772: &mt('Yes').'</label>'.(' 'x2).
4773: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4774: &mt('No').'</label></span></td></tr>';
4775: }
4776: $css_class = $rownum%2?' class="LC_odd_row"':'';
4777: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4778: $datatable .= '<tr '.$css_class.'>'.
4779: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4780: for (my $k=0; $k<=$maxnum; $k++) {
4781: my $vpos = $k+1;
4782: my $selstr;
4783: if ($k == $maxnum) {
4784: $selstr = ' selected="selected" ';
4785: }
4786: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4787: }
4788: $datatable .= '</select> '.&mt('Internal ID:').
4789: '<input type="text" size="10" name="addinststatus" value="" />'.
4790: ' '.&mt('(new)').
4791: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4792: &mt('Name displayed:').
4793: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4794: '<td class="LC_right_item"><span class="LC_nobreak">'.
4795: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4796: &mt('Yes').'</label>'.(' 'x2).
4797: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4798: &mt('No').'</label></span></td></tr>';
4799: '</tr>'."\n";
4800: $rownum ++;
4801: }
4802: }
4803: }
4804: $$rowtotal += $rownum;
4805: return $datatable;
4806: }
4807:
4808: sub get_languages_hash {
4809: my %langchoices;
4810: foreach my $id (&Apache::loncommon::languageids()) {
4811: my $code = &Apache::loncommon::supportedlanguagecode($id);
4812: if ($code ne '') {
4813: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4814: }
4815: }
4816: return %langchoices;
4817: }
4818:
4819: sub defaults_titles {
4820: my ($dom) = @_;
4821: my %titles = &Apache::lonlocal::texthash (
4822: 'auth_def' => 'Default authentication type',
4823: 'auth_arg_def' => 'Default authentication argument',
4824: 'lang_def' => 'Default language',
4825: 'timezone_def' => 'Default timezone',
4826: 'datelocale_def' => 'Default locale for dates',
4827: 'portal_def' => 'Portal/Default URL',
4828: );
4829: if ($dom) {
4830: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4831: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4832: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4833: $protocol = 'http' if ($protocol ne 'https');
4834: if ($uint_dom) {
4835: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4836: $uint_dom);
4837: }
4838: }
4839: return (\%titles);
4840: }
4841:
4842: sub print_scantronformat {
4843: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4844: my $itemcount = 1;
4845: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4846: %confhash);
4847: my $switchserver = &check_switchserver($dom,$confname);
4848: my %lt = &Apache::lonlocal::texthash (
4849: default => 'Default bubblesheet format file error',
4850: custom => 'Custom bubblesheet format file error',
4851: );
4852: my %scantronfiles = (
4853: default => 'default.tab',
4854: custom => 'custom.tab',
4855: );
4856: foreach my $key (keys(%scantronfiles)) {
4857: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4858: .$scantronfiles{$key};
4859: }
4860: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4861: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4862: if (!$switchserver) {
4863: my $servadm = $r->dir_config('lonAdmEMail');
4864: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4865: if ($configuserok eq 'ok') {
4866: if ($author_ok eq 'ok') {
4867: my %legacyfile = (
4868: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4869: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4870: );
4871: my %md5chk;
4872: foreach my $type (keys(%legacyfile)) {
4873: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4874: chomp($md5chk{$type});
4875: }
4876: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4877: foreach my $type (keys(%legacyfile)) {
4878: ($scantronurls{$type},my $error) =
4879: &legacy_scantronformat($r,$dom,$confname,
4880: $type,$legacyfile{$type},
4881: $scantronurls{$type},
4882: $scantronfiles{$type});
4883: if ($error ne '') {
4884: $error{$type} = $error;
4885: }
4886: }
4887: if (keys(%error) == 0) {
4888: $is_custom = 1;
4889: $confhash{'scantron'}{'scantronformat'} =
4890: $scantronurls{'custom'};
4891: my $putresult =
4892: &Apache::lonnet::put_dom('configuration',
4893: \%confhash,$dom);
4894: if ($putresult ne 'ok') {
4895: $error{'custom'} =
4896: '<span class="LC_error">'.
4897: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4898: }
4899: }
4900: } else {
4901: ($scantronurls{'default'},my $error) =
4902: &legacy_scantronformat($r,$dom,$confname,
4903: 'default',$legacyfile{'default'},
4904: $scantronurls{'default'},
4905: $scantronfiles{'default'});
4906: if ($error eq '') {
4907: $confhash{'scantron'}{'scantronformat'} = '';
4908: my $putresult =
4909: &Apache::lonnet::put_dom('configuration',
4910: \%confhash,$dom);
4911: if ($putresult ne 'ok') {
4912: $error{'default'} =
4913: '<span class="LC_error">'.
4914: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4915: }
4916: } else {
4917: $error{'default'} = $error;
4918: }
4919: }
4920: }
4921: }
4922: } else {
4923: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
4924: }
4925: }
4926: if (ref($settings) eq 'HASH') {
4927: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4928: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4929: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4930: $scantronurl = '';
4931: } else {
4932: $scantronurl = $settings->{'scantronformat'};
4933: }
4934: $is_custom = 1;
4935: } else {
4936: $scantronurl = $scantronurls{'default'};
4937: }
4938: } else {
4939: if ($is_custom) {
4940: $scantronurl = $scantronurls{'custom'};
4941: } else {
4942: $scantronurl = $scantronurls{'default'};
4943: }
4944: }
4945: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4946: $datatable .= '<tr'.$css_class.'>';
4947: if (!$is_custom) {
4948: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4949: '<span class="LC_nobreak">';
4950: if ($scantronurl) {
4951: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4952: undef,undef,undef,undef,'background-color:#ffffff');
4953: } else {
4954: $datatable = &mt('File unavailable for display');
4955: }
4956: $datatable .= '</span></td>';
4957: if (keys(%error) == 0) {
4958: $datatable .= '<td valign="bottom">';
4959: if (!$switchserver) {
4960: $datatable .= &mt('Upload:').'<br />';
4961: }
4962: } else {
4963: my $errorstr;
4964: foreach my $key (sort(keys(%error))) {
4965: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4966: }
4967: $datatable .= '<td>'.$errorstr;
4968: }
4969: } else {
4970: if (keys(%error) > 0) {
4971: my $errorstr;
4972: foreach my $key (sort(keys(%error))) {
4973: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4974: }
4975: $datatable .= '<td>'.$errorstr.'</td><td> ';
4976: } elsif ($scantronurl) {
4977: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4978: undef,undef,undef,undef,'background-color:#ffffff');
4979: $datatable .= '<td><span class="LC_nobreak">'.
4980: $link.
4981: '<label><input type="checkbox" name="scantronformat_del"'.
4982: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
4983: '<td><span class="LC_nobreak"> '.
4984: &mt('Replace:').'</span><br />';
4985: }
4986: }
4987: if (keys(%error) == 0) {
4988: if ($switchserver) {
4989: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4990: } else {
4991: $datatable .='<span class="LC_nobreak"> '.
4992: '<input type="file" name="scantronformat" /></span>';
4993: }
4994: }
4995: $datatable .= '</td></tr>';
4996: $$rowtotal ++;
4997: return $datatable;
4998: }
4999:
5000: sub legacy_scantronformat {
5001: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5002: my ($url,$error);
5003: my @statinfo = &Apache::lonnet::stat_file($newurl);
5004: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5005: (my $result,$url) =
5006: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5007: '','',$newfile);
5008: if ($result ne 'ok') {
5009: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
5010: }
5011: }
5012: return ($url,$error);
5013: }
5014:
5015: sub print_coursecategories {
5016: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5017: my $datatable;
5018: if ($position eq 'top') {
5019: my (%checked);
5020: my @catitems = ('unauth','auth');
5021: my @cattypes = ('std','domonly','codesrch','none');
5022: $checked{'unauth'} = 'std';
5023: $checked{'auth'} = 'std';
5024: if (ref($settings) eq 'HASH') {
5025: foreach my $type (@cattypes) {
5026: if ($type eq $settings->{'unauth'}) {
5027: $checked{'unauth'} = $type;
5028: }
5029: if ($type eq $settings->{'auth'}) {
5030: $checked{'auth'} = $type;
5031: }
5032: }
5033: }
5034: my %lt = &Apache::lonlocal::texthash (
5035: unauth => 'Catalog type for unauthenticated users',
5036: auth => 'Catalog type for authenticated users',
5037: none => 'No catalog',
5038: std => 'Standard catalog',
5039: domonly => 'Domain-only catalog',
5040: codesrch => "Code search form",
5041: );
5042: my $itemcount = 0;
5043: foreach my $item (@catitems) {
5044: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5045: $datatable .= '<tr '.$css_class.'>'.
5046: '<td>'.$lt{$item}.'</td>'.
5047: '<td class="LC_right_item"><span class="LC_nobreak">';
5048: foreach my $type (@cattypes) {
5049: my $ischecked;
5050: if ($checked{$item} eq $type) {
5051: $ischecked=' checked="checked"';
5052: }
5053: $datatable .= '<label>'.
5054: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5055: ' />'.$lt{$type}.'</label> ';
5056: }
5057: $datatable .= '</td></tr>';
5058: $itemcount ++;
5059: }
5060: $$rowtotal += $itemcount;
5061: } elsif ($position eq 'middle') {
5062: my $toggle_cats_crs = ' ';
5063: my $toggle_cats_dom = ' checked="checked" ';
5064: my $can_cat_crs = ' ';
5065: my $can_cat_dom = ' checked="checked" ';
5066: my $toggle_catscomm_comm = ' ';
5067: my $toggle_catscomm_dom = ' checked="checked" ';
5068: my $can_catcomm_comm = ' ';
5069: my $can_catcomm_dom = ' checked="checked" ';
5070:
5071: if (ref($settings) eq 'HASH') {
5072: if ($settings->{'togglecats'} eq 'crs') {
5073: $toggle_cats_crs = $toggle_cats_dom;
5074: $toggle_cats_dom = ' ';
5075: }
5076: if ($settings->{'categorize'} eq 'crs') {
5077: $can_cat_crs = $can_cat_dom;
5078: $can_cat_dom = ' ';
5079: }
5080: if ($settings->{'togglecatscomm'} eq 'comm') {
5081: $toggle_catscomm_comm = $toggle_catscomm_dom;
5082: $toggle_catscomm_dom = ' ';
5083: }
5084: if ($settings->{'categorizecomm'} eq 'comm') {
5085: $can_catcomm_comm = $can_catcomm_dom;
5086: $can_catcomm_dom = ' ';
5087: }
5088: }
5089: my %title = &Apache::lonlocal::texthash (
5090: togglecats => 'Show/Hide a course in catalog',
5091: togglecatscomm => 'Show/Hide a community in catalog',
5092: categorize => 'Assign a category to a course',
5093: categorizecomm => 'Assign a category to a community',
5094: );
5095: my %level = &Apache::lonlocal::texthash (
5096: dom => 'Set in Domain',
5097: crs => 'Set in Course',
5098: comm => 'Set in Community',
5099: );
5100: $datatable = '<tr class="LC_odd_row">'.
5101: '<td>'.$title{'togglecats'}.'</td>'.
5102: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5103: '<input type="radio" name="togglecats"'.
5104: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5105: '<label><input type="radio" name="togglecats"'.
5106: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5107: '</tr><tr>'.
5108: '<td>'.$title{'categorize'}.'</td>'.
5109: '<td class="LC_right_item"><span class="LC_nobreak">'.
5110: '<label><input type="radio" name="categorize"'.
5111: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5112: '<label><input type="radio" name="categorize"'.
5113: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
5114: '</tr><tr class="LC_odd_row">'.
5115: '<td>'.$title{'togglecatscomm'}.'</td>'.
5116: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5117: '<input type="radio" name="togglecatscomm"'.
5118: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5119: '<label><input type="radio" name="togglecatscomm"'.
5120: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5121: '</tr><tr>'.
5122: '<td>'.$title{'categorizecomm'}.'</td>'.
5123: '<td class="LC_right_item"><span class="LC_nobreak">'.
5124: '<label><input type="radio" name="categorizecomm"'.
5125: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5126: '<label><input type="radio" name="categorizecomm"'.
5127: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
5128: '</tr>';
5129: $$rowtotal += 4;
5130: } else {
5131: my $css_class;
5132: my $itemcount = 1;
5133: my $cathash;
5134: if (ref($settings) eq 'HASH') {
5135: $cathash = $settings->{'cats'};
5136: }
5137: if (ref($cathash) eq 'HASH') {
5138: my (@cats,@trails,%allitems,%idx,@jsarray);
5139: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5140: \%allitems,\%idx,\@jsarray);
5141: my $maxdepth = scalar(@cats);
5142: my $colattrib = '';
5143: if ($maxdepth > 2) {
5144: $colattrib = ' colspan="2" ';
5145: }
5146: my @path;
5147: if (@cats > 0) {
5148: if (ref($cats[0]) eq 'ARRAY') {
5149: my $numtop = @{$cats[0]};
5150: my $maxnum = $numtop;
5151: my %default_names = (
5152: instcode => &mt('Official courses'),
5153: communities => &mt('Communities'),
5154: );
5155:
5156: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5157: ($cathash->{'instcode::0'} eq '') ||
5158: (!grep(/^communities$/,@{$cats[0]})) ||
5159: ($cathash->{'communities::0'} eq '')) {
5160: $maxnum ++;
5161: }
5162: my $lastidx;
5163: for (my $i=0; $i<$numtop; $i++) {
5164: my $parent = $cats[0][$i];
5165: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5166: my $item = &escape($parent).'::0';
5167: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5168: $lastidx = $idx{$item};
5169: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5170: .'<select name="'.$item.'"'.$chgstr.'>';
5171: for (my $k=0; $k<=$maxnum; $k++) {
5172: my $vpos = $k+1;
5173: my $selstr;
5174: if ($k == $i) {
5175: $selstr = ' selected="selected" ';
5176: }
5177: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5178: }
5179: $datatable .= '</select></span></td><td>';
5180: if ($parent eq 'instcode' || $parent eq 'communities') {
5181: $datatable .= '<span class="LC_nobreak">'
5182: .$default_names{$parent}.'</span>';
5183: if ($parent eq 'instcode') {
5184: $datatable .= '<br /><span class="LC_nobreak">('
5185: .&mt('with institutional codes')
5186: .')</span></td><td'.$colattrib.'>';
5187: } else {
5188: $datatable .= '<table><tr><td>';
5189: }
5190: $datatable .= '<span class="LC_nobreak">'
5191: .'<label><input type="radio" name="'
5192: .$parent.'" value="1" checked="checked" />'
5193: .&mt('Display').'</label>';
5194: if ($parent eq 'instcode') {
5195: $datatable .= ' ';
5196: } else {
5197: $datatable .= '</span></td></tr><tr><td>'
5198: .'<span class="LC_nobreak">';
5199: }
5200: $datatable .= '<label><input type="radio" name="'
5201: .$parent.'" value="0" />'
5202: .&mt('Do not display').'</label></span>';
5203: if ($parent eq 'communities') {
5204: $datatable .= '</td></tr></table>';
5205: }
5206: $datatable .= '</td>';
5207: } else {
5208: $datatable .= $parent
5209: .' <span class="LC_nobreak"><label>'
5210: .'<input type="checkbox" name="deletecategory" '
5211: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5212: }
5213: my $depth = 1;
5214: push(@path,$parent);
5215: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5216: pop(@path);
5217: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5218: $itemcount ++;
5219: }
5220: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5221: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5222: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
5223: for (my $k=0; $k<=$maxnum; $k++) {
5224: my $vpos = $k+1;
5225: my $selstr;
5226: if ($k == $numtop) {
5227: $selstr = ' selected="selected" ';
5228: }
5229: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5230: }
5231: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
5232: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5233: .'</tr>'."\n";
5234: $itemcount ++;
5235: foreach my $default ('instcode','communities') {
5236: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5237: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5238: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5239: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5240: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5241: for (my $k=0; $k<=$maxnum; $k++) {
5242: my $vpos = $k+1;
5243: my $selstr;
5244: if ($k == $maxnum) {
5245: $selstr = ' selected="selected" ';
5246: }
5247: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5248: }
5249: $datatable .= '</select></span></td>'.
5250: '<td><span class="LC_nobreak">'.
5251: $default_names{$default}.'</span>';
5252: if ($default eq 'instcode') {
5253: $datatable .= '<br /><span class="LC_nobreak">('
5254: .&mt('with institutional codes').')</span>';
5255: }
5256: $datatable .= '</td>'
5257: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5258: .&mt('Display').'</label> '
5259: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5260: .&mt('Do not display').'</label></span></td></tr>';
5261: }
5262: }
5263: }
5264: } else {
5265: $datatable .= &initialize_categories($itemcount);
5266: }
5267: } else {
5268: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
5269: .&initialize_categories($itemcount);
5270: }
5271: $$rowtotal += $itemcount;
5272: }
5273: return $datatable;
5274: }
5275:
5276: sub print_serverstatuses {
5277: my ($dom,$settings,$rowtotal) = @_;
5278: my $datatable;
5279: my @pages = &serverstatus_pages();
5280: my (%namedaccess,%machineaccess);
5281: foreach my $type (@pages) {
5282: $namedaccess{$type} = '';
5283: $machineaccess{$type}= '';
5284: }
5285: if (ref($settings) eq 'HASH') {
5286: foreach my $type (@pages) {
5287: if (exists($settings->{$type})) {
5288: if (ref($settings->{$type}) eq 'HASH') {
5289: foreach my $key (keys(%{$settings->{$type}})) {
5290: if ($key eq 'namedusers') {
5291: $namedaccess{$type} = $settings->{$type}->{$key};
5292: } elsif ($key eq 'machines') {
5293: $machineaccess{$type} = $settings->{$type}->{$key};
5294: }
5295: }
5296: }
5297: }
5298: }
5299: }
5300: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
5301: my $rownum = 0;
5302: my $css_class;
5303: foreach my $type (@pages) {
5304: $rownum ++;
5305: $css_class = $rownum%2?' class="LC_odd_row"':'';
5306: $datatable .= '<tr'.$css_class.'>'.
5307: '<td><span class="LC_nobreak">'.
5308: $titles->{$type}.'</span></td>'.
5309: '<td class="LC_left_item">'.
5310: '<input type="text" name="'.$type.'_namedusers" '.
5311: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5312: '<td class="LC_right_item">'.
5313: '<span class="LC_nobreak">'.
5314: '<input type="text" name="'.$type.'_machines" '.
5315: 'value="'.$machineaccess{$type}.'" size="10" />'.
5316: '</td></tr>'."\n";
5317: }
5318: $$rowtotal += $rownum;
5319: return $datatable;
5320: }
5321:
5322: sub serverstatus_pages {
5323: return ('userstatus','lonstatus','loncron','server-status','codeversions',
5324: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
5325: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
5326: 'uniquecodes','diskusage','coursecatalog');
5327: }
5328:
5329: sub defaults_javascript {
5330: my ($settings) = @_;
5331: return unless (ref($settings) eq 'HASH');
5332: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5333: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5334: if ($maxnum eq '') {
5335: $maxnum = 0;
5336: }
5337: $maxnum ++;
5338: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5339: return <<"ENDSCRIPT";
5340: <script type="text/javascript">
5341: // <![CDATA[
5342: function reorderTypes(form,caller) {
5343: var changedVal;
5344: $jstext
5345: var newpos = 'addinststatus_pos';
5346: var current = new Array;
5347: var maxh = $maxnum;
5348: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5349: var oldVal;
5350: if (caller == newpos) {
5351: changedVal = newitemVal;
5352: } else {
5353: var curritem = 'inststatus_pos_'+caller;
5354: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5355: current[newitemVal] = newpos;
5356: }
5357: for (var i=0; i<inststatuses.length; i++) {
5358: if (inststatuses[i] != caller) {
5359: var elementName = 'inststatus_pos_'+inststatuses[i];
5360: if (form.elements[elementName]) {
5361: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5362: current[currVal] = elementName;
5363: }
5364: }
5365: }
5366: for (var j=0; j<maxh; j++) {
5367: if (current[j] == undefined) {
5368: oldVal = j;
5369: }
5370: }
5371: if (oldVal < changedVal) {
5372: for (var k=oldVal+1; k<=changedVal ; k++) {
5373: var elementName = current[k];
5374: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5375: }
5376: } else {
5377: for (var k=changedVal; k<oldVal; k++) {
5378: var elementName = current[k];
5379: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5380: }
5381: }
5382: return;
5383: }
5384:
5385: // ]]>
5386: </script>
5387:
5388: ENDSCRIPT
5389: }
5390: }
5391:
5392: sub coursecategories_javascript {
5393: my ($settings) = @_;
5394: my ($output,$jstext,$cathash);
5395: if (ref($settings) eq 'HASH') {
5396: $cathash = $settings->{'cats'};
5397: }
5398: if (ref($cathash) eq 'HASH') {
5399: my (@cats,@jsarray,%idx);
5400: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
5401: if (@jsarray > 0) {
5402: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5403: for (my $i=0; $i<@jsarray; $i++) {
5404: if (ref($jsarray[$i]) eq 'ARRAY') {
5405: my $catstr = join('","',@{$jsarray[$i]});
5406: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5407: }
5408: }
5409: }
5410: } else {
5411: $jstext = ' var categories = Array(1);'."\n".
5412: ' categories[0] = Array("instcode_pos");'."\n";
5413: }
5414: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5415: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5416: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
5417: $output = <<"ENDSCRIPT";
5418: <script type="text/javascript">
5419: // <![CDATA[
5420: function reorderCats(form,parent,item,idx) {
5421: var changedVal;
5422: $jstext
5423: var newpos = 'addcategory_pos';
5424: if (parent == '') {
5425: var has_instcode = 0;
5426: var maxtop = categories[idx].length;
5427: for (var j=0; j<maxtop; j++) {
5428: if (categories[idx][j] == 'instcode::0') {
5429: has_instcode == 1;
5430: }
5431: }
5432: if (has_instcode == 0) {
5433: categories[idx][maxtop] = 'instcode_pos';
5434: }
5435: } else {
5436: newpos += '_'+parent;
5437: }
5438: var maxh = 1 + categories[idx].length;
5439: var current = new Array;
5440: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5441: if (item == newpos) {
5442: changedVal = newitemVal;
5443: } else {
5444: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5445: current[newitemVal] = newpos;
5446: }
5447: for (var i=0; i<categories[idx].length; i++) {
5448: var elementName = categories[idx][i];
5449: if (elementName != item) {
5450: if (form.elements[elementName]) {
5451: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5452: current[currVal] = elementName;
5453: }
5454: }
5455: }
5456: var oldVal;
5457: for (var j=0; j<maxh; j++) {
5458: if (current[j] == undefined) {
5459: oldVal = j;
5460: }
5461: }
5462: if (oldVal < changedVal) {
5463: for (var k=oldVal+1; k<=changedVal ; k++) {
5464: var elementName = current[k];
5465: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5466: }
5467: } else {
5468: for (var k=changedVal; k<oldVal; k++) {
5469: var elementName = current[k];
5470: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5471: }
5472: }
5473: return;
5474: }
5475:
5476: function categoryCheck(form) {
5477: if (form.elements['addcategory_name'].value == 'instcode') {
5478: alert('$instcode_reserved\\n$choose_again');
5479: return false;
5480: }
5481: if (form.elements['addcategory_name'].value == 'communities') {
5482: alert('$communities_reserved\\n$choose_again');
5483: return false;
5484: }
5485: return true;
5486: }
5487:
5488: // ]]>
5489: </script>
5490:
5491: ENDSCRIPT
5492: return $output;
5493: }
5494:
5495: sub initialize_categories {
5496: my ($itemcount) = @_;
5497: my ($datatable,$css_class,$chgstr);
5498: my %default_names = (
5499: instcode => 'Official courses (with institutional codes)',
5500: communities => 'Communities',
5501: );
5502: my $select0 = ' selected="selected"';
5503: my $select1 = '';
5504: foreach my $default ('instcode','communities') {
5505: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5506: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5507: if ($default eq 'communities') {
5508: $select1 = $select0;
5509: $select0 = '';
5510: }
5511: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5512: .'<select name="'.$default.'_pos">'
5513: .'<option value="0"'.$select0.'>1</option>'
5514: .'<option value="1"'.$select1.'>2</option>'
5515: .'<option value="2">3</option></select> '
5516: .$default_names{$default}
5517: .'</span></td><td><span class="LC_nobreak">'
5518: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5519: .&mt('Display').'</label> <label>'
5520: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
5521: .'</label></span></td></tr>';
5522: $itemcount ++;
5523: }
5524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5525: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
5526: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5527: .'<select name="addcategory_pos"'.$chgstr.'>'
5528: .'<option value="0">1</option>'
5529: .'<option value="1">2</option>'
5530: .'<option value="2" selected="selected">3</option></select> '
5531: .&mt('Add category').'</td><td>'.&mt('Name:')
5532: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5533: return $datatable;
5534: }
5535:
5536: sub build_category_rows {
5537: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5538: my ($text,$name,$item,$chgstr);
5539: if (ref($cats) eq 'ARRAY') {
5540: my $maxdepth = scalar(@{$cats});
5541: if (ref($cats->[$depth]) eq 'HASH') {
5542: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5543: my $numchildren = @{$cats->[$depth]{$parent}};
5544: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5545: $text .= '<td><table class="LC_data_table">';
5546: my ($idxnum,$parent_name,$parent_item);
5547: my $higher = $depth - 1;
5548: if ($higher == 0) {
5549: $parent_name = &escape($parent).'::'.$higher;
5550: } else {
5551: if (ref($path) eq 'ARRAY') {
5552: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5553: }
5554: }
5555: $parent_item = 'addcategory_pos_'.$parent_name;
5556: for (my $j=0; $j<=$numchildren; $j++) {
5557: if ($j < $numchildren) {
5558: $name = $cats->[$depth]{$parent}[$j];
5559: $item = &escape($name).':'.&escape($parent).':'.$depth;
5560: $idxnum = $idx->{$item};
5561: } else {
5562: $name = $parent_name;
5563: $item = $parent_item;
5564: }
5565: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5566: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
5567: for (my $i=0; $i<=$numchildren; $i++) {
5568: my $vpos = $i+1;
5569: my $selstr;
5570: if ($j == $i) {
5571: $selstr = ' selected="selected" ';
5572: }
5573: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5574: }
5575: $text .= '</select> ';
5576: if ($j < $numchildren) {
5577: my $deeper = $depth+1;
5578: $text .= $name.' '
5579: .'<label><input type="checkbox" name="deletecategory" value="'
5580: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5581: if(ref($path) eq 'ARRAY') {
5582: push(@{$path},$name);
5583: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
5584: pop(@{$path});
5585: }
5586: } else {
5587: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
5588: if ($j == $numchildren) {
5589: $text .= $name;
5590: } else {
5591: $text .= $item;
5592: }
5593: $text .= '" value="" />';
5594: }
5595: $text .= '</td></tr>';
5596: }
5597: $text .= '</table></td>';
5598: } else {
5599: my $higher = $depth-1;
5600: if ($higher == 0) {
5601: $name = &escape($parent).'::'.$higher;
5602: } else {
5603: if (ref($path) eq 'ARRAY') {
5604: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5605: }
5606: }
5607: my $colspan;
5608: if ($parent ne 'instcode') {
5609: $colspan = $maxdepth - $depth - 1;
5610: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5611: }
5612: }
5613: }
5614: }
5615: return $text;
5616: }
5617:
5618: sub modifiable_userdata_row {
5619: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5620: my ($role,$rolename,$statustype);
5621: $role = $item;
5622: if ($context eq 'cancreate') {
5623: if ($item =~ /^emailusername_(.+)$/) {
5624: $statustype = $1;
5625: $role = 'emailusername';
5626: if (ref($usertypes) eq 'HASH') {
5627: if ($usertypes->{$statustype}) {
5628: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5629: } else {
5630: $rolename = &mt('Data provided by user');
5631: }
5632: }
5633: }
5634: } elsif ($context eq 'selfcreate') {
5635: if (ref($usertypes) eq 'HASH') {
5636: $rolename = $usertypes->{$role};
5637: } else {
5638: $rolename = $role;
5639: }
5640: } else {
5641: if ($role eq 'cr') {
5642: $rolename = &mt('Custom role');
5643: } else {
5644: $rolename = &Apache::lonnet::plaintext($role);
5645: }
5646: }
5647: my (@fields,%fieldtitles);
5648: if (ref($fieldsref) eq 'ARRAY') {
5649: @fields = @{$fieldsref};
5650: } else {
5651: @fields = ('lastname','firstname','middlename','generation',
5652: 'permanentemail','id');
5653: }
5654: if ((ref($titlesref) eq 'HASH')) {
5655: %fieldtitles = %{$titlesref};
5656: } else {
5657: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5658: }
5659: my $output;
5660: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5661: $output = '<tr '.$css_class.'>'.
5662: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5663: '<td class="LC_left_item" colspan="2"><table>';
5664: my $rem;
5665: my %checks;
5666: if (ref($settings) eq 'HASH') {
5667: if (ref($settings->{$context}) eq 'HASH') {
5668: if (ref($settings->{$context}->{$role}) eq 'HASH') {
5669: my $hashref = $settings->{$context}->{$role};
5670: if ($role eq 'emailusername') {
5671: if ($statustype) {
5672: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5673: $hashref = $settings->{$context}->{$role}->{$statustype};
5674: if (ref($hashref) eq 'HASH') {
5675: foreach my $field (@fields) {
5676: if ($hashref->{$field}) {
5677: $checks{$field} = $hashref->{$field};
5678: }
5679: }
5680: }
5681: }
5682: }
5683: } else {
5684: if (ref($hashref) eq 'HASH') {
5685: foreach my $field (@fields) {
5686: if ($hashref->{$field}) {
5687: $checks{$field} = ' checked="checked" ';
5688: }
5689: }
5690: }
5691: }
5692: }
5693: }
5694: }
5695:
5696: for (my $i=0; $i<@fields; $i++) {
5697: my $rem = $i%($numinrow);
5698: if ($rem == 0) {
5699: if ($i > 0) {
5700: $output .= '</tr>';
5701: }
5702: $output .= '<tr>';
5703: }
5704: my $check = ' ';
5705: unless ($role eq 'emailusername') {
5706: if (exists($checks{$fields[$i]})) {
5707: $check = $checks{$fields[$i]}
5708: } else {
5709: if ($role eq 'st') {
5710: if (ref($settings) ne 'HASH') {
5711: $check = ' checked="checked" ';
5712: }
5713: }
5714: }
5715: }
5716: $output .= '<td class="LC_left_item">'.
5717: '<span class="LC_nobreak">';
5718: if ($role eq 'emailusername') {
5719: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5720: $checks{$fields[$i]} = 'omit';
5721: }
5722: foreach my $option ('required','optional','omit') {
5723: my $checked='';
5724: if ($checks{$fields[$i]} eq $option) {
5725: $checked='checked="checked" ';
5726: }
5727: $output .= '<label>'.
5728: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5729: &mt($option).'</label>'.(' ' x2);
5730: }
5731: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5732: } else {
5733: $output .= '<label>'.
5734: '<input type="checkbox" name="canmodify_'.$role.'" '.
5735: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5736: '</label>';
5737: }
5738: $output .= '</span></td>';
5739: $rem = @fields%($numinrow);
5740: }
5741: my $colsleft = $numinrow - $rem;
5742: if ($colsleft > 1 ) {
5743: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5744: ' </td>';
5745: } elsif ($colsleft == 1) {
5746: $output .= '<td class="LC_left_item"> </td>';
5747: }
5748: $output .= '</tr></table></td></tr>';
5749: return $output;
5750: }
5751:
5752: sub insttypes_row {
5753: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
5754: my %lt = &Apache::lonlocal::texthash (
5755: cansearch => 'Users allowed to search',
5756: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
5757: lockablenames => 'User preference to lock name',
5758: );
5759: my $showdom;
5760: if ($context eq 'cansearch') {
5761: $showdom = ' ('.$dom.')';
5762: }
5763: my $class = 'LC_left_item';
5764: if ($context eq 'statustocreate') {
5765: $class = 'LC_right_item';
5766: }
5767: my $css_class = ' class="LC_odd_row"';
5768: if ($rownum ne '') {
5769: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5770: }
5771: my $output = '<tr'.$css_class.'>'.
5772: '<td>'.$lt{$context}.$showdom.
5773: '</td><td class="'.$class.'" colspan="2"><table>';
5774: my $rem;
5775: if (ref($types) eq 'ARRAY') {
5776: for (my $i=0; $i<@{$types}; $i++) {
5777: if (defined($usertypes->{$types->[$i]})) {
5778: my $rem = $i%($numinrow);
5779: if ($rem == 0) {
5780: if ($i > 0) {
5781: $output .= '</tr>';
5782: }
5783: $output .= '<tr>';
5784: }
5785: my $check = ' ';
5786: if (ref($settings) eq 'HASH') {
5787: if (ref($settings->{$context}) eq 'ARRAY') {
5788: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5789: $check = ' checked="checked" ';
5790: }
5791: } elsif ($context eq 'statustocreate') {
5792: $check = ' checked="checked" ';
5793: }
5794: }
5795: $output .= '<td class="LC_left_item">'.
5796: '<span class="LC_nobreak"><label>'.
5797: '<input type="checkbox" name="'.$context.'" '.
5798: 'value="'.$types->[$i].'"'.$check.'/>'.
5799: $usertypes->{$types->[$i]}.'</label></span></td>';
5800: }
5801: }
5802: $rem = @{$types}%($numinrow);
5803: }
5804: my $colsleft = $numinrow - $rem;
5805: if (($rem == 0) && (@{$types} > 0)) {
5806: $output .= '<tr>';
5807: }
5808: if ($colsleft > 1) {
5809: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5810: } else {
5811: $output .= '<td class="LC_left_item">';
5812: }
5813: my $defcheck = ' ';
5814: if (ref($settings) eq 'HASH') {
5815: if (ref($settings->{$context}) eq 'ARRAY') {
5816: if (grep(/^default$/,@{$settings->{$context}})) {
5817: $defcheck = ' checked="checked" ';
5818: }
5819: } elsif ($context eq 'statustocreate') {
5820: $defcheck = ' checked="checked" ';
5821: }
5822: }
5823: $output .= '<span class="LC_nobreak"><label>'.
5824: '<input type="checkbox" name="'.$context.'" '.
5825: 'value="default"'.$defcheck.'/>'.
5826: $othertitle.'</label></span></td>'.
5827: '</tr></table></td></tr>';
5828: return $output;
5829: }
5830:
5831: sub sorted_searchtitles {
5832: my %searchtitles = &Apache::lonlocal::texthash(
5833: 'uname' => 'username',
5834: 'lastname' => 'last name',
5835: 'lastfirst' => 'last name, first name',
5836: );
5837: my @titleorder = ('uname','lastname','lastfirst');
5838: return (\%searchtitles,\@titleorder);
5839: }
5840:
5841: sub sorted_searchtypes {
5842: my %srchtypes_desc = (
5843: exact => 'is exact match',
5844: contains => 'contains ..',
5845: begins => 'begins with ..',
5846: );
5847: my @srchtypeorder = ('exact','begins','contains');
5848: return (\%srchtypes_desc,\@srchtypeorder);
5849: }
5850:
5851: sub usertype_update_row {
5852: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5853: my $datatable;
5854: my $numinrow = 4;
5855: foreach my $type (@{$types}) {
5856: if (defined($usertypes->{$type})) {
5857: $$rownums ++;
5858: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5859: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5860: '</td><td class="LC_left_item"><table>';
5861: for (my $i=0; $i<@{$fields}; $i++) {
5862: my $rem = $i%($numinrow);
5863: if ($rem == 0) {
5864: if ($i > 0) {
5865: $datatable .= '</tr>';
5866: }
5867: $datatable .= '<tr>';
5868: }
5869: my $check = ' ';
5870: if (ref($settings) eq 'HASH') {
5871: if (ref($settings->{'fields'}) eq 'HASH') {
5872: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5873: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5874: $check = ' checked="checked" ';
5875: }
5876: }
5877: }
5878: }
5879:
5880: if ($i == @{$fields}-1) {
5881: my $colsleft = $numinrow - $rem;
5882: if ($colsleft > 1) {
5883: $datatable .= '<td colspan="'.$colsleft.'">';
5884: } else {
5885: $datatable .= '<td>';
5886: }
5887: } else {
5888: $datatable .= '<td>';
5889: }
5890: $datatable .= '<span class="LC_nobreak"><label>'.
5891: '<input type="checkbox" name="updateable_'.$type.
5892: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5893: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
5894: }
5895: $datatable .= '</tr></table></td></tr>';
5896: }
5897: }
5898: return $datatable;
5899: }
5900:
5901: sub modify_login {
5902: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
5903: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5904: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5905: %title = ( coursecatalog => 'Display course catalog',
5906: adminmail => 'Display administrator E-mail address',
5907: helpdesk => 'Display "Contact Helpdesk" link',
5908: newuser => 'Link for visitors to create a user account',
5909: loginheader => 'Log-in box header');
5910: @offon = ('off','on');
5911: if (ref($domconfig{login}) eq 'HASH') {
5912: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5913: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5914: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5915: }
5916: }
5917: }
5918: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5919: \%domconfig,\%loginhash);
5920: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
5921: foreach my $item (@toggles) {
5922: $loginhash{login}{$item} = $env{'form.'.$item};
5923: }
5924: $loginhash{login}{loginheader} = $env{'form.loginheader'};
5925: if (ref($colchanges{'login'}) eq 'HASH') {
5926: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5927: \%loginhash);
5928: }
5929:
5930: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5931: my %domservers = &Apache::lonnet::get_servers($dom);
5932: my @loginvia_attribs = ('serverpath','custompath','exempt');
5933: if (keys(%servers) > 1) {
5934: foreach my $lonhost (keys(%servers)) {
5935: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5936: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5937: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5938: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5939: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5940: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5941: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5942: $changes{'loginvia'}{$lonhost} = 1;
5943: } else {
5944: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5945: $changes{'loginvia'}{$lonhost} = 1;
5946: }
5947: } else {
5948: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5949: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5950: $changes{'loginvia'}{$lonhost} = 1;
5951: }
5952: }
5953: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5954: foreach my $item (@loginvia_attribs) {
5955: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5956: }
5957: } else {
5958: foreach my $item (@loginvia_attribs) {
5959: my $new = $env{'form.'.$lonhost.'_'.$item};
5960: if (($item eq 'serverpath') && ($new eq 'custom')) {
5961: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5962: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5963: $new = '/';
5964: }
5965: }
5966: if (($item eq 'custompath') &&
5967: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5968: $new = '';
5969: }
5970: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5971: $changes{'loginvia'}{$lonhost} = 1;
5972: }
5973: if ($item eq 'exempt') {
5974: $new = &check_exempt_addresses($new);
5975: }
5976: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5977: }
5978: }
5979: } else {
5980: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5981: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5982: $changes{'loginvia'}{$lonhost} = 1;
5983: foreach my $item (@loginvia_attribs) {
5984: my $new = $env{'form.'.$lonhost.'_'.$item};
5985: if (($item eq 'serverpath') && ($new eq 'custom')) {
5986: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5987: $new = '/';
5988: }
5989: }
5990: if (($item eq 'custompath') &&
5991: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5992: $new = '';
5993: }
5994: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5995: }
5996: }
5997: }
5998: }
5999: }
6000:
6001: my $servadm = $r->dir_config('lonAdmEMail');
6002: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6003: if (ref($domconfig{'login'}) eq 'HASH') {
6004: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6005: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6006: if ($lang eq 'nolang') {
6007: push(@currlangs,$lang);
6008: } elsif (defined($langchoices{$lang})) {
6009: push(@currlangs,$lang);
6010: } else {
6011: next;
6012: }
6013: }
6014: }
6015: }
6016: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6017: if (@currlangs > 0) {
6018: foreach my $lang (@currlangs) {
6019: if (grep(/^\Q$lang\E$/,@delurls)) {
6020: $changes{'helpurl'}{$lang} = 1;
6021: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6022: $changes{'helpurl'}{$lang} = 1;
6023: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6024: push(@newlangs,$lang);
6025: } else {
6026: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6027: }
6028: }
6029: }
6030: unless (grep(/^nolang$/,@currlangs)) {
6031: if ($env{'form.loginhelpurl_nolang.filename'}) {
6032: $changes{'helpurl'}{'nolang'} = 1;
6033: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6034: push(@newlangs,'nolang');
6035: }
6036: }
6037: if ($env{'form.loginhelpurl_add_lang'}) {
6038: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6039: ($env{'form.loginhelpurl_add_file.filename'})) {
6040: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6041: $addedfile = $env{'form.loginhelpurl_add_lang'};
6042: }
6043: }
6044: if ((@newlangs > 0) || ($addedfile)) {
6045: my $error;
6046: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6047: if ($configuserok eq 'ok') {
6048: if ($switchserver) {
6049: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6050: } elsif ($author_ok eq 'ok') {
6051: my @allnew = @newlangs;
6052: if ($addedfile ne '') {
6053: push(@allnew,$addedfile);
6054: }
6055: foreach my $lang (@allnew) {
6056: my $formelem = 'loginhelpurl_'.$lang;
6057: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6058: $formelem = 'loginhelpurl_add_file';
6059: }
6060: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6061: "help/$lang",'','',$newfile{$lang});
6062: if ($result eq 'ok') {
6063: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6064: $changes{'helpurl'}{$lang} = 1;
6065: } else {
6066: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6067: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6068: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6069: (!grep(/^\Q$lang\E$/,@delurls))) {
6070: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6071: }
6072: }
6073: }
6074: } else {
6075: $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);
6076: }
6077: } else {
6078: $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);
6079: }
6080: if ($error) {
6081: &Apache::lonnet::logthis($error);
6082: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6083: }
6084: }
6085:
6086: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6087: if (ref($domconfig{'login'}) eq 'HASH') {
6088: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6089: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6090: if ($domservers{$lonhost}) {
6091: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6092: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
6093: $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
6094: }
6095: }
6096: }
6097: }
6098: }
6099: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6100: foreach my $lonhost (sort(keys(%domservers))) {
6101: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6102: $changes{'headtag'}{$lonhost} = 1;
6103: } else {
6104: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6105: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6106: }
6107: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6108: push(@newhosts,$lonhost);
6109: } elsif ($currheadtagurls{$lonhost}) {
6110: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6111: if ($currexempt{$lonhost}) {
6112: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6113: $changes{'headtag'}{$lonhost} = 1;
6114: }
6115: } elsif ($possexempt{$lonhost}) {
6116: $changes{'headtag'}{$lonhost} = 1;
6117: }
6118: if ($possexempt{$lonhost}) {
6119: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6120: }
6121: }
6122: }
6123: }
6124: if (@newhosts) {
6125: my $error;
6126: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6127: if ($configuserok eq 'ok') {
6128: if ($switchserver) {
6129: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6130: } elsif ($author_ok eq 'ok') {
6131: foreach my $lonhost (@newhosts) {
6132: my $formelem = 'loginheadtag_'.$lonhost;
6133: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6134: "login/headtag/$lonhost",'','',
6135: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6136: if ($result eq 'ok') {
6137: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6138: $changes{'headtag'}{$lonhost} = 1;
6139: if ($possexempt{$lonhost}) {
6140: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6141: }
6142: } else {
6143: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6144: $newheadtagurls{$lonhost},$result);
6145: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6146: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6147: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6148: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6149: }
6150: }
6151: }
6152: } else {
6153: $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);
6154: }
6155: } else {
6156: $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);
6157: }
6158: if ($error) {
6159: &Apache::lonnet::logthis($error);
6160: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6161: }
6162: }
6163: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6164:
6165: my $defaulthelpfile = '/adm/loginproblems.html';
6166: my $defaulttext = &mt('Default in use');
6167:
6168: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6169: $dom);
6170: if ($putresult eq 'ok') {
6171: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
6172: my %defaultchecked = (
6173: 'coursecatalog' => 'on',
6174: 'helpdesk' => 'on',
6175: 'adminmail' => 'off',
6176: 'newuser' => 'off',
6177: );
6178: if (ref($domconfig{'login'}) eq 'HASH') {
6179: foreach my $item (@toggles) {
6180: if ($defaultchecked{$item} eq 'on') {
6181: if (($domconfig{'login'}{$item} eq '0') &&
6182: ($env{'form.'.$item} eq '1')) {
6183: $changes{$item} = 1;
6184: } elsif (($domconfig{'login'}{$item} eq '' ||
6185: $domconfig{'login'}{$item} eq '1') &&
6186: ($env{'form.'.$item} eq '0')) {
6187: $changes{$item} = 1;
6188: }
6189: } elsif ($defaultchecked{$item} eq 'off') {
6190: if (($domconfig{'login'}{$item} eq '1') &&
6191: ($env{'form.'.$item} eq '0')) {
6192: $changes{$item} = 1;
6193: } elsif (($domconfig{'login'}{$item} eq '' ||
6194: $domconfig{'login'}{$item} eq '0') &&
6195: ($env{'form.'.$item} eq '1')) {
6196: $changes{$item} = 1;
6197: }
6198: }
6199: }
6200: }
6201: if (keys(%changes) > 0 || $colchgtext) {
6202: &Apache::loncommon::devalidate_domconfig_cache($dom);
6203: if (ref($lastactref) eq 'HASH') {
6204: $lastactref->{'domainconfig'} = 1;
6205: }
6206: $resulttext = &mt('Changes made:').'<ul>';
6207: foreach my $item (sort(keys(%changes))) {
6208: if ($item eq 'loginvia') {
6209: if (ref($changes{$item}) eq 'HASH') {
6210: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6211: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6212: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6213: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6214: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6215: $protocol = 'http' if ($protocol ne 'https');
6216: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6217:
6218: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6219: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6220: } else {
6221: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6222: }
6223: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6224: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6225: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6226: }
6227: $resulttext .= '</li>';
6228: } else {
6229: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6230: }
6231: } else {
6232: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
6233: }
6234: }
6235: $resulttext .= '</ul></li>';
6236: }
6237: } elsif ($item eq 'helpurl') {
6238: if (ref($changes{$item}) eq 'HASH') {
6239: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6240: if (grep(/^\Q$lang\E$/,@delurls)) {
6241: my ($chg,$link);
6242: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6243: if ($lang eq 'nolang') {
6244: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6245: } else {
6246: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6247: }
6248: $resulttext .= '<li>'.$chg.'</li>';
6249: } else {
6250: my $chg;
6251: if ($lang eq 'nolang') {
6252: $chg = &mt('custom log-in help file for no preferred language');
6253: } else {
6254: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6255: }
6256: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6257: $loginhash{'login'}{'helpurl'}{$lang}.
6258: '?inhibitmenu=yes',$chg,600,500).
6259: '</li>';
6260: }
6261: }
6262: }
6263: } elsif ($item eq 'headtag') {
6264: if (ref($changes{$item}) eq 'HASH') {
6265: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6266: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6267: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6268: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6269: $resulttext .= '<li><a href="'.
6270: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6271: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6272: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6273: if ($possexempt{$lonhost}) {
6274: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6275: } else {
6276: $resulttext .= &mt('included for any client IP');
6277: }
6278: $resulttext .= '</li>';
6279: }
6280: }
6281: }
6282: } elsif ($item eq 'captcha') {
6283: if (ref($loginhash{'login'}) eq 'HASH') {
6284: my $chgtxt;
6285: if ($loginhash{'login'}{$item} eq 'notused') {
6286: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6287: } else {
6288: my %captchas = &captcha_phrases();
6289: if ($captchas{$loginhash{'login'}{$item}}) {
6290: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6291: } else {
6292: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6293: }
6294: }
6295: $resulttext .= '<li>'.$chgtxt.'</li>';
6296: }
6297: } elsif ($item eq 'recaptchakeys') {
6298: if (ref($loginhash{'login'}) eq 'HASH') {
6299: my ($privkey,$pubkey);
6300: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6301: $pubkey = $loginhash{'login'}{$item}{'public'};
6302: $privkey = $loginhash{'login'}{$item}{'private'};
6303: }
6304: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6305: if (!$pubkey) {
6306: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6307: } else {
6308: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6309: }
6310: if (!$privkey) {
6311: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6312: } else {
6313: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
6314: }
6315: $chgtxt .= '</ul>';
6316: $resulttext .= '<li>'.$chgtxt.'</li>';
6317: }
6318: } else {
6319: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6320: }
6321: }
6322: $resulttext .= $colchgtext.'</ul>';
6323: } else {
6324: $resulttext = &mt('No changes made to log-in page settings');
6325: }
6326: } else {
6327: $resulttext = '<span class="LC_error">'.
6328: &mt('An error occurred: [_1]',$putresult).'</span>';
6329: }
6330: if ($errors) {
6331: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
6332: $errors.'</ul>';
6333: }
6334: return $resulttext;
6335: }
6336:
6337:
6338: sub check_exempt_addresses {
6339: my ($iplist) = @_;
6340: $iplist =~ s/^\s+//;
6341: $iplist =~ s/\s+$//;
6342: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6343: my (@okips,$new);
6344: foreach my $ip (@poss_ips) {
6345: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6346: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6347: push(@okips,$ip);
6348: }
6349: }
6350: }
6351: if (@okips > 0) {
6352: $new = join(',',@okips);
6353: } else {
6354: $new = '';
6355: }
6356: return $new;
6357: }
6358:
6359: sub color_font_choices {
6360: my %choices =
6361: &Apache::lonlocal::texthash (
6362: img => "Header",
6363: bgs => "Background colors",
6364: links => "Link colors",
6365: images => "Images",
6366: font => "Font color",
6367: fontmenu => "Font menu",
6368: pgbg => "Page",
6369: tabbg => "Header",
6370: sidebg => "Border",
6371: link => "Link",
6372: alink => "Active link",
6373: vlink => "Visited link",
6374: );
6375: return %choices;
6376: }
6377:
6378: sub modify_rolecolors {
6379: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
6380: my ($resulttext,%rolehash);
6381: $rolehash{'rolecolors'} = {};
6382: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6383: if ($domconfig{'rolecolors'} eq '') {
6384: $domconfig{'rolecolors'} = {};
6385: }
6386: }
6387: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
6388: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6389: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6390: $dom);
6391: if ($putresult eq 'ok') {
6392: if (keys(%changes) > 0) {
6393: &Apache::loncommon::devalidate_domconfig_cache($dom);
6394: if (ref($lastactref) eq 'HASH') {
6395: $lastactref->{'domainconfig'} = 1;
6396: }
6397: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6398: $rolehash{'rolecolors'});
6399: } else {
6400: $resulttext = &mt('No changes made to default color schemes');
6401: }
6402: } else {
6403: $resulttext = '<span class="LC_error">'.
6404: &mt('An error occurred: [_1]',$putresult).'</span>';
6405: }
6406: if ($errors) {
6407: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6408: $errors.'</ul>';
6409: }
6410: return $resulttext;
6411: }
6412:
6413: sub modify_colors {
6414: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
6415: my (%changes,%choices);
6416: my @bgs;
6417: my @links = ('link','alink','vlink');
6418: my @logintext;
6419: my @images;
6420: my $servadm = $r->dir_config('lonAdmEMail');
6421: my $errors;
6422: my %defaults;
6423: foreach my $role (@{$roles}) {
6424: if ($role eq 'login') {
6425: %choices = &login_choices();
6426: @logintext = ('textcol','bgcol');
6427: } else {
6428: %choices = &color_font_choices();
6429: }
6430: if ($role eq 'login') {
6431: @images = ('img','logo','domlogo','login');
6432: @bgs = ('pgbg','mainbg','sidebg');
6433: } else {
6434: @images = ('img');
6435: @bgs = ('pgbg','tabbg','sidebg');
6436: }
6437: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6438: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6439: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6440: }
6441: if ($role eq 'login') {
6442: foreach my $item (@logintext) {
6443: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6444: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6445: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6446: }
6447: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
6448: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6449: }
6450: }
6451: } else {
6452: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6453: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6454: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6455: }
6456: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
6457: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6458: }
6459: }
6460: foreach my $item (@bgs) {
6461: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6462: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6463: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6464: }
6465: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
6466: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6467: }
6468: }
6469: foreach my $item (@links) {
6470: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6471: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6472: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6473: }
6474: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
6475: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6476: }
6477: }
6478: my ($configuserok,$author_ok,$switchserver) =
6479: &config_check($dom,$confname,$servadm);
6480: my ($width,$height) = &thumb_dimensions();
6481: if (ref($domconfig->{$role}) ne 'HASH') {
6482: $domconfig->{$role} = {};
6483: }
6484: foreach my $img (@images) {
6485: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6486: if (defined($env{'form.login_showlogo_'.$img})) {
6487: $confhash->{$role}{'showlogo'}{$img} = 1;
6488: } else {
6489: $confhash->{$role}{'showlogo'}{$img} = 0;
6490: }
6491: }
6492: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6493: && !defined($domconfig->{$role}{$img})
6494: && !$env{'form.'.$role.'_del_'.$img}
6495: && $env{'form.'.$role.'_import_'.$img}) {
6496: # import the old configured image from the .tab setting
6497: # if they haven't provided a new one
6498: $domconfig->{$role}{$img} =
6499: $env{'form.'.$role.'_import_'.$img};
6500: }
6501: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
6502: my $error;
6503: if ($configuserok eq 'ok') {
6504: if ($switchserver) {
6505: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
6506: } else {
6507: if ($author_ok eq 'ok') {
6508: my ($result,$logourl) =
6509: &publishlogo($r,'upload',$role.'_'.$img,
6510: $dom,$confname,$img,$width,$height);
6511: if ($result eq 'ok') {
6512: $confhash->{$role}{$img} = $logourl;
6513: $changes{$role}{'images'}{$img} = 1;
6514: } else {
6515: $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);
6516: }
6517: } else {
6518: $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);
6519: }
6520: }
6521: } else {
6522: $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);
6523: }
6524: if ($error) {
6525: &Apache::lonnet::logthis($error);
6526: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6527: }
6528: } elsif ($domconfig->{$role}{$img} ne '') {
6529: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6530: my $error;
6531: if ($configuserok eq 'ok') {
6532: # is confname an author?
6533: if ($switchserver eq '') {
6534: if ($author_ok eq 'ok') {
6535: my ($result,$logourl) =
6536: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6537: $dom,$confname,$img,$width,$height);
6538: if ($result eq 'ok') {
6539: $confhash->{$role}{$img} = $logourl;
6540: $changes{$role}{'images'}{$img} = 1;
6541: }
6542: }
6543: }
6544: }
6545: }
6546: }
6547: }
6548: if (ref($domconfig) eq 'HASH') {
6549: if (ref($domconfig->{$role}) eq 'HASH') {
6550: foreach my $img (@images) {
6551: if ($domconfig->{$role}{$img} ne '') {
6552: if ($env{'form.'.$role.'_del_'.$img}) {
6553: $confhash->{$role}{$img} = '';
6554: $changes{$role}{'images'}{$img} = 1;
6555: } else {
6556: if ($confhash->{$role}{$img} eq '') {
6557: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6558: }
6559: }
6560: } else {
6561: if ($env{'form.'.$role.'_del_'.$img}) {
6562: $confhash->{$role}{$img} = '';
6563: $changes{$role}{'images'}{$img} = 1;
6564: }
6565: }
6566: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6567: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6568: if ($confhash->{$role}{'showlogo'}{$img} ne
6569: $domconfig->{$role}{'showlogo'}{$img}) {
6570: $changes{$role}{'showlogo'}{$img} = 1;
6571: }
6572: } else {
6573: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6574: $changes{$role}{'showlogo'}{$img} = 1;
6575: }
6576: }
6577: }
6578: }
6579: if ($domconfig->{$role}{'font'} ne '') {
6580: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6581: $changes{$role}{'font'} = 1;
6582: }
6583: } else {
6584: if ($confhash->{$role}{'font'}) {
6585: $changes{$role}{'font'} = 1;
6586: }
6587: }
6588: if ($role ne 'login') {
6589: if ($domconfig->{$role}{'fontmenu'} ne '') {
6590: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6591: $changes{$role}{'fontmenu'} = 1;
6592: }
6593: } else {
6594: if ($confhash->{$role}{'fontmenu'}) {
6595: $changes{$role}{'fontmenu'} = 1;
6596: }
6597: }
6598: }
6599: foreach my $item (@bgs) {
6600: if ($domconfig->{$role}{$item} ne '') {
6601: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6602: $changes{$role}{'bgs'}{$item} = 1;
6603: }
6604: } else {
6605: if ($confhash->{$role}{$item}) {
6606: $changes{$role}{'bgs'}{$item} = 1;
6607: }
6608: }
6609: }
6610: foreach my $item (@links) {
6611: if ($domconfig->{$role}{$item} ne '') {
6612: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6613: $changes{$role}{'links'}{$item} = 1;
6614: }
6615: } else {
6616: if ($confhash->{$role}{$item}) {
6617: $changes{$role}{'links'}{$item} = 1;
6618: }
6619: }
6620: }
6621: foreach my $item (@logintext) {
6622: if ($domconfig->{$role}{$item} ne '') {
6623: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6624: $changes{$role}{'logintext'}{$item} = 1;
6625: }
6626: } else {
6627: if ($confhash->{$role}{$item}) {
6628: $changes{$role}{'logintext'}{$item} = 1;
6629: }
6630: }
6631: }
6632: } else {
6633: &default_change_checker($role,\@images,\@links,\@bgs,
6634: \@logintext,$confhash,\%changes);
6635: }
6636: } else {
6637: &default_change_checker($role,\@images,\@links,\@bgs,
6638: \@logintext,$confhash,\%changes);
6639: }
6640: }
6641: return ($errors,%changes);
6642: }
6643:
6644: sub config_check {
6645: my ($dom,$confname,$servadm) = @_;
6646: my ($configuserok,$author_ok,$switchserver,%currroles);
6647: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6648: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6649: $confname,$servadm);
6650: if ($configuserok eq 'ok') {
6651: $switchserver = &check_switchserver($dom,$confname);
6652: if ($switchserver eq '') {
6653: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6654: }
6655: }
6656: return ($configuserok,$author_ok,$switchserver);
6657: }
6658:
6659: sub default_change_checker {
6660: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
6661: foreach my $item (@{$links}) {
6662: if ($confhash->{$role}{$item}) {
6663: $changes->{$role}{'links'}{$item} = 1;
6664: }
6665: }
6666: foreach my $item (@{$bgs}) {
6667: if ($confhash->{$role}{$item}) {
6668: $changes->{$role}{'bgs'}{$item} = 1;
6669: }
6670: }
6671: foreach my $item (@{$logintext}) {
6672: if ($confhash->{$role}{$item}) {
6673: $changes->{$role}{'logintext'}{$item} = 1;
6674: }
6675: }
6676: foreach my $img (@{$images}) {
6677: if ($env{'form.'.$role.'_del_'.$img}) {
6678: $confhash->{$role}{$img} = '';
6679: $changes->{$role}{'images'}{$img} = 1;
6680: }
6681: if ($role eq 'login') {
6682: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6683: $changes->{$role}{'showlogo'}{$img} = 1;
6684: }
6685: }
6686: }
6687: if ($confhash->{$role}{'font'}) {
6688: $changes->{$role}{'font'} = 1;
6689: }
6690: }
6691:
6692: sub display_colorchgs {
6693: my ($dom,$changes,$roles,$confhash) = @_;
6694: my (%choices,$resulttext);
6695: if (!grep(/^login$/,@{$roles})) {
6696: $resulttext = &mt('Changes made:').'<br />';
6697: }
6698: foreach my $role (@{$roles}) {
6699: if ($role eq 'login') {
6700: %choices = &login_choices();
6701: } else {
6702: %choices = &color_font_choices();
6703: }
6704: if (ref($changes->{$role}) eq 'HASH') {
6705: if ($role ne 'login') {
6706: $resulttext .= '<h4>'.&mt($role).'</h4>';
6707: }
6708: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6709: if ($role ne 'login') {
6710: $resulttext .= '<ul>';
6711: }
6712: if (ref($changes->{$role}{$key}) eq 'HASH') {
6713: if ($role ne 'login') {
6714: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6715: }
6716: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
6717: if (($role eq 'login') && ($key eq 'showlogo')) {
6718: if ($confhash->{$role}{$key}{$item}) {
6719: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6720: } else {
6721: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6722: }
6723: } elsif ($confhash->{$role}{$item} eq '') {
6724: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6725: } else {
6726: my $newitem = $confhash->{$role}{$item};
6727: if ($key eq 'images') {
6728: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6729: }
6730: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
6731: }
6732: }
6733: if ($role ne 'login') {
6734: $resulttext .= '</ul></li>';
6735: }
6736: } else {
6737: if ($confhash->{$role}{$key} eq '') {
6738: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6739: } else {
6740: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6741: }
6742: }
6743: if ($role ne 'login') {
6744: $resulttext .= '</ul>';
6745: }
6746: }
6747: }
6748: }
6749: return $resulttext;
6750: }
6751:
6752: sub thumb_dimensions {
6753: return ('200','50');
6754: }
6755:
6756: sub check_dimensions {
6757: my ($inputfile) = @_;
6758: my ($fullwidth,$fullheight);
6759: if ($inputfile =~ m|^[/\w.\-]+$|) {
6760: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6761: my $imageinfo = <PIPE>;
6762: if (!close(PIPE)) {
6763: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6764: }
6765: chomp($imageinfo);
6766: my ($fullsize) =
6767: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
6768: if ($fullsize) {
6769: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6770: }
6771: }
6772: }
6773: return ($fullwidth,$fullheight);
6774: }
6775:
6776: sub check_configuser {
6777: my ($uhome,$dom,$confname,$servadm) = @_;
6778: my ($configuserok,%currroles);
6779: if ($uhome eq 'no_host') {
6780: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6781: my $configpass = &LONCAPA::Enrollment::create_password();
6782: $configuserok =
6783: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6784: $configpass,'','','','','',undef,$servadm);
6785: } else {
6786: $configuserok = 'ok';
6787: %currroles =
6788: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6789: }
6790: return ($configuserok,%currroles);
6791: }
6792:
6793: sub check_authorstatus {
6794: my ($dom,$confname,%currroles) = @_;
6795: my $author_ok;
6796: if (!$currroles{':'.$dom.':au'}) {
6797: my $start = time;
6798: my $end = 0;
6799: $author_ok =
6800: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
6801: 'au',$end,$start,'','','domconfig');
6802: } else {
6803: $author_ok = 'ok';
6804: }
6805: return $author_ok;
6806: }
6807:
6808: sub publishlogo {
6809: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
6810: my ($output,$fname,$logourl);
6811: if ($action eq 'upload') {
6812: $fname=$env{'form.'.$formname.'.filename'};
6813: chop($env{'form.'.$formname});
6814: } else {
6815: ($fname) = ($formname =~ /([^\/]+)$/);
6816: }
6817: if ($savefileas ne '') {
6818: $fname = $savefileas;
6819: }
6820: $fname=&Apache::lonnet::clean_filename($fname);
6821: # See if there is anything left
6822: unless ($fname) { return ('error: no uploaded file'); }
6823: $fname="$subdir/$fname";
6824: my $docroot=$r->dir_config('lonDocRoot');
6825: my $filepath="$docroot/priv";
6826: my $relpath = "$dom/$confname";
6827: my ($fnamepath,$file,$fetchthumb);
6828: $file=$fname;
6829: if ($fname=~m|/|) {
6830: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6831: }
6832: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
6833: my $count;
6834: for ($count=5;$count<=$#parts;$count++) {
6835: $filepath.="/$parts[$count]";
6836: if ((-e $filepath)!=1) {
6837: mkdir($filepath,02770);
6838: }
6839: }
6840: # Check for bad extension and disallow upload
6841: if ($file=~/\.(\w+)$/ &&
6842: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6843: $output =
6844: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
6845: } elsif ($file=~/\.(\w+)$/ &&
6846: !defined(&Apache::loncommon::fileembstyle($1))) {
6847: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6848: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
6849: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
6850: } elsif (-d "$filepath/$file") {
6851: $output = &mt('Filename is a directory name - rename the file and re-upload');
6852: } else {
6853: my $source = $filepath.'/'.$file;
6854: my $logfile;
6855: if (!open($logfile,">>$source".'.log')) {
6856: return (&mt('No write permission to Authoring Space'));
6857: }
6858: print $logfile
6859: "\n================= Publish ".localtime()." ================\n".
6860: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6861: # Save the file
6862: if (!open(FH,'>'.$source)) {
6863: &Apache::lonnet::logthis('Failed to create '.$source);
6864: return (&mt('Failed to create file'));
6865: }
6866: if ($action eq 'upload') {
6867: if (!print FH ($env{'form.'.$formname})) {
6868: &Apache::lonnet::logthis('Failed to write to '.$source);
6869: return (&mt('Failed to write file'));
6870: }
6871: } else {
6872: my $original = &Apache::lonnet::filelocation('',$formname);
6873: if(!copy($original,$source)) {
6874: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6875: return (&mt('Failed to write file'));
6876: }
6877: }
6878: close(FH);
6879: chmod(0660, $source); # Permissions to rw-rw---.
6880:
6881: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6882: my $copyfile=$targetdir.'/'.$file;
6883:
6884: my @parts=split(/\//,$targetdir);
6885: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6886: for (my $count=5;$count<=$#parts;$count++) {
6887: $path.="/$parts[$count]";
6888: if (!-e $path) {
6889: print $logfile "\nCreating directory ".$path;
6890: mkdir($path,02770);
6891: }
6892: }
6893: my $versionresult;
6894: if (-e $copyfile) {
6895: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6896: } else {
6897: $versionresult = 'ok';
6898: }
6899: if ($versionresult eq 'ok') {
6900: if (copy($source,$copyfile)) {
6901: print $logfile "\nCopied original source to ".$copyfile."\n";
6902: $output = 'ok';
6903: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
6904: push(@{$modified_urls},[$copyfile,$source]);
6905: my $metaoutput =
6906: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6907: unless ($registered_cleanup) {
6908: my $handlers = $r->get_handlers('PerlCleanupHandler');
6909: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6910: $registered_cleanup=1;
6911: }
6912: } else {
6913: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6914: $output = &mt('Failed to copy file to RES space').", $!";
6915: }
6916: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6917: my $inputfile = $filepath.'/'.$file;
6918: my $outfile = $filepath.'/'.'tn-'.$file;
6919: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6920: if ($fullwidth ne '' && $fullheight ne '') {
6921: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6922: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6923: system("convert -sample $thumbsize $inputfile $outfile");
6924: chmod(0660, $filepath.'/tn-'.$file);
6925: if (-e $outfile) {
6926: my $copyfile=$targetdir.'/tn-'.$file;
6927: if (copy($outfile,$copyfile)) {
6928: print $logfile "\nCopied source to ".$copyfile."\n";
6929: my $thumb_metaoutput =
6930: &write_metadata($dom,$confname,$formname,
6931: $targetdir,'tn-'.$file,$logfile);
6932: push(@{$modified_urls},[$copyfile,$outfile]);
6933: unless ($registered_cleanup) {
6934: my $handlers = $r->get_handlers('PerlCleanupHandler');
6935: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6936: $registered_cleanup=1;
6937: }
6938: } else {
6939: print $logfile "\nUnable to write ".$copyfile.
6940: ':'.$!."\n";
6941: }
6942: }
6943: }
6944: }
6945: }
6946: } else {
6947: $output = $versionresult;
6948: }
6949: }
6950: return ($output,$logourl);
6951: }
6952:
6953: sub logo_versioning {
6954: my ($targetdir,$file,$logfile) = @_;
6955: my $target = $targetdir.'/'.$file;
6956: my ($maxversion,$fn,$extn,$output);
6957: $maxversion = 0;
6958: if ($file =~ /^(.+)\.(\w+)$/) {
6959: $fn=$1;
6960: $extn=$2;
6961: }
6962: opendir(DIR,$targetdir);
6963: while (my $filename=readdir(DIR)) {
6964: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6965: $maxversion=($1>$maxversion)?$1:$maxversion;
6966: }
6967: }
6968: $maxversion++;
6969: print $logfile "\nCreating old version ".$maxversion."\n";
6970: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6971: if (copy($target,$copyfile)) {
6972: print $logfile "Copied old target to ".$copyfile."\n";
6973: $copyfile=$copyfile.'.meta';
6974: if (copy($target.'.meta',$copyfile)) {
6975: print $logfile "Copied old target metadata to ".$copyfile."\n";
6976: $output = 'ok';
6977: } else {
6978: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6979: $output = &mt('Failed to copy old meta').", $!, ";
6980: }
6981: } else {
6982: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6983: $output = &mt('Failed to copy old target').", $!, ";
6984: }
6985: return $output;
6986: }
6987:
6988: sub write_metadata {
6989: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6990: my (%metadatafields,%metadatakeys,$output);
6991: $metadatafields{'title'}=$formname;
6992: $metadatafields{'creationdate'}=time;
6993: $metadatafields{'lastrevisiondate'}=time;
6994: $metadatafields{'copyright'}='public';
6995: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6996: $env{'user.domain'};
6997: $metadatafields{'authorspace'}=$confname.':'.$dom;
6998: $metadatafields{'domain'}=$dom;
6999: {
7000: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7001: my $mfh;
7002: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
7003: foreach (sort(keys(%metadatafields))) {
7004: unless ($_=~/\./) {
7005: my $unikey=$_;
7006: $unikey=~/^([A-Za-z]+)/;
7007: my $tag=$1;
7008: $tag=~tr/A-Z/a-z/;
7009: print $mfh "\n\<$tag";
7010: foreach (split(/\,/,$metadatakeys{$unikey})) {
7011: my $value=$metadatafields{$unikey.'.'.$_};
7012: $value=~s/\"/\'\'/g;
7013: print $mfh ' '.$_.'="'.$value.'"';
7014: }
7015: print $mfh '>'.
7016: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7017: .'</'.$tag.'>';
7018: }
7019: }
7020: $output = 'ok';
7021: print $logfile "\nWrote metadata";
7022: close($mfh);
7023: } else {
7024: print $logfile "\nFailed to open metadata file";
7025: $output = &mt('Could not write metadata');
7026: }
7027: }
7028: return $output;
7029: }
7030:
7031: sub notifysubscribed {
7032: foreach my $targetsource (@{$modified_urls}){
7033: next unless (ref($targetsource) eq 'ARRAY');
7034: my ($target,$source)=@{$targetsource};
7035: if ($source ne '') {
7036: if (open(my $logfh,'>>'.$source.'.log')) {
7037: print $logfh "\nCleanup phase: Notifications\n";
7038: my @subscribed=&subscribed_hosts($target);
7039: foreach my $subhost (@subscribed) {
7040: print $logfh "\nNotifying host ".$subhost.':';
7041: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7042: print $logfh $reply;
7043: }
7044: my @subscribedmeta=&subscribed_hosts("$target.meta");
7045: foreach my $subhost (@subscribedmeta) {
7046: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7047: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7048: $subhost);
7049: print $logfh $reply;
7050: }
7051: print $logfh "\n============ Done ============\n";
7052: close($logfh);
7053: }
7054: }
7055: }
7056: return OK;
7057: }
7058:
7059: sub subscribed_hosts {
7060: my ($target) = @_;
7061: my @subscribed;
7062: if (open(my $fh,"<$target.subscription")) {
7063: while (my $subline=<$fh>) {
7064: if ($subline =~ /^($match_lonid):/) {
7065: my $host = $1;
7066: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7067: unless (grep(/^\Q$host\E$/,@subscribed)) {
7068: push(@subscribed,$host);
7069: }
7070: }
7071: }
7072: }
7073: }
7074: return @subscribed;
7075: }
7076:
7077: sub check_switchserver {
7078: my ($dom,$confname) = @_;
7079: my ($allowed,$switchserver);
7080: my $home = &Apache::lonnet::homeserver($confname,$dom);
7081: if ($home eq 'no_host') {
7082: $home = &Apache::lonnet::domain($dom,'primary');
7083: }
7084: my @ids=&Apache::lonnet::current_machine_ids();
7085: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7086: if (!$allowed) {
7087: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
7088: }
7089: return $switchserver;
7090: }
7091:
7092: sub modify_quotas {
7093: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
7094: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
7095: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
7096: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7097: $validationfieldsref);
7098: if ($action eq 'quotas') {
7099: $context = 'tools';
7100: } else {
7101: $context = $action;
7102: }
7103: if ($context eq 'requestcourses') {
7104: @usertools = ('official','unofficial','community','textbook');
7105: @options =('norequest','approval','validate','autolimit');
7106: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7107: %titles = &courserequest_titles();
7108: $toolregexp = join('|',@usertools);
7109: %conditions = &courserequest_conditions();
7110: $confname = $dom.'-domainconfig';
7111: my $servadm = $r->dir_config('lonAdmEMail');
7112: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7113: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7114: &Apache::loncoursequeueadmin::requestcourses_validation_types();
7115: } elsif ($context eq 'requestauthor') {
7116: @usertools = ('author');
7117: %titles = &authorrequest_titles();
7118: } else {
7119: @usertools = ('aboutme','blog','webdav','portfolio');
7120: %titles = &tool_titles();
7121: }
7122: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7123: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7124: foreach my $key (keys(%env)) {
7125: if ($context eq 'requestcourses') {
7126: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7127: my $item = $1;
7128: my $type = $2;
7129: if ($type =~ /^limit_(.+)/) {
7130: $limithash{$item}{$1} = $env{$key};
7131: } else {
7132: $confhash{$item}{$type} = $env{$key};
7133: }
7134: }
7135: } elsif ($context eq 'requestauthor') {
7136: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7137: $confhash{$1} = $env{$key};
7138: }
7139: } else {
7140: if ($key =~ /^form\.quota_(.+)$/) {
7141: $confhash{'defaultquota'}{$1} = $env{$key};
7142: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7143: $confhash{'authorquota'}{$1} = $env{$key};
7144: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
7145: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7146: }
7147: }
7148: }
7149: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
7150: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
7151: @approvalnotify = sort(@approvalnotify);
7152: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
7153: my @crstypes = ('official','unofficial','community','textbook');
7154: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7155: foreach my $type (@hasuniquecode) {
7156: if (grep(/^\Q$type\E$/,@crstypes)) {
7157: $confhash{'uniquecode'}{$type} = 1;
7158: }
7159: }
7160: my (%newbook,%allpos);
7161: if ($context eq 'requestcourses') {
7162: foreach my $type ('textbooks','templates') {
7163: @{$allpos{$type}} = ();
7164: my $invalid;
7165: if ($type eq 'textbooks') {
7166: $invalid = &mt('Invalid LON-CAPA course for textbook');
7167: } else {
7168: $invalid = &mt('Invalid LON-CAPA course for template');
7169: }
7170: if ($env{'form.'.$type.'_addbook'}) {
7171: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7172: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7173: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7174: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7175: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7176: } else {
7177: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7178: my $position = $env{'form.'.$type.'_addbook_pos'};
7179: $position =~ s/\D+//g;
7180: if ($position ne '') {
7181: $allpos{$type}[$position] = $newbook{$type};
7182: }
7183: }
7184: } else {
7185: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7186: }
7187: }
7188: }
7189: }
7190: if (ref($domconfig{$action}) eq 'HASH') {
7191: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7192: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7193: $changes{'notify'}{'approval'} = 1;
7194: }
7195: } else {
7196: if ($confhash{'notify'}{'approval'}) {
7197: $changes{'notify'}{'approval'} = 1;
7198: }
7199: }
7200: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7201: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7202: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7203: unless ($confhash{'uniquecode'}{$crstype}) {
7204: $changes{'uniquecode'} = 1;
7205: }
7206: }
7207: unless ($changes{'uniquecode'}) {
7208: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7209: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7210: $changes{'uniquecode'} = 1;
7211: }
7212: }
7213: }
7214: } else {
7215: $changes{'uniquecode'} = 1;
7216: }
7217: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7218: $changes{'uniquecode'} = 1;
7219: }
7220: if ($context eq 'requestcourses') {
7221: foreach my $type ('textbooks','templates') {
7222: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7223: my %deletions;
7224: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7225: if (@todelete) {
7226: map { $deletions{$_} = 1; } @todelete;
7227: }
7228: my %imgdeletions;
7229: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7230: if (@todeleteimages) {
7231: map { $imgdeletions{$_} = 1; } @todeleteimages;
7232: }
7233: my $maxnum = $env{'form.'.$type.'_maxnum'};
7234: for (my $i=0; $i<=$maxnum; $i++) {
7235: my $itemid = $env{'form.'.$type.'_id_'.$i};
7236: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7237: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7238: if ($deletions{$key}) {
7239: if ($domconfig{$action}{$type}{$key}{'image'}) {
7240: #FIXME need to obsolete item in RES space
7241: }
7242: next;
7243: } else {
7244: my $newpos = $env{'form.'.$itemid};
7245: $newpos =~ s/\D+//g;
7246: foreach my $item ('subject','title','publisher','author') {
7247: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7248: ($type eq 'templates'));
7249: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7250: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7251: $changes{$type}{$key} = 1;
7252: }
7253: }
7254: $allpos{$type}[$newpos] = $key;
7255: }
7256: if ($imgdeletions{$key}) {
7257: $changes{$type}{$key} = 1;
7258: #FIXME need to obsolete item in RES space
7259: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7260: my ($cdom,$cnum) = split(/_/,$key);
7261: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7262: $cdom,$cnum,$type,$configuserok,
7263: $switchserver,$author_ok);
7264: if ($imgurl) {
7265: $confhash{$type}{$key}{'image'} = $imgurl;
7266: $changes{$type}{$key} = 1;
7267: }
7268: if ($error) {
7269: &Apache::lonnet::logthis($error);
7270: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7271: }
7272: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7273: $confhash{$type}{$key}{'image'} =
7274: $domconfig{$action}{$type}{$key}{'image'};
7275: }
7276: }
7277: }
7278: }
7279: }
7280: }
7281: } else {
7282: if ($confhash{'notify'}{'approval'}) {
7283: $changes{'notify'}{'approval'} = 1;
7284: }
7285: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7286: $changes{'uniquecode'} = 1;
7287: }
7288: }
7289: if ($context eq 'requestcourses') {
7290: foreach my $type ('textbooks','templates') {
7291: if ($newbook{$type}) {
7292: $changes{$type}{$newbook{$type}} = 1;
7293: foreach my $item ('subject','title','publisher','author') {
7294: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7295: ($type eq 'template'));
7296: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7297: if ($env{'form.'.$type.'_addbook_'.$item}) {
7298: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7299: }
7300: }
7301: if ($type eq 'textbooks') {
7302: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7303: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7304: my ($imageurl,$error) =
7305: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7306: $configuserok,$switchserver,$author_ok);
7307: if ($imageurl) {
7308: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7309: }
7310: if ($error) {
7311: &Apache::lonnet::logthis($error);
7312: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7313: }
7314: }
7315: }
7316: }
7317: if (@{$allpos{$type}} > 0) {
7318: my $idx = 0;
7319: foreach my $item (@{$allpos{$type}}) {
7320: if ($item ne '') {
7321: $confhash{$type}{$item}{'order'} = $idx;
7322: if (ref($domconfig{$action}) eq 'HASH') {
7323: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7324: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7325: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7326: $changes{$type}{$item} = 1;
7327: }
7328: }
7329: }
7330: }
7331: $idx ++;
7332: }
7333: }
7334: }
7335: }
7336: if (ref($validationitemsref) eq 'ARRAY') {
7337: foreach my $item (@{$validationitemsref}) {
7338: if ($item eq 'fields') {
7339: my @changed;
7340: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7341: if (@{$confhash{'validation'}{$item}} > 0) {
7342: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7343: }
7344: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7345: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7346: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7347: $domconfig{'requestcourses'}{'validation'}{$item});
7348: } else {
7349: @changed = @{$confhash{'validation'}{$item}};
7350: }
7351: } else {
7352: @changed = @{$confhash{'validation'}{$item}};
7353: }
7354: if (@changed) {
7355: if ($confhash{'validation'}{$item}) {
7356: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7357: } else {
7358: $changes{'validation'}{$item} = &mt('None');
7359: }
7360: }
7361: } else {
7362: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7363: if ($item eq 'markup') {
7364: if ($env{'form.requestcourses_validation_'.$item}) {
7365: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7366: }
7367: }
7368: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7369: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7370: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7371: }
7372: } else {
7373: if ($confhash{'validation'}{$item} ne '') {
7374: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7375: }
7376: }
7377: }
7378: }
7379: }
7380: if ($env{'form.validationdc'}) {
7381: my $newval = $env{'form.validationdc'};
7382: my %domcoords = &get_active_dcs($dom);
7383: if (exists($domcoords{$newval})) {
7384: $confhash{'validation'}{'dc'} = $newval;
7385: }
7386: }
7387: if (ref($confhash{'validation'}) eq 'HASH') {
7388: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7389: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7390: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7391: if ($confhash{'validation'}{'dc'} eq '') {
7392: $changes{'validation'}{'dc'} = &mt('None');
7393: } else {
7394: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7395: }
7396: }
7397: } elsif ($confhash{'validation'}{'dc'} ne '') {
7398: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7399: }
7400: } elsif ($confhash{'validation'}{'dc'} ne '') {
7401: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7402: }
7403: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7404: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7405: $changes{'validation'}{'dc'} = &mt('None');
7406: }
7407: }
7408: }
7409: } else {
7410: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
7411: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
7412: }
7413: foreach my $item (@usertools) {
7414: foreach my $type (@{$types},'default','_LC_adv') {
7415: my $unset;
7416: if ($context eq 'requestcourses') {
7417: $unset = '0';
7418: if ($type eq '_LC_adv') {
7419: $unset = '';
7420: }
7421: if ($confhash{$item}{$type} eq 'autolimit') {
7422: $confhash{$item}{$type} .= '=';
7423: unless ($limithash{$item}{$type} =~ /\D/) {
7424: $confhash{$item}{$type} .= $limithash{$item}{$type};
7425: }
7426: }
7427: } elsif ($context eq 'requestauthor') {
7428: $unset = '0';
7429: if ($type eq '_LC_adv') {
7430: $unset = '';
7431: }
7432: } else {
7433: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7434: $confhash{$item}{$type} = 1;
7435: } else {
7436: $confhash{$item}{$type} = 0;
7437: }
7438: }
7439: if (ref($domconfig{$action}) eq 'HASH') {
7440: if ($action eq 'requestauthor') {
7441: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7442: $changes{$type} = 1;
7443: }
7444: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
7445: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7446: $changes{$item}{$type} = 1;
7447: }
7448: } else {
7449: if ($context eq 'requestcourses') {
7450: if ($confhash{$item}{$type} ne $unset) {
7451: $changes{$item}{$type} = 1;
7452: }
7453: } else {
7454: if (!$confhash{$item}{$type}) {
7455: $changes{$item}{$type} = 1;
7456: }
7457: }
7458: }
7459: } else {
7460: if ($context eq 'requestcourses') {
7461: if ($confhash{$item}{$type} ne $unset) {
7462: $changes{$item}{$type} = 1;
7463: }
7464: } elsif ($context eq 'requestauthor') {
7465: if ($confhash{$type} ne $unset) {
7466: $changes{$type} = 1;
7467: }
7468: } else {
7469: if (!$confhash{$item}{$type}) {
7470: $changes{$item}{$type} = 1;
7471: }
7472: }
7473: }
7474: }
7475: }
7476: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
7477: if (ref($domconfig{'quotas'}) eq 'HASH') {
7478: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7479: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7480: if (exists($confhash{'defaultquota'}{$key})) {
7481: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7482: $changes{'defaultquota'}{$key} = 1;
7483: }
7484: } else {
7485: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
7486: }
7487: }
7488: } else {
7489: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7490: if (exists($confhash{'defaultquota'}{$key})) {
7491: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7492: $changes{'defaultquota'}{$key} = 1;
7493: }
7494: } else {
7495: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
7496: }
7497: }
7498: }
7499: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7500: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7501: if (exists($confhash{'authorquota'}{$key})) {
7502: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7503: $changes{'authorquota'}{$key} = 1;
7504: }
7505: } else {
7506: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7507: }
7508: }
7509: }
7510: }
7511: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7512: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7513: if (ref($domconfig{'quotas'}) eq 'HASH') {
7514: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7515: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7516: $changes{'defaultquota'}{$key} = 1;
7517: }
7518: } else {
7519: if (!exists($domconfig{'quotas'}{$key})) {
7520: $changes{'defaultquota'}{$key} = 1;
7521: }
7522: }
7523: } else {
7524: $changes{'defaultquota'}{$key} = 1;
7525: }
7526: }
7527: }
7528: if (ref($confhash{'authorquota'}) eq 'HASH') {
7529: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7530: if (ref($domconfig{'quotas'}) eq 'HASH') {
7531: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7532: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7533: $changes{'authorquota'}{$key} = 1;
7534: }
7535: } else {
7536: $changes{'authorquota'}{$key} = 1;
7537: }
7538: } else {
7539: $changes{'authorquota'}{$key} = 1;
7540: }
7541: }
7542: }
7543: }
7544:
7545: if ($context eq 'requestauthor') {
7546: $domdefaults{'requestauthor'} = \%confhash;
7547: } else {
7548: foreach my $key (keys(%confhash)) {
7549: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
7550: $domdefaults{$key} = $confhash{$key};
7551: }
7552: }
7553: }
7554:
7555: my %quotahash = (
7556: $action => { %confhash }
7557: );
7558: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7559: $dom);
7560: if ($putresult eq 'ok') {
7561: if (keys(%changes) > 0) {
7562: my $cachetime = 24*60*60;
7563: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7564: if (ref($lastactref) eq 'HASH') {
7565: $lastactref->{'domdefaults'} = 1;
7566: }
7567: $resulttext = &mt('Changes made:').'<ul>';
7568: unless (($context eq 'requestcourses') ||
7569: ($context eq 'requestauthor')) {
7570: if (ref($changes{'defaultquota'}) eq 'HASH') {
7571: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7572: foreach my $type (@{$types},'default') {
7573: if (defined($changes{'defaultquota'}{$type})) {
7574: my $typetitle = $usertypes->{$type};
7575: if ($type eq 'default') {
7576: $typetitle = $othertitle;
7577: }
7578: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
7579: }
7580: }
7581: $resulttext .= '</ul></li>';
7582: }
7583: if (ref($changes{'authorquota'}) eq 'HASH') {
7584: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
7585: foreach my $type (@{$types},'default') {
7586: if (defined($changes{'authorquota'}{$type})) {
7587: my $typetitle = $usertypes->{$type};
7588: if ($type eq 'default') {
7589: $typetitle = $othertitle;
7590: }
7591: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
7592: }
7593: }
7594: $resulttext .= '</ul></li>';
7595: }
7596: }
7597: my %newenv;
7598: foreach my $item (@usertools) {
7599: my (%haschgs,%inconf);
7600: if ($context eq 'requestauthor') {
7601: %haschgs = %changes;
7602: %inconf = %confhash;
7603: } else {
7604: if (ref($changes{$item}) eq 'HASH') {
7605: %haschgs = %{$changes{$item}};
7606: }
7607: if (ref($confhash{$item}) eq 'HASH') {
7608: %inconf = %{$confhash{$item}};
7609: }
7610: }
7611: if (keys(%haschgs) > 0) {
7612: my $newacc =
7613: &Apache::lonnet::usertools_access($env{'user.name'},
7614: $env{'user.domain'},
7615: $item,'reload',$context);
7616: if (($context eq 'requestcourses') ||
7617: ($context eq 'requestauthor')) {
7618: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7619: $newenv{'environment.canrequest.'.$item} = $newacc;
7620: }
7621: } else {
7622: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7623: $newenv{'environment.availabletools.'.$item} = $newacc;
7624: }
7625: }
7626: unless ($context eq 'requestauthor') {
7627: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7628: }
7629: foreach my $type (@{$types},'default','_LC_adv') {
7630: if ($haschgs{$type}) {
7631: my $typetitle = $usertypes->{$type};
7632: if ($type eq 'default') {
7633: $typetitle = $othertitle;
7634: } elsif ($type eq '_LC_adv') {
7635: $typetitle = 'LON-CAPA Advanced Users';
7636: }
7637: if ($inconf{$type}) {
7638: if ($context eq 'requestcourses') {
7639: my $cond;
7640: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
7641: if ($1 eq '') {
7642: $cond = &mt('(Automatic processing of any request).');
7643: } else {
7644: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7645: }
7646: } else {
7647: $cond = $conditions{$inconf{$type}};
7648: }
7649: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
7650: } elsif ($context eq 'requestauthor') {
7651: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7652: $titles{$inconf{$type}},$typetitle);
7653:
7654: } else {
7655: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7656: }
7657: } else {
7658: if ($type eq '_LC_adv') {
7659: if ($inconf{$type} eq '0') {
7660: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7661: } else {
7662: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7663: }
7664: } else {
7665: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7666: }
7667: }
7668: }
7669: }
7670: unless ($context eq 'requestauthor') {
7671: $resulttext .= '</ul></li>';
7672: }
7673: }
7674: }
7675: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
7676: if (ref($changes{'notify'}) eq 'HASH') {
7677: if ($changes{'notify'}{'approval'}) {
7678: if (ref($confhash{'notify'}) eq 'HASH') {
7679: if ($confhash{'notify'}{'approval'}) {
7680: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7681: } else {
7682: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
7683: }
7684: }
7685: }
7686: }
7687: }
7688: if ($action eq 'requestcourses') {
7689: my @offon = ('off','on');
7690: if ($changes{'uniquecode'}) {
7691: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7692: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7693: $resulttext .= '<li>'.
7694: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7695: '</li>';
7696: } else {
7697: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7698: '</li>';
7699: }
7700: }
7701: foreach my $type ('textbooks','templates') {
7702: if (ref($changes{$type}) eq 'HASH') {
7703: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7704: foreach my $key (sort(keys(%{$changes{$type}}))) {
7705: my %coursehash = &Apache::lonnet::coursedescription($key);
7706: my $coursetitle = $coursehash{'description'};
7707: my $position = $confhash{$type}{$key}{'order'} + 1;
7708: $resulttext .= '<li>';
7709: foreach my $item ('subject','title','publisher','author') {
7710: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7711: ($type eq 'templates'));
7712: my $name = $item.':';
7713: $name =~ s/^(\w)/\U$1/;
7714: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7715: }
7716: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7717: if ($type eq 'textbooks') {
7718: if ($confhash{$type}{$key}{'image'}) {
7719: $resulttext .= ' '.&mt('Image: [_1]',
7720: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7721: ' alt="Textbook cover" />').'<br />';
7722: }
7723: }
7724: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
7725: }
7726: $resulttext .= '</ul></li>';
7727: }
7728: }
7729: if (ref($changes{'validation'}) eq 'HASH') {
7730: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7731: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7732: foreach my $item (@{$validationitemsref}) {
7733: if (exists($changes{'validation'}{$item})) {
7734: if ($item eq 'markup') {
7735: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7736: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7737: } else {
7738: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7739: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7740: }
7741: }
7742: }
7743: if (exists($changes{'validation'}{'dc'})) {
7744: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7745: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7746: }
7747: }
7748: }
7749: }
7750: $resulttext .= '</ul>';
7751: if (keys(%newenv)) {
7752: &Apache::lonnet::appenv(\%newenv);
7753: }
7754: } else {
7755: if ($context eq 'requestcourses') {
7756: $resulttext = &mt('No changes made to rights to request creation of courses.');
7757: } elsif ($context eq 'requestauthor') {
7758: $resulttext = &mt('No changes made to rights to request author space.');
7759: } else {
7760: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
7761: }
7762: }
7763: } else {
7764: $resulttext = '<span class="LC_error">'.
7765: &mt('An error occurred: [_1]',$putresult).'</span>';
7766: }
7767: if ($errors) {
7768: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7769: '<ul>'.$errors.'</ul></p>';
7770: }
7771: return $resulttext;
7772: }
7773:
7774: sub process_textbook_image {
7775: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
7776: my $filename = $env{'form.'.$caller.'.filename'};
7777: my ($error,$url);
7778: my ($width,$height) = (50,50);
7779: if ($configuserok eq 'ok') {
7780: if ($switchserver) {
7781: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7782: $switchserver);
7783: } elsif ($author_ok eq 'ok') {
7784: my ($result,$imageurl) =
7785: &publishlogo($r,'upload',$caller,$dom,$confname,
7786: "$type/$dom/$cnum/cover",$width,$height);
7787: if ($result eq 'ok') {
7788: $url = $imageurl;
7789: } else {
7790: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7791: }
7792: } else {
7793: $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);
7794: }
7795: } else {
7796: $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);
7797: }
7798: return ($url,$error);
7799: }
7800:
7801: sub modify_autoenroll {
7802: my ($dom,$lastactref,%domconfig) = @_;
7803: my ($resulttext,%changes);
7804: my %currautoenroll;
7805: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7806: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7807: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7808: }
7809: }
7810: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7811: my %title = ( run => 'Auto-enrollment active',
7812: sender => 'Sender for notification messages',
7813: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
7814: my @offon = ('off','on');
7815: my $sender_uname = $env{'form.sender_uname'};
7816: my $sender_domain = $env{'form.sender_domain'};
7817: if ($sender_domain eq '') {
7818: $sender_uname = '';
7819: } elsif ($sender_uname eq '') {
7820: $sender_domain = '';
7821: }
7822: my $coowners = $env{'form.autoassign_coowners'};
7823: my %autoenrollhash = (
7824: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7825: 'sender_uname' => $sender_uname,
7826: 'sender_domain' => $sender_domain,
7827: 'co-owners' => $coowners,
7828: }
7829: );
7830: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7831: $dom);
7832: if ($putresult eq 'ok') {
7833: if (exists($currautoenroll{'run'})) {
7834: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7835: $changes{'run'} = 1;
7836: }
7837: } elsif ($autorun) {
7838: if ($env{'form.autoenroll_run'} ne '1') {
7839: $changes{'run'} = 1;
7840: }
7841: }
7842: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
7843: $changes{'sender'} = 1;
7844: }
7845: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
7846: $changes{'sender'} = 1;
7847: }
7848: if ($currautoenroll{'co-owners'} ne '') {
7849: if ($currautoenroll{'co-owners'} ne $coowners) {
7850: $changes{'coowners'} = 1;
7851: }
7852: } elsif ($coowners) {
7853: $changes{'coowners'} = 1;
7854: }
7855: if (keys(%changes) > 0) {
7856: $resulttext = &mt('Changes made:').'<ul>';
7857: if ($changes{'run'}) {
7858: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7859: }
7860: if ($changes{'sender'}) {
7861: if ($sender_uname eq '' || $sender_domain eq '') {
7862: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7863: } else {
7864: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7865: }
7866: }
7867: if ($changes{'coowners'}) {
7868: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7869: &Apache::loncommon::devalidate_domconfig_cache($dom);
7870: if (ref($lastactref) eq 'HASH') {
7871: $lastactref->{'domainconfig'} = 1;
7872: }
7873: }
7874: $resulttext .= '</ul>';
7875: } else {
7876: $resulttext = &mt('No changes made to auto-enrollment settings');
7877: }
7878: } else {
7879: $resulttext = '<span class="LC_error">'.
7880: &mt('An error occurred: [_1]',$putresult).'</span>';
7881: }
7882: return $resulttext;
7883: }
7884:
7885: sub modify_autoupdate {
7886: my ($dom,%domconfig) = @_;
7887: my ($resulttext,%currautoupdate,%fields,%changes);
7888: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7889: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7890: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7891: }
7892: }
7893: my @offon = ('off','on');
7894: my %title = &Apache::lonlocal::texthash (
7895: run => 'Auto-update:',
7896: classlists => 'Updates to user information in classlists?'
7897: );
7898: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7899: my %fieldtitles = &Apache::lonlocal::texthash (
7900: id => 'Student/Employee ID',
7901: permanentemail => 'E-mail address',
7902: lastname => 'Last Name',
7903: firstname => 'First Name',
7904: middlename => 'Middle Name',
7905: generation => 'Generation',
7906: );
7907: $othertitle = &mt('All users');
7908: if (keys(%{$usertypes}) > 0) {
7909: $othertitle = &mt('Other users');
7910: }
7911: foreach my $key (keys(%env)) {
7912: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
7913: my ($usertype,$item) = ($1,$2);
7914: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7915: if ($usertype eq 'default') {
7916: push(@{$fields{$1}},$2);
7917: } elsif (ref($types) eq 'ARRAY') {
7918: if (grep(/^\Q$usertype\E$/,@{$types})) {
7919: push(@{$fields{$1}},$2);
7920: }
7921: }
7922: }
7923: }
7924: }
7925: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7926: @lockablenames = sort(@lockablenames);
7927: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7928: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7929: if (@changed) {
7930: $changes{'lockablenames'} = 1;
7931: }
7932: } else {
7933: if (@lockablenames) {
7934: $changes{'lockablenames'} = 1;
7935: }
7936: }
7937: my %updatehash = (
7938: autoupdate => { run => $env{'form.autoupdate_run'},
7939: classlists => $env{'form.classlists'},
7940: fields => {%fields},
7941: lockablenames => \@lockablenames,
7942: }
7943: );
7944: foreach my $key (keys(%currautoupdate)) {
7945: if (($key eq 'run') || ($key eq 'classlists')) {
7946: if (exists($updatehash{autoupdate}{$key})) {
7947: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7948: $changes{$key} = 1;
7949: }
7950: }
7951: } elsif ($key eq 'fields') {
7952: if (ref($currautoupdate{$key}) eq 'HASH') {
7953: foreach my $item (@{$types},'default') {
7954: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7955: my $change = 0;
7956: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7957: if (!exists($fields{$item})) {
7958: $change = 1;
7959: last;
7960: } elsif (ref($fields{$item}) eq 'ARRAY') {
7961: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
7962: $change = 1;
7963: last;
7964: }
7965: }
7966: }
7967: if ($change) {
7968: push(@{$changes{$key}},$item);
7969: }
7970: }
7971: }
7972: }
7973: } elsif ($key eq 'lockablenames') {
7974: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7975: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7976: if (@changed) {
7977: $changes{'lockablenames'} = 1;
7978: }
7979: } else {
7980: if (@lockablenames) {
7981: $changes{'lockablenames'} = 1;
7982: }
7983: }
7984: }
7985: }
7986: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7987: if (@lockablenames) {
7988: $changes{'lockablenames'} = 1;
7989: }
7990: }
7991: foreach my $item (@{$types},'default') {
7992: if (defined($fields{$item})) {
7993: if (ref($currautoupdate{'fields'}) eq 'HASH') {
7994: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7995: my $change = 0;
7996: if (ref($fields{$item}) eq 'ARRAY') {
7997: foreach my $type (@{$fields{$item}}) {
7998: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7999: $change = 1;
8000: last;
8001: }
8002: }
8003: }
8004: if ($change) {
8005: push(@{$changes{'fields'}},$item);
8006: }
8007: } else {
8008: push(@{$changes{'fields'}},$item);
8009: }
8010: } else {
8011: push(@{$changes{'fields'}},$item);
8012: }
8013: }
8014: }
8015: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8016: $dom);
8017: if ($putresult eq 'ok') {
8018: if (keys(%changes) > 0) {
8019: $resulttext = &mt('Changes made:').'<ul>';
8020: foreach my $key (sort(keys(%changes))) {
8021: if ($key eq 'lockablenames') {
8022: $resulttext .= '<li>';
8023: if (@lockablenames) {
8024: $usertypes->{'default'} = $othertitle;
8025: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8026: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8027: } else {
8028: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8029: }
8030: $resulttext .= '</li>';
8031: } elsif (ref($changes{$key}) eq 'ARRAY') {
8032: foreach my $item (@{$changes{$key}}) {
8033: my @newvalues;
8034: foreach my $type (@{$fields{$item}}) {
8035: push(@newvalues,$fieldtitles{$type});
8036: }
8037: my $newvaluestr;
8038: if (@newvalues > 0) {
8039: $newvaluestr = join(', ',@newvalues);
8040: } else {
8041: $newvaluestr = &mt('none');
8042: }
8043: if ($item eq 'default') {
8044: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
8045: } else {
8046: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
8047: }
8048: }
8049: } else {
8050: my $newvalue;
8051: if ($key eq 'run') {
8052: $newvalue = $offon[$env{'form.autoupdate_run'}];
8053: } else {
8054: $newvalue = $offon[$env{'form.'.$key}];
8055: }
8056: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8057: }
8058: }
8059: $resulttext .= '</ul>';
8060: } else {
8061: $resulttext = &mt('No changes made to autoupdates');
8062: }
8063: } else {
8064: $resulttext = '<span class="LC_error">'.
8065: &mt('An error occurred: [_1]',$putresult).'</span>';
8066: }
8067: return $resulttext;
8068: }
8069:
8070: sub modify_autocreate {
8071: my ($dom,%domconfig) = @_;
8072: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8073: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8074: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8075: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8076: }
8077: }
8078: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8079: req => 'Auto-creation of validated requests for official courses',
8080: xmldc => 'Identity of course creator of courses from XML files',
8081: );
8082: my @types = ('xml','req');
8083: foreach my $item (@types) {
8084: $newvals{$item} = $env{'form.autocreate_'.$item};
8085: $newvals{$item} =~ s/\D//g;
8086: $newvals{$item} = 0 if ($newvals{$item} eq '');
8087: }
8088: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8089: my %domcoords = &get_active_dcs($dom);
8090: unless (exists($domcoords{$newvals{'xmldc'}})) {
8091: $newvals{'xmldc'} = '';
8092: }
8093: %autocreatehash = (
8094: autocreate => { xml => $newvals{'xml'},
8095: req => $newvals{'req'},
8096: }
8097: );
8098: if ($newvals{'xmldc'} ne '') {
8099: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8100: }
8101: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8102: $dom);
8103: if ($putresult eq 'ok') {
8104: my @items = @types;
8105: if ($newvals{'xml'}) {
8106: push(@items,'xmldc');
8107: }
8108: foreach my $item (@items) {
8109: if (exists($currautocreate{$item})) {
8110: if ($currautocreate{$item} ne $newvals{$item}) {
8111: $changes{$item} = 1;
8112: }
8113: } elsif ($newvals{$item}) {
8114: $changes{$item} = 1;
8115: }
8116: }
8117: if (keys(%changes) > 0) {
8118: my @offon = ('off','on');
8119: $resulttext = &mt('Changes made:').'<ul>';
8120: foreach my $item (@types) {
8121: if ($changes{$item}) {
8122: my $newtxt = $offon[$newvals{$item}];
8123: $resulttext .= '<li>'.
8124: &mt("$title{$item} set to [_1]$newtxt [_2]",
8125: '<b>','</b>').
8126: '</li>';
8127: }
8128: }
8129: if ($changes{'xmldc'}) {
8130: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8131: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
8132: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
8133: }
8134: $resulttext .= '</ul>';
8135: } else {
8136: $resulttext = &mt('No changes made to auto-creation settings');
8137: }
8138: } else {
8139: $resulttext = '<span class="LC_error">'.
8140: &mt('An error occurred: [_1]',$putresult).'</span>';
8141: }
8142: return $resulttext;
8143: }
8144:
8145: sub modify_directorysrch {
8146: my ($dom,%domconfig) = @_;
8147: my ($resulttext,%changes);
8148: my %currdirsrch;
8149: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8150: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8151: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8152: }
8153: }
8154: my %title = ( available => 'Directory search available',
8155: localonly => 'Other domains can search',
8156: searchby => 'Search types',
8157: searchtypes => 'Search latitude');
8158: my @offon = ('off','on');
8159: my @otherdoms = ('Yes','No');
8160:
8161: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
8162: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8163: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8164:
8165: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8166: if (keys(%{$usertypes}) == 0) {
8167: @cansearch = ('default');
8168: } else {
8169: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8170: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8171: if (!grep(/^\Q$type\E$/,@cansearch)) {
8172: push(@{$changes{'cansearch'}},$type);
8173: }
8174: }
8175: foreach my $type (@cansearch) {
8176: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8177: push(@{$changes{'cansearch'}},$type);
8178: }
8179: }
8180: } else {
8181: push(@{$changes{'cansearch'}},@cansearch);
8182: }
8183: }
8184:
8185: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8186: foreach my $by (@{$currdirsrch{'searchby'}}) {
8187: if (!grep(/^\Q$by\E$/,@searchby)) {
8188: push(@{$changes{'searchby'}},$by);
8189: }
8190: }
8191: foreach my $by (@searchby) {
8192: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8193: push(@{$changes{'searchby'}},$by);
8194: }
8195: }
8196: } else {
8197: push(@{$changes{'searchby'}},@searchby);
8198: }
8199:
8200: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8201: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8202: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8203: push(@{$changes{'searchtypes'}},$type);
8204: }
8205: }
8206: foreach my $type (@searchtypes) {
8207: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8208: push(@{$changes{'searchtypes'}},$type);
8209: }
8210: }
8211: } else {
8212: if (exists($currdirsrch{'searchtypes'})) {
8213: foreach my $type (@searchtypes) {
8214: if ($type ne $currdirsrch{'searchtypes'}) {
8215: push(@{$changes{'searchtypes'}},$type);
8216: }
8217: }
8218: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8219: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8220: }
8221: } else {
8222: push(@{$changes{'searchtypes'}},@searchtypes);
8223: }
8224: }
8225:
8226: my %dirsrch_hash = (
8227: directorysrch => { available => $env{'form.dirsrch_available'},
8228: cansearch => \@cansearch,
8229: localonly => $env{'form.dirsrch_localonly'},
8230: searchby => \@searchby,
8231: searchtypes => \@searchtypes,
8232: }
8233: );
8234: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8235: $dom);
8236: if ($putresult eq 'ok') {
8237: if (exists($currdirsrch{'available'})) {
8238: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8239: $changes{'available'} = 1;
8240: }
8241: } else {
8242: if ($env{'form.dirsrch_available'} eq '1') {
8243: $changes{'available'} = 1;
8244: }
8245: }
8246: if (exists($currdirsrch{'localonly'})) {
8247: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8248: $changes{'localonly'} = 1;
8249: }
8250: } else {
8251: if ($env{'form.dirsrch_localonly'} eq '1') {
8252: $changes{'localonly'} = 1;
8253: }
8254: }
8255: if (keys(%changes) > 0) {
8256: $resulttext = &mt('Changes made:').'<ul>';
8257: if ($changes{'available'}) {
8258: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8259: }
8260: if ($changes{'localonly'}) {
8261: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8262: }
8263:
8264: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8265: my $chgtext;
8266: if (ref($usertypes) eq 'HASH') {
8267: if (keys(%{$usertypes}) > 0) {
8268: foreach my $type (@{$types}) {
8269: if (grep(/^\Q$type\E$/,@cansearch)) {
8270: $chgtext .= $usertypes->{$type}.'; ';
8271: }
8272: }
8273: if (grep(/^default$/,@cansearch)) {
8274: $chgtext .= $othertitle;
8275: } else {
8276: $chgtext =~ s/\; $//;
8277: }
8278: $resulttext .=
8279: '<li>'.
8280: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8281: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8282: '</li>';
8283: }
8284: }
8285: }
8286: if (ref($changes{'searchby'}) eq 'ARRAY') {
8287: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8288: my $chgtext;
8289: foreach my $type (@{$titleorder}) {
8290: if (grep(/^\Q$type\E$/,@searchby)) {
8291: if (defined($searchtitles->{$type})) {
8292: $chgtext .= $searchtitles->{$type}.'; ';
8293: }
8294: }
8295: }
8296: $chgtext =~ s/\; $//;
8297: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8298: }
8299: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8300: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8301: my $chgtext;
8302: foreach my $type (@{$srchtypeorder}) {
8303: if (grep(/^\Q$type\E$/,@searchtypes)) {
8304: if (defined($srchtypes_desc->{$type})) {
8305: $chgtext .= $srchtypes_desc->{$type}.'; ';
8306: }
8307: }
8308: }
8309: $chgtext =~ s/\; $//;
8310: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
8311: }
8312: $resulttext .= '</ul>';
8313: } else {
8314: $resulttext = &mt('No changes made to institution directory search settings');
8315: }
8316: } else {
8317: $resulttext = '<span class="LC_error">'.
8318: &mt('An error occurred: [_1]',$putresult).'</span>';
8319: }
8320: return $resulttext;
8321: }
8322:
8323: sub modify_contacts {
8324: my ($dom,$lastactref,%domconfig) = @_;
8325: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8326: if (ref($domconfig{'contacts'}) eq 'HASH') {
8327: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8328: $currsetting{$key} = $domconfig{'contacts'}{$key};
8329: }
8330: }
8331: my (%others,%to,%bcc);
8332: my @contacts = ('supportemail','adminemail');
8333: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
8334: 'requestsmail','updatesmail','idconflictsmail');
8335: my @toggles = ('reporterrors','reportupdates');
8336: foreach my $type (@mailings) {
8337: @{$newsetting{$type}} =
8338: &Apache::loncommon::get_env_multiple('form.'.$type);
8339: foreach my $item (@contacts) {
8340: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8341: $contacts_hash{contacts}{$type}{$item} = 1;
8342: } else {
8343: $contacts_hash{contacts}{$type}{$item} = 0;
8344: }
8345: }
8346: $others{$type} = $env{'form.'.$type.'_others'};
8347: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
8348: if ($type eq 'helpdeskmail') {
8349: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8350: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8351: }
8352: }
8353: foreach my $item (@contacts) {
8354: $to{$item} = $env{'form.'.$item};
8355: $contacts_hash{'contacts'}{$item} = $to{$item};
8356: }
8357: foreach my $item (@toggles) {
8358: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8359: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8360: }
8361: }
8362: if (keys(%currsetting) > 0) {
8363: foreach my $item (@contacts) {
8364: if ($to{$item} ne $currsetting{$item}) {
8365: $changes{$item} = 1;
8366: }
8367: }
8368: foreach my $type (@mailings) {
8369: foreach my $item (@contacts) {
8370: if (ref($currsetting{$type}) eq 'HASH') {
8371: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8372: push(@{$changes{$type}},$item);
8373: }
8374: } else {
8375: push(@{$changes{$type}},@{$newsetting{$type}});
8376: }
8377: }
8378: if ($others{$type} ne $currsetting{$type}{'others'}) {
8379: push(@{$changes{$type}},'others');
8380: }
8381: if ($type eq 'helpdeskmail') {
8382: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8383: push(@{$changes{$type}},'bcc');
8384: }
8385: }
8386: }
8387: } else {
8388: my %default;
8389: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8390: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8391: $default{'errormail'} = 'adminemail';
8392: $default{'packagesmail'} = 'adminemail';
8393: $default{'helpdeskmail'} = 'supportemail';
8394: $default{'lonstatusmail'} = 'adminemail';
8395: $default{'requestsmail'} = 'adminemail';
8396: $default{'updatesmail'} = 'adminemail';
8397: foreach my $item (@contacts) {
8398: if ($to{$item} ne $default{$item}) {
8399: $changes{$item} = 1;
8400: }
8401: }
8402: foreach my $type (@mailings) {
8403: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8404:
8405: push(@{$changes{$type}},@{$newsetting{$type}});
8406: }
8407: if ($others{$type} ne '') {
8408: push(@{$changes{$type}},'others');
8409: }
8410: if ($type eq 'helpdeskmail') {
8411: if ($bcc{$type} ne '') {
8412: push(@{$changes{$type}},'bcc');
8413: }
8414: }
8415: }
8416: }
8417: foreach my $item (@toggles) {
8418: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8419: $changes{$item} = 1;
8420: } elsif ((!$env{'form.'.$item}) &&
8421: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8422: $changes{$item} = 1;
8423: }
8424: }
8425: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8426: $dom);
8427: if ($putresult eq 'ok') {
8428: if (keys(%changes) > 0) {
8429: &Apache::loncommon::devalidate_domconfig_cache($dom);
8430: if (ref($lastactref) eq 'HASH') {
8431: $lastactref->{'domainconfig'} = 1;
8432: }
8433: my ($titles,$short_titles) = &contact_titles();
8434: $resulttext = &mt('Changes made:').'<ul>';
8435: foreach my $item (@contacts) {
8436: if ($changes{$item}) {
8437: $resulttext .= '<li>'.$titles->{$item}.
8438: &mt(' set to: ').
8439: '<span class="LC_cusr_emph">'.
8440: $to{$item}.'</span></li>';
8441: }
8442: }
8443: foreach my $type (@mailings) {
8444: if (ref($changes{$type}) eq 'ARRAY') {
8445: $resulttext .= '<li>'.$titles->{$type}.': ';
8446: my @text;
8447: foreach my $item (@{$newsetting{$type}}) {
8448: push(@text,$short_titles->{$item});
8449: }
8450: if ($others{$type} ne '') {
8451: push(@text,$others{$type});
8452: }
8453: $resulttext .= '<span class="LC_cusr_emph">'.
8454: join(', ',@text).'</span>';
8455: if ($type eq 'helpdeskmail') {
8456: if ($bcc{$type} ne '') {
8457: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8458: }
8459: }
8460: $resulttext .= '</li>';
8461: }
8462: }
8463: my @offon = ('off','on');
8464: if ($changes{'reporterrors'}) {
8465: $resulttext .= '<li>'.
8466: &mt('E-mail error reports to [_1] set to "'.
8467: $offon[$env{'form.reporterrors'}].'".',
8468: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8469: &mt('LON-CAPA core group - MSU'),600,500)).
8470: '</li>';
8471: }
8472: if ($changes{'reportupdates'}) {
8473: $resulttext .= '<li>'.
8474: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8475: $offon[$env{'form.reportupdates'}].'".',
8476: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8477: &mt('LON-CAPA core group - MSU'),600,500)).
8478: '</li>';
8479: }
8480: $resulttext .= '</ul>';
8481: } else {
8482: $resulttext = &mt('No changes made to contact information');
8483: }
8484: } else {
8485: $resulttext = '<span class="LC_error">'.
8486: &mt('An error occurred: [_1].',$putresult).'</span>';
8487: }
8488: return $resulttext;
8489: }
8490:
8491: sub modify_usercreation {
8492: my ($dom,%domconfig) = @_;
8493: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
8494: my $warningmsg;
8495: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8496: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8497: if ($key eq 'cancreate') {
8498: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8499: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8500: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8501: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8502: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8503: } else {
8504: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8505: }
8506: }
8507: }
8508: } elsif ($key eq 'email_rule') {
8509: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8510: } else {
8511: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8512: }
8513: }
8514: }
8515: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8516: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8517: my @contexts = ('author','course','requestcrs');
8518: foreach my $item(@contexts) {
8519: $cancreate{$item} = $env{'form.can_createuser_'.$item};
8520: }
8521: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8522: foreach my $item (@contexts) {
8523: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8524: push(@{$changes{'cancreate'}},$item);
8525: }
8526: }
8527: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8528: foreach my $item (@contexts) {
8529: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
8530: if ($cancreate{$item} ne 'any') {
8531: push(@{$changes{'cancreate'}},$item);
8532: }
8533: } else {
8534: if ($cancreate{$item} ne 'none') {
8535: push(@{$changes{'cancreate'}},$item);
8536: }
8537: }
8538: }
8539: } else {
8540: foreach my $item (@contexts) {
8541: push(@{$changes{'cancreate'}},$item);
8542: }
8543: }
8544:
8545: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8546: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8547: if (!grep(/^\Q$type\E$/,@username_rule)) {
8548: push(@{$changes{'username_rule'}},$type);
8549: }
8550: }
8551: foreach my $type (@username_rule) {
8552: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8553: push(@{$changes{'username_rule'}},$type);
8554: }
8555: }
8556: } else {
8557: push(@{$changes{'username_rule'}},@username_rule);
8558: }
8559:
8560: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8561: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8562: if (!grep(/^\Q$type\E$/,@id_rule)) {
8563: push(@{$changes{'id_rule'}},$type);
8564: }
8565: }
8566: foreach my $type (@id_rule) {
8567: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8568: push(@{$changes{'id_rule'}},$type);
8569: }
8570: }
8571: } else {
8572: push(@{$changes{'id_rule'}},@id_rule);
8573: }
8574:
8575: my @authen_contexts = ('author','course','domain');
8576: my @authtypes = ('int','krb4','krb5','loc');
8577: my %authhash;
8578: foreach my $item (@authen_contexts) {
8579: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8580: foreach my $auth (@authtypes) {
8581: if (grep(/^\Q$auth\E$/,@authallowed)) {
8582: $authhash{$item}{$auth} = 1;
8583: } else {
8584: $authhash{$item}{$auth} = 0;
8585: }
8586: }
8587: }
8588: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
8589: foreach my $item (@authen_contexts) {
8590: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8591: foreach my $auth (@authtypes) {
8592: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8593: push(@{$changes{'authtypes'}},$item);
8594: last;
8595: }
8596: }
8597: }
8598: }
8599: } else {
8600: foreach my $item (@authen_contexts) {
8601: push(@{$changes{'authtypes'}},$item);
8602: }
8603: }
8604:
8605: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8606: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8607: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8608: $save_usercreate{'id_rule'} = \@id_rule;
8609: $save_usercreate{'username_rule'} = \@username_rule,
8610: $save_usercreate{'authtypes'} = \%authhash;
8611:
8612: my %usercreation_hash = (
8613: usercreation => \%save_usercreate,
8614: );
8615:
8616: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8617: $dom);
8618:
8619: if ($putresult eq 'ok') {
8620: if (keys(%changes) > 0) {
8621: $resulttext = &mt('Changes made:').'<ul>';
8622: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8623: my %lt = &usercreation_types();
8624: foreach my $type (@{$changes{'cancreate'}}) {
8625: my $chgtext = $lt{$type}.', ';
8626: if ($cancreate{$type} eq 'none') {
8627: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8628: } elsif ($cancreate{$type} eq 'any') {
8629: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8630: } elsif ($cancreate{$type} eq 'official') {
8631: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8632: } elsif ($cancreate{$type} eq 'unofficial') {
8633: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8634: }
8635: $resulttext .= '<li>'.$chgtext.'</li>';
8636: }
8637: }
8638: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8639: my ($rules,$ruleorder) =
8640: &Apache::lonnet::inst_userrules($dom,'username');
8641: my $chgtext = '<ul>';
8642: foreach my $type (@username_rule) {
8643: if (ref($rules->{$type}) eq 'HASH') {
8644: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8645: }
8646: }
8647: $chgtext .= '</ul>';
8648: if (@username_rule > 0) {
8649: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8650: } else {
8651: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8652: }
8653: }
8654: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8655: my ($idrules,$idruleorder) =
8656: &Apache::lonnet::inst_userrules($dom,'id');
8657: my $chgtext = '<ul>';
8658: foreach my $type (@id_rule) {
8659: if (ref($idrules->{$type}) eq 'HASH') {
8660: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8661: }
8662: }
8663: $chgtext .= '</ul>';
8664: if (@id_rule > 0) {
8665: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8666: } else {
8667: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8668: }
8669: }
8670: my %authname = &authtype_names();
8671: my %context_title = &context_names();
8672: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8673: my $chgtext = '<ul>';
8674: foreach my $type (@{$changes{'authtypes'}}) {
8675: my @allowed;
8676: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8677: foreach my $auth (@authtypes) {
8678: if ($authhash{$type}{$auth}) {
8679: push(@allowed,$authname{$auth});
8680: }
8681: }
8682: if (@allowed > 0) {
8683: $chgtext .= join(', ',@allowed).'</li>';
8684: } else {
8685: $chgtext .= &mt('none').'</li>';
8686: }
8687: }
8688: $chgtext .= '</ul>';
8689: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8690: $resulttext .= '</li>';
8691: }
8692: $resulttext .= '</ul>';
8693: } else {
8694: $resulttext = &mt('No changes made to user creation settings');
8695: }
8696: } else {
8697: $resulttext = '<span class="LC_error">'.
8698: &mt('An error occurred: [_1]',$putresult).'</span>';
8699: }
8700: if ($warningmsg ne '') {
8701: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8702: }
8703: return $resulttext;
8704: }
8705:
8706: sub modify_selfcreation {
8707: my ($dom,%domconfig) = @_;
8708: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8709: my (%save_usercreate,%save_usermodify);
8710: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8711: if (ref($types) eq 'ARRAY') {
8712: $usertypes->{'default'} = $othertitle;
8713: push(@{$types},'default');
8714: }
8715: #
8716: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8717: #
8718: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8719: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8720: if ($key eq 'cancreate') {
8721: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8722: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8723: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8724: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8725: ($item eq 'emailusername') || ($item eq 'notify') ||
8726: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
8727: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8728: } else {
8729: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8730: }
8731: }
8732: }
8733: } elsif ($key eq 'email_rule') {
8734: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8735: } else {
8736: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8737: }
8738: }
8739: }
8740: #
8741: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8742: #
8743: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8744: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8745: if ($key eq 'selfcreate') {
8746: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8747: } else {
8748: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8749: }
8750: }
8751: }
8752:
8753: my @contexts = ('selfcreate');
8754: @{$cancreate{'selfcreate'}} = ();
8755: %{$cancreate{'emailusername'}} = ();
8756: @{$cancreate{'statustocreate'}} = ();
8757: %{$cancreate{'selfcreateprocessing'}} = ();
8758: %{$cancreate{'shibenv'}} = ();
8759: my %selfcreatetypes = (
8760: sso => 'users authenticated by institutional single sign on',
8761: login => 'users authenticated by institutional log-in',
8762: email => 'users who provide a valid e-mail address for use as username',
8763: );
8764: #
8765: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8766: # is permitted.
8767: #
8768:
8769: my @statuses;
8770: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8771: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8772: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8773: }
8774: }
8775: push(@statuses,'default');
8776:
8777: foreach my $item ('login','sso','email') {
8778: if ($item eq 'email') {
8779: if ($env{'form.cancreate_email'}) {
8780: push(@{$cancreate{'selfcreate'}},'email');
8781: push(@contexts,'selfcreateprocessing');
8782: foreach my $type (@statuses) {
8783: if ($type eq 'default') {
8784: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8785: } else {
8786: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8787: }
8788: }
8789: }
8790: } else {
8791: if ($env{'form.cancreate_'.$item}) {
8792: push(@{$cancreate{'selfcreate'}},$item);
8793: }
8794: }
8795: }
8796: my (@email_rule,%userinfo,%savecaptcha);
8797: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8798: #
8799: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8800: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
8801: #
8802:
8803: if ($env{'form.cancreate_email'}) {
8804: push(@contexts,'emailusername');
8805: if (ref($types) eq 'ARRAY') {
8806: foreach my $type (@{$types}) {
8807: if (ref($infofields) eq 'ARRAY') {
8808: foreach my $field (@{$infofields}) {
8809: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8810: $cancreate{'emailusername'}{$type}{$field} = $1;
8811: }
8812: }
8813: }
8814: }
8815: }
8816: #
8817: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8818: # queued requests for self-creation of account using e-mail address as username
8819: #
8820:
8821: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8822: @approvalnotify = sort(@approvalnotify);
8823: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8824: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8825: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8826: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8827: push(@{$changes{'cancreate'}},'notify');
8828: }
8829: } else {
8830: if ($cancreate{'notify'}{'approval'}) {
8831: push(@{$changes{'cancreate'}},'notify');
8832: }
8833: }
8834: } elsif ($cancreate{'notify'}{'approval'}) {
8835: push(@{$changes{'cancreate'}},'notify');
8836: }
8837:
8838: #
8839: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8840: #
8841: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8842: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8843: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8844: if (@{$curr_usercreation{'email_rule'}} > 0) {
8845: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8846: if (!grep(/^\Q$type\E$/,@email_rule)) {
8847: push(@{$changes{'email_rule'}},$type);
8848: }
8849: }
8850: }
8851: if (@email_rule > 0) {
8852: foreach my $type (@email_rule) {
8853: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8854: push(@{$changes{'email_rule'}},$type);
8855: }
8856: }
8857: }
8858: } elsif (@email_rule > 0) {
8859: push(@{$changes{'email_rule'}},@email_rule);
8860: }
8861: }
8862: #
8863: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
8864: # institutional log-in.
8865: #
8866: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8867: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8868: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8869: ($domdefaults{'auth_def'} eq 'localauth'))) {
8870: $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.').' '.
8871: &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.');
8872: }
8873: }
8874: my @fields = ('lastname','firstname','middlename','generation',
8875: 'permanentemail','id');
8876: my @shibfields = (@fields,'inststatus');
8877: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8878: #
8879: # Where usernames may created for institutional log-in and/or institutional single sign on:
8880: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8881: # may self-create accounts
8882: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8883: # which the user may supply, if institutional data is unavailable.
8884: #
8885: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8886: if (ref($types) eq 'ARRAY') {
8887: if (@{$types} > 1) {
8888: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8889: push(@contexts,'statustocreate');
8890: } else {
8891: undef($cancreate{'statustocreate'});
8892: }
8893: foreach my $type (@{$types}) {
8894: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8895: foreach my $field (@fields) {
8896: if (grep(/^\Q$field\E$/,@modifiable)) {
8897: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8898: } else {
8899: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8900: }
8901: }
8902: }
8903: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8904: foreach my $type (@{$types}) {
8905: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8906: foreach my $field (@fields) {
8907: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8908: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8909: push(@{$changes{'selfcreate'}},$type);
8910: last;
8911: }
8912: }
8913: }
8914: }
8915: } else {
8916: foreach my $type (@{$types}) {
8917: push(@{$changes{'selfcreate'}},$type);
8918: }
8919: }
8920: }
8921: foreach my $field (@shibfields) {
8922: if ($env{'form.shibenv_'.$field} ne '') {
8923: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8924: }
8925: }
8926: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8927: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8928: foreach my $field (@shibfields) {
8929: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8930: push(@{$changes{'cancreate'}},'shibenv');
8931: }
8932: }
8933: } else {
8934: foreach my $field (@shibfields) {
8935: if ($env{'form.shibenv_'.$field}) {
8936: push(@{$changes{'cancreate'}},'shibenv');
8937: last;
8938: }
8939: }
8940: }
8941: }
8942: }
8943: foreach my $item (@contexts) {
8944: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8945: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8946: if (ref($cancreate{$item}) eq 'ARRAY') {
8947: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8948: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8949: push(@{$changes{'cancreate'}},$item);
8950: }
8951: }
8952: }
8953: }
8954: if (ref($cancreate{$item}) eq 'ARRAY') {
8955: foreach my $type (@{$cancreate{$item}}) {
8956: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8957: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8958: push(@{$changes{'cancreate'}},$item);
8959: }
8960: }
8961: }
8962: }
8963: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8964: if (ref($cancreate{$item}) eq 'HASH') {
8965: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
8966: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8967: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8968: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8969: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8970: push(@{$changes{'cancreate'}},$item);
8971: }
8972: }
8973: }
8974: } elsif ($item eq 'selfcreateprocessing') {
8975: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8976: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8977: push(@{$changes{'cancreate'}},$item);
8978: }
8979: }
8980: } else {
8981: if (!$cancreate{$item}{$curr}) {
8982: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8983: push(@{$changes{'cancreate'}},$item);
8984: }
8985: }
8986: }
8987: }
8988: foreach my $field (keys(%{$cancreate{$item}})) {
8989: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8990: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8991: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8992: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8993: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8994: push(@{$changes{'cancreate'}},$item);
8995: }
8996: }
8997: } else {
8998: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8999: push(@{$changes{'cancreate'}},$item);
9000: }
9001: }
9002: }
9003: } elsif ($item eq 'selfcreateprocessing') {
9004: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
9005: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9006: push(@{$changes{'cancreate'}},$item);
9007: }
9008: }
9009: } else {
9010: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
9011: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9012: push(@{$changes{'cancreate'}},$item);
9013: }
9014: }
9015: }
9016: }
9017: }
9018: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9019: if (ref($cancreate{$item}) eq 'ARRAY') {
9020: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9021: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9022: push(@{$changes{'cancreate'}},$item);
9023: }
9024: }
9025: } elsif (ref($cancreate{$item}) eq 'HASH') {
9026: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9027: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9028: push(@{$changes{'cancreate'}},$item);
9029: }
9030: }
9031: }
9032: } elsif ($item eq 'emailusername') {
9033: if (ref($cancreate{$item}) eq 'HASH') {
9034: foreach my $type (keys(%{$cancreate{$item}})) {
9035: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9036: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9037: if ($cancreate{$item}{$type}{$field}) {
9038: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9039: push(@{$changes{'cancreate'}},$item);
9040: }
9041: last;
9042: }
9043: }
9044: }
9045: }
9046: }
9047: }
9048: }
9049: #
9050: # Populate %save_usercreate hash with updates to self-creation configuration.
9051: #
9052: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9053: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
9054: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9055: if (ref($cancreate{'notify'}) eq 'HASH') {
9056: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9057: }
9058: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9059: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9060: }
9061: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9062: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9063: }
9064: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9065: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9066: }
9067: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9068: $save_usercreate{'emailrule'} = \@email_rule;
9069:
9070: my %userconfig_hash = (
9071: usercreation => \%save_usercreate,
9072: usermodification => \%save_usermodify,
9073: );
9074: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9075: $dom);
9076: #
9077: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9078: #
9079: if ($putresult eq 'ok') {
9080: if (keys(%changes) > 0) {
9081: $resulttext = &mt('Changes made:').'<ul>';
9082: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9083: my %lt = &selfcreation_types();
9084: foreach my $type (@{$changes{'cancreate'}}) {
9085: my $chgtext;
9086: if ($type eq 'selfcreate') {
9087: if (@{$cancreate{$type}} == 0) {
9088: $chgtext .= &mt('Self creation of a new user account is not permitted.');
9089: } else {
9090: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9091: '<ul>';
9092: foreach my $case (@{$cancreate{$type}}) {
9093: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9094: }
9095: $chgtext .= '</ul>';
9096: if (ref($cancreate{$type}) eq 'ARRAY') {
9097: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9098: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9099: if (@{$cancreate{'statustocreate'}} == 0) {
9100: $chgtext .= '<br />'.
9101: '<span class="LC_warning">'.
9102: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9103: '</span>';
9104: }
9105: }
9106: }
9107: }
9108: }
9109: } elsif ($type eq 'shibenv') {
9110: if (keys(%{$cancreate{$type}}) == 0) {
9111: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9112: } else {
9113: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9114: '<ul>';
9115: foreach my $field (@shibfields) {
9116: next if ($cancreate{$type}{$field} eq '');
9117: if ($field eq 'inststatus') {
9118: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9119: } else {
9120: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9121: }
9122: }
9123: $chgtext .= '</ul>';
9124: }
9125: } elsif ($type eq 'statustocreate') {
9126: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9127: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9128: if (@{$cancreate{'selfcreate'}} > 0) {
9129: if (@{$cancreate{'statustocreate'}} == 0) {
9130: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
9131: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
9132: $chgtext .= '<br />'.
9133: '<span class="LC_warning">'.
9134: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9135: '</span>';
9136: }
9137: } elsif (ref($usertypes) eq 'HASH') {
9138: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
9139: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9140: } else {
9141: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9142: }
9143: $chgtext .= '<ul>';
9144: foreach my $case (@{$cancreate{$type}}) {
9145: if ($case eq 'default') {
9146: $chgtext .= '<li>'.$othertitle.'</li>';
9147: } else {
9148: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
9149: }
9150: }
9151: $chgtext .= '</ul>';
9152: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
9153: $chgtext .= '<br /><span class="LC_warning">'.
9154: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9155: '</span>';
9156: }
9157: }
9158: } else {
9159: if (@{$cancreate{$type}} == 0) {
9160: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9161: } else {
9162: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
9163: }
9164: }
9165: }
9166: } elsif ($type eq 'selfcreateprocessing') {
9167: my %choices = &Apache::lonlocal::texthash (
9168: automatic => 'Automatic approval',
9169: approval => 'Queued for approval',
9170: );
9171: if (@statuses > 1) {
9172: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9173: '<ul>';
9174: foreach my $type (@statuses) {
9175: if ($type eq 'default') {
9176: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9177: } else {
9178: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9179: }
9180: }
9181: $chgtext .= '</ul>';
9182: } else {
9183: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9184: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9185: }
9186: } elsif ($type eq 'captcha') {
9187: if ($savecaptcha{$type} eq 'notused') {
9188: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9189: } else {
9190: my %captchas = &captcha_phrases();
9191: if ($captchas{$savecaptcha{$type}}) {
9192: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
9193: } else {
9194: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9195: }
9196: }
9197: } elsif ($type eq 'recaptchakeys') {
9198: my ($privkey,$pubkey);
9199: if (ref($savecaptcha{$type}) eq 'HASH') {
9200: $pubkey = $savecaptcha{$type}{'public'};
9201: $privkey = $savecaptcha{$type}{'private'};
9202: }
9203: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9204: if (!$pubkey) {
9205: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9206: } else {
9207: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9208: }
9209: if (!$privkey) {
9210: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9211: } else {
9212: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9213: }
9214: $chgtext .= '</ul>';
9215: } elsif ($type eq 'emailusername') {
9216: if (ref($cancreate{'emailusername'}) eq 'HASH') {
9217: if (ref($types) eq 'ARRAY') {
9218: foreach my $type (@{$types}) {
9219: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9220: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
9221: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
9222: '<ul>';
9223: foreach my $field (@{$infofields}) {
9224: if ($cancreate{'emailusername'}{$type}{$field}) {
9225: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9226: }
9227: }
9228: $chgtext .= '</ul>';
9229: } else {
9230: $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 />';
9231: }
9232: } else {
9233: $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 />';
9234: }
9235: }
9236: }
9237: }
9238: } elsif ($type eq 'notify') {
9239: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9240: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9241: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9242: if ($cancreate{'notify'}{'approval'}) {
9243: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9244: }
9245: }
9246: }
9247: }
9248: if ($chgtext) {
9249: $resulttext .= '<li>'.$chgtext.'</li>';
9250: }
9251: }
9252: }
9253: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9254: my ($emailrules,$emailruleorder) =
9255: &Apache::lonnet::inst_userrules($dom,'email');
9256: my $chgtext = '<ul>';
9257: foreach my $type (@email_rule) {
9258: if (ref($emailrules->{$type}) eq 'HASH') {
9259: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9260: }
9261: }
9262: $chgtext .= '</ul>';
9263: if (@email_rule > 0) {
9264: $resulttext .= '<li>'.
9265: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9266: $chgtext.
9267: '</li>';
9268: } else {
9269: $resulttext .= '<li>'.
9270: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9271: '</li>';
9272: }
9273: }
9274: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9275: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9276: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9277: foreach my $type (@{$changes{'selfcreate'}}) {
9278: my $typename = $type;
9279: if (ref($usertypes) eq 'HASH') {
9280: if ($usertypes->{$type} ne '') {
9281: $typename = $usertypes->{$type};
9282: }
9283: }
9284: my @modifiable;
9285: $resulttext .= '<li>'.
9286: &mt('Self-creation of account by users with status: [_1]',
9287: '<span class="LC_cusr_emph">'.$typename.'</span>').
9288: ' - '.&mt('modifiable fields (if institutional data blank): ');
9289: foreach my $field (@fields) {
9290: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9291: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9292: }
9293: }
9294: if (@modifiable > 0) {
9295: $resulttext .= join(', ',@modifiable);
9296: } else {
9297: $resulttext .= &mt('none');
9298: }
9299: $resulttext .= '</li>';
9300: }
9301: $resulttext .= '</ul></li>';
9302: }
9303: $resulttext .= '</ul>';
9304: } else {
9305: $resulttext = &mt('No changes made to self-creation settings');
9306: }
9307: } else {
9308: $resulttext = '<span class="LC_error">'.
9309: &mt('An error occurred: [_1]',$putresult).'</span>';
9310: }
9311: if ($warningmsg ne '') {
9312: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9313: }
9314: return $resulttext;
9315: }
9316:
9317: sub process_captcha {
9318: my ($container,$changes,$newsettings,$current) = @_;
9319: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9320: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9321: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9322: $newsettings->{'captcha'} = 'original';
9323: }
9324: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9325: if ($container eq 'cancreate') {
9326: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9327: push(@{$changes->{'cancreate'}},'captcha');
9328: } elsif (!defined($changes->{'cancreate'})) {
9329: $changes->{'cancreate'} = ['captcha'];
9330: }
9331: } else {
9332: $changes->{'captcha'} = 1;
9333: }
9334: }
9335: my ($newpub,$newpriv,$currpub,$currpriv);
9336: if ($newsettings->{'captcha'} eq 'recaptcha') {
9337: $newpub = $env{'form.'.$container.'_recaptchapub'};
9338: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
9339: $newpub =~ s/[^\w\-]//g;
9340: $newpriv =~ s/[^\w\-]//g;
9341: $newsettings->{'recaptchakeys'} = {
9342: public => $newpub,
9343: private => $newpriv,
9344: };
9345: }
9346: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9347: $currpub = $current->{'recaptchakeys'}{'public'};
9348: $currpriv = $current->{'recaptchakeys'}{'private'};
9349: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9350: $newsettings->{'recaptchakeys'} = {
9351: public => '',
9352: private => '',
9353: }
9354: }
9355: }
9356: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9357: if ($container eq 'cancreate') {
9358: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9359: push(@{$changes->{'cancreate'}},'recaptchakeys');
9360: } elsif (!defined($changes->{'cancreate'})) {
9361: $changes->{'cancreate'} = ['recaptchakeys'];
9362: }
9363: } else {
9364: $changes->{'recaptchakeys'} = 1;
9365: }
9366: }
9367: return;
9368: }
9369:
9370: sub modify_usermodification {
9371: my ($dom,%domconfig) = @_;
9372: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
9373: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9374: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9375: if ($key eq 'selfcreate') {
9376: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9377: } else {
9378: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9379: }
9380: }
9381: }
9382: my @contexts = ('author','course');
9383: my %context_title = (
9384: author => 'In author context',
9385: course => 'In course context',
9386: );
9387: my @fields = ('lastname','firstname','middlename','generation',
9388: 'permanentemail','id');
9389: my %roles = (
9390: author => ['ca','aa'],
9391: course => ['st','ep','ta','in','cr'],
9392: );
9393: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9394: foreach my $context (@contexts) {
9395: foreach my $role (@{$roles{$context}}) {
9396: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9397: foreach my $item (@fields) {
9398: if (grep(/^\Q$item\E$/,@modifiable)) {
9399: $modifyhash{$context}{$role}{$item} = 1;
9400: } else {
9401: $modifyhash{$context}{$role}{$item} = 0;
9402: }
9403: }
9404: }
9405: if (ref($curr_usermodification{$context}) eq 'HASH') {
9406: foreach my $role (@{$roles{$context}}) {
9407: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9408: foreach my $field (@fields) {
9409: if ($modifyhash{$context}{$role}{$field} ne
9410: $curr_usermodification{$context}{$role}{$field}) {
9411: push(@{$changes{$context}},$role);
9412: last;
9413: }
9414: }
9415: }
9416: }
9417: } else {
9418: foreach my $context (@contexts) {
9419: foreach my $role (@{$roles{$context}}) {
9420: push(@{$changes{$context}},$role);
9421: }
9422: }
9423: }
9424: }
9425: my %usermodification_hash = (
9426: usermodification => \%modifyhash,
9427: );
9428: my $putresult = &Apache::lonnet::put_dom('configuration',
9429: \%usermodification_hash,$dom);
9430: if ($putresult eq 'ok') {
9431: if (keys(%changes) > 0) {
9432: $resulttext = &mt('Changes made: ').'<ul>';
9433: foreach my $context (@contexts) {
9434: if (ref($changes{$context}) eq 'ARRAY') {
9435: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9436: if (ref($changes{$context}) eq 'ARRAY') {
9437: foreach my $role (@{$changes{$context}}) {
9438: my $rolename;
9439: if ($role eq 'cr') {
9440: $rolename = &mt('Custom');
9441: } else {
9442: $rolename = &Apache::lonnet::plaintext($role);
9443: }
9444: my @modifiable;
9445: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
9446: foreach my $field (@fields) {
9447: if ($modifyhash{$context}{$role}{$field}) {
9448: push(@modifiable,$fieldtitles{$field});
9449: }
9450: }
9451: if (@modifiable > 0) {
9452: $resulttext .= join(', ',@modifiable);
9453: } else {
9454: $resulttext .= &mt('none');
9455: }
9456: $resulttext .= '</li>';
9457: }
9458: $resulttext .= '</ul></li>';
9459: }
9460: }
9461: }
9462: $resulttext .= '</ul>';
9463: } else {
9464: $resulttext = &mt('No changes made to user modification settings');
9465: }
9466: } else {
9467: $resulttext = '<span class="LC_error">'.
9468: &mt('An error occurred: [_1]',$putresult).'</span>';
9469: }
9470: return $resulttext;
9471: }
9472:
9473: sub modify_defaults {
9474: my ($dom,$lastactref,%domconfig) = @_;
9475: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
9476: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9477: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
9478: my @authtypes = ('internal','krb4','krb5','localauth');
9479: foreach my $item (@items) {
9480: $newvalues{$item} = $env{'form.'.$item};
9481: if ($item eq 'auth_def') {
9482: if ($newvalues{$item} ne '') {
9483: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9484: push(@errors,$item);
9485: }
9486: }
9487: } elsif ($item eq 'lang_def') {
9488: if ($newvalues{$item} ne '') {
9489: if ($newvalues{$item} =~ /^(\w+)/) {
9490: my $langcode = $1;
9491: if ($langcode ne 'x_chef') {
9492: if (code2language($langcode) eq '') {
9493: push(@errors,$item);
9494: }
9495: }
9496: } else {
9497: push(@errors,$item);
9498: }
9499: }
9500: } elsif ($item eq 'timezone_def') {
9501: if ($newvalues{$item} ne '') {
9502: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
9503: push(@errors,$item);
9504: }
9505: }
9506: } elsif ($item eq 'datelocale_def') {
9507: if ($newvalues{$item} ne '') {
9508: my @datelocale_ids = DateTime::Locale->ids();
9509: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9510: push(@errors,$item);
9511: }
9512: }
9513: } elsif ($item eq 'portal_def') {
9514: if ($newvalues{$item} ne '') {
9515: 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])\/?$/) {
9516: push(@errors,$item);
9517: }
9518: }
9519: }
9520: if (grep(/^\Q$item\E$/,@errors)) {
9521: $newvalues{$item} = $domdefaults{$item};
9522: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9523: $changes{$item} = 1;
9524: }
9525: $domdefaults{$item} = $newvalues{$item};
9526: }
9527: my %defaults_hash = (
9528: defaults => \%newvalues,
9529: );
9530: my $title = &defaults_titles();
9531:
9532: my $currinststatus;
9533: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9534: $currinststatus = $domconfig{'inststatus'};
9535: } else {
9536: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9537: $currinststatus = {
9538: inststatustypes => $usertypes,
9539: inststatusorder => $types,
9540: inststatusguest => [],
9541: };
9542: }
9543: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9544: my @allpos;
9545: my %guests;
9546: my %alltypes;
9547: my ($currtitles,$currguests,$currorder);
9548: if (ref($currinststatus) eq 'HASH') {
9549: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9550: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9551: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9552: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9553: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9554: }
9555: }
9556: unless (grep(/^\Q$type\E$/,@todelete)) {
9557: my $position = $env{'form.inststatus_pos_'.$type};
9558: $position =~ s/\D+//g;
9559: $allpos[$position] = $type;
9560: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9561: $alltypes{$type} =~ s/`//g;
9562: if ($env{'form.inststatus_guest_'.$type}) {
9563: $guests{$type} = 1;
9564: }
9565: }
9566: }
9567: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9568: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9569: }
9570: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9571: $currtitles =~ s/,$//;
9572: }
9573: }
9574: if ($env{'form.addinststatus'}) {
9575: my $newtype = $env{'form.addinststatus'};
9576: $newtype =~ s/\W//g;
9577: unless (exists($alltypes{$newtype})) {
9578: if ($env{'form.addinststatus_guest'}) {
9579: $guests{$newtype} = 1;
9580: }
9581: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9582: $alltypes{$newtype} =~ s/`//g;
9583: my $position = $env{'form.addinststatus_pos'};
9584: $position =~ s/\D+//g;
9585: if ($position ne '') {
9586: $allpos[$position] = $newtype;
9587: }
9588: }
9589: }
9590: my (@orderedstatus,@orderedguests);
9591: foreach my $type (@allpos) {
9592: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9593: push(@orderedstatus,$type);
9594: if ($guests{$type}) {
9595: push(@orderedguests,$type);
9596: }
9597: }
9598: }
9599: foreach my $type (keys(%alltypes)) {
9600: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9601: delete($alltypes{$type});
9602: }
9603: }
9604: $defaults_hash{'inststatus'} = {
9605: inststatustypes => \%alltypes,
9606: inststatusorder => \@orderedstatus,
9607: inststatusguest => \@orderedguests,
9608: };
9609: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9610: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9611: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9612: }
9613: }
9614: if ($currorder ne join(',',@orderedstatus)) {
9615: $changes{'inststatus'}{'inststatusorder'} = 1;
9616: }
9617: if ($currguests ne join(',',@orderedguests)) {
9618: $changes{'inststatus'}{'inststatusguest'} = 1;
9619: }
9620: my $newtitles;
9621: foreach my $item (@orderedstatus) {
9622: $newtitles .= $alltypes{$item}.',';
9623: }
9624: $newtitles =~ s/,$//;
9625: if ($currtitles ne $newtitles) {
9626: $changes{'inststatus'}{'inststatustypes'} = 1;
9627: }
9628: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9629: $dom);
9630: if ($putresult eq 'ok') {
9631: if (keys(%changes) > 0) {
9632: $resulttext = &mt('Changes made:').'<ul>';
9633: my $version = &Apache::lonnet::get_server_loncaparev($dom);
9634: 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";
9635: foreach my $item (sort(keys(%changes))) {
9636: if ($item eq 'inststatus') {
9637: if (ref($changes{'inststatus'}) eq 'HASH') {
9638: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9639: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9640: foreach my $type (@orderedstatus) {
9641: $resulttext .= $alltypes{$type}.', ';
9642: }
9643: $resulttext =~ s/, $//;
9644: $resulttext .= '</li>';
9645: }
9646: if ($changes{'inststatus'}{'inststatusguest'}) {
9647: $resulttext .= '<li>';
9648: if (@orderedguests) {
9649: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9650: foreach my $type (@orderedguests) {
9651: $resulttext .= $alltypes{$type}.', ';
9652: }
9653: $resulttext =~ s/, $//;
9654: } else {
9655: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9656: }
9657: $resulttext .= '</li>';
9658: }
9659: }
9660: } else {
9661: my $value = $env{'form.'.$item};
9662: if ($value eq '') {
9663: $value = &mt('none');
9664: } elsif ($item eq 'auth_def') {
9665: my %authnames = &authtype_names();
9666: my %shortauth = (
9667: internal => 'int',
9668: krb4 => 'krb4',
9669: krb5 => 'krb5',
9670: localauth => 'loc',
9671: );
9672: $value = $authnames{$shortauth{$value}};
9673: }
9674: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9675: $mailmsgtext .= "$title->{$item} set to $value\n";
9676: }
9677: }
9678: $resulttext .= '</ul>';
9679: $mailmsgtext .= "\n";
9680: my $cachetime = 24*60*60;
9681: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9682: if (ref($lastactref) eq 'HASH') {
9683: $lastactref->{'domdefaults'} = 1;
9684: }
9685: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
9686: my $notify = 1;
9687: if (ref($domconfig{'contacts'}) eq 'HASH') {
9688: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9689: $notify = 0;
9690: }
9691: }
9692: if ($notify) {
9693: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9694: "LON-CAPA Domain Settings Change - $dom",
9695: $mailmsgtext);
9696: }
9697: }
9698: } else {
9699: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
9700: }
9701: } else {
9702: $resulttext = '<span class="LC_error">'.
9703: &mt('An error occurred: [_1]',$putresult).'</span>';
9704: }
9705: if (@errors > 0) {
9706: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9707: foreach my $item (@errors) {
9708: $resulttext .= ' "'.$title->{$item}.'",';
9709: }
9710: $resulttext =~ s/,$//;
9711: }
9712: return $resulttext;
9713: }
9714:
9715: sub modify_scantron {
9716: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
9717: my ($resulttext,%confhash,%changes,$errors);
9718: my $custom = 'custom.tab';
9719: my $default = 'default.tab';
9720: my $servadm = $r->dir_config('lonAdmEMail');
9721: my ($configuserok,$author_ok,$switchserver) =
9722: &config_check($dom,$confname,$servadm);
9723: if ($env{'form.scantronformat.filename'} ne '') {
9724: my $error;
9725: if ($configuserok eq 'ok') {
9726: if ($switchserver) {
9727: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
9728: } else {
9729: if ($author_ok eq 'ok') {
9730: my ($result,$scantronurl) =
9731: &publishlogo($r,'upload','scantronformat',$dom,
9732: $confname,'scantron','','',$custom);
9733: if ($result eq 'ok') {
9734: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
9735: $changes{'scantronformat'} = 1;
9736: } else {
9737: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9738: }
9739: } else {
9740: $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);
9741: }
9742: }
9743: } else {
9744: $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);
9745: }
9746: if ($error) {
9747: &Apache::lonnet::logthis($error);
9748: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9749: }
9750: }
9751: if (ref($domconfig{'scantron'}) eq 'HASH') {
9752: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9753: if ($env{'form.scantronformat_del'}) {
9754: $confhash{'scantron'}{'scantronformat'} = '';
9755: $changes{'scantronformat'} = 1;
9756: }
9757: }
9758: }
9759: if (keys(%confhash) > 0) {
9760: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9761: $dom);
9762: if ($putresult eq 'ok') {
9763: if (keys(%changes) > 0) {
9764: if (ref($confhash{'scantron'}) eq 'HASH') {
9765: $resulttext = &mt('Changes made:').'<ul>';
9766: if ($confhash{'scantron'}{'scantronformat'} eq '') {
9767: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
9768: } else {
9769: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
9770: }
9771: $resulttext .= '</ul>';
9772: } else {
9773: $resulttext = &mt('Changes made to bubblesheet format file.');
9774: }
9775: $resulttext .= '</ul>';
9776: &Apache::loncommon::devalidate_domconfig_cache($dom);
9777: if (ref($lastactref) eq 'HASH') {
9778: $lastactref->{'domainconfig'} = 1;
9779: }
9780: } else {
9781: $resulttext = &mt('No changes made to bubblesheet format file');
9782: }
9783: } else {
9784: $resulttext = '<span class="LC_error">'.
9785: &mt('An error occurred: [_1]',$putresult).'</span>';
9786: }
9787: } else {
9788: $resulttext = &mt('No changes made to bubblesheet format file');
9789: }
9790: if ($errors) {
9791: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9792: $errors.'</ul>';
9793: }
9794: return $resulttext;
9795: }
9796:
9797: sub modify_coursecategories {
9798: my ($dom,$lastactref,%domconfig) = @_;
9799: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9800: $cathash);
9801: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
9802: my @catitems = ('unauth','auth');
9803: my @cattypes = ('std','domonly','codesrch','none');
9804: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9805: $cathash = $domconfig{'coursecategories'}{'cats'};
9806: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9807: $changes{'togglecats'} = 1;
9808: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9809: }
9810: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9811: $changes{'categorize'} = 1;
9812: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9813: }
9814: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9815: $changes{'togglecatscomm'} = 1;
9816: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9817: }
9818: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9819: $changes{'categorizecomm'} = 1;
9820: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9821: }
9822: foreach my $item (@catitems) {
9823: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9824: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9825: $changes{$item} = 1;
9826: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9827: }
9828: }
9829: }
9830: } else {
9831: $changes{'togglecats'} = 1;
9832: $changes{'categorize'} = 1;
9833: $changes{'togglecatscomm'} = 1;
9834: $changes{'categorizecomm'} = 1;
9835: $domconfig{'coursecategories'} = {
9836: togglecats => $env{'form.togglecats'},
9837: categorize => $env{'form.categorize'},
9838: togglecatscomm => $env{'form.togglecatscomm'},
9839: categorizecomm => $env{'form.categorizecomm'},
9840: };
9841: foreach my $item (@catitems) {
9842: if ($env{'form.coursecat_'.$item} ne 'std') {
9843: $changes{$item} = 1;
9844: }
9845: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9846: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9847: }
9848: }
9849: }
9850: if (ref($cathash) eq 'HASH') {
9851: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
9852: push (@deletecategory,'instcode::0');
9853: }
9854: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9855: push(@deletecategory,'communities::0');
9856: }
9857: }
9858: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9859: if (ref($cathash) eq 'HASH') {
9860: if (@deletecategory > 0) {
9861: #FIXME Need to remove category from all courses using a deleted category
9862: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
9863: foreach my $item (@deletecategory) {
9864: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9865: delete($domconfig{'coursecategories'}{'cats'}{$item});
9866: $deletions{$item} = 1;
9867: &recurse_cat_deletes($item,$cathash,\%deletions);
9868: }
9869: }
9870: }
9871: foreach my $item (keys(%{$cathash})) {
9872: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9873: if ($cathash->{$item} ne $env{'form.'.$item}) {
9874: $reorderings{$item} = 1;
9875: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
9876: }
9877: if ($env{'form.addcategory_name_'.$item} ne '') {
9878: my $newcat = $env{'form.addcategory_name_'.$item};
9879: my $newdepth = $depth+1;
9880: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
9881: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
9882: $adds{$newitem} = 1;
9883: }
9884: if ($env{'form.subcat_'.$item} ne '') {
9885: my $newcat = $env{'form.subcat_'.$item};
9886: my $newdepth = $depth+1;
9887: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
9888: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
9889: $adds{$newitem} = 1;
9890: }
9891: }
9892: }
9893: if ($env{'form.instcode'} eq '1') {
9894: if (ref($cathash) eq 'HASH') {
9895: my $newitem = 'instcode::0';
9896: if ($cathash->{$newitem} eq '') {
9897: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
9898: $adds{$newitem} = 1;
9899: }
9900: } else {
9901: my $newitem = 'instcode::0';
9902: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
9903: $adds{$newitem} = 1;
9904: }
9905: }
9906: if ($env{'form.communities'} eq '1') {
9907: if (ref($cathash) eq 'HASH') {
9908: my $newitem = 'communities::0';
9909: if ($cathash->{$newitem} eq '') {
9910: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9911: $adds{$newitem} = 1;
9912: }
9913: } else {
9914: my $newitem = 'communities::0';
9915: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9916: $adds{$newitem} = 1;
9917: }
9918: }
9919: if ($env{'form.addcategory_name'} ne '') {
9920: if (($env{'form.addcategory_name'} ne 'instcode') &&
9921: ($env{'form.addcategory_name'} ne 'communities')) {
9922: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9923: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9924: $adds{$newitem} = 1;
9925: }
9926: }
9927: my $putresult;
9928: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9929: if (keys(%deletions) > 0) {
9930: foreach my $key (keys(%deletions)) {
9931: if ($predelallitems{$key} ne '') {
9932: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9933: }
9934: }
9935: }
9936: my (@chkcats,@chktrails,%chkallitems);
9937: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
9938: if (ref($chkcats[0]) eq 'ARRAY') {
9939: my $depth = 0;
9940: my $chg = 0;
9941: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9942: my $name = $chkcats[0][$i];
9943: my $item;
9944: if ($name eq '') {
9945: $chg ++;
9946: } else {
9947: $item = &escape($name).'::0';
9948: if ($chg) {
9949: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
9950: }
9951: $depth ++;
9952: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
9953: $depth --;
9954: }
9955: }
9956: }
9957: }
9958: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9959: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
9960: if ($putresult eq 'ok') {
9961: my %title = (
9962: togglecats => 'Show/Hide a course in catalog',
9963: categorize => 'Assign a category to a course',
9964: togglecatscomm => 'Show/Hide a community in catalog',
9965: categorizecomm => 'Assign a category to a community',
9966: );
9967: my %level = (
9968: dom => 'set in Domain ("Modify Course/Community")',
9969: crs => 'set in Course ("Course Configuration")',
9970: comm => 'set in Community ("Community Configuration")',
9971: none => 'No catalog',
9972: std => 'Standard catalog',
9973: domonly => 'Domain-only catalog',
9974: codesrch => 'Code search form',
9975: );
9976: $resulttext = &mt('Changes made:').'<ul>';
9977: if ($changes{'togglecats'}) {
9978: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9979: }
9980: if ($changes{'categorize'}) {
9981: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
9982: }
9983: if ($changes{'togglecatscomm'}) {
9984: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9985: }
9986: if ($changes{'categorizecomm'}) {
9987: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9988: }
9989: if ($changes{'unauth'}) {
9990: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9991: }
9992: if ($changes{'auth'}) {
9993: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9994: }
9995: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9996: my $cathash;
9997: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9998: $cathash = $domconfig{'coursecategories'}{'cats'};
9999: } else {
10000: $cathash = {};
10001: }
10002: my (@cats,@trails,%allitems);
10003: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10004: if (keys(%deletions) > 0) {
10005: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10006: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
10007: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10008: }
10009: $resulttext .= '</ul></li>';
10010: }
10011: if (keys(%reorderings) > 0) {
10012: my %sort_by_trail;
10013: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10014: foreach my $key (keys(%reorderings)) {
10015: if ($allitems{$key} ne '') {
10016: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10017: }
10018: }
10019: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10020: $resulttext .= '<li>'.$trails[$trail].'</li>';
10021: }
10022: $resulttext .= '</ul></li>';
10023: }
10024: if (keys(%adds) > 0) {
10025: my %sort_by_trail;
10026: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10027: foreach my $key (keys(%adds)) {
10028: if ($allitems{$key} ne '') {
10029: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10030: }
10031: }
10032: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10033: $resulttext .= '<li>'.$trails[$trail].'</li>';
10034: }
10035: $resulttext .= '</ul></li>';
10036: }
10037: }
10038: $resulttext .= '</ul>';
10039: if ($changes{'unauth'} || $changes{'auth'}) {
10040: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10041: if ($changes{'auth'}) {
10042: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10043: }
10044: if ($changes{'unauth'}) {
10045: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10046: }
10047: my $cachetime = 24*60*60;
10048: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10049: if (ref($lastactref) eq 'HASH') {
10050: $lastactref->{'domdefaults'} = 1;
10051: }
10052: }
10053: } else {
10054: $resulttext = '<span class="LC_error">'.
10055: &mt('An error occurred: [_1]',$putresult).'</span>';
10056: }
10057: } else {
10058: $resulttext = &mt('No changes made to course and community categories');
10059: }
10060: return $resulttext;
10061: }
10062:
10063: sub modify_serverstatuses {
10064: my ($dom,%domconfig) = @_;
10065: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10066: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10067: %currserverstatus = %{$domconfig{'serverstatuses'}};
10068: }
10069: my @pages = &serverstatus_pages();
10070: foreach my $type (@pages) {
10071: $newserverstatus{$type}{'namedusers'} = '';
10072: $newserverstatus{$type}{'machines'} = '';
10073: if (defined($env{'form.'.$type.'_namedusers'})) {
10074: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10075: my @okusers;
10076: foreach my $user (@users) {
10077: my ($uname,$udom) = split(/:/,$user);
10078: if (($udom =~ /^$match_domain$/) &&
10079: (&Apache::lonnet::domain($udom)) &&
10080: ($uname =~ /^$match_username$/)) {
10081: if (!grep(/^\Q$user\E/,@okusers)) {
10082: push(@okusers,$user);
10083: }
10084: }
10085: }
10086: if (@okusers > 0) {
10087: @okusers = sort(@okusers);
10088: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10089: }
10090: }
10091: if (defined($env{'form.'.$type.'_machines'})) {
10092: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10093: my @okmachines;
10094: foreach my $ip (@machines) {
10095: my @parts = split(/\./,$ip);
10096: next if (@parts < 4);
10097: my $badip = 0;
10098: for (my $i=0; $i<4; $i++) {
10099: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10100: $badip = 1;
10101: last;
10102: }
10103: }
10104: if (!$badip) {
10105: push(@okmachines,$ip);
10106: }
10107: }
10108: @okmachines = sort(@okmachines);
10109: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10110: }
10111: }
10112: my %serverstatushash = (
10113: serverstatuses => \%newserverstatus,
10114: );
10115: foreach my $type (@pages) {
10116: foreach my $setting ('namedusers','machines') {
10117: my (@current,@new);
10118: if (ref($currserverstatus{$type}) eq 'HASH') {
10119: if ($currserverstatus{$type}{$setting} ne '') {
10120: @current = split(/,/,$currserverstatus{$type}{$setting});
10121: }
10122: }
10123: if ($newserverstatus{$type}{$setting} ne '') {
10124: @new = split(/,/,$newserverstatus{$type}{$setting});
10125: }
10126: if (@current > 0) {
10127: if (@new > 0) {
10128: foreach my $item (@current) {
10129: if (!grep(/^\Q$item\E$/,@new)) {
10130: $changes{$type}{$setting} = 1;
10131: last;
10132: }
10133: }
10134: foreach my $item (@new) {
10135: if (!grep(/^\Q$item\E$/,@current)) {
10136: $changes{$type}{$setting} = 1;
10137: last;
10138: }
10139: }
10140: } else {
10141: $changes{$type}{$setting} = 1;
10142: }
10143: } elsif (@new > 0) {
10144: $changes{$type}{$setting} = 1;
10145: }
10146: }
10147: }
10148: if (keys(%changes) > 0) {
10149: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
10150: my $putresult = &Apache::lonnet::put_dom('configuration',
10151: \%serverstatushash,$dom);
10152: if ($putresult eq 'ok') {
10153: $resulttext .= &mt('Changes made:').'<ul>';
10154: foreach my $type (@pages) {
10155: if (ref($changes{$type}) eq 'HASH') {
10156: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
10157: if ($changes{$type}{'namedusers'}) {
10158: if ($newserverstatus{$type}{'namedusers'} eq '') {
10159: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10160: } else {
10161: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10162: }
10163: }
10164: if ($changes{$type}{'machines'}) {
10165: if ($newserverstatus{$type}{'machines'} eq '') {
10166: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10167: } else {
10168: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10169: }
10170:
10171: }
10172: $resulttext .= '</ul></li>';
10173: }
10174: }
10175: $resulttext .= '</ul>';
10176: } else {
10177: $resulttext = '<span class="LC_error">'.
10178: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10179:
10180: }
10181: } else {
10182: $resulttext = &mt('No changes made to access to server status pages');
10183: }
10184: return $resulttext;
10185: }
10186:
10187: sub modify_helpsettings {
10188: my ($r,$dom,$confname,%domconfig) = @_;
10189: my ($resulttext,$errors,%changes,%helphash);
10190: my %defaultchecked = ('submitbugs' => 'on');
10191: my @offon = ('off','on');
10192: my @toggles = ('submitbugs');
10193: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10194: foreach my $item (@toggles) {
10195: if ($defaultchecked{$item} eq 'on') {
10196: if ($domconfig{'helpsettings'}{$item} eq '') {
10197: if ($env{'form.'.$item} eq '0') {
10198: $changes{$item} = 1;
10199: }
10200: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10201: $changes{$item} = 1;
10202: }
10203: } elsif ($defaultchecked{$item} eq 'off') {
10204: if ($domconfig{'helpsettings'}{$item} eq '') {
10205: if ($env{'form.'.$item} eq '1') {
10206: $changes{$item} = 1;
10207: }
10208: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10209: $changes{$item} = 1;
10210: }
10211: }
10212: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10213: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
10214: }
10215: }
10216: }
10217: my $putresult;
10218: if (keys(%changes) > 0) {
10219: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10220: if ($putresult eq 'ok') {
10221: $resulttext = &mt('Changes made:').'<ul>';
10222: foreach my $item (sort(keys(%changes))) {
10223: if ($item eq 'submitbugs') {
10224: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10225: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10226: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10227: }
10228: }
10229: $resulttext .= '</ul>';
10230: } else {
10231: $resulttext = &mt('No changes made to help settings');
10232: $errors .= '<li><span class="LC_error">'.
10233: &mt('An error occurred storing the settings: [_1]',
10234: $putresult).'</span></li>';
10235: }
10236: }
10237: if ($errors) {
10238: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
10239: $errors.'</ul>';
10240: }
10241: return $resulttext;
10242: }
10243:
10244: sub modify_coursedefaults {
10245: my ($dom,$lastactref,%domconfig) = @_;
10246: my ($resulttext,$errors,%changes,%defaultshash);
10247: my %defaultchecked = (
10248: 'canuse_pdfforms' => 'off',
10249: 'uselcmath' => 'on',
10250: 'usejsme' => 'on'
10251: );
10252: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
10253: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
10254: 'uploadquota_community','uploadquota_textbook');
10255: my @types = ('official','unofficial','community','textbook');
10256: my %staticdefaults = (
10257: anonsurvey_threshold => 10,
10258: uploadquota => 500,
10259: postsubmit => 60,
10260: );
10261:
10262: $defaultshash{'coursedefaults'} = {};
10263:
10264: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10265: if ($domconfig{'coursedefaults'} eq '') {
10266: $domconfig{'coursedefaults'} = {};
10267: }
10268: }
10269:
10270: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10271: foreach my $item (@toggles) {
10272: if ($defaultchecked{$item} eq 'on') {
10273: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10274: ($env{'form.'.$item} eq '0')) {
10275: $changes{$item} = 1;
10276: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10277: $changes{$item} = 1;
10278: }
10279: } elsif ($defaultchecked{$item} eq 'off') {
10280: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10281: ($env{'form.'.$item} eq '1')) {
10282: $changes{$item} = 1;
10283: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10284: $changes{$item} = 1;
10285: }
10286: }
10287: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10288: }
10289: foreach my $item (@numbers) {
10290: my ($currdef,$newdef);
10291: $newdef = $env{'form.'.$item};
10292: if ($item eq 'anonsurvey_threshold') {
10293: $currdef = $domconfig{'coursedefaults'}{$item};
10294: $newdef =~ s/\D//g;
10295: if ($newdef eq '' || $newdef < 1) {
10296: $newdef = 1;
10297: }
10298: $defaultshash{'coursedefaults'}{$item} = $newdef;
10299: } else {
10300: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10301: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10302: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10303: }
10304: $newdef =~ s/[^\w.\-]//g;
10305: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10306: }
10307: if ($currdef ne $newdef) {
10308: my $staticdef;
10309: if ($item eq 'anonsurvey_threshold') {
10310: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10311: $changes{$item} = 1;
10312: }
10313: } else {
10314: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10315: $changes{'uploadquota'} = 1;
10316: }
10317: }
10318: }
10319: }
10320:
10321: my %credits;
10322: foreach my $type (@types) {
10323: unless ($type eq 'community') {
10324: $credits{$type} = $env{'form.'.$type.'_credits'};
10325: $credits{$type} =~ s/[^\d.]+//g;
10326: }
10327: }
10328: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10329: ($env{'form.coursecredits'} eq '1')) {
10330: $changes{'coursecredits'} = 1;
10331: foreach my $type (keys(%credits)) {
10332: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10333: }
10334: } else {
10335: if ($env{'form.coursecredits'} eq '1') {
10336: foreach my $type (@types) {
10337: unless ($type eq 'community') {
10338: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10339: $changes{'coursecredits'} = 1;
10340: }
10341: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10342: }
10343: }
10344: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10345: foreach my $type (@types) {
10346: unless ($type eq 'community') {
10347: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10348: $changes{'coursecredits'} = 1;
10349: last;
10350: }
10351: }
10352: }
10353: }
10354: }
10355: if ($env{'form.postsubmit'} eq '1') {
10356: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10357: my %currtimeout;
10358: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10359: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10360: $changes{'postsubmit'} = 1;
10361: }
10362: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10363: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10364: }
10365: } else {
10366: $changes{'postsubmit'} = 1;
10367: }
10368: foreach my $type (@types) {
10369: my $timeout = $env{'form.'.$type.'_timeout'};
10370: $timeout =~ s/\D//g;
10371: if ($timeout == $staticdefaults{'postsubmit'}) {
10372: $timeout = '';
10373: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10374: $timeout = '0';
10375: }
10376: unless ($timeout eq '') {
10377: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10378: }
10379: if (exists($currtimeout{$type})) {
10380: if ($timeout ne $currtimeout{$type}) {
10381: $changes{'postsubmit'} = 1;
10382: }
10383: } elsif ($timeout ne '') {
10384: $changes{'postsubmit'} = 1;
10385: }
10386: }
10387: } else {
10388: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10389: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10390: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10391: $changes{'postsubmit'} = 1;
10392: }
10393: } else {
10394: $changes{'postsubmit'} = 1;
10395: }
10396: }
10397: }
10398: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10399: $dom);
10400: if ($putresult eq 'ok') {
10401: if (keys(%changes) > 0) {
10402: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10403: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
10404: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) {
10405: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
10406: if ($changes{$item}) {
10407: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10408: }
10409: }
10410: if ($changes{'coursecredits'}) {
10411: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10412: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10413: $domdefaults{$type.'credits'} =
10414: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10415: }
10416: }
10417: }
10418: if ($changes{'postsubmit'}) {
10419: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10420: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10421: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10422: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10423: $domdefaults{$type.'postsubtimeout'} =
10424: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10425: }
10426: }
10427: }
10428: }
10429: if ($changes{'uploadquota'}) {
10430: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10431: foreach my $type (@types) {
10432: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10433: }
10434: }
10435: }
10436: my $cachetime = 24*60*60;
10437: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10438: if (ref($lastactref) eq 'HASH') {
10439: $lastactref->{'domdefaults'} = 1;
10440: }
10441: }
10442: $resulttext = &mt('Changes made:').'<ul>';
10443: foreach my $item (sort(keys(%changes))) {
10444: if ($item eq 'canuse_pdfforms') {
10445: if ($env{'form.'.$item} eq '1') {
10446: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10447: } else {
10448: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10449: }
10450: } elsif ($item eq 'uselcmath') {
10451: if ($env{'form.'.$item} eq '1') {
10452: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
10453: } else {
10454: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10455: }
10456: } elsif ($item eq 'usejsme') {
10457: if ($env{'form.'.$item} eq '1') {
10458: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10459: } else {
10460: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
10461: }
10462: } elsif ($item eq 'anonsurvey_threshold') {
10463: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
10464: } elsif ($item eq 'uploadquota') {
10465: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10466: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10467: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10468: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
10469: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10470:
10471: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10472: '</ul>'.
10473: '</li>';
10474: } else {
10475: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10476: }
10477: } elsif ($item eq 'postsubmit') {
10478: if ($domdefaults{'postsubmit'} eq 'off') {
10479: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10480: } else {
10481: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10482: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10483: $resulttext .= &mt('durations:').'<ul>';
10484: foreach my $type (@types) {
10485: $resulttext .= '<li>';
10486: my $timeout;
10487: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10488: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10489: }
10490: my $display;
10491: if ($timeout eq '0') {
10492: $display = &mt('unlimited');
10493: } elsif ($timeout eq '') {
10494: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10495: } else {
10496: $display = &mt('[quant,_1,second]',$timeout);
10497: }
10498: if ($type eq 'community') {
10499: $resulttext .= &mt('Communities');
10500: } elsif ($type eq 'official') {
10501: $resulttext .= &mt('Official courses');
10502: } elsif ($type eq 'unofficial') {
10503: $resulttext .= &mt('Unofficial courses');
10504: } elsif ($type eq 'textbook') {
10505: $resulttext .= &mt('Textbook courses');
10506: }
10507: $resulttext .= ' -- '.$display.'</li>';
10508: }
10509: $resulttext .= '</ul>';
10510: }
10511: $resulttext .= '</li>';
10512: }
10513: } elsif ($item eq 'coursecredits') {
10514: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10515: if (($domdefaults{'officialcredits'} eq '') &&
10516: ($domdefaults{'unofficialcredits'} eq '') &&
10517: ($domdefaults{'textbookcredits'} eq '')) {
10518: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10519: } else {
10520: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10521: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10522: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
10523: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
10524: '</ul>'.
10525: '</li>';
10526: }
10527: } else {
10528: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10529: }
10530: }
10531: }
10532: $resulttext .= '</ul>';
10533: } else {
10534: $resulttext = &mt('No changes made to course defaults');
10535: }
10536: } else {
10537: $resulttext = '<span class="LC_error">'.
10538: &mt('An error occurred: [_1]',$putresult).'</span>';
10539: }
10540: return $resulttext;
10541: }
10542:
10543: sub modify_selfenrollment {
10544: my ($dom,$lastactref,%domconfig) = @_;
10545: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10546: my @types = ('official','unofficial','community','textbook');
10547: my %titles = &tool_titles();
10548: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10549: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10550: $ordered{'default'} = ['types','registered','approval','limit'];
10551:
10552: my (%roles,%shown,%toplevel);
10553: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10554:
10555: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10556: if ($domconfig{'selfenrollment'} eq '') {
10557: $domconfig{'selfenrollment'} = {};
10558: }
10559: }
10560: %toplevel = (
10561: admin => 'Configuration Rights',
10562: default => 'Default settings',
10563: validation => 'Validation of self-enrollment requests',
10564: );
10565: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10566:
10567: if (ref($ordered{'admin'}) eq 'ARRAY') {
10568: foreach my $item (@{$ordered{'admin'}}) {
10569: foreach my $type (@types) {
10570: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10571: $selfenrollhash{'admin'}{$type}{$item} = 1;
10572: } else {
10573: $selfenrollhash{'admin'}{$type}{$item} = 0;
10574: }
10575: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10576: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10577: if ($selfenrollhash{'admin'}{$type}{$item} ne
10578: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10579: push(@{$changes{'admin'}{$type}},$item);
10580: }
10581: } else {
10582: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10583: push(@{$changes{'admin'}{$type}},$item);
10584: }
10585: }
10586: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10587: push(@{$changes{'admin'}{$type}},$item);
10588: }
10589: }
10590: }
10591: }
10592:
10593: foreach my $item (@{$ordered{'default'}}) {
10594: foreach my $type (@types) {
10595: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10596: if ($item eq 'types') {
10597: unless (($value eq 'all') || ($value eq 'dom')) {
10598: $value = '';
10599: }
10600: } elsif ($item eq 'registered') {
10601: unless ($value eq '1') {
10602: $value = 0;
10603: }
10604: } elsif ($item eq 'approval') {
10605: unless ($value =~ /^[012]$/) {
10606: $value = 0;
10607: }
10608: } else {
10609: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10610: $value = 'none';
10611: }
10612: }
10613: $selfenrollhash{'default'}{$type}{$item} = $value;
10614: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10615: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10616: if ($selfenrollhash{'default'}{$type}{$item} ne
10617: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10618: push(@{$changes{'default'}{$type}},$item);
10619: }
10620: } else {
10621: push(@{$changes{'default'}{$type}},$item);
10622: }
10623: } else {
10624: push(@{$changes{'default'}{$type}},$item);
10625: }
10626: if ($item eq 'limit') {
10627: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10628: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10629: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10630: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10631: }
10632: } else {
10633: $selfenrollhash{'default'}{$type}{'cap'} = '';
10634: }
10635: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10636: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10637: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10638: push(@{$changes{'default'}{$type}},'cap');
10639: }
10640: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10641: push(@{$changes{'default'}{$type}},'cap');
10642: }
10643: }
10644: }
10645: }
10646:
10647: foreach my $item (@{$itemsref}) {
10648: if ($item eq 'fields') {
10649: my @changed;
10650: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10651: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10652: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10653: }
10654: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10655: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10656: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10657: $domconfig{'selfenrollment'}{'validation'}{$item});
10658: } else {
10659: @changed = @{$selfenrollhash{'validation'}{$item}};
10660: }
10661: } else {
10662: @changed = @{$selfenrollhash{'validation'}{$item}};
10663: }
10664: if (@changed) {
10665: if ($selfenrollhash{'validation'}{$item}) {
10666: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10667: } else {
10668: $changes{'validation'}{$item} = &mt('None');
10669: }
10670: }
10671: } else {
10672: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10673: if ($item eq 'markup') {
10674: if ($env{'form.selfenroll_validation_'.$item}) {
10675: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10676: }
10677: }
10678: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10679: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10680: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10681: }
10682: }
10683: }
10684: }
10685:
10686: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10687: $dom);
10688: if ($putresult eq 'ok') {
10689: if (keys(%changes) > 0) {
10690: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10691: $resulttext = &mt('Changes made:').'<ul>';
10692: foreach my $key ('admin','default','validation') {
10693: if (ref($changes{$key}) eq 'HASH') {
10694: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10695: if ($key eq 'validation') {
10696: foreach my $item (@{$itemsref}) {
10697: if (exists($changes{$key}{$item})) {
10698: if ($item eq 'markup') {
10699: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10700: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10701: } else {
10702: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10703: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10704: }
10705: }
10706: }
10707: } else {
10708: foreach my $type (@types) {
10709: if ($type eq 'community') {
10710: $roles{'1'} = &mt('Community personnel');
10711: } else {
10712: $roles{'1'} = &mt('Course personnel');
10713: }
10714: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10715: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10716: if ($key eq 'admin') {
10717: my @mgrdc = ();
10718: if (ref($ordered{$key}) eq 'ARRAY') {
10719: foreach my $item (@{$ordered{'admin'}}) {
10720: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10721: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10722: push(@mgrdc,$item);
10723: }
10724: }
10725: }
10726: if (@mgrdc) {
10727: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10728: } else {
10729: delete($domdefaults{$type.'selfenrolladmdc'});
10730: }
10731: }
10732: } else {
10733: if (ref($ordered{$key}) eq 'ARRAY') {
10734: foreach my $item (@{$ordered{$key}}) {
10735: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10736: $domdefaults{$type.'selfenroll'.$item} =
10737: $selfenrollhash{$key}{$type}{$item};
10738: }
10739: }
10740: }
10741: }
10742: }
10743: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10744: foreach my $item (@{$ordered{$key}}) {
10745: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10746: $resulttext .= '<li>';
10747: if ($key eq 'admin') {
10748: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10749: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10750: } else {
10751: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10752: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10753: }
10754: $resulttext .= '</li>';
10755: }
10756: }
10757: $resulttext .= '</ul></li>';
10758: }
10759: }
10760: $resulttext .= '</ul></li>';
10761: }
10762: }
10763: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10764: my $cachetime = 24*60*60;
10765: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10766: if (ref($lastactref) eq 'HASH') {
10767: $lastactref->{'domdefaults'} = 1;
10768: }
10769: }
10770: }
10771: $resulttext .= '</ul>';
10772: } else {
10773: $resulttext = &mt('No changes made to self-enrollment settings');
10774: }
10775: } else {
10776: $resulttext = '<span class="LC_error">'.
10777: &mt('An error occurred: [_1]',$putresult).'</span>';
10778: }
10779: return $resulttext;
10780: }
10781:
10782: sub modify_usersessions {
10783: my ($dom,$lastactref,%domconfig) = @_;
10784: my @hostingtypes = ('version','excludedomain','includedomain');
10785: my @offloadtypes = ('primary','default');
10786: my %types = (
10787: remote => \@hostingtypes,
10788: hosted => \@hostingtypes,
10789: spares => \@offloadtypes,
10790: );
10791: my @prefixes = ('remote','hosted','spares');
10792: my @lcversions = &Apache::lonnet::all_loncaparevs();
10793: my (%by_ip,%by_location,@intdoms);
10794: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10795: my @locations = sort(keys(%by_location));
10796: my (%defaultshash,%changes);
10797: foreach my $prefix (@prefixes) {
10798: $defaultshash{'usersessions'}{$prefix} = {};
10799: }
10800: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10801: my $resulttext;
10802: my %iphost = &Apache::lonnet::get_iphost();
10803: foreach my $prefix (@prefixes) {
10804: next if ($prefix eq 'spares');
10805: foreach my $type (@{$types{$prefix}}) {
10806: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10807: if ($type eq 'version') {
10808: my $value = $env{'form.'.$prefix.'_'.$type};
10809: my $okvalue;
10810: if ($value ne '') {
10811: if (grep(/^\Q$value\E$/,@lcversions)) {
10812: $okvalue = $value;
10813: }
10814: }
10815: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10816: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10817: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10818: if ($inuse == 0) {
10819: $changes{$prefix}{$type} = 1;
10820: } else {
10821: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10822: $changes{$prefix}{$type} = 1;
10823: }
10824: if ($okvalue ne '') {
10825: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10826: }
10827: }
10828: } else {
10829: if (($inuse == 1) && ($okvalue ne '')) {
10830: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10831: $changes{$prefix}{$type} = 1;
10832: }
10833: }
10834: } else {
10835: if (($inuse == 1) && ($okvalue ne '')) {
10836: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10837: $changes{$prefix}{$type} = 1;
10838: }
10839: }
10840: } else {
10841: if (($inuse == 1) && ($okvalue ne '')) {
10842: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10843: $changes{$prefix}{$type} = 1;
10844: }
10845: }
10846: } else {
10847: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10848: my @okvals;
10849: foreach my $val (@vals) {
10850: if ($val =~ /:/) {
10851: my @items = split(/:/,$val);
10852: foreach my $item (@items) {
10853: if (ref($by_location{$item}) eq 'ARRAY') {
10854: push(@okvals,$item);
10855: }
10856: }
10857: } else {
10858: if (ref($by_location{$val}) eq 'ARRAY') {
10859: push(@okvals,$val);
10860: }
10861: }
10862: }
10863: @okvals = sort(@okvals);
10864: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10865: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10866: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10867: if ($inuse == 0) {
10868: $changes{$prefix}{$type} = 1;
10869: } else {
10870: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10871: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10872: if (@changed > 0) {
10873: $changes{$prefix}{$type} = 1;
10874: }
10875: }
10876: } else {
10877: if ($inuse == 1) {
10878: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10879: $changes{$prefix}{$type} = 1;
10880: }
10881: }
10882: } else {
10883: if ($inuse == 1) {
10884: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10885: $changes{$prefix}{$type} = 1;
10886: }
10887: }
10888: } else {
10889: if ($inuse == 1) {
10890: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10891: $changes{$prefix}{$type} = 1;
10892: }
10893: }
10894: }
10895: }
10896: }
10897:
10898: my @alldoms = &Apache::lonnet::all_domains();
10899: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10900: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10901: my $savespares;
10902:
10903: foreach my $lonhost (sort(keys(%servers))) {
10904: my $serverhomeID =
10905: &Apache::lonnet::get_server_homeID($servers{$lonhost});
10906: my $serverhostname = &Apache::lonnet::hostname($lonhost);
10907: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10908: my %spareschg;
10909: foreach my $type (@{$types{'spares'}}) {
10910: my @okspares;
10911: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10912: foreach my $server (@checked) {
10913: if (&Apache::lonnet::hostname($server) ne '') {
10914: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10915: unless (grep(/^\Q$server\E$/,@okspares)) {
10916: push(@okspares,$server);
10917: }
10918: }
10919: }
10920: }
10921: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10922: my $newspare;
10923: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10924: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
10925: $newspare = $new;
10926: }
10927: }
10928: my @spares;
10929: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10930: @spares = sort(@okspares,$newspare);
10931: } else {
10932: @spares = sort(@okspares);
10933: }
10934: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
10935: if (ref($spareid{$lonhost}) eq 'HASH') {
10936: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
10937: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
10938: if (@diffs > 0) {
10939: $spareschg{$type} = 1;
10940: }
10941: }
10942: }
10943: }
10944: if (keys(%spareschg) > 0) {
10945: $changes{'spares'}{$lonhost} = \%spareschg;
10946: }
10947: }
10948: $defaultshash{'usersessions'}{'offloadnow'} = {};
10949: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
10950: my @okoffload;
10951: if (@offloadnow) {
10952: foreach my $server (@offloadnow) {
10953: if (&Apache::lonnet::hostname($server) ne '') {
10954: unless (grep(/^\Q$server\E$/,@okoffload)) {
10955: push(@okoffload,$server);
10956: }
10957: }
10958: }
10959: if (@okoffload) {
10960: foreach my $lonhost (@okoffload) {
10961: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
10962: }
10963: }
10964: }
10965: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10966: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10967: if (ref($changes{'spares'}) eq 'HASH') {
10968: if (keys(%{$changes{'spares'}}) > 0) {
10969: $savespares = 1;
10970: }
10971: }
10972: } else {
10973: $savespares = 1;
10974: }
10975: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
10976: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
10977: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
10978: $changes{'offloadnow'} = 1;
10979: last;
10980: }
10981: }
10982: unless ($changes{'offloadnow'}) {
10983: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
10984: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
10985: $changes{'offloadnow'} = 1;
10986: last;
10987: }
10988: }
10989: }
10990: } elsif (@okoffload) {
10991: $changes{'offloadnow'} = 1;
10992: }
10993: } elsif (@okoffload) {
10994: $changes{'offloadnow'} = 1;
10995: }
10996: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10997: if ((keys(%changes) > 0) || ($savespares)) {
10998: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10999: $dom);
11000: if ($putresult eq 'ok') {
11001: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11002: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11003: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11004: }
11005: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11006: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11007: }
11008: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11009: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11010: }
11011: }
11012: my $cachetime = 24*60*60;
11013: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11014: if (ref($lastactref) eq 'HASH') {
11015: $lastactref->{'domdefaults'} = 1;
11016: }
11017: if (keys(%changes) > 0) {
11018: my %lt = &usersession_titles();
11019: $resulttext = &mt('Changes made:').'<ul>';
11020: foreach my $prefix (@prefixes) {
11021: if (ref($changes{$prefix}) eq 'HASH') {
11022: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11023: if ($prefix eq 'spares') {
11024: if (ref($changes{$prefix}) eq 'HASH') {
11025: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11026: $resulttext .= '<li><b>'.$lonhost.'</b> ';
11027: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
11028: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11029: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11030: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11031: foreach my $type (@{$types{$prefix}}) {
11032: if ($changes{$prefix}{$lonhost}{$type}) {
11033: my $offloadto = &mt('None');
11034: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11035: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
11036: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11037: }
11038: }
11039: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
11040: }
11041: }
11042: }
11043: $resulttext .= '</li>';
11044: }
11045: }
11046: } else {
11047: foreach my $type (@{$types{$prefix}}) {
11048: if (defined($changes{$prefix}{$type})) {
11049: my $newvalue;
11050: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11051: if (ref($defaultshash{'usersessions'}{$prefix})) {
11052: if ($type eq 'version') {
11053: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11054: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11055: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11056: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11057: }
11058: }
11059: }
11060: }
11061: if ($newvalue eq '') {
11062: if ($type eq 'version') {
11063: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11064: } else {
11065: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11066: }
11067: } else {
11068: if ($type eq 'version') {
11069: $newvalue .= ' '.&mt('(or later)');
11070: }
11071: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
11072: }
11073: }
11074: }
11075: }
11076: $resulttext .= '</ul>';
11077: }
11078: }
11079: if ($changes{'offloadnow'}) {
11080: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11081: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11082: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11083: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11084: $resulttext .= '<li>'.$lonhost.'</li>';
11085: }
11086: $resulttext .= '</ul>';
11087: } else {
11088: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11089: }
11090: } else {
11091: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11092: }
11093: }
11094: $resulttext .= '</ul>';
11095: } else {
11096: $resulttext = $nochgmsg;
11097: }
11098: } else {
11099: $resulttext = '<span class="LC_error">'.
11100: &mt('An error occurred: [_1]',$putresult).'</span>';
11101: }
11102: } else {
11103: $resulttext = $nochgmsg;
11104: }
11105: return $resulttext;
11106: }
11107:
11108: sub modify_loadbalancing {
11109: my ($dom,%domconfig) = @_;
11110: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11111: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11112: my ($othertitle,$usertypes,$types) =
11113: &Apache::loncommon::sorted_inst_types($dom);
11114: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11115: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
11116: my @sparestypes = ('primary','default');
11117: my %typetitles = &sparestype_titles();
11118: my $resulttext;
11119: my (%currbalancer,%currtargets,%currrules,%existing);
11120: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11121: %existing = %{$domconfig{'loadbalancing'}};
11122: }
11123: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11124: \%currtargets,\%currrules);
11125: my ($saveloadbalancing,%defaultshash,%changes);
11126: my ($alltypes,$othertypes,$titles) =
11127: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11128: my %ruletitles = &offloadtype_text();
11129: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11130: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11131: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11132: if ($balancer eq '') {
11133: next;
11134: }
11135: if (!exists($servers{$balancer})) {
11136: if (exists($currbalancer{$balancer})) {
11137: push(@{$changes{'delete'}},$balancer);
11138: }
11139: next;
11140: }
11141: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11142: push(@{$changes{'delete'}},$balancer);
11143: next;
11144: }
11145: if (!exists($currbalancer{$balancer})) {
11146: push(@{$changes{'add'}},$balancer);
11147: }
11148: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11149: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11150: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11151: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11152: $saveloadbalancing = 1;
11153: }
11154: foreach my $sparetype (@sparestypes) {
11155: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11156: my @offloadto;
11157: foreach my $target (@targets) {
11158: if (($servers{$target}) && ($target ne $balancer)) {
11159: if ($sparetype eq 'default') {
11160: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11161: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
11162: }
11163: }
11164: unless(grep(/^\Q$target\E$/,@offloadto)) {
11165: push(@offloadto,$target);
11166: }
11167: }
11168: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
11169: }
11170: }
11171: if (ref($currtargets{$balancer}) eq 'HASH') {
11172: foreach my $sparetype (@sparestypes) {
11173: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11174: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
11175: if (@targetdiffs > 0) {
11176: $changes{'curr'}{$balancer}{'targets'} = 1;
11177: }
11178: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11179: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11180: $changes{'curr'}{$balancer}{'targets'} = 1;
11181: }
11182: }
11183: }
11184: } else {
11185: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11186: foreach my $sparetype (@sparestypes) {
11187: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11188: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11189: $changes{'curr'}{$balancer}{'targets'} = 1;
11190: }
11191: }
11192: }
11193: }
11194: }
11195: my $ishomedom;
11196: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11197: $ishomedom = 1;
11198: }
11199: if (ref($alltypes) eq 'ARRAY') {
11200: foreach my $type (@{$alltypes}) {
11201: my $rule;
11202: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
11203: (!$ishomedom)) {
11204: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11205: }
11206: if ($rule eq 'specific') {
11207: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11208: if (exists($servers{$specifiedhost})) {
11209: $rule = $specifiedhost;
11210: }
11211: }
11212: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11213: if (ref($currrules{$balancer}) eq 'HASH') {
11214: if ($rule ne $currrules{$balancer}{$type}) {
11215: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
11216: }
11217: } elsif ($rule ne '') {
11218: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
11219: }
11220: }
11221: }
11222: }
11223: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11224: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11225: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11226: $defaultshash{'loadbalancing'} = {};
11227: }
11228: my $putresult = &Apache::lonnet::put_dom('configuration',
11229: \%defaultshash,$dom);
11230: if ($putresult eq 'ok') {
11231: if (keys(%changes) > 0) {
11232: my %toupdate;
11233: if (ref($changes{'delete'}) eq 'ARRAY') {
11234: foreach my $balancer (sort(@{$changes{'delete'}})) {
11235: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
11236: $toupdate{$balancer} = 1;
11237: }
11238: }
11239: if (ref($changes{'add'}) eq 'ARRAY') {
11240: foreach my $balancer (sort(@{$changes{'add'}})) {
11241: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
11242: $toupdate{$balancer} = 1;
11243: }
11244: }
11245: if (ref($changes{'curr'}) eq 'HASH') {
11246: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
11247: $toupdate{$balancer} = 1;
11248: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11249: if ($changes{'curr'}{$balancer}{'targets'}) {
11250: my %offloadstr;
11251: foreach my $sparetype (@sparestypes) {
11252: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11253: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11254: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11255: }
11256: }
11257: }
11258: if (keys(%offloadstr) == 0) {
11259: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
11260: } else {
11261: my $showoffload;
11262: foreach my $sparetype (@sparestypes) {
11263: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11264: if (defined($offloadstr{$sparetype})) {
11265: $showoffload .= $offloadstr{$sparetype};
11266: } else {
11267: $showoffload .= &mt('None');
11268: }
11269: $showoffload .= (' 'x3);
11270: }
11271: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
11272: }
11273: }
11274: }
11275: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11276: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11277: foreach my $type (@{$alltypes}) {
11278: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11279: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11280: my $balancetext;
11281: if ($rule eq '') {
11282: $balancetext = $ruletitles{'default'};
11283: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
11284: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11285: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11286: foreach my $sparetype (@sparestypes) {
11287: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11288: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11289: }
11290: }
11291: foreach my $item (@{$alltypes}) {
11292: next if ($item =~ /^_LC_ipchange/);
11293: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11294: if ($hasrule eq 'homeserver') {
11295: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11296: } else {
11297: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11298: if ($servers{$hasrule}) {
11299: $toupdate{$hasrule} = 1;
11300: }
11301: }
11302: }
11303: }
11304: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11305: $balancetext = $ruletitles{$rule};
11306: } else {
11307: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11308: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11309: if ($receiver) {
11310: $toupdate{$receiver};
11311: }
11312: }
11313: } else {
11314: $balancetext = $ruletitles{$rule};
11315: }
11316: } else {
11317: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11318: }
11319: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
11320: }
11321: }
11322: }
11323: }
11324: if (keys(%toupdate)) {
11325: my %thismachine;
11326: my $updatedhere;
11327: my $cachetime = 60*60*24;
11328: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11329: foreach my $lonhost (keys(%toupdate)) {
11330: if ($thismachine{$lonhost}) {
11331: unless ($updatedhere) {
11332: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11333: $defaultshash{'loadbalancing'},
11334: $cachetime);
11335: $updatedhere = 1;
11336: }
11337: } else {
11338: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11339: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11340: }
11341: }
11342: }
11343: }
11344: }
11345: if ($resulttext ne '') {
11346: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
11347: } else {
11348: $resulttext = $nochgmsg;
11349: }
11350: } else {
11351: $resulttext = $nochgmsg;
11352: }
11353: } else {
11354: $resulttext = '<span class="LC_error">'.
11355: &mt('An error occurred: [_1]',$putresult).'</span>';
11356: }
11357: } else {
11358: $resulttext = $nochgmsg;
11359: }
11360: return $resulttext;
11361: }
11362:
11363: sub recurse_check {
11364: my ($chkcats,$categories,$depth,$name) = @_;
11365: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11366: my $chg = 0;
11367: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11368: my $category = $chkcats->[$depth]{$name}[$j];
11369: my $item;
11370: if ($category eq '') {
11371: $chg ++;
11372: } else {
11373: my $deeper = $depth + 1;
11374: $item = &escape($category).':'.&escape($name).':'.$depth;
11375: if ($chg) {
11376: $categories->{$item} -= $chg;
11377: }
11378: &recurse_check($chkcats,$categories,$deeper,$category);
11379: $deeper --;
11380: }
11381: }
11382: }
11383: return;
11384: }
11385:
11386: sub recurse_cat_deletes {
11387: my ($item,$coursecategories,$deletions) = @_;
11388: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11389: my $subdepth = $depth + 1;
11390: if (ref($coursecategories) eq 'HASH') {
11391: foreach my $subitem (keys(%{$coursecategories})) {
11392: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11393: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11394: delete($coursecategories->{$subitem});
11395: $deletions->{$subitem} = 1;
11396: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
11397: }
11398: }
11399: }
11400: return;
11401: }
11402:
11403: sub get_active_dcs {
11404: my ($dom) = @_;
11405: my $now = time;
11406: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
11407: my %domcoords;
11408: my $numdcs = 0;
11409: foreach my $server (keys(%dompersonnel)) {
11410: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11411: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
11412: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
11413: }
11414: }
11415: return %domcoords;
11416: }
11417:
11418: sub active_dc_picker {
11419: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
11420: my %domcoords = &get_active_dcs($dom);
11421: my @domcoord = keys(%domcoords);
11422: if (keys(%currhash)) {
11423: foreach my $dc (keys(%currhash)) {
11424: unless (exists($domcoords{$dc})) {
11425: push(@domcoord,$dc);
11426: }
11427: }
11428: }
11429: @domcoord = sort(@domcoord);
11430: my $numdcs = scalar(@domcoord);
11431: my $rows = 0;
11432: my $table;
11433: if ($numdcs > 1) {
11434: $table = '<table>';
11435: for (my $i=0; $i<@domcoord; $i++) {
11436: my $rem = $i%($numinrow);
11437: if ($rem == 0) {
11438: if ($i > 0) {
11439: $table .= '</tr>';
11440: }
11441: $table .= '<tr>';
11442: $rows ++;
11443: }
11444: my $check = '';
11445: if ($inputtype eq 'radio') {
11446: if (keys(%currhash) == 0) {
11447: if (!$i) {
11448: $check = ' checked="checked"';
11449: }
11450: } elsif (exists($currhash{$domcoord[$i]})) {
11451: $check = ' checked="checked"';
11452: }
11453: } else {
11454: if (exists($currhash{$domcoord[$i]})) {
11455: $check = ' checked="checked"';
11456: }
11457: }
11458: if ($i == @domcoord - 1) {
11459: my $colsleft = $numinrow - $rem;
11460: if ($colsleft > 1) {
11461: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
11462: } else {
11463: $table .= '<td class="LC_left_item">';
11464: }
11465: } else {
11466: $table .= '<td class="LC_left_item">';
11467: }
11468: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11469: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11470: $table .= '<span class="LC_nobreak"><label>'.
11471: '<input type="'.$inputtype.'" name="'.$name.'"'.
11472: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11473: if ($user ne $dcname.':'.$dcdom) {
11474: $table .= ' ('.$dcname.':'.$dcdom.')';
11475: }
11476: $table .= '</label></span></td>';
11477: }
11478: $table .= '</tr></table>';
11479: } elsif ($numdcs == 1) {
11480: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11481: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11482: if ($inputtype eq 'radio') {
11483: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
11484: if ($user ne $dcname.':'.$dcdom) {
11485: $table .= ' ('.$dcname.':'.$dcdom.')';
11486: }
11487: } else {
11488: my $check;
11489: if (exists($currhash{$domcoord[0]})) {
11490: $check = ' checked="checked"';
11491: }
11492: $table = '<span class="LC_nobreak"><label>'.
11493: '<input type="checkbox" name="'.$name.'" '.
11494: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
11495: if ($user ne $dcname.':'.$dcdom) {
11496: $table .= ' ('.$dcname.':'.$dcdom.')';
11497: }
11498: $table .= '</label></span>';
11499: $rows ++;
11500: }
11501: }
11502: return ($numdcs,$table,$rows);
11503: }
11504:
11505: sub usersession_titles {
11506: return &Apache::lonlocal::texthash(
11507: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11508: remote => 'Hosting of sessions for users in this domain on servers in other domains',
11509: spares => 'Servers offloaded to, when busy',
11510: version => 'LON-CAPA version requirement',
11511: excludedomain => 'Allow all, but exclude specific domains',
11512: includedomain => 'Deny all, but include specific domains',
11513: primary => 'Primary (checked first)',
11514: default => 'Default',
11515: );
11516: }
11517:
11518: sub id_for_thisdom {
11519: my (%servers) = @_;
11520: my %altids;
11521: foreach my $server (keys(%servers)) {
11522: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11523: if ($serverhome ne $server) {
11524: $altids{$serverhome} = $server;
11525: }
11526: }
11527: return %altids;
11528: }
11529:
11530: sub count_servers {
11531: my ($currbalancer,%servers) = @_;
11532: my (@spares,$numspares);
11533: foreach my $lonhost (sort(keys(%servers))) {
11534: next if ($currbalancer eq $lonhost);
11535: push(@spares,$lonhost);
11536: }
11537: if ($currbalancer) {
11538: $numspares = scalar(@spares);
11539: } else {
11540: $numspares = scalar(@spares) - 1;
11541: }
11542: return ($numspares,@spares);
11543: }
11544:
11545: sub lonbalance_targets_js {
11546: my ($dom,$types,$servers,$settings) = @_;
11547: my $select = &mt('Select');
11548: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11549: if (ref($servers) eq 'HASH') {
11550: $alltargets = join("','",sort(keys(%{$servers})));
11551: my @homedoms;
11552: foreach my $server (sort(keys(%{$servers}))) {
11553: if (&Apache::lonnet::host_domain($server) eq $dom) {
11554: push(@homedoms,'1');
11555: } else {
11556: push(@homedoms,'0');
11557: }
11558: }
11559: $allishome = join("','",@homedoms);
11560: }
11561: if (ref($types) eq 'ARRAY') {
11562: if (@{$types} > 0) {
11563: @alltypes = @{$types};
11564: }
11565: }
11566: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11567: $allinsttypes = join("','",@alltypes);
11568: my (%currbalancer,%currtargets,%currrules,%existing);
11569: if (ref($settings) eq 'HASH') {
11570: %existing = %{$settings};
11571: }
11572: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11573: \%currtargets,\%currrules);
11574: my $balancers = join("','",sort(keys(%currbalancer)));
11575: return <<"END";
11576:
11577: <script type="text/javascript">
11578: // <![CDATA[
11579:
11580: currBalancers = new Array('$balancers');
11581:
11582: function toggleTargets(balnum) {
11583: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11584: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11585: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11586: var prevbalancer = prevhostitem.value;
11587: var baltotal = document.getElementById('loadbalancing_total').value;
11588: prevhostitem.value = balancer;
11589: if (prevbalancer != '') {
11590: var prevIdx = currBalancers.indexOf(prevbalancer);
11591: if (prevIdx != -1) {
11592: currBalancers.splice(prevIdx,1);
11593: }
11594: }
11595: if (balancer == '') {
11596: hideSpares(balnum);
11597: } else {
11598: var currIdx = currBalancers.indexOf(balancer);
11599: if (currIdx == -1) {
11600: currBalancers.push(balancer);
11601: }
11602: var homedoms = new Array('$allishome');
11603: var ishomedom = homedoms[lonhostitem.selectedIndex];
11604: showSpares(balancer,ishomedom,balnum);
11605: }
11606: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
11607: return;
11608: }
11609:
11610: function showSpares(balancer,ishomedom,balnum) {
11611: var alltargets = new Array('$alltargets');
11612: var insttypes = new Array('$allinsttypes');
11613: var offloadtypes = new Array('primary','default');
11614:
11615: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11616: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
11617:
11618: for (var i=0; i<offloadtypes.length; i++) {
11619: var count = 0;
11620: for (var j=0; j<alltargets.length; j++) {
11621: if (alltargets[j] != balancer) {
11622: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11623: item.value = alltargets[j];
11624: item.style.textAlign='left';
11625: item.style.textFace='normal';
11626: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11627: if (currBalancers.indexOf(alltargets[j]) == -1) {
11628: item.disabled = '';
11629: } else {
11630: item.disabled = 'disabled';
11631: item.checked = false;
11632: }
11633: count ++;
11634: }
11635: }
11636: }
11637: for (var k=0; k<insttypes.length; k++) {
11638: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
11639: if (ishomedom == 1) {
11640: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11641: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11642: } else {
11643: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11644: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11645: }
11646: } else {
11647: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11648: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11649: }
11650: if ((insttypes[k] != '_LC_external') &&
11651: ((insttypes[k] != '_LC_internetdom') ||
11652: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
11653: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11654: item.options.length = 0;
11655: item.options[0] = new Option("","",true,true);
11656: var idx = 0;
11657: for (var m=0; m<alltargets.length; m++) {
11658: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11659: idx ++;
11660: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11661: }
11662: }
11663: }
11664: }
11665: return;
11666: }
11667:
11668: function hideSpares(balnum) {
11669: var alltargets = new Array('$alltargets');
11670: var insttypes = new Array('$allinsttypes');
11671: var offloadtypes = new Array('primary','default');
11672:
11673: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11674: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
11675:
11676: var total = alltargets.length - 1;
11677: for (var i=0; i<offloadtypes; i++) {
11678: for (var j=0; j<total; j++) {
11679: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11680: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11681: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
11682: }
11683: }
11684: for (var k=0; k<insttypes.length; k++) {
11685: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11686: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11687: if (insttypes[k] != '_LC_external') {
11688: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11689: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
11690: }
11691: }
11692: return;
11693: }
11694:
11695: function checkOffloads(item,balnum,type) {
11696: var alltargets = new Array('$alltargets');
11697: var offloadtypes = new Array('primary','default');
11698: if (item.checked) {
11699: var total = alltargets.length - 1;
11700: var other;
11701: if (type == offloadtypes[0]) {
11702: other = offloadtypes[1];
11703: } else {
11704: other = offloadtypes[0];
11705: }
11706: for (var i=0; i<total; i++) {
11707: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
11708: if (server == item.value) {
11709: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11710: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
11711: }
11712: }
11713: }
11714: }
11715: return;
11716: }
11717:
11718: function singleServerToggle(balnum,type) {
11719: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
11720: if (offloadtoSelIdx == 0) {
11721: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11722: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11723:
11724: } else {
11725: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11726: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11727: }
11728: return;
11729: }
11730:
11731: function balanceruleChange(formname,balnum,type) {
11732: if (type == '_LC_external') {
11733: return;
11734: }
11735: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
11736: for (var i=0; i<typesRules.length; i++) {
11737: if (formname.elements[typesRules[i]].checked) {
11738: if (formname.elements[typesRules[i]].value != 'specific') {
11739: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11740: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11741: } else {
11742: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11743: }
11744: }
11745: }
11746: return;
11747: }
11748:
11749: function balancerDeleteChange(balnum) {
11750: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11751: var baltotal = document.getElementById('loadbalancing_total').value;
11752: var addtarget;
11753: var removetarget;
11754: var action = 'delete';
11755: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11756: var lonhost = hostitem.value;
11757: var currIdx = currBalancers.indexOf(lonhost);
11758: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11759: if (currIdx != -1) {
11760: currBalancers.splice(currIdx,1);
11761: }
11762: addtarget = lonhost;
11763: } else {
11764: if (currIdx == -1) {
11765: currBalancers.push(lonhost);
11766: }
11767: removetarget = lonhost;
11768: action = 'undelete';
11769: }
11770: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11771: }
11772: return;
11773: }
11774:
11775: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11776: if (baltotal > 1) {
11777: var offloadtypes = new Array('primary','default');
11778: var alltargets = new Array('$alltargets');
11779: var insttypes = new Array('$allinsttypes');
11780: for (var i=0; i<baltotal; i++) {
11781: if (i != balnum) {
11782: for (var j=0; j<offloadtypes.length; j++) {
11783: var total = alltargets.length - 1;
11784: for (var k=0; k<total; k++) {
11785: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11786: var server = serveritem.value;
11787: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11788: if (server == addtarget) {
11789: serveritem.disabled = '';
11790: }
11791: }
11792: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11793: if (server == removetarget) {
11794: serveritem.disabled = 'disabled';
11795: serveritem.checked = false;
11796: }
11797: }
11798: }
11799: }
11800: for (var j=0; j<insttypes.length; j++) {
11801: if (insttypes[j] != '_LC_external') {
11802: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11803: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11804: var currSel = singleserver.selectedIndex;
11805: var currVal = singleserver.options[currSel].value;
11806: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11807: var numoptions = singleserver.options.length;
11808: var needsnew = 1;
11809: for (var k=0; k<numoptions; k++) {
11810: if (singleserver.options[k] == addtarget) {
11811: needsnew = 0;
11812: break;
11813: }
11814: }
11815: if (needsnew == 1) {
11816: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11817: }
11818: }
11819: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11820: singleserver.options.length = 0;
11821: if ((currVal) && (currVal != removetarget)) {
11822: singleserver.options[0] = new Option("","",false,false);
11823: } else {
11824: singleserver.options[0] = new Option("","",true,true);
11825: }
11826: var idx = 0;
11827: for (var m=0; m<alltargets.length; m++) {
11828: if (currBalancers.indexOf(alltargets[m]) == -1) {
11829: idx ++;
11830: if (currVal == alltargets[m]) {
11831: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11832: } else {
11833: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11834: }
11835: }
11836: }
11837: }
11838: }
11839: }
11840: }
11841: }
11842: }
11843: }
11844: return;
11845: }
11846:
11847: // ]]>
11848: </script>
11849:
11850: END
11851: }
11852:
11853: sub new_spares_js {
11854: my @sparestypes = ('primary','default');
11855: my $types = join("','",@sparestypes);
11856: my $select = &mt('Select');
11857: return <<"END";
11858:
11859: <script type="text/javascript">
11860: // <![CDATA[
11861:
11862: function updateNewSpares(formname,lonhost) {
11863: var types = new Array('$types');
11864: var include = new Array();
11865: var exclude = new Array();
11866: for (var i=0; i<types.length; i++) {
11867: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11868: for (var j=0; j<spareboxes.length; j++) {
11869: if (formname.elements[spareboxes[j]].checked) {
11870: exclude.push(formname.elements[spareboxes[j]].value);
11871: } else {
11872: include.push(formname.elements[spareboxes[j]].value);
11873: }
11874: }
11875: }
11876: for (var i=0; i<types.length; i++) {
11877: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11878: var selIdx = newSpare.selectedIndex;
11879: var currnew = newSpare.options[selIdx].value;
11880: var okSpares = new Array();
11881: for (var j=0; j<newSpare.options.length; j++) {
11882: var possible = newSpare.options[j].value;
11883: if (possible != '') {
11884: if (exclude.indexOf(possible) == -1) {
11885: okSpares.push(possible);
11886: } else {
11887: if (currnew == possible) {
11888: selIdx = 0;
11889: }
11890: }
11891: }
11892: }
11893: for (var k=0; k<include.length; k++) {
11894: if (okSpares.indexOf(include[k]) == -1) {
11895: okSpares.push(include[k]);
11896: }
11897: }
11898: okSpares.sort();
11899: newSpare.options.length = 0;
11900: if (selIdx == 0) {
11901: newSpare.options[0] = new Option("$select","",true,true);
11902: } else {
11903: newSpare.options[0] = new Option("$select","",false,false);
11904: }
11905: for (var m=0; m<okSpares.length; m++) {
11906: var idx = m+1;
11907: var selThis = 0;
11908: if (selIdx != 0) {
11909: if (okSpares[m] == currnew) {
11910: selThis = 1;
11911: }
11912: }
11913: if (selThis == 1) {
11914: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11915: } else {
11916: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11917: }
11918: }
11919: }
11920: return;
11921: }
11922:
11923: function checkNewSpares(lonhost,type) {
11924: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11925: var chosen = newSpare.options[newSpare.selectedIndex].value;
11926: if (chosen != '') {
11927: var othertype;
11928: var othernewSpare;
11929: if (type == 'primary') {
11930: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11931: }
11932: if (type == 'default') {
11933: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11934: }
11935: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11936: othernewSpare.selectedIndex = 0;
11937: }
11938: }
11939: return;
11940: }
11941:
11942: // ]]>
11943: </script>
11944:
11945: END
11946:
11947: }
11948:
11949: sub common_domprefs_js {
11950: return <<"END";
11951:
11952: <script type="text/javascript">
11953: // <![CDATA[
11954:
11955: function getIndicesByName(formname,item) {
11956: var group = new Array();
11957: for (var i=0;i<formname.elements.length;i++) {
11958: if (formname.elements[i].name == item) {
11959: group.push(formname.elements[i].id);
11960: }
11961: }
11962: return group;
11963: }
11964:
11965: // ]]>
11966: </script>
11967:
11968: END
11969:
11970: }
11971:
11972: sub recaptcha_js {
11973: my %lt = &captcha_phrases();
11974: return <<"END";
11975:
11976: <script type="text/javascript">
11977: // <![CDATA[
11978:
11979: function updateCaptcha(caller,context) {
11980: var privitem;
11981: var pubitem;
11982: var privtext;
11983: var pubtext;
11984: if (document.getElementById(context+'_recaptchapub')) {
11985: pubitem = document.getElementById(context+'_recaptchapub');
11986: } else {
11987: return;
11988: }
11989: if (document.getElementById(context+'_recaptchapriv')) {
11990: privitem = document.getElementById(context+'_recaptchapriv');
11991: } else {
11992: return;
11993: }
11994: if (document.getElementById(context+'_recaptchapubtxt')) {
11995: pubtext = document.getElementById(context+'_recaptchapubtxt');
11996: } else {
11997: return;
11998: }
11999: if (document.getElementById(context+'_recaptchaprivtxt')) {
12000: privtext = document.getElementById(context+'_recaptchaprivtxt');
12001: } else {
12002: return;
12003: }
12004: if (caller.checked) {
12005: if (caller.value == 'recaptcha') {
12006: pubitem.type = 'text';
12007: privitem.type = 'text';
12008: pubitem.size = '40';
12009: privitem.size = '40';
12010: pubtext.innerHTML = "$lt{'pub'}";
12011: privtext.innerHTML = "$lt{'priv'}";
12012: } else {
12013: pubitem.type = 'hidden';
12014: privitem.type = 'hidden';
12015: pubtext.innerHTML = '';
12016: privtext.innerHTML = '';
12017: }
12018: }
12019: return;
12020: }
12021:
12022: // ]]>
12023: </script>
12024:
12025: END
12026:
12027: }
12028:
12029: sub toggle_display_js {
12030: return <<"END";
12031:
12032: <script type="text/javascript">
12033: // <![CDATA[
12034:
12035: function toggleDisplay(domForm,caller) {
12036: if (document.getElementById(caller)) {
12037: var divitem = document.getElementById(caller);
12038: var optionsElement = domForm.coursecredits;
12039: if (caller == 'emailoptions') {
12040: optionsElement = domForm.cancreate_email;
12041: }
12042: if (caller == 'studentsubmission') {
12043: optionsElement = domForm.postsubmit;
12044: }
12045: if (optionsElement.length) {
12046: var currval;
12047: for (var i=0; i<optionsElement.length; i++) {
12048: if (optionsElement[i].checked) {
12049: currval = optionsElement[i].value;
12050: }
12051: }
12052: if (currval == 1) {
12053: divitem.style.display = 'block';
12054: } else {
12055: divitem.style.display = 'none';
12056: }
12057: }
12058: }
12059: return;
12060: }
12061:
12062: // ]]>
12063: </script>
12064:
12065: END
12066:
12067: }
12068:
12069: sub captcha_phrases {
12070: return &Apache::lonlocal::texthash (
12071: priv => 'Private key',
12072: pub => 'Public key',
12073: original => 'original (CAPTCHA)',
12074: recaptcha => 'successor (ReCAPTCHA)',
12075: notused => 'unused',
12076: );
12077: }
12078:
12079: sub devalidate_remote_domconfs {
12080: my ($dom,$cachekeys) = @_;
12081: return unless (ref($cachekeys) eq 'HASH');
12082: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12083: my %thismachine;
12084: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12085: my @posscached = ('domainconfig','domdefaults');
12086: if (keys(%servers)) {
12087: foreach my $server (keys(%servers)) {
12088: next if ($thismachine{$server});
12089: my @cached;
12090: foreach my $name (@posscached) {
12091: if ($cachekeys->{$name}) {
12092: push(@cached,&escape($name).':'.&escape($dom));
12093: }
12094: }
12095: if (@cached) {
12096: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12097: }
12098: }
12099: }
12100: return;
12101: }
12102:
12103: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>