Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.23
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.23! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.22 2013/08/08 00:54:47 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 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:
1.101 raeburn 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
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 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
1.160.6.5 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
1.101 raeburn 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,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
99:
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
107: (official, unofficial and community). In each case the radio buttons allow the
108: selection of one of four values:
109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.69 raeburn 168: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 169: use LONCAPA::Enrollment;
1.81 raeburn 170: use LONCAPA::lonauthcgi();
1.9 raeburn 171: use File::Copy;
1.43 raeburn 172: use Locale::Language;
1.62 raeburn 173: use DateTime::TimeZone;
1.68 raeburn 174: use DateTime::Locale;
1.1 raeburn 175:
1.155 raeburn 176: my $registered_cleanup;
177: my $modified_urls;
178:
1.1 raeburn 179: sub handler {
180: my $r=shift;
181: if ($r->header_only) {
182: &Apache::loncommon::content_type($r,'text/html');
183: $r->send_http_header;
184: return OK;
185: }
186:
1.91 raeburn 187: my $context = 'domain';
1.1 raeburn 188: my $dom = $env{'request.role.domain'};
1.5 albertel 189: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 190: if (&Apache::lonnet::allowed('mau',$dom)) {
191: &Apache::loncommon::content_type($r,'text/html');
192: $r->send_http_header;
193: } else {
194: $env{'user.error.msg'}=
195: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
196: return HTTP_NOT_ACCEPTABLE;
197: }
1.155 raeburn 198:
199: $registered_cleanup=0;
200: @{$modified_urls}=();
201:
1.1 raeburn 202: &Apache::lonhtmlcommon::clear_breadcrumbs();
203: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 204: ['phase','actions']);
1.30 raeburn 205: my $phase = 'pickactions';
1.3 raeburn 206: if ( exists($env{'form.phase'}) ) {
207: $phase = $env{'form.phase'};
208: }
1.150 raeburn 209: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 210: my %domconfig =
1.6 raeburn 211: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 212: 'quotas','autoenroll','autoupdate','autocreate',
213: 'directorysrch','usercreation','usermodification',
214: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 215: 'serverstatuses','requestcourses','coursedefaults',
216: 'usersessions','loadbalancing','requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 219: 'usercreation','usermodification','scantron',
1.160.6.5 raeburn 220: 'requestcourses','requestauthor','coursecategories',
1.160.6.16 raeburn 221: 'serverstatuses','coursedefaults','usersessions');
1.160.6.7 raeburn 222: my %existing;
223: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
224: %existing = %{$domconfig{'loadbalancing'}};
225: }
226: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 227: push(@prefs_order,'loadbalancing');
228: }
1.30 raeburn 229: my %prefs = (
230: 'rolecolors' =>
231: { text => 'Default color schemes',
1.67 raeburn 232: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 233: header => [{col1 => 'Student Settings',
234: col2 => '',},
235: {col1 => 'Coordinator Settings',
236: col2 => '',},
237: {col1 => 'Author Settings',
238: col2 => '',},
239: {col1 => 'Administrator Settings',
240: col2 => '',}],
241: },
1.110 raeburn 242: 'login' =>
1.30 raeburn 243: { text => 'Log-in page options',
1.67 raeburn 244: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 245: header => [{col1 => 'Log-in Page Items',
246: col2 => '',},
247: {col1 => 'Log-in Help',
248: col2 => 'Value'}],
1.30 raeburn 249: },
1.43 raeburn 250: 'defaults' =>
1.141 raeburn 251: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 252: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 253: header => [{col1 => 'Setting',
254: col2 => 'Value'}],
255: },
1.30 raeburn 256: 'quotas' =>
1.160.6.20 raeburn 257: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 258: help => 'Domain_Configuration_Quotas',
1.77 raeburn 259: header => [{col1 => 'User affiliation',
1.72 raeburn 260: col2 => 'Available tools',
1.160.6.20 raeburn 261: col3 => 'Quotas, Mb; (Authoring requires role)',}],
1.30 raeburn 262: },
263: 'autoenroll' =>
264: { text => 'Auto-enrollment settings',
1.67 raeburn 265: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 266: header => [{col1 => 'Configuration setting',
267: col2 => 'Value(s)'}],
268: },
269: 'autoupdate' =>
270: { text => 'Auto-update settings',
1.67 raeburn 271: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 272: header => [{col1 => 'Setting',
273: col2 => 'Value',},
1.131 raeburn 274: {col1 => 'Setting',
275: col2 => 'Affiliation'},
1.43 raeburn 276: {col1 => 'User population',
1.131 raeburn 277: col2 => 'Updateable user data'}],
1.30 raeburn 278: },
1.125 raeburn 279: 'autocreate' =>
280: { text => 'Auto-course creation settings',
281: help => 'Domain_Configuration_Auto_Creation',
282: header => [{col1 => 'Configuration Setting',
283: col2 => 'Value',}],
284: },
1.30 raeburn 285: 'directorysrch' =>
286: { text => 'Institutional directory searches',
1.67 raeburn 287: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 288: header => [{col1 => 'Setting',
289: col2 => 'Value',}],
290: },
291: 'contacts' =>
292: { text => 'Contact Information',
1.67 raeburn 293: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 294: header => [{col1 => 'Setting',
295: col2 => 'Value',}],
296: },
297:
298: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.69 raeburn 308: 'usermodification' =>
1.33 raeburn 309: { text => 'User modification',
1.67 raeburn 310: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 311: header => [{col1 => 'Target user has role',
312: col2 => 'User information updateable in author context'},
313: {col1 => 'Target user has role',
1.63 raeburn 314: col2 => 'User information updateable in course context'},
315: {col1 => "Status of user",
316: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 317: },
1.69 raeburn 318: 'scantron' =>
1.95 www 319: { text => 'Bubblesheet format file',
1.67 raeburn 320: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 321: header => [ {col1 => 'Item',
322: col2 => '',
323: }],
324: },
1.86 raeburn 325: 'requestcourses' =>
326: {text => 'Request creation of courses',
327: help => 'Domain_Configuration_Request_Courses',
328: header => [{col1 => 'User affiliation',
1.102 raeburn 329: col2 => 'Availability/Processing of requests',},
330: {col1 => 'Setting',
331: col2 => 'Value'}],
1.86 raeburn 332: },
1.160.6.5 raeburn 333: 'requestauthor' =>
334: {text => 'Request authoring space',
335: help => 'Domain_Configuration_Request_Author',
336: header => [{col1 => 'User affiliation',
337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
339: col2 => 'Value'}],
340: },
1.69 raeburn 341: 'coursecategories' =>
1.120 raeburn 342: { text => 'Cataloging of courses/communities',
1.67 raeburn 343: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 344: header => [{col1 => 'Category settings',
1.57 raeburn 345: col2 => '',},
346: {col1 => 'Categories',
347: col2 => '',
348: }],
1.69 raeburn 349: },
350: 'serverstatuses' =>
1.77 raeburn 351: {text => 'Access to server status pages',
1.69 raeburn 352: help => 'Domain_Configuration_Server_Status',
353: header => [{col1 => 'Status Page',
354: col2 => 'Other named users',
355: col3 => 'Specific IPs',
356: }],
357: },
1.160.6.16 raeburn 358: 'coursedefaults' =>
359: {text => 'Course/Community defaults',
360: help => 'Domain_Configuration_Course_Defaults',
361: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
362: col2 => 'Value',},],
363: },
1.141 raeburn 364: 'usersessions' =>
1.145 raeburn 365: {text => 'User session hosting/offloading',
1.137 raeburn 366: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 367: header => [{col1 => 'Domain server',
368: col2 => 'Servers to offload sessions to when busy'},
369: {col1 => 'Hosting of users from other domains',
1.137 raeburn 370: col2 => 'Rules'},
371: {col1 => "Hosting domain's own users elsewhere",
372: col2 => 'Rules'}],
373: },
1.150 raeburn 374: 'loadbalancing' =>
1.160.6.7 raeburn 375: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 376: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 377: header => [{col1 => 'Balancers',
1.150 raeburn 378: col2 => 'Default destinations',
1.160.6.13 raeburn 379: col3 => 'User affiliation',
1.150 raeburn 380: col4 => 'Overrides'},
381: ],
382: },
1.3 raeburn 383: );
1.110 raeburn 384: if (keys(%servers) > 1) {
385: $prefs{'login'} = { text => 'Log-in page options',
386: help => 'Domain_Configuration_Login_Page',
387: header => [{col1 => 'Log-in Service',
388: col2 => 'Server Setting',},
389: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 390: col2 => ''},
391: {col1 => 'Log-in Help',
392: col2 => 'Value'}],
1.110 raeburn 393: };
394: }
1.160.6.13 raeburn 395:
1.6 raeburn 396: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 397: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 398: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 399: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 400: text=>"Settings to display/modify"});
1.9 raeburn 401: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 402:
1.3 raeburn 403: if ($phase eq 'process') {
1.91 raeburn 404: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 405: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 406: my $js = &recaptcha_js().
407: &credits_js();
1.160.6.7 raeburn 408: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 409: my ($othertitle,$usertypes,$types) =
410: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 411: $js .= &lonbalance_targets_js($dom,$types,\%servers,
412: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 413: &new_spares_js().
414: &common_domprefs_js().
415: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 416: }
1.150 raeburn 417: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 418: } else {
1.160.6.11 raeburn 419: # check if domconfig user exists for the domain.
420: my $servadm = $r->dir_config('lonAdmEMail');
421: my ($configuserok,$author_ok,$switchserver) =
422: &config_check($dom,$confname,$servadm);
423: unless ($configuserok eq 'ok') {
424: &Apache::lonconfigsettings::print_header($r,$phase,$context);
425: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
426: $confname).
427: '<br />'
428: );
429: if ($switchserver) {
430: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
431: '<br />'.
432: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
433: '<br />'.
434: &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).
435: '<br />'.
436: &mt('To do that now, use the following link: [_1]',$switchserver)
437: );
438: } else {
439: $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.').
440: '<br />'.
441: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
442: );
443: }
444: $r->print(&Apache::loncommon::end_page());
445: return OK;
446: }
1.21 raeburn 447: if (keys(%domconfig) == 0) {
448: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 449: my @ids=&Apache::lonnet::current_machine_ids();
450: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 451: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 452: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 453: my $custom_img_count = 0;
454: foreach my $img (@loginimages) {
455: if ($designhash{$dom.'.login.'.$img} ne '') {
456: $custom_img_count ++;
457: }
458: }
459: foreach my $role (@roles) {
460: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
461: $custom_img_count ++;
462: }
463: }
464: if ($custom_img_count > 0) {
1.94 raeburn 465: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 466: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 467: $r->print(
468: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
469: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
470: &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 />'.
471: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
472: if ($switch_server) {
1.30 raeburn 473: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 474: }
1.91 raeburn 475: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 476: return OK;
477: }
478: }
479: }
1.91 raeburn 480: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 481: }
482: return OK;
483: }
484:
485: sub process_changes {
1.92 raeburn 486: my ($r,$dom,$confname,$action,$roles,$values) = @_;
487: my %domconfig;
488: if (ref($values) eq 'HASH') {
489: %domconfig = %{$values};
490: }
1.3 raeburn 491: my $output;
492: if ($action eq 'login') {
1.9 raeburn 493: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 494: } elsif ($action eq 'rolecolors') {
1.9 raeburn 495: $output = &modify_rolecolors($r,$dom,$confname,$roles,
496: %domconfig);
1.3 raeburn 497: } elsif ($action eq 'quotas') {
1.86 raeburn 498: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 499: } elsif ($action eq 'autoenroll') {
500: $output = &modify_autoenroll($dom,%domconfig);
501: } elsif ($action eq 'autoupdate') {
502: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 503: } elsif ($action eq 'autocreate') {
504: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 505: } elsif ($action eq 'directorysrch') {
506: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 507: } elsif ($action eq 'usercreation') {
1.28 raeburn 508: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 509: } elsif ($action eq 'usermodification') {
510: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 511: } elsif ($action eq 'contacts') {
512: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 513: } elsif ($action eq 'defaults') {
1.160.6.23! raeburn 514: $output = &modify_defaults($dom,$r,%domconfig);
1.46 raeburn 515: } elsif ($action eq 'scantron') {
1.48 raeburn 516: $output = &modify_scantron($r,$dom,$confname,%domconfig);
517: } elsif ($action eq 'coursecategories') {
518: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 519: } elsif ($action eq 'serverstatuses') {
520: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 521: } elsif ($action eq 'requestcourses') {
522: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.5 raeburn 523: } elsif ($action eq 'requestauthor') {
524: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.16 raeburn 525: } elsif ($action eq 'coursedefaults') {
526: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 527: } elsif ($action eq 'usersessions') {
528: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 529: } elsif ($action eq 'loadbalancing') {
530: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 531: }
532: return $output;
533: }
534:
535: sub print_config_box {
1.9 raeburn 536: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 537: my $rowtotal = 0;
1.49 raeburn 538: my $output;
539: if ($action eq 'coursecategories') {
540: $output = &coursecategories_javascript($settings);
1.91 raeburn 541: }
1.49 raeburn 542: $output .=
1.30 raeburn 543: '<table class="LC_nested_outer">
1.3 raeburn 544: <tr>
1.66 raeburn 545: <th align="left" valign="middle"><span class="LC_nobreak">'.
546: &mt($item->{text}).' '.
547: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
548: '</tr>';
1.30 raeburn 549: $rowtotal ++;
1.110 raeburn 550: my $numheaders = 1;
551: if (ref($item->{'header'}) eq 'ARRAY') {
552: $numheaders = scalar(@{$item->{'header'}});
553: }
554: if ($numheaders > 1) {
1.64 raeburn 555: my $colspan = '';
1.145 raeburn 556: my $rightcolspan = '';
1.160.6.5 raeburn 557: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
558: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 559: $colspan = ' colspan="2"';
560: }
1.145 raeburn 561: if ($action eq 'usersessions') {
562: $rightcolspan = ' colspan="3"';
563: }
1.30 raeburn 564: $output .= '
1.3 raeburn 565: <tr>
566: <td>
567: <table class="LC_nested">
568: <tr class="LC_info_row">
1.59 bisitz 569: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 570: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 571: </tr>';
1.69 raeburn 572: $rowtotal ++;
1.6 raeburn 573: if ($action eq 'autoupdate') {
1.30 raeburn 574: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 575: } elsif ($action eq 'usercreation') {
1.33 raeburn 576: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
577: } elsif ($action eq 'usermodification') {
578: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 579: } elsif ($action eq 'coursecategories') {
580: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 581: } elsif ($action eq 'login') {
1.160.6.5 raeburn 582: if ($numheaders == 3) {
583: $colspan = ' colspan="2"';
584: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
585: } else {
586: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
587: }
1.102 raeburn 588: } elsif ($action eq 'requestcourses') {
589: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 590: } elsif ($action eq 'requestauthor') {
591: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 592: } elsif ($action eq 'usersessions') {
593: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 594: } elsif ($action eq 'rolecolors') {
1.30 raeburn 595: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 596: }
1.30 raeburn 597: $output .= '
1.6 raeburn 598: </table>
599: </td>
600: </tr>
601: <tr>
602: <td>
603: <table class="LC_nested">
604: <tr class="LC_info_row">
1.59 bisitz 605: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 606: $output .= '
1.59 bisitz 607: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 608: </tr>';
609: $rowtotal ++;
1.6 raeburn 610: if ($action eq 'autoupdate') {
1.131 raeburn 611: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
612: </table>
613: </td>
614: </tr>
615: <tr>
616: <td>
617: <table class="LC_nested">
618: <tr class="LC_info_row">
619: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
620: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
621: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
622: $rowtotal ++;
1.28 raeburn 623: } elsif ($action eq 'usercreation') {
1.34 raeburn 624: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
625: </table>
626: </td>
627: </tr>
628: <tr>
629: <td>
630: <table class="LC_nested">
631: <tr class="LC_info_row">
1.59 bisitz 632: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
633: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 634: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
635: $rowtotal ++;
1.33 raeburn 636: } elsif ($action eq 'usermodification') {
1.63 raeburn 637: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
638: </table>
639: </td>
640: </tr>
641: <tr>
642: <td>
643: <table class="LC_nested">
644: <tr class="LC_info_row">
645: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
646: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
647: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
648: $rowtotal ++;
1.57 raeburn 649: } elsif ($action eq 'coursecategories') {
650: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 651: } elsif ($action eq 'login') {
1.160.6.5 raeburn 652: if ($numheaders == 3) {
653: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
654: </table>
655: </td>
656: </tr>
657: <tr>
658: <td>
659: <table class="LC_nested">
660: <tr class="LC_info_row">
661: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
662: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
663: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
664: $rowtotal ++;
665: } else {
666: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
667: }
1.102 raeburn 668: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 669: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
670: } elsif ($action eq 'requestauthor') {
671: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 672: } elsif ($action eq 'usersessions') {
1.145 raeburn 673: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
674: </table>
675: </td>
676: </tr>
677: <tr>
678: <td>
679: <table class="LC_nested">
680: <tr class="LC_info_row">
681: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
682: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
683: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
684: $rowtotal ++;
1.122 jms 685: } elsif ($action eq 'rolecolors') {
1.30 raeburn 686: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 687: </table>
688: </td>
689: </tr>
690: <tr>
691: <td>
692: <table class="LC_nested">
693: <tr class="LC_info_row">
1.69 raeburn 694: <td class="LC_left_item"'.$colspan.' valign="top">'.
695: &mt($item->{'header'}->[2]->{'col1'}).'</td>
696: <td class="LC_right_item" valign="top">'.
697: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 698: </tr>'.
1.30 raeburn 699: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 700: </table>
701: </td>
702: </tr>
703: <tr>
704: <td>
705: <table class="LC_nested">
706: <tr class="LC_info_row">
1.59 bisitz 707: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
708: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 709: </tr>'.
1.30 raeburn 710: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
711: $rowtotal += 2;
1.6 raeburn 712: }
1.3 raeburn 713: } else {
1.30 raeburn 714: $output .= '
1.3 raeburn 715: <tr>
716: <td>
717: <table class="LC_nested">
1.30 raeburn 718: <tr class="LC_info_row">';
1.24 raeburn 719: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 720: $output .= '
1.59 bisitz 721: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 722: } elsif ($action eq 'serverstatuses') {
723: $output .= '
724: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
725: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
726:
1.6 raeburn 727: } else {
1.30 raeburn 728: $output .= '
1.69 raeburn 729: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
730: }
1.72 raeburn 731: if (defined($item->{'header'}->[0]->{'col3'})) {
732: $output .= '<td class="LC_left_item" valign="top">'.
733: &mt($item->{'header'}->[0]->{'col2'});
734: if ($action eq 'serverstatuses') {
735: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
736: }
1.69 raeburn 737: } else {
738: $output .= '<td class="LC_right_item" valign="top">'.
739: &mt($item->{'header'}->[0]->{'col2'});
740: }
741: $output .= '</td>';
742: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 743: if (defined($item->{'header'}->[0]->{'col4'})) {
744: $output .= '<td class="LC_left_item" valign="top">'.
745: &mt($item->{'header'}->[0]->{'col3'});
746: } else {
747: $output .= '<td class="LC_right_item" valign="top">'.
748: &mt($item->{'header'}->[0]->{'col3'});
749: }
1.69 raeburn 750: if ($action eq 'serverstatuses') {
751: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
752: }
753: $output .= '</td>';
1.6 raeburn 754: }
1.150 raeburn 755: if ($item->{'header'}->[0]->{'col4'}) {
756: $output .= '<td class="LC_right_item" valign="top">'.
757: &mt($item->{'header'}->[0]->{'col4'});
758: }
1.69 raeburn 759: $output .= '</tr>';
1.48 raeburn 760: $rowtotal ++;
1.160.6.5 raeburn 761: if ($action eq 'quotas') {
1.86 raeburn 762: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 763: } elsif ($action eq 'autoenroll') {
1.30 raeburn 764: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 765: } elsif ($action eq 'autocreate') {
766: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 767: } elsif ($action eq 'directorysrch') {
1.30 raeburn 768: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 769: } elsif ($action eq 'contacts') {
1.30 raeburn 770: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 771: } elsif ($action eq 'defaults') {
772: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 773: } elsif ($action eq 'scantron') {
774: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 775: } elsif ($action eq 'serverstatuses') {
776: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 777: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 778: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 779: } elsif ($action eq 'loadbalancing') {
780: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.160.6.16 raeburn 781: } elsif ($action eq 'coursedefaults') {
782: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 783: }
1.3 raeburn 784: }
1.30 raeburn 785: $output .= '
1.3 raeburn 786: </table>
787: </td>
788: </tr>
1.30 raeburn 789: </table><br />';
790: return ($output,$rowtotal);
1.1 raeburn 791: }
792:
1.3 raeburn 793: sub print_login {
1.160.6.5 raeburn 794: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 795: my ($css_class,$datatable);
1.6 raeburn 796: my %choices = &login_choices();
1.110 raeburn 797:
1.160.6.5 raeburn 798: if ($caller eq 'service') {
1.149 raeburn 799: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 800: my $choice = $choices{'disallowlogin'};
801: $css_class = ' class="LC_odd_row"';
1.128 raeburn 802: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 803: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 804: '<th>'.$choices{'server'}.'</th>'.
805: '<th>'.$choices{'serverpath'}.'</th>'.
806: '<th>'.$choices{'custompath'}.'</th>'.
807: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 808: my %disallowed;
809: if (ref($settings) eq 'HASH') {
810: if (ref($settings->{'loginvia'}) eq 'HASH') {
811: %disallowed = %{$settings->{'loginvia'}};
812: }
813: }
814: foreach my $lonhost (sort(keys(%servers))) {
815: my $direct = 'selected="selected"';
1.128 raeburn 816: if (ref($disallowed{$lonhost}) eq 'HASH') {
817: if ($disallowed{$lonhost}{'server'} ne '') {
818: $direct = '';
819: }
1.110 raeburn 820: }
1.115 raeburn 821: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 822: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 823: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
824: '</option>';
1.160.6.13 raeburn 825: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 826: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 827: my $selected = '';
1.128 raeburn 828: if (ref($disallowed{$lonhost}) eq 'HASH') {
829: if ($hostid eq $disallowed{$lonhost}{'server'}) {
830: $selected = 'selected="selected"';
831: }
1.110 raeburn 832: }
833: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
834: $servers{$hostid}.'</option>';
835: }
1.128 raeburn 836: $datatable .= '</select></td>'.
837: '<td><select name="'.$lonhost.'_serverpath">';
838: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
839: my $pathname = $path;
840: if ($path eq 'custom') {
841: $pathname = &mt('Custom Path').' ->';
842: }
843: my $selected = '';
844: if (ref($disallowed{$lonhost}) eq 'HASH') {
845: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
846: $selected = 'selected="selected"';
847: }
848: } elsif ($path eq '') {
849: $selected = 'selected="selected"';
850: }
851: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
852: }
853: $datatable .= '</select></td>';
854: my ($custom,$exempt);
855: if (ref($disallowed{$lonhost}) eq 'HASH') {
856: $custom = $disallowed{$lonhost}{'custompath'};
857: $exempt = $disallowed{$lonhost}{'exempt'};
858: }
859: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
860: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
861: '</tr>';
1.110 raeburn 862: }
863: $datatable .= '</table></td></tr>';
864: return $datatable;
1.160.6.5 raeburn 865: } elsif ($caller eq 'page') {
866: my %defaultchecked = (
867: 'coursecatalog' => 'on',
1.160.6.14 raeburn 868: 'helpdesk' => 'on',
1.160.6.5 raeburn 869: 'adminmail' => 'off',
870: 'newuser' => 'off',
871: );
1.160.6.14 raeburn 872: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 873: my (%checkedon,%checkedoff);
1.42 raeburn 874: foreach my $item (@toggles) {
1.160.6.5 raeburn 875: if ($defaultchecked{$item} eq 'on') {
876: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 877: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 878: } elsif ($defaultchecked{$item} eq 'off') {
879: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 880: $checkedon{$item} = ' ';
881: }
1.1 raeburn 882: }
1.160.6.5 raeburn 883: my @images = ('img','logo','domlogo','login');
884: my @logintext = ('textcol','bgcol');
885: my @bgs = ('pgbg','mainbg','sidebg');
886: my @links = ('link','alink','vlink');
887: my %designhash = &Apache::loncommon::get_domainconf($dom);
888: my %defaultdesign = %Apache::loncommon::defaultdesign;
889: my (%is_custom,%designs);
890: my %defaults = (
891: font => $defaultdesign{'login.font'},
892: );
1.6 raeburn 893: foreach my $item (@images) {
1.160.6.5 raeburn 894: $defaults{$item} = $defaultdesign{'login.'.$item};
895: $defaults{'showlogo'}{$item} = 1;
896: }
897: foreach my $item (@bgs) {
898: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 899: }
1.41 raeburn 900: foreach my $item (@logintext) {
1.160.6.5 raeburn 901: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 902: }
1.160.6.5 raeburn 903: foreach my $item (@links) {
904: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 905: }
1.160.6.5 raeburn 906: if (ref($settings) eq 'HASH') {
907: foreach my $item (@toggles) {
908: if ($settings->{$item} eq '1') {
909: $checkedon{$item} = ' checked="checked" ';
910: $checkedoff{$item} = ' ';
911: } elsif ($settings->{$item} eq '0') {
912: $checkedoff{$item} = ' checked="checked" ';
913: $checkedon{$item} = ' ';
914: }
1.6 raeburn 915: }
1.160.6.5 raeburn 916: foreach my $item (@images) {
917: if (defined($settings->{$item})) {
918: $designs{$item} = $settings->{$item};
919: $is_custom{$item} = 1;
920: }
921: if (defined($settings->{'showlogo'}{$item})) {
922: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
923: }
924: }
925: foreach my $item (@logintext) {
926: if ($settings->{$item} ne '') {
927: $designs{'logintext'}{$item} = $settings->{$item};
928: $is_custom{$item} = 1;
929: }
930: }
931: if ($settings->{'font'} ne '') {
932: $designs{'font'} = $settings->{'font'};
933: $is_custom{'font'} = 1;
934: }
935: foreach my $item (@bgs) {
936: if ($settings->{$item} ne '') {
937: $designs{'bgs'}{$item} = $settings->{$item};
938: $is_custom{$item} = 1;
939: }
940: }
941: foreach my $item (@links) {
942: if ($settings->{$item} ne '') {
943: $designs{'links'}{$item} = $settings->{$item};
944: $is_custom{$item} = 1;
945: }
946: }
947: } else {
948: if ($designhash{$dom.'.login.font'} ne '') {
949: $designs{'font'} = $designhash{$dom.'.login.font'};
950: $is_custom{'font'} = 1;
951: }
952: foreach my $item (@images) {
953: if ($designhash{$dom.'.login.'.$item} ne '') {
954: $designs{$item} = $designhash{$dom.'.login.'.$item};
955: $is_custom{$item} = 1;
956: }
957: }
958: foreach my $item (@bgs) {
959: if ($designhash{$dom.'.login.'.$item} ne '') {
960: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
961: $is_custom{$item} = 1;
962: }
963: }
964: foreach my $item (@links) {
965: if ($designhash{$dom.'.login.'.$item} ne '') {
966: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
967: $is_custom{$item} = 1;
968: }
1.6 raeburn 969: }
970: }
1.160.6.5 raeburn 971: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
972: logo => 'Institution Logo',
973: domlogo => 'Domain Logo',
974: login => 'Login box');
975: my $itemcount = 1;
976: foreach my $item (@toggles) {
977: $css_class = $itemcount%2?' class="LC_odd_row"':'';
978: $datatable .=
979: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
980: '</td><td>'.
981: '<span class="LC_nobreak"><label><input type="radio" name="'.
982: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
983: '</label> <label><input type="radio" name="'.$item.'"'.
984: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
985: '</tr>';
986: $itemcount ++;
1.6 raeburn 987: }
1.160.6.5 raeburn 988: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
989: $datatable .= '</tr></table></td></tr>';
990: } elsif ($caller eq 'help') {
991: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
992: my $switchserver = &check_switchserver($dom,$confname);
993: my $itemcount = 1;
994: $defaulturl = '/adm/loginproblems.html';
995: $defaulttype = 'default';
996: %lt = &Apache::lonlocal::texthash (
997: del => 'Delete?',
998: rep => 'Replace:',
999: upl => 'Upload:',
1000: default => 'Default',
1001: custom => 'Custom',
1002: );
1003: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1004: my @currlangs;
1005: if (ref($settings) eq 'HASH') {
1006: if (ref($settings->{'helpurl'}) eq 'HASH') {
1007: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1008: next if ($settings->{'helpurl'}{$key} eq '');
1009: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1010: $type{$key} = 'custom';
1011: unless ($key eq 'nolang') {
1012: push(@currlangs,$key);
1013: }
1014: }
1015: } elsif ($settings->{'helpurl'} ne '') {
1016: $type{'nolang'} = 'custom';
1017: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1018: }
1019: }
1.160.6.5 raeburn 1020: foreach my $lang ('nolang',sort(@currlangs)) {
1021: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1022: $datatable .= '<tr'.$css_class.'>';
1023: if ($url{$lang} eq '') {
1024: $url{$lang} = $defaulturl;
1025: }
1026: if ($type{$lang} eq '') {
1027: $type{$lang} = $defaulttype;
1028: }
1029: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1030: if ($lang eq 'nolang') {
1031: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1032: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1033: } else {
1034: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1035: $langchoices{$lang},
1036: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1037: }
1038: $datatable .= '</span></td>'."\n".
1039: '<td class="LC_left_item">';
1040: if ($type{$lang} eq 'custom') {
1041: $datatable .= '<span class="LC_nobreak"><label>'.
1042: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1043: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1044: } else {
1045: $datatable .= $lt{'upl'};
1046: }
1047: $datatable .='<br />';
1048: if ($switchserver) {
1049: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1050: } else {
1051: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1052: }
1.160.6.5 raeburn 1053: $datatable .= '</td></tr>';
1054: $itemcount ++;
1.6 raeburn 1055: }
1.160.6.5 raeburn 1056: my @addlangs;
1057: foreach my $lang (sort(keys(%langchoices))) {
1058: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1059: push(@addlangs,$lang);
1060: }
1061: if (@addlangs > 0) {
1062: my %toadd;
1063: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1064: $toadd{''} = &mt('Select');
1065: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1066: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1067: &mt('Add log-in help page for a specific language:').' '.
1068: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1069: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1070: if ($switchserver) {
1071: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1072: } else {
1073: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1074: }
1.160.6.5 raeburn 1075: $datatable .= '</td></tr>';
1076: $itemcount ++;
1.6 raeburn 1077: }
1.160.6.5 raeburn 1078: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1079: }
1.6 raeburn 1080: return $datatable;
1081: }
1082:
1083: sub login_choices {
1084: my %choices =
1085: &Apache::lonlocal::texthash (
1.116 bisitz 1086: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1087: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1088: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1089: disallowlogin => "Login page requests redirected",
1090: hostid => "Server",
1.128 raeburn 1091: server => "Redirect to:",
1092: serverpath => "Path",
1093: custompath => "Custom",
1094: exempt => "Exempt IP(s)",
1.110 raeburn 1095: directlogin => "No redirect",
1096: newuser => "Link to create a user account",
1097: img => "Header",
1098: logo => "Main Logo",
1099: domlogo => "Domain Logo",
1100: login => "Log-in Header",
1101: textcol => "Text color",
1102: bgcol => "Box color",
1103: bgs => "Background colors",
1104: links => "Link colors",
1105: font => "Font color",
1106: pgbg => "Header",
1107: mainbg => "Page",
1108: sidebg => "Login box",
1109: link => "Link",
1110: alink => "Active link",
1111: vlink => "Visited link",
1.6 raeburn 1112: );
1113: return %choices;
1114: }
1115:
1116: sub print_rolecolors {
1.30 raeburn 1117: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1118: my %choices = &color_font_choices();
1119: my @bgs = ('pgbg','tabbg','sidebg');
1120: my @links = ('link','alink','vlink');
1121: my @images = ('img');
1122: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1123: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1124: my %defaultdesign = %Apache::loncommon::defaultdesign;
1125: my (%is_custom,%designs);
1.160.6.22 raeburn 1126: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1127: if (ref($settings) eq 'HASH') {
1128: if (ref($settings->{$role}) eq 'HASH') {
1129: if ($settings->{$role}->{'img'} ne '') {
1130: $designs{'img'} = $settings->{$role}->{'img'};
1131: $is_custom{'img'} = 1;
1132: }
1133: if ($settings->{$role}->{'font'} ne '') {
1134: $designs{'font'} = $settings->{$role}->{'font'};
1135: $is_custom{'font'} = 1;
1136: }
1.97 tempelho 1137: if ($settings->{$role}->{'fontmenu'} ne '') {
1138: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1139: $is_custom{'fontmenu'} = 1;
1140: }
1.6 raeburn 1141: foreach my $item (@bgs) {
1142: if ($settings->{$role}->{$item} ne '') {
1143: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1144: $is_custom{$item} = 1;
1145: }
1146: }
1147: foreach my $item (@links) {
1148: if ($settings->{$role}->{$item} ne '') {
1149: $designs{'links'}{$item} = $settings->{$role}->{$item};
1150: $is_custom{$item} = 1;
1151: }
1152: }
1153: }
1154: } else {
1155: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1156: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1157: $is_custom{'img'} = 1;
1158: }
1.97 tempelho 1159: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1160: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1161: $is_custom{'fontmenu'} = 1;
1162: }
1.6 raeburn 1163: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1164: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1165: $is_custom{'font'} = 1;
1166: }
1167: foreach my $item (@bgs) {
1168: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1169: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1170: $is_custom{$item} = 1;
1171:
1172: }
1173: }
1174: foreach my $item (@links) {
1175: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1176: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1177: $is_custom{$item} = 1;
1178: }
1179: }
1180: }
1181: my $itemcount = 1;
1.30 raeburn 1182: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1183: $datatable .= '</tr></table></td></tr>';
1184: return $datatable;
1185: }
1186:
1.160.6.22 raeburn 1187: sub role_defaults {
1188: my ($role,$bgs,$links,$images,$logintext) = @_;
1189: my %defaults;
1190: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1191: return %defaults;
1192: }
1193: my %defaultdesign = %Apache::loncommon::defaultdesign;
1194: if ($role eq 'login') {
1195: %defaults = (
1196: font => $defaultdesign{$role.'.font'},
1197: );
1198: if (ref($logintext) eq 'ARRAY') {
1199: foreach my $item (@{$logintext}) {
1200: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1201: }
1202: }
1203: foreach my $item (@{$images}) {
1204: $defaults{'showlogo'}{$item} = 1;
1205: }
1206: } else {
1207: %defaults = (
1208: img => $defaultdesign{$role.'.img'},
1209: font => $defaultdesign{$role.'.font'},
1210: fontmenu => $defaultdesign{$role.'.fontmenu'},
1211: );
1212: }
1213: foreach my $item (@{$bgs}) {
1214: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1215: }
1216: foreach my $item (@{$links}) {
1217: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1218: }
1219: foreach my $item (@{$images}) {
1220: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1221: }
1222: return %defaults;
1223: }
1224:
1.6 raeburn 1225: sub display_color_options {
1.9 raeburn 1226: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1227: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1228: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1229: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1230: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1231: '<td>'.$choices->{'font'}.'</td>';
1232: if (!$is_custom->{'font'}) {
1.30 raeburn 1233: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1234: } else {
1235: $datatable .= '<td> </td>';
1236: }
1.160.6.9 raeburn 1237: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1238:
1.8 raeburn 1239: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1240: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1241: ' value="'.$current_color.'" /> '.
1242: ' </td></tr>';
1.107 raeburn 1243: unless ($role eq 'login') {
1244: $datatable .= '<tr'.$css_class.'>'.
1245: '<td>'.$choices->{'fontmenu'}.'</td>';
1246: if (!$is_custom->{'fontmenu'}) {
1247: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1248: } else {
1249: $datatable .= '<td> </td>';
1250: }
1.160.6.22 raeburn 1251: $current_color = $designs->{'fontmenu'} ?
1252: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1253: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1254: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1255: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1256: ' value="'.$current_color.'" /> '.
1257: ' </td></tr>';
1.97 tempelho 1258: }
1.9 raeburn 1259: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1260: foreach my $img (@{$images}) {
1.18 albertel 1261: $itemcount ++;
1.6 raeburn 1262: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1263: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1264: '<td>'.$choices->{$img};
1.41 raeburn 1265: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1266: if ($role eq 'login') {
1267: if ($img eq 'login') {
1268: $login_hdr_pick =
1.135 bisitz 1269: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1270: $logincolors =
1271: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1272: $designs,$defaults);
1.70 raeburn 1273: } elsif ($img ne 'domlogo') {
1274: $datatable.= &logo_display_options($img,$defaults,$designs);
1275: }
1276: }
1277: $datatable .= '</td>';
1.6 raeburn 1278: if ($designs->{$img} ne '') {
1279: $imgfile = $designs->{$img};
1.18 albertel 1280: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1281: } else {
1282: $imgfile = $defaults->{$img};
1283: }
1284: if ($imgfile) {
1.9 raeburn 1285: my ($showfile,$fullsize);
1286: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1287: my $urldir = $1;
1288: my $filename = $2;
1289: my @info = &Apache::lonnet::stat_file($designs->{$img});
1290: if (@info) {
1291: my $thumbfile = 'tn-'.$filename;
1292: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1293: if (@thumb) {
1294: $showfile = $urldir.'/'.$thumbfile;
1295: } else {
1296: $showfile = $imgfile;
1297: }
1298: } else {
1299: $showfile = '';
1300: }
1301: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1302: $showfile = $imgfile;
1.6 raeburn 1303: my $imgdir = $1;
1304: my $filename = $2;
1.159 raeburn 1305: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1306: $showfile = "/$imgdir/tn-".$filename;
1307: } else {
1.159 raeburn 1308: my $input = $londocroot.$imgfile;
1309: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1310: if (!-e $output) {
1.9 raeburn 1311: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1312: my ($fullwidth,$fullheight) = &check_dimensions($input);
1313: if ($fullwidth ne '' && $fullheight ne '') {
1314: if ($fullwidth > $width && $fullheight > $height) {
1315: my $size = $width.'x'.$height;
1316: system("convert -sample $size $input $output");
1.159 raeburn 1317: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1318: }
1319: }
1.6 raeburn 1320: }
1321: }
1.16 raeburn 1322: }
1.6 raeburn 1323: if ($showfile) {
1.40 raeburn 1324: if ($showfile =~ m{^/(adm|res)/}) {
1325: if ($showfile =~ m{^/res/}) {
1326: my $local_showfile =
1327: &Apache::lonnet::filelocation('',$showfile);
1328: &Apache::lonnet::repcopy($local_showfile);
1329: }
1330: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1331: }
1332: if ($imgfile) {
1333: if ($imgfile =~ m{^/(adm|res)/}) {
1334: if ($imgfile =~ m{^/res/}) {
1335: my $local_imgfile =
1336: &Apache::lonnet::filelocation('',$imgfile);
1337: &Apache::lonnet::repcopy($local_imgfile);
1338: }
1339: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1340: } else {
1341: $fullsize = $imgfile;
1342: }
1343: }
1.41 raeburn 1344: $datatable .= '<td>';
1345: if ($img eq 'login') {
1.135 bisitz 1346: $datatable .= $login_hdr_pick;
1347: }
1.41 raeburn 1348: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1349: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1350: } else {
1.160.6.22 raeburn 1351: $datatable .= '<td> </td><td class="LC_left_item">'.
1352: &mt('Upload:').'<br />';
1.6 raeburn 1353: }
1354: } else {
1.160.6.22 raeburn 1355: $datatable .= '<td> </td><td class="LC_left_item">'.
1356: &mt('Upload:').'<br />';
1.6 raeburn 1357: }
1.9 raeburn 1358: if ($switchserver) {
1359: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1360: } else {
1.135 bisitz 1361: if ($img ne 'login') { # suppress file selection for Log-in header
1362: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1363: }
1.9 raeburn 1364: }
1365: $datatable .= '</td></tr>';
1.6 raeburn 1366: }
1367: $itemcount ++;
1368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1369: $datatable .= '<tr'.$css_class.'>'.
1370: '<td>'.$choices->{'bgs'}.'</td>';
1371: my $bgs_def;
1372: foreach my $item (@{$bgs}) {
1373: if (!$is_custom->{$item}) {
1.70 raeburn 1374: $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>';
1.6 raeburn 1375: }
1376: }
1377: if ($bgs_def) {
1.8 raeburn 1378: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1379: } else {
1380: $datatable .= '<td> </td>';
1381: }
1382: $datatable .= '<td class="LC_right_item">'.
1383: '<table border="0"><tr>';
1.160.6.13 raeburn 1384:
1.6 raeburn 1385: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1386: $datatable .= '<td align="center">'.$choices->{$item};
1387: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1388: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1389: $datatable .= ' ';
1.6 raeburn 1390: }
1.160.6.9 raeburn 1391: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1392: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1393: }
1394: $datatable .= '</tr></table></td></tr>';
1395: $itemcount ++;
1396: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1397: $datatable .= '<tr'.$css_class.'>'.
1398: '<td>'.$choices->{'links'}.'</td>';
1399: my $links_def;
1400: foreach my $item (@{$links}) {
1401: if (!$is_custom->{$item}) {
1.30 raeburn 1402: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1403: }
1404: }
1405: if ($links_def) {
1.8 raeburn 1406: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1407: } else {
1408: $datatable .= '<td> </td>';
1409: }
1410: $datatable .= '<td class="LC_right_item">'.
1411: '<table border="0"><tr>';
1412: foreach my $item (@{$links}) {
1.160.6.22 raeburn 1413: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1414: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1415: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1416: $datatable.=' ';
1.6 raeburn 1417: }
1.160.6.9 raeburn 1418: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1419: '" /></td>';
1420: }
1.30 raeburn 1421: $$rowtotal += $itemcount;
1.3 raeburn 1422: return $datatable;
1423: }
1424:
1.70 raeburn 1425: sub logo_display_options {
1426: my ($img,$defaults,$designs) = @_;
1427: my $checkedon;
1428: if (ref($defaults) eq 'HASH') {
1429: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1430: if ($defaults->{'showlogo'}{$img}) {
1431: $checkedon = 'checked="checked" ';
1432: }
1433: }
1434: }
1435: if (ref($designs) eq 'HASH') {
1436: if (ref($designs->{'showlogo'}) eq 'HASH') {
1437: if (defined($designs->{'showlogo'}{$img})) {
1438: if ($designs->{'showlogo'}{$img} == 0) {
1439: $checkedon = '';
1440: } elsif ($designs->{'showlogo'}{$img} == 1) {
1441: $checkedon = 'checked="checked" ';
1442: }
1443: }
1444: }
1445: }
1446: return '<br /><label> <input type="checkbox" name="'.
1447: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1448: &mt('show').'</label>'."\n";
1449: }
1450:
1.41 raeburn 1451: sub login_header_options {
1.135 bisitz 1452: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1453: my $output = '';
1.41 raeburn 1454: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1455: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1456: if (!$is_custom->{'textcol'}) {
1457: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1458: ' ';
1459: }
1460: if (!$is_custom->{'bgcol'}) {
1461: $output .= $choices->{'bgcol'}.': '.
1462: '<span id="css_'.$role.'_font" style="background-color: '.
1463: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1464: }
1465: $output .= '<br />';
1466: }
1467: $output .='<br />';
1468: return $output;
1469: }
1470:
1471: sub login_text_colors {
1.160.6.22 raeburn 1472: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1473: my $color_menu = '<table border="0"><tr>';
1474: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1475: $color_menu .= '<td align="center">'.$choices->{$item};
1476: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1477: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1478: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1479: }
1480: $color_menu .= '</tr></table><br />';
1481: return $color_menu;
1482: }
1483:
1484: sub image_changes {
1485: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1486: my $output;
1.135 bisitz 1487: if ($img eq 'login') {
1488: # suppress image for Log-in header
1489: } elsif (!$is_custom) {
1.70 raeburn 1490: if ($img ne 'domlogo') {
1.41 raeburn 1491: $output .= &mt('Default image:').'<br />';
1492: } else {
1493: $output .= &mt('Default in use:').'<br />';
1494: }
1495: }
1.135 bisitz 1496: if ($img eq 'login') { # suppress image for Log-in header
1497: $output .= '<td>'.$logincolors;
1.41 raeburn 1498: } else {
1.135 bisitz 1499: if ($img_import) {
1500: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1501: }
1502: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1503: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1504: if ($is_custom) {
1505: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1506: '<input type="checkbox" name="'.
1507: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1508: '</label> '.&mt('Replace:').'</span><br />';
1509: } else {
1.160.6.22 raeburn 1510: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1511: }
1.41 raeburn 1512: }
1513: return $output;
1514: }
1515:
1.3 raeburn 1516: sub print_quotas {
1.86 raeburn 1517: my ($dom,$settings,$rowtotal,$action) = @_;
1518: my $context;
1519: if ($action eq 'quotas') {
1520: $context = 'tools';
1521: } else {
1522: $context = $action;
1523: }
1.160.6.20 raeburn 1524: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1525: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1526: my $typecount = 0;
1.101 raeburn 1527: my ($css_class,%titles);
1.86 raeburn 1528: if ($context eq 'requestcourses') {
1.98 raeburn 1529: @usertools = ('official','unofficial','community');
1.106 raeburn 1530: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1531: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1532: %titles = &courserequest_titles();
1.160.6.5 raeburn 1533: } elsif ($context eq 'requestauthor') {
1534: @usertools = ('author');
1535: @options = ('norequest','approval','automatic');
1536: %titles = &authorrequest_titles();
1.86 raeburn 1537: } else {
1.160.6.4 raeburn 1538: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1539: %titles = &tool_titles();
1.86 raeburn 1540: }
1.26 raeburn 1541: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1542: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1543: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1544: unless (($context eq 'requestcourses') ||
1545: ($context eq 'requestauthor')) {
1.86 raeburn 1546: if (ref($settings) eq 'HASH') {
1547: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1548: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1549: } else {
1550: $currdefquota = $settings->{$type};
1551: }
1.160.6.20 raeburn 1552: if (ref($settings->{authorquota}) eq 'HASH') {
1553: $currauthorquota = $settings->{authorquota}->{$type};
1554: }
1.78 raeburn 1555: }
1.72 raeburn 1556: }
1.3 raeburn 1557: if (defined($usertypes->{$type})) {
1558: $typecount ++;
1559: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1560: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1561: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1562: '<td class="LC_left_item">';
1.101 raeburn 1563: if ($context eq 'requestcourses') {
1564: $datatable .= '<table><tr>';
1565: }
1566: my %cell;
1.72 raeburn 1567: foreach my $item (@usertools) {
1.101 raeburn 1568: if ($context eq 'requestcourses') {
1569: my ($curroption,$currlimit);
1570: if (ref($settings) eq 'HASH') {
1571: if (ref($settings->{$item}) eq 'HASH') {
1572: $curroption = $settings->{$item}->{$type};
1573: if ($curroption =~ /^autolimit=(\d*)$/) {
1574: $currlimit = $1;
1575: }
1576: }
1577: }
1578: if (!$curroption) {
1579: $curroption = 'norequest';
1580: }
1581: $datatable .= '<th>'.$titles{$item}.'</th>';
1582: foreach my $option (@options) {
1583: my $val = $option;
1584: if ($option eq 'norequest') {
1585: $val = 0;
1586: }
1587: if ($option eq 'validate') {
1588: my $canvalidate = 0;
1589: if (ref($validations{$item}) eq 'HASH') {
1590: if ($validations{$item}{$type}) {
1591: $canvalidate = 1;
1592: }
1593: }
1594: next if (!$canvalidate);
1595: }
1596: my $checked = '';
1597: if ($option eq $curroption) {
1598: $checked = ' checked="checked"';
1599: } elsif ($option eq 'autolimit') {
1600: if ($curroption =~ /^autolimit/) {
1601: $checked = ' checked="checked"';
1602: }
1603: }
1604: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1605: '<input type="radio" name="crsreq_'.$item.
1606: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1607: $titles{$option}.'</label>';
1.101 raeburn 1608: if ($option eq 'autolimit') {
1.127 raeburn 1609: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1610: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1611: 'value="'.$currlimit.'" />';
1.101 raeburn 1612: }
1.127 raeburn 1613: $cell{$item} .= '</span> ';
1.103 raeburn 1614: if ($option eq 'autolimit') {
1.127 raeburn 1615: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1616: }
1.101 raeburn 1617: }
1.160.6.5 raeburn 1618: } elsif ($context eq 'requestauthor') {
1619: my $curroption;
1620: if (ref($settings) eq 'HASH') {
1621: $curroption = $settings->{$type};
1622: }
1623: if (!$curroption) {
1624: $curroption = 'norequest';
1625: }
1626: foreach my $option (@options) {
1627: my $val = $option;
1628: if ($option eq 'norequest') {
1629: $val = 0;
1630: }
1631: my $checked = '';
1632: if ($option eq $curroption) {
1633: $checked = ' checked="checked"';
1634: }
1635: $datatable .= '<span class="LC_nobreak"><label>'.
1636: '<input type="radio" name="authorreq_'.$type.
1637: '" value="'.$val.'"'.$checked.' />'.
1638: $titles{$option}.'</label></span> ';
1639: }
1.101 raeburn 1640: } else {
1641: my $checked = 'checked="checked" ';
1642: if (ref($settings) eq 'HASH') {
1643: if (ref($settings->{$item}) eq 'HASH') {
1644: if ($settings->{$item}->{$type} == 0) {
1645: $checked = '';
1646: } elsif ($settings->{$item}->{$type} == 1) {
1647: $checked = 'checked="checked" ';
1648: }
1.78 raeburn 1649: }
1.72 raeburn 1650: }
1.101 raeburn 1651: $datatable .= '<span class="LC_nobreak"><label>'.
1652: '<input type="checkbox" name="'.$context.'_'.$item.
1653: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1654: '</label></span> ';
1.72 raeburn 1655: }
1.101 raeburn 1656: }
1657: if ($context eq 'requestcourses') {
1658: $datatable .= '</tr><tr>';
1659: foreach my $item (@usertools) {
1.106 raeburn 1660: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1661: }
1662: $datatable .= '</tr></table>';
1.72 raeburn 1663: }
1.86 raeburn 1664: $datatable .= '</td>';
1.160.6.5 raeburn 1665: unless (($context eq 'requestcourses') ||
1666: ($context eq 'requestauthor')) {
1.86 raeburn 1667: $datatable .=
1.160.6.20 raeburn 1668: '<td class="LC_right_item">'.
1669: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1670: '<input type="text" name="quota_'.$type.
1.72 raeburn 1671: '" value="'.$currdefquota.
1.160.6.20 raeburn 1672: '" size="5" /></span>'.(' ' x 2).
1673: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1674: '<input type="text" name="authorquota_'.$type.
1675: '" value="'.$currauthorquota.
1676: '" size="5" /></span></td>';
1.86 raeburn 1677: }
1678: $datatable .= '</tr>';
1.3 raeburn 1679: }
1680: }
1681: }
1.160.6.5 raeburn 1682: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1683: $defaultquota = '20';
1.160.6.20 raeburn 1684: $authorquota = '500';
1.86 raeburn 1685: if (ref($settings) eq 'HASH') {
1686: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1687: $defaultquota = $settings->{'defaultquota'}->{'default'};
1688: } elsif (defined($settings->{'default'})) {
1689: $defaultquota = $settings->{'default'};
1690: }
1.160.6.20 raeburn 1691: if (ref($settings->{'authorquota'}) eq 'HASH') {
1692: $authorquota = $settings->{'authorquota'}->{'default'};
1693: }
1.3 raeburn 1694: }
1695: }
1696: $typecount ++;
1697: $css_class = $typecount%2?' class="LC_odd_row"':'';
1698: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1699: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1700: '<td class="LC_left_item">';
1.101 raeburn 1701: if ($context eq 'requestcourses') {
1702: $datatable .= '<table><tr>';
1703: }
1704: my %defcell;
1.72 raeburn 1705: foreach my $item (@usertools) {
1.101 raeburn 1706: if ($context eq 'requestcourses') {
1707: my ($curroption,$currlimit);
1708: if (ref($settings) eq 'HASH') {
1709: if (ref($settings->{$item}) eq 'HASH') {
1710: $curroption = $settings->{$item}->{'default'};
1711: if ($curroption =~ /^autolimit=(\d*)$/) {
1712: $currlimit = $1;
1713: }
1714: }
1715: }
1716: if (!$curroption) {
1717: $curroption = 'norequest';
1718: }
1719: $datatable .= '<th>'.$titles{$item}.'</th>';
1720: foreach my $option (@options) {
1721: my $val = $option;
1722: if ($option eq 'norequest') {
1723: $val = 0;
1724: }
1725: if ($option eq 'validate') {
1726: my $canvalidate = 0;
1727: if (ref($validations{$item}) eq 'HASH') {
1728: if ($validations{$item}{'default'}) {
1729: $canvalidate = 1;
1730: }
1731: }
1732: next if (!$canvalidate);
1733: }
1734: my $checked = '';
1735: if ($option eq $curroption) {
1736: $checked = ' checked="checked"';
1737: } elsif ($option eq 'autolimit') {
1738: if ($curroption =~ /^autolimit/) {
1739: $checked = ' checked="checked"';
1740: }
1741: }
1742: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1743: '<input type="radio" name="crsreq_'.$item.
1744: '_default" value="'.$val.'"'.$checked.' />'.
1745: $titles{$option}.'</label>';
1746: if ($option eq 'autolimit') {
1.127 raeburn 1747: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1748: $item.'_limit_default" size="1" '.
1749: 'value="'.$currlimit.'" />';
1750: }
1.127 raeburn 1751: $defcell{$item} .= '</span> ';
1.104 raeburn 1752: if ($option eq 'autolimit') {
1.127 raeburn 1753: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1754: }
1.101 raeburn 1755: }
1.160.6.5 raeburn 1756: } elsif ($context eq 'requestauthor') {
1757: my $curroption;
1758: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1759: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1760: }
1761: if (!$curroption) {
1762: $curroption = 'norequest';
1763: }
1764: foreach my $option (@options) {
1765: my $val = $option;
1766: if ($option eq 'norequest') {
1767: $val = 0;
1768: }
1769: my $checked = '';
1770: if ($option eq $curroption) {
1771: $checked = ' checked="checked"';
1772: }
1773: $datatable .= '<span class="LC_nobreak"><label>'.
1774: '<input type="radio" name="authorreq_default"'.
1775: ' value="'.$val.'"'.$checked.' />'.
1776: $titles{$option}.'</label></span> ';
1777: }
1.101 raeburn 1778: } else {
1779: my $checked = 'checked="checked" ';
1780: if (ref($settings) eq 'HASH') {
1781: if (ref($settings->{$item}) eq 'HASH') {
1782: if ($settings->{$item}->{'default'} == 0) {
1783: $checked = '';
1784: } elsif ($settings->{$item}->{'default'} == 1) {
1785: $checked = 'checked="checked" ';
1786: }
1.78 raeburn 1787: }
1.72 raeburn 1788: }
1.101 raeburn 1789: $datatable .= '<span class="LC_nobreak"><label>'.
1790: '<input type="checkbox" name="'.$context.'_'.$item.
1791: '" value="default" '.$checked.'/>'.$titles{$item}.
1792: '</label></span> ';
1793: }
1794: }
1795: if ($context eq 'requestcourses') {
1796: $datatable .= '</tr><tr>';
1797: foreach my $item (@usertools) {
1.106 raeburn 1798: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1799: }
1.101 raeburn 1800: $datatable .= '</tr></table>';
1.72 raeburn 1801: }
1.86 raeburn 1802: $datatable .= '</td>';
1.160.6.5 raeburn 1803: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1804: $datatable .= '<td class="LC_right_item">'.
1805: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1806: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1807: $defaultquota.'" size="5" /></span>'.(' ' x2).
1808: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1809: '<input type="text" name="authorquota" value="'.
1810: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1811: }
1812: $datatable .= '</tr>';
1.72 raeburn 1813: $typecount ++;
1814: $css_class = $typecount%2?' class="LC_odd_row"':'';
1815: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1816: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1817: if ($context eq 'requestcourses') {
1.109 raeburn 1818: $datatable .= &mt('(overrides affiliation, if set)').
1819: '</td>'.
1820: '<td class="LC_left_item">'.
1821: '<table><tr>';
1.101 raeburn 1822: } else {
1.109 raeburn 1823: $datatable .= &mt('(overrides affiliation, if checked)').
1824: '</td>'.
1825: '<td class="LC_left_item" colspan="2">'.
1826: '<br />';
1.101 raeburn 1827: }
1828: my %advcell;
1.72 raeburn 1829: foreach my $item (@usertools) {
1.101 raeburn 1830: if ($context eq 'requestcourses') {
1831: my ($curroption,$currlimit);
1832: if (ref($settings) eq 'HASH') {
1833: if (ref($settings->{$item}) eq 'HASH') {
1834: $curroption = $settings->{$item}->{'_LC_adv'};
1835: if ($curroption =~ /^autolimit=(\d*)$/) {
1836: $currlimit = $1;
1837: }
1838: }
1839: }
1840: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1841: my $checked = '';
1842: if ($curroption eq '') {
1843: $checked = ' checked="checked"';
1844: }
1845: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1846: '<input type="radio" name="crsreq_'.$item.
1847: '__LC_adv" value=""'.$checked.' />'.
1848: &mt('No override set').'</label></span> ';
1.101 raeburn 1849: foreach my $option (@options) {
1850: my $val = $option;
1851: if ($option eq 'norequest') {
1852: $val = 0;
1853: }
1854: if ($option eq 'validate') {
1855: my $canvalidate = 0;
1856: if (ref($validations{$item}) eq 'HASH') {
1857: if ($validations{$item}{'_LC_adv'}) {
1858: $canvalidate = 1;
1859: }
1860: }
1861: next if (!$canvalidate);
1862: }
1863: my $checked = '';
1.104 raeburn 1864: if ($val eq $curroption) {
1.101 raeburn 1865: $checked = ' checked="checked"';
1866: } elsif ($option eq 'autolimit') {
1867: if ($curroption =~ /^autolimit/) {
1868: $checked = ' checked="checked"';
1869: }
1870: }
1871: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1872: '<input type="radio" name="crsreq_'.$item.
1873: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1874: $titles{$option}.'</label>';
1875: if ($option eq 'autolimit') {
1.127 raeburn 1876: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1877: $item.'_limit__LC_adv" size="1" '.
1878: 'value="'.$currlimit.'" />';
1879: }
1.127 raeburn 1880: $advcell{$item} .= '</span> ';
1.104 raeburn 1881: if ($option eq 'autolimit') {
1.127 raeburn 1882: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1883: }
1.101 raeburn 1884: }
1.160.6.5 raeburn 1885: } elsif ($context eq 'requestauthor') {
1886: my $curroption;
1887: if (ref($settings) eq 'HASH') {
1888: $curroption = $settings->{'_LC_adv'};
1889: }
1890: my $checked = '';
1891: if ($curroption eq '') {
1892: $checked = ' checked="checked"';
1893: }
1894: $datatable .= '<span class="LC_nobreak"><label>'.
1895: '<input type="radio" name="authorreq__LC_adv"'.
1896: ' value=""'.$checked.' />'.
1897: &mt('No override set').'</label></span> ';
1898: foreach my $option (@options) {
1899: my $val = $option;
1900: if ($option eq 'norequest') {
1901: $val = 0;
1902: }
1903: my $checked = '';
1904: if ($val eq $curroption) {
1905: $checked = ' checked="checked"';
1906: }
1907: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1908: '<input type="radio" name="authorreq__LC_adv"'.
1909: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1910: $titles{$option}.'</label></span> ';
1911: }
1.101 raeburn 1912: } else {
1913: my $checked = 'checked="checked" ';
1914: if (ref($settings) eq 'HASH') {
1915: if (ref($settings->{$item}) eq 'HASH') {
1916: if ($settings->{$item}->{'_LC_adv'} == 0) {
1917: $checked = '';
1918: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1919: $checked = 'checked="checked" ';
1920: }
1.79 raeburn 1921: }
1.72 raeburn 1922: }
1.101 raeburn 1923: $datatable .= '<span class="LC_nobreak"><label>'.
1924: '<input type="checkbox" name="'.$context.'_'.$item.
1925: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1926: '</label></span> ';
1927: }
1928: }
1929: if ($context eq 'requestcourses') {
1930: $datatable .= '</tr><tr>';
1931: foreach my $item (@usertools) {
1.106 raeburn 1932: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1933: }
1.101 raeburn 1934: $datatable .= '</tr></table>';
1.72 raeburn 1935: }
1.98 raeburn 1936: $datatable .= '</td></tr>';
1.30 raeburn 1937: $$rowtotal += $typecount;
1.3 raeburn 1938: return $datatable;
1939: }
1940:
1.160.6.5 raeburn 1941: sub print_requestmail {
1942: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 1943: my ($now,$datatable,%currapp,$rows);
1.102 raeburn 1944: $now = time;
1945: if (ref($settings) eq 'HASH') {
1946: if (ref($settings->{'notify'}) eq 'HASH') {
1947: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.16 raeburn 1948: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1949: }
1950: }
1951: }
1.160.6.16 raeburn 1952: my $numinrow = 2;
1.102 raeburn 1953: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1954: my $text;
1955: if ($action eq 'requestcourses') {
1956: $text = &mt('Receive notification of course requests requiring approval');
1957: } else {
1958: $text = &mt('Receive notification of authoring space requests requiring approval')
1959: }
1960: $datatable = '<tr '.$css_class.'>'.
1961: ' <td>'.$text.'</td>'.
1.102 raeburn 1962: ' <td class="LC_left_item">';
1.160.6.16 raeburn 1963: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1964: 'reqapprovalnotify',%currapp);
1965: if ($numdc > 0) {
1966: $datatable .= $table;
1.102 raeburn 1967: } else {
1968: $datatable .= &mt('There are no active Domain Coordinators');
1969: }
1970: $datatable .='</td></tr>';
1971: $$rowtotal += $rows;
1972: return $datatable;
1973: }
1974:
1.3 raeburn 1975: sub print_autoenroll {
1.30 raeburn 1976: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1977: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1978: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1979: if (ref($settings) eq 'HASH') {
1980: if (exists($settings->{'run'})) {
1981: if ($settings->{'run'} eq '0') {
1982: $runoff = ' checked="checked" ';
1983: $runon = ' ';
1984: } else {
1985: $runon = ' checked="checked" ';
1986: $runoff = ' ';
1987: }
1988: } else {
1989: if ($autorun) {
1990: $runon = ' checked="checked" ';
1991: $runoff = ' ';
1992: } else {
1993: $runoff = ' checked="checked" ';
1994: $runon = ' ';
1995: }
1996: }
1.129 raeburn 1997: if (exists($settings->{'co-owners'})) {
1998: if ($settings->{'co-owners'} eq '0') {
1999: $coownersoff = ' checked="checked" ';
2000: $coownerson = ' ';
2001: } else {
2002: $coownerson = ' checked="checked" ';
2003: $coownersoff = ' ';
2004: }
2005: } else {
2006: $coownersoff = ' checked="checked" ';
2007: $coownerson = ' ';
2008: }
1.3 raeburn 2009: if (exists($settings->{'sender_domain'})) {
2010: $defdom = $settings->{'sender_domain'};
2011: }
1.14 raeburn 2012: } else {
2013: if ($autorun) {
2014: $runon = ' checked="checked" ';
2015: $runoff = ' ';
2016: } else {
2017: $runoff = ' checked="checked" ';
2018: $runon = ' ';
2019: }
1.3 raeburn 2020: }
2021: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2022: my $notif_sender;
2023: if (ref($settings) eq 'HASH') {
2024: $notif_sender = $settings->{'sender_uname'};
2025: }
1.3 raeburn 2026: my $datatable='<tr class="LC_odd_row">'.
2027: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2028: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2029: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2030: $runon.' value="1" />'.&mt('Yes').'</label> '.
2031: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2032: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2033: '</tr><tr>'.
2034: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2035: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2036: &mt('username').': '.
2037: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2038: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2039: ': '.$domform.'</span></td></tr>'.
2040: '<tr class="LC_odd_row">'.
2041: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2042: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2043: '<input type="radio" name="autoassign_coowners"'.
2044: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2045: '<label><input type="radio" name="autoassign_coowners"'.
2046: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2047: '</tr>';
2048: $$rowtotal += 3;
1.3 raeburn 2049: return $datatable;
2050: }
2051:
2052: sub print_autoupdate {
1.30 raeburn 2053: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2054: my $datatable;
2055: if ($position eq 'top') {
2056: my $updateon = ' ';
2057: my $updateoff = ' checked="checked" ';
2058: my $classlistson = ' ';
2059: my $classlistsoff = ' checked="checked" ';
2060: if (ref($settings) eq 'HASH') {
2061: if ($settings->{'run'} eq '1') {
2062: $updateon = $updateoff;
2063: $updateoff = ' ';
2064: }
2065: if ($settings->{'classlists'} eq '1') {
2066: $classlistson = $classlistsoff;
2067: $classlistsoff = ' ';
2068: }
2069: }
2070: my %title = (
2071: run => 'Auto-update active?',
2072: classlists => 'Update information in classlists?',
2073: );
2074: $datatable = '<tr class="LC_odd_row">'.
2075: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2076: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2077: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2078: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2079: '<label><input type="radio" name="autoupdate_run"'.
2080: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2081: '</tr><tr>'.
2082: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2083: '<td class="LC_right_item"><span class="LC_nobreak">'.
2084: '<label><input type="radio" name="classlists"'.
2085: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2086: '<label><input type="radio" name="classlists"'.
2087: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2088: '</tr>';
1.30 raeburn 2089: $$rowtotal += 2;
1.131 raeburn 2090: } elsif ($position eq 'middle') {
2091: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2092: my $numinrow = 3;
2093: my $locknamesettings;
2094: $datatable .= &insttypes_row($settings,$types,$usertypes,
2095: $dom,$numinrow,$othertitle,
2096: 'lockablenames');
2097: $$rowtotal ++;
1.3 raeburn 2098: } else {
1.44 raeburn 2099: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2100: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2101: 'permanentemail','id');
1.33 raeburn 2102: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2103: my $numrows = 0;
1.26 raeburn 2104: if (ref($types) eq 'ARRAY') {
2105: if (@{$types} > 0) {
2106: $datatable =
2107: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2108: \@fields,$types,\$numrows);
1.30 raeburn 2109: $$rowtotal += @{$types};
1.26 raeburn 2110: }
1.3 raeburn 2111: }
2112: $datatable .=
2113: &usertype_update_row($settings,{'default' => $othertitle},
2114: \%fieldtitles,\@fields,['default'],
2115: \$numrows);
1.30 raeburn 2116: $$rowtotal ++;
1.3 raeburn 2117: }
2118: return $datatable;
2119: }
2120:
1.125 raeburn 2121: sub print_autocreate {
2122: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2123: my (%createon,%createoff,%currhash);
1.125 raeburn 2124: my @types = ('xml','req');
2125: if (ref($settings) eq 'HASH') {
2126: foreach my $item (@types) {
2127: $createoff{$item} = ' checked="checked" ';
2128: $createon{$item} = ' ';
2129: if (exists($settings->{$item})) {
2130: if ($settings->{$item}) {
2131: $createon{$item} = ' checked="checked" ';
2132: $createoff{$item} = ' ';
2133: }
2134: }
2135: }
1.160.6.16 raeburn 2136: if ($settings->{'xmldc'} ne '') {
2137: $currhash{$settings->{'xmldc'}} = 1;
2138: }
1.125 raeburn 2139: } else {
2140: foreach my $item (@types) {
2141: $createoff{$item} = ' checked="checked" ';
2142: $createon{$item} = ' ';
2143: }
2144: }
2145: $$rowtotal += 2;
1.160.6.16 raeburn 2146: my $numinrow = 2;
1.125 raeburn 2147: my $datatable='<tr class="LC_odd_row">'.
2148: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2149: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2150: '<input type="radio" name="autocreate_xml"'.
2151: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2152: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2153: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2154: '</td></tr><tr>'.
2155: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2156: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2157: '<input type="radio" name="autocreate_req"'.
2158: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2159: '<label><input type="radio" name="autocreate_req"'.
2160: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2161: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2162: 'autocreate_xmldc',%currhash);
1.125 raeburn 2163: if ($numdc > 1) {
1.143 raeburn 2164: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2165: &mt('Course creation processed as: (choose Dom. Coord.)').
2166: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2167: } else {
1.143 raeburn 2168: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2169: }
1.160.6.16 raeburn 2170: $$rowtotal += $rows;
1.125 raeburn 2171: return $datatable;
2172: }
2173:
1.23 raeburn 2174: sub print_directorysrch {
1.30 raeburn 2175: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2176: my $srchon = ' ';
2177: my $srchoff = ' checked="checked" ';
1.25 raeburn 2178: my ($exacton,$containson,$beginson);
1.24 raeburn 2179: my $localon = ' ';
2180: my $localoff = ' checked="checked" ';
1.23 raeburn 2181: if (ref($settings) eq 'HASH') {
2182: if ($settings->{'available'} eq '1') {
2183: $srchon = $srchoff;
2184: $srchoff = ' ';
2185: }
1.24 raeburn 2186: if ($settings->{'localonly'} eq '1') {
2187: $localon = $localoff;
2188: $localoff = ' ';
2189: }
1.25 raeburn 2190: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2191: foreach my $type (@{$settings->{'searchtypes'}}) {
2192: if ($type eq 'exact') {
2193: $exacton = ' checked="checked" ';
2194: } elsif ($type eq 'contains') {
2195: $containson = ' checked="checked" ';
2196: } elsif ($type eq 'begins') {
2197: $beginson = ' checked="checked" ';
2198: }
2199: }
2200: } else {
2201: if ($settings->{'searchtypes'} eq 'exact') {
2202: $exacton = ' checked="checked" ';
2203: } elsif ($settings->{'searchtypes'} eq 'contains') {
2204: $containson = ' checked="checked" ';
2205: } elsif ($settings->{'searchtypes'} eq 'specify') {
2206: $exacton = ' checked="checked" ';
2207: $containson = ' checked="checked" ';
2208: }
1.23 raeburn 2209: }
2210: }
2211: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2212: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2213:
2214: my $numinrow = 4;
1.26 raeburn 2215: my $cansrchrow = 0;
1.23 raeburn 2216: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2217: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2218: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2219: '<input type="radio" name="dirsrch_available"'.
2220: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2221: '<label><input type="radio" name="dirsrch_available"'.
2222: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2223: '</tr><tr>'.
1.30 raeburn 2224: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2225: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2226: '<input type="radio" name="dirsrch_localonly"'.
2227: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2228: '<label><input type="radio" name="dirsrch_localonly"'.
2229: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2230: '</tr>';
1.30 raeburn 2231: $$rowtotal += 2;
1.26 raeburn 2232: if (ref($usertypes) eq 'HASH') {
2233: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2234: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2235: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2236: $cansrchrow = 1;
2237: }
2238: }
2239: if ($cansrchrow) {
1.30 raeburn 2240: $$rowtotal ++;
1.26 raeburn 2241: $datatable .= '<tr>';
2242: } else {
2243: $datatable .= '<tr class="LC_odd_row">';
2244: }
1.30 raeburn 2245: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2246: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2247: foreach my $title (@{$titleorder}) {
2248: if (defined($searchtitles->{$title})) {
2249: my $check = ' ';
1.93 raeburn 2250: if (ref($settings) eq 'HASH') {
1.39 raeburn 2251: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2252: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2253: $check = ' checked="checked" ';
2254: }
1.25 raeburn 2255: }
2256: }
2257: $datatable .= '<td class="LC_left_item">'.
2258: '<span class="LC_nobreak"><label>'.
2259: '<input type="checkbox" name="searchby" '.
2260: 'value="'.$title.'"'.$check.'/>'.
2261: $searchtitles->{$title}.'</label></span></td>';
2262: }
2263: }
1.26 raeburn 2264: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2265: $$rowtotal ++;
1.26 raeburn 2266: if ($cansrchrow) {
2267: $datatable .= '<tr class="LC_odd_row">';
2268: } else {
2269: $datatable .= '<tr>';
2270: }
1.30 raeburn 2271: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2272: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2273: '<span class="LC_nobreak"><label>'.
2274: '<input type="checkbox" name="searchtypes" '.
2275: $exacton.' value="exact" />'.&mt('Exact match').
2276: '</label> '.
2277: '<label><input type="checkbox" name="searchtypes" '.
2278: $beginson.' value="begins" />'.&mt('Begins with').
2279: '</label> '.
2280: '<label><input type="checkbox" name="searchtypes" '.
2281: $containson.' value="contains" />'.&mt('Contains').
2282: '</label></span></td></tr>';
1.30 raeburn 2283: $$rowtotal ++;
1.25 raeburn 2284: return $datatable;
2285: }
2286:
1.28 raeburn 2287: sub print_contacts {
1.30 raeburn 2288: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2289: my $datatable;
2290: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2291: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2292: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23! raeburn 2293: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2294: foreach my $type (@mailings) {
2295: $otheremails{$type} = '';
2296: }
1.134 raeburn 2297: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2298: if (ref($settings) eq 'HASH') {
2299: foreach my $item (@contacts) {
2300: if (exists($settings->{$item})) {
2301: $to{$item} = $settings->{$item};
2302: }
2303: }
2304: foreach my $type (@mailings) {
2305: if (exists($settings->{$type})) {
2306: if (ref($settings->{$type}) eq 'HASH') {
2307: foreach my $item (@contacts) {
2308: if ($settings->{$type}{$item}) {
2309: $checked{$type}{$item} = ' checked="checked" ';
2310: }
2311: }
2312: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2313: if ($type eq 'helpdeskmail') {
2314: $bccemails{$type} = $settings->{$type}{'bcc'};
2315: }
1.28 raeburn 2316: }
1.89 raeburn 2317: } elsif ($type eq 'lonstatusmail') {
2318: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2319: }
2320: }
2321: } else {
2322: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2323: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2324: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2325: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2326: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2327: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2328: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23! raeburn 2329: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
! 2330: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2331: }
2332: my ($titles,$short_titles) = &contact_titles();
2333: my $rownum = 0;
2334: my $css_class;
2335: foreach my $item (@contacts) {
1.69 raeburn 2336: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2337: $datatable .= '<tr'.$css_class.'>'.
2338: '<td><span class="LC_nobreak">'.$titles->{$item}.
2339: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2340: '<input type="text" name="'.$item.'" value="'.
2341: $to{$item}.'" /></td></tr>';
1.160.6.23! raeburn 2342: $rownum ++;
1.28 raeburn 2343: }
2344: foreach my $type (@mailings) {
1.69 raeburn 2345: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2346: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2347: '<td><span class="LC_nobreak">'.
2348: $titles->{$type}.': </span></td>'.
1.28 raeburn 2349: '<td class="LC_left_item">'.
2350: '<span class="LC_nobreak">';
2351: foreach my $item (@contacts) {
2352: $datatable .= '<label>'.
2353: '<input type="checkbox" name="'.$type.'"'.
2354: $checked{$type}{$item}.
2355: ' value="'.$item.'" />'.$short_titles->{$item}.
2356: '</label> ';
2357: }
2358: $datatable .= '</span><br />'.&mt('Others').': '.
2359: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2360: 'value="'.$otheremails{$type}.'" />';
2361: if ($type eq 'helpdeskmail') {
1.136 raeburn 2362: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2363: '<input type="text" name="'.$type.'_bcc" '.
2364: 'value="'.$bccemails{$type}.'" />';
2365: }
2366: $datatable .= '</td></tr>'."\n";
1.160.6.23! raeburn 2367: $rownum ++;
1.28 raeburn 2368: }
1.160.6.23! raeburn 2369: my %choices;
! 2370: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
! 2371: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
! 2372: &mt('LON-CAPA core group - MSU'),600,500));
! 2373: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
! 2374: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
! 2375: &mt('LON-CAPA core group - MSU'),600,500));
! 2376: my @toggles = ('reporterrors','reportupdates');
! 2377: my %defaultchecked = ('reporterrors' => 'on',
! 2378: 'reportupdates' => 'on');
! 2379: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
! 2380: \%choices,$rownum);
! 2381: $datatable .= $reports;
1.30 raeburn 2382: $$rowtotal += $rownum;
1.28 raeburn 2383: return $datatable;
2384: }
2385:
1.118 jms 2386: sub print_helpsettings {
1.160.6.5 raeburn 2387: my ($dom,$confname,$settings,$rowtotal) = @_;
2388: my ($datatable,$itemcount);
2389: $itemcount = 1;
2390: my (%choices,%defaultchecked,@toggles);
2391: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2392: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2393: &mt('LON-CAPA bug tracker'),600,500));
2394: %defaultchecked = ('submitbugs' => 'on');
2395: @toggles = ('submitbugs',);
1.122 jms 2396:
1.160.6.5 raeburn 2397: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2398: \%choices,$itemcount);
2399: return $datatable;
1.121 raeburn 2400: }
2401:
2402: sub radiobutton_prefs {
1.160.6.16 raeburn 2403: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2404: $additional) = @_;
1.121 raeburn 2405: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2406: (ref($choices) eq 'HASH'));
2407:
2408: my (%checkedon,%checkedoff,$datatable,$css_class);
2409:
2410: foreach my $item (@{$toggles}) {
2411: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2412: $checkedon{$item} = ' checked="checked" ';
2413: $checkedoff{$item} = ' ';
1.121 raeburn 2414: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2415: $checkedoff{$item} = ' checked="checked" ';
2416: $checkedon{$item} = ' ';
2417: }
2418: }
2419: if (ref($settings) eq 'HASH') {
1.121 raeburn 2420: foreach my $item (@{$toggles}) {
1.118 jms 2421: if ($settings->{$item} eq '1') {
2422: $checkedon{$item} = ' checked="checked" ';
2423: $checkedoff{$item} = ' ';
2424: } elsif ($settings->{$item} eq '0') {
2425: $checkedoff{$item} = ' checked="checked" ';
2426: $checkedon{$item} = ' ';
2427: }
2428: }
1.121 raeburn 2429: }
1.160.6.16 raeburn 2430: if ($onclick) {
2431: $onclick = ' onclick="'.$onclick.'"';
2432: }
1.121 raeburn 2433: foreach my $item (@{$toggles}) {
1.118 jms 2434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2435: $datatable .=
1.160.6.16 raeburn 2436: '<tr'.$css_class.'><td valign="top">'.
2437: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2438: '</span></td>'.
2439: '<td class="LC_right_item"><span class="LC_nobreak">'.
2440: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2441: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2442: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2443: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2444: '</span>'.$additional.
2445: '</td>'.
1.118 jms 2446: '</tr>';
2447: $itemcount ++;
1.121 raeburn 2448: }
2449: return ($datatable,$itemcount);
2450: }
2451:
2452: sub print_coursedefaults {
1.139 raeburn 2453: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2454: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2455: my $itemcount = 1;
1.160.6.16 raeburn 2456: my %choices = &Apache::lonlocal::texthash (
2457: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2458: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2459: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2460: coursecredits => 'Credits can be specified for courses',
2461: );
1.160.6.21 raeburn 2462: my %staticdefaults = (
2463: anonsurvey_threshold => 10,
2464: uploadquota => 500,
2465: );
1.139 raeburn 2466: if ($position eq 'top') {
2467: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2468: @toggles = ('canuse_pdfforms');
1.139 raeburn 2469: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2470: \%choices,$itemcount);
1.139 raeburn 2471: } else {
2472: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.21 raeburn 2473: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.160.6.16 raeburn 2474: my $currusecredits = 0;
1.160.6.21 raeburn 2475: my @types = ('official','unofficial','community');
1.139 raeburn 2476: if (ref($settings) eq 'HASH') {
2477: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2478: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2479: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2480: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2481: }
2482: }
1.160.6.16 raeburn 2483: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2484: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2485: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2486: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2487: $currusecredits = 1;
2488: }
2489: }
1.139 raeburn 2490: }
2491: if (!$currdefresponder) {
1.160.6.21 raeburn 2492: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2493: } elsif ($currdefresponder < 1) {
2494: $currdefresponder = 1;
2495: }
1.160.6.21 raeburn 2496: foreach my $type (@types) {
2497: if ($curruploadquota{$type} eq '') {
2498: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2499: }
2500: }
1.139 raeburn 2501: $datatable .=
1.160.6.16 raeburn 2502: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2503: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2504: '</span></td>'.
2505: '<td class="LC_right_item"><span class="LC_nobreak">'.
2506: '<input type="text" name="anonsurvey_threshold"'.
2507: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.21 raeburn 2508: '</td></tr>'."\n".
2509: '<tr><td><span class="LC_nobreak">'.
2510: $choices{'uploadquota'}.
2511: '</span></td>'.
2512: '<td align="right" class="LC_right_item">'.
2513: '<table><tr>';
2514: foreach my $type (@types) {
2515: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2516: '<input type="text" name="uploadquota_'.$type.'"'.
2517: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2518: }
2519: $datatable .= '</tr></table></td></tr>'."\n";
2520: $itemcount += 2;
1.160.6.16 raeburn 2521: my $onclick = 'toggleCredits(this.form);';
2522: my $display = 'none';
2523: if ($currusecredits) {
2524: $display = 'block';
2525: }
2526: my $additional = '<div id="credits" style="display: '.$display.'">'.
2527: '<span class="LC_nobreak">'.
2528: &mt('Default credits for official courses [_1]',
2529: '<input type="text" name="official_credits" value="'.
2530: $def_official_credits.'" size="3" />').
2531: '</span><br />'.
2532: '<span class="LC_nobreak">'.
2533: &mt('Default credits for unofficial courses [_1]',
2534: '<input type="text" name="unofficial_credits" value="'.
2535: $def_unofficial_credits.'" size="3" />').
2536: '</span></div>'."\n";
2537: %defaultchecked = ('coursecredits' => 'off');
2538: @toggles = ('coursecredits');
2539: my $current = {
2540: 'coursecredits' => $currusecredits,
2541: };
2542: (my $table,$itemcount) =
2543: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2544: \%choices,$itemcount,$onclick,$additional);
2545: $datatable .= $table;
1.139 raeburn 2546: }
1.160.6.16 raeburn 2547: $$rowtotal += $itemcount;
1.121 raeburn 2548: return $datatable;
1.118 jms 2549: }
2550:
1.137 raeburn 2551: sub print_usersessions {
2552: my ($position,$dom,$settings,$rowtotal) = @_;
2553: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2554: my (%by_ip,%by_location,@intdoms);
2555: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2556:
2557: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2558: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2559: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2560: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2561: my $itemcount = 1;
2562: if ($position eq 'top') {
1.152 raeburn 2563: if (keys(%serverhomes) > 1) {
1.145 raeburn 2564: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2565: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2566: } else {
1.140 raeburn 2567: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2568: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2569: }
1.137 raeburn 2570: } else {
1.145 raeburn 2571: if (keys(%by_location) == 0) {
2572: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2573: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2574: } else {
2575: my %lt = &usersession_titles();
2576: my $numinrow = 5;
2577: my $prefix;
2578: my @types;
2579: if ($position eq 'bottom') {
2580: $prefix = 'remote';
2581: @types = ('version','excludedomain','includedomain');
2582: } else {
2583: $prefix = 'hosted';
2584: @types = ('excludedomain','includedomain');
2585: }
2586: my (%current,%checkedon,%checkedoff);
2587: my @lcversions = &Apache::lonnet::all_loncaparevs();
2588: my @locations = sort(keys(%by_location));
2589: foreach my $type (@types) {
2590: $checkedon{$type} = '';
2591: $checkedoff{$type} = ' checked="checked"';
2592: }
2593: if (ref($settings) eq 'HASH') {
2594: if (ref($settings->{$prefix}) eq 'HASH') {
2595: foreach my $key (keys(%{$settings->{$prefix}})) {
2596: $current{$key} = $settings->{$prefix}{$key};
2597: if ($key eq 'version') {
2598: if ($current{$key} ne '') {
2599: $checkedon{$key} = ' checked="checked"';
2600: $checkedoff{$key} = '';
2601: }
2602: } elsif (ref($current{$key}) eq 'ARRAY') {
2603: $checkedon{$key} = ' checked="checked"';
2604: $checkedoff{$key} = '';
2605: }
1.137 raeburn 2606: }
2607: }
2608: }
1.145 raeburn 2609: foreach my $type (@types) {
2610: next if ($type ne 'version' && !@locations);
2611: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2612: $datatable .= '<tr'.$css_class.'>
2613: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2614: <span class="LC_nobreak">
2615: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2616: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2617: if ($type eq 'version') {
2618: my $selector = '<select name="'.$prefix.'_version">';
2619: foreach my $version (@lcversions) {
2620: my $selected = '';
2621: if ($current{'version'} eq $version) {
2622: $selected = ' selected="selected"';
2623: }
2624: $selector .= ' <option value="'.$version.'"'.
2625: $selected.'>'.$version.'</option>';
2626: }
2627: $selector .= '</select> ';
2628: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2629: } else {
2630: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2631: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2632: ' />'.(' 'x2).
2633: '<input type="button" value="'.&mt('uncheck all').'" '.
2634: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2635: "\n".
2636: '</div><div><table>';
2637: my $rem;
2638: for (my $i=0; $i<@locations; $i++) {
2639: my ($showloc,$value,$checkedtype);
2640: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2641: my $ip = $by_location{$locations[$i]}->[0];
2642: if (ref($by_ip{$ip}) eq 'ARRAY') {
2643: $value = join(':',@{$by_ip{$ip}});
2644: $showloc = join(', ',@{$by_ip{$ip}});
2645: if (ref($current{$type}) eq 'ARRAY') {
2646: foreach my $loc (@{$by_ip{$ip}}) {
2647: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2648: $checkedtype = ' checked="checked"';
2649: last;
2650: }
2651: }
1.138 raeburn 2652: }
2653: }
2654: }
1.145 raeburn 2655: $rem = $i%($numinrow);
2656: if ($rem == 0) {
2657: if ($i > 0) {
2658: $datatable .= '</tr>';
2659: }
2660: $datatable .= '<tr>';
2661: }
2662: $datatable .= '<td class="LC_left_item">'.
2663: '<span class="LC_nobreak"><label>'.
2664: '<input type="checkbox" name="'.$prefix.'_'.$type.
2665: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2666: '</label></span></td>';
1.137 raeburn 2667: }
1.145 raeburn 2668: $rem = @locations%($numinrow);
2669: my $colsleft = $numinrow - $rem;
2670: if ($colsleft > 1 ) {
2671: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2672: ' </td>';
2673: } elsif ($colsleft == 1) {
2674: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2675: }
1.145 raeburn 2676: $datatable .= '</tr></table>';
1.137 raeburn 2677: }
1.145 raeburn 2678: $datatable .= '</td></tr>';
2679: $itemcount ++;
1.137 raeburn 2680: }
2681: }
2682: }
2683: $$rowtotal += $itemcount;
2684: return $datatable;
2685: }
2686:
1.138 raeburn 2687: sub build_location_hashes {
2688: my ($intdoms,$by_ip,$by_location) = @_;
2689: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2690: (ref($by_location) eq 'HASH'));
2691: my %iphost = &Apache::lonnet::get_iphost();
2692: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2693: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2694: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2695: foreach my $id (@{$iphost{$primary_ip}}) {
2696: my $intdom = &Apache::lonnet::internet_dom($id);
2697: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2698: push(@{$intdoms},$intdom);
2699: }
2700: }
2701: }
2702: foreach my $ip (keys(%iphost)) {
2703: if (ref($iphost{$ip}) eq 'ARRAY') {
2704: foreach my $id (@{$iphost{$ip}}) {
2705: my $location = &Apache::lonnet::internet_dom($id);
2706: if ($location) {
2707: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2708: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2709: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2710: push(@{$by_ip->{$ip}},$location);
2711: }
2712: } else {
2713: $by_ip->{$ip} = [$location];
2714: }
2715: }
2716: }
2717: }
2718: }
2719: foreach my $ip (sort(keys(%{$by_ip}))) {
2720: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2721: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2722: my $first = $by_ip->{$ip}->[0];
2723: if (ref($by_location->{$first}) eq 'ARRAY') {
2724: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2725: push(@{$by_location->{$first}},$ip);
2726: }
2727: } else {
2728: $by_location->{$first} = [$ip];
2729: }
2730: }
2731: }
2732: return;
2733: }
2734:
1.145 raeburn 2735: sub current_offloads_to {
2736: my ($dom,$settings,$servers) = @_;
2737: my (%spareid,%otherdomconfigs);
1.152 raeburn 2738: if (ref($servers) eq 'HASH') {
1.145 raeburn 2739: foreach my $lonhost (sort(keys(%{$servers}))) {
2740: my $gotspares;
1.152 raeburn 2741: if (ref($settings) eq 'HASH') {
2742: if (ref($settings->{'spares'}) eq 'HASH') {
2743: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2744: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2745: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2746: $gotspares = 1;
2747: }
1.145 raeburn 2748: }
2749: }
2750: unless ($gotspares) {
2751: my $gotspares;
2752: my $serverhomeID =
2753: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2754: my $serverhomedom =
2755: &Apache::lonnet::host_domain($serverhomeID);
2756: if ($serverhomedom ne $dom) {
2757: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2758: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2759: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2760: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2761: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2762: $gotspares = 1;
2763: }
2764: }
2765: } else {
2766: $otherdomconfigs{$serverhomedom} =
2767: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2768: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2769: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2770: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2771: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2772: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2773: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2774: $gotspares = 1;
2775: }
2776: }
2777: }
2778: }
2779: }
2780: }
2781: }
2782: unless ($gotspares) {
2783: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2784: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2785: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2786: } else {
2787: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2788: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2789: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2790: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2791: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2792: } else {
1.150 raeburn 2793: my %what = (
2794: spareid => 1,
2795: );
2796: my ($result,$returnhash) =
2797: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2798: if ($result eq 'ok') {
2799: if (ref($returnhash) eq 'HASH') {
2800: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2801: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2802: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2803: }
2804: }
1.145 raeburn 2805: }
2806: }
2807: }
2808: }
2809: }
2810: }
2811: return %spareid;
2812: }
2813:
2814: sub spares_row {
1.152 raeburn 2815: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2816: my $css_class;
2817: my $numinrow = 4;
2818: my $itemcount = 1;
2819: my $datatable;
1.152 raeburn 2820: my %typetitles = &sparestype_titles();
2821: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2822: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2823: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2824: my ($othercontrol,$serverdom);
2825: if ($serverhome ne $server) {
2826: $serverdom = &Apache::lonnet::host_domain($serverhome);
2827: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2828: } else {
2829: $serverdom = &Apache::lonnet::host_domain($server);
2830: if ($serverdom ne $dom) {
2831: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2832: }
2833: }
2834: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2835: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2836: $datatable .= '<tr'.$css_class.'>
2837: <td rowspan="2">
1.160.6.13 raeburn 2838: <span class="LC_nobreak">'.
2839: &mt('[_1] when busy, offloads to:'
2840: ,'<b>'.$server.'</b>').
2841: "\n";
1.145 raeburn 2842: my (%current,%canselect);
1.152 raeburn 2843: my @choices =
2844: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2845: foreach my $type ('primary','default') {
2846: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2847: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2848: my @spares = @{$spareid->{$server}{$type}};
2849: if (@spares > 0) {
1.152 raeburn 2850: if ($othercontrol) {
2851: $current{$type} = join(', ',@spares);
2852: } else {
2853: $current{$type} .= '<table>';
2854: my $numspares = scalar(@spares);
2855: for (my $i=0; $i<@spares; $i++) {
2856: my $rem = $i%($numinrow);
2857: if ($rem == 0) {
2858: if ($i > 0) {
2859: $current{$type} .= '</tr>';
2860: }
2861: $current{$type} .= '<tr>';
1.145 raeburn 2862: }
1.152 raeburn 2863: $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'".');" /> '.
2864: $spareid->{$server}{$type}[$i].
2865: '</label></td>'."\n";
2866: }
2867: my $rem = @spares%($numinrow);
2868: my $colsleft = $numinrow - $rem;
2869: if ($colsleft > 1 ) {
2870: $current{$type} .= '<td colspan="'.$colsleft.
2871: '" class="LC_left_item">'.
2872: ' </td>';
2873: } elsif ($colsleft == 1) {
2874: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2875: }
1.152 raeburn 2876: $current{$type} .= '</tr></table>';
1.150 raeburn 2877: }
1.145 raeburn 2878: }
2879: }
2880: if ($current{$type} eq '') {
2881: $current{$type} = &mt('None specified');
2882: }
1.152 raeburn 2883: if ($othercontrol) {
2884: if ($type eq 'primary') {
2885: $canselect{$type} = $othercontrol;
2886: }
2887: } else {
2888: $canselect{$type} =
2889: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2890: '<select name="newspare_'.$type.'_'.$server.'" '.
2891: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2892: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2893: if (@choices > 0) {
2894: foreach my $lonhost (@choices) {
2895: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2896: }
2897: }
2898: $canselect{$type} .= '</select>'."\n";
2899: }
2900: } else {
2901: $current{$type} = &mt('Could not be determined');
2902: if ($type eq 'primary') {
2903: $canselect{$type} = $othercontrol;
2904: }
1.145 raeburn 2905: }
1.152 raeburn 2906: if ($type eq 'default') {
2907: $datatable .= '<tr'.$css_class.'>';
2908: }
2909: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2910: '<td>'.$current{$type}.'</td>'."\n".
2911: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2912: }
2913: $itemcount ++;
2914: }
2915: }
2916: $$rowtotal += $itemcount;
2917: return $datatable;
2918: }
2919:
1.152 raeburn 2920: sub possible_newspares {
2921: my ($server,$currspares,$serverhomes,$altids) = @_;
2922: my $serverhostname = &Apache::lonnet::hostname($server);
2923: my %excluded;
2924: if ($serverhostname ne '') {
2925: %excluded = (
2926: $serverhostname => 1,
2927: );
2928: }
2929: if (ref($currspares) eq 'HASH') {
2930: foreach my $type (keys(%{$currspares})) {
2931: if (ref($currspares->{$type}) eq 'ARRAY') {
2932: if (@{$currspares->{$type}} > 0) {
2933: foreach my $curr (@{$currspares->{$type}}) {
2934: my $hostname = &Apache::lonnet::hostname($curr);
2935: $excluded{$hostname} = 1;
2936: }
2937: }
2938: }
2939: }
2940: }
2941: my @choices;
2942: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2943: if (keys(%{$serverhomes}) > 1) {
2944: foreach my $name (sort(keys(%{$serverhomes}))) {
2945: unless ($excluded{$name}) {
2946: if (exists($altids->{$serverhomes->{$name}})) {
2947: push(@choices,$altids->{$serverhomes->{$name}});
2948: } else {
2949: push(@choices,$serverhomes->{$name});
1.145 raeburn 2950: }
2951: }
2952: }
2953: }
2954: }
1.152 raeburn 2955: return sort(@choices);
1.145 raeburn 2956: }
2957:
1.150 raeburn 2958: sub print_loadbalancing {
2959: my ($dom,$settings,$rowtotal) = @_;
2960: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2961: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2962: my $numinrow = 1;
2963: my $datatable;
2964: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2965: my (%currbalancer,%currtargets,%currrules,%existing);
2966: if (ref($settings) eq 'HASH') {
2967: %existing = %{$settings};
2968: }
2969: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2970: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2971: \%currtargets,\%currrules);
1.150 raeburn 2972: } else {
2973: return;
2974: }
2975: my ($othertitle,$usertypes,$types) =
2976: &Apache::loncommon::sorted_inst_types($dom);
2977: my $rownum = 6;
2978: if (ref($types) eq 'ARRAY') {
2979: $rownum += scalar(@{$types});
2980: }
1.160.6.7 raeburn 2981: my @css_class = ('LC_odd_row','LC_even_row');
2982: my $balnum = 0;
2983: my $islast;
2984: my (@toshow,$disabledtext);
2985: if (keys(%currbalancer) > 0) {
2986: @toshow = sort(keys(%currbalancer));
2987: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2988: push(@toshow,'');
2989: }
2990: } else {
2991: @toshow = ('');
2992: $disabledtext = &mt('No existing load balancer');
2993: }
2994: foreach my $lonhost (@toshow) {
2995: if ($balnum == scalar(@toshow)-1) {
2996: $islast = 1;
2997: } else {
2998: $islast = 0;
2999: }
3000: my $cssidx = $balnum%2;
3001: my $targets_div_style = 'display: none';
3002: my $disabled_div_style = 'display: block';
3003: my $homedom_div_style = 'display: none';
3004: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3005: '<td rowspan="'.$rownum.'" valign="top">'.
3006: '<p>';
3007: if ($lonhost eq '') {
3008: $datatable .= '<span class="LC_nobreak">';
3009: if (keys(%currbalancer) > 0) {
3010: $datatable .= &mt('Add balancer:');
3011: } else {
3012: $datatable .= &mt('Enable balancer:');
3013: }
3014: $datatable .= ' '.
3015: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3016: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3017: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3018: '<option value="" selected="selected">'.&mt('None').
3019: '</option>'."\n";
3020: foreach my $server (sort(keys(%servers))) {
3021: next if ($currbalancer{$server});
3022: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3023: }
3024: $datatable .=
3025: '</select>'."\n".
3026: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3027: } else {
3028: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3029: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3030: &mt('Stop balancing').'</label>'.
3031: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3032: $targets_div_style = 'display: block';
3033: $disabled_div_style = 'display: none';
3034: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3035: $homedom_div_style = 'display: block';
3036: }
3037: }
3038: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3039: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3040: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3041: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3042: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3043: my @sparestypes = ('primary','default');
3044: my %typetitles = &sparestype_titles();
3045: foreach my $sparetype (@sparestypes) {
3046: my $targettable;
3047: for (my $i=0; $i<$numspares; $i++) {
3048: my $checked;
3049: if (ref($currtargets{$lonhost}) eq 'HASH') {
3050: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3051: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3052: $checked = ' checked="checked"';
3053: }
3054: }
3055: }
3056: my ($chkboxval,$disabled);
3057: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3058: $chkboxval = $spares[$i];
3059: }
3060: if (exists($currbalancer{$spares[$i]})) {
3061: $disabled = ' disabled="disabled"';
3062: }
3063: $targettable .=
3064: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3065: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3066: '</span></label></td>';
3067: my $rem = $i%($numinrow);
3068: if ($rem == 0) {
3069: if (($i > 0) && ($i < $numspares-1)) {
3070: $targettable .= '</tr>';
3071: }
3072: if ($i < $numspares-1) {
3073: $targettable .= '<tr>';
1.150 raeburn 3074: }
3075: }
3076: }
1.160.6.7 raeburn 3077: if ($targettable ne '') {
3078: my $rem = $numspares%($numinrow);
3079: my $colsleft = $numinrow - $rem;
3080: if ($colsleft > 1 ) {
3081: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3082: ' </td>';
3083: } elsif ($colsleft == 1) {
3084: $targettable .= '<td class="LC_left_item"> </td>';
3085: }
3086: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3087: '<table><tr>'.$targettable.'</tr></table><br />';
3088: }
3089: }
3090: $datatable .= '</div></td></tr>'.
3091: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3092: $othertitle,$usertypes,$types,\%servers,
3093: \%currbalancer,$lonhost,
3094: $targets_div_style,$homedom_div_style,
3095: $css_class[$cssidx],$balnum,$islast);
3096: $$rowtotal += $rownum;
3097: $balnum ++;
3098: }
3099: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3100: return $datatable;
3101: }
3102:
3103: sub get_loadbalancers_config {
3104: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3105: return unless ((ref($servers) eq 'HASH') &&
3106: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3107: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3108: if (keys(%{$existing}) > 0) {
3109: my $oldlonhost;
3110: foreach my $key (sort(keys(%{$existing}))) {
3111: if ($key eq 'lonhost') {
3112: $oldlonhost = $existing->{'lonhost'};
3113: $currbalancer->{$oldlonhost} = 1;
3114: } elsif ($key eq 'targets') {
3115: if ($oldlonhost) {
3116: $currtargets->{$oldlonhost} = $existing->{'targets'};
3117: }
3118: } elsif ($key eq 'rules') {
3119: if ($oldlonhost) {
3120: $currrules->{$oldlonhost} = $existing->{'rules'};
3121: }
3122: } elsif (ref($existing->{$key}) eq 'HASH') {
3123: $currbalancer->{$key} = 1;
3124: $currtargets->{$key} = $existing->{$key}{'targets'};
3125: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3126: }
3127: }
1.160.6.7 raeburn 3128: } else {
3129: my ($balancerref,$targetsref) =
3130: &Apache::lonnet::get_lonbalancer_config($servers);
3131: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3132: foreach my $server (sort(keys(%{$balancerref}))) {
3133: $currbalancer->{$server} = 1;
3134: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3135: }
3136: }
3137: }
1.160.6.7 raeburn 3138: return;
1.150 raeburn 3139: }
3140:
3141: sub loadbalancing_rules {
3142: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3143: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3144: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3145: my $output;
1.160.6.7 raeburn 3146: my $num = 0;
3147: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3148: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3149: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3150: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3151: $num ++;
1.150 raeburn 3152: my $current;
3153: if (ref($currrules) eq 'HASH') {
3154: $current = $currrules->{$type};
3155: }
3156: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3157: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3158: $current = '';
3159: }
3160: }
3161: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3162: $servers,$currbalancer,$lonhost,$dom,
3163: $targets_div_style,$homedom_div_style,
3164: $css_class,$balnum,$num,$islast);
1.150 raeburn 3165: }
3166: }
3167: return $output;
3168: }
3169:
3170: sub loadbalancing_titles {
3171: my ($dom,$intdom,$usertypes,$types) = @_;
3172: my %othertypes = (
3173: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3174: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3175: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3176: '_LC_external' => &mt('Users not from [_1]',$intdom),
3177: );
3178: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3179: if (ref($types) eq 'ARRAY') {
3180: unshift(@alltypes,@{$types},'default');
3181: }
3182: my %titles;
3183: foreach my $type (@alltypes) {
3184: if ($type =~ /^_LC_/) {
3185: $titles{$type} = $othertypes{$type};
3186: } elsif ($type eq 'default') {
3187: $titles{$type} = &mt('All users from [_1]',$dom);
3188: if (ref($types) eq 'ARRAY') {
3189: if (@{$types} > 0) {
3190: $titles{$type} = &mt('Other users from [_1]',$dom);
3191: }
3192: }
3193: } elsif (ref($usertypes) eq 'HASH') {
3194: $titles{$type} = $usertypes->{$type};
3195: }
3196: }
3197: return (\@alltypes,\%othertypes,\%titles);
3198: }
3199:
3200: sub loadbalance_rule_row {
1.160.6.7 raeburn 3201: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3202: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3203: my @rulenames = ('default','homeserver');
3204: my %ruletitles = &offloadtype_text();
3205: if ($type eq '_LC_external') {
3206: push(@rulenames,'externalbalancer');
3207: } else {
3208: push(@rulenames,'specific');
3209: }
1.160.6.3 raeburn 3210: push(@rulenames,'none');
1.150 raeburn 3211: my $style = $targets_div_style;
3212: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3213: $style = $homedom_div_style;
3214: }
1.160.6.7 raeburn 3215: my $space;
3216: if ($islast && $num == 1) {
3217: $space = '<div display="inline-block"> </div>';
3218: }
3219: my $output =
3220: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3221: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3222: '<td valaign="top">'.$space.
3223: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3224: for (my $i=0; $i<@rulenames; $i++) {
3225: my $rule = $rulenames[$i];
3226: my ($checked,$extra);
3227: if ($rulenames[$i] eq 'default') {
3228: $rule = '';
3229: }
3230: if ($rulenames[$i] eq 'specific') {
3231: if (ref($servers) eq 'HASH') {
3232: my $default;
3233: if (($current ne '') && (exists($servers->{$current}))) {
3234: $checked = ' checked="checked"';
3235: }
3236: unless ($checked) {
3237: $default = ' selected="selected"';
3238: }
1.160.6.7 raeburn 3239: $extra =
3240: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3241: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3242: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3243: '<option value=""'.$default.'></option>'."\n";
3244: foreach my $server (sort(keys(%{$servers}))) {
3245: if (ref($currbalancer) eq 'HASH') {
3246: next if (exists($currbalancer->{$server}));
3247: }
1.150 raeburn 3248: my $selected;
1.160.6.7 raeburn 3249: if ($server eq $current) {
1.150 raeburn 3250: $selected = ' selected="selected"';
3251: }
1.160.6.7 raeburn 3252: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3253: }
3254: $extra .= '</select>';
3255: }
3256: } elsif ($rule eq $current) {
3257: $checked = ' checked="checked"';
3258: }
3259: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3260: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3261: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3262: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3263: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3264: '</label>'.$extra.'</span><br />'."\n";
3265: }
3266: $output .= '</div></td></tr>'."\n";
3267: return $output;
3268: }
3269:
3270: sub offloadtype_text {
3271: my %ruletitles = &Apache::lonlocal::texthash (
3272: 'default' => 'Offloads to default destinations',
3273: 'homeserver' => "Offloads to user's home server",
3274: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3275: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3276: 'none' => 'No offload',
1.150 raeburn 3277: );
3278: return %ruletitles;
3279: }
3280:
3281: sub sparestype_titles {
3282: my %typestitles = &Apache::lonlocal::texthash (
3283: 'primary' => 'primary',
3284: 'default' => 'default',
3285: );
3286: return %typestitles;
3287: }
3288:
1.28 raeburn 3289: sub contact_titles {
3290: my %titles = &Apache::lonlocal::texthash (
3291: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3292: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3293: 'errormail' => 'Error reports to be e-mailed to',
3294: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3295: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3296: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3297: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3298: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23! raeburn 3299: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3300: );
3301: my %short_titles = &Apache::lonlocal::texthash (
3302: adminemail => 'Admin E-mail address',
3303: supportemail => 'Support E-mail',
3304: );
3305: return (\%titles,\%short_titles);
3306: }
3307:
1.72 raeburn 3308: sub tool_titles {
3309: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3310: aboutme => 'Personal web page',
1.86 raeburn 3311: blog => 'Blog',
1.160.6.4 raeburn 3312: webdav => 'WebDAV',
1.86 raeburn 3313: portfolio => 'Portfolio',
1.88 bisitz 3314: official => 'Official courses (with institutional codes)',
3315: unofficial => 'Unofficial courses',
1.98 raeburn 3316: community => 'Communities',
1.86 raeburn 3317: );
1.72 raeburn 3318: return %titles;
3319: }
3320:
1.101 raeburn 3321: sub courserequest_titles {
3322: my %titles = &Apache::lonlocal::texthash (
3323: official => 'Official',
3324: unofficial => 'Unofficial',
3325: community => 'Communities',
3326: norequest => 'Not allowed',
1.104 raeburn 3327: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3328: validate => 'With validation',
3329: autolimit => 'Numerical limit',
1.103 raeburn 3330: unlimited => '(blank for unlimited)',
1.101 raeburn 3331: );
3332: return %titles;
3333: }
3334:
1.160.6.5 raeburn 3335: sub authorrequest_titles {
3336: my %titles = &Apache::lonlocal::texthash (
3337: norequest => 'Not allowed',
3338: approval => 'Approval by Dom. Coord.',
3339: automatic => 'Automatic approval',
3340: );
3341: return %titles;
3342: }
3343:
1.101 raeburn 3344: sub courserequest_conditions {
3345: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3346: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3347: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3348: );
3349: return %conditions;
3350: }
3351:
3352:
1.27 raeburn 3353: sub print_usercreation {
1.30 raeburn 3354: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3355: my $numinrow = 4;
1.28 raeburn 3356: my $datatable;
3357: if ($position eq 'top') {
1.30 raeburn 3358: $$rowtotal ++;
1.34 raeburn 3359: my $rowcount = 0;
1.32 raeburn 3360: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3361: if (ref($rules) eq 'HASH') {
3362: if (keys(%{$rules}) > 0) {
1.32 raeburn 3363: $datatable .= &user_formats_row('username',$settings,$rules,
3364: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3365: $$rowtotal ++;
1.32 raeburn 3366: $rowcount ++;
3367: }
3368: }
3369: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3370: if (ref($idrules) eq 'HASH') {
3371: if (keys(%{$idrules}) > 0) {
3372: $datatable .= &user_formats_row('id',$settings,$idrules,
3373: $idruleorder,$numinrow,$rowcount);
3374: $$rowtotal ++;
3375: $rowcount ++;
1.28 raeburn 3376: }
3377: }
1.43 raeburn 3378: my ($emailrules,$emailruleorder) =
3379: &Apache::lonnet::inst_userrules($dom,'email');
3380: if (ref($emailrules) eq 'HASH') {
3381: if (keys(%{$emailrules}) > 0) {
3382: $datatable .= &user_formats_row('email',$settings,$emailrules,
3383: $emailruleorder,$numinrow,$rowcount);
3384: $$rowtotal ++;
3385: $rowcount ++;
3386: }
3387: }
1.39 raeburn 3388: if ($rowcount == 0) {
3389: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3390: $$rowtotal ++;
3391: $rowcount ++;
3392: }
1.34 raeburn 3393: } elsif ($position eq 'middle') {
1.100 raeburn 3394: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3395: my ($rules,$ruleorder) =
3396: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3397: my %lt = &usercreation_types();
3398: my %checked;
1.50 raeburn 3399: my @selfcreate;
1.34 raeburn 3400: if (ref($settings) eq 'HASH') {
3401: if (ref($settings->{'cancreate'}) eq 'HASH') {
3402: foreach my $item (@creators) {
3403: $checked{$item} = $settings->{'cancreate'}{$item};
3404: }
1.50 raeburn 3405: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3406: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3407: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3408: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3409: @selfcreate = ('email','login','sso');
3410: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3411: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3412: }
3413: }
1.34 raeburn 3414: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3415: foreach my $item (@creators) {
3416: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3417: $checked{$item} = 'none';
3418: }
3419: }
3420: }
3421: }
3422: my $rownum = 0;
3423: foreach my $item (@creators) {
3424: $rownum ++;
1.50 raeburn 3425: if ($item ne 'selfcreate') {
3426: if ($checked{$item} eq '') {
1.43 raeburn 3427: $checked{$item} = 'any';
3428: }
1.34 raeburn 3429: }
3430: my $css_class;
3431: if ($rownum%2) {
3432: $css_class = '';
3433: } else {
3434: $css_class = ' class="LC_odd_row" ';
3435: }
3436: $datatable .= '<tr'.$css_class.'>'.
3437: '<td><span class="LC_nobreak">'.$lt{$item}.
3438: '</span></td><td align="right">';
1.50 raeburn 3439: my @options;
1.45 raeburn 3440: if ($item eq 'selfcreate') {
1.43 raeburn 3441: push(@options,('email','login','sso'));
3442: } else {
1.50 raeburn 3443: @options = ('any');
1.43 raeburn 3444: if (ref($rules) eq 'HASH') {
3445: if (keys(%{$rules}) > 0) {
3446: push(@options,('official','unofficial'));
3447: }
1.37 raeburn 3448: }
1.50 raeburn 3449: push(@options,'none');
1.37 raeburn 3450: }
3451: foreach my $option (@options) {
1.50 raeburn 3452: my $type = 'radio';
1.34 raeburn 3453: my $check = ' ';
1.50 raeburn 3454: if ($item eq 'selfcreate') {
3455: $type = 'checkbox';
3456: if (grep(/^\Q$option\E$/,@selfcreate)) {
3457: $check = ' checked="checked" ';
3458: }
3459: } else {
3460: if ($checked{$item} eq $option) {
3461: $check = ' checked="checked" ';
3462: }
1.34 raeburn 3463: }
3464: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3465: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3466: $item.'" value="'.$option.'"'.$check.'/> '.
3467: $lt{$option}.'</label> </span>';
3468: }
3469: $datatable .= '</td></tr>';
3470: }
1.93 raeburn 3471: my ($othertitle,$usertypes,$types) =
3472: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3473: my $createsettings;
3474: if (ref($settings) eq 'HASH') {
3475: $createsettings = $settings->{cancreate};
3476: }
1.93 raeburn 3477: if (ref($usertypes) eq 'HASH') {
3478: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3479: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3480: $dom,$numinrow,$othertitle,
3481: 'statustocreate');
3482: $$rowtotal ++;
1.160.6.5 raeburn 3483: $rownum ++;
1.93 raeburn 3484: }
3485: }
1.160.6.5 raeburn 3486: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3487: } else {
3488: my @contexts = ('author','course','domain');
3489: my @authtypes = ('int','krb4','krb5','loc');
3490: my %checked;
3491: if (ref($settings) eq 'HASH') {
3492: if (ref($settings->{'authtypes'}) eq 'HASH') {
3493: foreach my $item (@contexts) {
3494: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3495: foreach my $auth (@authtypes) {
3496: if ($settings->{'authtypes'}{$item}{$auth}) {
3497: $checked{$item}{$auth} = ' checked="checked" ';
3498: }
3499: }
3500: }
3501: }
1.27 raeburn 3502: }
1.35 raeburn 3503: } else {
3504: foreach my $item (@contexts) {
1.36 raeburn 3505: foreach my $auth (@authtypes) {
1.35 raeburn 3506: $checked{$item}{$auth} = ' checked="checked" ';
3507: }
3508: }
1.27 raeburn 3509: }
1.28 raeburn 3510: my %title = &context_names();
3511: my %authname = &authtype_names();
3512: my $rownum = 0;
3513: my $css_class;
3514: foreach my $item (@contexts) {
3515: if ($rownum%2) {
3516: $css_class = '';
3517: } else {
3518: $css_class = ' class="LC_odd_row" ';
3519: }
1.30 raeburn 3520: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3521: '<td>'.$title{$item}.
3522: '</td><td class="LC_left_item">'.
3523: '<span class="LC_nobreak">';
3524: foreach my $auth (@authtypes) {
3525: $datatable .= '<label>'.
3526: '<input type="checkbox" name="'.$item.'_auth" '.
3527: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3528: $authname{$auth}.'</label> ';
3529: }
3530: $datatable .= '</span></td></tr>';
3531: $rownum ++;
1.27 raeburn 3532: }
1.30 raeburn 3533: $$rowtotal += $rownum;
1.27 raeburn 3534: }
3535: return $datatable;
3536: }
3537:
1.160.6.5 raeburn 3538: sub captcha_choice {
3539: my ($context,$settings,$itemcount) = @_;
3540: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3541: my %lt = &captcha_phrases();
3542: $keyentry = 'hidden';
3543: if ($context eq 'cancreate') {
3544: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3545: } elsif ($context eq 'login') {
3546: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3547: }
3548: if (ref($settings) eq 'HASH') {
3549: if ($settings->{'captcha'}) {
3550: $checked{$settings->{'captcha'}} = ' checked="checked"';
3551: } else {
3552: $checked{'original'} = ' checked="checked"';
3553: }
3554: if ($settings->{'captcha'} eq 'recaptcha') {
3555: $pubtext = $lt{'pub'};
3556: $privtext = $lt{'priv'};
3557: $keyentry = 'text';
3558: }
3559: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3560: $currpub = $settings->{'recaptchakeys'}{'public'};
3561: $currpriv = $settings->{'recaptchakeys'}{'private'};
3562: }
3563: } else {
3564: $checked{'original'} = ' checked="checked"';
3565: }
3566: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3567: my $output = '<tr'.$css_class.'>'.
3568: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3569: '<table><tr><td>'."\n";
3570: foreach my $option ('original','recaptcha','notused') {
3571: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3572: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3573: $lt{$option}.'</label></span>';
3574: unless ($option eq 'notused') {
3575: $output .= (' 'x2)."\n";
3576: }
3577: }
3578: #
3579: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3580: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3581: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3582: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3583: #
3584: $output .= '</td></tr>'."\n".
3585: '<tr><td>'."\n".
3586: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3587: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3588: $currpub.'" size="40" /></span><br />'."\n".
3589: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3590: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3591: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3592: '</td></tr>';
3593: return $output;
3594: }
3595:
1.32 raeburn 3596: sub user_formats_row {
3597: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3598: my $output;
3599: my %text = (
3600: 'username' => 'new usernames',
3601: 'id' => 'IDs',
1.45 raeburn 3602: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3603: );
3604: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3605: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3606: '<td><span class="LC_nobreak">';
3607: if ($type eq 'email') {
3608: $output .= &mt("Formats disallowed for $text{$type}: ");
3609: } else {
3610: $output .= &mt("Format rules to check for $text{$type}: ");
3611: }
3612: $output .= '</span></td>'.
3613: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3614: my $rem;
3615: if (ref($ruleorder) eq 'ARRAY') {
3616: for (my $i=0; $i<@{$ruleorder}; $i++) {
3617: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3618: my $rem = $i%($numinrow);
3619: if ($rem == 0) {
3620: if ($i > 0) {
3621: $output .= '</tr>';
3622: }
3623: $output .= '<tr>';
3624: }
3625: my $check = ' ';
1.39 raeburn 3626: if (ref($settings) eq 'HASH') {
3627: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3628: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3629: $check = ' checked="checked" ';
3630: }
1.27 raeburn 3631: }
3632: }
3633: $output .= '<td class="LC_left_item">'.
3634: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3635: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3636: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3637: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3638: }
3639: }
3640: $rem = @{$ruleorder}%($numinrow);
3641: }
3642: my $colsleft = $numinrow - $rem;
3643: if ($colsleft > 1 ) {
3644: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3645: ' </td>';
3646: } elsif ($colsleft == 1) {
3647: $output .= '<td class="LC_left_item"> </td>';
3648: }
3649: $output .= '</tr></table></td></tr>';
3650: return $output;
3651: }
3652:
1.34 raeburn 3653: sub usercreation_types {
3654: my %lt = &Apache::lonlocal::texthash (
3655: author => 'When adding a co-author',
3656: course => 'When adding a user to a course',
1.100 raeburn 3657: requestcrs => 'When requesting a course',
1.45 raeburn 3658: selfcreate => 'User creates own account',
1.34 raeburn 3659: any => 'Any',
3660: official => 'Institutional only ',
3661: unofficial => 'Non-institutional only',
1.85 schafran 3662: email => 'E-mail address',
1.43 raeburn 3663: login => 'Institutional Login',
3664: sso => 'SSO',
1.34 raeburn 3665: none => 'None',
3666: );
3667: return %lt;
1.48 raeburn 3668: }
1.34 raeburn 3669:
1.28 raeburn 3670: sub authtype_names {
3671: my %lt = &Apache::lonlocal::texthash(
3672: int => 'Internal',
3673: krb4 => 'Kerberos 4',
3674: krb5 => 'Kerberos 5',
3675: loc => 'Local',
3676: );
3677: return %lt;
3678: }
3679:
3680: sub context_names {
3681: my %context_title = &Apache::lonlocal::texthash(
3682: author => 'Creating users when an Author',
3683: course => 'Creating users when in a course',
3684: domain => 'Creating users when a Domain Coordinator',
3685: );
3686: return %context_title;
3687: }
3688:
1.33 raeburn 3689: sub print_usermodification {
3690: my ($position,$dom,$settings,$rowtotal) = @_;
3691: my $numinrow = 4;
3692: my ($context,$datatable,$rowcount);
3693: if ($position eq 'top') {
3694: $rowcount = 0;
3695: $context = 'author';
3696: foreach my $role ('ca','aa') {
3697: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3698: $numinrow,$rowcount);
3699: $$rowtotal ++;
3700: $rowcount ++;
3701: }
1.63 raeburn 3702: } elsif ($position eq 'middle') {
1.33 raeburn 3703: $context = 'course';
3704: $rowcount = 0;
3705: foreach my $role ('st','ep','ta','in','cr') {
3706: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3707: $numinrow,$rowcount);
3708: $$rowtotal ++;
3709: $rowcount ++;
3710: }
1.63 raeburn 3711: } elsif ($position eq 'bottom') {
3712: $context = 'selfcreate';
3713: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3714: $usertypes->{'default'} = $othertitle;
3715: if (ref($types) eq 'ARRAY') {
3716: push(@{$types},'default');
3717: $usertypes->{'default'} = $othertitle;
3718: foreach my $status (@{$types}) {
3719: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3720: $numinrow,$rowcount,$usertypes);
3721: $$rowtotal ++;
3722: $rowcount ++;
3723: }
3724: }
1.33 raeburn 3725: }
3726: return $datatable;
3727: }
3728:
1.43 raeburn 3729: sub print_defaults {
3730: my ($dom,$rowtotal) = @_;
1.68 raeburn 3731: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3732: 'datelocale_def','portal_def');
1.43 raeburn 3733: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3734: my $titles = &defaults_titles($dom);
1.43 raeburn 3735: my $rownum = 0;
3736: my ($datatable,$css_class);
3737: foreach my $item (@items) {
3738: if ($rownum%2) {
3739: $css_class = '';
3740: } else {
3741: $css_class = ' class="LC_odd_row" ';
3742: }
3743: $datatable .= '<tr'.$css_class.'>'.
3744: '<td><span class="LC_nobreak">'.$titles->{$item}.
3745: '</span></td><td class="LC_right_item">';
3746: if ($item eq 'auth_def') {
3747: my @authtypes = ('internal','krb4','krb5','localauth');
3748: my %shortauth = (
3749: internal => 'int',
3750: krb4 => 'krb4',
3751: krb5 => 'krb5',
3752: localauth => 'loc'
3753: );
3754: my %authnames = &authtype_names();
3755: foreach my $auth (@authtypes) {
3756: my $checked = ' ';
3757: if ($domdefaults{$item} eq $auth) {
3758: $checked = ' checked="checked" ';
3759: }
3760: $datatable .= '<label><input type="radio" name="'.$item.
3761: '" value="'.$auth.'"'.$checked.'/>'.
3762: $authnames{$shortauth{$auth}}.'</label> ';
3763: }
1.54 raeburn 3764: } elsif ($item eq 'timezone_def') {
3765: my $includeempty = 1;
3766: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3767: } elsif ($item eq 'datelocale_def') {
3768: my $includeempty = 1;
3769: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3770: } elsif ($item eq 'lang_def') {
3771: my %langchoices = &get_languages_hash();
3772: $langchoices{''} = 'No language preference';
3773: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3774: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3775: \%langchoices);
1.43 raeburn 3776: } else {
1.141 raeburn 3777: my $size;
3778: if ($item eq 'portal_def') {
3779: $size = ' size="25"';
3780: }
1.43 raeburn 3781: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3782: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3783: }
3784: $datatable .= '</td></tr>';
3785: $rownum ++;
3786: }
3787: $$rowtotal += $rownum;
3788: return $datatable;
3789: }
3790:
1.160.6.5 raeburn 3791: sub get_languages_hash {
3792: my %langchoices;
3793: foreach my $id (&Apache::loncommon::languageids()) {
3794: my $code = &Apache::loncommon::supportedlanguagecode($id);
3795: if ($code ne '') {
3796: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3797: }
3798: }
3799: return %langchoices;
3800: }
3801:
1.43 raeburn 3802: sub defaults_titles {
1.141 raeburn 3803: my ($dom) = @_;
1.43 raeburn 3804: my %titles = &Apache::lonlocal::texthash (
3805: 'auth_def' => 'Default authentication type',
3806: 'auth_arg_def' => 'Default authentication argument',
3807: 'lang_def' => 'Default language',
1.54 raeburn 3808: 'timezone_def' => 'Default timezone',
1.68 raeburn 3809: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3810: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3811: );
1.141 raeburn 3812: if ($dom) {
3813: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3814: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3815: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3816: $protocol = 'http' if ($protocol ne 'https');
3817: if ($uint_dom) {
3818: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3819: $uint_dom);
3820: }
3821: }
1.43 raeburn 3822: return (\%titles);
3823: }
3824:
1.46 raeburn 3825: sub print_scantronformat {
3826: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3827: my $itemcount = 1;
1.60 raeburn 3828: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3829: %confhash);
1.46 raeburn 3830: my $switchserver = &check_switchserver($dom,$confname);
3831: my %lt = &Apache::lonlocal::texthash (
1.95 www 3832: default => 'Default bubblesheet format file error',
3833: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3834: );
3835: my %scantronfiles = (
3836: default => 'default.tab',
3837: custom => 'custom.tab',
3838: );
3839: foreach my $key (keys(%scantronfiles)) {
3840: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3841: .$scantronfiles{$key};
3842: }
3843: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3844: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3845: if (!$switchserver) {
3846: my $servadm = $r->dir_config('lonAdmEMail');
3847: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3848: if ($configuserok eq 'ok') {
3849: if ($author_ok eq 'ok') {
3850: my %legacyfile = (
3851: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3852: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3853: );
3854: my %md5chk;
3855: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3856: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3857: chomp($md5chk{$type});
1.46 raeburn 3858: }
3859: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3860: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3861: ($scantronurls{$type},my $error) =
1.46 raeburn 3862: &legacy_scantronformat($r,$dom,$confname,
3863: $type,$legacyfile{$type},
3864: $scantronurls{$type},
3865: $scantronfiles{$type});
1.60 raeburn 3866: if ($error ne '') {
3867: $error{$type} = $error;
3868: }
3869: }
3870: if (keys(%error) == 0) {
3871: $is_custom = 1;
3872: $confhash{'scantron'}{'scantronformat'} =
3873: $scantronurls{'custom'};
3874: my $putresult =
3875: &Apache::lonnet::put_dom('configuration',
3876: \%confhash,$dom);
3877: if ($putresult ne 'ok') {
3878: $error{'custom'} =
3879: '<span class="LC_error">'.
3880: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3881: }
1.46 raeburn 3882: }
3883: } else {
1.60 raeburn 3884: ($scantronurls{'default'},my $error) =
1.46 raeburn 3885: &legacy_scantronformat($r,$dom,$confname,
3886: 'default',$legacyfile{'default'},
3887: $scantronurls{'default'},
3888: $scantronfiles{'default'});
1.60 raeburn 3889: if ($error eq '') {
3890: $confhash{'scantron'}{'scantronformat'} = '';
3891: my $putresult =
3892: &Apache::lonnet::put_dom('configuration',
3893: \%confhash,$dom);
3894: if ($putresult ne 'ok') {
3895: $error{'default'} =
3896: '<span class="LC_error">'.
3897: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3898: }
3899: } else {
3900: $error{'default'} = $error;
3901: }
1.46 raeburn 3902: }
3903: }
3904: }
3905: } else {
1.95 www 3906: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3907: }
3908: }
3909: if (ref($settings) eq 'HASH') {
3910: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3911: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3912: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3913: $scantronurl = '';
3914: } else {
3915: $scantronurl = $settings->{'scantronformat'};
3916: }
3917: $is_custom = 1;
3918: } else {
3919: $scantronurl = $scantronurls{'default'};
3920: }
3921: } else {
1.60 raeburn 3922: if ($is_custom) {
3923: $scantronurl = $scantronurls{'custom'};
3924: } else {
3925: $scantronurl = $scantronurls{'default'};
3926: }
1.46 raeburn 3927: }
3928: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3929: $datatable .= '<tr'.$css_class.'>';
3930: if (!$is_custom) {
1.65 raeburn 3931: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3932: '<span class="LC_nobreak">';
1.46 raeburn 3933: if ($scantronurl) {
1.160.6.21 raeburn 3934: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
3935: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 3936: } else {
3937: $datatable = &mt('File unavailable for display');
3938: }
1.65 raeburn 3939: $datatable .= '</span></td>';
1.60 raeburn 3940: if (keys(%error) == 0) {
3941: $datatable .= '<td valign="bottom">';
3942: if (!$switchserver) {
3943: $datatable .= &mt('Upload:').'<br />';
3944: }
3945: } else {
3946: my $errorstr;
3947: foreach my $key (sort(keys(%error))) {
3948: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3949: }
3950: $datatable .= '<td>'.$errorstr;
3951: }
1.46 raeburn 3952: } else {
3953: if (keys(%error) > 0) {
3954: my $errorstr;
3955: foreach my $key (sort(keys(%error))) {
3956: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3957: }
1.60 raeburn 3958: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3959: } elsif ($scantronurl) {
1.160.6.21 raeburn 3960: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
3961: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 3962: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 3963: $link.
3964: '<label><input type="checkbox" name="scantronformat_del"'.
3965: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 3966: '<td><span class="LC_nobreak"> '.
3967: &mt('Replace:').'</span><br />';
1.46 raeburn 3968: }
3969: }
3970: if (keys(%error) == 0) {
3971: if ($switchserver) {
3972: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3973: } else {
1.65 raeburn 3974: $datatable .='<span class="LC_nobreak"> '.
3975: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3976: }
3977: }
3978: $datatable .= '</td></tr>';
3979: $$rowtotal ++;
3980: return $datatable;
3981: }
3982:
3983: sub legacy_scantronformat {
3984: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3985: my ($url,$error);
3986: my @statinfo = &Apache::lonnet::stat_file($newurl);
3987: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3988: (my $result,$url) =
3989: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3990: '','',$newfile);
3991: if ($result ne 'ok') {
1.130 raeburn 3992: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3993: }
3994: }
3995: return ($url,$error);
3996: }
1.43 raeburn 3997:
1.49 raeburn 3998: sub print_coursecategories {
1.57 raeburn 3999: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4000: my $datatable;
4001: if ($position eq 'top') {
4002: my $toggle_cats_crs = ' ';
4003: my $toggle_cats_dom = ' checked="checked" ';
4004: my $can_cat_crs = ' ';
4005: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4006: my $toggle_catscomm_comm = ' ';
4007: my $toggle_catscomm_dom = ' checked="checked" ';
4008: my $can_catcomm_comm = ' ';
4009: my $can_catcomm_dom = ' checked="checked" ';
4010:
1.57 raeburn 4011: if (ref($settings) eq 'HASH') {
4012: if ($settings->{'togglecats'} eq 'crs') {
4013: $toggle_cats_crs = $toggle_cats_dom;
4014: $toggle_cats_dom = ' ';
4015: }
4016: if ($settings->{'categorize'} eq 'crs') {
4017: $can_cat_crs = $can_cat_dom;
4018: $can_cat_dom = ' ';
4019: }
1.120 raeburn 4020: if ($settings->{'togglecatscomm'} eq 'comm') {
4021: $toggle_catscomm_comm = $toggle_catscomm_dom;
4022: $toggle_catscomm_dom = ' ';
4023: }
4024: if ($settings->{'categorizecomm'} eq 'comm') {
4025: $can_catcomm_comm = $can_catcomm_dom;
4026: $can_catcomm_dom = ' ';
4027: }
1.57 raeburn 4028: }
4029: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4030: togglecats => 'Show/Hide a course in catalog',
4031: togglecatscomm => 'Show/Hide a community in catalog',
4032: categorize => 'Assign a category to a course',
4033: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4034: );
4035: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4036: dom => 'Set in Domain',
4037: crs => 'Set in Course',
4038: comm => 'Set in Community',
1.57 raeburn 4039: );
4040: $datatable = '<tr class="LC_odd_row">'.
4041: '<td>'.$title{'togglecats'}.'</td>'.
4042: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4043: '<input type="radio" name="togglecats"'.
4044: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4045: '<label><input type="radio" name="togglecats"'.
4046: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4047: '</tr><tr>'.
4048: '<td>'.$title{'categorize'}.'</td>'.
4049: '<td class="LC_right_item"><span class="LC_nobreak">'.
4050: '<label><input type="radio" name="categorize"'.
4051: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4052: '<label><input type="radio" name="categorize"'.
4053: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4054: '</tr><tr class="LC_odd_row">'.
4055: '<td>'.$title{'togglecatscomm'}.'</td>'.
4056: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4057: '<input type="radio" name="togglecatscomm"'.
4058: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4059: '<label><input type="radio" name="togglecatscomm"'.
4060: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4061: '</tr><tr>'.
4062: '<td>'.$title{'categorizecomm'}.'</td>'.
4063: '<td class="LC_right_item"><span class="LC_nobreak">'.
4064: '<label><input type="radio" name="categorizecomm"'.
4065: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4066: '<label><input type="radio" name="categorizecomm"'.
4067: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4068: '</tr>';
1.120 raeburn 4069: $$rowtotal += 4;
1.57 raeburn 4070: } else {
4071: my $css_class;
4072: my $itemcount = 1;
4073: my $cathash;
4074: if (ref($settings) eq 'HASH') {
4075: $cathash = $settings->{'cats'};
4076: }
4077: if (ref($cathash) eq 'HASH') {
4078: my (@cats,@trails,%allitems,%idx,@jsarray);
4079: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4080: \%allitems,\%idx,\@jsarray);
4081: my $maxdepth = scalar(@cats);
4082: my $colattrib = '';
4083: if ($maxdepth > 2) {
4084: $colattrib = ' colspan="2" ';
4085: }
4086: my @path;
4087: if (@cats > 0) {
4088: if (ref($cats[0]) eq 'ARRAY') {
4089: my $numtop = @{$cats[0]};
4090: my $maxnum = $numtop;
1.120 raeburn 4091: my %default_names = (
4092: instcode => &mt('Official courses'),
4093: communities => &mt('Communities'),
4094: );
4095:
4096: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4097: ($cathash->{'instcode::0'} eq '') ||
4098: (!grep(/^communities$/,@{$cats[0]})) ||
4099: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4100: $maxnum ++;
4101: }
4102: my $lastidx;
4103: for (my $i=0; $i<$numtop; $i++) {
4104: my $parent = $cats[0][$i];
4105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4106: my $item = &escape($parent).'::0';
4107: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4108: $lastidx = $idx{$item};
4109: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4110: .'<select name="'.$item.'"'.$chgstr.'>';
4111: for (my $k=0; $k<=$maxnum; $k++) {
4112: my $vpos = $k+1;
4113: my $selstr;
4114: if ($k == $i) {
4115: $selstr = ' selected="selected" ';
4116: }
4117: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4118: }
4119: $datatable .= '</select></td><td>';
1.120 raeburn 4120: if ($parent eq 'instcode' || $parent eq 'communities') {
4121: $datatable .= '<span class="LC_nobreak">'
4122: .$default_names{$parent}.'</span>';
4123: if ($parent eq 'instcode') {
4124: $datatable .= '<br /><span class="LC_nobreak">('
4125: .&mt('with institutional codes')
4126: .')</span></td><td'.$colattrib.'>';
4127: } else {
4128: $datatable .= '<table><tr><td>';
4129: }
4130: $datatable .= '<span class="LC_nobreak">'
4131: .'<label><input type="radio" name="'
4132: .$parent.'" value="1" checked="checked" />'
4133: .&mt('Display').'</label>';
4134: if ($parent eq 'instcode') {
4135: $datatable .= ' ';
4136: } else {
4137: $datatable .= '</span></td></tr><tr><td>'
4138: .'<span class="LC_nobreak">';
4139: }
4140: $datatable .= '<label><input type="radio" name="'
4141: .$parent.'" value="0" />'
4142: .&mt('Do not display').'</label></span>';
4143: if ($parent eq 'communities') {
4144: $datatable .= '</td></tr></table>';
4145: }
4146: $datatable .= '</td>';
1.57 raeburn 4147: } else {
4148: $datatable .= $parent
4149: .' <label><input type="checkbox" name="deletecategory" '
4150: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4151: }
4152: my $depth = 1;
4153: push(@path,$parent);
4154: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4155: pop(@path);
4156: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4157: $itemcount ++;
4158: }
1.48 raeburn 4159: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4160: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4161: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4162: for (my $k=0; $k<=$maxnum; $k++) {
4163: my $vpos = $k+1;
4164: my $selstr;
1.57 raeburn 4165: if ($k == $numtop) {
1.48 raeburn 4166: $selstr = ' selected="selected" ';
4167: }
4168: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4169: }
1.59 bisitz 4170: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4171: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4172: .'</tr>'."\n";
1.48 raeburn 4173: $itemcount ++;
1.120 raeburn 4174: foreach my $default ('instcode','communities') {
4175: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4176: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4177: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4178: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4179: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4180: for (my $k=0; $k<=$maxnum; $k++) {
4181: my $vpos = $k+1;
4182: my $selstr;
4183: if ($k == $maxnum) {
4184: $selstr = ' selected="selected" ';
4185: }
4186: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4187: }
1.120 raeburn 4188: $datatable .= '</select></span></td>'.
4189: '<td><span class="LC_nobreak">'.
4190: $default_names{$default}.'</span>';
4191: if ($default eq 'instcode') {
4192: $datatable .= '<br /><span class="LC_nobreak">('
4193: .&mt('with institutional codes').')</span>';
4194: }
4195: $datatable .= '</td>'
4196: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4197: .&mt('Display').'</label> '
4198: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4199: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4200: }
4201: }
4202: }
1.57 raeburn 4203: } else {
4204: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4205: }
4206: } else {
1.57 raeburn 4207: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4208: .&initialize_categories($itemcount);
1.48 raeburn 4209: }
1.57 raeburn 4210: $$rowtotal += $itemcount;
1.48 raeburn 4211: }
4212: return $datatable;
4213: }
4214:
1.69 raeburn 4215: sub print_serverstatuses {
4216: my ($dom,$settings,$rowtotal) = @_;
4217: my $datatable;
4218: my @pages = &serverstatus_pages();
4219: my (%namedaccess,%machineaccess);
4220: foreach my $type (@pages) {
4221: $namedaccess{$type} = '';
4222: $machineaccess{$type}= '';
4223: }
4224: if (ref($settings) eq 'HASH') {
4225: foreach my $type (@pages) {
4226: if (exists($settings->{$type})) {
4227: if (ref($settings->{$type}) eq 'HASH') {
4228: foreach my $key (keys(%{$settings->{$type}})) {
4229: if ($key eq 'namedusers') {
4230: $namedaccess{$type} = $settings->{$type}->{$key};
4231: } elsif ($key eq 'machines') {
4232: $machineaccess{$type} = $settings->{$type}->{$key};
4233: }
4234: }
4235: }
4236: }
4237: }
4238: }
1.81 raeburn 4239: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4240: my $rownum = 0;
4241: my $css_class;
4242: foreach my $type (@pages) {
4243: $rownum ++;
4244: $css_class = $rownum%2?' class="LC_odd_row"':'';
4245: $datatable .= '<tr'.$css_class.'>'.
4246: '<td><span class="LC_nobreak">'.
4247: $titles->{$type}.'</span></td>'.
4248: '<td class="LC_left_item">'.
4249: '<input type="text" name="'.$type.'_namedusers" '.
4250: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4251: '<td class="LC_right_item">'.
4252: '<span class="LC_nobreak">'.
4253: '<input type="text" name="'.$type.'_machines" '.
4254: 'value="'.$machineaccess{$type}.'" size="10" />'.
4255: '</td></tr>'."\n";
4256: }
4257: $$rowtotal += $rownum;
4258: return $datatable;
4259: }
4260:
4261: sub serverstatus_pages {
4262: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4263: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4264: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4265: }
4266:
1.49 raeburn 4267: sub coursecategories_javascript {
4268: my ($settings) = @_;
1.57 raeburn 4269: my ($output,$jstext,$cathash);
1.49 raeburn 4270: if (ref($settings) eq 'HASH') {
1.57 raeburn 4271: $cathash = $settings->{'cats'};
4272: }
4273: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4274: my (@cats,@jsarray,%idx);
1.57 raeburn 4275: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4276: if (@jsarray > 0) {
4277: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4278: for (my $i=0; $i<@jsarray; $i++) {
4279: if (ref($jsarray[$i]) eq 'ARRAY') {
4280: my $catstr = join('","',@{$jsarray[$i]});
4281: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4282: }
4283: }
4284: }
4285: } else {
4286: $jstext = ' var categories = Array(1);'."\n".
4287: ' categories[0] = Array("instcode_pos");'."\n";
4288: }
1.120 raeburn 4289: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4290: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4291: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4292: $output = <<"ENDSCRIPT";
4293: <script type="text/javascript">
1.109 raeburn 4294: // <![CDATA[
1.49 raeburn 4295: function reorderCats(form,parent,item,idx) {
4296: var changedVal;
4297: $jstext
4298: var newpos = 'addcategory_pos';
4299: var current = new Array;
4300: if (parent == '') {
4301: var has_instcode = 0;
4302: var maxtop = categories[idx].length;
4303: for (var j=0; j<maxtop; j++) {
4304: if (categories[idx][j] == 'instcode::0') {
4305: has_instcode == 1;
4306: }
4307: }
4308: if (has_instcode == 0) {
4309: categories[idx][maxtop] = 'instcode_pos';
4310: }
4311: } else {
4312: newpos += '_'+parent;
4313: }
4314: var maxh = 1 + categories[idx].length;
4315: var current = new Array;
4316: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4317: if (item == newpos) {
4318: changedVal = newitemVal;
4319: } else {
4320: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4321: current[newitemVal] = newpos;
4322: }
4323: for (var i=0; i<categories[idx].length; i++) {
4324: var elementName = categories[idx][i];
4325: if (elementName != item) {
4326: if (form.elements[elementName]) {
4327: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4328: current[currVal] = elementName;
4329: }
4330: }
4331: }
4332: var oldVal;
4333: for (var j=0; j<maxh; j++) {
4334: if (current[j] == undefined) {
4335: oldVal = j;
4336: }
4337: }
4338: if (oldVal < changedVal) {
4339: for (var k=oldVal+1; k<=changedVal ; k++) {
4340: var elementName = current[k];
4341: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4342: }
4343: } else {
4344: for (var k=changedVal; k<oldVal; k++) {
4345: var elementName = current[k];
4346: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4347: }
4348: }
4349: return;
4350: }
1.120 raeburn 4351:
4352: function categoryCheck(form) {
4353: if (form.elements['addcategory_name'].value == 'instcode') {
4354: alert('$instcode_reserved\\n$choose_again');
4355: return false;
4356: }
4357: if (form.elements['addcategory_name'].value == 'communities') {
4358: alert('$communities_reserved\\n$choose_again');
4359: return false;
4360: }
4361: return true;
4362: }
4363:
1.109 raeburn 4364: // ]]>
1.49 raeburn 4365: </script>
4366:
4367: ENDSCRIPT
4368: return $output;
4369: }
4370:
1.48 raeburn 4371: sub initialize_categories {
4372: my ($itemcount) = @_;
1.120 raeburn 4373: my ($datatable,$css_class,$chgstr);
4374: my %default_names = (
4375: instcode => 'Official courses (with institutional codes)',
4376: communities => 'Communities',
4377: );
4378: my $select0 = ' selected="selected"';
4379: my $select1 = '';
4380: foreach my $default ('instcode','communities') {
4381: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4382: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4383: if ($default eq 'communities') {
4384: $select1 = $select0;
4385: $select0 = '';
4386: }
4387: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4388: .'<select name="'.$default.'_pos">'
4389: .'<option value="0"'.$select0.'>1</option>'
4390: .'<option value="1"'.$select1.'>2</option>'
4391: .'<option value="2">3</option></select> '
4392: .$default_names{$default}
4393: .'</span></td><td><span class="LC_nobreak">'
4394: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4395: .&mt('Display').'</label> <label>'
4396: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4397: .'</label></span></td></tr>';
1.120 raeburn 4398: $itemcount ++;
4399: }
1.48 raeburn 4400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4401: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4402: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4403: .'<select name="addcategory_pos"'.$chgstr.'>'
4404: .'<option value="0">1</option>'
4405: .'<option value="1">2</option>'
4406: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4407: .&mt('Add category').'</td><td>'.&mt('Name:')
4408: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4409: return $datatable;
4410: }
4411:
4412: sub build_category_rows {
1.49 raeburn 4413: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4414: my ($text,$name,$item,$chgstr);
1.48 raeburn 4415: if (ref($cats) eq 'ARRAY') {
4416: my $maxdepth = scalar(@{$cats});
4417: if (ref($cats->[$depth]) eq 'HASH') {
4418: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4419: my $numchildren = @{$cats->[$depth]{$parent}};
4420: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23! raeburn 4421: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4422: my ($idxnum,$parent_name,$parent_item);
4423: my $higher = $depth - 1;
4424: if ($higher == 0) {
4425: $parent_name = &escape($parent).'::'.$higher;
4426: } else {
4427: if (ref($path) eq 'ARRAY') {
4428: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4429: }
4430: }
4431: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4432: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4433: if ($j < $numchildren) {
1.48 raeburn 4434: $name = $cats->[$depth]{$parent}[$j];
4435: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4436: $idxnum = $idx->{$item};
4437: } else {
4438: $name = $parent_name;
4439: $item = $parent_item;
1.48 raeburn 4440: }
1.49 raeburn 4441: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4442: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4443: for (my $i=0; $i<=$numchildren; $i++) {
4444: my $vpos = $i+1;
4445: my $selstr;
4446: if ($j == $i) {
4447: $selstr = ' selected="selected" ';
4448: }
4449: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4450: }
4451: $text .= '</select> ';
4452: if ($j < $numchildren) {
4453: my $deeper = $depth+1;
4454: $text .= $name.' '
4455: .'<label><input type="checkbox" name="deletecategory" value="'
4456: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4457: if(ref($path) eq 'ARRAY') {
4458: push(@{$path},$name);
1.49 raeburn 4459: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4460: pop(@{$path});
4461: }
4462: } else {
1.59 bisitz 4463: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4464: if ($j == $numchildren) {
4465: $text .= $name;
4466: } else {
4467: $text .= $item;
4468: }
4469: $text .= '" value="" />';
4470: }
4471: $text .= '</td></tr>';
4472: }
4473: $text .= '</table></td>';
4474: } else {
4475: my $higher = $depth-1;
4476: if ($higher == 0) {
4477: $name = &escape($parent).'::'.$higher;
4478: } else {
4479: if (ref($path) eq 'ARRAY') {
4480: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4481: }
4482: }
4483: my $colspan;
4484: if ($parent ne 'instcode') {
4485: $colspan = $maxdepth - $depth - 1;
4486: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4487: }
4488: }
4489: }
4490: }
4491: return $text;
4492: }
4493:
1.33 raeburn 4494: sub modifiable_userdata_row {
1.63 raeburn 4495: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4496: my $rolename;
1.63 raeburn 4497: if ($context eq 'selfcreate') {
4498: if (ref($usertypes) eq 'HASH') {
4499: $rolename = $usertypes->{$role};
4500: } else {
4501: $rolename = $role;
4502: }
1.33 raeburn 4503: } else {
1.63 raeburn 4504: if ($role eq 'cr') {
4505: $rolename = &mt('Custom role');
4506: } else {
4507: $rolename = &Apache::lonnet::plaintext($role);
4508: }
1.33 raeburn 4509: }
4510: my @fields = ('lastname','firstname','middlename','generation',
4511: 'permanentemail','id');
4512: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4513: my $output;
4514: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4515: $output = '<tr '.$css_class.'>'.
4516: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4517: '<td class="LC_left_item" colspan="2"><table>';
4518: my $rem;
4519: my %checks;
4520: if (ref($settings) eq 'HASH') {
4521: if (ref($settings->{$context}) eq 'HASH') {
4522: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4523: foreach my $field (@fields) {
4524: if ($settings->{$context}->{$role}->{$field}) {
4525: $checks{$field} = ' checked="checked" ';
4526: }
4527: }
4528: }
4529: }
4530: }
4531: for (my $i=0; $i<@fields; $i++) {
4532: my $rem = $i%($numinrow);
4533: if ($rem == 0) {
4534: if ($i > 0) {
4535: $output .= '</tr>';
4536: }
4537: $output .= '<tr>';
4538: }
4539: my $check = ' ';
4540: if (exists($checks{$fields[$i]})) {
4541: $check = $checks{$fields[$i]}
4542: } else {
4543: if ($role eq 'st') {
4544: if (ref($settings) ne 'HASH') {
4545: $check = ' checked="checked" ';
4546: }
4547: }
4548: }
4549: $output .= '<td class="LC_left_item">'.
4550: '<span class="LC_nobreak"><label>'.
4551: '<input type="checkbox" name="canmodify_'.$role.'" '.
4552: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4553: '</label></span></td>';
4554: $rem = @fields%($numinrow);
4555: }
4556: my $colsleft = $numinrow - $rem;
4557: if ($colsleft > 1 ) {
4558: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4559: ' </td>';
4560: } elsif ($colsleft == 1) {
4561: $output .= '<td class="LC_left_item"> </td>';
4562: }
4563: $output .= '</tr></table></td></tr>';
4564: return $output;
4565: }
1.28 raeburn 4566:
1.93 raeburn 4567: sub insttypes_row {
4568: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4569: my %lt = &Apache::lonlocal::texthash (
4570: cansearch => 'Users allowed to search',
4571: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4572: lockablenames => 'User preference to lock name',
1.93 raeburn 4573: );
4574: my $showdom;
4575: if ($context eq 'cansearch') {
4576: $showdom = ' ('.$dom.')';
4577: }
1.160.6.5 raeburn 4578: my $class = 'LC_left_item';
4579: if ($context eq 'statustocreate') {
4580: $class = 'LC_right_item';
4581: }
1.25 raeburn 4582: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4583: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4584: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4585: my $rem;
4586: if (ref($types) eq 'ARRAY') {
4587: for (my $i=0; $i<@{$types}; $i++) {
4588: if (defined($usertypes->{$types->[$i]})) {
4589: my $rem = $i%($numinrow);
4590: if ($rem == 0) {
4591: if ($i > 0) {
4592: $output .= '</tr>';
4593: }
4594: $output .= '<tr>';
1.23 raeburn 4595: }
1.26 raeburn 4596: my $check = ' ';
1.99 raeburn 4597: if (ref($settings) eq 'HASH') {
4598: if (ref($settings->{$context}) eq 'ARRAY') {
4599: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4600: $check = ' checked="checked" ';
4601: }
4602: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4603: $check = ' checked="checked" ';
4604: }
1.23 raeburn 4605: }
1.26 raeburn 4606: $output .= '<td class="LC_left_item">'.
4607: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4608: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4609: 'value="'.$types->[$i].'"'.$check.'/>'.
4610: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4611: }
4612: }
1.26 raeburn 4613: $rem = @{$types}%($numinrow);
1.23 raeburn 4614: }
4615: my $colsleft = $numinrow - $rem;
1.131 raeburn 4616: if (($rem == 0) && (@{$types} > 0)) {
4617: $output .= '<tr>';
4618: }
1.23 raeburn 4619: if ($colsleft > 1) {
1.25 raeburn 4620: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4621: } else {
1.25 raeburn 4622: $output .= '<td class="LC_left_item">';
1.23 raeburn 4623: }
4624: my $defcheck = ' ';
1.99 raeburn 4625: if (ref($settings) eq 'HASH') {
4626: if (ref($settings->{$context}) eq 'ARRAY') {
4627: if (grep(/^default$/,@{$settings->{$context}})) {
4628: $defcheck = ' checked="checked" ';
4629: }
4630: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4631: $defcheck = ' checked="checked" ';
4632: }
1.23 raeburn 4633: }
1.25 raeburn 4634: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4635: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4636: 'value="default"'.$defcheck.'/>'.
4637: $othertitle.'</label></span></td>'.
4638: '</tr></table></td></tr>';
4639: return $output;
1.23 raeburn 4640: }
4641:
4642: sub sorted_searchtitles {
4643: my %searchtitles = &Apache::lonlocal::texthash(
4644: 'uname' => 'username',
4645: 'lastname' => 'last name',
4646: 'lastfirst' => 'last name, first name',
4647: );
4648: my @titleorder = ('uname','lastname','lastfirst');
4649: return (\%searchtitles,\@titleorder);
4650: }
4651:
1.25 raeburn 4652: sub sorted_searchtypes {
4653: my %srchtypes_desc = (
4654: exact => 'is exact match',
4655: contains => 'contains ..',
4656: begins => 'begins with ..',
4657: );
4658: my @srchtypeorder = ('exact','begins','contains');
4659: return (\%srchtypes_desc,\@srchtypeorder);
4660: }
4661:
1.3 raeburn 4662: sub usertype_update_row {
4663: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4664: my $datatable;
4665: my $numinrow = 4;
4666: foreach my $type (@{$types}) {
4667: if (defined($usertypes->{$type})) {
4668: $$rownums ++;
4669: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4670: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4671: '</td><td class="LC_left_item"><table>';
4672: for (my $i=0; $i<@{$fields}; $i++) {
4673: my $rem = $i%($numinrow);
4674: if ($rem == 0) {
4675: if ($i > 0) {
4676: $datatable .= '</tr>';
4677: }
4678: $datatable .= '<tr>';
4679: }
4680: my $check = ' ';
1.39 raeburn 4681: if (ref($settings) eq 'HASH') {
4682: if (ref($settings->{'fields'}) eq 'HASH') {
4683: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4684: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4685: $check = ' checked="checked" ';
4686: }
1.3 raeburn 4687: }
4688: }
4689: }
4690:
4691: if ($i == @{$fields}-1) {
4692: my $colsleft = $numinrow - $rem;
4693: if ($colsleft > 1) {
4694: $datatable .= '<td colspan="'.$colsleft.'">';
4695: } else {
4696: $datatable .= '<td>';
4697: }
4698: } else {
4699: $datatable .= '<td>';
4700: }
1.8 raeburn 4701: $datatable .= '<span class="LC_nobreak"><label>'.
4702: '<input type="checkbox" name="updateable_'.$type.
4703: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4704: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4705: }
4706: $datatable .= '</tr></table></td></tr>';
4707: }
4708: }
4709: return $datatable;
1.1 raeburn 4710: }
4711:
4712: sub modify_login {
1.9 raeburn 4713: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4714: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4715: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4716: %title = ( coursecatalog => 'Display course catalog',
4717: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 4718: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4719: newuser => 'Link for visitors to create a user account',
4720: loginheader => 'Log-in box header');
4721: @offon = ('off','on');
1.112 raeburn 4722: if (ref($domconfig{login}) eq 'HASH') {
4723: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4724: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4725: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4726: }
4727: }
4728: }
1.9 raeburn 4729: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4730: \%domconfig,\%loginhash);
1.160.6.14 raeburn 4731: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4732: foreach my $item (@toggles) {
4733: $loginhash{login}{$item} = $env{'form.'.$item};
4734: }
1.41 raeburn 4735: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4736: if (ref($colchanges{'login'}) eq 'HASH') {
4737: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4738: \%loginhash);
4739: }
1.110 raeburn 4740:
1.149 raeburn 4741: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4742: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4743: if (keys(%servers) > 1) {
4744: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4745: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4746: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4747: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4748: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4749: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4750: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4751: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4752: $changes{'loginvia'}{$lonhost} = 1;
4753: } else {
4754: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4755: $changes{'loginvia'}{$lonhost} = 1;
4756: }
4757: } else {
4758: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4759: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4760: $changes{'loginvia'}{$lonhost} = 1;
4761: }
4762: }
4763: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4764: foreach my $item (@loginvia_attribs) {
4765: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4766: }
4767: } else {
4768: foreach my $item (@loginvia_attribs) {
4769: my $new = $env{'form.'.$lonhost.'_'.$item};
4770: if (($item eq 'serverpath') && ($new eq 'custom')) {
4771: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4772: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4773: $new = '/';
4774: }
4775: }
4776: if (($item eq 'custompath') &&
4777: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4778: $new = '';
4779: }
4780: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4781: $changes{'loginvia'}{$lonhost} = 1;
4782: }
4783: if ($item eq 'exempt') {
4784: $new =~ s/^\s+//;
4785: $new =~ s/\s+$//;
4786: my @poss_ips = split(/\s*[,:]\s*/,$new);
4787: my @okips;
4788: foreach my $ip (@poss_ips) {
4789: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4790: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4791: push(@okips,$ip);
4792: }
4793: }
4794: }
4795: if (@okips > 0) {
4796: $new = join(',',@okips);
4797: } else {
4798: $new = '';
4799: }
4800: }
4801: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4802: }
4803: }
1.112 raeburn 4804: } else {
1.128 raeburn 4805: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4806: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4807: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4808: foreach my $item (@loginvia_attribs) {
4809: my $new = $env{'form.'.$lonhost.'_'.$item};
4810: if (($item eq 'serverpath') && ($new eq 'custom')) {
4811: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4812: $new = '/';
4813: }
4814: }
4815: if (($item eq 'custompath') &&
4816: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4817: $new = '';
4818: }
4819: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4820: }
1.110 raeburn 4821: }
4822: }
4823: }
4824: }
1.119 raeburn 4825:
1.160.6.5 raeburn 4826: my $servadm = $r->dir_config('lonAdmEMail');
4827: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4828: if (ref($domconfig{'login'}) eq 'HASH') {
4829: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4830: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4831: if ($lang eq 'nolang') {
4832: push(@currlangs,$lang);
4833: } elsif (defined($langchoices{$lang})) {
4834: push(@currlangs,$lang);
4835: } else {
4836: next;
4837: }
4838: }
4839: }
4840: }
4841: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4842: if (@currlangs > 0) {
4843: foreach my $lang (@currlangs) {
4844: if (grep(/^\Q$lang\E$/,@delurls)) {
4845: $changes{'helpurl'}{$lang} = 1;
4846: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4847: $changes{'helpurl'}{$lang} = 1;
4848: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4849: push(@newlangs,$lang);
4850: } else {
4851: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4852: }
4853: }
4854: }
4855: unless (grep(/^nolang$/,@currlangs)) {
4856: if ($env{'form.loginhelpurl_nolang.filename'}) {
4857: $changes{'helpurl'}{'nolang'} = 1;
4858: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4859: push(@newlangs,'nolang');
4860: }
4861: }
4862: if ($env{'form.loginhelpurl_add_lang'}) {
4863: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4864: ($env{'form.loginhelpurl_add_file.filename'})) {
4865: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4866: $addedfile = $env{'form.loginhelpurl_add_lang'};
4867: }
4868: }
4869: if ((@newlangs > 0) || ($addedfile)) {
4870: my $error;
4871: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4872: if ($configuserok eq 'ok') {
4873: if ($switchserver) {
4874: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4875: } elsif ($author_ok eq 'ok') {
4876: my @allnew = @newlangs;
4877: if ($addedfile ne '') {
4878: push(@allnew,$addedfile);
4879: }
4880: foreach my $lang (@allnew) {
4881: my $formelem = 'loginhelpurl_'.$lang;
4882: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4883: $formelem = 'loginhelpurl_add_file';
4884: }
4885: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4886: "help/$lang",'','',$newfile{$lang});
4887: if ($result eq 'ok') {
4888: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4889: $changes{'helpurl'}{$lang} = 1;
4890: } else {
4891: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4892: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4893: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4894: (!grep(/^\Q$lang\E$/,@delurls))) {
4895:
4896: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4897: }
4898: }
4899: }
4900: } else {
4901: $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);
4902: }
4903: } else {
4904: $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);
4905: }
4906: if ($error) {
4907: &Apache::lonnet::logthis($error);
4908: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4909: }
4910: }
4911: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4912:
4913: my $defaulthelpfile = '/adm/loginproblems.html';
4914: my $defaulttext = &mt('Default in use');
4915:
1.1 raeburn 4916: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4917: $dom);
4918: if ($putresult eq 'ok') {
1.160.6.14 raeburn 4919: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4920: my %defaultchecked = (
4921: 'coursecatalog' => 'on',
1.160.6.14 raeburn 4922: 'helpdesk' => 'on',
1.42 raeburn 4923: 'adminmail' => 'off',
1.43 raeburn 4924: 'newuser' => 'off',
1.42 raeburn 4925: );
1.55 raeburn 4926: if (ref($domconfig{'login'}) eq 'HASH') {
4927: foreach my $item (@toggles) {
4928: if ($defaultchecked{$item} eq 'on') {
4929: if (($domconfig{'login'}{$item} eq '0') &&
4930: ($env{'form.'.$item} eq '1')) {
4931: $changes{$item} = 1;
4932: } elsif (($domconfig{'login'}{$item} eq '' ||
4933: $domconfig{'login'}{$item} eq '1') &&
4934: ($env{'form.'.$item} eq '0')) {
4935: $changes{$item} = 1;
4936: }
4937: } elsif ($defaultchecked{$item} eq 'off') {
4938: if (($domconfig{'login'}{$item} eq '1') &&
4939: ($env{'form.'.$item} eq '0')) {
4940: $changes{$item} = 1;
4941: } elsif (($domconfig{'login'}{$item} eq '' ||
4942: $domconfig{'login'}{$item} eq '0') &&
4943: ($env{'form.'.$item} eq '1')) {
4944: $changes{$item} = 1;
4945: }
1.42 raeburn 4946: }
4947: }
1.41 raeburn 4948: }
1.6 raeburn 4949: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4950: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4951: $resulttext = &mt('Changes made:').'<ul>';
4952: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4953: if ($item eq 'loginvia') {
1.112 raeburn 4954: if (ref($changes{$item}) eq 'HASH') {
4955: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4956: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4957: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4958: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4959: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4960: $protocol = 'http' if ($protocol ne 'https');
4961: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4962:
4963: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4964: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4965: } else {
4966: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4967: }
4968: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4969: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4970: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4971: }
4972: $resulttext .= '</li>';
4973: } else {
4974: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4975: }
1.112 raeburn 4976: } else {
1.128 raeburn 4977: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4978: }
4979: }
1.128 raeburn 4980: $resulttext .= '</ul></li>';
1.112 raeburn 4981: }
1.160.6.5 raeburn 4982: } elsif ($item eq 'helpurl') {
4983: if (ref($changes{$item}) eq 'HASH') {
4984: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4985: if (grep(/^\Q$lang\E$/,@delurls)) {
4986: my ($chg,$link);
4987: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4988: if ($lang eq 'nolang') {
4989: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4990: } else {
4991: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4992: }
4993: $resulttext .= '<li>'.$chg.'</li>';
4994: } else {
4995: my $chg;
4996: if ($lang eq 'nolang') {
4997: $chg = &mt('custom log-in help file for no preferred language');
4998: } else {
4999: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5000: }
5001: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5002: $loginhash{'login'}{'helpurl'}{$lang}.
5003: '?inhibitmenu=yes',$chg,600,500).
5004: '</li>';
5005: }
5006: }
5007: }
5008: } elsif ($item eq 'captcha') {
5009: if (ref($loginhash{'login'}) eq 'HASH') {
5010: my $chgtxt;
5011: if ($loginhash{'login'}{$item} eq 'notused') {
5012: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5013: } else {
5014: my %captchas = &captcha_phrases();
5015: if ($captchas{$loginhash{'login'}{$item}}) {
5016: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5017: } else {
5018: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5019: }
5020: }
5021: $resulttext .= '<li>'.$chgtxt.'</li>';
5022: }
5023: } elsif ($item eq 'recaptchakeys') {
5024: if (ref($loginhash{'login'}) eq 'HASH') {
5025: my ($privkey,$pubkey);
5026: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5027: $pubkey = $loginhash{'login'}{$item}{'public'};
5028: $privkey = $loginhash{'login'}{$item}{'private'};
5029: }
5030: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5031: if (!$pubkey) {
5032: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5033: } else {
5034: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5035: }
5036: if (!$privkey) {
5037: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5038: } else {
5039: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5040: }
5041: $chgtxt .= '</ul>';
5042: $resulttext .= '<li>'.$chgtxt.'</li>';
5043: }
1.41 raeburn 5044: } else {
5045: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5046: }
1.1 raeburn 5047: }
1.6 raeburn 5048: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5049: } else {
5050: $resulttext = &mt('No changes made to log-in page settings');
5051: }
5052: } else {
1.11 albertel 5053: $resulttext = '<span class="LC_error">'.
5054: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5055: }
1.6 raeburn 5056: if ($errors) {
1.9 raeburn 5057: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5058: $errors.'</ul>';
5059: }
5060: return $resulttext;
5061: }
5062:
5063: sub color_font_choices {
5064: my %choices =
5065: &Apache::lonlocal::texthash (
5066: img => "Header",
5067: bgs => "Background colors",
5068: links => "Link colors",
1.55 raeburn 5069: images => "Images",
1.6 raeburn 5070: font => "Font color",
1.160.6.22 raeburn 5071: fontmenu => "Font menu",
1.76 raeburn 5072: pgbg => "Page",
1.6 raeburn 5073: tabbg => "Header",
5074: sidebg => "Border",
5075: link => "Link",
5076: alink => "Active link",
5077: vlink => "Visited link",
5078: );
5079: return %choices;
5080: }
5081:
5082: sub modify_rolecolors {
1.9 raeburn 5083: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5084: my ($resulttext,%rolehash);
5085: $rolehash{'rolecolors'} = {};
1.55 raeburn 5086: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5087: if ($domconfig{'rolecolors'} eq '') {
5088: $domconfig{'rolecolors'} = {};
5089: }
5090: }
1.9 raeburn 5091: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5092: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5093: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5094: $dom);
5095: if ($putresult eq 'ok') {
5096: if (keys(%changes) > 0) {
1.41 raeburn 5097: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5098: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5099: $rolehash{'rolecolors'});
5100: } else {
5101: $resulttext = &mt('No changes made to default color schemes');
5102: }
5103: } else {
1.11 albertel 5104: $resulttext = '<span class="LC_error">'.
5105: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5106: }
5107: if ($errors) {
5108: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5109: $errors.'</ul>';
5110: }
5111: return $resulttext;
5112: }
5113:
5114: sub modify_colors {
1.9 raeburn 5115: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5116: my (%changes,%choices);
1.51 raeburn 5117: my @bgs;
1.6 raeburn 5118: my @links = ('link','alink','vlink');
1.41 raeburn 5119: my @logintext;
1.6 raeburn 5120: my @images;
5121: my $servadm = $r->dir_config('lonAdmEMail');
5122: my $errors;
1.160.6.22 raeburn 5123: my %defaults;
1.6 raeburn 5124: foreach my $role (@{$roles}) {
5125: if ($role eq 'login') {
1.12 raeburn 5126: %choices = &login_choices();
1.41 raeburn 5127: @logintext = ('textcol','bgcol');
1.12 raeburn 5128: } else {
5129: %choices = &color_font_choices();
5130: }
5131: if ($role eq 'login') {
1.41 raeburn 5132: @images = ('img','logo','domlogo','login');
1.51 raeburn 5133: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5134: } else {
5135: @images = ('img');
1.160.6.22 raeburn 5136: @bgs = ('pgbg','tabbg','sidebg');
5137: }
5138: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5139: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5140: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5141: }
5142: if ($role eq 'login') {
5143: foreach my $item (@logintext) {
5144: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5145: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5146: }
5147: }
5148: } else {
5149: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5150: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5151: }
1.6 raeburn 5152: }
1.160.6.22 raeburn 5153: foreach my $item (@bgs) {
5154: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5155: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5156: }
5157: }
5158: foreach my $item (@links) {
5159: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5160: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5161: }
1.6 raeburn 5162: }
1.46 raeburn 5163: my ($configuserok,$author_ok,$switchserver) =
5164: &config_check($dom,$confname,$servadm);
1.9 raeburn 5165: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5166: if (ref($domconfig->{$role}) ne 'HASH') {
5167: $domconfig->{$role} = {};
5168: }
1.8 raeburn 5169: foreach my $img (@images) {
1.70 raeburn 5170: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5171: if (defined($env{'form.login_showlogo_'.$img})) {
5172: $confhash->{$role}{'showlogo'}{$img} = 1;
5173: } else {
5174: $confhash->{$role}{'showlogo'}{$img} = 0;
5175: }
5176: }
1.18 albertel 5177: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5178: && !defined($domconfig->{$role}{$img})
5179: && !$env{'form.'.$role.'_del_'.$img}
5180: && $env{'form.'.$role.'_import_'.$img}) {
5181: # import the old configured image from the .tab setting
5182: # if they haven't provided a new one
5183: $domconfig->{$role}{$img} =
5184: $env{'form.'.$role.'_import_'.$img};
5185: }
1.6 raeburn 5186: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5187: my $error;
1.6 raeburn 5188: if ($configuserok eq 'ok') {
1.9 raeburn 5189: if ($switchserver) {
1.12 raeburn 5190: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5191: } else {
5192: if ($author_ok eq 'ok') {
5193: my ($result,$logourl) =
5194: &publishlogo($r,'upload',$role.'_'.$img,
5195: $dom,$confname,$img,$width,$height);
5196: if ($result eq 'ok') {
5197: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5198: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5199: } else {
1.12 raeburn 5200: $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);
1.9 raeburn 5201: }
5202: } else {
1.46 raeburn 5203: $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);
1.6 raeburn 5204: }
5205: }
5206: } else {
1.46 raeburn 5207: $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);
1.9 raeburn 5208: }
5209: if ($error) {
1.8 raeburn 5210: &Apache::lonnet::logthis($error);
1.11 albertel 5211: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5212: }
5213: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5214: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5215: my $error;
5216: if ($configuserok eq 'ok') {
5217: # is confname an author?
5218: if ($switchserver eq '') {
5219: if ($author_ok eq 'ok') {
5220: my ($result,$logourl) =
5221: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5222: $dom,$confname,$img,$width,$height);
5223: if ($result eq 'ok') {
5224: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5225: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5226: }
5227: }
5228: }
5229: }
1.6 raeburn 5230: }
5231: }
5232: }
5233: if (ref($domconfig) eq 'HASH') {
5234: if (ref($domconfig->{$role}) eq 'HASH') {
5235: foreach my $img (@images) {
5236: if ($domconfig->{$role}{$img} ne '') {
5237: if ($env{'form.'.$role.'_del_'.$img}) {
5238: $confhash->{$role}{$img} = '';
1.12 raeburn 5239: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5240: } else {
1.9 raeburn 5241: if ($confhash->{$role}{$img} eq '') {
5242: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5243: }
1.6 raeburn 5244: }
5245: } else {
5246: if ($env{'form.'.$role.'_del_'.$img}) {
5247: $confhash->{$role}{$img} = '';
1.12 raeburn 5248: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5249: }
5250: }
1.70 raeburn 5251: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5252: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5253: if ($confhash->{$role}{'showlogo'}{$img} ne
5254: $domconfig->{$role}{'showlogo'}{$img}) {
5255: $changes{$role}{'showlogo'}{$img} = 1;
5256: }
5257: } else {
5258: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5259: $changes{$role}{'showlogo'}{$img} = 1;
5260: }
5261: }
5262: }
5263: }
1.6 raeburn 5264: if ($domconfig->{$role}{'font'} ne '') {
5265: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5266: $changes{$role}{'font'} = 1;
5267: }
5268: } else {
5269: if ($confhash->{$role}{'font'}) {
5270: $changes{$role}{'font'} = 1;
5271: }
5272: }
1.107 raeburn 5273: if ($role ne 'login') {
5274: if ($domconfig->{$role}{'fontmenu'} ne '') {
5275: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5276: $changes{$role}{'fontmenu'} = 1;
5277: }
5278: } else {
5279: if ($confhash->{$role}{'fontmenu'}) {
5280: $changes{$role}{'fontmenu'} = 1;
5281: }
1.97 tempelho 5282: }
5283: }
1.6 raeburn 5284: foreach my $item (@bgs) {
5285: if ($domconfig->{$role}{$item} ne '') {
5286: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5287: $changes{$role}{'bgs'}{$item} = 1;
5288: }
5289: } else {
5290: if ($confhash->{$role}{$item}) {
5291: $changes{$role}{'bgs'}{$item} = 1;
5292: }
5293: }
5294: }
5295: foreach my $item (@links) {
5296: if ($domconfig->{$role}{$item} ne '') {
5297: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5298: $changes{$role}{'links'}{$item} = 1;
5299: }
5300: } else {
5301: if ($confhash->{$role}{$item}) {
5302: $changes{$role}{'links'}{$item} = 1;
5303: }
5304: }
5305: }
1.41 raeburn 5306: foreach my $item (@logintext) {
5307: if ($domconfig->{$role}{$item} ne '') {
5308: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5309: $changes{$role}{'logintext'}{$item} = 1;
5310: }
5311: } else {
5312: if ($confhash->{$role}{$item}) {
5313: $changes{$role}{'logintext'}{$item} = 1;
5314: }
5315: }
5316: }
1.6 raeburn 5317: } else {
5318: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5319: \@logintext,$confhash,\%changes);
1.6 raeburn 5320: }
5321: } else {
5322: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5323: \@logintext,$confhash,\%changes);
1.6 raeburn 5324: }
5325: }
5326: return ($errors,%changes);
5327: }
5328:
1.46 raeburn 5329: sub config_check {
5330: my ($dom,$confname,$servadm) = @_;
5331: my ($configuserok,$author_ok,$switchserver,%currroles);
5332: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5333: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5334: $confname,$servadm);
5335: if ($configuserok eq 'ok') {
5336: $switchserver = &check_switchserver($dom,$confname);
5337: if ($switchserver eq '') {
5338: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5339: }
5340: }
5341: return ($configuserok,$author_ok,$switchserver);
5342: }
5343:
1.6 raeburn 5344: sub default_change_checker {
1.41 raeburn 5345: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5346: foreach my $item (@{$links}) {
5347: if ($confhash->{$role}{$item}) {
5348: $changes->{$role}{'links'}{$item} = 1;
5349: }
5350: }
5351: foreach my $item (@{$bgs}) {
5352: if ($confhash->{$role}{$item}) {
5353: $changes->{$role}{'bgs'}{$item} = 1;
5354: }
5355: }
1.41 raeburn 5356: foreach my $item (@{$logintext}) {
5357: if ($confhash->{$role}{$item}) {
5358: $changes->{$role}{'logintext'}{$item} = 1;
5359: }
5360: }
1.6 raeburn 5361: foreach my $img (@{$images}) {
5362: if ($env{'form.'.$role.'_del_'.$img}) {
5363: $confhash->{$role}{$img} = '';
1.12 raeburn 5364: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5365: }
1.70 raeburn 5366: if ($role eq 'login') {
5367: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5368: $changes->{$role}{'showlogo'}{$img} = 1;
5369: }
5370: }
1.6 raeburn 5371: }
5372: if ($confhash->{$role}{'font'}) {
5373: $changes->{$role}{'font'} = 1;
5374: }
1.48 raeburn 5375: }
1.6 raeburn 5376:
5377: sub display_colorchgs {
5378: my ($dom,$changes,$roles,$confhash) = @_;
5379: my (%choices,$resulttext);
5380: if (!grep(/^login$/,@{$roles})) {
5381: $resulttext = &mt('Changes made:').'<br />';
5382: }
5383: foreach my $role (@{$roles}) {
5384: if ($role eq 'login') {
5385: %choices = &login_choices();
5386: } else {
5387: %choices = &color_font_choices();
5388: }
5389: if (ref($changes->{$role}) eq 'HASH') {
5390: if ($role ne 'login') {
5391: $resulttext .= '<h4>'.&mt($role).'</h4>';
5392: }
5393: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5394: if ($role ne 'login') {
5395: $resulttext .= '<ul>';
5396: }
5397: if (ref($changes->{$role}{$key}) eq 'HASH') {
5398: if ($role ne 'login') {
5399: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5400: }
5401: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5402: if (($role eq 'login') && ($key eq 'showlogo')) {
5403: if ($confhash->{$role}{$key}{$item}) {
5404: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5405: } else {
5406: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5407: }
5408: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5409: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5410: } else {
1.12 raeburn 5411: my $newitem = $confhash->{$role}{$item};
5412: if ($key eq 'images') {
5413: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5414: }
5415: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5416: }
5417: }
5418: if ($role ne 'login') {
5419: $resulttext .= '</ul></li>';
5420: }
5421: } else {
5422: if ($confhash->{$role}{$key} eq '') {
5423: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5424: } else {
5425: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5426: }
5427: }
5428: if ($role ne 'login') {
5429: $resulttext .= '</ul>';
5430: }
5431: }
5432: }
5433: }
1.3 raeburn 5434: return $resulttext;
1.1 raeburn 5435: }
5436:
1.9 raeburn 5437: sub thumb_dimensions {
5438: return ('200','50');
5439: }
5440:
1.16 raeburn 5441: sub check_dimensions {
5442: my ($inputfile) = @_;
5443: my ($fullwidth,$fullheight);
5444: if ($inputfile =~ m|^[/\w.\-]+$|) {
5445: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5446: my $imageinfo = <PIPE>;
5447: if (!close(PIPE)) {
5448: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5449: }
5450: chomp($imageinfo);
5451: my ($fullsize) =
1.21 raeburn 5452: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5453: if ($fullsize) {
5454: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5455: }
5456: }
5457: }
5458: return ($fullwidth,$fullheight);
5459: }
5460:
1.9 raeburn 5461: sub check_configuser {
5462: my ($uhome,$dom,$confname,$servadm) = @_;
5463: my ($configuserok,%currroles);
5464: if ($uhome eq 'no_host') {
5465: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5466: my $configpass = &LONCAPA::Enrollment::create_password();
5467: $configuserok =
5468: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5469: $configpass,'','','','','',undef,$servadm);
5470: } else {
5471: $configuserok = 'ok';
5472: %currroles =
5473: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5474: }
5475: return ($configuserok,%currroles);
5476: }
5477:
5478: sub check_authorstatus {
5479: my ($dom,$confname,%currroles) = @_;
5480: my $author_ok;
1.40 raeburn 5481: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5482: my $start = time;
5483: my $end = 0;
5484: $author_ok =
5485: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5486: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5487: } else {
5488: $author_ok = 'ok';
5489: }
5490: return $author_ok;
5491: }
5492:
5493: sub publishlogo {
1.46 raeburn 5494: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5495: my ($output,$fname,$logourl);
5496: if ($action eq 'upload') {
5497: $fname=$env{'form.'.$formname.'.filename'};
5498: chop($env{'form.'.$formname});
5499: } else {
5500: ($fname) = ($formname =~ /([^\/]+)$/);
5501: }
1.46 raeburn 5502: if ($savefileas ne '') {
5503: $fname = $savefileas;
5504: }
1.9 raeburn 5505: $fname=&Apache::lonnet::clean_filename($fname);
5506: # See if there is anything left
5507: unless ($fname) { return ('error: no uploaded file'); }
5508: $fname="$subdir/$fname";
1.160.6.5 raeburn 5509: my $docroot=$r->dir_config('lonDocRoot');
5510: my $filepath="$docroot/priv";
5511: my $relpath = "$dom/$confname";
1.9 raeburn 5512: my ($fnamepath,$file,$fetchthumb);
5513: $file=$fname;
5514: if ($fname=~m|/|) {
5515: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5516: }
1.160.6.5 raeburn 5517: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5518: my $count;
1.160.6.5 raeburn 5519: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5520: $filepath.="/$parts[$count]";
5521: if ((-e $filepath)!=1) {
5522: mkdir($filepath,02770);
5523: }
5524: }
5525: # Check for bad extension and disallow upload
5526: if ($file=~/\.(\w+)$/ &&
5527: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5528: $output =
5529: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5530: } elsif ($file=~/\.(\w+)$/ &&
5531: !defined(&Apache::loncommon::fileembstyle($1))) {
5532: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5533: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 5534: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 5535: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 5536: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5537: } else {
5538: my $source = $filepath.'/'.$file;
5539: my $logfile;
5540: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 5541: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5542: }
5543: print $logfile
5544: "\n================= Publish ".localtime()." ================\n".
5545: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5546: # Save the file
5547: if (!open(FH,'>'.$source)) {
5548: &Apache::lonnet::logthis('Failed to create '.$source);
5549: return (&mt('Failed to create file'));
5550: }
5551: if ($action eq 'upload') {
5552: if (!print FH ($env{'form.'.$formname})) {
5553: &Apache::lonnet::logthis('Failed to write to '.$source);
5554: return (&mt('Failed to write file'));
5555: }
5556: } else {
5557: my $original = &Apache::lonnet::filelocation('',$formname);
5558: if(!copy($original,$source)) {
5559: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5560: return (&mt('Failed to write file'));
5561: }
5562: }
5563: close(FH);
5564: chmod(0660, $source); # Permissions to rw-rw---.
5565:
5566: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5567: my $copyfile=$targetdir.'/'.$file;
5568:
5569: my @parts=split(/\//,$targetdir);
5570: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5571: for (my $count=5;$count<=$#parts;$count++) {
5572: $path.="/$parts[$count]";
5573: if (!-e $path) {
5574: print $logfile "\nCreating directory ".$path;
5575: mkdir($path,02770);
5576: }
5577: }
5578: my $versionresult;
5579: if (-e $copyfile) {
5580: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5581: } else {
5582: $versionresult = 'ok';
5583: }
5584: if ($versionresult eq 'ok') {
5585: if (copy($source,$copyfile)) {
5586: print $logfile "\nCopied original source to ".$copyfile."\n";
5587: $output = 'ok';
5588: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5589: push(@{$modified_urls},[$copyfile,$source]);
5590: my $metaoutput =
5591: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5592: unless ($registered_cleanup) {
5593: my $handlers = $r->get_handlers('PerlCleanupHandler');
5594: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5595: $registered_cleanup=1;
5596: }
1.9 raeburn 5597: } else {
5598: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5599: $output = &mt('Failed to copy file to RES space').", $!";
5600: }
5601: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5602: my $inputfile = $filepath.'/'.$file;
5603: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5604: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5605: if ($fullwidth ne '' && $fullheight ne '') {
5606: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5607: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5608: system("convert -sample $thumbsize $inputfile $outfile");
5609: chmod(0660, $filepath.'/tn-'.$file);
5610: if (-e $outfile) {
5611: my $copyfile=$targetdir.'/tn-'.$file;
5612: if (copy($outfile,$copyfile)) {
5613: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5614: my $thumb_metaoutput =
5615: &write_metadata($dom,$confname,$formname,
5616: $targetdir,'tn-'.$file,$logfile);
5617: push(@{$modified_urls},[$copyfile,$outfile]);
5618: unless ($registered_cleanup) {
5619: my $handlers = $r->get_handlers('PerlCleanupHandler');
5620: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5621: $registered_cleanup=1;
5622: }
1.16 raeburn 5623: } else {
5624: print $logfile "\nUnable to write ".$copyfile.
5625: ':'.$!."\n";
5626: }
5627: }
1.9 raeburn 5628: }
5629: }
5630: }
5631: } else {
5632: $output = $versionresult;
5633: }
5634: }
5635: return ($output,$logourl);
5636: }
5637:
5638: sub logo_versioning {
5639: my ($targetdir,$file,$logfile) = @_;
5640: my $target = $targetdir.'/'.$file;
5641: my ($maxversion,$fn,$extn,$output);
5642: $maxversion = 0;
5643: if ($file =~ /^(.+)\.(\w+)$/) {
5644: $fn=$1;
5645: $extn=$2;
5646: }
5647: opendir(DIR,$targetdir);
5648: while (my $filename=readdir(DIR)) {
5649: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5650: $maxversion=($1>$maxversion)?$1:$maxversion;
5651: }
5652: }
5653: $maxversion++;
5654: print $logfile "\nCreating old version ".$maxversion."\n";
5655: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5656: if (copy($target,$copyfile)) {
5657: print $logfile "Copied old target to ".$copyfile."\n";
5658: $copyfile=$copyfile.'.meta';
5659: if (copy($target.'.meta',$copyfile)) {
5660: print $logfile "Copied old target metadata to ".$copyfile."\n";
5661: $output = 'ok';
5662: } else {
5663: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5664: $output = &mt('Failed to copy old meta').", $!, ";
5665: }
5666: } else {
5667: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5668: $output = &mt('Failed to copy old target').", $!, ";
5669: }
5670: return $output;
5671: }
5672:
5673: sub write_metadata {
5674: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5675: my (%metadatafields,%metadatakeys,$output);
5676: $metadatafields{'title'}=$formname;
5677: $metadatafields{'creationdate'}=time;
5678: $metadatafields{'lastrevisiondate'}=time;
5679: $metadatafields{'copyright'}='public';
5680: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5681: $env{'user.domain'};
5682: $metadatafields{'authorspace'}=$confname.':'.$dom;
5683: $metadatafields{'domain'}=$dom;
5684: {
5685: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5686: my $mfh;
1.155 raeburn 5687: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5688: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5689: unless ($_=~/\./) {
5690: my $unikey=$_;
5691: $unikey=~/^([A-Za-z]+)/;
5692: my $tag=$1;
5693: $tag=~tr/A-Z/a-z/;
5694: print $mfh "\n\<$tag";
5695: foreach (split(/\,/,$metadatakeys{$unikey})) {
5696: my $value=$metadatafields{$unikey.'.'.$_};
5697: $value=~s/\"/\'\'/g;
5698: print $mfh ' '.$_.'="'.$value.'"';
5699: }
5700: print $mfh '>'.
5701: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5702: .'</'.$tag.'>';
5703: }
5704: }
5705: $output = 'ok';
5706: print $logfile "\nWrote metadata";
5707: close($mfh);
5708: } else {
5709: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5710: $output = &mt('Could not write metadata');
5711: }
5712: }
1.155 raeburn 5713: return $output;
5714: }
5715:
5716: sub notifysubscribed {
5717: foreach my $targetsource (@{$modified_urls}){
5718: next unless (ref($targetsource) eq 'ARRAY');
5719: my ($target,$source)=@{$targetsource};
5720: if ($source ne '') {
5721: if (open(my $logfh,'>>'.$source.'.log')) {
5722: print $logfh "\nCleanup phase: Notifications\n";
5723: my @subscribed=&subscribed_hosts($target);
5724: foreach my $subhost (@subscribed) {
5725: print $logfh "\nNotifying host ".$subhost.':';
5726: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5727: print $logfh $reply;
5728: }
5729: my @subscribedmeta=&subscribed_hosts("$target.meta");
5730: foreach my $subhost (@subscribedmeta) {
5731: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5732: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5733: $subhost);
5734: print $logfh $reply;
5735: }
5736: print $logfh "\n============ Done ============\n";
1.160 raeburn 5737: close($logfh);
1.155 raeburn 5738: }
5739: }
5740: }
5741: return OK;
5742: }
5743:
5744: sub subscribed_hosts {
5745: my ($target) = @_;
5746: my @subscribed;
5747: if (open(my $fh,"<$target.subscription")) {
5748: while (my $subline=<$fh>) {
5749: if ($subline =~ /^($match_lonid):/) {
5750: my $host = $1;
5751: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5752: unless (grep(/^\Q$host\E$/,@subscribed)) {
5753: push(@subscribed,$host);
5754: }
5755: }
5756: }
5757: }
5758: }
5759: return @subscribed;
1.9 raeburn 5760: }
5761:
5762: sub check_switchserver {
5763: my ($dom,$confname) = @_;
5764: my ($allowed,$switchserver);
5765: my $home = &Apache::lonnet::homeserver($confname,$dom);
5766: if ($home eq 'no_host') {
5767: $home = &Apache::lonnet::domain($dom,'primary');
5768: }
5769: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5770: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5771: if (!$allowed) {
1.160.6.11 raeburn 5772: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5773: }
5774: return $switchserver;
5775: }
5776:
1.1 raeburn 5777: sub modify_quotas {
1.86 raeburn 5778: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5779: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5780: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5781: if ($action eq 'quotas') {
5782: $context = 'tools';
5783: } else {
5784: $context = $action;
5785: }
5786: if ($context eq 'requestcourses') {
1.98 raeburn 5787: @usertools = ('official','unofficial','community');
1.106 raeburn 5788: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5789: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5790: %titles = &courserequest_titles();
5791: $toolregexp = join('|',@usertools);
5792: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5793: } elsif ($context eq 'requestauthor') {
5794: @usertools = ('author');
5795: %titles = &authorrequest_titles();
1.86 raeburn 5796: } else {
1.160.6.4 raeburn 5797: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5798: %titles = &tool_titles();
1.86 raeburn 5799: }
1.72 raeburn 5800: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5801: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5802: foreach my $key (keys(%env)) {
1.101 raeburn 5803: if ($context eq 'requestcourses') {
5804: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5805: my $item = $1;
5806: my $type = $2;
5807: if ($type =~ /^limit_(.+)/) {
5808: $limithash{$item}{$1} = $env{$key};
5809: } else {
5810: $confhash{$item}{$type} = $env{$key};
5811: }
5812: }
1.160.6.5 raeburn 5813: } elsif ($context eq 'requestauthor') {
5814: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5815: $confhash{$1} = $env{$key};
5816: }
1.101 raeburn 5817: } else {
1.86 raeburn 5818: if ($key =~ /^form\.quota_(.+)$/) {
5819: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 5820: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5821: $confhash{'authorquota'}{$1} = $env{$key};
5822: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5823: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5824: }
1.72 raeburn 5825: }
5826: }
1.160.6.5 raeburn 5827: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5828: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5829: @approvalnotify = sort(@approvalnotify);
5830: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5831: if (ref($domconfig{$action}) eq 'HASH') {
5832: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5833: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5834: $changes{'notify'}{'approval'} = 1;
5835: }
5836: } else {
1.144 raeburn 5837: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5838: $changes{'notify'}{'approval'} = 1;
5839: }
5840: }
5841: } else {
1.144 raeburn 5842: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5843: $changes{'notify'}{'approval'} = 1;
5844: }
5845: }
5846: } else {
1.86 raeburn 5847: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 5848: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5849: }
1.72 raeburn 5850: foreach my $item (@usertools) {
5851: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5852: my $unset;
1.101 raeburn 5853: if ($context eq 'requestcourses') {
1.104 raeburn 5854: $unset = '0';
5855: if ($type eq '_LC_adv') {
5856: $unset = '';
5857: }
1.101 raeburn 5858: if ($confhash{$item}{$type} eq 'autolimit') {
5859: $confhash{$item}{$type} .= '=';
5860: unless ($limithash{$item}{$type} =~ /\D/) {
5861: $confhash{$item}{$type} .= $limithash{$item}{$type};
5862: }
5863: }
1.160.6.5 raeburn 5864: } elsif ($context eq 'requestauthor') {
5865: $unset = '0';
5866: if ($type eq '_LC_adv') {
5867: $unset = '';
5868: }
1.72 raeburn 5869: } else {
1.101 raeburn 5870: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5871: $confhash{$item}{$type} = 1;
5872: } else {
5873: $confhash{$item}{$type} = 0;
5874: }
1.72 raeburn 5875: }
1.86 raeburn 5876: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5877: if ($action eq 'requestauthor') {
5878: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5879: $changes{$type} = 1;
5880: }
5881: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5882: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5883: $changes{$item}{$type} = 1;
5884: }
5885: } else {
5886: if ($context eq 'requestcourses') {
1.104 raeburn 5887: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5888: $changes{$item}{$type} = 1;
5889: }
5890: } else {
5891: if (!$confhash{$item}{$type}) {
5892: $changes{$item}{$type} = 1;
5893: }
5894: }
5895: }
5896: } else {
5897: if ($context eq 'requestcourses') {
1.104 raeburn 5898: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5899: $changes{$item}{$type} = 1;
5900: }
1.160.6.5 raeburn 5901: } elsif ($context eq 'requestauthor') {
5902: if ($confhash{$type} ne $unset) {
5903: $changes{$type} = 1;
5904: }
1.72 raeburn 5905: } else {
5906: if (!$confhash{$item}{$type}) {
5907: $changes{$item}{$type} = 1;
5908: }
5909: }
5910: }
1.1 raeburn 5911: }
5912: }
1.160.6.5 raeburn 5913: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5914: if (ref($domconfig{'quotas'}) eq 'HASH') {
5915: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5916: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5917: if (exists($confhash{'defaultquota'}{$key})) {
5918: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5919: $changes{'defaultquota'}{$key} = 1;
5920: }
5921: } else {
5922: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5923: }
5924: }
1.86 raeburn 5925: } else {
5926: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5927: if (exists($confhash{'defaultquota'}{$key})) {
5928: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5929: $changes{'defaultquota'}{$key} = 1;
5930: }
5931: } else {
5932: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5933: }
1.1 raeburn 5934: }
5935: }
1.160.6.20 raeburn 5936: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5937: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5938: if (exists($confhash{'authorquota'}{$key})) {
5939: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5940: $changes{'authorquota'}{$key} = 1;
5941: }
5942: } else {
5943: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5944: }
5945: }
5946: }
1.1 raeburn 5947: }
1.86 raeburn 5948: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5949: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5950: if (ref($domconfig{'quotas'}) eq 'HASH') {
5951: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5952: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5953: $changes{'defaultquota'}{$key} = 1;
5954: }
5955: } else {
5956: if (!exists($domconfig{'quotas'}{$key})) {
5957: $changes{'defaultquota'}{$key} = 1;
5958: }
1.72 raeburn 5959: }
5960: } else {
1.86 raeburn 5961: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5962: }
1.1 raeburn 5963: }
5964: }
1.160.6.20 raeburn 5965: if (ref($confhash{'authorquota'}) eq 'HASH') {
5966: foreach my $key (keys(%{$confhash{'authorquota'}})) {
5967: if (ref($domconfig{'quotas'}) eq 'HASH') {
5968: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5969: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
5970: $changes{'authorquota'}{$key} = 1;
5971: }
5972: } else {
5973: $changes{'authorquota'}{$key} = 1;
5974: }
5975: } else {
5976: $changes{'authorquota'}{$key} = 1;
5977: }
5978: }
5979: }
1.1 raeburn 5980: }
1.72 raeburn 5981:
1.160.6.5 raeburn 5982: if ($context eq 'requestauthor') {
5983: $domdefaults{'requestauthor'} = \%confhash;
5984: } else {
5985: foreach my $key (keys(%confhash)) {
5986: $domdefaults{$key} = $confhash{$key};
5987: }
1.72 raeburn 5988: }
1.160.6.5 raeburn 5989:
1.1 raeburn 5990: my %quotahash = (
1.86 raeburn 5991: $action => { %confhash }
1.1 raeburn 5992: );
5993: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5994: $dom);
5995: if ($putresult eq 'ok') {
5996: if (keys(%changes) > 0) {
1.72 raeburn 5997: my $cachetime = 24*60*60;
5998: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5999:
1.1 raeburn 6000: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 6001: unless (($context eq 'requestcourses') ||
6002: ($context eq 'requestauthor')) {
1.86 raeburn 6003: if (ref($changes{'defaultquota'}) eq 'HASH') {
6004: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6005: foreach my $type (@{$types},'default') {
6006: if (defined($changes{'defaultquota'}{$type})) {
6007: my $typetitle = $usertypes->{$type};
6008: if ($type eq 'default') {
6009: $typetitle = $othertitle;
6010: }
6011: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6012: }
6013: }
1.86 raeburn 6014: $resulttext .= '</ul></li>';
1.72 raeburn 6015: }
1.160.6.20 raeburn 6016: if (ref($changes{'authorquota'}) eq 'HASH') {
6017: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6018: foreach my $type (@{$types},'default') {
6019: if (defined($changes{'authorquota'}{$type})) {
6020: my $typetitle = $usertypes->{$type};
6021: if ($type eq 'default') {
6022: $typetitle = $othertitle;
6023: }
6024: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
6025: }
6026: }
6027: $resulttext .= '</ul></li>';
6028: }
1.72 raeburn 6029: }
1.80 raeburn 6030: my %newenv;
1.72 raeburn 6031: foreach my $item (@usertools) {
1.160.6.5 raeburn 6032: my (%haschgs,%inconf);
6033: if ($context eq 'requestauthor') {
6034: %haschgs = %changes;
6035: %inconf = %confhash;
6036: } else {
6037: if (ref($changes{$item}) eq 'HASH') {
6038: %haschgs = %{$changes{$item}};
6039: }
6040: if (ref($confhash{$item}) eq 'HASH') {
6041: %inconf = %{$confhash{$item}};
6042: }
6043: }
6044: if (keys(%haschgs) > 0) {
1.80 raeburn 6045: my $newacc =
6046: &Apache::lonnet::usertools_access($env{'user.name'},
6047: $env{'user.domain'},
1.86 raeburn 6048: $item,'reload',$context);
1.160.6.5 raeburn 6049: if (($context eq 'requestcourses') ||
6050: ($context eq 'requestauthor')) {
1.108 raeburn 6051: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6052: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6053: }
6054: } else {
6055: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6056: $newenv{'environment.availabletools.'.$item} = $newacc;
6057: }
1.80 raeburn 6058: }
1.160.6.5 raeburn 6059: unless ($context eq 'requestauthor') {
6060: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6061: }
1.72 raeburn 6062: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 6063: if ($haschgs{$type}) {
1.72 raeburn 6064: my $typetitle = $usertypes->{$type};
6065: if ($type eq 'default') {
6066: $typetitle = $othertitle;
6067: } elsif ($type eq '_LC_adv') {
6068: $typetitle = 'LON-CAPA Advanced Users';
6069: }
1.160.6.5 raeburn 6070: if ($inconf{$type}) {
1.101 raeburn 6071: if ($context eq 'requestcourses') {
6072: my $cond;
1.160.6.5 raeburn 6073: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6074: if ($1 eq '') {
6075: $cond = &mt('(Automatic processing of any request).');
6076: } else {
6077: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6078: }
6079: } else {
1.160.6.5 raeburn 6080: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6081: }
6082: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 6083: } elsif ($context eq 'requestauthor') {
6084: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6085: $titles{$inconf{$type}},$typetitle);
6086:
1.101 raeburn 6087: } else {
6088: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6089: }
1.72 raeburn 6090: } else {
1.104 raeburn 6091: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 6092: if ($inconf{$type} eq '0') {
1.104 raeburn 6093: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6094: } else {
6095: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6096: }
6097: } else {
6098: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6099: }
1.72 raeburn 6100: }
6101: }
1.26 raeburn 6102: }
1.160.6.5 raeburn 6103: unless ($context eq 'requestauthor') {
6104: $resulttext .= '</ul></li>';
6105: }
1.26 raeburn 6106: }
1.1 raeburn 6107: }
1.160.6.5 raeburn 6108: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6109: if (ref($changes{'notify'}) eq 'HASH') {
6110: if ($changes{'notify'}{'approval'}) {
6111: if (ref($confhash{'notify'}) eq 'HASH') {
6112: if ($confhash{'notify'}{'approval'}) {
6113: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6114: } else {
1.160.6.5 raeburn 6115: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6116: }
6117: }
6118: }
6119: }
6120: }
1.1 raeburn 6121: $resulttext .= '</ul>';
1.80 raeburn 6122: if (keys(%newenv)) {
6123: &Apache::lonnet::appenv(\%newenv);
6124: }
1.1 raeburn 6125: } else {
1.86 raeburn 6126: if ($context eq 'requestcourses') {
6127: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 6128: } elsif ($context eq 'requestauthor') {
6129: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6130: } else {
1.90 weissno 6131: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6132: }
1.1 raeburn 6133: }
6134: } else {
1.11 albertel 6135: $resulttext = '<span class="LC_error">'.
6136: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6137: }
1.3 raeburn 6138: return $resulttext;
1.1 raeburn 6139: }
6140:
1.3 raeburn 6141: sub modify_autoenroll {
6142: my ($dom,%domconfig) = @_;
1.1 raeburn 6143: my ($resulttext,%changes);
6144: my %currautoenroll;
6145: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6146: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6147: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6148: }
6149: }
6150: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6151: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6152: sender => 'Sender for notification messages',
6153: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6154: my @offon = ('off','on');
1.17 raeburn 6155: my $sender_uname = $env{'form.sender_uname'};
6156: my $sender_domain = $env{'form.sender_domain'};
6157: if ($sender_domain eq '') {
6158: $sender_uname = '';
6159: } elsif ($sender_uname eq '') {
6160: $sender_domain = '';
6161: }
1.129 raeburn 6162: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6163: my %autoenrollhash = (
1.129 raeburn 6164: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6165: 'sender_uname' => $sender_uname,
6166: 'sender_domain' => $sender_domain,
6167: 'co-owners' => $coowners,
1.1 raeburn 6168: }
6169: );
1.4 raeburn 6170: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6171: $dom);
1.1 raeburn 6172: if ($putresult eq 'ok') {
6173: if (exists($currautoenroll{'run'})) {
6174: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6175: $changes{'run'} = 1;
6176: }
6177: } elsif ($autorun) {
6178: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6179: $changes{'run'} = 1;
1.1 raeburn 6180: }
6181: }
1.17 raeburn 6182: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6183: $changes{'sender'} = 1;
6184: }
1.17 raeburn 6185: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6186: $changes{'sender'} = 1;
6187: }
1.129 raeburn 6188: if ($currautoenroll{'co-owners'} ne '') {
6189: if ($currautoenroll{'co-owners'} ne $coowners) {
6190: $changes{'coowners'} = 1;
6191: }
6192: } elsif ($coowners) {
6193: $changes{'coowners'} = 1;
6194: }
1.1 raeburn 6195: if (keys(%changes) > 0) {
6196: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6197: if ($changes{'run'}) {
1.1 raeburn 6198: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6199: }
6200: if ($changes{'sender'}) {
1.17 raeburn 6201: if ($sender_uname eq '' || $sender_domain eq '') {
6202: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6203: } else {
6204: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6205: }
1.1 raeburn 6206: }
1.129 raeburn 6207: if ($changes{'coowners'}) {
6208: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6209: &Apache::loncommon::devalidate_domconfig_cache($dom);
6210: }
1.1 raeburn 6211: $resulttext .= '</ul>';
6212: } else {
6213: $resulttext = &mt('No changes made to auto-enrollment settings');
6214: }
6215: } else {
1.11 albertel 6216: $resulttext = '<span class="LC_error">'.
6217: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6218: }
1.3 raeburn 6219: return $resulttext;
1.1 raeburn 6220: }
6221:
6222: sub modify_autoupdate {
1.3 raeburn 6223: my ($dom,%domconfig) = @_;
1.1 raeburn 6224: my ($resulttext,%currautoupdate,%fields,%changes);
6225: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6226: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6227: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6228: }
6229: }
6230: my @offon = ('off','on');
6231: my %title = &Apache::lonlocal::texthash (
6232: run => 'Auto-update:',
6233: classlists => 'Updates to user information in classlists?'
6234: );
1.44 raeburn 6235: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6236: my %fieldtitles = &Apache::lonlocal::texthash (
6237: id => 'Student/Employee ID',
1.20 raeburn 6238: permanentemail => 'E-mail address',
1.1 raeburn 6239: lastname => 'Last Name',
6240: firstname => 'First Name',
6241: middlename => 'Middle Name',
1.132 raeburn 6242: generation => 'Generation',
1.1 raeburn 6243: );
1.142 raeburn 6244: $othertitle = &mt('All users');
1.1 raeburn 6245: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6246: $othertitle = &mt('Other users');
1.1 raeburn 6247: }
6248: foreach my $key (keys(%env)) {
6249: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6250: my ($usertype,$item) = ($1,$2);
6251: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6252: if ($usertype eq 'default') {
6253: push(@{$fields{$1}},$2);
6254: } elsif (ref($types) eq 'ARRAY') {
6255: if (grep(/^\Q$usertype\E$/,@{$types})) {
6256: push(@{$fields{$1}},$2);
6257: }
6258: }
6259: }
1.1 raeburn 6260: }
6261: }
1.131 raeburn 6262: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6263: @lockablenames = sort(@lockablenames);
6264: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6265: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6266: if (@changed) {
6267: $changes{'lockablenames'} = 1;
6268: }
6269: } else {
6270: if (@lockablenames) {
6271: $changes{'lockablenames'} = 1;
6272: }
6273: }
1.1 raeburn 6274: my %updatehash = (
6275: autoupdate => { run => $env{'form.autoupdate_run'},
6276: classlists => $env{'form.classlists'},
6277: fields => {%fields},
1.131 raeburn 6278: lockablenames => \@lockablenames,
1.1 raeburn 6279: }
6280: );
6281: foreach my $key (keys(%currautoupdate)) {
6282: if (($key eq 'run') || ($key eq 'classlists')) {
6283: if (exists($updatehash{autoupdate}{$key})) {
6284: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6285: $changes{$key} = 1;
6286: }
6287: }
6288: } elsif ($key eq 'fields') {
6289: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6290: foreach my $item (@{$types},'default') {
1.1 raeburn 6291: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6292: my $change = 0;
6293: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6294: if (!exists($fields{$item})) {
6295: $change = 1;
1.132 raeburn 6296: last;
1.1 raeburn 6297: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6298: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6299: $change = 1;
1.132 raeburn 6300: last;
1.1 raeburn 6301: }
6302: }
6303: }
6304: if ($change) {
6305: push(@{$changes{$key}},$item);
6306: }
1.26 raeburn 6307: }
1.1 raeburn 6308: }
6309: }
1.131 raeburn 6310: } elsif ($key eq 'lockablenames') {
6311: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6312: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6313: if (@changed) {
6314: $changes{'lockablenames'} = 1;
6315: }
6316: } else {
6317: if (@lockablenames) {
6318: $changes{'lockablenames'} = 1;
6319: }
6320: }
6321: }
6322: }
6323: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6324: if (@lockablenames) {
6325: $changes{'lockablenames'} = 1;
1.1 raeburn 6326: }
6327: }
1.26 raeburn 6328: foreach my $item (@{$types},'default') {
6329: if (defined($fields{$item})) {
6330: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6331: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6332: my $change = 0;
6333: if (ref($fields{$item}) eq 'ARRAY') {
6334: foreach my $type (@{$fields{$item}}) {
6335: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6336: $change = 1;
6337: last;
6338: }
6339: }
6340: }
6341: if ($change) {
6342: push(@{$changes{'fields'}},$item);
6343: }
6344: } else {
1.26 raeburn 6345: push(@{$changes{'fields'}},$item);
6346: }
6347: } else {
6348: push(@{$changes{'fields'}},$item);
1.1 raeburn 6349: }
6350: }
6351: }
6352: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6353: $dom);
6354: if ($putresult eq 'ok') {
6355: if (keys(%changes) > 0) {
6356: $resulttext = &mt('Changes made:').'<ul>';
6357: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6358: if ($key eq 'lockablenames') {
6359: $resulttext .= '<li>';
6360: if (@lockablenames) {
6361: $usertypes->{'default'} = $othertitle;
6362: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6363: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6364: } else {
6365: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6366: }
6367: $resulttext .= '</li>';
6368: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6369: foreach my $item (@{$changes{$key}}) {
6370: my @newvalues;
6371: foreach my $type (@{$fields{$item}}) {
6372: push(@newvalues,$fieldtitles{$type});
6373: }
1.3 raeburn 6374: my $newvaluestr;
6375: if (@newvalues > 0) {
6376: $newvaluestr = join(', ',@newvalues);
6377: } else {
6378: $newvaluestr = &mt('none');
1.6 raeburn 6379: }
1.1 raeburn 6380: if ($item eq 'default') {
1.26 raeburn 6381: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6382: } else {
1.26 raeburn 6383: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6384: }
6385: }
6386: } else {
6387: my $newvalue;
6388: if ($key eq 'run') {
6389: $newvalue = $offon[$env{'form.autoupdate_run'}];
6390: } else {
6391: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6392: }
1.1 raeburn 6393: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6394: }
6395: }
6396: $resulttext .= '</ul>';
6397: } else {
1.3 raeburn 6398: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6399: }
6400: } else {
1.11 albertel 6401: $resulttext = '<span class="LC_error">'.
6402: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6403: }
1.3 raeburn 6404: return $resulttext;
1.1 raeburn 6405: }
6406:
1.125 raeburn 6407: sub modify_autocreate {
6408: my ($dom,%domconfig) = @_;
6409: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6410: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6411: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6412: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6413: }
6414: }
6415: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6416: req => 'Auto-creation of validated requests for official courses',
6417: xmldc => 'Identity of course creator of courses from XML files',
6418: );
6419: my @types = ('xml','req');
6420: foreach my $item (@types) {
6421: $newvals{$item} = $env{'form.autocreate_'.$item};
6422: $newvals{$item} =~ s/\D//g;
6423: $newvals{$item} = 0 if ($newvals{$item} eq '');
6424: }
6425: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6426: my %domcoords = &get_active_dcs($dom);
6427: unless (exists($domcoords{$newvals{'xmldc'}})) {
6428: $newvals{'xmldc'} = '';
6429: }
6430: %autocreatehash = (
6431: autocreate => { xml => $newvals{'xml'},
6432: req => $newvals{'req'},
6433: }
6434: );
6435: if ($newvals{'xmldc'} ne '') {
6436: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6437: }
6438: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6439: $dom);
6440: if ($putresult eq 'ok') {
6441: my @items = @types;
6442: if ($newvals{'xml'}) {
6443: push(@items,'xmldc');
6444: }
6445: foreach my $item (@items) {
6446: if (exists($currautocreate{$item})) {
6447: if ($currautocreate{$item} ne $newvals{$item}) {
6448: $changes{$item} = 1;
6449: }
6450: } elsif ($newvals{$item}) {
6451: $changes{$item} = 1;
6452: }
6453: }
6454: if (keys(%changes) > 0) {
6455: my @offon = ('off','on');
6456: $resulttext = &mt('Changes made:').'<ul>';
6457: foreach my $item (@types) {
6458: if ($changes{$item}) {
6459: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6460: $resulttext .= '<li>'.
6461: &mt("$title{$item} set to [_1]$newtxt [_2]",
6462: '<b>','</b>').
6463: '</li>';
1.125 raeburn 6464: }
6465: }
6466: if ($changes{'xmldc'}) {
6467: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6468: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6469: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6470: }
6471: $resulttext .= '</ul>';
6472: } else {
6473: $resulttext = &mt('No changes made to auto-creation settings');
6474: }
6475: } else {
6476: $resulttext = '<span class="LC_error">'.
6477: &mt('An error occurred: [_1]',$putresult).'</span>';
6478: }
6479: return $resulttext;
6480: }
6481:
1.23 raeburn 6482: sub modify_directorysrch {
6483: my ($dom,%domconfig) = @_;
6484: my ($resulttext,%changes);
6485: my %currdirsrch;
6486: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6487: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6488: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6489: }
6490: }
6491: my %title = ( available => 'Directory search available',
1.24 raeburn 6492: localonly => 'Other domains can search',
1.23 raeburn 6493: searchby => 'Search types',
6494: searchtypes => 'Search latitude');
6495: my @offon = ('off','on');
1.24 raeburn 6496: my @otherdoms = ('Yes','No');
1.23 raeburn 6497:
1.25 raeburn 6498: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6499: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6500: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6501:
1.44 raeburn 6502: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6503: if (keys(%{$usertypes}) == 0) {
6504: @cansearch = ('default');
6505: } else {
6506: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6507: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6508: if (!grep(/^\Q$type\E$/,@cansearch)) {
6509: push(@{$changes{'cansearch'}},$type);
6510: }
1.23 raeburn 6511: }
1.26 raeburn 6512: foreach my $type (@cansearch) {
6513: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6514: push(@{$changes{'cansearch'}},$type);
6515: }
1.23 raeburn 6516: }
1.26 raeburn 6517: } else {
6518: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6519: }
6520: }
6521:
6522: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6523: foreach my $by (@{$currdirsrch{'searchby'}}) {
6524: if (!grep(/^\Q$by\E$/,@searchby)) {
6525: push(@{$changes{'searchby'}},$by);
6526: }
6527: }
6528: foreach my $by (@searchby) {
6529: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6530: push(@{$changes{'searchby'}},$by);
6531: }
6532: }
6533: } else {
6534: push(@{$changes{'searchby'}},@searchby);
6535: }
1.25 raeburn 6536:
6537: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6538: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6539: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6540: push(@{$changes{'searchtypes'}},$type);
6541: }
6542: }
6543: foreach my $type (@searchtypes) {
6544: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6545: push(@{$changes{'searchtypes'}},$type);
6546: }
6547: }
6548: } else {
6549: if (exists($currdirsrch{'searchtypes'})) {
6550: foreach my $type (@searchtypes) {
6551: if ($type ne $currdirsrch{'searchtypes'}) {
6552: push(@{$changes{'searchtypes'}},$type);
6553: }
6554: }
6555: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6556: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6557: }
6558: } else {
6559: push(@{$changes{'searchtypes'}},@searchtypes);
6560: }
6561: }
6562:
1.23 raeburn 6563: my %dirsrch_hash = (
6564: directorysrch => { available => $env{'form.dirsrch_available'},
6565: cansearch => \@cansearch,
1.24 raeburn 6566: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6567: searchby => \@searchby,
1.25 raeburn 6568: searchtypes => \@searchtypes,
1.23 raeburn 6569: }
6570: );
6571: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6572: $dom);
6573: if ($putresult eq 'ok') {
6574: if (exists($currdirsrch{'available'})) {
6575: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6576: $changes{'available'} = 1;
6577: }
6578: } else {
6579: if ($env{'form.dirsrch_available'} eq '1') {
6580: $changes{'available'} = 1;
6581: }
6582: }
1.24 raeburn 6583: if (exists($currdirsrch{'localonly'})) {
6584: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6585: $changes{'localonly'} = 1;
6586: }
6587: } else {
6588: if ($env{'form.dirsrch_localonly'} eq '1') {
6589: $changes{'localonly'} = 1;
6590: }
6591: }
1.23 raeburn 6592: if (keys(%changes) > 0) {
6593: $resulttext = &mt('Changes made:').'<ul>';
6594: if ($changes{'available'}) {
6595: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6596: }
1.24 raeburn 6597: if ($changes{'localonly'}) {
6598: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6599: }
6600:
1.23 raeburn 6601: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6602: my $chgtext;
1.26 raeburn 6603: if (ref($usertypes) eq 'HASH') {
6604: if (keys(%{$usertypes}) > 0) {
6605: foreach my $type (@{$types}) {
6606: if (grep(/^\Q$type\E$/,@cansearch)) {
6607: $chgtext .= $usertypes->{$type}.'; ';
6608: }
6609: }
6610: if (grep(/^default$/,@cansearch)) {
6611: $chgtext .= $othertitle;
6612: } else {
6613: $chgtext =~ s/\; $//;
6614: }
1.160.6.13 raeburn 6615: $resulttext .=
6616: '<li>'.
6617: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6618: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6619: '</li>';
1.23 raeburn 6620: }
6621: }
6622: }
6623: if (ref($changes{'searchby'}) eq 'ARRAY') {
6624: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6625: my $chgtext;
6626: foreach my $type (@{$titleorder}) {
6627: if (grep(/^\Q$type\E$/,@searchby)) {
6628: if (defined($searchtitles->{$type})) {
6629: $chgtext .= $searchtitles->{$type}.'; ';
6630: }
6631: }
6632: }
6633: $chgtext =~ s/\; $//;
6634: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6635: }
1.25 raeburn 6636: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6637: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6638: my $chgtext;
6639: foreach my $type (@{$srchtypeorder}) {
6640: if (grep(/^\Q$type\E$/,@searchtypes)) {
6641: if (defined($srchtypes_desc->{$type})) {
6642: $chgtext .= $srchtypes_desc->{$type}.'; ';
6643: }
6644: }
6645: }
6646: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 6647: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6648: }
6649: $resulttext .= '</ul>';
6650: } else {
6651: $resulttext = &mt('No changes made to institution directory search settings');
6652: }
6653: } else {
6654: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6655: &mt('An error occurred: [_1]',$putresult).'</span>';
6656: }
6657: return $resulttext;
6658: }
6659:
1.28 raeburn 6660: sub modify_contacts {
6661: my ($dom,%domconfig) = @_;
6662: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6663: if (ref($domconfig{'contacts'}) eq 'HASH') {
6664: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6665: $currsetting{$key} = $domconfig{'contacts'}{$key};
6666: }
6667: }
1.134 raeburn 6668: my (%others,%to,%bcc);
1.28 raeburn 6669: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6670: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23! raeburn 6671: 'requestsmail','updatesmail','idconflictsmail');
! 6672: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 6673: foreach my $type (@mailings) {
6674: @{$newsetting{$type}} =
6675: &Apache::loncommon::get_env_multiple('form.'.$type);
6676: foreach my $item (@contacts) {
6677: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6678: $contacts_hash{contacts}{$type}{$item} = 1;
6679: } else {
6680: $contacts_hash{contacts}{$type}{$item} = 0;
6681: }
6682: }
6683: $others{$type} = $env{'form.'.$type.'_others'};
6684: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6685: if ($type eq 'helpdeskmail') {
6686: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6687: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6688: }
1.28 raeburn 6689: }
6690: foreach my $item (@contacts) {
6691: $to{$item} = $env{'form.'.$item};
6692: $contacts_hash{'contacts'}{$item} = $to{$item};
6693: }
1.160.6.23! raeburn 6694: foreach my $item (@toggles) {
! 6695: if ($env{'form.'.$item} =~ /^(0|1)$/) {
! 6696: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
! 6697: }
! 6698: }
1.28 raeburn 6699: if (keys(%currsetting) > 0) {
6700: foreach my $item (@contacts) {
6701: if ($to{$item} ne $currsetting{$item}) {
6702: $changes{$item} = 1;
6703: }
6704: }
6705: foreach my $type (@mailings) {
6706: foreach my $item (@contacts) {
6707: if (ref($currsetting{$type}) eq 'HASH') {
6708: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6709: push(@{$changes{$type}},$item);
6710: }
6711: } else {
6712: push(@{$changes{$type}},@{$newsetting{$type}});
6713: }
6714: }
6715: if ($others{$type} ne $currsetting{$type}{'others'}) {
6716: push(@{$changes{$type}},'others');
6717: }
1.134 raeburn 6718: if ($type eq 'helpdeskmail') {
6719: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6720: push(@{$changes{$type}},'bcc');
6721: }
6722: }
1.28 raeburn 6723: }
6724: } else {
6725: my %default;
6726: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6727: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6728: $default{'errormail'} = 'adminemail';
6729: $default{'packagesmail'} = 'adminemail';
6730: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6731: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6732: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 6733: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6734: foreach my $item (@contacts) {
6735: if ($to{$item} ne $default{$item}) {
6736: $changes{$item} = 1;
1.160.6.23! raeburn 6737: }
1.28 raeburn 6738: }
6739: foreach my $type (@mailings) {
6740: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6741:
6742: push(@{$changes{$type}},@{$newsetting{$type}});
6743: }
6744: if ($others{$type} ne '') {
6745: push(@{$changes{$type}},'others');
1.134 raeburn 6746: }
6747: if ($type eq 'helpdeskmail') {
6748: if ($bcc{$type} ne '') {
6749: push(@{$changes{$type}},'bcc');
6750: }
6751: }
1.28 raeburn 6752: }
6753: }
1.160.6.23! raeburn 6754: foreach my $item (@toggles) {
! 6755: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
! 6756: $changes{$item} = 1;
! 6757: } elsif ((!$env{'form.'.$item}) &&
! 6758: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
! 6759: $changes{$item} = 1;
! 6760: }
! 6761: }
1.28 raeburn 6762: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6763: $dom);
6764: if ($putresult eq 'ok') {
6765: if (keys(%changes) > 0) {
6766: my ($titles,$short_titles) = &contact_titles();
6767: $resulttext = &mt('Changes made:').'<ul>';
6768: foreach my $item (@contacts) {
6769: if ($changes{$item}) {
6770: $resulttext .= '<li>'.$titles->{$item}.
6771: &mt(' set to: ').
6772: '<span class="LC_cusr_emph">'.
6773: $to{$item}.'</span></li>';
6774: }
6775: }
6776: foreach my $type (@mailings) {
6777: if (ref($changes{$type}) eq 'ARRAY') {
6778: $resulttext .= '<li>'.$titles->{$type}.': ';
6779: my @text;
6780: foreach my $item (@{$newsetting{$type}}) {
6781: push(@text,$short_titles->{$item});
6782: }
6783: if ($others{$type} ne '') {
6784: push(@text,$others{$type});
6785: }
6786: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6787: join(', ',@text).'</span>';
6788: if ($type eq 'helpdeskmail') {
6789: if ($bcc{$type} ne '') {
6790: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6791: }
6792: }
6793: $resulttext .= '</li>';
1.28 raeburn 6794: }
6795: }
1.160.6.23! raeburn 6796: my @offon = ('off','on');
! 6797: if ($changes{'reporterrors'}) {
! 6798: $resulttext .= '<li>'.
! 6799: &mt('E-mail error reports to [_1] set to "'.
! 6800: $offon[$env{'form.reporterrors'}].'".',
! 6801: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
! 6802: &mt('LON-CAPA core group - MSU'),600,500)).
! 6803: '</li>';
! 6804: }
! 6805: if ($changes{'reportupdates'}) {
! 6806: $resulttext .= '<li>'.
! 6807: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
! 6808: $offon[$env{'form.reportupdates'}].'".',
! 6809: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
! 6810: &mt('LON-CAPA core group - MSU'),600,500)).
! 6811: '</li>';
! 6812: }
1.28 raeburn 6813: $resulttext .= '</ul>';
6814: } else {
1.34 raeburn 6815: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6816: }
6817: } else {
6818: $resulttext = '<span class="LC_error">'.
6819: &mt('An error occurred: [_1].',$putresult).'</span>';
6820: }
6821: return $resulttext;
6822: }
6823:
6824: sub modify_usercreation {
1.27 raeburn 6825: my ($dom,%domconfig) = @_;
1.34 raeburn 6826: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6827: my $warningmsg;
1.27 raeburn 6828: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6829: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6830: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6831: }
6832: }
6833: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6834: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6835: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6836: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6837: foreach my $item(@contexts) {
1.45 raeburn 6838: if ($item eq 'selfcreate') {
1.50 raeburn 6839: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6840: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6841: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6842: if (ref($cancreate{$item}) eq 'ARRAY') {
6843: if (grep(/^login$/,@{$cancreate{$item}})) {
6844: $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.').' '.&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.');
6845: }
1.43 raeburn 6846: }
6847: }
1.50 raeburn 6848: } else {
6849: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6850: }
1.34 raeburn 6851: }
1.93 raeburn 6852: my ($othertitle,$usertypes,$types) =
6853: &Apache::loncommon::sorted_inst_types($dom);
6854: if (ref($types) eq 'ARRAY') {
6855: if (@{$types} > 0) {
6856: @{$cancreate{'statustocreate'}} =
6857: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6858: } else {
6859: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6860: }
6861: push(@contexts,'statustocreate');
6862: }
1.160.6.5 raeburn 6863: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6864: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6865: foreach my $item (@contexts) {
1.93 raeburn 6866: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6867: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6868: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6869: if (ref($cancreate{$item}) eq 'ARRAY') {
6870: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6871: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6872: push(@{$changes{'cancreate'}},$item);
6873: }
1.50 raeburn 6874: }
6875: }
6876: }
6877: } else {
6878: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6879: if (@{$cancreate{$item}} > 0) {
6880: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6881: push(@{$changes{'cancreate'}},$item);
6882: }
6883: }
6884: } else {
6885: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6886: if (@{$cancreate{$item}} < 3) {
6887: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6888: push(@{$changes{'cancreate'}},$item);
6889: }
6890: }
6891: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6892: if (@{$cancreate{$item}} > 0) {
6893: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6894: push(@{$changes{'cancreate'}},$item);
6895: }
6896: }
6897: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6898: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6899: push(@{$changes{'cancreate'}},$item);
6900: }
6901: }
6902: }
6903: }
6904: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6905: foreach my $type (@{$cancreate{$item}}) {
6906: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6907: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6908: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6909: push(@{$changes{'cancreate'}},$item);
6910: }
6911: }
6912: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6913: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6914: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6915: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6916: push(@{$changes{'cancreate'}},$item);
6917: }
6918: }
6919: }
6920: }
6921: }
6922: } else {
6923: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6924: push(@{$changes{'cancreate'}},$item);
6925: }
6926: }
1.27 raeburn 6927: }
1.34 raeburn 6928: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6929: foreach my $item (@contexts) {
1.43 raeburn 6930: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6931: if ($cancreate{$item} ne 'any') {
6932: push(@{$changes{'cancreate'}},$item);
6933: }
6934: } else {
6935: if ($cancreate{$item} ne 'none') {
6936: push(@{$changes{'cancreate'}},$item);
6937: }
1.27 raeburn 6938: }
6939: }
6940: } else {
1.43 raeburn 6941: foreach my $item (@contexts) {
1.34 raeburn 6942: push(@{$changes{'cancreate'}},$item);
6943: }
1.27 raeburn 6944: }
1.34 raeburn 6945:
1.27 raeburn 6946: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6947: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6948: if (!grep(/^\Q$type\E$/,@username_rule)) {
6949: push(@{$changes{'username_rule'}},$type);
6950: }
6951: }
6952: foreach my $type (@username_rule) {
6953: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6954: push(@{$changes{'username_rule'}},$type);
6955: }
6956: }
6957: } else {
6958: push(@{$changes{'username_rule'}},@username_rule);
6959: }
6960:
1.32 raeburn 6961: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6962: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6963: if (!grep(/^\Q$type\E$/,@id_rule)) {
6964: push(@{$changes{'id_rule'}},$type);
6965: }
6966: }
6967: foreach my $type (@id_rule) {
6968: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6969: push(@{$changes{'id_rule'}},$type);
6970: }
6971: }
6972: } else {
6973: push(@{$changes{'id_rule'}},@id_rule);
6974: }
6975:
1.43 raeburn 6976: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6977: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6978: if (!grep(/^\Q$type\E$/,@email_rule)) {
6979: push(@{$changes{'email_rule'}},$type);
6980: }
6981: }
6982: foreach my $type (@email_rule) {
6983: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6984: push(@{$changes{'email_rule'}},$type);
6985: }
6986: }
6987: } else {
6988: push(@{$changes{'email_rule'}},@email_rule);
6989: }
6990:
6991: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6992: my @authtypes = ('int','krb4','krb5','loc');
6993: my %authhash;
1.43 raeburn 6994: foreach my $item (@authen_contexts) {
1.28 raeburn 6995: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6996: foreach my $auth (@authtypes) {
6997: if (grep(/^\Q$auth\E$/,@authallowed)) {
6998: $authhash{$item}{$auth} = 1;
6999: } else {
7000: $authhash{$item}{$auth} = 0;
7001: }
7002: }
7003: }
7004: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7005: foreach my $item (@authen_contexts) {
1.28 raeburn 7006: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7007: foreach my $auth (@authtypes) {
7008: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7009: push(@{$changes{'authtypes'}},$item);
7010: last;
7011: }
7012: }
7013: }
7014: }
7015: } else {
1.43 raeburn 7016: foreach my $item (@authen_contexts) {
1.28 raeburn 7017: push(@{$changes{'authtypes'}},$item);
7018: }
7019: }
7020:
1.27 raeburn 7021: my %usercreation_hash = (
1.28 raeburn 7022: usercreation => {
1.34 raeburn 7023: cancreate => \%cancreate,
1.27 raeburn 7024: username_rule => \@username_rule,
1.32 raeburn 7025: id_rule => \@id_rule,
1.43 raeburn 7026: email_rule => \@email_rule,
1.32 raeburn 7027: authtypes => \%authhash,
1.27 raeburn 7028: }
7029: );
7030:
7031: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7032: $dom);
1.50 raeburn 7033:
7034: my %selfcreatetypes = (
7035: sso => 'users authenticated by institutional single sign on',
7036: login => 'users authenticated by institutional log-in',
7037: email => 'users who provide a valid e-mail address for use as the username',
7038: );
1.27 raeburn 7039: if ($putresult eq 'ok') {
7040: if (keys(%changes) > 0) {
7041: $resulttext = &mt('Changes made:').'<ul>';
7042: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7043: my %lt = &usercreation_types();
7044: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7045: my $chgtext;
1.160.6.5 raeburn 7046: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7047: $chgtext = $lt{$type}.', ';
7048: }
1.45 raeburn 7049: if ($type eq 'selfcreate') {
1.50 raeburn 7050: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7051: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7052: } else {
1.100 raeburn 7053: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7054: foreach my $case (@{$cancreate{$type}}) {
7055: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7056: }
7057: $chgtext .= '</ul>';
1.100 raeburn 7058: if (ref($cancreate{$type}) eq 'ARRAY') {
7059: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7060: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7061: if (@{$cancreate{'statustocreate'}} == 0) {
7062: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7063: }
7064: }
7065: }
7066: }
1.43 raeburn 7067: }
1.93 raeburn 7068: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7069: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7070: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7071: if (@{$cancreate{'selfcreate'}} > 0) {
7072: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7073:
7074: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7075: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7076: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7077: }
1.96 raeburn 7078: } elsif (ref($usertypes) eq 'HASH') {
7079: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7080: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7081: } else {
7082: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7083: }
7084: $chgtext .= '<ul>';
7085: foreach my $case (@{$cancreate{$type}}) {
7086: if ($case eq 'default') {
7087: $chgtext .= '<li>'.$othertitle.'</li>';
7088: } else {
7089: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7090: }
7091: }
1.100 raeburn 7092: $chgtext .= '</ul>';
7093: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7094: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7095: }
7096: }
7097: } else {
7098: if (@{$cancreate{$type}} == 0) {
7099: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7100: } else {
7101: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
1.93 raeburn 7102: }
7103: }
7104: }
1.160.6.5 raeburn 7105: } elsif ($type eq 'captcha') {
7106: if ($cancreate{$type} eq 'notused') {
7107: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7108: } else {
7109: my %captchas = &captcha_phrases();
7110: if ($captchas{$cancreate{$type}}) {
7111: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7112: } else {
7113: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7114: }
7115: }
7116: } elsif ($type eq 'recaptchakeys') {
7117: my ($privkey,$pubkey);
7118: if (ref($cancreate{$type}) eq 'HASH') {
7119: $pubkey = $cancreate{$type}{'public'};
7120: $privkey = $cancreate{$type}{'private'};
7121: }
7122: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7123: if (!$pubkey) {
7124: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7125: } else {
7126: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7127: }
7128: if (!$privkey) {
7129: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7130: } else {
7131: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7132: }
7133: $chgtext .= '</ul>';
1.43 raeburn 7134: } else {
7135: if ($cancreate{$type} eq 'none') {
7136: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7137: } elsif ($cancreate{$type} eq 'any') {
7138: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7139: } elsif ($cancreate{$type} eq 'official') {
7140: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7141: } elsif ($cancreate{$type} eq 'unofficial') {
7142: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7143: }
1.34 raeburn 7144: }
7145: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7146: }
7147: }
7148: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7149: my ($rules,$ruleorder) =
7150: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7151: my $chgtext = '<ul>';
7152: foreach my $type (@username_rule) {
7153: if (ref($rules->{$type}) eq 'HASH') {
7154: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7155: }
7156: }
7157: $chgtext .= '</ul>';
7158: if (@username_rule > 0) {
7159: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7160: } else {
1.28 raeburn 7161: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7162: }
7163: }
1.32 raeburn 7164: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7165: my ($idrules,$idruleorder) =
7166: &Apache::lonnet::inst_userrules($dom,'id');
7167: my $chgtext = '<ul>';
7168: foreach my $type (@id_rule) {
7169: if (ref($idrules->{$type}) eq 'HASH') {
7170: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7171: }
7172: }
7173: $chgtext .= '</ul>';
7174: if (@id_rule > 0) {
7175: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7176: } else {
7177: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7178: }
7179: }
1.43 raeburn 7180: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7181: my ($emailrules,$emailruleorder) =
7182: &Apache::lonnet::inst_userrules($dom,'email');
7183: my $chgtext = '<ul>';
7184: foreach my $type (@email_rule) {
7185: if (ref($emailrules->{$type}) eq 'HASH') {
7186: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7187: }
7188: }
7189: $chgtext .= '</ul>';
7190: if (@email_rule > 0) {
7191: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7192: } else {
7193: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7194: }
7195: }
7196:
1.28 raeburn 7197: my %authname = &authtype_names();
7198: my %context_title = &context_names();
7199: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7200: my $chgtext = '<ul>';
7201: foreach my $type (@{$changes{'authtypes'}}) {
7202: my @allowed;
7203: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7204: foreach my $auth (@authtypes) {
7205: if ($authhash{$type}{$auth}) {
7206: push(@allowed,$authname{$auth});
7207: }
7208: }
1.43 raeburn 7209: if (@allowed > 0) {
7210: $chgtext .= join(', ',@allowed).'</li>';
7211: } else {
7212: $chgtext .= &mt('none').'</li>';
7213: }
1.28 raeburn 7214: }
7215: $chgtext .= '</ul>';
7216: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7217: $resulttext .= '</li>';
7218: }
1.27 raeburn 7219: $resulttext .= '</ul>';
7220: } else {
1.28 raeburn 7221: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7222: }
7223: } else {
7224: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7225: &mt('An error occurred: [_1]',$putresult).'</span>';
7226: }
1.43 raeburn 7227: if ($warningmsg ne '') {
7228: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7229: }
1.23 raeburn 7230: return $resulttext;
7231: }
7232:
1.160.6.5 raeburn 7233: sub process_captcha {
7234: my ($container,$changes,$newsettings,$current) = @_;
7235: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7236: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7237: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7238: $newsettings->{'captcha'} = 'original';
7239: }
7240: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7241: if ($container eq 'cancreate') {
7242: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7243: push(@{$changes->{'cancreate'}},'captcha');
7244: } elsif (!defined($changes->{'cancreate'})) {
7245: $changes->{'cancreate'} = ['captcha'];
7246: }
7247: } else {
7248: $changes->{'captcha'} = 1;
7249: }
7250: }
7251: my ($newpub,$newpriv,$currpub,$currpriv);
7252: if ($newsettings->{'captcha'} eq 'recaptcha') {
7253: $newpub = $env{'form.'.$container.'_recaptchapub'};
7254: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7255: $newpub =~ s/\W//g;
7256: $newpriv =~ s/\W//g;
7257: $newsettings->{'recaptchakeys'} = {
7258: public => $newpub,
7259: private => $newpriv,
7260: };
7261: }
7262: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7263: $currpub = $current->{'recaptchakeys'}{'public'};
7264: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7265: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7266: $newsettings->{'recaptchakeys'} = {
7267: public => '',
7268: private => '',
7269: }
7270: }
1.160.6.5 raeburn 7271: }
7272: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7273: if ($container eq 'cancreate') {
7274: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7275: push(@{$changes->{'cancreate'}},'recaptchakeys');
7276: } elsif (!defined($changes->{'cancreate'})) {
7277: $changes->{'cancreate'} = ['recaptchakeys'];
7278: }
7279: } else {
7280: $changes->{'recaptchakeys'} = 1;
7281: }
7282: }
7283: return;
7284: }
7285:
1.33 raeburn 7286: sub modify_usermodification {
7287: my ($dom,%domconfig) = @_;
7288: my ($resulttext,%curr_usermodification,%changes);
7289: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7290: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7291: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7292: }
7293: }
1.63 raeburn 7294: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7295: my %context_title = (
7296: author => 'In author context',
7297: course => 'In course context',
1.63 raeburn 7298: selfcreate => 'When self creating account',
1.33 raeburn 7299: );
7300: my @fields = ('lastname','firstname','middlename','generation',
7301: 'permanentemail','id');
7302: my %roles = (
7303: author => ['ca','aa'],
7304: course => ['st','ep','ta','in','cr'],
7305: );
1.63 raeburn 7306: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7307: if (ref($types) eq 'ARRAY') {
7308: push(@{$types},'default');
7309: $usertypes->{'default'} = $othertitle;
7310: }
7311: $roles{'selfcreate'} = $types;
1.33 raeburn 7312: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7313: my %modifyhash;
7314: foreach my $context (@contexts) {
7315: foreach my $role (@{$roles{$context}}) {
7316: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7317: foreach my $item (@fields) {
7318: if (grep(/^\Q$item\E$/,@modifiable)) {
7319: $modifyhash{$context}{$role}{$item} = 1;
7320: } else {
7321: $modifyhash{$context}{$role}{$item} = 0;
7322: }
7323: }
7324: }
7325: if (ref($curr_usermodification{$context}) eq 'HASH') {
7326: foreach my $role (@{$roles{$context}}) {
7327: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7328: foreach my $field (@fields) {
7329: if ($modifyhash{$context}{$role}{$field} ne
7330: $curr_usermodification{$context}{$role}{$field}) {
7331: push(@{$changes{$context}},$role);
7332: last;
7333: }
7334: }
7335: }
7336: }
7337: } else {
7338: foreach my $context (@contexts) {
7339: foreach my $role (@{$roles{$context}}) {
7340: push(@{$changes{$context}},$role);
7341: }
7342: }
7343: }
7344: }
7345: my %usermodification_hash = (
7346: usermodification => \%modifyhash,
7347: );
7348: my $putresult = &Apache::lonnet::put_dom('configuration',
7349: \%usermodification_hash,$dom);
7350: if ($putresult eq 'ok') {
7351: if (keys(%changes) > 0) {
7352: $resulttext = &mt('Changes made: ').'<ul>';
7353: foreach my $context (@contexts) {
7354: if (ref($changes{$context}) eq 'ARRAY') {
7355: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7356: if (ref($changes{$context}) eq 'ARRAY') {
7357: foreach my $role (@{$changes{$context}}) {
7358: my $rolename;
1.63 raeburn 7359: if ($context eq 'selfcreate') {
7360: $rolename = $role;
7361: if (ref($usertypes) eq 'HASH') {
7362: if ($usertypes->{$role} ne '') {
7363: $rolename = $usertypes->{$role};
7364: }
7365: }
1.33 raeburn 7366: } else {
1.63 raeburn 7367: if ($role eq 'cr') {
7368: $rolename = &mt('Custom');
7369: } else {
7370: $rolename = &Apache::lonnet::plaintext($role);
7371: }
1.33 raeburn 7372: }
7373: my @modifiable;
1.63 raeburn 7374: if ($context eq 'selfcreate') {
1.126 bisitz 7375: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63 raeburn 7376: } else {
7377: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7378: }
1.33 raeburn 7379: foreach my $field (@fields) {
7380: if ($modifyhash{$context}{$role}{$field}) {
7381: push(@modifiable,$fieldtitles{$field});
7382: }
7383: }
7384: if (@modifiable > 0) {
7385: $resulttext .= join(', ',@modifiable);
7386: } else {
7387: $resulttext .= &mt('none');
7388: }
7389: $resulttext .= '</li>';
7390: }
7391: $resulttext .= '</ul></li>';
7392: }
7393: }
7394: }
7395: $resulttext .= '</ul>';
7396: } else {
7397: $resulttext = &mt('No changes made to user modification settings');
7398: }
7399: } else {
7400: $resulttext = '<span class="LC_error">'.
7401: &mt('An error occurred: [_1]',$putresult).'</span>';
7402: }
7403: return $resulttext;
7404: }
7405:
1.43 raeburn 7406: sub modify_defaults {
1.160.6.23! raeburn 7407: my ($dom,$r,%domconfig) = @_;
1.43 raeburn 7408: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7409: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7410: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7411: my @authtypes = ('internal','krb4','krb5','localauth');
7412: foreach my $item (@items) {
7413: $newvalues{$item} = $env{'form.'.$item};
7414: if ($item eq 'auth_def') {
7415: if ($newvalues{$item} ne '') {
7416: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7417: push(@errors,$item);
7418: }
7419: }
7420: } elsif ($item eq 'lang_def') {
7421: if ($newvalues{$item} ne '') {
7422: if ($newvalues{$item} =~ /^(\w+)/) {
7423: my $langcode = $1;
1.103 raeburn 7424: if ($langcode ne 'x_chef') {
7425: if (code2language($langcode) eq '') {
7426: push(@errors,$item);
7427: }
1.43 raeburn 7428: }
7429: } else {
7430: push(@errors,$item);
7431: }
7432: }
1.54 raeburn 7433: } elsif ($item eq 'timezone_def') {
7434: if ($newvalues{$item} ne '') {
1.62 raeburn 7435: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7436: push(@errors,$item);
7437: }
7438: }
1.68 raeburn 7439: } elsif ($item eq 'datelocale_def') {
7440: if ($newvalues{$item} ne '') {
7441: my @datelocale_ids = DateTime::Locale->ids();
7442: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7443: push(@errors,$item);
7444: }
7445: }
1.141 raeburn 7446: } elsif ($item eq 'portal_def') {
7447: if ($newvalues{$item} ne '') {
7448: 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])\/?$/) {
7449: push(@errors,$item);
7450: }
7451: }
1.43 raeburn 7452: }
7453: if (grep(/^\Q$item\E$/,@errors)) {
7454: $newvalues{$item} = $domdefaults{$item};
7455: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7456: $changes{$item} = 1;
7457: }
1.72 raeburn 7458: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7459: }
7460: my %defaults_hash = (
1.72 raeburn 7461: defaults => \%newvalues,
7462: );
1.43 raeburn 7463: my $title = &defaults_titles();
7464: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7465: $dom);
7466: if ($putresult eq 'ok') {
7467: if (keys(%changes) > 0) {
7468: $resulttext = &mt('Changes made:').'<ul>';
7469: my $version = $r->dir_config('lonVersion');
7470: 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";
7471: foreach my $item (sort(keys(%changes))) {
7472: my $value = $env{'form.'.$item};
7473: if ($value eq '') {
7474: $value = &mt('none');
7475: } elsif ($item eq 'auth_def') {
7476: my %authnames = &authtype_names();
7477: my %shortauth = (
7478: internal => 'int',
7479: krb4 => 'krb4',
7480: krb5 => 'krb5',
7481: localauth => 'loc',
7482: );
7483: $value = $authnames{$shortauth{$value}};
7484: }
7485: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7486: $mailmsgtext .= "$title->{$item} set to $value\n";
7487: }
7488: $resulttext .= '</ul>';
7489: $mailmsgtext .= "\n";
7490: my $cachetime = 24*60*60;
1.72 raeburn 7491: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7492: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23! raeburn 7493: my $notify = 1;
! 7494: if (ref($domconfig{'contacts'}) eq 'HASH') {
! 7495: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
! 7496: $notify = 0;
! 7497: }
! 7498: }
! 7499: if ($notify) {
! 7500: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
! 7501: "LON-CAPA Domain Settings Change - $dom",
! 7502: $mailmsgtext);
! 7503: }
1.54 raeburn 7504: }
1.43 raeburn 7505: } else {
1.54 raeburn 7506: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7507: }
7508: } else {
7509: $resulttext = '<span class="LC_error">'.
7510: &mt('An error occurred: [_1]',$putresult).'</span>';
7511: }
7512: if (@errors > 0) {
7513: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7514: foreach my $item (@errors) {
7515: $resulttext .= ' "'.$title->{$item}.'",';
7516: }
7517: $resulttext =~ s/,$//;
7518: }
7519: return $resulttext;
7520: }
7521:
1.46 raeburn 7522: sub modify_scantron {
1.48 raeburn 7523: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7524: my ($resulttext,%confhash,%changes,$errors);
7525: my $custom = 'custom.tab';
7526: my $default = 'default.tab';
7527: my $servadm = $r->dir_config('lonAdmEMail');
7528: my ($configuserok,$author_ok,$switchserver) =
7529: &config_check($dom,$confname,$servadm);
7530: if ($env{'form.scantronformat.filename'} ne '') {
7531: my $error;
7532: if ($configuserok eq 'ok') {
7533: if ($switchserver) {
1.130 raeburn 7534: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7535: } else {
7536: if ($author_ok eq 'ok') {
7537: my ($result,$scantronurl) =
7538: &publishlogo($r,'upload','scantronformat',$dom,
7539: $confname,'scantron','','',$custom);
7540: if ($result eq 'ok') {
7541: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7542: $changes{'scantronformat'} = 1;
1.46 raeburn 7543: } else {
7544: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7545: }
7546: } else {
7547: $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);
7548: }
7549: }
7550: } else {
7551: $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);
7552: }
7553: if ($error) {
7554: &Apache::lonnet::logthis($error);
7555: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7556: }
7557: }
1.48 raeburn 7558: if (ref($domconfig{'scantron'}) eq 'HASH') {
7559: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7560: if ($env{'form.scantronformat_del'}) {
7561: $confhash{'scantron'}{'scantronformat'} = '';
7562: $changes{'scantronformat'} = 1;
1.46 raeburn 7563: }
7564: }
7565: }
7566: if (keys(%confhash) > 0) {
7567: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7568: $dom);
7569: if ($putresult eq 'ok') {
7570: if (keys(%changes) > 0) {
1.48 raeburn 7571: if (ref($confhash{'scantron'}) eq 'HASH') {
7572: $resulttext = &mt('Changes made:').'<ul>';
7573: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7574: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7575: } else {
1.130 raeburn 7576: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7577: }
1.48 raeburn 7578: $resulttext .= '</ul>';
7579: } else {
1.130 raeburn 7580: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7581: }
7582: $resulttext .= '</ul>';
7583: &Apache::loncommon::devalidate_domconfig_cache($dom);
7584: } else {
1.130 raeburn 7585: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7586: }
7587: } else {
7588: $resulttext = '<span class="LC_error">'.
7589: &mt('An error occurred: [_1]',$putresult).'</span>';
7590: }
7591: } else {
1.130 raeburn 7592: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7593: }
7594: if ($errors) {
7595: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7596: $errors.'</ul>';
7597: }
7598: return $resulttext;
7599: }
7600:
1.48 raeburn 7601: sub modify_coursecategories {
7602: my ($dom,%domconfig) = @_;
1.57 raeburn 7603: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7604: $cathash);
1.48 raeburn 7605: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7606: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7607: $cathash = $domconfig{'coursecategories'}{'cats'};
7608: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7609: $changes{'togglecats'} = 1;
7610: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7611: }
7612: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7613: $changes{'categorize'} = 1;
7614: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7615: }
1.120 raeburn 7616: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7617: $changes{'togglecatscomm'} = 1;
7618: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7619: }
7620: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7621: $changes{'categorizecomm'} = 1;
7622: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7623: }
1.57 raeburn 7624: } else {
7625: $changes{'togglecats'} = 1;
7626: $changes{'categorize'} = 1;
1.124 raeburn 7627: $changes{'togglecatscomm'} = 1;
7628: $changes{'categorizecomm'} = 1;
1.87 raeburn 7629: $domconfig{'coursecategories'} = {
7630: togglecats => $env{'form.togglecats'},
7631: categorize => $env{'form.categorize'},
1.124 raeburn 7632: togglecatscomm => $env{'form.togglecatscomm'},
7633: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7634: };
1.57 raeburn 7635: }
7636: if (ref($cathash) eq 'HASH') {
7637: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7638: push (@deletecategory,'instcode::0');
7639: }
1.120 raeburn 7640: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7641: push(@deletecategory,'communities::0');
7642: }
1.48 raeburn 7643: }
1.57 raeburn 7644: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7645: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7646: if (@deletecategory > 0) {
7647: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7648: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7649: foreach my $item (@deletecategory) {
1.57 raeburn 7650: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7651: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7652: $deletions{$item} = 1;
1.57 raeburn 7653: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7654: }
7655: }
7656: }
1.57 raeburn 7657: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7658: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7659: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7660: $reorderings{$item} = 1;
1.57 raeburn 7661: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7662: }
7663: if ($env{'form.addcategory_name_'.$item} ne '') {
7664: my $newcat = $env{'form.addcategory_name_'.$item};
7665: my $newdepth = $depth+1;
7666: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7667: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7668: $adds{$newitem} = 1;
7669: }
7670: if ($env{'form.subcat_'.$item} ne '') {
7671: my $newcat = $env{'form.subcat_'.$item};
7672: my $newdepth = $depth+1;
7673: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7674: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7675: $adds{$newitem} = 1;
7676: }
7677: }
7678: }
7679: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7680: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7681: my $newitem = 'instcode::0';
1.57 raeburn 7682: if ($cathash->{$newitem} eq '') {
7683: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7684: $adds{$newitem} = 1;
7685: }
7686: } else {
7687: my $newitem = 'instcode::0';
1.57 raeburn 7688: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7689: $adds{$newitem} = 1;
7690: }
7691: }
1.120 raeburn 7692: if ($env{'form.communities'} eq '1') {
7693: if (ref($cathash) eq 'HASH') {
7694: my $newitem = 'communities::0';
7695: if ($cathash->{$newitem} eq '') {
7696: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7697: $adds{$newitem} = 1;
7698: }
7699: } else {
7700: my $newitem = 'communities::0';
7701: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7702: $adds{$newitem} = 1;
7703: }
7704: }
1.48 raeburn 7705: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7706: if (($env{'form.addcategory_name'} ne 'instcode') &&
7707: ($env{'form.addcategory_name'} ne 'communities')) {
7708: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7709: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7710: $adds{$newitem} = 1;
7711: }
1.48 raeburn 7712: }
1.57 raeburn 7713: my $putresult;
1.48 raeburn 7714: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7715: if (keys(%deletions) > 0) {
7716: foreach my $key (keys(%deletions)) {
7717: if ($predelallitems{$key} ne '') {
7718: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7719: }
7720: }
7721: }
7722: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7723: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7724: if (ref($chkcats[0]) eq 'ARRAY') {
7725: my $depth = 0;
7726: my $chg = 0;
7727: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7728: my $name = $chkcats[0][$i];
7729: my $item;
7730: if ($name eq '') {
7731: $chg ++;
7732: } else {
7733: $item = &escape($name).'::0';
7734: if ($chg) {
1.57 raeburn 7735: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7736: }
7737: $depth ++;
1.57 raeburn 7738: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7739: $depth --;
7740: }
7741: }
7742: }
1.57 raeburn 7743: }
7744: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7745: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7746: if ($putresult eq 'ok') {
1.57 raeburn 7747: my %title = (
1.120 raeburn 7748: togglecats => 'Show/Hide a course in catalog',
7749: categorize => 'Assign a category to a course',
7750: togglecatscomm => 'Show/Hide a community in catalog',
7751: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7752: );
7753: my %level = (
1.120 raeburn 7754: dom => 'set in Domain ("Modify Course/Community")',
7755: crs => 'set in Course ("Course Configuration")',
7756: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7757: );
1.48 raeburn 7758: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7759: if ($changes{'togglecats'}) {
7760: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7761: }
7762: if ($changes{'categorize'}) {
7763: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7764: }
1.120 raeburn 7765: if ($changes{'togglecatscomm'}) {
7766: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7767: }
7768: if ($changes{'categorizecomm'}) {
7769: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7770: }
1.57 raeburn 7771: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7772: my $cathash;
7773: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7774: $cathash = $domconfig{'coursecategories'}{'cats'};
7775: } else {
7776: $cathash = {};
7777: }
7778: my (@cats,@trails,%allitems);
7779: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7780: if (keys(%deletions) > 0) {
7781: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7782: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7783: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7784: }
7785: $resulttext .= '</ul></li>';
7786: }
7787: if (keys(%reorderings) > 0) {
7788: my %sort_by_trail;
7789: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7790: foreach my $key (keys(%reorderings)) {
7791: if ($allitems{$key} ne '') {
7792: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7793: }
1.48 raeburn 7794: }
1.57 raeburn 7795: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7796: $resulttext .= '<li>'.$trails[$trail].'</li>';
7797: }
7798: $resulttext .= '</ul></li>';
1.48 raeburn 7799: }
1.57 raeburn 7800: if (keys(%adds) > 0) {
7801: my %sort_by_trail;
7802: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7803: foreach my $key (keys(%adds)) {
7804: if ($allitems{$key} ne '') {
7805: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7806: }
7807: }
7808: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7809: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7810: }
1.57 raeburn 7811: $resulttext .= '</ul></li>';
1.48 raeburn 7812: }
7813: }
7814: $resulttext .= '</ul>';
7815: } else {
7816: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7817: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7818: }
7819: } else {
1.120 raeburn 7820: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7821: }
7822: return $resulttext;
7823: }
7824:
1.69 raeburn 7825: sub modify_serverstatuses {
7826: my ($dom,%domconfig) = @_;
7827: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7828: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7829: %currserverstatus = %{$domconfig{'serverstatuses'}};
7830: }
7831: my @pages = &serverstatus_pages();
7832: foreach my $type (@pages) {
7833: $newserverstatus{$type}{'namedusers'} = '';
7834: $newserverstatus{$type}{'machines'} = '';
7835: if (defined($env{'form.'.$type.'_namedusers'})) {
7836: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7837: my @okusers;
7838: foreach my $user (@users) {
7839: my ($uname,$udom) = split(/:/,$user);
7840: if (($udom =~ /^$match_domain$/) &&
7841: (&Apache::lonnet::domain($udom)) &&
7842: ($uname =~ /^$match_username$/)) {
7843: if (!grep(/^\Q$user\E/,@okusers)) {
7844: push(@okusers,$user);
7845: }
7846: }
7847: }
7848: if (@okusers > 0) {
7849: @okusers = sort(@okusers);
7850: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7851: }
7852: }
7853: if (defined($env{'form.'.$type.'_machines'})) {
7854: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7855: my @okmachines;
7856: foreach my $ip (@machines) {
7857: my @parts = split(/\./,$ip);
7858: next if (@parts < 4);
7859: my $badip = 0;
7860: for (my $i=0; $i<4; $i++) {
7861: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7862: $badip = 1;
7863: last;
7864: }
7865: }
7866: if (!$badip) {
7867: push(@okmachines,$ip);
7868: }
7869: }
7870: @okmachines = sort(@okmachines);
7871: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7872: }
7873: }
7874: my %serverstatushash = (
7875: serverstatuses => \%newserverstatus,
7876: );
7877: foreach my $type (@pages) {
1.83 raeburn 7878: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7879: my (@current,@new);
1.83 raeburn 7880: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7881: if ($currserverstatus{$type}{$setting} ne '') {
7882: @current = split(/,/,$currserverstatus{$type}{$setting});
7883: }
7884: }
7885: if ($newserverstatus{$type}{$setting} ne '') {
7886: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7887: }
7888: if (@current > 0) {
7889: if (@new > 0) {
7890: foreach my $item (@current) {
7891: if (!grep(/^\Q$item\E$/,@new)) {
7892: $changes{$type}{$setting} = 1;
1.82 raeburn 7893: last;
7894: }
7895: }
1.84 raeburn 7896: foreach my $item (@new) {
7897: if (!grep(/^\Q$item\E$/,@current)) {
7898: $changes{$type}{$setting} = 1;
7899: last;
1.82 raeburn 7900: }
7901: }
7902: } else {
1.83 raeburn 7903: $changes{$type}{$setting} = 1;
1.69 raeburn 7904: }
1.83 raeburn 7905: } elsif (@new > 0) {
7906: $changes{$type}{$setting} = 1;
1.69 raeburn 7907: }
7908: }
7909: }
7910: if (keys(%changes) > 0) {
1.81 raeburn 7911: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7912: my $putresult = &Apache::lonnet::put_dom('configuration',
7913: \%serverstatushash,$dom);
7914: if ($putresult eq 'ok') {
7915: $resulttext .= &mt('Changes made:').'<ul>';
7916: foreach my $type (@pages) {
1.84 raeburn 7917: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7918: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7919: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7920: if ($newserverstatus{$type}{'namedusers'} eq '') {
7921: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7922: } else {
7923: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7924: }
1.84 raeburn 7925: }
7926: if ($changes{$type}{'machines'}) {
1.69 raeburn 7927: if ($newserverstatus{$type}{'machines'} eq '') {
7928: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7929: } else {
7930: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7931: }
7932:
7933: }
7934: $resulttext .= '</ul></li>';
7935: }
7936: }
7937: $resulttext .= '</ul>';
7938: } else {
7939: $resulttext = '<span class="LC_error">'.
7940: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7941:
7942: }
7943: } else {
7944: $resulttext = &mt('No changes made to access to server status pages');
7945: }
7946: return $resulttext;
7947: }
7948:
1.118 jms 7949: sub modify_helpsettings {
1.122 jms 7950: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7951: my ($resulttext,$errors,%changes,%helphash);
7952: my %defaultchecked = ('submitbugs' => 'on');
7953: my @offon = ('off','on');
1.118 jms 7954: my @toggles = ('submitbugs');
7955: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7956: foreach my $item (@toggles) {
1.160.6.5 raeburn 7957: if ($defaultchecked{$item} eq 'on') {
7958: if ($domconfig{'helpsettings'}{$item} eq '') {
7959: if ($env{'form.'.$item} eq '0') {
7960: $changes{$item} = 1;
7961: }
7962: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7963: $changes{$item} = 1;
7964: }
7965: } elsif ($defaultchecked{$item} eq 'off') {
7966: if ($domconfig{'helpsettings'}{$item} eq '') {
7967: if ($env{'form.'.$item} eq '1') {
7968: $changes{$item} = 1;
7969: }
7970: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7971: $changes{$item} = 1;
7972: }
7973: }
7974: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7975: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7976: }
7977: }
1.118 jms 7978: }
1.123 jms 7979: my $putresult;
7980: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7981: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7982: if ($putresult eq 'ok') {
7983: $resulttext = &mt('Changes made:').'<ul>';
7984: foreach my $item (sort(keys(%changes))) {
7985: if ($item eq 'submitbugs') {
7986: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7987: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7988: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7989: }
7990: }
7991: $resulttext .= '</ul>';
7992: } else {
7993: $resulttext = &mt('No changes made to help settings');
7994: $errors .= '<li><span class="LC_error">'.
7995: &mt('An error occurred storing the settings: [_1]',
7996: $putresult).'</span></li>';
7997: }
1.118 jms 7998: }
7999: if ($errors) {
1.160.6.5 raeburn 8000: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8001: $errors.'</ul>';
8002: }
8003: return $resulttext;
8004: }
8005:
1.121 raeburn 8006: sub modify_coursedefaults {
8007: my ($dom,%domconfig) = @_;
8008: my ($resulttext,$errors,%changes,%defaultshash);
8009: my %defaultchecked = ('canuse_pdfforms' => 'off');
8010: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 8011: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
8012: 'uploadquota_community');
8013: my @types = ('official','unofficial','community');
8014: my %staticdefaults = (
8015: anonsurvey_threshold => 10,
8016: uploadquota => 500,
8017: );
1.121 raeburn 8018:
8019: $defaultshash{'coursedefaults'} = {};
8020:
8021: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8022: if ($domconfig{'coursedefaults'} eq '') {
8023: $domconfig{'coursedefaults'} = {};
8024: }
8025: }
8026:
8027: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8028: foreach my $item (@toggles) {
8029: if ($defaultchecked{$item} eq 'on') {
8030: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8031: ($env{'form.'.$item} eq '0')) {
8032: $changes{$item} = 1;
1.160.6.16 raeburn 8033: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8034: $changes{$item} = 1;
8035: }
8036: } elsif ($defaultchecked{$item} eq 'off') {
8037: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8038: ($env{'form.'.$item} eq '1')) {
8039: $changes{$item} = 1;
8040: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8041: $changes{$item} = 1;
8042: }
8043: }
8044: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8045: }
1.160.6.21 raeburn 8046: foreach my $item (@numbers) {
8047: my ($currdef,$newdef);
8048: my $newdef = $env{'form.'.$item};
8049: if ($item eq 'anonsurvey_threshold') {
8050: $currdef = $domconfig{'coursedefaults'}{$item};
8051: $newdef =~ s/\D//g;
8052: if ($newdef eq '' || $newdef < 1) {
8053: $newdef = 1;
8054: }
8055: $defaultshash{'coursedefaults'}{$item} = $newdef;
8056: } else {
8057: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8058: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8059: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8060: }
8061: $newdef =~ s/[^\w.\-]//g;
8062: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8063: }
8064: if ($currdef ne $newdef) {
8065: my $staticdef;
8066: if ($item eq 'anonsurvey_threshold') {
8067: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8068: $changes{$item} = 1;
8069: }
8070: } else {
8071: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8072: $changes{'uploadquota'} = 1;
8073: }
8074: }
1.139 raeburn 8075: }
8076: }
1.160.6.16 raeburn 8077: my $officialcreds = $env{'form.official_credits'};
8078: $officialcreds =~ s/^[^\d\.]//g;
8079: my $unofficialcreds = $env{'form.unofficial_credits'};
8080: $unofficialcreds =~ s/^[^\d\.]//g;
8081: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8082: ($env{'form.coursecredits'} eq '1')) {
8083: $changes{'coursecredits'} = 1;
8084: } else {
8085: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
8086: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
8087: $changes{'coursecredits'} = 1;
8088: }
8089: }
8090: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8091: official => $officialcreds,
8092: unofficial => $unofficialcreds,
8093: }
1.121 raeburn 8094: }
8095: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8096: $dom);
8097: if ($putresult eq 'ok') {
1.160.6.16 raeburn 8098: my %domdefaults;
1.121 raeburn 8099: if (keys(%changes) > 0) {
1.160.6.21 raeburn 8100: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.160.6.16 raeburn 8101: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8102: if ($changes{'canuse_pdfforms'}) {
8103: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8104: }
8105: if ($changes{'coursecredits'}) {
8106: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8107: $domdefaults{'officialcredits'} =
8108: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8109: $domdefaults{'unofficialcredits'} =
8110: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8111: }
8112: }
1.160.6.21 raeburn 8113: if ($changes{'uploadquota'}) {
8114: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8115: foreach my $type (@types) {
8116: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8117: }
8118: }
8119: }
1.121 raeburn 8120: my $cachetime = 24*60*60;
8121: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8122: }
8123: $resulttext = &mt('Changes made:').'<ul>';
8124: foreach my $item (sort(keys(%changes))) {
8125: if ($item eq 'canuse_pdfforms') {
8126: if ($env{'form.'.$item} eq '1') {
8127: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8128: } else {
8129: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8130: }
1.139 raeburn 8131: } elsif ($item eq 'anonsurvey_threshold') {
8132: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 8133: } elsif ($item eq 'uploadquota') {
8134: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8135: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8136: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8137: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
8138: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8139: '</ul>'.
8140: '</li>';
8141: } else {
8142: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8143: }
1.160.6.16 raeburn 8144: } elsif ($item eq 'coursecredits') {
8145: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8146: if (($domdefaults{'officialcredits'} eq '') &&
8147: ($domdefaults{'unofficialcredits'} eq '')) {
8148: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8149: } else {
8150: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8151: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8152: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8153: '</ul>'.
8154: '</li>';
8155: }
8156: } else {
8157: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8158: }
1.140 raeburn 8159: }
1.121 raeburn 8160: }
8161: $resulttext .= '</ul>';
8162: } else {
8163: $resulttext = &mt('No changes made to course defaults');
8164: }
8165: } else {
8166: $resulttext = '<span class="LC_error">'.
8167: &mt('An error occurred: [_1]',$putresult).'</span>';
8168: }
8169: return $resulttext;
8170: }
8171:
1.137 raeburn 8172: sub modify_usersessions {
8173: my ($dom,%domconfig) = @_;
1.145 raeburn 8174: my @hostingtypes = ('version','excludedomain','includedomain');
8175: my @offloadtypes = ('primary','default');
8176: my %types = (
8177: remote => \@hostingtypes,
8178: hosted => \@hostingtypes,
8179: spares => \@offloadtypes,
8180: );
8181: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8182: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8183: my (%by_ip,%by_location,@intdoms);
8184: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8185: my @locations = sort(keys(%by_location));
1.137 raeburn 8186: my (%defaultshash,%changes);
8187: foreach my $prefix (@prefixes) {
8188: $defaultshash{'usersessions'}{$prefix} = {};
8189: }
8190: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8191: my $resulttext;
1.138 raeburn 8192: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8193: foreach my $prefix (@prefixes) {
1.145 raeburn 8194: next if ($prefix eq 'spares');
8195: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8196: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8197: if ($type eq 'version') {
8198: my $value = $env{'form.'.$prefix.'_'.$type};
8199: my $okvalue;
8200: if ($value ne '') {
8201: if (grep(/^\Q$value\E$/,@lcversions)) {
8202: $okvalue = $value;
8203: }
8204: }
8205: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8206: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8207: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8208: if ($inuse == 0) {
8209: $changes{$prefix}{$type} = 1;
8210: } else {
8211: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8212: $changes{$prefix}{$type} = 1;
8213: }
8214: if ($okvalue ne '') {
8215: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8216: }
8217: }
8218: } else {
8219: if (($inuse == 1) && ($okvalue ne '')) {
8220: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8221: $changes{$prefix}{$type} = 1;
8222: }
8223: }
8224: } else {
8225: if (($inuse == 1) && ($okvalue ne '')) {
8226: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8227: $changes{$prefix}{$type} = 1;
8228: }
8229: }
8230: } else {
8231: if (($inuse == 1) && ($okvalue ne '')) {
8232: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8233: $changes{$prefix}{$type} = 1;
8234: }
8235: }
8236: } else {
8237: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8238: my @okvals;
8239: foreach my $val (@vals) {
1.138 raeburn 8240: if ($val =~ /:/) {
8241: my @items = split(/:/,$val);
8242: foreach my $item (@items) {
8243: if (ref($by_location{$item}) eq 'ARRAY') {
8244: push(@okvals,$item);
8245: }
8246: }
8247: } else {
8248: if (ref($by_location{$val}) eq 'ARRAY') {
8249: push(@okvals,$val);
8250: }
1.137 raeburn 8251: }
8252: }
8253: @okvals = sort(@okvals);
8254: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8255: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8256: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8257: if ($inuse == 0) {
8258: $changes{$prefix}{$type} = 1;
8259: } else {
8260: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8261: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8262: if (@changed > 0) {
8263: $changes{$prefix}{$type} = 1;
8264: }
8265: }
8266: } else {
8267: if ($inuse == 1) {
8268: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8269: $changes{$prefix}{$type} = 1;
8270: }
8271: }
8272: } else {
8273: if ($inuse == 1) {
8274: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8275: $changes{$prefix}{$type} = 1;
8276: }
8277: }
8278: } else {
8279: if ($inuse == 1) {
8280: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8281: $changes{$prefix}{$type} = 1;
8282: }
8283: }
8284: }
8285: }
8286: }
1.145 raeburn 8287:
8288: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8289: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8290: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8291: my $savespares;
8292:
8293: foreach my $lonhost (sort(keys(%servers))) {
8294: my $serverhomeID =
8295: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8296: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8297: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8298: my %spareschg;
8299: foreach my $type (@{$types{'spares'}}) {
8300: my @okspares;
8301: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8302: foreach my $server (@checked) {
1.152 raeburn 8303: if (&Apache::lonnet::hostname($server) ne '') {
8304: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8305: unless (grep(/^\Q$server\E$/,@okspares)) {
8306: push(@okspares,$server);
8307: }
1.145 raeburn 8308: }
8309: }
8310: }
8311: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8312: my $newspare;
1.152 raeburn 8313: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8314: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8315: $newspare = $new;
8316: }
8317: }
1.152 raeburn 8318: my @spares;
8319: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8320: @spares = sort(@okspares,$newspare);
8321: } else {
8322: @spares = sort(@okspares);
8323: }
8324: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8325: if (ref($spareid{$lonhost}) eq 'HASH') {
8326: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8327: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8328: if (@diffs > 0) {
8329: $spareschg{$type} = 1;
8330: }
8331: }
8332: }
8333: }
8334: if (keys(%spareschg) > 0) {
8335: $changes{'spares'}{$lonhost} = \%spareschg;
8336: }
8337: }
8338:
8339: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8340: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8341: if (ref($changes{'spares'}) eq 'HASH') {
8342: if (keys(%{$changes{'spares'}}) > 0) {
8343: $savespares = 1;
8344: }
8345: }
8346: } else {
8347: $savespares = 1;
8348: }
8349: }
8350:
1.147 raeburn 8351: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8352: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8353: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8354: $dom);
8355: if ($putresult eq 'ok') {
8356: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8357: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8358: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8359: }
8360: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8361: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8362: }
8363: }
8364: my $cachetime = 24*60*60;
8365: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8366: if (keys(%changes) > 0) {
8367: my %lt = &usersession_titles();
8368: $resulttext = &mt('Changes made:').'<ul>';
8369: foreach my $prefix (@prefixes) {
8370: if (ref($changes{$prefix}) eq 'HASH') {
8371: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8372: if ($prefix eq 'spares') {
8373: if (ref($changes{$prefix}) eq 'HASH') {
8374: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8375: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8376: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8377: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8378: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8379: foreach my $type (@{$types{$prefix}}) {
8380: if ($changes{$prefix}{$lonhost}{$type}) {
8381: my $offloadto = &mt('None');
8382: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8383: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8384: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8385: }
1.145 raeburn 8386: }
1.147 raeburn 8387: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8388: }
1.137 raeburn 8389: }
8390: }
1.147 raeburn 8391: $resulttext .= '</li>';
1.137 raeburn 8392: }
8393: }
1.147 raeburn 8394: } else {
8395: foreach my $type (@{$types{$prefix}}) {
8396: if (defined($changes{$prefix}{$type})) {
8397: my $newvalue;
8398: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8399: if (ref($defaultshash{'usersessions'}{$prefix})) {
8400: if ($type eq 'version') {
8401: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8402: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8403: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8404: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8405: }
1.145 raeburn 8406: }
8407: }
8408: }
1.147 raeburn 8409: if ($newvalue eq '') {
8410: if ($type eq 'version') {
8411: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8412: } else {
8413: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8414: }
1.145 raeburn 8415: } else {
1.147 raeburn 8416: if ($type eq 'version') {
8417: $newvalue .= ' '.&mt('(or later)');
8418: }
8419: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8420: }
1.137 raeburn 8421: }
8422: }
8423: }
1.147 raeburn 8424: $resulttext .= '</ul>';
1.137 raeburn 8425: }
8426: }
1.147 raeburn 8427: $resulttext .= '</ul>';
8428: } else {
8429: $resulttext = $nochgmsg;
1.137 raeburn 8430: }
8431: } else {
8432: $resulttext = '<span class="LC_error">'.
8433: &mt('An error occurred: [_1]',$putresult).'</span>';
8434: }
8435: } else {
1.147 raeburn 8436: $resulttext = $nochgmsg;
1.137 raeburn 8437: }
8438: return $resulttext;
8439: }
8440:
1.150 raeburn 8441: sub modify_loadbalancing {
8442: my ($dom,%domconfig) = @_;
8443: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8444: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8445: my ($othertitle,$usertypes,$types) =
8446: &Apache::loncommon::sorted_inst_types($dom);
8447: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8448: my @sparestypes = ('primary','default');
8449: my %typetitles = &sparestype_titles();
8450: my $resulttext;
1.160.6.7 raeburn 8451: my (%currbalancer,%currtargets,%currrules,%existing);
8452: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8453: %existing = %{$domconfig{'loadbalancing'}};
8454: }
8455: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8456: \%currtargets,\%currrules);
8457: my ($saveloadbalancing,%defaultshash,%changes);
8458: my ($alltypes,$othertypes,$titles) =
8459: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8460: my %ruletitles = &offloadtype_text();
8461: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8462: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8463: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8464: if ($balancer eq '') {
8465: next;
8466: }
8467: if (!exists($servers{$balancer})) {
8468: if (exists($currbalancer{$balancer})) {
8469: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8470: }
1.160.6.7 raeburn 8471: next;
8472: }
8473: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8474: push(@{$changes{'delete'}},$balancer);
8475: next;
8476: }
8477: if (!exists($currbalancer{$balancer})) {
8478: push(@{$changes{'add'}},$balancer);
8479: }
8480: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8481: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8482: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8483: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8484: $saveloadbalancing = 1;
8485: }
8486: foreach my $sparetype (@sparestypes) {
8487: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8488: my @offloadto;
8489: foreach my $target (@targets) {
8490: if (($servers{$target}) && ($target ne $balancer)) {
8491: if ($sparetype eq 'default') {
8492: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8493: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8494: }
8495: }
1.160.6.7 raeburn 8496: unless(grep(/^\Q$target\E$/,@offloadto)) {
8497: push(@offloadto,$target);
8498: }
1.150 raeburn 8499: }
1.160.6.7 raeburn 8500: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8501: }
8502: }
1.160.6.7 raeburn 8503: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8504: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8505: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8506: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8507: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8508: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8509: }
1.160.6.7 raeburn 8510: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8511: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8512: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8513: }
8514: }
8515: }
8516: } else {
1.160.6.7 raeburn 8517: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8518: foreach my $sparetype (@sparestypes) {
8519: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8520: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8521: $changes{'curr'}{$balancer}{'targets'} = 1;
8522: }
1.150 raeburn 8523: }
8524: }
1.160.6.7 raeburn 8525: }
1.150 raeburn 8526: }
8527: my $ishomedom;
1.160.6.7 raeburn 8528: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8529: $ishomedom = 1;
1.150 raeburn 8530: }
8531: if (ref($alltypes) eq 'ARRAY') {
8532: foreach my $type (@{$alltypes}) {
8533: my $rule;
1.160.6.7 raeburn 8534: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8535: (!$ishomedom)) {
1.160.6.7 raeburn 8536: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8537: }
8538: if ($rule eq 'specific') {
8539: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8540: }
1.160.6.7 raeburn 8541: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8542: if (ref($currrules{$balancer}) eq 'HASH') {
8543: if ($rule ne $currrules{$balancer}{$type}) {
8544: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8545: }
8546: } elsif ($rule ne '') {
1.160.6.7 raeburn 8547: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8548: }
8549: }
8550: }
1.160.6.7 raeburn 8551: }
8552: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8553: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8554: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8555: $defaultshash{'loadbalancing'} = {};
8556: }
8557: my $putresult = &Apache::lonnet::put_dom('configuration',
8558: \%defaultshash,$dom);
8559:
8560: if ($putresult eq 'ok') {
8561: if (keys(%changes) > 0) {
8562: if (ref($changes{'delete'}) eq 'ARRAY') {
8563: foreach my $balancer (sort(@{$changes{'delete'}})) {
8564: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8565: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8566: }
1.160.6.7 raeburn 8567: }
8568: if (ref($changes{'add'}) eq 'ARRAY') {
8569: foreach my $balancer (sort(@{$changes{'add'}})) {
8570: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8571: }
8572: }
8573: if (ref($changes{'curr'}) eq 'HASH') {
8574: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8575: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8576: if ($changes{'curr'}{$balancer}{'targets'}) {
8577: my %offloadstr;
8578: foreach my $sparetype (@sparestypes) {
8579: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8580: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8581: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8582: }
8583: }
1.150 raeburn 8584: }
1.160.6.7 raeburn 8585: if (keys(%offloadstr) == 0) {
8586: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8587: } else {
1.160.6.7 raeburn 8588: my $showoffload;
8589: foreach my $sparetype (@sparestypes) {
8590: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8591: if (defined($offloadstr{$sparetype})) {
8592: $showoffload .= $offloadstr{$sparetype};
8593: } else {
8594: $showoffload .= &mt('None');
8595: }
8596: $showoffload .= (' 'x3);
8597: }
8598: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8599: }
8600: }
8601: }
1.160.6.7 raeburn 8602: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8603: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8604: foreach my $type (@{$alltypes}) {
8605: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8606: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8607: my $balancetext;
8608: if ($rule eq '') {
8609: $balancetext = $ruletitles{'default'};
8610: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8611: $balancetext = $ruletitles{$rule};
8612: } else {
8613: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8614: }
8615: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8616: }
8617: }
8618: }
8619: }
1.160.6.7 raeburn 8620: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8621: }
1.160.6.7 raeburn 8622: }
8623: if ($resulttext ne '') {
8624: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8625: } else {
8626: $resulttext = $nochgmsg;
8627: }
8628: } else {
1.160.6.7 raeburn 8629: $resulttext = $nochgmsg;
1.150 raeburn 8630: }
8631: } else {
1.160.6.7 raeburn 8632: $resulttext = '<span class="LC_error">'.
8633: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8634: }
8635: } else {
1.160.6.7 raeburn 8636: $resulttext = $nochgmsg;
1.150 raeburn 8637: }
8638: return $resulttext;
8639: }
8640:
1.48 raeburn 8641: sub recurse_check {
8642: my ($chkcats,$categories,$depth,$name) = @_;
8643: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8644: my $chg = 0;
8645: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8646: my $category = $chkcats->[$depth]{$name}[$j];
8647: my $item;
8648: if ($category eq '') {
8649: $chg ++;
8650: } else {
8651: my $deeper = $depth + 1;
8652: $item = &escape($category).':'.&escape($name).':'.$depth;
8653: if ($chg) {
8654: $categories->{$item} -= $chg;
8655: }
8656: &recurse_check($chkcats,$categories,$deeper,$category);
8657: $deeper --;
8658: }
8659: }
8660: }
8661: return;
8662: }
8663:
8664: sub recurse_cat_deletes {
8665: my ($item,$coursecategories,$deletions) = @_;
8666: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8667: my $subdepth = $depth + 1;
8668: if (ref($coursecategories) eq 'HASH') {
8669: foreach my $subitem (keys(%{$coursecategories})) {
8670: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8671: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8672: delete($coursecategories->{$subitem});
8673: $deletions->{$subitem} = 1;
8674: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8675: }
8676: }
8677: }
8678: return;
8679: }
8680:
1.125 raeburn 8681: sub get_active_dcs {
8682: my ($dom) = @_;
1.160.6.16 raeburn 8683: my $now = time;
8684: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8685: my %domcoords;
8686: my $numdcs = 0;
8687: foreach my $server (keys(%dompersonnel)) {
8688: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8689: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 8690: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8691: }
8692: }
8693: return %domcoords;
8694: }
8695:
8696: sub active_dc_picker {
1.160.6.16 raeburn 8697: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8698: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 8699: my @domcoord = keys(%domcoords);
8700: if (keys(%currhash)) {
8701: foreach my $dc (keys(%currhash)) {
8702: unless (exists($domcoords{$dc})) {
8703: push(@domcoord,$dc);
8704: }
8705: }
8706: }
8707: @domcoord = sort(@domcoord);
8708: my $numdcs = scalar(@domcoord);
8709: my $rows = 0;
8710: my $table;
1.125 raeburn 8711: if ($numdcs > 1) {
1.160.6.16 raeburn 8712: $table = '<table>';
8713: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8714: my $rem = $i%($numinrow);
8715: if ($rem == 0) {
8716: if ($i > 0) {
1.160.6.16 raeburn 8717: $table .= '</tr>';
1.125 raeburn 8718: }
1.160.6.16 raeburn 8719: $table .= '<tr>';
8720: $rows ++;
1.125 raeburn 8721: }
1.160.6.16 raeburn 8722: my $check = '';
8723: if ($inputtype eq 'radio') {
8724: if (keys(%currhash) == 0) {
8725: if (!$i) {
8726: $check = ' checked="checked"';
8727: }
8728: } elsif (exists($currhash{$domcoord[$i]})) {
8729: $check = ' checked="checked"';
8730: }
8731: } else {
8732: if (exists($currhash{$domcoord[$i]})) {
8733: $check = ' checked="checked"';
1.125 raeburn 8734: }
8735: }
1.160.6.16 raeburn 8736: if ($i == @domcoord - 1) {
1.125 raeburn 8737: my $colsleft = $numinrow - $rem;
8738: if ($colsleft > 1) {
1.160.6.16 raeburn 8739: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8740: } else {
1.160.6.16 raeburn 8741: $table .= '<td class="LC_left_item">';
1.125 raeburn 8742: }
8743: } else {
1.160.6.16 raeburn 8744: $table .= '<td class="LC_left_item">';
8745: }
8746: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8747: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8748: $table .= '<span class="LC_nobreak"><label>'.
8749: '<input type="'.$inputtype.'" name="'.$name.'"'.
8750: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8751: if ($user ne $dcname.':'.$dcdom) {
8752: $table .= ' ('.$dcname.':'.$dcdom.')'.
8753: '</label></span></td>';
1.125 raeburn 8754: }
8755: }
1.160.6.16 raeburn 8756: $table .= '</tr></table>';
8757: } elsif ($numdcs == 1) {
8758: if ($inputtype eq 'radio') {
8759: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8760: } else {
8761: my $check;
8762: if (exists($currhash{$domcoord[0]})) {
8763: $check = ' checked="checked"';
8764: }
8765: $table .= '<input type="checkbox" name="'.$name.'" '.
8766: 'value="'.$domcoord[0].'"'.$check.' />';
8767: $rows ++;
8768: }
1.125 raeburn 8769: }
1.160.6.16 raeburn 8770: return ($numdcs,$table,$rows);
1.125 raeburn 8771: }
8772:
1.137 raeburn 8773: sub usersession_titles {
8774: return &Apache::lonlocal::texthash(
8775: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8776: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8777: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8778: version => 'LON-CAPA version requirement',
1.138 raeburn 8779: excludedomain => 'Allow all, but exclude specific domains',
8780: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8781: primary => 'Primary (checked first)',
1.154 raeburn 8782: default => 'Default',
1.137 raeburn 8783: );
8784: }
8785:
1.152 raeburn 8786: sub id_for_thisdom {
8787: my (%servers) = @_;
8788: my %altids;
8789: foreach my $server (keys(%servers)) {
8790: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8791: if ($serverhome ne $server) {
8792: $altids{$serverhome} = $server;
8793: }
8794: }
8795: return %altids;
8796: }
8797:
1.150 raeburn 8798: sub count_servers {
8799: my ($currbalancer,%servers) = @_;
8800: my (@spares,$numspares);
8801: foreach my $lonhost (sort(keys(%servers))) {
8802: next if ($currbalancer eq $lonhost);
8803: push(@spares,$lonhost);
8804: }
8805: if ($currbalancer) {
8806: $numspares = scalar(@spares);
8807: } else {
8808: $numspares = scalar(@spares) - 1;
8809: }
8810: return ($numspares,@spares);
8811: }
8812:
8813: sub lonbalance_targets_js {
1.160.6.7 raeburn 8814: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8815: my $select = &mt('Select');
8816: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8817: if (ref($servers) eq 'HASH') {
8818: $alltargets = join("','",sort(keys(%{$servers})));
8819: my @homedoms;
8820: foreach my $server (sort(keys(%{$servers}))) {
8821: if (&Apache::lonnet::host_domain($server) eq $dom) {
8822: push(@homedoms,'1');
8823: } else {
8824: push(@homedoms,'0');
8825: }
8826: }
8827: $allishome = join("','",@homedoms);
8828: }
8829: if (ref($types) eq 'ARRAY') {
8830: if (@{$types} > 0) {
8831: @alltypes = @{$types};
8832: }
8833: }
8834: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8835: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8836: my (%currbalancer,%currtargets,%currrules,%existing);
8837: if (ref($settings) eq 'HASH') {
8838: %existing = %{$settings};
8839: }
8840: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8841: \%currtargets,\%currrules);
8842: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8843: return <<"END";
8844:
8845: <script type="text/javascript">
8846: // <![CDATA[
8847:
1.160.6.7 raeburn 8848: currBalancers = new Array('$balancers');
8849:
8850: function toggleTargets(balnum) {
8851: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8852: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8853: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8854: var prevbalancer = prevhostitem.value;
8855: var baltotal = document.getElementById('loadbalancing_total').value;
8856: prevhostitem.value = balancer;
8857: if (prevbalancer != '') {
8858: var prevIdx = currBalancers.indexOf(prevbalancer);
8859: if (prevIdx != -1) {
8860: currBalancers.splice(prevIdx,1);
8861: }
8862: }
1.150 raeburn 8863: if (balancer == '') {
1.160.6.7 raeburn 8864: hideSpares(balnum);
1.150 raeburn 8865: } else {
1.160.6.7 raeburn 8866: var currIdx = currBalancers.indexOf(balancer);
8867: if (currIdx == -1) {
8868: currBalancers.push(balancer);
8869: }
1.150 raeburn 8870: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8871: var ishomedom = homedoms[lonhostitem.selectedIndex];
8872: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8873: }
1.160.6.7 raeburn 8874: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8875: return;
8876: }
8877:
1.160.6.7 raeburn 8878: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8879: var alltargets = new Array('$alltargets');
8880: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8881: var offloadtypes = new Array('primary','default');
8882:
1.160.6.7 raeburn 8883: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8884: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8885:
1.151 raeburn 8886: for (var i=0; i<offloadtypes.length; i++) {
8887: var count = 0;
8888: for (var j=0; j<alltargets.length; j++) {
8889: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8890: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8891: item.value = alltargets[j];
8892: item.style.textAlign='left';
8893: item.style.textFace='normal';
8894: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8895: if (currBalancers.indexOf(alltargets[j]) == -1) {
8896: item.disabled = '';
8897: } else {
8898: item.disabled = 'disabled';
8899: item.checked = false;
8900: }
1.151 raeburn 8901: count ++;
8902: }
1.150 raeburn 8903: }
8904: }
1.151 raeburn 8905: for (var k=0; k<insttypes.length; k++) {
8906: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8907: if (ishomedom == 1) {
1.160.6.7 raeburn 8908: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8909: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8910: } else {
1.160.6.7 raeburn 8911: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8912: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8913:
8914: }
8915: } else {
1.160.6.7 raeburn 8916: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8917: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8918: }
1.151 raeburn 8919: if ((insttypes[k] != '_LC_external') &&
8920: ((insttypes[k] != '_LC_internetdom') ||
8921: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8922: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8923: item.options.length = 0;
8924: item.options[0] = new Option("","",true,true);
8925: var idx = 0;
1.151 raeburn 8926: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8927: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8928: idx ++;
8929: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8930:
1.150 raeburn 8931: }
8932: }
8933: }
8934: }
8935: return;
8936: }
8937:
1.160.6.7 raeburn 8938: function hideSpares(balnum) {
1.150 raeburn 8939: var alltargets = new Array('$alltargets');
8940: var insttypes = new Array('$allinsttypes');
8941: var offloadtypes = new Array('primary','default');
8942:
1.160.6.7 raeburn 8943: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8944: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8945:
8946: var total = alltargets.length - 1;
8947: for (var i=0; i<offloadtypes; i++) {
8948: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8949: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8950: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8951: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8952: }
1.150 raeburn 8953: }
8954: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8955: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8956: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8957: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8958: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8959: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8960: }
8961: }
8962: return;
8963: }
8964:
1.160.6.7 raeburn 8965: function checkOffloads(item,balnum,type) {
1.150 raeburn 8966: var alltargets = new Array('$alltargets');
8967: var offloadtypes = new Array('primary','default');
8968: if (item.checked) {
8969: var total = alltargets.length - 1;
8970: var other;
8971: if (type == offloadtypes[0]) {
1.151 raeburn 8972: other = offloadtypes[1];
1.150 raeburn 8973: } else {
1.151 raeburn 8974: other = offloadtypes[0];
1.150 raeburn 8975: }
8976: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8977: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8978: if (server == item.value) {
1.160.6.7 raeburn 8979: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8980: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8981: }
8982: }
8983: }
8984: }
8985: return;
8986: }
8987:
1.160.6.7 raeburn 8988: function singleServerToggle(balnum,type) {
8989: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8990: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 8991: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8992: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8993:
8994: } else {
1.160.6.7 raeburn 8995: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8996: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8997: }
8998: return;
8999: }
9000:
1.160.6.7 raeburn 9001: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9002: if (type == '_LC_external') {
9003: return;
9004: }
1.160.6.7 raeburn 9005: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9006: for (var i=0; i<typesRules.length; i++) {
9007: if (formname.elements[typesRules[i]].checked) {
9008: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 9009: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9010: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9011: } else {
1.160.6.7 raeburn 9012: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9013: }
9014: }
9015: }
9016: return;
9017: }
9018:
9019: function balancerDeleteChange(balnum) {
9020: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9021: var baltotal = document.getElementById('loadbalancing_total').value;
9022: var addtarget;
9023: var removetarget;
9024: var action = 'delete';
9025: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9026: var lonhost = hostitem.value;
9027: var currIdx = currBalancers.indexOf(lonhost);
9028: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9029: if (currIdx != -1) {
9030: currBalancers.splice(currIdx,1);
9031: }
9032: addtarget = lonhost;
9033: } else {
9034: if (currIdx == -1) {
9035: currBalancers.push(lonhost);
9036: }
9037: removetarget = lonhost;
9038: action = 'undelete';
9039: }
9040: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9041: }
9042: return;
9043: }
9044:
9045: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9046: if (baltotal > 1) {
9047: var offloadtypes = new Array('primary','default');
9048: var alltargets = new Array('$alltargets');
9049: var insttypes = new Array('$allinsttypes');
9050: for (var i=0; i<baltotal; i++) {
9051: if (i != balnum) {
9052: for (var j=0; j<offloadtypes.length; j++) {
9053: var total = alltargets.length - 1;
9054: for (var k=0; k<total; k++) {
9055: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9056: var server = serveritem.value;
9057: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9058: if (server == addtarget) {
9059: serveritem.disabled = '';
9060: }
9061: }
9062: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9063: if (server == removetarget) {
9064: serveritem.disabled = 'disabled';
9065: serveritem.checked = false;
9066: }
9067: }
9068: }
9069: }
9070: for (var j=0; j<insttypes.length; j++) {
9071: if (insttypes[j] != '_LC_external') {
9072: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9073: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9074: var currSel = singleserver.selectedIndex;
9075: var currVal = singleserver.options[currSel].value;
9076: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9077: var numoptions = singleserver.options.length;
9078: var needsnew = 1;
9079: for (var k=0; k<numoptions; k++) {
9080: if (singleserver.options[k] == addtarget) {
9081: needsnew = 0;
9082: break;
9083: }
9084: }
9085: if (needsnew == 1) {
9086: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9087: }
9088: }
9089: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9090: singleserver.options.length = 0;
9091: if ((currVal) && (currVal != removetarget)) {
9092: singleserver.options[0] = new Option("","",false,false);
9093: } else {
9094: singleserver.options[0] = new Option("","",true,true);
9095: }
9096: var idx = 0;
9097: for (var m=0; m<alltargets.length; m++) {
9098: if (currBalancers.indexOf(alltargets[m]) == -1) {
9099: idx ++;
9100: if (currVal == alltargets[m]) {
9101: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9102: } else {
9103: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9104: }
9105: }
9106: }
9107: }
9108: }
9109: }
9110: }
1.150 raeburn 9111: }
9112: }
9113: }
9114: return;
9115: }
9116:
1.152 raeburn 9117: // ]]>
9118: </script>
9119:
9120: END
9121: }
9122:
9123: sub new_spares_js {
9124: my @sparestypes = ('primary','default');
9125: my $types = join("','",@sparestypes);
9126: my $select = &mt('Select');
9127: return <<"END";
9128:
9129: <script type="text/javascript">
9130: // <![CDATA[
9131:
9132: function updateNewSpares(formname,lonhost) {
9133: var types = new Array('$types');
9134: var include = new Array();
9135: var exclude = new Array();
9136: for (var i=0; i<types.length; i++) {
9137: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9138: for (var j=0; j<spareboxes.length; j++) {
9139: if (formname.elements[spareboxes[j]].checked) {
9140: exclude.push(formname.elements[spareboxes[j]].value);
9141: } else {
9142: include.push(formname.elements[spareboxes[j]].value);
9143: }
9144: }
9145: }
9146: for (var i=0; i<types.length; i++) {
9147: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9148: var selIdx = newSpare.selectedIndex;
9149: var currnew = newSpare.options[selIdx].value;
9150: var okSpares = new Array();
9151: for (var j=0; j<newSpare.options.length; j++) {
9152: var possible = newSpare.options[j].value;
9153: if (possible != '') {
9154: if (exclude.indexOf(possible) == -1) {
9155: okSpares.push(possible);
9156: } else {
9157: if (currnew == possible) {
9158: selIdx = 0;
9159: }
9160: }
9161: }
9162: }
9163: for (var k=0; k<include.length; k++) {
9164: if (okSpares.indexOf(include[k]) == -1) {
9165: okSpares.push(include[k]);
9166: }
9167: }
9168: okSpares.sort();
9169: newSpare.options.length = 0;
9170: if (selIdx == 0) {
9171: newSpare.options[0] = new Option("$select","",true,true);
9172: } else {
9173: newSpare.options[0] = new Option("$select","",false,false);
9174: }
9175: for (var m=0; m<okSpares.length; m++) {
9176: var idx = m+1;
9177: var selThis = 0;
9178: if (selIdx != 0) {
9179: if (okSpares[m] == currnew) {
9180: selThis = 1;
9181: }
9182: }
9183: if (selThis == 1) {
9184: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9185: } else {
9186: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9187: }
9188: }
9189: }
9190: return;
9191: }
9192:
9193: function checkNewSpares(lonhost,type) {
9194: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9195: var chosen = newSpare.options[newSpare.selectedIndex].value;
9196: if (chosen != '') {
9197: var othertype;
9198: var othernewSpare;
9199: if (type == 'primary') {
9200: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9201: }
9202: if (type == 'default') {
9203: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9204: }
9205: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9206: othernewSpare.selectedIndex = 0;
9207: }
9208: }
9209: return;
9210: }
9211:
9212: // ]]>
9213: </script>
9214:
9215: END
9216:
9217: }
9218:
9219: sub common_domprefs_js {
9220: return <<"END";
9221:
9222: <script type="text/javascript">
9223: // <![CDATA[
9224:
1.150 raeburn 9225: function getIndicesByName(formname,item) {
1.152 raeburn 9226: var group = new Array();
1.150 raeburn 9227: for (var i=0;i<formname.elements.length;i++) {
9228: if (formname.elements[i].name == item) {
1.152 raeburn 9229: group.push(formname.elements[i].id);
1.150 raeburn 9230: }
9231: }
1.152 raeburn 9232: return group;
1.150 raeburn 9233: }
9234:
9235: // ]]>
9236: </script>
9237:
9238: END
1.152 raeburn 9239:
1.150 raeburn 9240: }
9241:
1.160.6.5 raeburn 9242: sub recaptcha_js {
9243: my %lt = &captcha_phrases();
9244: return <<"END";
9245:
9246: <script type="text/javascript">
9247: // <![CDATA[
9248:
9249: function updateCaptcha(caller,context) {
9250: var privitem;
9251: var pubitem;
9252: var privtext;
9253: var pubtext;
9254: if (document.getElementById(context+'_recaptchapub')) {
9255: pubitem = document.getElementById(context+'_recaptchapub');
9256: } else {
9257: return;
9258: }
9259: if (document.getElementById(context+'_recaptchapriv')) {
9260: privitem = document.getElementById(context+'_recaptchapriv');
9261: } else {
9262: return;
9263: }
9264: if (document.getElementById(context+'_recaptchapubtxt')) {
9265: pubtext = document.getElementById(context+'_recaptchapubtxt');
9266: } else {
9267: return;
9268: }
9269: if (document.getElementById(context+'_recaptchaprivtxt')) {
9270: privtext = document.getElementById(context+'_recaptchaprivtxt');
9271: } else {
9272: return;
9273: }
9274: if (caller.checked) {
9275: if (caller.value == 'recaptcha') {
9276: pubitem.type = 'text';
9277: privitem.type = 'text';
9278: pubitem.size = '40';
9279: privitem.size = '40';
9280: pubtext.innerHTML = "$lt{'pub'}";
9281: privtext.innerHTML = "$lt{'priv'}";
9282: } else {
9283: pubitem.type = 'hidden';
9284: privitem.type = 'hidden';
9285: pubtext.innerHTML = '';
9286: privtext.innerHTML = '';
9287: }
9288: }
9289: return;
9290: }
9291:
9292: // ]]>
9293: </script>
9294:
9295: END
9296:
9297: }
9298:
1.160.6.16 raeburn 9299: sub credits_js {
9300: return <<"END";
9301:
9302: <script type="text/javascript">
9303: // <![CDATA[
9304:
9305: function toggleCredits(domForm) {
9306: if (document.getElementById('credits')) {
9307: creditsitem = document.getElementById('credits');
9308: var creditsLength = domForm.coursecredits.length;
9309: if (creditsLength) {
9310: var currval;
9311: for (var i=0; i<creditsLength; i++) {
9312: if (domForm.coursecredits[i].checked) {
9313: currval = domForm.coursecredits[i].value;
9314: }
9315: }
9316: if (currval == 1) {
9317: creditsitem.style.display = 'block';
9318: } else {
9319: creditsitem.style.display = 'none';
9320: }
9321: }
9322: }
9323: return;
9324: }
9325:
9326: // ]]>
9327: </script>
9328:
9329: END
9330:
9331: }
9332:
1.160.6.5 raeburn 9333: sub captcha_phrases {
9334: return &Apache::lonlocal::texthash (
9335: priv => 'Private key',
9336: pub => 'Public key',
9337: original => 'original (CAPTCHA)',
9338: recaptcha => 'successor (ReCAPTCHA)',
9339: notused => 'unused',
9340: );
9341: }
9342:
1.3 raeburn 9343: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>