Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.10
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.10! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.9 2012/12/12 01:57:37 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
48: for use by individuals affliated with the institution. Accordingly, each domain
49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
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,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
1.104 raeburn 108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 109: which have the following effects:
110:
111: 0
112:
113: =over
114:
115: - course requests are not allowed for this course types/affiliation
116:
117: =back
118:
1.104 raeburn 119: approval
1.101 raeburn 120:
121: =over
122:
123: - course requests must be approved by a Doman Coordinator in the
124: course's domain
125:
126: =back
127:
128: validate
129:
130: =over
131:
132: - an institutional validation (e.g., check requestor is instructor
133: of record) needs to be passed before the course will be created. The required
134: validation is in localenroll.pm on the primary library server for the course
135: domain.
136:
137: =back
138:
139: autolimit
140:
141: =over
142:
1.143 raeburn 143: - course requests will be processed automatically up to a limit of
1.101 raeburn 144: N requests for the course type for the particular requestor.
145: If N is undefined, there is no limit to the number of course requests
146: which a course owner may submit and have processed automatically.
147:
148: =back
149:
150: =item modify_quotas()
151:
152: =back
153:
154: =cut
155:
1.1 raeburn 156: package Apache::domainprefs;
157:
158: use strict;
159: use Apache::Constants qw(:common :http);
160: use Apache::lonnet;
161: use Apache::loncommon();
162: use Apache::lonhtmlcommon();
163: use Apache::lonlocal;
1.43 raeburn 164: use Apache::lonmsg();
1.91 raeburn 165: use Apache::lonconfigsettings;
1.69 raeburn 166: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 167: use LONCAPA::Enrollment;
1.81 raeburn 168: use LONCAPA::lonauthcgi();
1.9 raeburn 169: use File::Copy;
1.43 raeburn 170: use Locale::Language;
1.62 raeburn 171: use DateTime::TimeZone;
1.68 raeburn 172: use DateTime::Locale;
1.1 raeburn 173:
1.155 raeburn 174: my $registered_cleanup;
175: my $modified_urls;
176:
1.1 raeburn 177: sub handler {
178: my $r=shift;
179: if ($r->header_only) {
180: &Apache::loncommon::content_type($r,'text/html');
181: $r->send_http_header;
182: return OK;
183: }
184:
1.91 raeburn 185: my $context = 'domain';
1.1 raeburn 186: my $dom = $env{'request.role.domain'};
1.5 albertel 187: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 188: if (&Apache::lonnet::allowed('mau',$dom)) {
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: } else {
192: $env{'user.error.msg'}=
193: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
194: return HTTP_NOT_ACCEPTABLE;
195: }
1.155 raeburn 196:
197: $registered_cleanup=0;
198: @{$modified_urls}=();
199:
1.1 raeburn 200: &Apache::lonhtmlcommon::clear_breadcrumbs();
201: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 202: ['phase','actions']);
1.30 raeburn 203: my $phase = 'pickactions';
1.3 raeburn 204: if ( exists($env{'form.phase'}) ) {
205: $phase = $env{'form.phase'};
206: }
1.150 raeburn 207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 208: my %domconfig =
1.6 raeburn 209: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 210: 'quotas','autoenroll','autoupdate','autocreate',
211: 'directorysrch','usercreation','usermodification',
212: 'contacts','defaults','scantron','coursecategories',
1.160.6.1 raeburn 213: 'serverstatuses','requestcourses','usersessions',
1.160.6.5 raeburn 214: 'loadbalancing','requestauthor'],$dom);
1.43 raeburn 215: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 216: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 217: 'usercreation','usermodification','scantron',
1.160.6.5 raeburn 218: 'requestcourses','requestauthor','coursecategories',
219: 'serverstatuses','usersessions');
1.160.6.7 raeburn 220: my %existing;
221: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
222: %existing = %{$domconfig{'loadbalancing'}};
223: }
224: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 225: push(@prefs_order,'loadbalancing');
226: }
1.30 raeburn 227: my %prefs = (
228: 'rolecolors' =>
229: { text => 'Default color schemes',
1.67 raeburn 230: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 231: header => [{col1 => 'Student Settings',
232: col2 => '',},
233: {col1 => 'Coordinator Settings',
234: col2 => '',},
235: {col1 => 'Author Settings',
236: col2 => '',},
237: {col1 => 'Administrator Settings',
238: col2 => '',}],
239: },
1.110 raeburn 240: 'login' =>
1.30 raeburn 241: { text => 'Log-in page options',
1.67 raeburn 242: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 243: header => [{col1 => 'Log-in Page Items',
244: col2 => '',},
245: {col1 => 'Log-in Help',
246: col2 => 'Value'}],
1.30 raeburn 247: },
1.43 raeburn 248: 'defaults' =>
1.141 raeburn 249: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 250: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 251: header => [{col1 => 'Setting',
252: col2 => 'Value'}],
253: },
1.30 raeburn 254: 'quotas' =>
1.160.6.4 raeburn 255: { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67 raeburn 256: help => 'Domain_Configuration_Quotas',
1.77 raeburn 257: header => [{col1 => 'User affiliation',
1.72 raeburn 258: col2 => 'Available tools',
259: col3 => 'Portfolio quota',}],
1.30 raeburn 260: },
261: 'autoenroll' =>
262: { text => 'Auto-enrollment settings',
1.67 raeburn 263: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 264: header => [{col1 => 'Configuration setting',
265: col2 => 'Value(s)'}],
266: },
267: 'autoupdate' =>
268: { text => 'Auto-update settings',
1.67 raeburn 269: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 270: header => [{col1 => 'Setting',
271: col2 => 'Value',},
1.131 raeburn 272: {col1 => 'Setting',
273: col2 => 'Affiliation'},
1.43 raeburn 274: {col1 => 'User population',
1.131 raeburn 275: col2 => 'Updateable user data'}],
1.30 raeburn 276: },
1.125 raeburn 277: 'autocreate' =>
278: { text => 'Auto-course creation settings',
279: help => 'Domain_Configuration_Auto_Creation',
280: header => [{col1 => 'Configuration Setting',
281: col2 => 'Value',}],
282: },
1.30 raeburn 283: 'directorysrch' =>
284: { text => 'Institutional directory searches',
1.67 raeburn 285: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 286: header => [{col1 => 'Setting',
287: col2 => 'Value',}],
288: },
289: 'contacts' =>
290: { text => 'Contact Information',
1.67 raeburn 291: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',}],
294: },
295:
296: 'usercreation' =>
297: { text => 'User creation',
1.67 raeburn 298: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 299: header => [{col1 => 'Format rule type',
300: col2 => 'Format rules in force'},
1.34 raeburn 301: {col1 => 'User account creation',
302: col2 => 'Usernames which may be created',},
1.30 raeburn 303: {col1 => 'Context',
1.43 raeburn 304: col2 => 'Assignable authentication types'}],
1.30 raeburn 305: },
1.69 raeburn 306: 'usermodification' =>
1.33 raeburn 307: { text => 'User modification',
1.67 raeburn 308: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 309: header => [{col1 => 'Target user has role',
310: col2 => 'User information updateable in author context'},
311: {col1 => 'Target user has role',
1.63 raeburn 312: col2 => 'User information updateable in course context'},
313: {col1 => "Status of user",
314: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 315: },
1.69 raeburn 316: 'scantron' =>
1.95 www 317: { text => 'Bubblesheet format file',
1.67 raeburn 318: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 319: header => [ {col1 => 'Item',
320: col2 => '',
321: }],
322: },
1.86 raeburn 323: 'requestcourses' =>
324: {text => 'Request creation of courses',
325: help => 'Domain_Configuration_Request_Courses',
326: header => [{col1 => 'User affiliation',
1.102 raeburn 327: col2 => 'Availability/Processing of requests',},
328: {col1 => 'Setting',
329: col2 => 'Value'}],
1.86 raeburn 330: },
1.160.6.5 raeburn 331: 'requestauthor' =>
332: {text => 'Request authoring space',
333: help => 'Domain_Configuration_Request_Author',
334: header => [{col1 => 'User affiliation',
335: col2 => 'Availability/Processing of requests',},
336: {col1 => 'Setting',
337: col2 => 'Value'}],
338: },
1.69 raeburn 339: 'coursecategories' =>
1.120 raeburn 340: { text => 'Cataloging of courses/communities',
1.67 raeburn 341: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 342: header => [{col1 => 'Category settings',
1.57 raeburn 343: col2 => '',},
344: {col1 => 'Categories',
345: col2 => '',
346: }],
1.69 raeburn 347: },
348: 'serverstatuses' =>
1.77 raeburn 349: {text => 'Access to server status pages',
1.69 raeburn 350: help => 'Domain_Configuration_Server_Status',
351: header => [{col1 => 'Status Page',
352: col2 => 'Other named users',
353: col3 => 'Specific IPs',
354: }],
355: },
1.141 raeburn 356: 'usersessions' =>
1.145 raeburn 357: {text => 'User session hosting/offloading',
1.137 raeburn 358: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 359: header => [{col1 => 'Domain server',
360: col2 => 'Servers to offload sessions to when busy'},
361: {col1 => 'Hosting of users from other domains',
1.137 raeburn 362: col2 => 'Rules'},
363: {col1 => "Hosting domain's own users elsewhere",
364: col2 => 'Rules'}],
365: },
1.150 raeburn 366: 'loadbalancing' =>
1.160.6.7 raeburn 367: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 368: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 369: header => [{col1 => 'Balancers',
1.150 raeburn 370: col2 => 'Default destinations',
371: col3 => 'User affliation',
372: col4 => 'Overrides'},
373: ],
374: },
1.3 raeburn 375: );
1.110 raeburn 376: if (keys(%servers) > 1) {
377: $prefs{'login'} = { text => 'Log-in page options',
378: help => 'Domain_Configuration_Login_Page',
379: header => [{col1 => 'Log-in Service',
380: col2 => 'Server Setting',},
381: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 382: col2 => ''},
383: {col1 => 'Log-in Help',
384: col2 => 'Value'}],
1.110 raeburn 385: };
386: }
1.6 raeburn 387: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 388: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 389: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 390: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 391: text=>"Settings to display/modify"});
1.9 raeburn 392: my $confname = $dom.'-domainconfig';
1.3 raeburn 393: if ($phase eq 'process') {
1.91 raeburn 394: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 395: } elsif ($phase eq 'display') {
1.160.6.5 raeburn 396: my $js = &recaptcha_js();
1.160.6.7 raeburn 397: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 398: my ($othertitle,$usertypes,$types) =
399: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 400: $js .= &lonbalance_targets_js($dom,$types,\%servers,
401: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 402: &new_spares_js().
403: &common_domprefs_js().
404: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 405: }
1.150 raeburn 406: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 407: } else {
1.21 raeburn 408: if (keys(%domconfig) == 0) {
409: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 410: my @ids=&Apache::lonnet::current_machine_ids();
411: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 412: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 413: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 414: my $custom_img_count = 0;
415: foreach my $img (@loginimages) {
416: if ($designhash{$dom.'.login.'.$img} ne '') {
417: $custom_img_count ++;
418: }
419: }
420: foreach my $role (@roles) {
421: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
422: $custom_img_count ++;
423: }
424: }
425: if ($custom_img_count > 0) {
1.94 raeburn 426: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 427: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 428: $r->print(
429: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
430: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
431: &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 />'.
432: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
433: if ($switch_server) {
1.30 raeburn 434: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 435: }
1.91 raeburn 436: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 437: return OK;
438: }
439: }
440: }
1.91 raeburn 441: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 442: }
443: return OK;
444: }
445:
446: sub process_changes {
1.92 raeburn 447: my ($r,$dom,$confname,$action,$roles,$values) = @_;
448: my %domconfig;
449: if (ref($values) eq 'HASH') {
450: %domconfig = %{$values};
451: }
1.3 raeburn 452: my $output;
453: if ($action eq 'login') {
1.9 raeburn 454: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 455: } elsif ($action eq 'rolecolors') {
1.9 raeburn 456: $output = &modify_rolecolors($r,$dom,$confname,$roles,
457: %domconfig);
1.3 raeburn 458: } elsif ($action eq 'quotas') {
1.86 raeburn 459: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 460: } elsif ($action eq 'autoenroll') {
461: $output = &modify_autoenroll($dom,%domconfig);
462: } elsif ($action eq 'autoupdate') {
463: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 464: } elsif ($action eq 'autocreate') {
465: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 466: } elsif ($action eq 'directorysrch') {
467: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 468: } elsif ($action eq 'usercreation') {
1.28 raeburn 469: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 470: } elsif ($action eq 'usermodification') {
471: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 472: } elsif ($action eq 'contacts') {
473: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 474: } elsif ($action eq 'defaults') {
475: $output = &modify_defaults($dom,$r);
1.46 raeburn 476: } elsif ($action eq 'scantron') {
1.48 raeburn 477: $output = &modify_scantron($r,$dom,$confname,%domconfig);
478: } elsif ($action eq 'coursecategories') {
479: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 480: } elsif ($action eq 'serverstatuses') {
481: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 482: } elsif ($action eq 'requestcourses') {
483: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.5 raeburn 484: } elsif ($action eq 'requestauthor') {
485: $output = &modify_quotas($dom,$action,%domconfig);
1.137 raeburn 486: } elsif ($action eq 'usersessions') {
487: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 488: } elsif ($action eq 'loadbalancing') {
489: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 490: }
491: return $output;
492: }
493:
494: sub print_config_box {
1.9 raeburn 495: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 496: my $rowtotal = 0;
1.49 raeburn 497: my $output;
498: if ($action eq 'coursecategories') {
499: $output = &coursecategories_javascript($settings);
1.91 raeburn 500: }
1.49 raeburn 501: $output .=
1.30 raeburn 502: '<table class="LC_nested_outer">
1.3 raeburn 503: <tr>
1.66 raeburn 504: <th align="left" valign="middle"><span class="LC_nobreak">'.
505: &mt($item->{text}).' '.
506: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
507: '</tr>';
1.30 raeburn 508: $rowtotal ++;
1.110 raeburn 509: my $numheaders = 1;
510: if (ref($item->{'header'}) eq 'ARRAY') {
511: $numheaders = scalar(@{$item->{'header'}});
512: }
513: if ($numheaders > 1) {
1.64 raeburn 514: my $colspan = '';
1.145 raeburn 515: my $rightcolspan = '';
1.160.6.5 raeburn 516: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
517: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 518: $colspan = ' colspan="2"';
519: }
1.145 raeburn 520: if ($action eq 'usersessions') {
521: $rightcolspan = ' colspan="3"';
522: }
1.30 raeburn 523: $output .= '
1.3 raeburn 524: <tr>
525: <td>
526: <table class="LC_nested">
527: <tr class="LC_info_row">
1.59 bisitz 528: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 529: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 530: </tr>';
1.69 raeburn 531: $rowtotal ++;
1.6 raeburn 532: if ($action eq 'autoupdate') {
1.30 raeburn 533: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 534: } elsif ($action eq 'usercreation') {
1.33 raeburn 535: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
536: } elsif ($action eq 'usermodification') {
537: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 538: } elsif ($action eq 'coursecategories') {
539: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 540: } elsif ($action eq 'login') {
1.160.6.5 raeburn 541: if ($numheaders == 3) {
542: $colspan = ' colspan="2"';
543: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
544: } else {
545: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
546: }
1.102 raeburn 547: } elsif ($action eq 'requestcourses') {
548: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 549: } elsif ($action eq 'requestauthor') {
550: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 551: } elsif ($action eq 'usersessions') {
552: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 553: } elsif ($action eq 'rolecolors') {
1.30 raeburn 554: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 555: }
1.30 raeburn 556: $output .= '
1.6 raeburn 557: </table>
558: </td>
559: </tr>
560: <tr>
561: <td>
562: <table class="LC_nested">
563: <tr class="LC_info_row">
1.59 bisitz 564: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 565: $output .= '
1.59 bisitz 566: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 567: </tr>';
568: $rowtotal ++;
1.6 raeburn 569: if ($action eq 'autoupdate') {
1.131 raeburn 570: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
571: </table>
572: </td>
573: </tr>
574: <tr>
575: <td>
576: <table class="LC_nested">
577: <tr class="LC_info_row">
578: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
579: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
580: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
581: $rowtotal ++;
1.28 raeburn 582: } elsif ($action eq 'usercreation') {
1.34 raeburn 583: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
584: </table>
585: </td>
586: </tr>
587: <tr>
588: <td>
589: <table class="LC_nested">
590: <tr class="LC_info_row">
1.59 bisitz 591: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
592: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 593: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
594: $rowtotal ++;
1.33 raeburn 595: } elsif ($action eq 'usermodification') {
1.63 raeburn 596: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
597: </table>
598: </td>
599: </tr>
600: <tr>
601: <td>
602: <table class="LC_nested">
603: <tr class="LC_info_row">
604: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
605: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
606: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
607: $rowtotal ++;
1.57 raeburn 608: } elsif ($action eq 'coursecategories') {
609: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 610: } elsif ($action eq 'login') {
1.160.6.5 raeburn 611: if ($numheaders == 3) {
612: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
613: </table>
614: </td>
615: </tr>
616: <tr>
617: <td>
618: <table class="LC_nested">
619: <tr class="LC_info_row">
620: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
621: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
622: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
623: $rowtotal ++;
624: } else {
625: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
626: }
1.102 raeburn 627: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 628: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
629: } elsif ($action eq 'requestauthor') {
630: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 631: } elsif ($action eq 'usersessions') {
1.145 raeburn 632: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
633: </table>
634: </td>
635: </tr>
636: <tr>
637: <td>
638: <table class="LC_nested">
639: <tr class="LC_info_row">
640: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
641: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
642: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
643: $rowtotal ++;
1.139 raeburn 644: } elsif ($action eq 'coursedefaults') {
645: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 646: } elsif ($action eq 'rolecolors') {
1.30 raeburn 647: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 648: </table>
649: </td>
650: </tr>
651: <tr>
652: <td>
653: <table class="LC_nested">
654: <tr class="LC_info_row">
1.69 raeburn 655: <td class="LC_left_item"'.$colspan.' valign="top">'.
656: &mt($item->{'header'}->[2]->{'col1'}).'</td>
657: <td class="LC_right_item" valign="top">'.
658: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 659: </tr>'.
1.30 raeburn 660: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 661: </table>
662: </td>
663: </tr>
664: <tr>
665: <td>
666: <table class="LC_nested">
667: <tr class="LC_info_row">
1.59 bisitz 668: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
669: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 670: </tr>'.
1.30 raeburn 671: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
672: $rowtotal += 2;
1.6 raeburn 673: }
1.3 raeburn 674: } else {
1.30 raeburn 675: $output .= '
1.3 raeburn 676: <tr>
677: <td>
678: <table class="LC_nested">
1.30 raeburn 679: <tr class="LC_info_row">';
1.24 raeburn 680: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 681: $output .= '
1.59 bisitz 682: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 683: } elsif ($action eq 'serverstatuses') {
684: $output .= '
685: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
686: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
687:
1.6 raeburn 688: } else {
1.30 raeburn 689: $output .= '
1.69 raeburn 690: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
691: }
1.72 raeburn 692: if (defined($item->{'header'}->[0]->{'col3'})) {
693: $output .= '<td class="LC_left_item" valign="top">'.
694: &mt($item->{'header'}->[0]->{'col2'});
695: if ($action eq 'serverstatuses') {
696: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
697: }
1.69 raeburn 698: } else {
699: $output .= '<td class="LC_right_item" valign="top">'.
700: &mt($item->{'header'}->[0]->{'col2'});
701: }
702: $output .= '</td>';
703: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 704: if (defined($item->{'header'}->[0]->{'col4'})) {
705: $output .= '<td class="LC_left_item" valign="top">'.
706: &mt($item->{'header'}->[0]->{'col3'});
707: } else {
708: $output .= '<td class="LC_right_item" valign="top">'.
709: &mt($item->{'header'}->[0]->{'col3'});
710: }
1.69 raeburn 711: if ($action eq 'serverstatuses') {
712: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
713: }
714: $output .= '</td>';
1.6 raeburn 715: }
1.150 raeburn 716: if ($item->{'header'}->[0]->{'col4'}) {
717: $output .= '<td class="LC_right_item" valign="top">'.
718: &mt($item->{'header'}->[0]->{'col4'});
719: }
1.69 raeburn 720: $output .= '</tr>';
1.48 raeburn 721: $rowtotal ++;
1.160.6.5 raeburn 722: if ($action eq 'quotas') {
1.86 raeburn 723: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 724: } elsif ($action eq 'autoenroll') {
1.30 raeburn 725: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 726: } elsif ($action eq 'autocreate') {
727: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 728: } elsif ($action eq 'directorysrch') {
1.30 raeburn 729: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 730: } elsif ($action eq 'contacts') {
1.30 raeburn 731: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 732: } elsif ($action eq 'defaults') {
733: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 734: } elsif ($action eq 'scantron') {
735: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 736: } elsif ($action eq 'serverstatuses') {
737: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 738: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 739: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 740: } elsif ($action eq 'loadbalancing') {
741: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 742: }
1.3 raeburn 743: }
1.30 raeburn 744: $output .= '
1.3 raeburn 745: </table>
746: </td>
747: </tr>
1.30 raeburn 748: </table><br />';
749: return ($output,$rowtotal);
1.1 raeburn 750: }
751:
1.3 raeburn 752: sub print_login {
1.160.6.5 raeburn 753: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 754: my ($css_class,$datatable);
1.6 raeburn 755: my %choices = &login_choices();
1.110 raeburn 756:
1.160.6.5 raeburn 757: if ($caller eq 'service') {
1.149 raeburn 758: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 759: my $choice = $choices{'disallowlogin'};
760: $css_class = ' class="LC_odd_row"';
1.128 raeburn 761: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 762: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 763: '<th>'.$choices{'server'}.'</th>'.
764: '<th>'.$choices{'serverpath'}.'</th>'.
765: '<th>'.$choices{'custompath'}.'</th>'.
766: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 767: my %disallowed;
768: if (ref($settings) eq 'HASH') {
769: if (ref($settings->{'loginvia'}) eq 'HASH') {
770: %disallowed = %{$settings->{'loginvia'}};
771: }
772: }
773: foreach my $lonhost (sort(keys(%servers))) {
774: my $direct = 'selected="selected"';
1.128 raeburn 775: if (ref($disallowed{$lonhost}) eq 'HASH') {
776: if ($disallowed{$lonhost}{'server'} ne '') {
777: $direct = '';
778: }
1.110 raeburn 779: }
1.115 raeburn 780: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 781: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 782: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
783: '</option>';
784: foreach my $hostid (keys(%servers)) {
1.115 raeburn 785: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 786: my $selected = '';
1.128 raeburn 787: if (ref($disallowed{$lonhost}) eq 'HASH') {
788: if ($hostid eq $disallowed{$lonhost}{'server'}) {
789: $selected = 'selected="selected"';
790: }
1.110 raeburn 791: }
792: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
793: $servers{$hostid}.'</option>';
794: }
1.128 raeburn 795: $datatable .= '</select></td>'.
796: '<td><select name="'.$lonhost.'_serverpath">';
797: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
798: my $pathname = $path;
799: if ($path eq 'custom') {
800: $pathname = &mt('Custom Path').' ->';
801: }
802: my $selected = '';
803: if (ref($disallowed{$lonhost}) eq 'HASH') {
804: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
805: $selected = 'selected="selected"';
806: }
807: } elsif ($path eq '') {
808: $selected = 'selected="selected"';
809: }
810: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
811: }
812: $datatable .= '</select></td>';
813: my ($custom,$exempt);
814: if (ref($disallowed{$lonhost}) eq 'HASH') {
815: $custom = $disallowed{$lonhost}{'custompath'};
816: $exempt = $disallowed{$lonhost}{'exempt'};
817: }
818: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
819: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
820: '</tr>';
1.110 raeburn 821: }
822: $datatable .= '</table></td></tr>';
823: return $datatable;
1.160.6.5 raeburn 824: } elsif ($caller eq 'page') {
825: my %defaultchecked = (
826: 'coursecatalog' => 'on',
827: 'adminmail' => 'off',
828: 'newuser' => 'off',
829: );
830: my @toggles = ('coursecatalog','adminmail','newuser');
831: my (%checkedon,%checkedoff);
1.42 raeburn 832: foreach my $item (@toggles) {
1.160.6.5 raeburn 833: if ($defaultchecked{$item} eq 'on') {
834: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 835: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 836: } elsif ($defaultchecked{$item} eq 'off') {
837: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 838: $checkedon{$item} = ' ';
839: }
1.1 raeburn 840: }
1.160.6.5 raeburn 841: my @images = ('img','logo','domlogo','login');
842: my @logintext = ('textcol','bgcol');
843: my @bgs = ('pgbg','mainbg','sidebg');
844: my @links = ('link','alink','vlink');
845: my %designhash = &Apache::loncommon::get_domainconf($dom);
846: my %defaultdesign = %Apache::loncommon::defaultdesign;
847: my (%is_custom,%designs);
848: my %defaults = (
849: font => $defaultdesign{'login.font'},
850: );
1.6 raeburn 851: foreach my $item (@images) {
1.160.6.5 raeburn 852: $defaults{$item} = $defaultdesign{'login.'.$item};
853: $defaults{'showlogo'}{$item} = 1;
854: }
855: foreach my $item (@bgs) {
856: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 857: }
1.41 raeburn 858: foreach my $item (@logintext) {
1.160.6.5 raeburn 859: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 860: }
1.160.6.5 raeburn 861: foreach my $item (@links) {
862: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 863: }
1.160.6.5 raeburn 864: if (ref($settings) eq 'HASH') {
865: foreach my $item (@toggles) {
866: if ($settings->{$item} eq '1') {
867: $checkedon{$item} = ' checked="checked" ';
868: $checkedoff{$item} = ' ';
869: } elsif ($settings->{$item} eq '0') {
870: $checkedoff{$item} = ' checked="checked" ';
871: $checkedon{$item} = ' ';
872: }
1.6 raeburn 873: }
1.160.6.5 raeburn 874: foreach my $item (@images) {
875: if (defined($settings->{$item})) {
876: $designs{$item} = $settings->{$item};
877: $is_custom{$item} = 1;
878: }
879: if (defined($settings->{'showlogo'}{$item})) {
880: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
881: }
882: }
883: foreach my $item (@logintext) {
884: if ($settings->{$item} ne '') {
885: $designs{'logintext'}{$item} = $settings->{$item};
886: $is_custom{$item} = 1;
887: }
888: }
889: if ($settings->{'font'} ne '') {
890: $designs{'font'} = $settings->{'font'};
891: $is_custom{'font'} = 1;
892: }
893: foreach my $item (@bgs) {
894: if ($settings->{$item} ne '') {
895: $designs{'bgs'}{$item} = $settings->{$item};
896: $is_custom{$item} = 1;
897: }
898: }
899: foreach my $item (@links) {
900: if ($settings->{$item} ne '') {
901: $designs{'links'}{$item} = $settings->{$item};
902: $is_custom{$item} = 1;
903: }
904: }
905: } else {
906: if ($designhash{$dom.'.login.font'} ne '') {
907: $designs{'font'} = $designhash{$dom.'.login.font'};
908: $is_custom{'font'} = 1;
909: }
910: foreach my $item (@images) {
911: if ($designhash{$dom.'.login.'.$item} ne '') {
912: $designs{$item} = $designhash{$dom.'.login.'.$item};
913: $is_custom{$item} = 1;
914: }
915: }
916: foreach my $item (@bgs) {
917: if ($designhash{$dom.'.login.'.$item} ne '') {
918: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
919: $is_custom{$item} = 1;
920: }
921: }
922: foreach my $item (@links) {
923: if ($designhash{$dom.'.login.'.$item} ne '') {
924: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
925: $is_custom{$item} = 1;
926: }
1.6 raeburn 927: }
928: }
1.160.6.5 raeburn 929: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
930: logo => 'Institution Logo',
931: domlogo => 'Domain Logo',
932: login => 'Login box');
933: my $itemcount = 1;
934: foreach my $item (@toggles) {
935: $css_class = $itemcount%2?' class="LC_odd_row"':'';
936: $datatable .=
937: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
938: '</td><td>'.
939: '<span class="LC_nobreak"><label><input type="radio" name="'.
940: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
941: '</label> <label><input type="radio" name="'.$item.'"'.
942: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
943: '</tr>';
944: $itemcount ++;
1.6 raeburn 945: }
1.160.6.5 raeburn 946: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
947: $datatable .= '</tr></table></td></tr>';
948: } elsif ($caller eq 'help') {
949: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
950: my $switchserver = &check_switchserver($dom,$confname);
951: my $itemcount = 1;
952: $defaulturl = '/adm/loginproblems.html';
953: $defaulttype = 'default';
954: %lt = &Apache::lonlocal::texthash (
955: del => 'Delete?',
956: rep => 'Replace:',
957: upl => 'Upload:',
958: default => 'Default',
959: custom => 'Custom',
960: );
961: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
962: my @currlangs;
963: if (ref($settings) eq 'HASH') {
964: if (ref($settings->{'helpurl'}) eq 'HASH') {
965: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
966: next if ($settings->{'helpurl'}{$key} eq '');
967: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
968: $type{$key} = 'custom';
969: unless ($key eq 'nolang') {
970: push(@currlangs,$key);
971: }
972: }
973: } elsif ($settings->{'helpurl'} ne '') {
974: $type{'nolang'} = 'custom';
975: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 976: }
977: }
1.160.6.5 raeburn 978: foreach my $lang ('nolang',sort(@currlangs)) {
979: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
980: $datatable .= '<tr'.$css_class.'>';
981: if ($url{$lang} eq '') {
982: $url{$lang} = $defaulturl;
983: }
984: if ($type{$lang} eq '') {
985: $type{$lang} = $defaulttype;
986: }
987: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
988: if ($lang eq 'nolang') {
989: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
990: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
991: } else {
992: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
993: $langchoices{$lang},
994: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
995: }
996: $datatable .= '</span></td>'."\n".
997: '<td class="LC_left_item">';
998: if ($type{$lang} eq 'custom') {
999: $datatable .= '<span class="LC_nobreak"><label>'.
1000: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1001: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1002: } else {
1003: $datatable .= $lt{'upl'};
1004: }
1005: $datatable .='<br />';
1006: if ($switchserver) {
1007: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1008: } else {
1009: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1010: }
1.160.6.5 raeburn 1011: $datatable .= '</td></tr>';
1012: $itemcount ++;
1.6 raeburn 1013: }
1.160.6.5 raeburn 1014: my @addlangs;
1015: foreach my $lang (sort(keys(%langchoices))) {
1016: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1017: push(@addlangs,$lang);
1018: }
1019: if (@addlangs > 0) {
1020: my %toadd;
1021: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1022: $toadd{''} = &mt('Select');
1023: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1024: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1025: &mt('Add log-in help page for a specific language:').' '.
1026: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1027: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1028: if ($switchserver) {
1029: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1030: } else {
1031: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1032: }
1.160.6.5 raeburn 1033: $datatable .= '</td></tr>';
1034: $itemcount ++;
1.6 raeburn 1035: }
1.160.6.5 raeburn 1036: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1037: }
1.6 raeburn 1038: return $datatable;
1039: }
1040:
1041: sub login_choices {
1042: my %choices =
1043: &Apache::lonlocal::texthash (
1.116 bisitz 1044: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1045: adminmail => "Display Administrator's E-mail Address?",
1046: disallowlogin => "Login page requests redirected",
1047: hostid => "Server",
1.128 raeburn 1048: server => "Redirect to:",
1049: serverpath => "Path",
1050: custompath => "Custom",
1051: exempt => "Exempt IP(s)",
1.110 raeburn 1052: directlogin => "No redirect",
1053: newuser => "Link to create a user account",
1054: img => "Header",
1055: logo => "Main Logo",
1056: domlogo => "Domain Logo",
1057: login => "Log-in Header",
1058: textcol => "Text color",
1059: bgcol => "Box color",
1060: bgs => "Background colors",
1061: links => "Link colors",
1062: font => "Font color",
1063: pgbg => "Header",
1064: mainbg => "Page",
1065: sidebg => "Login box",
1066: link => "Link",
1067: alink => "Active link",
1068: vlink => "Visited link",
1.6 raeburn 1069: );
1070: return %choices;
1071: }
1072:
1073: sub print_rolecolors {
1.30 raeburn 1074: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1075: my %choices = &color_font_choices();
1076: my @bgs = ('pgbg','tabbg','sidebg');
1077: my @links = ('link','alink','vlink');
1078: my @images = ('img');
1079: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1080: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1081: my %defaultdesign = %Apache::loncommon::defaultdesign;
1082: my (%is_custom,%designs);
1083: my %defaults = (
1084: img => $defaultdesign{$role.'.img'},
1085: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1086: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1087: );
1088: foreach my $item (@bgs) {
1089: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1090: }
1091: foreach my $item (@links) {
1092: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1093: }
1094: if (ref($settings) eq 'HASH') {
1095: if (ref($settings->{$role}) eq 'HASH') {
1096: if ($settings->{$role}->{'img'} ne '') {
1097: $designs{'img'} = $settings->{$role}->{'img'};
1098: $is_custom{'img'} = 1;
1099: }
1100: if ($settings->{$role}->{'font'} ne '') {
1101: $designs{'font'} = $settings->{$role}->{'font'};
1102: $is_custom{'font'} = 1;
1103: }
1.97 tempelho 1104: if ($settings->{$role}->{'fontmenu'} ne '') {
1105: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1106: $is_custom{'fontmenu'} = 1;
1107: }
1.6 raeburn 1108: foreach my $item (@bgs) {
1109: if ($settings->{$role}->{$item} ne '') {
1110: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1111: $is_custom{$item} = 1;
1112: }
1113: }
1114: foreach my $item (@links) {
1115: if ($settings->{$role}->{$item} ne '') {
1116: $designs{'links'}{$item} = $settings->{$role}->{$item};
1117: $is_custom{$item} = 1;
1118: }
1119: }
1120: }
1121: } else {
1122: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1123: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1124: $is_custom{'img'} = 1;
1125: }
1.97 tempelho 1126: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1127: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1128: $is_custom{'fontmenu'} = 1;
1129: }
1.6 raeburn 1130: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1131: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1132: $is_custom{'font'} = 1;
1133: }
1134: foreach my $item (@bgs) {
1135: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1136: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1137: $is_custom{$item} = 1;
1138:
1139: }
1140: }
1141: foreach my $item (@links) {
1142: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1143: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1144: $is_custom{$item} = 1;
1145: }
1146: }
1147: }
1148: my $itemcount = 1;
1.30 raeburn 1149: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1150: $datatable .= '</tr></table></td></tr>';
1151: return $datatable;
1152: }
1153:
1154: sub display_color_options {
1.9 raeburn 1155: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1156: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1157: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1158: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1159: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1160: '<td>'.$choices->{'font'}.'</td>';
1161: if (!$is_custom->{'font'}) {
1.30 raeburn 1162: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1163: } else {
1164: $datatable .= '<td> </td>';
1165: }
1.160.6.9 raeburn 1166: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1167:
1.8 raeburn 1168: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1169: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1170: ' value="'.$current_color.'" /> '.
1171: ' </td></tr>';
1.107 raeburn 1172: unless ($role eq 'login') {
1173: $datatable .= '<tr'.$css_class.'>'.
1174: '<td>'.$choices->{'fontmenu'}.'</td>';
1175: if (!$is_custom->{'fontmenu'}) {
1176: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1177: } else {
1178: $datatable .= '<td> </td>';
1179: }
1.160.6.9 raeburn 1180: $current_color = $designs->{'fontmenu'} ?
1181: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1182: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1183: '<input class="colorchooser" type="text" size="10" name="'
1184: .$role.'_fontmenu"'.
1185: ' value="'.$current_color.'" /> '.
1186: ' </td></tr>';
1.97 tempelho 1187: }
1.9 raeburn 1188: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1189: foreach my $img (@{$images}) {
1.18 albertel 1190: $itemcount ++;
1.6 raeburn 1191: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1192: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1193: '<td>'.$choices->{$img};
1.41 raeburn 1194: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1195: if ($role eq 'login') {
1196: if ($img eq 'login') {
1197: $login_hdr_pick =
1.135 bisitz 1198: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1199: $logincolors =
1200: &login_text_colors($img,$role,$logintext,$phase,$choices,
1201: $designs);
1202: } elsif ($img ne 'domlogo') {
1203: $datatable.= &logo_display_options($img,$defaults,$designs);
1204: }
1205: }
1206: $datatable .= '</td>';
1.6 raeburn 1207: if ($designs->{$img} ne '') {
1208: $imgfile = $designs->{$img};
1.18 albertel 1209: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1210: } else {
1211: $imgfile = $defaults->{$img};
1212: }
1213: if ($imgfile) {
1.9 raeburn 1214: my ($showfile,$fullsize);
1215: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1216: my $urldir = $1;
1217: my $filename = $2;
1218: my @info = &Apache::lonnet::stat_file($designs->{$img});
1219: if (@info) {
1220: my $thumbfile = 'tn-'.$filename;
1221: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1222: if (@thumb) {
1223: $showfile = $urldir.'/'.$thumbfile;
1224: } else {
1225: $showfile = $imgfile;
1226: }
1227: } else {
1228: $showfile = '';
1229: }
1230: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1231: $showfile = $imgfile;
1.6 raeburn 1232: my $imgdir = $1;
1233: my $filename = $2;
1.159 raeburn 1234: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1235: $showfile = "/$imgdir/tn-".$filename;
1236: } else {
1.159 raeburn 1237: my $input = $londocroot.$imgfile;
1238: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1239: if (!-e $output) {
1.9 raeburn 1240: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1241: my ($fullwidth,$fullheight) = &check_dimensions($input);
1242: if ($fullwidth ne '' && $fullheight ne '') {
1243: if ($fullwidth > $width && $fullheight > $height) {
1244: my $size = $width.'x'.$height;
1245: system("convert -sample $size $input $output");
1.159 raeburn 1246: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1247: }
1248: }
1.6 raeburn 1249: }
1250: }
1.16 raeburn 1251: }
1.6 raeburn 1252: if ($showfile) {
1.40 raeburn 1253: if ($showfile =~ m{^/(adm|res)/}) {
1254: if ($showfile =~ m{^/res/}) {
1255: my $local_showfile =
1256: &Apache::lonnet::filelocation('',$showfile);
1257: &Apache::lonnet::repcopy($local_showfile);
1258: }
1259: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1260: }
1261: if ($imgfile) {
1262: if ($imgfile =~ m{^/(adm|res)/}) {
1263: if ($imgfile =~ m{^/res/}) {
1264: my $local_imgfile =
1265: &Apache::lonnet::filelocation('',$imgfile);
1266: &Apache::lonnet::repcopy($local_imgfile);
1267: }
1268: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1269: } else {
1270: $fullsize = $imgfile;
1271: }
1272: }
1.41 raeburn 1273: $datatable .= '<td>';
1274: if ($img eq 'login') {
1.135 bisitz 1275: $datatable .= $login_hdr_pick;
1276: }
1.41 raeburn 1277: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1278: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1279: } else {
1280: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1281: &mt('Upload:');
1282: }
1283: } else {
1284: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1285: &mt('Upload:');
1286: }
1.9 raeburn 1287: if ($switchserver) {
1288: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1289: } else {
1.135 bisitz 1290: if ($img ne 'login') { # suppress file selection for Log-in header
1291: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1292: }
1.9 raeburn 1293: }
1294: $datatable .= '</td></tr>';
1.6 raeburn 1295: }
1296: $itemcount ++;
1297: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1298: $datatable .= '<tr'.$css_class.'>'.
1299: '<td>'.$choices->{'bgs'}.'</td>';
1300: my $bgs_def;
1301: foreach my $item (@{$bgs}) {
1302: if (!$is_custom->{$item}) {
1.70 raeburn 1303: $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 1304: }
1305: }
1306: if ($bgs_def) {
1.8 raeburn 1307: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1308: } else {
1309: $datatable .= '<td> </td>';
1310: }
1311: $datatable .= '<td class="LC_right_item">'.
1312: '<table border="0"><tr>';
1313: foreach my $item (@{$bgs}) {
1.160.6.9 raeburn 1314: $datatable .= '<td align="center">';
1315: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1316: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1317: $datatable .= ' ';
1.6 raeburn 1318: }
1.160.6.9 raeburn 1319: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1320: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1321: }
1322: $datatable .= '</tr></table></td></tr>';
1323: $itemcount ++;
1324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1325: $datatable .= '<tr'.$css_class.'>'.
1326: '<td>'.$choices->{'links'}.'</td>';
1327: my $links_def;
1328: foreach my $item (@{$links}) {
1329: if (!$is_custom->{$item}) {
1.30 raeburn 1330: $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 1331: }
1332: }
1333: if ($links_def) {
1.8 raeburn 1334: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1335: } else {
1336: $datatable .= '<td> </td>';
1337: }
1338: $datatable .= '<td class="LC_right_item">'.
1339: '<table border="0"><tr>';
1340: foreach my $item (@{$links}) {
1.160.6.9 raeburn 1341: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1342: $datatable .= '<td align="center">'."\n";
1343:
1.6 raeburn 1344: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1345: $datatable.=' ';
1.6 raeburn 1346: }
1.160.6.9 raeburn 1347: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1348: '" /></td>';
1.160.6.9 raeburn 1349:
1.6 raeburn 1350: }
1.30 raeburn 1351: $$rowtotal += $itemcount;
1.3 raeburn 1352: return $datatable;
1353: }
1354:
1.70 raeburn 1355: sub logo_display_options {
1356: my ($img,$defaults,$designs) = @_;
1357: my $checkedon;
1358: if (ref($defaults) eq 'HASH') {
1359: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1360: if ($defaults->{'showlogo'}{$img}) {
1361: $checkedon = 'checked="checked" ';
1362: }
1363: }
1364: }
1365: if (ref($designs) eq 'HASH') {
1366: if (ref($designs->{'showlogo'}) eq 'HASH') {
1367: if (defined($designs->{'showlogo'}{$img})) {
1368: if ($designs->{'showlogo'}{$img} == 0) {
1369: $checkedon = '';
1370: } elsif ($designs->{'showlogo'}{$img} == 1) {
1371: $checkedon = 'checked="checked" ';
1372: }
1373: }
1374: }
1375: }
1376: return '<br /><label> <input type="checkbox" name="'.
1377: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1378: &mt('show').'</label>'."\n";
1379: }
1380:
1.41 raeburn 1381: sub login_header_options {
1.135 bisitz 1382: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1383: my $output = '';
1.41 raeburn 1384: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1385: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1386: if (!$is_custom->{'textcol'}) {
1387: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1388: ' ';
1389: }
1390: if (!$is_custom->{'bgcol'}) {
1391: $output .= $choices->{'bgcol'}.': '.
1392: '<span id="css_'.$role.'_font" style="background-color: '.
1393: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1394: }
1395: $output .= '<br />';
1396: }
1397: $output .='<br />';
1398: return $output;
1399: }
1400:
1401: sub login_text_colors {
1402: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1403: my $color_menu = '<table border="0"><tr>';
1404: foreach my $item (@{$logintext}) {
1405: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1406: $color_menu .= '<td align="center">'.$link;
1407: if ($designs->{'logintext'}{$item}) {
1408: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1409: }
1410: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1411: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1412: '<td> </td>';
1413: }
1414: $color_menu .= '</tr></table><br />';
1415: return $color_menu;
1416: }
1417:
1418: sub image_changes {
1419: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1420: my $output;
1.135 bisitz 1421: if ($img eq 'login') {
1422: # suppress image for Log-in header
1423: } elsif (!$is_custom) {
1.70 raeburn 1424: if ($img ne 'domlogo') {
1.41 raeburn 1425: $output .= &mt('Default image:').'<br />';
1426: } else {
1427: $output .= &mt('Default in use:').'<br />';
1428: }
1429: }
1.135 bisitz 1430: if ($img eq 'login') { # suppress image for Log-in header
1431: $output .= '<td>'.$logincolors;
1.41 raeburn 1432: } else {
1.135 bisitz 1433: if ($img_import) {
1434: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1435: }
1436: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1437: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1438: if ($is_custom) {
1439: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1440: '<input type="checkbox" name="'.
1441: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1442: '</label> '.&mt('Replace:').'</span><br />';
1443: } else {
1444: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1445: }
1.41 raeburn 1446: }
1447: return $output;
1448: }
1449:
1.6 raeburn 1450: sub color_pick {
1451: my ($phase,$role,$item,$desc,$curcol) = @_;
1452: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1453: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1454: ');">'.$desc.'</a>';
1455: return $link;
1456: }
1457:
1.3 raeburn 1458: sub print_quotas {
1.86 raeburn 1459: my ($dom,$settings,$rowtotal,$action) = @_;
1460: my $context;
1461: if ($action eq 'quotas') {
1462: $context = 'tools';
1463: } else {
1464: $context = $action;
1465: }
1.101 raeburn 1466: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1467: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1468: my $typecount = 0;
1.101 raeburn 1469: my ($css_class,%titles);
1.86 raeburn 1470: if ($context eq 'requestcourses') {
1.98 raeburn 1471: @usertools = ('official','unofficial','community');
1.106 raeburn 1472: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1473: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1474: %titles = &courserequest_titles();
1.160.6.5 raeburn 1475: } elsif ($context eq 'requestauthor') {
1476: @usertools = ('author');
1477: @options = ('norequest','approval','automatic');
1478: %titles = &authorrequest_titles();
1.86 raeburn 1479: } else {
1.160.6.4 raeburn 1480: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1481: %titles = &tool_titles();
1.86 raeburn 1482: }
1.26 raeburn 1483: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1484: foreach my $type (@{$types}) {
1.72 raeburn 1485: my $currdefquota;
1.160.6.5 raeburn 1486: unless (($context eq 'requestcourses') ||
1487: ($context eq 'requestauthor')) {
1.86 raeburn 1488: if (ref($settings) eq 'HASH') {
1489: if (ref($settings->{defaultquota}) eq 'HASH') {
1490: $currdefquota = $settings->{defaultquota}->{$type};
1491: } else {
1492: $currdefquota = $settings->{$type};
1493: }
1.78 raeburn 1494: }
1.72 raeburn 1495: }
1.3 raeburn 1496: if (defined($usertypes->{$type})) {
1497: $typecount ++;
1498: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1499: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1500: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1501: '<td class="LC_left_item">';
1.101 raeburn 1502: if ($context eq 'requestcourses') {
1503: $datatable .= '<table><tr>';
1504: }
1505: my %cell;
1.72 raeburn 1506: foreach my $item (@usertools) {
1.101 raeburn 1507: if ($context eq 'requestcourses') {
1508: my ($curroption,$currlimit);
1509: if (ref($settings) eq 'HASH') {
1510: if (ref($settings->{$item}) eq 'HASH') {
1511: $curroption = $settings->{$item}->{$type};
1512: if ($curroption =~ /^autolimit=(\d*)$/) {
1513: $currlimit = $1;
1514: }
1515: }
1516: }
1517: if (!$curroption) {
1518: $curroption = 'norequest';
1519: }
1520: $datatable .= '<th>'.$titles{$item}.'</th>';
1521: foreach my $option (@options) {
1522: my $val = $option;
1523: if ($option eq 'norequest') {
1524: $val = 0;
1525: }
1526: if ($option eq 'validate') {
1527: my $canvalidate = 0;
1528: if (ref($validations{$item}) eq 'HASH') {
1529: if ($validations{$item}{$type}) {
1530: $canvalidate = 1;
1531: }
1532: }
1533: next if (!$canvalidate);
1534: }
1535: my $checked = '';
1536: if ($option eq $curroption) {
1537: $checked = ' checked="checked"';
1538: } elsif ($option eq 'autolimit') {
1539: if ($curroption =~ /^autolimit/) {
1540: $checked = ' checked="checked"';
1541: }
1542: }
1543: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1544: '<input type="radio" name="crsreq_'.$item.
1545: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1546: $titles{$option}.'</label>';
1.101 raeburn 1547: if ($option eq 'autolimit') {
1.127 raeburn 1548: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1549: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1550: 'value="'.$currlimit.'" />';
1.101 raeburn 1551: }
1.127 raeburn 1552: $cell{$item} .= '</span> ';
1.103 raeburn 1553: if ($option eq 'autolimit') {
1.127 raeburn 1554: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1555: }
1.101 raeburn 1556: }
1.160.6.5 raeburn 1557: } elsif ($context eq 'requestauthor') {
1558: my $curroption;
1559: if (ref($settings) eq 'HASH') {
1560: $curroption = $settings->{$type};
1561: }
1562: if (!$curroption) {
1563: $curroption = 'norequest';
1564: }
1565: foreach my $option (@options) {
1566: my $val = $option;
1567: if ($option eq 'norequest') {
1568: $val = 0;
1569: }
1570: my $checked = '';
1571: if ($option eq $curroption) {
1572: $checked = ' checked="checked"';
1573: }
1574: $datatable .= '<span class="LC_nobreak"><label>'.
1575: '<input type="radio" name="authorreq_'.$type.
1576: '" value="'.$val.'"'.$checked.' />'.
1577: $titles{$option}.'</label></span> ';
1578: }
1.101 raeburn 1579: } else {
1580: my $checked = 'checked="checked" ';
1581: if (ref($settings) eq 'HASH') {
1582: if (ref($settings->{$item}) eq 'HASH') {
1583: if ($settings->{$item}->{$type} == 0) {
1584: $checked = '';
1585: } elsif ($settings->{$item}->{$type} == 1) {
1586: $checked = 'checked="checked" ';
1587: }
1.78 raeburn 1588: }
1.72 raeburn 1589: }
1.101 raeburn 1590: $datatable .= '<span class="LC_nobreak"><label>'.
1591: '<input type="checkbox" name="'.$context.'_'.$item.
1592: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1593: '</label></span> ';
1.72 raeburn 1594: }
1.101 raeburn 1595: }
1596: if ($context eq 'requestcourses') {
1597: $datatable .= '</tr><tr>';
1598: foreach my $item (@usertools) {
1.106 raeburn 1599: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1600: }
1601: $datatable .= '</tr></table>';
1.72 raeburn 1602: }
1.86 raeburn 1603: $datatable .= '</td>';
1.160.6.5 raeburn 1604: unless (($context eq 'requestcourses') ||
1605: ($context eq 'requestauthor')) {
1.86 raeburn 1606: $datatable .=
1607: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1608: '<input type="text" name="quota_'.$type.
1.72 raeburn 1609: '" value="'.$currdefquota.
1.86 raeburn 1610: '" size="5" /> Mb</span></td>';
1611: }
1612: $datatable .= '</tr>';
1.3 raeburn 1613: }
1614: }
1615: }
1.160.6.5 raeburn 1616: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1617: $defaultquota = '20';
1618: if (ref($settings) eq 'HASH') {
1619: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1620: $defaultquota = $settings->{'defaultquota'}->{'default'};
1621: } elsif (defined($settings->{'default'})) {
1622: $defaultquota = $settings->{'default'};
1623: }
1.3 raeburn 1624: }
1625: }
1626: $typecount ++;
1627: $css_class = $typecount%2?' class="LC_odd_row"':'';
1628: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1629: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1630: '<td class="LC_left_item">';
1.101 raeburn 1631: if ($context eq 'requestcourses') {
1632: $datatable .= '<table><tr>';
1633: }
1634: my %defcell;
1.72 raeburn 1635: foreach my $item (@usertools) {
1.101 raeburn 1636: if ($context eq 'requestcourses') {
1637: my ($curroption,$currlimit);
1638: if (ref($settings) eq 'HASH') {
1639: if (ref($settings->{$item}) eq 'HASH') {
1640: $curroption = $settings->{$item}->{'default'};
1641: if ($curroption =~ /^autolimit=(\d*)$/) {
1642: $currlimit = $1;
1643: }
1644: }
1645: }
1646: if (!$curroption) {
1647: $curroption = 'norequest';
1648: }
1649: $datatable .= '<th>'.$titles{$item}.'</th>';
1650: foreach my $option (@options) {
1651: my $val = $option;
1652: if ($option eq 'norequest') {
1653: $val = 0;
1654: }
1655: if ($option eq 'validate') {
1656: my $canvalidate = 0;
1657: if (ref($validations{$item}) eq 'HASH') {
1658: if ($validations{$item}{'default'}) {
1659: $canvalidate = 1;
1660: }
1661: }
1662: next if (!$canvalidate);
1663: }
1664: my $checked = '';
1665: if ($option eq $curroption) {
1666: $checked = ' checked="checked"';
1667: } elsif ($option eq 'autolimit') {
1668: if ($curroption =~ /^autolimit/) {
1669: $checked = ' checked="checked"';
1670: }
1671: }
1672: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1673: '<input type="radio" name="crsreq_'.$item.
1674: '_default" value="'.$val.'"'.$checked.' />'.
1675: $titles{$option}.'</label>';
1676: if ($option eq 'autolimit') {
1.127 raeburn 1677: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1678: $item.'_limit_default" size="1" '.
1679: 'value="'.$currlimit.'" />';
1680: }
1.127 raeburn 1681: $defcell{$item} .= '</span> ';
1.104 raeburn 1682: if ($option eq 'autolimit') {
1.127 raeburn 1683: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1684: }
1.101 raeburn 1685: }
1.160.6.5 raeburn 1686: } elsif ($context eq 'requestauthor') {
1687: my $curroption;
1688: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1689: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1690: }
1691: if (!$curroption) {
1692: $curroption = 'norequest';
1693: }
1694: foreach my $option (@options) {
1695: my $val = $option;
1696: if ($option eq 'norequest') {
1697: $val = 0;
1698: }
1699: my $checked = '';
1700: if ($option eq $curroption) {
1701: $checked = ' checked="checked"';
1702: }
1703: $datatable .= '<span class="LC_nobreak"><label>'.
1704: '<input type="radio" name="authorreq_default"'.
1705: ' value="'.$val.'"'.$checked.' />'.
1706: $titles{$option}.'</label></span> ';
1707: }
1.101 raeburn 1708: } else {
1709: my $checked = 'checked="checked" ';
1710: if (ref($settings) eq 'HASH') {
1711: if (ref($settings->{$item}) eq 'HASH') {
1712: if ($settings->{$item}->{'default'} == 0) {
1713: $checked = '';
1714: } elsif ($settings->{$item}->{'default'} == 1) {
1715: $checked = 'checked="checked" ';
1716: }
1.78 raeburn 1717: }
1.72 raeburn 1718: }
1.101 raeburn 1719: $datatable .= '<span class="LC_nobreak"><label>'.
1720: '<input type="checkbox" name="'.$context.'_'.$item.
1721: '" value="default" '.$checked.'/>'.$titles{$item}.
1722: '</label></span> ';
1723: }
1724: }
1725: if ($context eq 'requestcourses') {
1726: $datatable .= '</tr><tr>';
1727: foreach my $item (@usertools) {
1.106 raeburn 1728: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1729: }
1.101 raeburn 1730: $datatable .= '</tr></table>';
1.72 raeburn 1731: }
1.86 raeburn 1732: $datatable .= '</td>';
1.160.6.5 raeburn 1733: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1734: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1735: '<input type="text" name="defaultquota" value="'.
1736: $defaultquota.'" size="5" /> Mb</span></td>';
1737: }
1738: $datatable .= '</tr>';
1.72 raeburn 1739: $typecount ++;
1740: $css_class = $typecount%2?' class="LC_odd_row"':'';
1741: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1742: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1743: if ($context eq 'requestcourses') {
1.109 raeburn 1744: $datatable .= &mt('(overrides affiliation, if set)').
1745: '</td>'.
1746: '<td class="LC_left_item">'.
1747: '<table><tr>';
1.101 raeburn 1748: } else {
1.109 raeburn 1749: $datatable .= &mt('(overrides affiliation, if checked)').
1750: '</td>'.
1751: '<td class="LC_left_item" colspan="2">'.
1752: '<br />';
1.101 raeburn 1753: }
1754: my %advcell;
1.72 raeburn 1755: foreach my $item (@usertools) {
1.101 raeburn 1756: if ($context eq 'requestcourses') {
1757: my ($curroption,$currlimit);
1758: if (ref($settings) eq 'HASH') {
1759: if (ref($settings->{$item}) eq 'HASH') {
1760: $curroption = $settings->{$item}->{'_LC_adv'};
1761: if ($curroption =~ /^autolimit=(\d*)$/) {
1762: $currlimit = $1;
1763: }
1764: }
1765: }
1766: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1767: my $checked = '';
1768: if ($curroption eq '') {
1769: $checked = ' checked="checked"';
1770: }
1771: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1772: '<input type="radio" name="crsreq_'.$item.
1773: '__LC_adv" value=""'.$checked.' />'.
1774: &mt('No override set').'</label></span> ';
1.101 raeburn 1775: foreach my $option (@options) {
1776: my $val = $option;
1777: if ($option eq 'norequest') {
1778: $val = 0;
1779: }
1780: if ($option eq 'validate') {
1781: my $canvalidate = 0;
1782: if (ref($validations{$item}) eq 'HASH') {
1783: if ($validations{$item}{'_LC_adv'}) {
1784: $canvalidate = 1;
1785: }
1786: }
1787: next if (!$canvalidate);
1788: }
1789: my $checked = '';
1.104 raeburn 1790: if ($val eq $curroption) {
1.101 raeburn 1791: $checked = ' checked="checked"';
1792: } elsif ($option eq 'autolimit') {
1793: if ($curroption =~ /^autolimit/) {
1794: $checked = ' checked="checked"';
1795: }
1796: }
1797: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1798: '<input type="radio" name="crsreq_'.$item.
1799: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1800: $titles{$option}.'</label>';
1801: if ($option eq 'autolimit') {
1.127 raeburn 1802: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1803: $item.'_limit__LC_adv" size="1" '.
1804: 'value="'.$currlimit.'" />';
1805: }
1.127 raeburn 1806: $advcell{$item} .= '</span> ';
1.104 raeburn 1807: if ($option eq 'autolimit') {
1.127 raeburn 1808: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1809: }
1.101 raeburn 1810: }
1.160.6.5 raeburn 1811: } elsif ($context eq 'requestauthor') {
1812: my $curroption;
1813: if (ref($settings) eq 'HASH') {
1814: $curroption = $settings->{'_LC_adv'};
1815: }
1816: my $checked = '';
1817: if ($curroption eq '') {
1818: $checked = ' checked="checked"';
1819: }
1820: $datatable .= '<span class="LC_nobreak"><label>'.
1821: '<input type="radio" name="authorreq__LC_adv"'.
1822: ' value=""'.$checked.' />'.
1823: &mt('No override set').'</label></span> ';
1824: foreach my $option (@options) {
1825: my $val = $option;
1826: if ($option eq 'norequest') {
1827: $val = 0;
1828: }
1829: my $checked = '';
1830: if ($val eq $curroption) {
1831: $checked = ' checked="checked"';
1832: }
1833: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1834: '<input type="radio" name="authorreq__LC_adv"'.
1835: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1836: $titles{$option}.'</label></span> ';
1837: }
1.101 raeburn 1838: } else {
1839: my $checked = 'checked="checked" ';
1840: if (ref($settings) eq 'HASH') {
1841: if (ref($settings->{$item}) eq 'HASH') {
1842: if ($settings->{$item}->{'_LC_adv'} == 0) {
1843: $checked = '';
1844: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1845: $checked = 'checked="checked" ';
1846: }
1.79 raeburn 1847: }
1.72 raeburn 1848: }
1.101 raeburn 1849: $datatable .= '<span class="LC_nobreak"><label>'.
1850: '<input type="checkbox" name="'.$context.'_'.$item.
1851: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1852: '</label></span> ';
1853: }
1854: }
1855: if ($context eq 'requestcourses') {
1856: $datatable .= '</tr><tr>';
1857: foreach my $item (@usertools) {
1.106 raeburn 1858: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1859: }
1.101 raeburn 1860: $datatable .= '</tr></table>';
1.72 raeburn 1861: }
1.98 raeburn 1862: $datatable .= '</td></tr>';
1.30 raeburn 1863: $$rowtotal += $typecount;
1.3 raeburn 1864: return $datatable;
1865: }
1866:
1.160.6.5 raeburn 1867: sub print_requestmail {
1868: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1869: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1870: $now = time;
1871: $rows = 0;
1872: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1873: foreach my $server (keys(%dompersonnel)) {
1874: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1875: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1876: if (!grep(/^$uname:$udom$/,@domcoord)) {
1877: push(@domcoord,$uname.':'.$udom);
1878: }
1879: }
1880: }
1881: if (ref($settings) eq 'HASH') {
1882: if (ref($settings->{'notify'}) eq 'HASH') {
1883: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1884: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1885: }
1886: }
1887: }
1.104 raeburn 1888: if (@currapproval) {
1889: foreach my $dc (@currapproval) {
1.102 raeburn 1890: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1891: push(@domcoord,$dc);
1892: }
1893: }
1894: }
1895: @domcoord = sort(@domcoord);
1896: my $numinrow = 4;
1897: my $numdc = @domcoord;
1898: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1899: my $text;
1900: if ($action eq 'requestcourses') {
1901: $text = &mt('Receive notification of course requests requiring approval');
1902: } else {
1903: $text = &mt('Receive notification of authoring space requests requiring approval')
1904: }
1905: $datatable = '<tr '.$css_class.'>'.
1906: ' <td>'.$text.'</td>'.
1.102 raeburn 1907: ' <td class="LC_left_item">';
1908: if (@domcoord > 0) {
1909: $datatable .= '<table>';
1910: for (my $i=0; $i<$numdc; $i++) {
1911: my $rem = $i%($numinrow);
1912: if ($rem == 0) {
1913: if ($i > 0) {
1914: $datatable .= '</tr>';
1915: }
1916: $datatable .= '<tr>';
1917: $rows ++;
1918: }
1919: my $check = ' ';
1.104 raeburn 1920: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1921: $check = ' checked="checked" ';
1922: }
1923: my ($uname,$udom) = split(':',$domcoord[$i]);
1924: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1925: if ($i == $numdc-1) {
1926: my $colsleft = $numinrow-$rem;
1927: if ($colsleft > 1) {
1928: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1929: } else {
1930: $datatable .= '<td class="LC_left_item">';
1931: }
1932: } else {
1933: $datatable .= '<td class="LC_left_item">';
1934: }
1935: $datatable .= '<span class="LC_nobreak"><label>'.
1936: '<input type="checkbox" name="reqapprovalnotify" '.
1937: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1938: $fullname.'</label></span></td>';
1939: }
1940: $datatable .= '</tr></table>';
1941: } else {
1942: $datatable .= &mt('There are no active Domain Coordinators');
1943: $rows ++;
1944: }
1945: $datatable .='</td></tr>';
1946: $$rowtotal += $rows;
1947: return $datatable;
1948: }
1949:
1.3 raeburn 1950: sub print_autoenroll {
1.30 raeburn 1951: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1952: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1953: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1954: if (ref($settings) eq 'HASH') {
1955: if (exists($settings->{'run'})) {
1956: if ($settings->{'run'} eq '0') {
1957: $runoff = ' checked="checked" ';
1958: $runon = ' ';
1959: } else {
1960: $runon = ' checked="checked" ';
1961: $runoff = ' ';
1962: }
1963: } else {
1964: if ($autorun) {
1965: $runon = ' checked="checked" ';
1966: $runoff = ' ';
1967: } else {
1968: $runoff = ' checked="checked" ';
1969: $runon = ' ';
1970: }
1971: }
1.129 raeburn 1972: if (exists($settings->{'co-owners'})) {
1973: if ($settings->{'co-owners'} eq '0') {
1974: $coownersoff = ' checked="checked" ';
1975: $coownerson = ' ';
1976: } else {
1977: $coownerson = ' checked="checked" ';
1978: $coownersoff = ' ';
1979: }
1980: } else {
1981: $coownersoff = ' checked="checked" ';
1982: $coownerson = ' ';
1983: }
1.3 raeburn 1984: if (exists($settings->{'sender_domain'})) {
1985: $defdom = $settings->{'sender_domain'};
1986: }
1.14 raeburn 1987: } else {
1988: if ($autorun) {
1989: $runon = ' checked="checked" ';
1990: $runoff = ' ';
1991: } else {
1992: $runoff = ' checked="checked" ';
1993: $runon = ' ';
1994: }
1.3 raeburn 1995: }
1996: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1997: my $notif_sender;
1998: if (ref($settings) eq 'HASH') {
1999: $notif_sender = $settings->{'sender_uname'};
2000: }
1.3 raeburn 2001: my $datatable='<tr class="LC_odd_row">'.
2002: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2003: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2004: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2005: $runon.' value="1" />'.&mt('Yes').'</label> '.
2006: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2007: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2008: '</tr><tr>'.
2009: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2010: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2011: &mt('username').': '.
2012: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2013: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2014: ': '.$domform.'</span></td></tr>'.
2015: '<tr class="LC_odd_row">'.
2016: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2017: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2018: '<input type="radio" name="autoassign_coowners"'.
2019: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2020: '<label><input type="radio" name="autoassign_coowners"'.
2021: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2022: '</tr>';
2023: $$rowtotal += 3;
1.3 raeburn 2024: return $datatable;
2025: }
2026:
2027: sub print_autoupdate {
1.30 raeburn 2028: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2029: my $datatable;
2030: if ($position eq 'top') {
2031: my $updateon = ' ';
2032: my $updateoff = ' checked="checked" ';
2033: my $classlistson = ' ';
2034: my $classlistsoff = ' checked="checked" ';
2035: if (ref($settings) eq 'HASH') {
2036: if ($settings->{'run'} eq '1') {
2037: $updateon = $updateoff;
2038: $updateoff = ' ';
2039: }
2040: if ($settings->{'classlists'} eq '1') {
2041: $classlistson = $classlistsoff;
2042: $classlistsoff = ' ';
2043: }
2044: }
2045: my %title = (
2046: run => 'Auto-update active?',
2047: classlists => 'Update information in classlists?',
2048: );
2049: $datatable = '<tr class="LC_odd_row">'.
2050: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2051: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2052: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2053: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2054: '<label><input type="radio" name="autoupdate_run"'.
2055: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2056: '</tr><tr>'.
2057: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2058: '<td class="LC_right_item"><span class="LC_nobreak">'.
2059: '<label><input type="radio" name="classlists"'.
2060: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2061: '<label><input type="radio" name="classlists"'.
2062: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2063: '</tr>';
1.30 raeburn 2064: $$rowtotal += 2;
1.131 raeburn 2065: } elsif ($position eq 'middle') {
2066: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2067: my $numinrow = 3;
2068: my $locknamesettings;
2069: $datatable .= &insttypes_row($settings,$types,$usertypes,
2070: $dom,$numinrow,$othertitle,
2071: 'lockablenames');
2072: $$rowtotal ++;
1.3 raeburn 2073: } else {
1.44 raeburn 2074: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2075: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2076: 'permanentemail','id');
1.33 raeburn 2077: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2078: my $numrows = 0;
1.26 raeburn 2079: if (ref($types) eq 'ARRAY') {
2080: if (@{$types} > 0) {
2081: $datatable =
2082: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2083: \@fields,$types,\$numrows);
1.30 raeburn 2084: $$rowtotal += @{$types};
1.26 raeburn 2085: }
1.3 raeburn 2086: }
2087: $datatable .=
2088: &usertype_update_row($settings,{'default' => $othertitle},
2089: \%fieldtitles,\@fields,['default'],
2090: \$numrows);
1.30 raeburn 2091: $$rowtotal ++;
1.3 raeburn 2092: }
2093: return $datatable;
2094: }
2095:
1.125 raeburn 2096: sub print_autocreate {
2097: my ($dom,$settings,$rowtotal) = @_;
2098: my (%createon,%createoff);
2099: my $curr_dc;
2100: my @types = ('xml','req');
2101: if (ref($settings) eq 'HASH') {
2102: foreach my $item (@types) {
2103: $createoff{$item} = ' checked="checked" ';
2104: $createon{$item} = ' ';
2105: if (exists($settings->{$item})) {
2106: if ($settings->{$item}) {
2107: $createon{$item} = ' checked="checked" ';
2108: $createoff{$item} = ' ';
2109: }
2110: }
2111: }
2112: $curr_dc = $settings->{'xmldc'};
2113: } else {
2114: foreach my $item (@types) {
2115: $createoff{$item} = ' checked="checked" ';
2116: $createon{$item} = ' ';
2117: }
2118: }
2119: $$rowtotal += 2;
2120: my $datatable='<tr class="LC_odd_row">'.
2121: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2122: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2123: '<input type="radio" name="autocreate_xml"'.
2124: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2125: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2126: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2127: '</td></tr><tr>'.
2128: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2129: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2130: '<input type="radio" name="autocreate_req"'.
2131: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2132: '<label><input type="radio" name="autocreate_req"'.
2133: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2134: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2135: if ($numdc > 1) {
1.143 raeburn 2136: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2137: &mt('Course creation processed as: (choose Dom. Coord.)').
2138: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2139: $$rowtotal ++ ;
2140: } else {
1.143 raeburn 2141: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2142: }
2143: return $datatable;
2144: }
2145:
1.23 raeburn 2146: sub print_directorysrch {
1.30 raeburn 2147: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2148: my $srchon = ' ';
2149: my $srchoff = ' checked="checked" ';
1.25 raeburn 2150: my ($exacton,$containson,$beginson);
1.24 raeburn 2151: my $localon = ' ';
2152: my $localoff = ' checked="checked" ';
1.23 raeburn 2153: if (ref($settings) eq 'HASH') {
2154: if ($settings->{'available'} eq '1') {
2155: $srchon = $srchoff;
2156: $srchoff = ' ';
2157: }
1.24 raeburn 2158: if ($settings->{'localonly'} eq '1') {
2159: $localon = $localoff;
2160: $localoff = ' ';
2161: }
1.25 raeburn 2162: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2163: foreach my $type (@{$settings->{'searchtypes'}}) {
2164: if ($type eq 'exact') {
2165: $exacton = ' checked="checked" ';
2166: } elsif ($type eq 'contains') {
2167: $containson = ' checked="checked" ';
2168: } elsif ($type eq 'begins') {
2169: $beginson = ' checked="checked" ';
2170: }
2171: }
2172: } else {
2173: if ($settings->{'searchtypes'} eq 'exact') {
2174: $exacton = ' checked="checked" ';
2175: } elsif ($settings->{'searchtypes'} eq 'contains') {
2176: $containson = ' checked="checked" ';
2177: } elsif ($settings->{'searchtypes'} eq 'specify') {
2178: $exacton = ' checked="checked" ';
2179: $containson = ' checked="checked" ';
2180: }
1.23 raeburn 2181: }
2182: }
2183: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2184: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2185:
2186: my $numinrow = 4;
1.26 raeburn 2187: my $cansrchrow = 0;
1.23 raeburn 2188: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2189: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2190: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2191: '<input type="radio" name="dirsrch_available"'.
2192: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2193: '<label><input type="radio" name="dirsrch_available"'.
2194: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2195: '</tr><tr>'.
1.30 raeburn 2196: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2197: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2198: '<input type="radio" name="dirsrch_localonly"'.
2199: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2200: '<label><input type="radio" name="dirsrch_localonly"'.
2201: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2202: '</tr>';
1.30 raeburn 2203: $$rowtotal += 2;
1.26 raeburn 2204: if (ref($usertypes) eq 'HASH') {
2205: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2206: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2207: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2208: $cansrchrow = 1;
2209: }
2210: }
2211: if ($cansrchrow) {
1.30 raeburn 2212: $$rowtotal ++;
1.26 raeburn 2213: $datatable .= '<tr>';
2214: } else {
2215: $datatable .= '<tr class="LC_odd_row">';
2216: }
1.30 raeburn 2217: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2218: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2219: foreach my $title (@{$titleorder}) {
2220: if (defined($searchtitles->{$title})) {
2221: my $check = ' ';
1.93 raeburn 2222: if (ref($settings) eq 'HASH') {
1.39 raeburn 2223: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2224: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2225: $check = ' checked="checked" ';
2226: }
1.25 raeburn 2227: }
2228: }
2229: $datatable .= '<td class="LC_left_item">'.
2230: '<span class="LC_nobreak"><label>'.
2231: '<input type="checkbox" name="searchby" '.
2232: 'value="'.$title.'"'.$check.'/>'.
2233: $searchtitles->{$title}.'</label></span></td>';
2234: }
2235: }
1.26 raeburn 2236: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2237: $$rowtotal ++;
1.26 raeburn 2238: if ($cansrchrow) {
2239: $datatable .= '<tr class="LC_odd_row">';
2240: } else {
2241: $datatable .= '<tr>';
2242: }
1.30 raeburn 2243: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2244: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2245: '<span class="LC_nobreak"><label>'.
2246: '<input type="checkbox" name="searchtypes" '.
2247: $exacton.' value="exact" />'.&mt('Exact match').
2248: '</label> '.
2249: '<label><input type="checkbox" name="searchtypes" '.
2250: $beginson.' value="begins" />'.&mt('Begins with').
2251: '</label> '.
2252: '<label><input type="checkbox" name="searchtypes" '.
2253: $containson.' value="contains" />'.&mt('Contains').
2254: '</label></span></td></tr>';
1.30 raeburn 2255: $$rowtotal ++;
1.25 raeburn 2256: return $datatable;
2257: }
2258:
1.28 raeburn 2259: sub print_contacts {
1.30 raeburn 2260: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2261: my $datatable;
2262: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2263: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2264: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2265: 'requestsmail');
1.28 raeburn 2266: foreach my $type (@mailings) {
2267: $otheremails{$type} = '';
2268: }
1.134 raeburn 2269: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2270: if (ref($settings) eq 'HASH') {
2271: foreach my $item (@contacts) {
2272: if (exists($settings->{$item})) {
2273: $to{$item} = $settings->{$item};
2274: }
2275: }
2276: foreach my $type (@mailings) {
2277: if (exists($settings->{$type})) {
2278: if (ref($settings->{$type}) eq 'HASH') {
2279: foreach my $item (@contacts) {
2280: if ($settings->{$type}{$item}) {
2281: $checked{$type}{$item} = ' checked="checked" ';
2282: }
2283: }
2284: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2285: if ($type eq 'helpdeskmail') {
2286: $bccemails{$type} = $settings->{$type}{'bcc'};
2287: }
1.28 raeburn 2288: }
1.89 raeburn 2289: } elsif ($type eq 'lonstatusmail') {
2290: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2291: }
2292: }
2293: } else {
2294: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2295: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2296: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2297: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2298: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2299: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2300: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2301: }
2302: my ($titles,$short_titles) = &contact_titles();
2303: my $rownum = 0;
2304: my $css_class;
2305: foreach my $item (@contacts) {
1.69 raeburn 2306: $rownum ++;
2307: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2308: $datatable .= '<tr'.$css_class.'>'.
2309: '<td><span class="LC_nobreak">'.$titles->{$item}.
2310: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2311: '<input type="text" name="'.$item.'" value="'.
2312: $to{$item}.'" /></td></tr>';
2313: }
2314: foreach my $type (@mailings) {
1.69 raeburn 2315: $rownum ++;
2316: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2317: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2318: '<td><span class="LC_nobreak">'.
2319: $titles->{$type}.': </span></td>'.
1.28 raeburn 2320: '<td class="LC_left_item">'.
2321: '<span class="LC_nobreak">';
2322: foreach my $item (@contacts) {
2323: $datatable .= '<label>'.
2324: '<input type="checkbox" name="'.$type.'"'.
2325: $checked{$type}{$item}.
2326: ' value="'.$item.'" />'.$short_titles->{$item}.
2327: '</label> ';
2328: }
2329: $datatable .= '</span><br />'.&mt('Others').': '.
2330: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2331: 'value="'.$otheremails{$type}.'" />';
2332: if ($type eq 'helpdeskmail') {
1.136 raeburn 2333: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2334: '<input type="text" name="'.$type.'_bcc" '.
2335: 'value="'.$bccemails{$type}.'" />';
2336: }
2337: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2338: }
1.30 raeburn 2339: $$rowtotal += $rownum;
1.28 raeburn 2340: return $datatable;
2341: }
2342:
1.118 jms 2343: sub print_helpsettings {
1.160.6.5 raeburn 2344: my ($dom,$confname,$settings,$rowtotal) = @_;
2345: my ($datatable,$itemcount);
2346: $itemcount = 1;
2347: my (%choices,%defaultchecked,@toggles);
2348: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2349: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2350: &mt('LON-CAPA bug tracker'),600,500));
2351: %defaultchecked = ('submitbugs' => 'on');
2352: @toggles = ('submitbugs',);
1.122 jms 2353:
1.160.6.5 raeburn 2354: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2355: \%choices,$itemcount);
2356: return $datatable;
1.121 raeburn 2357: }
2358:
2359: sub radiobutton_prefs {
2360: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2361: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2362: (ref($choices) eq 'HASH'));
2363:
2364: my (%checkedon,%checkedoff,$datatable,$css_class);
2365:
2366: foreach my $item (@{$toggles}) {
2367: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2368: $checkedon{$item} = ' checked="checked" ';
2369: $checkedoff{$item} = ' ';
1.121 raeburn 2370: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2371: $checkedoff{$item} = ' checked="checked" ';
2372: $checkedon{$item} = ' ';
2373: }
2374: }
2375: if (ref($settings) eq 'HASH') {
1.121 raeburn 2376: foreach my $item (@{$toggles}) {
1.118 jms 2377: if ($settings->{$item} eq '1') {
2378: $checkedon{$item} = ' checked="checked" ';
2379: $checkedoff{$item} = ' ';
2380: } elsif ($settings->{$item} eq '0') {
2381: $checkedoff{$item} = ' checked="checked" ';
2382: $checkedon{$item} = ' ';
2383: }
2384: }
1.121 raeburn 2385: }
2386: foreach my $item (@{$toggles}) {
1.118 jms 2387: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2388: $datatable .=
2389: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2390: '</span></td>'.
2391: '<td class="LC_right_item"><span class="LC_nobreak">'.
2392: '<label><input type="radio" name="'.
2393: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2394: '</label> <label><input type="radio" name="'.$item.'" '.
2395: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2396: '</span></td>'.
2397: '</tr>';
2398: $itemcount ++;
1.121 raeburn 2399: }
2400: return ($datatable,$itemcount);
2401: }
2402:
2403: sub print_coursedefaults {
1.139 raeburn 2404: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2405: my ($css_class,$datatable);
2406: my $itemcount = 1;
1.139 raeburn 2407: if ($position eq 'top') {
2408: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2409: %choices =
2410: &Apache::lonlocal::texthash (
2411: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2412: );
2413: %defaultchecked = ('canuse_pdfforms' => 'off');
2414: @toggles = ('canuse_pdfforms',);
2415: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2416: \%choices,$itemcount);
1.139 raeburn 2417: $$rowtotal += $itemcount;
2418: } else {
2419: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2420: my %choices =
2421: &Apache::lonlocal::texthash (
2422: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2423: );
2424: my $currdefresponder;
2425: if (ref($settings) eq 'HASH') {
2426: $currdefresponder = $settings->{'anonsurvey_threshold'};
2427: }
2428: if (!$currdefresponder) {
2429: $currdefresponder = 10;
2430: } elsif ($currdefresponder < 1) {
2431: $currdefresponder = 1;
2432: }
2433: $datatable .=
2434: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2435: '</span></td>'.
2436: '<td class="LC_right_item"><span class="LC_nobreak">'.
2437: '<input type="text" name="anonsurvey_threshold"'.
2438: ' value="'.$currdefresponder.'" size="5" /></span>'.
2439: '</td></tr>';
2440: }
1.121 raeburn 2441: return $datatable;
1.118 jms 2442: }
2443:
1.137 raeburn 2444: sub print_usersessions {
2445: my ($position,$dom,$settings,$rowtotal) = @_;
2446: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2447: my (%by_ip,%by_location,@intdoms);
2448: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2449:
2450: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2451: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2452: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2453: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2454: my $itemcount = 1;
2455: if ($position eq 'top') {
1.152 raeburn 2456: if (keys(%serverhomes) > 1) {
1.145 raeburn 2457: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2458: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2459: } else {
1.140 raeburn 2460: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2461: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2462: }
1.137 raeburn 2463: } else {
1.145 raeburn 2464: if (keys(%by_location) == 0) {
2465: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2466: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2467: } else {
2468: my %lt = &usersession_titles();
2469: my $numinrow = 5;
2470: my $prefix;
2471: my @types;
2472: if ($position eq 'bottom') {
2473: $prefix = 'remote';
2474: @types = ('version','excludedomain','includedomain');
2475: } else {
2476: $prefix = 'hosted';
2477: @types = ('excludedomain','includedomain');
2478: }
2479: my (%current,%checkedon,%checkedoff);
2480: my @lcversions = &Apache::lonnet::all_loncaparevs();
2481: my @locations = sort(keys(%by_location));
2482: foreach my $type (@types) {
2483: $checkedon{$type} = '';
2484: $checkedoff{$type} = ' checked="checked"';
2485: }
2486: if (ref($settings) eq 'HASH') {
2487: if (ref($settings->{$prefix}) eq 'HASH') {
2488: foreach my $key (keys(%{$settings->{$prefix}})) {
2489: $current{$key} = $settings->{$prefix}{$key};
2490: if ($key eq 'version') {
2491: if ($current{$key} ne '') {
2492: $checkedon{$key} = ' checked="checked"';
2493: $checkedoff{$key} = '';
2494: }
2495: } elsif (ref($current{$key}) eq 'ARRAY') {
2496: $checkedon{$key} = ' checked="checked"';
2497: $checkedoff{$key} = '';
2498: }
1.137 raeburn 2499: }
2500: }
2501: }
1.145 raeburn 2502: foreach my $type (@types) {
2503: next if ($type ne 'version' && !@locations);
2504: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2505: $datatable .= '<tr'.$css_class.'>
2506: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2507: <span class="LC_nobreak">
2508: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2509: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2510: if ($type eq 'version') {
2511: my $selector = '<select name="'.$prefix.'_version">';
2512: foreach my $version (@lcversions) {
2513: my $selected = '';
2514: if ($current{'version'} eq $version) {
2515: $selected = ' selected="selected"';
2516: }
2517: $selector .= ' <option value="'.$version.'"'.
2518: $selected.'>'.$version.'</option>';
2519: }
2520: $selector .= '</select> ';
2521: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2522: } else {
2523: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2524: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2525: ' />'.(' 'x2).
2526: '<input type="button" value="'.&mt('uncheck all').'" '.
2527: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2528: "\n".
2529: '</div><div><table>';
2530: my $rem;
2531: for (my $i=0; $i<@locations; $i++) {
2532: my ($showloc,$value,$checkedtype);
2533: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2534: my $ip = $by_location{$locations[$i]}->[0];
2535: if (ref($by_ip{$ip}) eq 'ARRAY') {
2536: $value = join(':',@{$by_ip{$ip}});
2537: $showloc = join(', ',@{$by_ip{$ip}});
2538: if (ref($current{$type}) eq 'ARRAY') {
2539: foreach my $loc (@{$by_ip{$ip}}) {
2540: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2541: $checkedtype = ' checked="checked"';
2542: last;
2543: }
2544: }
1.138 raeburn 2545: }
2546: }
2547: }
1.145 raeburn 2548: $rem = $i%($numinrow);
2549: if ($rem == 0) {
2550: if ($i > 0) {
2551: $datatable .= '</tr>';
2552: }
2553: $datatable .= '<tr>';
2554: }
2555: $datatable .= '<td class="LC_left_item">'.
2556: '<span class="LC_nobreak"><label>'.
2557: '<input type="checkbox" name="'.$prefix.'_'.$type.
2558: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2559: '</label></span></td>';
1.137 raeburn 2560: }
1.145 raeburn 2561: $rem = @locations%($numinrow);
2562: my $colsleft = $numinrow - $rem;
2563: if ($colsleft > 1 ) {
2564: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2565: ' </td>';
2566: } elsif ($colsleft == 1) {
2567: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2568: }
1.145 raeburn 2569: $datatable .= '</tr></table>';
1.137 raeburn 2570: }
1.145 raeburn 2571: $datatable .= '</td></tr>';
2572: $itemcount ++;
1.137 raeburn 2573: }
2574: }
2575: }
2576: $$rowtotal += $itemcount;
2577: return $datatable;
2578: }
2579:
1.138 raeburn 2580: sub build_location_hashes {
2581: my ($intdoms,$by_ip,$by_location) = @_;
2582: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2583: (ref($by_location) eq 'HASH'));
2584: my %iphost = &Apache::lonnet::get_iphost();
2585: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2586: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2587: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2588: foreach my $id (@{$iphost{$primary_ip}}) {
2589: my $intdom = &Apache::lonnet::internet_dom($id);
2590: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2591: push(@{$intdoms},$intdom);
2592: }
2593: }
2594: }
2595: foreach my $ip (keys(%iphost)) {
2596: if (ref($iphost{$ip}) eq 'ARRAY') {
2597: foreach my $id (@{$iphost{$ip}}) {
2598: my $location = &Apache::lonnet::internet_dom($id);
2599: if ($location) {
2600: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2601: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2602: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2603: push(@{$by_ip->{$ip}},$location);
2604: }
2605: } else {
2606: $by_ip->{$ip} = [$location];
2607: }
2608: }
2609: }
2610: }
2611: }
2612: foreach my $ip (sort(keys(%{$by_ip}))) {
2613: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2614: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2615: my $first = $by_ip->{$ip}->[0];
2616: if (ref($by_location->{$first}) eq 'ARRAY') {
2617: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2618: push(@{$by_location->{$first}},$ip);
2619: }
2620: } else {
2621: $by_location->{$first} = [$ip];
2622: }
2623: }
2624: }
2625: return;
2626: }
2627:
1.145 raeburn 2628: sub current_offloads_to {
2629: my ($dom,$settings,$servers) = @_;
2630: my (%spareid,%otherdomconfigs);
1.152 raeburn 2631: if (ref($servers) eq 'HASH') {
1.145 raeburn 2632: foreach my $lonhost (sort(keys(%{$servers}))) {
2633: my $gotspares;
1.152 raeburn 2634: if (ref($settings) eq 'HASH') {
2635: if (ref($settings->{'spares'}) eq 'HASH') {
2636: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2637: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2638: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2639: $gotspares = 1;
2640: }
1.145 raeburn 2641: }
2642: }
2643: unless ($gotspares) {
2644: my $gotspares;
2645: my $serverhomeID =
2646: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2647: my $serverhomedom =
2648: &Apache::lonnet::host_domain($serverhomeID);
2649: if ($serverhomedom ne $dom) {
2650: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2651: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2652: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2653: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2654: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2655: $gotspares = 1;
2656: }
2657: }
2658: } else {
2659: $otherdomconfigs{$serverhomedom} =
2660: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2661: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2662: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2663: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2664: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2665: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2666: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2667: $gotspares = 1;
2668: }
2669: }
2670: }
2671: }
2672: }
2673: }
2674: }
2675: unless ($gotspares) {
2676: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2677: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2678: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2679: } else {
2680: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2681: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2682: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2683: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2684: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2685: } else {
1.150 raeburn 2686: my %what = (
2687: spareid => 1,
2688: );
2689: my ($result,$returnhash) =
2690: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2691: if ($result eq 'ok') {
2692: if (ref($returnhash) eq 'HASH') {
2693: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2694: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2695: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2696: }
2697: }
1.145 raeburn 2698: }
2699: }
2700: }
2701: }
2702: }
2703: }
2704: return %spareid;
2705: }
2706:
2707: sub spares_row {
1.152 raeburn 2708: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2709: my $css_class;
2710: my $numinrow = 4;
2711: my $itemcount = 1;
2712: my $datatable;
1.152 raeburn 2713: my %typetitles = &sparestype_titles();
2714: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2715: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2716: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2717: my ($othercontrol,$serverdom);
2718: if ($serverhome ne $server) {
2719: $serverdom = &Apache::lonnet::host_domain($serverhome);
2720: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2721: } else {
2722: $serverdom = &Apache::lonnet::host_domain($server);
2723: if ($serverdom ne $dom) {
2724: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2725: }
2726: }
2727: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2728: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2729: $datatable .= '<tr'.$css_class.'>
2730: <td rowspan="2">
1.152 raeburn 2731: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2732: my (%current,%canselect);
1.152 raeburn 2733: my @choices =
2734: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2735: foreach my $type ('primary','default') {
2736: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2737: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2738: my @spares = @{$spareid->{$server}{$type}};
2739: if (@spares > 0) {
1.152 raeburn 2740: if ($othercontrol) {
2741: $current{$type} = join(', ',@spares);
2742: } else {
2743: $current{$type} .= '<table>';
2744: my $numspares = scalar(@spares);
2745: for (my $i=0; $i<@spares; $i++) {
2746: my $rem = $i%($numinrow);
2747: if ($rem == 0) {
2748: if ($i > 0) {
2749: $current{$type} .= '</tr>';
2750: }
2751: $current{$type} .= '<tr>';
1.145 raeburn 2752: }
1.152 raeburn 2753: $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'".');" /> '.
2754: $spareid->{$server}{$type}[$i].
2755: '</label></td>'."\n";
2756: }
2757: my $rem = @spares%($numinrow);
2758: my $colsleft = $numinrow - $rem;
2759: if ($colsleft > 1 ) {
2760: $current{$type} .= '<td colspan="'.$colsleft.
2761: '" class="LC_left_item">'.
2762: ' </td>';
2763: } elsif ($colsleft == 1) {
2764: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2765: }
1.152 raeburn 2766: $current{$type} .= '</tr></table>';
1.150 raeburn 2767: }
1.145 raeburn 2768: }
2769: }
2770: if ($current{$type} eq '') {
2771: $current{$type} = &mt('None specified');
2772: }
1.152 raeburn 2773: if ($othercontrol) {
2774: if ($type eq 'primary') {
2775: $canselect{$type} = $othercontrol;
2776: }
2777: } else {
2778: $canselect{$type} =
2779: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2780: '<select name="newspare_'.$type.'_'.$server.'" '.
2781: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2782: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2783: if (@choices > 0) {
2784: foreach my $lonhost (@choices) {
2785: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2786: }
2787: }
2788: $canselect{$type} .= '</select>'."\n";
2789: }
2790: } else {
2791: $current{$type} = &mt('Could not be determined');
2792: if ($type eq 'primary') {
2793: $canselect{$type} = $othercontrol;
2794: }
1.145 raeburn 2795: }
1.152 raeburn 2796: if ($type eq 'default') {
2797: $datatable .= '<tr'.$css_class.'>';
2798: }
2799: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2800: '<td>'.$current{$type}.'</td>'."\n".
2801: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2802: }
2803: $itemcount ++;
2804: }
2805: }
2806: $$rowtotal += $itemcount;
2807: return $datatable;
2808: }
2809:
1.152 raeburn 2810: sub possible_newspares {
2811: my ($server,$currspares,$serverhomes,$altids) = @_;
2812: my $serverhostname = &Apache::lonnet::hostname($server);
2813: my %excluded;
2814: if ($serverhostname ne '') {
2815: %excluded = (
2816: $serverhostname => 1,
2817: );
2818: }
2819: if (ref($currspares) eq 'HASH') {
2820: foreach my $type (keys(%{$currspares})) {
2821: if (ref($currspares->{$type}) eq 'ARRAY') {
2822: if (@{$currspares->{$type}} > 0) {
2823: foreach my $curr (@{$currspares->{$type}}) {
2824: my $hostname = &Apache::lonnet::hostname($curr);
2825: $excluded{$hostname} = 1;
2826: }
2827: }
2828: }
2829: }
2830: }
2831: my @choices;
2832: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2833: if (keys(%{$serverhomes}) > 1) {
2834: foreach my $name (sort(keys(%{$serverhomes}))) {
2835: unless ($excluded{$name}) {
2836: if (exists($altids->{$serverhomes->{$name}})) {
2837: push(@choices,$altids->{$serverhomes->{$name}});
2838: } else {
2839: push(@choices,$serverhomes->{$name});
1.145 raeburn 2840: }
2841: }
2842: }
2843: }
2844: }
1.152 raeburn 2845: return sort(@choices);
1.145 raeburn 2846: }
2847:
1.150 raeburn 2848: sub print_loadbalancing {
2849: my ($dom,$settings,$rowtotal) = @_;
2850: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2851: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2852: my $numinrow = 1;
2853: my $datatable;
2854: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2855: my (%currbalancer,%currtargets,%currrules,%existing);
2856: if (ref($settings) eq 'HASH') {
2857: %existing = %{$settings};
2858: }
2859: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2860: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2861: \%currtargets,\%currrules);
1.150 raeburn 2862: } else {
2863: return;
2864: }
2865: my ($othertitle,$usertypes,$types) =
2866: &Apache::loncommon::sorted_inst_types($dom);
2867: my $rownum = 6;
2868: if (ref($types) eq 'ARRAY') {
2869: $rownum += scalar(@{$types});
2870: }
1.160.6.7 raeburn 2871: my @css_class = ('LC_odd_row','LC_even_row');
2872: my $balnum = 0;
2873: my $islast;
2874: my (@toshow,$disabledtext);
2875: if (keys(%currbalancer) > 0) {
2876: @toshow = sort(keys(%currbalancer));
2877: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2878: push(@toshow,'');
2879: }
2880: } else {
2881: @toshow = ('');
2882: $disabledtext = &mt('No existing load balancer');
2883: }
2884: foreach my $lonhost (@toshow) {
2885: if ($balnum == scalar(@toshow)-1) {
2886: $islast = 1;
2887: } else {
2888: $islast = 0;
2889: }
2890: my $cssidx = $balnum%2;
2891: my $targets_div_style = 'display: none';
2892: my $disabled_div_style = 'display: block';
2893: my $homedom_div_style = 'display: none';
2894: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2895: '<td rowspan="'.$rownum.'" valign="top">'.
2896: '<p>';
2897: if ($lonhost eq '') {
2898: $datatable .= '<span class="LC_nobreak">';
2899: if (keys(%currbalancer) > 0) {
2900: $datatable .= &mt('Add balancer:');
2901: } else {
2902: $datatable .= &mt('Enable balancer:');
2903: }
2904: $datatable .= ' '.
2905: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2906: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2907: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2908: '<option value="" selected="selected">'.&mt('None').
2909: '</option>'."\n";
2910: foreach my $server (sort(keys(%servers))) {
2911: next if ($currbalancer{$server});
2912: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2913: }
2914: $datatable .=
2915: '</select>'."\n".
2916: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2917: } else {
2918: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2919: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2920: &mt('Stop balancing').'</label>'.
2921: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2922: $targets_div_style = 'display: block';
2923: $disabled_div_style = 'display: none';
2924: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2925: $homedom_div_style = 'display: block';
2926: }
2927: }
2928: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2929: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2930: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2931: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2932: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2933: my @sparestypes = ('primary','default');
2934: my %typetitles = &sparestype_titles();
2935: foreach my $sparetype (@sparestypes) {
2936: my $targettable;
2937: for (my $i=0; $i<$numspares; $i++) {
2938: my $checked;
2939: if (ref($currtargets{$lonhost}) eq 'HASH') {
2940: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
2941: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
2942: $checked = ' checked="checked"';
2943: }
2944: }
2945: }
2946: my ($chkboxval,$disabled);
2947: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
2948: $chkboxval = $spares[$i];
2949: }
2950: if (exists($currbalancer{$spares[$i]})) {
2951: $disabled = ' disabled="disabled"';
2952: }
2953: $targettable .=
2954: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
2955: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2956: '</span></label></td>';
2957: my $rem = $i%($numinrow);
2958: if ($rem == 0) {
2959: if (($i > 0) && ($i < $numspares-1)) {
2960: $targettable .= '</tr>';
2961: }
2962: if ($i < $numspares-1) {
2963: $targettable .= '<tr>';
1.150 raeburn 2964: }
2965: }
2966: }
1.160.6.7 raeburn 2967: if ($targettable ne '') {
2968: my $rem = $numspares%($numinrow);
2969: my $colsleft = $numinrow - $rem;
2970: if ($colsleft > 1 ) {
2971: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2972: ' </td>';
2973: } elsif ($colsleft == 1) {
2974: $targettable .= '<td class="LC_left_item"> </td>';
2975: }
2976: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2977: '<table><tr>'.$targettable.'</tr></table><br />';
2978: }
2979: }
2980: my $cssidx = $balnum%2;
2981: $datatable .= '</div></td></tr>'.
2982: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
2983: $othertitle,$usertypes,$types,\%servers,
2984: \%currbalancer,$lonhost,
2985: $targets_div_style,$homedom_div_style,
2986: $css_class[$cssidx],$balnum,$islast);
2987: $$rowtotal += $rownum;
2988: $balnum ++;
2989: }
2990: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
2991: return $datatable;
2992: }
2993:
2994: sub get_loadbalancers_config {
2995: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
2996: return unless ((ref($servers) eq 'HASH') &&
2997: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
2998: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
2999: if (keys(%{$existing}) > 0) {
3000: my $oldlonhost;
3001: foreach my $key (sort(keys(%{$existing}))) {
3002: if ($key eq 'lonhost') {
3003: $oldlonhost = $existing->{'lonhost'};
3004: $currbalancer->{$oldlonhost} = 1;
3005: } elsif ($key eq 'targets') {
3006: if ($oldlonhost) {
3007: $currtargets->{$oldlonhost} = $existing->{'targets'};
3008: }
3009: } elsif ($key eq 'rules') {
3010: if ($oldlonhost) {
3011: $currrules->{$oldlonhost} = $existing->{'rules'};
3012: }
3013: } elsif (ref($existing->{$key}) eq 'HASH') {
3014: $currbalancer->{$key} = 1;
3015: $currtargets->{$key} = $existing->{$key}{'targets'};
3016: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3017: }
3018: }
1.160.6.7 raeburn 3019: } else {
3020: my ($balancerref,$targetsref) =
3021: &Apache::lonnet::get_lonbalancer_config($servers);
3022: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3023: foreach my $server (sort(keys(%{$balancerref}))) {
3024: $currbalancer->{$server} = 1;
3025: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3026: }
3027: }
3028: }
1.160.6.7 raeburn 3029: return;
1.150 raeburn 3030: }
3031:
3032: sub loadbalancing_rules {
3033: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3034: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3035: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3036: my $output;
1.160.6.7 raeburn 3037: my $num = 0;
3038: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3039: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3040: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3041: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3042: $num ++;
1.150 raeburn 3043: my $current;
3044: if (ref($currrules) eq 'HASH') {
3045: $current = $currrules->{$type};
3046: }
3047: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3048: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3049: $current = '';
3050: }
3051: }
3052: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3053: $servers,$currbalancer,$lonhost,$dom,
3054: $targets_div_style,$homedom_div_style,
3055: $css_class,$balnum,$num,$islast);
1.150 raeburn 3056: }
3057: }
3058: return $output;
3059: }
3060:
3061: sub loadbalancing_titles {
3062: my ($dom,$intdom,$usertypes,$types) = @_;
3063: my %othertypes = (
3064: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3065: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3066: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3067: '_LC_external' => &mt('Users not from [_1]',$intdom),
3068: );
3069: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3070: if (ref($types) eq 'ARRAY') {
3071: unshift(@alltypes,@{$types},'default');
3072: }
3073: my %titles;
3074: foreach my $type (@alltypes) {
3075: if ($type =~ /^_LC_/) {
3076: $titles{$type} = $othertypes{$type};
3077: } elsif ($type eq 'default') {
3078: $titles{$type} = &mt('All users from [_1]',$dom);
3079: if (ref($types) eq 'ARRAY') {
3080: if (@{$types} > 0) {
3081: $titles{$type} = &mt('Other users from [_1]',$dom);
3082: }
3083: }
3084: } elsif (ref($usertypes) eq 'HASH') {
3085: $titles{$type} = $usertypes->{$type};
3086: }
3087: }
3088: return (\@alltypes,\%othertypes,\%titles);
3089: }
3090:
3091: sub loadbalance_rule_row {
1.160.6.7 raeburn 3092: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3093: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3094: my @rulenames = ('default','homeserver');
3095: my %ruletitles = &offloadtype_text();
3096: if ($type eq '_LC_external') {
3097: push(@rulenames,'externalbalancer');
3098: } else {
3099: push(@rulenames,'specific');
3100: }
1.160.6.3 raeburn 3101: push(@rulenames,'none');
1.150 raeburn 3102: my $style = $targets_div_style;
3103: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3104: $style = $homedom_div_style;
3105: }
1.160.6.7 raeburn 3106: my $space;
3107: if ($islast && $num == 1) {
3108: $space = '<div display="inline-block"> </div>';
3109: }
3110: my $output =
3111: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3112: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3113: '<td valaign="top">'.$space.
3114: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3115: for (my $i=0; $i<@rulenames; $i++) {
3116: my $rule = $rulenames[$i];
3117: my ($checked,$extra);
3118: if ($rulenames[$i] eq 'default') {
3119: $rule = '';
3120: }
3121: if ($rulenames[$i] eq 'specific') {
3122: if (ref($servers) eq 'HASH') {
3123: my $default;
3124: if (($current ne '') && (exists($servers->{$current}))) {
3125: $checked = ' checked="checked"';
3126: }
3127: unless ($checked) {
3128: $default = ' selected="selected"';
3129: }
1.160.6.7 raeburn 3130: $extra =
3131: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3132: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3133: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3134: '<option value=""'.$default.'></option>'."\n";
3135: foreach my $server (sort(keys(%{$servers}))) {
3136: if (ref($currbalancer) eq 'HASH') {
3137: next if (exists($currbalancer->{$server}));
3138: }
1.150 raeburn 3139: my $selected;
1.160.6.7 raeburn 3140: if ($server eq $current) {
1.150 raeburn 3141: $selected = ' selected="selected"';
3142: }
1.160.6.7 raeburn 3143: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3144: }
3145: $extra .= '</select>';
3146: }
3147: } elsif ($rule eq $current) {
3148: $checked = ' checked="checked"';
3149: }
3150: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3151: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3152: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3153: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3154: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3155: '</label>'.$extra.'</span><br />'."\n";
3156: }
3157: $output .= '</div></td></tr>'."\n";
3158: return $output;
3159: }
3160:
3161: sub offloadtype_text {
3162: my %ruletitles = &Apache::lonlocal::texthash (
3163: 'default' => 'Offloads to default destinations',
3164: 'homeserver' => "Offloads to user's home server",
3165: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3166: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3167: 'none' => 'No offload',
1.150 raeburn 3168: );
3169: return %ruletitles;
3170: }
3171:
3172: sub sparestype_titles {
3173: my %typestitles = &Apache::lonlocal::texthash (
3174: 'primary' => 'primary',
3175: 'default' => 'default',
3176: );
3177: return %typestitles;
3178: }
3179:
1.28 raeburn 3180: sub contact_titles {
3181: my %titles = &Apache::lonlocal::texthash (
3182: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3183: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3184: 'errormail' => 'Error reports to be e-mailed to',
3185: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3186: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3187: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3188: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3189: );
3190: my %short_titles = &Apache::lonlocal::texthash (
3191: adminemail => 'Admin E-mail address',
3192: supportemail => 'Support E-mail',
3193: );
3194: return (\%titles,\%short_titles);
3195: }
3196:
1.72 raeburn 3197: sub tool_titles {
3198: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3199: aboutme => 'Personal web page',
1.86 raeburn 3200: blog => 'Blog',
1.160.6.4 raeburn 3201: webdav => 'WebDAV',
1.86 raeburn 3202: portfolio => 'Portfolio',
1.88 bisitz 3203: official => 'Official courses (with institutional codes)',
3204: unofficial => 'Unofficial courses',
1.98 raeburn 3205: community => 'Communities',
1.86 raeburn 3206: );
1.72 raeburn 3207: return %titles;
3208: }
3209:
1.101 raeburn 3210: sub courserequest_titles {
3211: my %titles = &Apache::lonlocal::texthash (
3212: official => 'Official',
3213: unofficial => 'Unofficial',
3214: community => 'Communities',
3215: norequest => 'Not allowed',
1.104 raeburn 3216: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3217: validate => 'With validation',
3218: autolimit => 'Numerical limit',
1.103 raeburn 3219: unlimited => '(blank for unlimited)',
1.101 raeburn 3220: );
3221: return %titles;
3222: }
3223:
1.160.6.5 raeburn 3224: sub authorrequest_titles {
3225: my %titles = &Apache::lonlocal::texthash (
3226: norequest => 'Not allowed',
3227: approval => 'Approval by Dom. Coord.',
3228: automatic => 'Automatic approval',
3229: );
3230: return %titles;
3231: }
3232:
1.101 raeburn 3233: sub courserequest_conditions {
3234: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3235: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3236: validate => '(Processing of request subject to instittutional validation).',
3237: );
3238: return %conditions;
3239: }
3240:
3241:
1.27 raeburn 3242: sub print_usercreation {
1.30 raeburn 3243: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3244: my $numinrow = 4;
1.28 raeburn 3245: my $datatable;
3246: if ($position eq 'top') {
1.30 raeburn 3247: $$rowtotal ++;
1.34 raeburn 3248: my $rowcount = 0;
1.32 raeburn 3249: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3250: if (ref($rules) eq 'HASH') {
3251: if (keys(%{$rules}) > 0) {
1.32 raeburn 3252: $datatable .= &user_formats_row('username',$settings,$rules,
3253: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3254: $$rowtotal ++;
1.32 raeburn 3255: $rowcount ++;
3256: }
3257: }
3258: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3259: if (ref($idrules) eq 'HASH') {
3260: if (keys(%{$idrules}) > 0) {
3261: $datatable .= &user_formats_row('id',$settings,$idrules,
3262: $idruleorder,$numinrow,$rowcount);
3263: $$rowtotal ++;
3264: $rowcount ++;
1.28 raeburn 3265: }
3266: }
1.43 raeburn 3267: my ($emailrules,$emailruleorder) =
3268: &Apache::lonnet::inst_userrules($dom,'email');
3269: if (ref($emailrules) eq 'HASH') {
3270: if (keys(%{$emailrules}) > 0) {
3271: $datatable .= &user_formats_row('email',$settings,$emailrules,
3272: $emailruleorder,$numinrow,$rowcount);
3273: $$rowtotal ++;
3274: $rowcount ++;
3275: }
3276: }
1.39 raeburn 3277: if ($rowcount == 0) {
3278: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3279: $$rowtotal ++;
3280: $rowcount ++;
3281: }
1.34 raeburn 3282: } elsif ($position eq 'middle') {
1.100 raeburn 3283: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3284: my ($rules,$ruleorder) =
3285: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3286: my %lt = &usercreation_types();
3287: my %checked;
1.50 raeburn 3288: my @selfcreate;
1.34 raeburn 3289: if (ref($settings) eq 'HASH') {
3290: if (ref($settings->{'cancreate'}) eq 'HASH') {
3291: foreach my $item (@creators) {
3292: $checked{$item} = $settings->{'cancreate'}{$item};
3293: }
1.50 raeburn 3294: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3295: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3296: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3297: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3298: @selfcreate = ('email','login','sso');
3299: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3300: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3301: }
3302: }
1.34 raeburn 3303: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3304: foreach my $item (@creators) {
3305: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3306: $checked{$item} = 'none';
3307: }
3308: }
3309: }
3310: }
3311: my $rownum = 0;
3312: foreach my $item (@creators) {
3313: $rownum ++;
1.50 raeburn 3314: if ($item ne 'selfcreate') {
3315: if ($checked{$item} eq '') {
1.43 raeburn 3316: $checked{$item} = 'any';
3317: }
1.34 raeburn 3318: }
3319: my $css_class;
3320: if ($rownum%2) {
3321: $css_class = '';
3322: } else {
3323: $css_class = ' class="LC_odd_row" ';
3324: }
3325: $datatable .= '<tr'.$css_class.'>'.
3326: '<td><span class="LC_nobreak">'.$lt{$item}.
3327: '</span></td><td align="right">';
1.50 raeburn 3328: my @options;
1.45 raeburn 3329: if ($item eq 'selfcreate') {
1.43 raeburn 3330: push(@options,('email','login','sso'));
3331: } else {
1.50 raeburn 3332: @options = ('any');
1.43 raeburn 3333: if (ref($rules) eq 'HASH') {
3334: if (keys(%{$rules}) > 0) {
3335: push(@options,('official','unofficial'));
3336: }
1.37 raeburn 3337: }
1.50 raeburn 3338: push(@options,'none');
1.37 raeburn 3339: }
3340: foreach my $option (@options) {
1.50 raeburn 3341: my $type = 'radio';
1.34 raeburn 3342: my $check = ' ';
1.50 raeburn 3343: if ($item eq 'selfcreate') {
3344: $type = 'checkbox';
3345: if (grep(/^\Q$option\E$/,@selfcreate)) {
3346: $check = ' checked="checked" ';
3347: }
3348: } else {
3349: if ($checked{$item} eq $option) {
3350: $check = ' checked="checked" ';
3351: }
1.34 raeburn 3352: }
3353: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3354: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3355: $item.'" value="'.$option.'"'.$check.'/> '.
3356: $lt{$option}.'</label> </span>';
3357: }
3358: $datatable .= '</td></tr>';
3359: }
1.93 raeburn 3360: my ($othertitle,$usertypes,$types) =
3361: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3362: my $createsettings;
3363: if (ref($settings) eq 'HASH') {
3364: $createsettings = $settings->{cancreate};
3365: }
1.93 raeburn 3366: if (ref($usertypes) eq 'HASH') {
3367: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3368: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3369: $dom,$numinrow,$othertitle,
3370: 'statustocreate');
3371: $$rowtotal ++;
1.160.6.5 raeburn 3372: $rownum ++;
1.93 raeburn 3373: }
3374: }
1.160.6.5 raeburn 3375: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3376: } else {
3377: my @contexts = ('author','course','domain');
3378: my @authtypes = ('int','krb4','krb5','loc');
3379: my %checked;
3380: if (ref($settings) eq 'HASH') {
3381: if (ref($settings->{'authtypes'}) eq 'HASH') {
3382: foreach my $item (@contexts) {
3383: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3384: foreach my $auth (@authtypes) {
3385: if ($settings->{'authtypes'}{$item}{$auth}) {
3386: $checked{$item}{$auth} = ' checked="checked" ';
3387: }
3388: }
3389: }
3390: }
1.27 raeburn 3391: }
1.35 raeburn 3392: } else {
3393: foreach my $item (@contexts) {
1.36 raeburn 3394: foreach my $auth (@authtypes) {
1.35 raeburn 3395: $checked{$item}{$auth} = ' checked="checked" ';
3396: }
3397: }
1.27 raeburn 3398: }
1.28 raeburn 3399: my %title = &context_names();
3400: my %authname = &authtype_names();
3401: my $rownum = 0;
3402: my $css_class;
3403: foreach my $item (@contexts) {
3404: if ($rownum%2) {
3405: $css_class = '';
3406: } else {
3407: $css_class = ' class="LC_odd_row" ';
3408: }
1.30 raeburn 3409: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3410: '<td>'.$title{$item}.
3411: '</td><td class="LC_left_item">'.
3412: '<span class="LC_nobreak">';
3413: foreach my $auth (@authtypes) {
3414: $datatable .= '<label>'.
3415: '<input type="checkbox" name="'.$item.'_auth" '.
3416: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3417: $authname{$auth}.'</label> ';
3418: }
3419: $datatable .= '</span></td></tr>';
3420: $rownum ++;
1.27 raeburn 3421: }
1.30 raeburn 3422: $$rowtotal += $rownum;
1.27 raeburn 3423: }
3424: return $datatable;
3425: }
3426:
1.160.6.5 raeburn 3427: sub captcha_choice {
3428: my ($context,$settings,$itemcount) = @_;
3429: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3430: my %lt = &captcha_phrases();
3431: $keyentry = 'hidden';
3432: if ($context eq 'cancreate') {
3433: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3434: } elsif ($context eq 'login') {
3435: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3436: }
3437: if (ref($settings) eq 'HASH') {
3438: if ($settings->{'captcha'}) {
3439: $checked{$settings->{'captcha'}} = ' checked="checked"';
3440: } else {
3441: $checked{'original'} = ' checked="checked"';
3442: }
3443: if ($settings->{'captcha'} eq 'recaptcha') {
3444: $pubtext = $lt{'pub'};
3445: $privtext = $lt{'priv'};
3446: $keyentry = 'text';
3447: }
3448: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3449: $currpub = $settings->{'recaptchakeys'}{'public'};
3450: $currpriv = $settings->{'recaptchakeys'}{'private'};
3451: }
3452: } else {
3453: $checked{'original'} = ' checked="checked"';
3454: }
3455: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3456: my $output = '<tr'.$css_class.'>'.
3457: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3458: '<table><tr><td>'."\n";
3459: foreach my $option ('original','recaptcha','notused') {
3460: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3461: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3462: $lt{$option}.'</label></span>';
3463: unless ($option eq 'notused') {
3464: $output .= (' 'x2)."\n";
3465: }
3466: }
3467: #
3468: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3469: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3470: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3471: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3472: #
3473: $output .= '</td></tr>'."\n".
3474: '<tr><td>'."\n".
3475: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3476: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3477: $currpub.'" size="40" /></span><br />'."\n".
3478: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3479: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3480: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3481: '</td></tr>';
3482: return $output;
3483: }
3484:
1.32 raeburn 3485: sub user_formats_row {
3486: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3487: my $output;
3488: my %text = (
3489: 'username' => 'new usernames',
3490: 'id' => 'IDs',
1.45 raeburn 3491: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3492: );
3493: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3494: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3495: '<td><span class="LC_nobreak">';
3496: if ($type eq 'email') {
3497: $output .= &mt("Formats disallowed for $text{$type}: ");
3498: } else {
3499: $output .= &mt("Format rules to check for $text{$type}: ");
3500: }
3501: $output .= '</span></td>'.
3502: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3503: my $rem;
3504: if (ref($ruleorder) eq 'ARRAY') {
3505: for (my $i=0; $i<@{$ruleorder}; $i++) {
3506: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3507: my $rem = $i%($numinrow);
3508: if ($rem == 0) {
3509: if ($i > 0) {
3510: $output .= '</tr>';
3511: }
3512: $output .= '<tr>';
3513: }
3514: my $check = ' ';
1.39 raeburn 3515: if (ref($settings) eq 'HASH') {
3516: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3517: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3518: $check = ' checked="checked" ';
3519: }
1.27 raeburn 3520: }
3521: }
3522: $output .= '<td class="LC_left_item">'.
3523: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3524: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3525: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3526: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3527: }
3528: }
3529: $rem = @{$ruleorder}%($numinrow);
3530: }
3531: my $colsleft = $numinrow - $rem;
3532: if ($colsleft > 1 ) {
3533: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3534: ' </td>';
3535: } elsif ($colsleft == 1) {
3536: $output .= '<td class="LC_left_item"> </td>';
3537: }
3538: $output .= '</tr></table></td></tr>';
3539: return $output;
3540: }
3541:
1.34 raeburn 3542: sub usercreation_types {
3543: my %lt = &Apache::lonlocal::texthash (
3544: author => 'When adding a co-author',
3545: course => 'When adding a user to a course',
1.100 raeburn 3546: requestcrs => 'When requesting a course',
1.45 raeburn 3547: selfcreate => 'User creates own account',
1.34 raeburn 3548: any => 'Any',
3549: official => 'Institutional only ',
3550: unofficial => 'Non-institutional only',
1.85 schafran 3551: email => 'E-mail address',
1.43 raeburn 3552: login => 'Institutional Login',
3553: sso => 'SSO',
1.34 raeburn 3554: none => 'None',
3555: );
3556: return %lt;
1.48 raeburn 3557: }
1.34 raeburn 3558:
1.28 raeburn 3559: sub authtype_names {
3560: my %lt = &Apache::lonlocal::texthash(
3561: int => 'Internal',
3562: krb4 => 'Kerberos 4',
3563: krb5 => 'Kerberos 5',
3564: loc => 'Local',
3565: );
3566: return %lt;
3567: }
3568:
3569: sub context_names {
3570: my %context_title = &Apache::lonlocal::texthash(
3571: author => 'Creating users when an Author',
3572: course => 'Creating users when in a course',
3573: domain => 'Creating users when a Domain Coordinator',
3574: );
3575: return %context_title;
3576: }
3577:
1.33 raeburn 3578: sub print_usermodification {
3579: my ($position,$dom,$settings,$rowtotal) = @_;
3580: my $numinrow = 4;
3581: my ($context,$datatable,$rowcount);
3582: if ($position eq 'top') {
3583: $rowcount = 0;
3584: $context = 'author';
3585: foreach my $role ('ca','aa') {
3586: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3587: $numinrow,$rowcount);
3588: $$rowtotal ++;
3589: $rowcount ++;
3590: }
1.63 raeburn 3591: } elsif ($position eq 'middle') {
1.33 raeburn 3592: $context = 'course';
3593: $rowcount = 0;
3594: foreach my $role ('st','ep','ta','in','cr') {
3595: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3596: $numinrow,$rowcount);
3597: $$rowtotal ++;
3598: $rowcount ++;
3599: }
1.63 raeburn 3600: } elsif ($position eq 'bottom') {
3601: $context = 'selfcreate';
3602: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3603: $usertypes->{'default'} = $othertitle;
3604: if (ref($types) eq 'ARRAY') {
3605: push(@{$types},'default');
3606: $usertypes->{'default'} = $othertitle;
3607: foreach my $status (@{$types}) {
3608: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3609: $numinrow,$rowcount,$usertypes);
3610: $$rowtotal ++;
3611: $rowcount ++;
3612: }
3613: }
1.33 raeburn 3614: }
3615: return $datatable;
3616: }
3617:
1.43 raeburn 3618: sub print_defaults {
3619: my ($dom,$rowtotal) = @_;
1.68 raeburn 3620: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3621: 'datelocale_def','portal_def');
1.43 raeburn 3622: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3623: my $titles = &defaults_titles($dom);
1.43 raeburn 3624: my $rownum = 0;
3625: my ($datatable,$css_class);
3626: foreach my $item (@items) {
3627: if ($rownum%2) {
3628: $css_class = '';
3629: } else {
3630: $css_class = ' class="LC_odd_row" ';
3631: }
3632: $datatable .= '<tr'.$css_class.'>'.
3633: '<td><span class="LC_nobreak">'.$titles->{$item}.
3634: '</span></td><td class="LC_right_item">';
3635: if ($item eq 'auth_def') {
3636: my @authtypes = ('internal','krb4','krb5','localauth');
3637: my %shortauth = (
3638: internal => 'int',
3639: krb4 => 'krb4',
3640: krb5 => 'krb5',
3641: localauth => 'loc'
3642: );
3643: my %authnames = &authtype_names();
3644: foreach my $auth (@authtypes) {
3645: my $checked = ' ';
3646: if ($domdefaults{$item} eq $auth) {
3647: $checked = ' checked="checked" ';
3648: }
3649: $datatable .= '<label><input type="radio" name="'.$item.
3650: '" value="'.$auth.'"'.$checked.'/>'.
3651: $authnames{$shortauth{$auth}}.'</label> ';
3652: }
1.54 raeburn 3653: } elsif ($item eq 'timezone_def') {
3654: my $includeempty = 1;
3655: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3656: } elsif ($item eq 'datelocale_def') {
3657: my $includeempty = 1;
3658: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3659: } elsif ($item eq 'lang_def') {
3660: my %langchoices = &get_languages_hash();
3661: $langchoices{''} = 'No language preference';
3662: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3663: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3664: \%langchoices);
1.43 raeburn 3665: } else {
1.141 raeburn 3666: my $size;
3667: if ($item eq 'portal_def') {
3668: $size = ' size="25"';
3669: }
1.43 raeburn 3670: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3671: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3672: }
3673: $datatable .= '</td></tr>';
3674: $rownum ++;
3675: }
3676: $$rowtotal += $rownum;
3677: return $datatable;
3678: }
3679:
1.160.6.5 raeburn 3680: sub get_languages_hash {
3681: my %langchoices;
3682: foreach my $id (&Apache::loncommon::languageids()) {
3683: my $code = &Apache::loncommon::supportedlanguagecode($id);
3684: if ($code ne '') {
3685: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3686: }
3687: }
3688: return %langchoices;
3689: }
3690:
1.43 raeburn 3691: sub defaults_titles {
1.141 raeburn 3692: my ($dom) = @_;
1.43 raeburn 3693: my %titles = &Apache::lonlocal::texthash (
3694: 'auth_def' => 'Default authentication type',
3695: 'auth_arg_def' => 'Default authentication argument',
3696: 'lang_def' => 'Default language',
1.54 raeburn 3697: 'timezone_def' => 'Default timezone',
1.68 raeburn 3698: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3699: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3700: );
1.141 raeburn 3701: if ($dom) {
3702: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3703: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3704: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3705: $protocol = 'http' if ($protocol ne 'https');
3706: if ($uint_dom) {
3707: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3708: $uint_dom);
3709: }
3710: }
1.43 raeburn 3711: return (\%titles);
3712: }
3713:
1.46 raeburn 3714: sub print_scantronformat {
3715: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3716: my $itemcount = 1;
1.60 raeburn 3717: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3718: %confhash);
1.46 raeburn 3719: my $switchserver = &check_switchserver($dom,$confname);
3720: my %lt = &Apache::lonlocal::texthash (
1.95 www 3721: default => 'Default bubblesheet format file error',
3722: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3723: );
3724: my %scantronfiles = (
3725: default => 'default.tab',
3726: custom => 'custom.tab',
3727: );
3728: foreach my $key (keys(%scantronfiles)) {
3729: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3730: .$scantronfiles{$key};
3731: }
3732: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3733: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3734: if (!$switchserver) {
3735: my $servadm = $r->dir_config('lonAdmEMail');
3736: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3737: if ($configuserok eq 'ok') {
3738: if ($author_ok eq 'ok') {
3739: my %legacyfile = (
3740: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3741: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3742: );
3743: my %md5chk;
3744: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3745: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3746: chomp($md5chk{$type});
1.46 raeburn 3747: }
3748: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3749: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3750: ($scantronurls{$type},my $error) =
1.46 raeburn 3751: &legacy_scantronformat($r,$dom,$confname,
3752: $type,$legacyfile{$type},
3753: $scantronurls{$type},
3754: $scantronfiles{$type});
1.60 raeburn 3755: if ($error ne '') {
3756: $error{$type} = $error;
3757: }
3758: }
3759: if (keys(%error) == 0) {
3760: $is_custom = 1;
3761: $confhash{'scantron'}{'scantronformat'} =
3762: $scantronurls{'custom'};
3763: my $putresult =
3764: &Apache::lonnet::put_dom('configuration',
3765: \%confhash,$dom);
3766: if ($putresult ne 'ok') {
3767: $error{'custom'} =
3768: '<span class="LC_error">'.
3769: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3770: }
1.46 raeburn 3771: }
3772: } else {
1.60 raeburn 3773: ($scantronurls{'default'},my $error) =
1.46 raeburn 3774: &legacy_scantronformat($r,$dom,$confname,
3775: 'default',$legacyfile{'default'},
3776: $scantronurls{'default'},
3777: $scantronfiles{'default'});
1.60 raeburn 3778: if ($error eq '') {
3779: $confhash{'scantron'}{'scantronformat'} = '';
3780: my $putresult =
3781: &Apache::lonnet::put_dom('configuration',
3782: \%confhash,$dom);
3783: if ($putresult ne 'ok') {
3784: $error{'default'} =
3785: '<span class="LC_error">'.
3786: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3787: }
3788: } else {
3789: $error{'default'} = $error;
3790: }
1.46 raeburn 3791: }
3792: }
3793: }
3794: } else {
1.95 www 3795: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3796: }
3797: }
3798: if (ref($settings) eq 'HASH') {
3799: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3800: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3801: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3802: $scantronurl = '';
3803: } else {
3804: $scantronurl = $settings->{'scantronformat'};
3805: }
3806: $is_custom = 1;
3807: } else {
3808: $scantronurl = $scantronurls{'default'};
3809: }
3810: } else {
1.60 raeburn 3811: if ($is_custom) {
3812: $scantronurl = $scantronurls{'custom'};
3813: } else {
3814: $scantronurl = $scantronurls{'default'};
3815: }
1.46 raeburn 3816: }
3817: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3818: $datatable .= '<tr'.$css_class.'>';
3819: if (!$is_custom) {
1.65 raeburn 3820: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3821: '<span class="LC_nobreak">';
1.46 raeburn 3822: if ($scantronurl) {
3823: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3824: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3825: } else {
3826: $datatable = &mt('File unavailable for display');
3827: }
1.65 raeburn 3828: $datatable .= '</span></td>';
1.60 raeburn 3829: if (keys(%error) == 0) {
3830: $datatable .= '<td valign="bottom">';
3831: if (!$switchserver) {
3832: $datatable .= &mt('Upload:').'<br />';
3833: }
3834: } else {
3835: my $errorstr;
3836: foreach my $key (sort(keys(%error))) {
3837: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3838: }
3839: $datatable .= '<td>'.$errorstr;
3840: }
1.46 raeburn 3841: } else {
3842: if (keys(%error) > 0) {
3843: my $errorstr;
3844: foreach my $key (sort(keys(%error))) {
3845: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3846: }
1.60 raeburn 3847: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3848: } elsif ($scantronurl) {
1.65 raeburn 3849: $datatable .= '<td><span class="LC_nobreak">'.
3850: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3851: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3852: '<input type="checkbox" name="scantronformat_del"'.
3853: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3854: '<td><span class="LC_nobreak"> '.
3855: &mt('Replace:').'</span><br />';
1.46 raeburn 3856: }
3857: }
3858: if (keys(%error) == 0) {
3859: if ($switchserver) {
3860: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3861: } else {
1.65 raeburn 3862: $datatable .='<span class="LC_nobreak"> '.
3863: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3864: }
3865: }
3866: $datatable .= '</td></tr>';
3867: $$rowtotal ++;
3868: return $datatable;
3869: }
3870:
3871: sub legacy_scantronformat {
3872: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3873: my ($url,$error);
3874: my @statinfo = &Apache::lonnet::stat_file($newurl);
3875: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3876: (my $result,$url) =
3877: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3878: '','',$newfile);
3879: if ($result ne 'ok') {
1.130 raeburn 3880: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3881: }
3882: }
3883: return ($url,$error);
3884: }
1.43 raeburn 3885:
1.49 raeburn 3886: sub print_coursecategories {
1.57 raeburn 3887: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3888: my $datatable;
3889: if ($position eq 'top') {
3890: my $toggle_cats_crs = ' ';
3891: my $toggle_cats_dom = ' checked="checked" ';
3892: my $can_cat_crs = ' ';
3893: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3894: my $toggle_catscomm_comm = ' ';
3895: my $toggle_catscomm_dom = ' checked="checked" ';
3896: my $can_catcomm_comm = ' ';
3897: my $can_catcomm_dom = ' checked="checked" ';
3898:
1.57 raeburn 3899: if (ref($settings) eq 'HASH') {
3900: if ($settings->{'togglecats'} eq 'crs') {
3901: $toggle_cats_crs = $toggle_cats_dom;
3902: $toggle_cats_dom = ' ';
3903: }
3904: if ($settings->{'categorize'} eq 'crs') {
3905: $can_cat_crs = $can_cat_dom;
3906: $can_cat_dom = ' ';
3907: }
1.120 raeburn 3908: if ($settings->{'togglecatscomm'} eq 'comm') {
3909: $toggle_catscomm_comm = $toggle_catscomm_dom;
3910: $toggle_catscomm_dom = ' ';
3911: }
3912: if ($settings->{'categorizecomm'} eq 'comm') {
3913: $can_catcomm_comm = $can_catcomm_dom;
3914: $can_catcomm_dom = ' ';
3915: }
1.57 raeburn 3916: }
3917: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3918: togglecats => 'Show/Hide a course in catalog',
3919: togglecatscomm => 'Show/Hide a community in catalog',
3920: categorize => 'Assign a category to a course',
3921: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3922: );
3923: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3924: dom => 'Set in Domain',
3925: crs => 'Set in Course',
3926: comm => 'Set in Community',
1.57 raeburn 3927: );
3928: $datatable = '<tr class="LC_odd_row">'.
3929: '<td>'.$title{'togglecats'}.'</td>'.
3930: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3931: '<input type="radio" name="togglecats"'.
3932: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3933: '<label><input type="radio" name="togglecats"'.
3934: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3935: '</tr><tr>'.
3936: '<td>'.$title{'categorize'}.'</td>'.
3937: '<td class="LC_right_item"><span class="LC_nobreak">'.
3938: '<label><input type="radio" name="categorize"'.
3939: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3940: '<label><input type="radio" name="categorize"'.
3941: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3942: '</tr><tr class="LC_odd_row">'.
3943: '<td>'.$title{'togglecatscomm'}.'</td>'.
3944: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3945: '<input type="radio" name="togglecatscomm"'.
3946: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3947: '<label><input type="radio" name="togglecatscomm"'.
3948: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3949: '</tr><tr>'.
3950: '<td>'.$title{'categorizecomm'}.'</td>'.
3951: '<td class="LC_right_item"><span class="LC_nobreak">'.
3952: '<label><input type="radio" name="categorizecomm"'.
3953: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3954: '<label><input type="radio" name="categorizecomm"'.
3955: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3956: '</tr>';
1.120 raeburn 3957: $$rowtotal += 4;
1.57 raeburn 3958: } else {
3959: my $css_class;
3960: my $itemcount = 1;
3961: my $cathash;
3962: if (ref($settings) eq 'HASH') {
3963: $cathash = $settings->{'cats'};
3964: }
3965: if (ref($cathash) eq 'HASH') {
3966: my (@cats,@trails,%allitems,%idx,@jsarray);
3967: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3968: \%allitems,\%idx,\@jsarray);
3969: my $maxdepth = scalar(@cats);
3970: my $colattrib = '';
3971: if ($maxdepth > 2) {
3972: $colattrib = ' colspan="2" ';
3973: }
3974: my @path;
3975: if (@cats > 0) {
3976: if (ref($cats[0]) eq 'ARRAY') {
3977: my $numtop = @{$cats[0]};
3978: my $maxnum = $numtop;
1.120 raeburn 3979: my %default_names = (
3980: instcode => &mt('Official courses'),
3981: communities => &mt('Communities'),
3982: );
3983:
3984: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3985: ($cathash->{'instcode::0'} eq '') ||
3986: (!grep(/^communities$/,@{$cats[0]})) ||
3987: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3988: $maxnum ++;
3989: }
3990: my $lastidx;
3991: for (my $i=0; $i<$numtop; $i++) {
3992: my $parent = $cats[0][$i];
3993: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3994: my $item = &escape($parent).'::0';
3995: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3996: $lastidx = $idx{$item};
3997: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3998: .'<select name="'.$item.'"'.$chgstr.'>';
3999: for (my $k=0; $k<=$maxnum; $k++) {
4000: my $vpos = $k+1;
4001: my $selstr;
4002: if ($k == $i) {
4003: $selstr = ' selected="selected" ';
4004: }
4005: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4006: }
4007: $datatable .= '</select></td><td>';
1.120 raeburn 4008: if ($parent eq 'instcode' || $parent eq 'communities') {
4009: $datatable .= '<span class="LC_nobreak">'
4010: .$default_names{$parent}.'</span>';
4011: if ($parent eq 'instcode') {
4012: $datatable .= '<br /><span class="LC_nobreak">('
4013: .&mt('with institutional codes')
4014: .')</span></td><td'.$colattrib.'>';
4015: } else {
4016: $datatable .= '<table><tr><td>';
4017: }
4018: $datatable .= '<span class="LC_nobreak">'
4019: .'<label><input type="radio" name="'
4020: .$parent.'" value="1" checked="checked" />'
4021: .&mt('Display').'</label>';
4022: if ($parent eq 'instcode') {
4023: $datatable .= ' ';
4024: } else {
4025: $datatable .= '</span></td></tr><tr><td>'
4026: .'<span class="LC_nobreak">';
4027: }
4028: $datatable .= '<label><input type="radio" name="'
4029: .$parent.'" value="0" />'
4030: .&mt('Do not display').'</label></span>';
4031: if ($parent eq 'communities') {
4032: $datatable .= '</td></tr></table>';
4033: }
4034: $datatable .= '</td>';
1.57 raeburn 4035: } else {
4036: $datatable .= $parent
4037: .' <label><input type="checkbox" name="deletecategory" '
4038: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4039: }
4040: my $depth = 1;
4041: push(@path,$parent);
4042: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4043: pop(@path);
4044: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4045: $itemcount ++;
4046: }
1.48 raeburn 4047: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4048: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4049: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4050: for (my $k=0; $k<=$maxnum; $k++) {
4051: my $vpos = $k+1;
4052: my $selstr;
1.57 raeburn 4053: if ($k == $numtop) {
1.48 raeburn 4054: $selstr = ' selected="selected" ';
4055: }
4056: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4057: }
1.59 bisitz 4058: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4059: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4060: .'</tr>'."\n";
1.48 raeburn 4061: $itemcount ++;
1.120 raeburn 4062: foreach my $default ('instcode','communities') {
4063: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4064: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4065: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4066: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4067: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4068: for (my $k=0; $k<=$maxnum; $k++) {
4069: my $vpos = $k+1;
4070: my $selstr;
4071: if ($k == $maxnum) {
4072: $selstr = ' selected="selected" ';
4073: }
4074: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4075: }
1.120 raeburn 4076: $datatable .= '</select></span></td>'.
4077: '<td><span class="LC_nobreak">'.
4078: $default_names{$default}.'</span>';
4079: if ($default eq 'instcode') {
4080: $datatable .= '<br /><span class="LC_nobreak">('
4081: .&mt('with institutional codes').')</span>';
4082: }
4083: $datatable .= '</td>'
4084: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4085: .&mt('Display').'</label> '
4086: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4087: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4088: }
4089: }
4090: }
1.57 raeburn 4091: } else {
4092: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4093: }
4094: } else {
1.57 raeburn 4095: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4096: .&initialize_categories($itemcount);
1.48 raeburn 4097: }
1.57 raeburn 4098: $$rowtotal += $itemcount;
1.48 raeburn 4099: }
4100: return $datatable;
4101: }
4102:
1.69 raeburn 4103: sub print_serverstatuses {
4104: my ($dom,$settings,$rowtotal) = @_;
4105: my $datatable;
4106: my @pages = &serverstatus_pages();
4107: my (%namedaccess,%machineaccess);
4108: foreach my $type (@pages) {
4109: $namedaccess{$type} = '';
4110: $machineaccess{$type}= '';
4111: }
4112: if (ref($settings) eq 'HASH') {
4113: foreach my $type (@pages) {
4114: if (exists($settings->{$type})) {
4115: if (ref($settings->{$type}) eq 'HASH') {
4116: foreach my $key (keys(%{$settings->{$type}})) {
4117: if ($key eq 'namedusers') {
4118: $namedaccess{$type} = $settings->{$type}->{$key};
4119: } elsif ($key eq 'machines') {
4120: $machineaccess{$type} = $settings->{$type}->{$key};
4121: }
4122: }
4123: }
4124: }
4125: }
4126: }
1.81 raeburn 4127: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4128: my $rownum = 0;
4129: my $css_class;
4130: foreach my $type (@pages) {
4131: $rownum ++;
4132: $css_class = $rownum%2?' class="LC_odd_row"':'';
4133: $datatable .= '<tr'.$css_class.'>'.
4134: '<td><span class="LC_nobreak">'.
4135: $titles->{$type}.'</span></td>'.
4136: '<td class="LC_left_item">'.
4137: '<input type="text" name="'.$type.'_namedusers" '.
4138: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4139: '<td class="LC_right_item">'.
4140: '<span class="LC_nobreak">'.
4141: '<input type="text" name="'.$type.'_machines" '.
4142: 'value="'.$machineaccess{$type}.'" size="10" />'.
4143: '</td></tr>'."\n";
4144: }
4145: $$rowtotal += $rownum;
4146: return $datatable;
4147: }
4148:
4149: sub serverstatus_pages {
4150: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4151: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4152: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4153: }
4154:
1.49 raeburn 4155: sub coursecategories_javascript {
4156: my ($settings) = @_;
1.57 raeburn 4157: my ($output,$jstext,$cathash);
1.49 raeburn 4158: if (ref($settings) eq 'HASH') {
1.57 raeburn 4159: $cathash = $settings->{'cats'};
4160: }
4161: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4162: my (@cats,@jsarray,%idx);
1.57 raeburn 4163: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4164: if (@jsarray > 0) {
4165: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4166: for (my $i=0; $i<@jsarray; $i++) {
4167: if (ref($jsarray[$i]) eq 'ARRAY') {
4168: my $catstr = join('","',@{$jsarray[$i]});
4169: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4170: }
4171: }
4172: }
4173: } else {
4174: $jstext = ' var categories = Array(1);'."\n".
4175: ' categories[0] = Array("instcode_pos");'."\n";
4176: }
1.120 raeburn 4177: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4178: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4179: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4180: $output = <<"ENDSCRIPT";
4181: <script type="text/javascript">
1.109 raeburn 4182: // <![CDATA[
1.49 raeburn 4183: function reorderCats(form,parent,item,idx) {
4184: var changedVal;
4185: $jstext
4186: var newpos = 'addcategory_pos';
4187: var current = new Array;
4188: if (parent == '') {
4189: var has_instcode = 0;
4190: var maxtop = categories[idx].length;
4191: for (var j=0; j<maxtop; j++) {
4192: if (categories[idx][j] == 'instcode::0') {
4193: has_instcode == 1;
4194: }
4195: }
4196: if (has_instcode == 0) {
4197: categories[idx][maxtop] = 'instcode_pos';
4198: }
4199: } else {
4200: newpos += '_'+parent;
4201: }
4202: var maxh = 1 + categories[idx].length;
4203: var current = new Array;
4204: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4205: if (item == newpos) {
4206: changedVal = newitemVal;
4207: } else {
4208: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4209: current[newitemVal] = newpos;
4210: }
4211: for (var i=0; i<categories[idx].length; i++) {
4212: var elementName = categories[idx][i];
4213: if (elementName != item) {
4214: if (form.elements[elementName]) {
4215: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4216: current[currVal] = elementName;
4217: }
4218: }
4219: }
4220: var oldVal;
4221: for (var j=0; j<maxh; j++) {
4222: if (current[j] == undefined) {
4223: oldVal = j;
4224: }
4225: }
4226: if (oldVal < changedVal) {
4227: for (var k=oldVal+1; k<=changedVal ; k++) {
4228: var elementName = current[k];
4229: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4230: }
4231: } else {
4232: for (var k=changedVal; k<oldVal; k++) {
4233: var elementName = current[k];
4234: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4235: }
4236: }
4237: return;
4238: }
1.120 raeburn 4239:
4240: function categoryCheck(form) {
4241: if (form.elements['addcategory_name'].value == 'instcode') {
4242: alert('$instcode_reserved\\n$choose_again');
4243: return false;
4244: }
4245: if (form.elements['addcategory_name'].value == 'communities') {
4246: alert('$communities_reserved\\n$choose_again');
4247: return false;
4248: }
4249: return true;
4250: }
4251:
1.109 raeburn 4252: // ]]>
1.49 raeburn 4253: </script>
4254:
4255: ENDSCRIPT
4256: return $output;
4257: }
4258:
1.48 raeburn 4259: sub initialize_categories {
4260: my ($itemcount) = @_;
1.120 raeburn 4261: my ($datatable,$css_class,$chgstr);
4262: my %default_names = (
4263: instcode => 'Official courses (with institutional codes)',
4264: communities => 'Communities',
4265: );
4266: my $select0 = ' selected="selected"';
4267: my $select1 = '';
4268: foreach my $default ('instcode','communities') {
4269: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4270: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4271: if ($default eq 'communities') {
4272: $select1 = $select0;
4273: $select0 = '';
4274: }
4275: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4276: .'<select name="'.$default.'_pos">'
4277: .'<option value="0"'.$select0.'>1</option>'
4278: .'<option value="1"'.$select1.'>2</option>'
4279: .'<option value="2">3</option></select> '
4280: .$default_names{$default}
4281: .'</span></td><td><span class="LC_nobreak">'
4282: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4283: .&mt('Display').'</label> <label>'
4284: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4285: .'</label></span></td></tr>';
1.120 raeburn 4286: $itemcount ++;
4287: }
1.48 raeburn 4288: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4289: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4290: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4291: .'<select name="addcategory_pos"'.$chgstr.'>'
4292: .'<option value="0">1</option>'
4293: .'<option value="1">2</option>'
4294: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4295: .&mt('Add category').'</td><td>'.&mt('Name:')
4296: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4297: return $datatable;
4298: }
4299:
4300: sub build_category_rows {
1.49 raeburn 4301: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4302: my ($text,$name,$item,$chgstr);
1.48 raeburn 4303: if (ref($cats) eq 'ARRAY') {
4304: my $maxdepth = scalar(@{$cats});
4305: if (ref($cats->[$depth]) eq 'HASH') {
4306: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4307: my $numchildren = @{$cats->[$depth]{$parent}};
4308: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4309: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4310: my ($idxnum,$parent_name,$parent_item);
4311: my $higher = $depth - 1;
4312: if ($higher == 0) {
4313: $parent_name = &escape($parent).'::'.$higher;
4314: } else {
4315: if (ref($path) eq 'ARRAY') {
4316: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4317: }
4318: }
4319: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4320: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4321: if ($j < $numchildren) {
1.48 raeburn 4322: $name = $cats->[$depth]{$parent}[$j];
4323: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4324: $idxnum = $idx->{$item};
4325: } else {
4326: $name = $parent_name;
4327: $item = $parent_item;
1.48 raeburn 4328: }
1.49 raeburn 4329: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4330: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4331: for (my $i=0; $i<=$numchildren; $i++) {
4332: my $vpos = $i+1;
4333: my $selstr;
4334: if ($j == $i) {
4335: $selstr = ' selected="selected" ';
4336: }
4337: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4338: }
4339: $text .= '</select> ';
4340: if ($j < $numchildren) {
4341: my $deeper = $depth+1;
4342: $text .= $name.' '
4343: .'<label><input type="checkbox" name="deletecategory" value="'
4344: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4345: if(ref($path) eq 'ARRAY') {
4346: push(@{$path},$name);
1.49 raeburn 4347: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4348: pop(@{$path});
4349: }
4350: } else {
1.59 bisitz 4351: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4352: if ($j == $numchildren) {
4353: $text .= $name;
4354: } else {
4355: $text .= $item;
4356: }
4357: $text .= '" value="" />';
4358: }
4359: $text .= '</td></tr>';
4360: }
4361: $text .= '</table></td>';
4362: } else {
4363: my $higher = $depth-1;
4364: if ($higher == 0) {
4365: $name = &escape($parent).'::'.$higher;
4366: } else {
4367: if (ref($path) eq 'ARRAY') {
4368: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4369: }
4370: }
4371: my $colspan;
4372: if ($parent ne 'instcode') {
4373: $colspan = $maxdepth - $depth - 1;
4374: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4375: }
4376: }
4377: }
4378: }
4379: return $text;
4380: }
4381:
1.33 raeburn 4382: sub modifiable_userdata_row {
1.63 raeburn 4383: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4384: my $rolename;
1.63 raeburn 4385: if ($context eq 'selfcreate') {
4386: if (ref($usertypes) eq 'HASH') {
4387: $rolename = $usertypes->{$role};
4388: } else {
4389: $rolename = $role;
4390: }
1.33 raeburn 4391: } else {
1.63 raeburn 4392: if ($role eq 'cr') {
4393: $rolename = &mt('Custom role');
4394: } else {
4395: $rolename = &Apache::lonnet::plaintext($role);
4396: }
1.33 raeburn 4397: }
4398: my @fields = ('lastname','firstname','middlename','generation',
4399: 'permanentemail','id');
4400: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4401: my $output;
4402: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4403: $output = '<tr '.$css_class.'>'.
4404: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4405: '<td class="LC_left_item" colspan="2"><table>';
4406: my $rem;
4407: my %checks;
4408: if (ref($settings) eq 'HASH') {
4409: if (ref($settings->{$context}) eq 'HASH') {
4410: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4411: foreach my $field (@fields) {
4412: if ($settings->{$context}->{$role}->{$field}) {
4413: $checks{$field} = ' checked="checked" ';
4414: }
4415: }
4416: }
4417: }
4418: }
4419: for (my $i=0; $i<@fields; $i++) {
4420: my $rem = $i%($numinrow);
4421: if ($rem == 0) {
4422: if ($i > 0) {
4423: $output .= '</tr>';
4424: }
4425: $output .= '<tr>';
4426: }
4427: my $check = ' ';
4428: if (exists($checks{$fields[$i]})) {
4429: $check = $checks{$fields[$i]}
4430: } else {
4431: if ($role eq 'st') {
4432: if (ref($settings) ne 'HASH') {
4433: $check = ' checked="checked" ';
4434: }
4435: }
4436: }
4437: $output .= '<td class="LC_left_item">'.
4438: '<span class="LC_nobreak"><label>'.
4439: '<input type="checkbox" name="canmodify_'.$role.'" '.
4440: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4441: '</label></span></td>';
4442: $rem = @fields%($numinrow);
4443: }
4444: my $colsleft = $numinrow - $rem;
4445: if ($colsleft > 1 ) {
4446: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4447: ' </td>';
4448: } elsif ($colsleft == 1) {
4449: $output .= '<td class="LC_left_item"> </td>';
4450: }
4451: $output .= '</tr></table></td></tr>';
4452: return $output;
4453: }
1.28 raeburn 4454:
1.93 raeburn 4455: sub insttypes_row {
4456: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4457: my %lt = &Apache::lonlocal::texthash (
4458: cansearch => 'Users allowed to search',
4459: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4460: lockablenames => 'User preference to lock name',
1.93 raeburn 4461: );
4462: my $showdom;
4463: if ($context eq 'cansearch') {
4464: $showdom = ' ('.$dom.')';
4465: }
1.160.6.5 raeburn 4466: my $class = 'LC_left_item';
4467: if ($context eq 'statustocreate') {
4468: $class = 'LC_right_item';
4469: }
1.25 raeburn 4470: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4471: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4472: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4473: my $rem;
4474: if (ref($types) eq 'ARRAY') {
4475: for (my $i=0; $i<@{$types}; $i++) {
4476: if (defined($usertypes->{$types->[$i]})) {
4477: my $rem = $i%($numinrow);
4478: if ($rem == 0) {
4479: if ($i > 0) {
4480: $output .= '</tr>';
4481: }
4482: $output .= '<tr>';
1.23 raeburn 4483: }
1.26 raeburn 4484: my $check = ' ';
1.99 raeburn 4485: if (ref($settings) eq 'HASH') {
4486: if (ref($settings->{$context}) eq 'ARRAY') {
4487: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4488: $check = ' checked="checked" ';
4489: }
4490: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4491: $check = ' checked="checked" ';
4492: }
1.23 raeburn 4493: }
1.26 raeburn 4494: $output .= '<td class="LC_left_item">'.
4495: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4496: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4497: 'value="'.$types->[$i].'"'.$check.'/>'.
4498: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4499: }
4500: }
1.26 raeburn 4501: $rem = @{$types}%($numinrow);
1.23 raeburn 4502: }
4503: my $colsleft = $numinrow - $rem;
1.131 raeburn 4504: if (($rem == 0) && (@{$types} > 0)) {
4505: $output .= '<tr>';
4506: }
1.23 raeburn 4507: if ($colsleft > 1) {
1.25 raeburn 4508: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4509: } else {
1.25 raeburn 4510: $output .= '<td class="LC_left_item">';
1.23 raeburn 4511: }
4512: my $defcheck = ' ';
1.99 raeburn 4513: if (ref($settings) eq 'HASH') {
4514: if (ref($settings->{$context}) eq 'ARRAY') {
4515: if (grep(/^default$/,@{$settings->{$context}})) {
4516: $defcheck = ' checked="checked" ';
4517: }
4518: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4519: $defcheck = ' checked="checked" ';
4520: }
1.23 raeburn 4521: }
1.25 raeburn 4522: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4523: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4524: 'value="default"'.$defcheck.'/>'.
4525: $othertitle.'</label></span></td>'.
4526: '</tr></table></td></tr>';
4527: return $output;
1.23 raeburn 4528: }
4529:
4530: sub sorted_searchtitles {
4531: my %searchtitles = &Apache::lonlocal::texthash(
4532: 'uname' => 'username',
4533: 'lastname' => 'last name',
4534: 'lastfirst' => 'last name, first name',
4535: );
4536: my @titleorder = ('uname','lastname','lastfirst');
4537: return (\%searchtitles,\@titleorder);
4538: }
4539:
1.25 raeburn 4540: sub sorted_searchtypes {
4541: my %srchtypes_desc = (
4542: exact => 'is exact match',
4543: contains => 'contains ..',
4544: begins => 'begins with ..',
4545: );
4546: my @srchtypeorder = ('exact','begins','contains');
4547: return (\%srchtypes_desc,\@srchtypeorder);
4548: }
4549:
1.3 raeburn 4550: sub usertype_update_row {
4551: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4552: my $datatable;
4553: my $numinrow = 4;
4554: foreach my $type (@{$types}) {
4555: if (defined($usertypes->{$type})) {
4556: $$rownums ++;
4557: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4558: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4559: '</td><td class="LC_left_item"><table>';
4560: for (my $i=0; $i<@{$fields}; $i++) {
4561: my $rem = $i%($numinrow);
4562: if ($rem == 0) {
4563: if ($i > 0) {
4564: $datatable .= '</tr>';
4565: }
4566: $datatable .= '<tr>';
4567: }
4568: my $check = ' ';
1.39 raeburn 4569: if (ref($settings) eq 'HASH') {
4570: if (ref($settings->{'fields'}) eq 'HASH') {
4571: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4572: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4573: $check = ' checked="checked" ';
4574: }
1.3 raeburn 4575: }
4576: }
4577: }
4578:
4579: if ($i == @{$fields}-1) {
4580: my $colsleft = $numinrow - $rem;
4581: if ($colsleft > 1) {
4582: $datatable .= '<td colspan="'.$colsleft.'">';
4583: } else {
4584: $datatable .= '<td>';
4585: }
4586: } else {
4587: $datatable .= '<td>';
4588: }
1.8 raeburn 4589: $datatable .= '<span class="LC_nobreak"><label>'.
4590: '<input type="checkbox" name="updateable_'.$type.
4591: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4592: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4593: }
4594: $datatable .= '</tr></table></td></tr>';
4595: }
4596: }
4597: return $datatable;
1.1 raeburn 4598: }
4599:
4600: sub modify_login {
1.9 raeburn 4601: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4602: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4603: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4604: %title = ( coursecatalog => 'Display course catalog',
4605: adminmail => 'Display administrator E-mail address',
4606: newuser => 'Link for visitors to create a user account',
4607: loginheader => 'Log-in box header');
4608: @offon = ('off','on');
1.112 raeburn 4609: if (ref($domconfig{login}) eq 'HASH') {
4610: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4611: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4612: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4613: }
4614: }
4615: }
1.9 raeburn 4616: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4617: \%domconfig,\%loginhash);
1.118 jms 4618: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4619: foreach my $item (@toggles) {
4620: $loginhash{login}{$item} = $env{'form.'.$item};
4621: }
1.41 raeburn 4622: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4623: if (ref($colchanges{'login'}) eq 'HASH') {
4624: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4625: \%loginhash);
4626: }
1.110 raeburn 4627:
1.149 raeburn 4628: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4629: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4630: if (keys(%servers) > 1) {
4631: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4632: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4633: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4634: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4635: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4636: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4637: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4638: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4639: $changes{'loginvia'}{$lonhost} = 1;
4640: } else {
4641: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4642: $changes{'loginvia'}{$lonhost} = 1;
4643: }
4644: } else {
4645: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4646: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4647: $changes{'loginvia'}{$lonhost} = 1;
4648: }
4649: }
4650: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4651: foreach my $item (@loginvia_attribs) {
4652: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4653: }
4654: } else {
4655: foreach my $item (@loginvia_attribs) {
4656: my $new = $env{'form.'.$lonhost.'_'.$item};
4657: if (($item eq 'serverpath') && ($new eq 'custom')) {
4658: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4659: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4660: $new = '/';
4661: }
4662: }
4663: if (($item eq 'custompath') &&
4664: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4665: $new = '';
4666: }
4667: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4668: $changes{'loginvia'}{$lonhost} = 1;
4669: }
4670: if ($item eq 'exempt') {
4671: $new =~ s/^\s+//;
4672: $new =~ s/\s+$//;
4673: my @poss_ips = split(/\s*[,:]\s*/,$new);
4674: my @okips;
4675: foreach my $ip (@poss_ips) {
4676: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4677: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4678: push(@okips,$ip);
4679: }
4680: }
4681: }
4682: if (@okips > 0) {
4683: $new = join(',',@okips);
4684: } else {
4685: $new = '';
4686: }
4687: }
4688: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4689: }
4690: }
1.112 raeburn 4691: } else {
1.128 raeburn 4692: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4693: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4694: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4695: foreach my $item (@loginvia_attribs) {
4696: my $new = $env{'form.'.$lonhost.'_'.$item};
4697: if (($item eq 'serverpath') && ($new eq 'custom')) {
4698: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4699: $new = '/';
4700: }
4701: }
4702: if (($item eq 'custompath') &&
4703: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4704: $new = '';
4705: }
4706: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4707: }
1.110 raeburn 4708: }
4709: }
4710: }
4711: }
1.119 raeburn 4712:
1.160.6.5 raeburn 4713: my $servadm = $r->dir_config('lonAdmEMail');
4714: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4715: if (ref($domconfig{'login'}) eq 'HASH') {
4716: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4717: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4718: if ($lang eq 'nolang') {
4719: push(@currlangs,$lang);
4720: } elsif (defined($langchoices{$lang})) {
4721: push(@currlangs,$lang);
4722: } else {
4723: next;
4724: }
4725: }
4726: }
4727: }
4728: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4729: if (@currlangs > 0) {
4730: foreach my $lang (@currlangs) {
4731: if (grep(/^\Q$lang\E$/,@delurls)) {
4732: $changes{'helpurl'}{$lang} = 1;
4733: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4734: $changes{'helpurl'}{$lang} = 1;
4735: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4736: push(@newlangs,$lang);
4737: } else {
4738: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4739: }
4740: }
4741: }
4742: unless (grep(/^nolang$/,@currlangs)) {
4743: if ($env{'form.loginhelpurl_nolang.filename'}) {
4744: $changes{'helpurl'}{'nolang'} = 1;
4745: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4746: push(@newlangs,'nolang');
4747: }
4748: }
4749: if ($env{'form.loginhelpurl_add_lang'}) {
4750: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4751: ($env{'form.loginhelpurl_add_file.filename'})) {
4752: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4753: $addedfile = $env{'form.loginhelpurl_add_lang'};
4754: }
4755: }
4756: if ((@newlangs > 0) || ($addedfile)) {
4757: my $error;
4758: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4759: if ($configuserok eq 'ok') {
4760: if ($switchserver) {
4761: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4762: } elsif ($author_ok eq 'ok') {
4763: my @allnew = @newlangs;
4764: if ($addedfile ne '') {
4765: push(@allnew,$addedfile);
4766: }
4767: foreach my $lang (@allnew) {
4768: my $formelem = 'loginhelpurl_'.$lang;
4769: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4770: $formelem = 'loginhelpurl_add_file';
4771: }
4772: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4773: "help/$lang",'','',$newfile{$lang});
4774: if ($result eq 'ok') {
4775: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4776: $changes{'helpurl'}{$lang} = 1;
4777: } else {
4778: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4779: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4780: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4781: (!grep(/^\Q$lang\E$/,@delurls))) {
4782:
4783: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4784: }
4785: }
4786: }
4787: } else {
4788: $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);
4789: }
4790: } else {
4791: $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);
4792: }
4793: if ($error) {
4794: &Apache::lonnet::logthis($error);
4795: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4796: }
4797: }
4798: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4799:
4800: my $defaulthelpfile = '/adm/loginproblems.html';
4801: my $defaulttext = &mt('Default in use');
4802:
1.1 raeburn 4803: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4804: $dom);
4805: if ($putresult eq 'ok') {
1.118 jms 4806: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4807: my %defaultchecked = (
4808: 'coursecatalog' => 'on',
4809: 'adminmail' => 'off',
1.43 raeburn 4810: 'newuser' => 'off',
1.42 raeburn 4811: );
1.55 raeburn 4812: if (ref($domconfig{'login'}) eq 'HASH') {
4813: foreach my $item (@toggles) {
4814: if ($defaultchecked{$item} eq 'on') {
4815: if (($domconfig{'login'}{$item} eq '0') &&
4816: ($env{'form.'.$item} eq '1')) {
4817: $changes{$item} = 1;
4818: } elsif (($domconfig{'login'}{$item} eq '' ||
4819: $domconfig{'login'}{$item} eq '1') &&
4820: ($env{'form.'.$item} eq '0')) {
4821: $changes{$item} = 1;
4822: }
4823: } elsif ($defaultchecked{$item} eq 'off') {
4824: if (($domconfig{'login'}{$item} eq '1') &&
4825: ($env{'form.'.$item} eq '0')) {
4826: $changes{$item} = 1;
4827: } elsif (($domconfig{'login'}{$item} eq '' ||
4828: $domconfig{'login'}{$item} eq '0') &&
4829: ($env{'form.'.$item} eq '1')) {
4830: $changes{$item} = 1;
4831: }
1.42 raeburn 4832: }
4833: }
1.41 raeburn 4834: }
1.6 raeburn 4835: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4836: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4837: $resulttext = &mt('Changes made:').'<ul>';
4838: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4839: if ($item eq 'loginvia') {
1.112 raeburn 4840: if (ref($changes{$item}) eq 'HASH') {
4841: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4842: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4843: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4844: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4845: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4846: $protocol = 'http' if ($protocol ne 'https');
4847: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4848:
4849: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4850: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4851: } else {
4852: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4853: }
4854: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4855: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4856: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4857: }
4858: $resulttext .= '</li>';
4859: } else {
4860: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4861: }
1.112 raeburn 4862: } else {
1.128 raeburn 4863: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4864: }
4865: }
1.128 raeburn 4866: $resulttext .= '</ul></li>';
1.112 raeburn 4867: }
1.160.6.5 raeburn 4868: } elsif ($item eq 'helpurl') {
4869: if (ref($changes{$item}) eq 'HASH') {
4870: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4871: if (grep(/^\Q$lang\E$/,@delurls)) {
4872: my ($chg,$link);
4873: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4874: if ($lang eq 'nolang') {
4875: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4876: } else {
4877: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4878: }
4879: $resulttext .= '<li>'.$chg.'</li>';
4880: } else {
4881: my $chg;
4882: if ($lang eq 'nolang') {
4883: $chg = &mt('custom log-in help file for no preferred language');
4884: } else {
4885: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4886: }
4887: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4888: $loginhash{'login'}{'helpurl'}{$lang}.
4889: '?inhibitmenu=yes',$chg,600,500).
4890: '</li>';
4891: }
4892: }
4893: }
4894: } elsif ($item eq 'captcha') {
4895: if (ref($loginhash{'login'}) eq 'HASH') {
4896: my $chgtxt;
4897: if ($loginhash{'login'}{$item} eq 'notused') {
4898: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4899: } else {
4900: my %captchas = &captcha_phrases();
4901: if ($captchas{$loginhash{'login'}{$item}}) {
4902: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4903: } else {
4904: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4905: }
4906: }
4907: $resulttext .= '<li>'.$chgtxt.'</li>';
4908: }
4909: } elsif ($item eq 'recaptchakeys') {
4910: if (ref($loginhash{'login'}) eq 'HASH') {
4911: my ($privkey,$pubkey);
4912: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4913: $pubkey = $loginhash{'login'}{$item}{'public'};
4914: $privkey = $loginhash{'login'}{$item}{'private'};
4915: }
4916: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4917: if (!$pubkey) {
4918: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4919: } else {
4920: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4921: }
4922: if (!$privkey) {
4923: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4924: } else {
4925: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4926: }
4927: $chgtxt .= '</ul>';
4928: $resulttext .= '<li>'.$chgtxt.'</li>';
4929: }
1.41 raeburn 4930: } else {
4931: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4932: }
1.1 raeburn 4933: }
1.6 raeburn 4934: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4935: } else {
4936: $resulttext = &mt('No changes made to log-in page settings');
4937: }
4938: } else {
1.11 albertel 4939: $resulttext = '<span class="LC_error">'.
4940: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4941: }
1.6 raeburn 4942: if ($errors) {
1.9 raeburn 4943: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4944: $errors.'</ul>';
4945: }
4946: return $resulttext;
4947: }
4948:
4949: sub color_font_choices {
4950: my %choices =
4951: &Apache::lonlocal::texthash (
4952: img => "Header",
4953: bgs => "Background colors",
4954: links => "Link colors",
1.55 raeburn 4955: images => "Images",
1.6 raeburn 4956: font => "Font color",
1.97 tempelho 4957: fontmenu => "Font Menu",
1.76 raeburn 4958: pgbg => "Page",
1.6 raeburn 4959: tabbg => "Header",
4960: sidebg => "Border",
4961: link => "Link",
4962: alink => "Active link",
4963: vlink => "Visited link",
4964: );
4965: return %choices;
4966: }
4967:
4968: sub modify_rolecolors {
1.9 raeburn 4969: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4970: my ($resulttext,%rolehash);
4971: $rolehash{'rolecolors'} = {};
1.55 raeburn 4972: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4973: if ($domconfig{'rolecolors'} eq '') {
4974: $domconfig{'rolecolors'} = {};
4975: }
4976: }
1.9 raeburn 4977: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4978: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4979: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4980: $dom);
4981: if ($putresult eq 'ok') {
4982: if (keys(%changes) > 0) {
1.41 raeburn 4983: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4984: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4985: $rolehash{'rolecolors'});
4986: } else {
4987: $resulttext = &mt('No changes made to default color schemes');
4988: }
4989: } else {
1.11 albertel 4990: $resulttext = '<span class="LC_error">'.
4991: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4992: }
4993: if ($errors) {
4994: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4995: $errors.'</ul>';
4996: }
4997: return $resulttext;
4998: }
4999:
5000: sub modify_colors {
1.9 raeburn 5001: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5002: my (%changes,%choices);
1.51 raeburn 5003: my @bgs;
1.6 raeburn 5004: my @links = ('link','alink','vlink');
1.41 raeburn 5005: my @logintext;
1.6 raeburn 5006: my @images;
5007: my $servadm = $r->dir_config('lonAdmEMail');
5008: my $errors;
5009: foreach my $role (@{$roles}) {
5010: if ($role eq 'login') {
1.12 raeburn 5011: %choices = &login_choices();
1.41 raeburn 5012: @logintext = ('textcol','bgcol');
1.12 raeburn 5013: } else {
5014: %choices = &color_font_choices();
1.107 raeburn 5015: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5016: }
5017: if ($role eq 'login') {
1.41 raeburn 5018: @images = ('img','logo','domlogo','login');
1.51 raeburn 5019: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5020: } else {
5021: @images = ('img');
1.51 raeburn 5022: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5023: }
5024: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5025: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5026: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5027: }
1.46 raeburn 5028: my ($configuserok,$author_ok,$switchserver) =
5029: &config_check($dom,$confname,$servadm);
1.9 raeburn 5030: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5031: if (ref($domconfig->{$role}) ne 'HASH') {
5032: $domconfig->{$role} = {};
5033: }
1.8 raeburn 5034: foreach my $img (@images) {
1.70 raeburn 5035: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5036: if (defined($env{'form.login_showlogo_'.$img})) {
5037: $confhash->{$role}{'showlogo'}{$img} = 1;
5038: } else {
5039: $confhash->{$role}{'showlogo'}{$img} = 0;
5040: }
5041: }
1.18 albertel 5042: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5043: && !defined($domconfig->{$role}{$img})
5044: && !$env{'form.'.$role.'_del_'.$img}
5045: && $env{'form.'.$role.'_import_'.$img}) {
5046: # import the old configured image from the .tab setting
5047: # if they haven't provided a new one
5048: $domconfig->{$role}{$img} =
5049: $env{'form.'.$role.'_import_'.$img};
5050: }
1.6 raeburn 5051: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5052: my $error;
1.6 raeburn 5053: if ($configuserok eq 'ok') {
1.9 raeburn 5054: if ($switchserver) {
1.12 raeburn 5055: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5056: } else {
5057: if ($author_ok eq 'ok') {
5058: my ($result,$logourl) =
5059: &publishlogo($r,'upload',$role.'_'.$img,
5060: $dom,$confname,$img,$width,$height);
5061: if ($result eq 'ok') {
5062: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5063: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5064: } else {
1.12 raeburn 5065: $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 5066: }
5067: } else {
1.46 raeburn 5068: $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 5069: }
5070: }
5071: } else {
1.46 raeburn 5072: $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 5073: }
5074: if ($error) {
1.8 raeburn 5075: &Apache::lonnet::logthis($error);
1.11 albertel 5076: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5077: }
5078: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5079: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5080: my $error;
5081: if ($configuserok eq 'ok') {
5082: # is confname an author?
5083: if ($switchserver eq '') {
5084: if ($author_ok eq 'ok') {
5085: my ($result,$logourl) =
5086: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5087: $dom,$confname,$img,$width,$height);
5088: if ($result eq 'ok') {
5089: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5090: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5091: }
5092: }
5093: }
5094: }
1.6 raeburn 5095: }
5096: }
5097: }
5098: if (ref($domconfig) eq 'HASH') {
5099: if (ref($domconfig->{$role}) eq 'HASH') {
5100: foreach my $img (@images) {
5101: if ($domconfig->{$role}{$img} ne '') {
5102: if ($env{'form.'.$role.'_del_'.$img}) {
5103: $confhash->{$role}{$img} = '';
1.12 raeburn 5104: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5105: } else {
1.9 raeburn 5106: if ($confhash->{$role}{$img} eq '') {
5107: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5108: }
1.6 raeburn 5109: }
5110: } else {
5111: if ($env{'form.'.$role.'_del_'.$img}) {
5112: $confhash->{$role}{$img} = '';
1.12 raeburn 5113: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5114: }
5115: }
1.70 raeburn 5116: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5117: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5118: if ($confhash->{$role}{'showlogo'}{$img} ne
5119: $domconfig->{$role}{'showlogo'}{$img}) {
5120: $changes{$role}{'showlogo'}{$img} = 1;
5121: }
5122: } else {
5123: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5124: $changes{$role}{'showlogo'}{$img} = 1;
5125: }
5126: }
5127: }
5128: }
1.6 raeburn 5129: if ($domconfig->{$role}{'font'} ne '') {
5130: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5131: $changes{$role}{'font'} = 1;
5132: }
5133: } else {
5134: if ($confhash->{$role}{'font'}) {
5135: $changes{$role}{'font'} = 1;
5136: }
5137: }
1.107 raeburn 5138: if ($role ne 'login') {
5139: if ($domconfig->{$role}{'fontmenu'} ne '') {
5140: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5141: $changes{$role}{'fontmenu'} = 1;
5142: }
5143: } else {
5144: if ($confhash->{$role}{'fontmenu'}) {
5145: $changes{$role}{'fontmenu'} = 1;
5146: }
1.97 tempelho 5147: }
5148: }
1.6 raeburn 5149: foreach my $item (@bgs) {
5150: if ($domconfig->{$role}{$item} ne '') {
5151: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5152: $changes{$role}{'bgs'}{$item} = 1;
5153: }
5154: } else {
5155: if ($confhash->{$role}{$item}) {
5156: $changes{$role}{'bgs'}{$item} = 1;
5157: }
5158: }
5159: }
5160: foreach my $item (@links) {
5161: if ($domconfig->{$role}{$item} ne '') {
5162: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5163: $changes{$role}{'links'}{$item} = 1;
5164: }
5165: } else {
5166: if ($confhash->{$role}{$item}) {
5167: $changes{$role}{'links'}{$item} = 1;
5168: }
5169: }
5170: }
1.41 raeburn 5171: foreach my $item (@logintext) {
5172: if ($domconfig->{$role}{$item} ne '') {
5173: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5174: $changes{$role}{'logintext'}{$item} = 1;
5175: }
5176: } else {
5177: if ($confhash->{$role}{$item}) {
5178: $changes{$role}{'logintext'}{$item} = 1;
5179: }
5180: }
5181: }
1.6 raeburn 5182: } else {
5183: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5184: \@logintext,$confhash,\%changes);
1.6 raeburn 5185: }
5186: } else {
5187: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5188: \@logintext,$confhash,\%changes);
1.6 raeburn 5189: }
5190: }
5191: return ($errors,%changes);
5192: }
5193:
1.46 raeburn 5194: sub config_check {
5195: my ($dom,$confname,$servadm) = @_;
5196: my ($configuserok,$author_ok,$switchserver,%currroles);
5197: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5198: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5199: $confname,$servadm);
5200: if ($configuserok eq 'ok') {
5201: $switchserver = &check_switchserver($dom,$confname);
5202: if ($switchserver eq '') {
5203: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5204: }
5205: }
5206: return ($configuserok,$author_ok,$switchserver);
5207: }
5208:
1.6 raeburn 5209: sub default_change_checker {
1.41 raeburn 5210: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5211: foreach my $item (@{$links}) {
5212: if ($confhash->{$role}{$item}) {
5213: $changes->{$role}{'links'}{$item} = 1;
5214: }
5215: }
5216: foreach my $item (@{$bgs}) {
5217: if ($confhash->{$role}{$item}) {
5218: $changes->{$role}{'bgs'}{$item} = 1;
5219: }
5220: }
1.41 raeburn 5221: foreach my $item (@{$logintext}) {
5222: if ($confhash->{$role}{$item}) {
5223: $changes->{$role}{'logintext'}{$item} = 1;
5224: }
5225: }
1.6 raeburn 5226: foreach my $img (@{$images}) {
5227: if ($env{'form.'.$role.'_del_'.$img}) {
5228: $confhash->{$role}{$img} = '';
1.12 raeburn 5229: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5230: }
1.70 raeburn 5231: if ($role eq 'login') {
5232: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5233: $changes->{$role}{'showlogo'}{$img} = 1;
5234: }
5235: }
1.6 raeburn 5236: }
5237: if ($confhash->{$role}{'font'}) {
5238: $changes->{$role}{'font'} = 1;
5239: }
1.48 raeburn 5240: }
1.6 raeburn 5241:
5242: sub display_colorchgs {
5243: my ($dom,$changes,$roles,$confhash) = @_;
5244: my (%choices,$resulttext);
5245: if (!grep(/^login$/,@{$roles})) {
5246: $resulttext = &mt('Changes made:').'<br />';
5247: }
5248: foreach my $role (@{$roles}) {
5249: if ($role eq 'login') {
5250: %choices = &login_choices();
5251: } else {
5252: %choices = &color_font_choices();
5253: }
5254: if (ref($changes->{$role}) eq 'HASH') {
5255: if ($role ne 'login') {
5256: $resulttext .= '<h4>'.&mt($role).'</h4>';
5257: }
5258: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5259: if ($role ne 'login') {
5260: $resulttext .= '<ul>';
5261: }
5262: if (ref($changes->{$role}{$key}) eq 'HASH') {
5263: if ($role ne 'login') {
5264: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5265: }
5266: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5267: if (($role eq 'login') && ($key eq 'showlogo')) {
5268: if ($confhash->{$role}{$key}{$item}) {
5269: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5270: } else {
5271: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5272: }
5273: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5274: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5275: } else {
1.12 raeburn 5276: my $newitem = $confhash->{$role}{$item};
5277: if ($key eq 'images') {
5278: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5279: }
5280: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5281: }
5282: }
5283: if ($role ne 'login') {
5284: $resulttext .= '</ul></li>';
5285: }
5286: } else {
5287: if ($confhash->{$role}{$key} eq '') {
5288: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5289: } else {
5290: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5291: }
5292: }
5293: if ($role ne 'login') {
5294: $resulttext .= '</ul>';
5295: }
5296: }
5297: }
5298: }
1.3 raeburn 5299: return $resulttext;
1.1 raeburn 5300: }
5301:
1.9 raeburn 5302: sub thumb_dimensions {
5303: return ('200','50');
5304: }
5305:
1.16 raeburn 5306: sub check_dimensions {
5307: my ($inputfile) = @_;
5308: my ($fullwidth,$fullheight);
5309: if ($inputfile =~ m|^[/\w.\-]+$|) {
5310: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5311: my $imageinfo = <PIPE>;
5312: if (!close(PIPE)) {
5313: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5314: }
5315: chomp($imageinfo);
5316: my ($fullsize) =
1.21 raeburn 5317: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5318: if ($fullsize) {
5319: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5320: }
5321: }
5322: }
5323: return ($fullwidth,$fullheight);
5324: }
5325:
1.9 raeburn 5326: sub check_configuser {
5327: my ($uhome,$dom,$confname,$servadm) = @_;
5328: my ($configuserok,%currroles);
5329: if ($uhome eq 'no_host') {
5330: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5331: my $configpass = &LONCAPA::Enrollment::create_password();
5332: $configuserok =
5333: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5334: $configpass,'','','','','',undef,$servadm);
5335: } else {
5336: $configuserok = 'ok';
5337: %currroles =
5338: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5339: }
5340: return ($configuserok,%currroles);
5341: }
5342:
5343: sub check_authorstatus {
5344: my ($dom,$confname,%currroles) = @_;
5345: my $author_ok;
1.40 raeburn 5346: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5347: my $start = time;
5348: my $end = 0;
5349: $author_ok =
5350: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5351: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5352: } else {
5353: $author_ok = 'ok';
5354: }
5355: return $author_ok;
5356: }
5357:
5358: sub publishlogo {
1.46 raeburn 5359: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5360: my ($output,$fname,$logourl);
5361: if ($action eq 'upload') {
5362: $fname=$env{'form.'.$formname.'.filename'};
5363: chop($env{'form.'.$formname});
5364: } else {
5365: ($fname) = ($formname =~ /([^\/]+)$/);
5366: }
1.46 raeburn 5367: if ($savefileas ne '') {
5368: $fname = $savefileas;
5369: }
1.9 raeburn 5370: $fname=&Apache::lonnet::clean_filename($fname);
5371: # See if there is anything left
5372: unless ($fname) { return ('error: no uploaded file'); }
5373: $fname="$subdir/$fname";
1.160.6.5 raeburn 5374: my $docroot=$r->dir_config('lonDocRoot');
5375: my $filepath="$docroot/priv";
5376: my $relpath = "$dom/$confname";
1.9 raeburn 5377: my ($fnamepath,$file,$fetchthumb);
5378: $file=$fname;
5379: if ($fname=~m|/|) {
5380: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5381: }
1.160.6.5 raeburn 5382: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5383: my $count;
1.160.6.5 raeburn 5384: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5385: $filepath.="/$parts[$count]";
5386: if ((-e $filepath)!=1) {
5387: mkdir($filepath,02770);
5388: }
5389: }
5390: # Check for bad extension and disallow upload
5391: if ($file=~/\.(\w+)$/ &&
5392: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5393: $output =
5394: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5395: } elsif ($file=~/\.(\w+)$/ &&
5396: !defined(&Apache::loncommon::fileembstyle($1))) {
5397: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5398: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5399: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 5400: } elsif (-d "$filepath/$file") {
5401: $output = &mt('File name is a directory name - rename the file and re-upload');
5402: } else {
5403: my $source = $filepath.'/'.$file;
5404: my $logfile;
5405: if (!open($logfile,">>$source".'.log')) {
5406: return (&mt('No write permission to Construction Space'));
5407: }
5408: print $logfile
5409: "\n================= Publish ".localtime()." ================\n".
5410: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5411: # Save the file
5412: if (!open(FH,'>'.$source)) {
5413: &Apache::lonnet::logthis('Failed to create '.$source);
5414: return (&mt('Failed to create file'));
5415: }
5416: if ($action eq 'upload') {
5417: if (!print FH ($env{'form.'.$formname})) {
5418: &Apache::lonnet::logthis('Failed to write to '.$source);
5419: return (&mt('Failed to write file'));
5420: }
5421: } else {
5422: my $original = &Apache::lonnet::filelocation('',$formname);
5423: if(!copy($original,$source)) {
5424: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5425: return (&mt('Failed to write file'));
5426: }
5427: }
5428: close(FH);
5429: chmod(0660, $source); # Permissions to rw-rw---.
5430:
5431: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5432: my $copyfile=$targetdir.'/'.$file;
5433:
5434: my @parts=split(/\//,$targetdir);
5435: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5436: for (my $count=5;$count<=$#parts;$count++) {
5437: $path.="/$parts[$count]";
5438: if (!-e $path) {
5439: print $logfile "\nCreating directory ".$path;
5440: mkdir($path,02770);
5441: }
5442: }
5443: my $versionresult;
5444: if (-e $copyfile) {
5445: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5446: } else {
5447: $versionresult = 'ok';
5448: }
5449: if ($versionresult eq 'ok') {
5450: if (copy($source,$copyfile)) {
5451: print $logfile "\nCopied original source to ".$copyfile."\n";
5452: $output = 'ok';
5453: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5454: push(@{$modified_urls},[$copyfile,$source]);
5455: my $metaoutput =
5456: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5457: unless ($registered_cleanup) {
5458: my $handlers = $r->get_handlers('PerlCleanupHandler');
5459: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5460: $registered_cleanup=1;
5461: }
1.9 raeburn 5462: } else {
5463: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5464: $output = &mt('Failed to copy file to RES space').", $!";
5465: }
5466: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5467: my $inputfile = $filepath.'/'.$file;
5468: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5469: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5470: if ($fullwidth ne '' && $fullheight ne '') {
5471: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5472: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5473: system("convert -sample $thumbsize $inputfile $outfile");
5474: chmod(0660, $filepath.'/tn-'.$file);
5475: if (-e $outfile) {
5476: my $copyfile=$targetdir.'/tn-'.$file;
5477: if (copy($outfile,$copyfile)) {
5478: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5479: my $thumb_metaoutput =
5480: &write_metadata($dom,$confname,$formname,
5481: $targetdir,'tn-'.$file,$logfile);
5482: push(@{$modified_urls},[$copyfile,$outfile]);
5483: unless ($registered_cleanup) {
5484: my $handlers = $r->get_handlers('PerlCleanupHandler');
5485: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5486: $registered_cleanup=1;
5487: }
1.16 raeburn 5488: } else {
5489: print $logfile "\nUnable to write ".$copyfile.
5490: ':'.$!."\n";
5491: }
5492: }
1.9 raeburn 5493: }
5494: }
5495: }
5496: } else {
5497: $output = $versionresult;
5498: }
5499: }
5500: return ($output,$logourl);
5501: }
5502:
5503: sub logo_versioning {
5504: my ($targetdir,$file,$logfile) = @_;
5505: my $target = $targetdir.'/'.$file;
5506: my ($maxversion,$fn,$extn,$output);
5507: $maxversion = 0;
5508: if ($file =~ /^(.+)\.(\w+)$/) {
5509: $fn=$1;
5510: $extn=$2;
5511: }
5512: opendir(DIR,$targetdir);
5513: while (my $filename=readdir(DIR)) {
5514: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5515: $maxversion=($1>$maxversion)?$1:$maxversion;
5516: }
5517: }
5518: $maxversion++;
5519: print $logfile "\nCreating old version ".$maxversion."\n";
5520: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5521: if (copy($target,$copyfile)) {
5522: print $logfile "Copied old target to ".$copyfile."\n";
5523: $copyfile=$copyfile.'.meta';
5524: if (copy($target.'.meta',$copyfile)) {
5525: print $logfile "Copied old target metadata to ".$copyfile."\n";
5526: $output = 'ok';
5527: } else {
5528: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5529: $output = &mt('Failed to copy old meta').", $!, ";
5530: }
5531: } else {
5532: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5533: $output = &mt('Failed to copy old target').", $!, ";
5534: }
5535: return $output;
5536: }
5537:
5538: sub write_metadata {
5539: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5540: my (%metadatafields,%metadatakeys,$output);
5541: $metadatafields{'title'}=$formname;
5542: $metadatafields{'creationdate'}=time;
5543: $metadatafields{'lastrevisiondate'}=time;
5544: $metadatafields{'copyright'}='public';
5545: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5546: $env{'user.domain'};
5547: $metadatafields{'authorspace'}=$confname.':'.$dom;
5548: $metadatafields{'domain'}=$dom;
5549: {
5550: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5551: my $mfh;
1.155 raeburn 5552: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5553: foreach (sort keys %metadatafields) {
5554: unless ($_=~/\./) {
5555: my $unikey=$_;
5556: $unikey=~/^([A-Za-z]+)/;
5557: my $tag=$1;
5558: $tag=~tr/A-Z/a-z/;
5559: print $mfh "\n\<$tag";
5560: foreach (split(/\,/,$metadatakeys{$unikey})) {
5561: my $value=$metadatafields{$unikey.'.'.$_};
5562: $value=~s/\"/\'\'/g;
5563: print $mfh ' '.$_.'="'.$value.'"';
5564: }
5565: print $mfh '>'.
5566: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5567: .'</'.$tag.'>';
5568: }
5569: }
5570: $output = 'ok';
5571: print $logfile "\nWrote metadata";
5572: close($mfh);
5573: } else {
5574: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5575: $output = &mt('Could not write metadata');
5576: }
5577: }
1.155 raeburn 5578: return $output;
5579: }
5580:
5581: sub notifysubscribed {
5582: foreach my $targetsource (@{$modified_urls}){
5583: next unless (ref($targetsource) eq 'ARRAY');
5584: my ($target,$source)=@{$targetsource};
5585: if ($source ne '') {
5586: if (open(my $logfh,'>>'.$source.'.log')) {
5587: print $logfh "\nCleanup phase: Notifications\n";
5588: my @subscribed=&subscribed_hosts($target);
5589: foreach my $subhost (@subscribed) {
5590: print $logfh "\nNotifying host ".$subhost.':';
5591: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5592: print $logfh $reply;
5593: }
5594: my @subscribedmeta=&subscribed_hosts("$target.meta");
5595: foreach my $subhost (@subscribedmeta) {
5596: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5597: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5598: $subhost);
5599: print $logfh $reply;
5600: }
5601: print $logfh "\n============ Done ============\n";
1.160 raeburn 5602: close($logfh);
1.155 raeburn 5603: }
5604: }
5605: }
5606: return OK;
5607: }
5608:
5609: sub subscribed_hosts {
5610: my ($target) = @_;
5611: my @subscribed;
5612: if (open(my $fh,"<$target.subscription")) {
5613: while (my $subline=<$fh>) {
5614: if ($subline =~ /^($match_lonid):/) {
5615: my $host = $1;
5616: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5617: unless (grep(/^\Q$host\E$/,@subscribed)) {
5618: push(@subscribed,$host);
5619: }
5620: }
5621: }
5622: }
5623: }
5624: return @subscribed;
1.9 raeburn 5625: }
5626:
5627: sub check_switchserver {
5628: my ($dom,$confname) = @_;
5629: my ($allowed,$switchserver);
5630: my $home = &Apache::lonnet::homeserver($confname,$dom);
5631: if ($home eq 'no_host') {
5632: $home = &Apache::lonnet::domain($dom,'primary');
5633: }
5634: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5635: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5636: if (!$allowed) {
5637: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5638: }
5639: return $switchserver;
5640: }
5641:
1.1 raeburn 5642: sub modify_quotas {
1.86 raeburn 5643: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5644: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5645: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5646: if ($action eq 'quotas') {
5647: $context = 'tools';
5648: } else {
5649: $context = $action;
5650: }
5651: if ($context eq 'requestcourses') {
1.98 raeburn 5652: @usertools = ('official','unofficial','community');
1.106 raeburn 5653: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5654: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5655: %titles = &courserequest_titles();
5656: $toolregexp = join('|',@usertools);
5657: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5658: } elsif ($context eq 'requestauthor') {
5659: @usertools = ('author');
5660: %titles = &authorrequest_titles();
1.86 raeburn 5661: } else {
1.160.6.4 raeburn 5662: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5663: %titles = &tool_titles();
1.86 raeburn 5664: }
1.72 raeburn 5665: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5666: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5667: foreach my $key (keys(%env)) {
1.101 raeburn 5668: if ($context eq 'requestcourses') {
5669: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5670: my $item = $1;
5671: my $type = $2;
5672: if ($type =~ /^limit_(.+)/) {
5673: $limithash{$item}{$1} = $env{$key};
5674: } else {
5675: $confhash{$item}{$type} = $env{$key};
5676: }
5677: }
1.160.6.5 raeburn 5678: } elsif ($context eq 'requestauthor') {
5679: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5680: $confhash{$1} = $env{$key};
5681: }
1.101 raeburn 5682: } else {
1.86 raeburn 5683: if ($key =~ /^form\.quota_(.+)$/) {
5684: $confhash{'defaultquota'}{$1} = $env{$key};
5685: }
1.101 raeburn 5686: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5687: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5688: }
1.72 raeburn 5689: }
5690: }
1.160.6.5 raeburn 5691: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5692: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5693: @approvalnotify = sort(@approvalnotify);
5694: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5695: if (ref($domconfig{$action}) eq 'HASH') {
5696: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5697: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5698: $changes{'notify'}{'approval'} = 1;
5699: }
5700: } else {
1.144 raeburn 5701: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5702: $changes{'notify'}{'approval'} = 1;
5703: }
5704: }
5705: } else {
1.144 raeburn 5706: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5707: $changes{'notify'}{'approval'} = 1;
5708: }
5709: }
5710: } else {
1.86 raeburn 5711: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5712: }
1.72 raeburn 5713: foreach my $item (@usertools) {
5714: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5715: my $unset;
1.101 raeburn 5716: if ($context eq 'requestcourses') {
1.104 raeburn 5717: $unset = '0';
5718: if ($type eq '_LC_adv') {
5719: $unset = '';
5720: }
1.101 raeburn 5721: if ($confhash{$item}{$type} eq 'autolimit') {
5722: $confhash{$item}{$type} .= '=';
5723: unless ($limithash{$item}{$type} =~ /\D/) {
5724: $confhash{$item}{$type} .= $limithash{$item}{$type};
5725: }
5726: }
1.160.6.5 raeburn 5727: } elsif ($context eq 'requestauthor') {
5728: $unset = '0';
5729: if ($type eq '_LC_adv') {
5730: $unset = '';
5731: }
1.72 raeburn 5732: } else {
1.101 raeburn 5733: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5734: $confhash{$item}{$type} = 1;
5735: } else {
5736: $confhash{$item}{$type} = 0;
5737: }
1.72 raeburn 5738: }
1.86 raeburn 5739: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5740: if ($action eq 'requestauthor') {
5741: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5742: $changes{$type} = 1;
5743: }
5744: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5745: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5746: $changes{$item}{$type} = 1;
5747: }
5748: } else {
5749: if ($context eq 'requestcourses') {
1.104 raeburn 5750: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5751: $changes{$item}{$type} = 1;
5752: }
5753: } else {
5754: if (!$confhash{$item}{$type}) {
5755: $changes{$item}{$type} = 1;
5756: }
5757: }
5758: }
5759: } else {
5760: if ($context eq 'requestcourses') {
1.104 raeburn 5761: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5762: $changes{$item}{$type} = 1;
5763: }
1.160.6.5 raeburn 5764: } elsif ($context eq 'requestauthor') {
5765: if ($confhash{$type} ne $unset) {
5766: $changes{$type} = 1;
5767: }
1.72 raeburn 5768: } else {
5769: if (!$confhash{$item}{$type}) {
5770: $changes{$item}{$type} = 1;
5771: }
5772: }
5773: }
1.1 raeburn 5774: }
5775: }
1.160.6.5 raeburn 5776: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5777: if (ref($domconfig{'quotas'}) eq 'HASH') {
5778: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5779: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5780: if (exists($confhash{'defaultquota'}{$key})) {
5781: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5782: $changes{'defaultquota'}{$key} = 1;
5783: }
5784: } else {
5785: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5786: }
5787: }
1.86 raeburn 5788: } else {
5789: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5790: if (exists($confhash{'defaultquota'}{$key})) {
5791: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5792: $changes{'defaultquota'}{$key} = 1;
5793: }
5794: } else {
5795: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5796: }
1.1 raeburn 5797: }
5798: }
5799: }
1.86 raeburn 5800: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5801: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5802: if (ref($domconfig{'quotas'}) eq 'HASH') {
5803: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5804: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5805: $changes{'defaultquota'}{$key} = 1;
5806: }
5807: } else {
5808: if (!exists($domconfig{'quotas'}{$key})) {
5809: $changes{'defaultquota'}{$key} = 1;
5810: }
1.72 raeburn 5811: }
5812: } else {
1.86 raeburn 5813: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5814: }
1.1 raeburn 5815: }
5816: }
5817: }
1.72 raeburn 5818:
1.160.6.5 raeburn 5819: if ($context eq 'requestauthor') {
5820: $domdefaults{'requestauthor'} = \%confhash;
5821: } else {
5822: foreach my $key (keys(%confhash)) {
5823: $domdefaults{$key} = $confhash{$key};
5824: }
1.72 raeburn 5825: }
1.160.6.5 raeburn 5826:
1.1 raeburn 5827: my %quotahash = (
1.86 raeburn 5828: $action => { %confhash }
1.1 raeburn 5829: );
5830: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5831: $dom);
5832: if ($putresult eq 'ok') {
5833: if (keys(%changes) > 0) {
1.72 raeburn 5834: my $cachetime = 24*60*60;
5835: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5836:
1.1 raeburn 5837: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 5838: unless (($context eq 'requestcourses') ||
5839: ($context eq 'requestauthor')) {
1.86 raeburn 5840: if (ref($changes{'defaultquota'}) eq 'HASH') {
5841: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5842: foreach my $type (@{$types},'default') {
5843: if (defined($changes{'defaultquota'}{$type})) {
5844: my $typetitle = $usertypes->{$type};
5845: if ($type eq 'default') {
5846: $typetitle = $othertitle;
5847: }
5848: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5849: }
5850: }
1.86 raeburn 5851: $resulttext .= '</ul></li>';
1.72 raeburn 5852: }
5853: }
1.80 raeburn 5854: my %newenv;
1.72 raeburn 5855: foreach my $item (@usertools) {
1.160.6.5 raeburn 5856: my (%haschgs,%inconf);
5857: if ($context eq 'requestauthor') {
5858: %haschgs = %changes;
5859: %inconf = %confhash;
5860: } else {
5861: if (ref($changes{$item}) eq 'HASH') {
5862: %haschgs = %{$changes{$item}};
5863: }
5864: if (ref($confhash{$item}) eq 'HASH') {
5865: %inconf = %{$confhash{$item}};
5866: }
5867: }
5868: if (keys(%haschgs) > 0) {
1.80 raeburn 5869: my $newacc =
5870: &Apache::lonnet::usertools_access($env{'user.name'},
5871: $env{'user.domain'},
1.86 raeburn 5872: $item,'reload',$context);
1.160.6.5 raeburn 5873: if (($context eq 'requestcourses') ||
5874: ($context eq 'requestauthor')) {
1.108 raeburn 5875: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5876: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5877: }
5878: } else {
5879: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5880: $newenv{'environment.availabletools.'.$item} = $newacc;
5881: }
1.80 raeburn 5882: }
1.160.6.5 raeburn 5883: unless ($context eq 'requestauthor') {
5884: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5885: }
1.72 raeburn 5886: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 5887: if ($haschgs{$type}) {
1.72 raeburn 5888: my $typetitle = $usertypes->{$type};
5889: if ($type eq 'default') {
5890: $typetitle = $othertitle;
5891: } elsif ($type eq '_LC_adv') {
5892: $typetitle = 'LON-CAPA Advanced Users';
5893: }
1.160.6.5 raeburn 5894: if ($inconf{$type}) {
1.101 raeburn 5895: if ($context eq 'requestcourses') {
5896: my $cond;
1.160.6.5 raeburn 5897: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5898: if ($1 eq '') {
5899: $cond = &mt('(Automatic processing of any request).');
5900: } else {
5901: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5902: }
5903: } else {
1.160.6.5 raeburn 5904: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5905: }
5906: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 5907: } elsif ($context eq 'requestauthor') {
5908: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5909: $titles{$inconf{$type}},$typetitle);
5910:
1.101 raeburn 5911: } else {
5912: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5913: }
1.72 raeburn 5914: } else {
1.104 raeburn 5915: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 5916: if ($inconf{$type} eq '0') {
1.104 raeburn 5917: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5918: } else {
5919: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5920: }
5921: } else {
5922: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5923: }
1.72 raeburn 5924: }
5925: }
1.26 raeburn 5926: }
1.160.6.5 raeburn 5927: unless ($context eq 'requestauthor') {
5928: $resulttext .= '</ul></li>';
5929: }
1.26 raeburn 5930: }
1.1 raeburn 5931: }
1.160.6.5 raeburn 5932: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5933: if (ref($changes{'notify'}) eq 'HASH') {
5934: if ($changes{'notify'}{'approval'}) {
5935: if (ref($confhash{'notify'}) eq 'HASH') {
5936: if ($confhash{'notify'}{'approval'}) {
5937: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5938: } else {
1.160.6.5 raeburn 5939: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5940: }
5941: }
5942: }
5943: }
5944: }
1.1 raeburn 5945: $resulttext .= '</ul>';
1.80 raeburn 5946: if (keys(%newenv)) {
5947: &Apache::lonnet::appenv(\%newenv);
5948: }
1.1 raeburn 5949: } else {
1.86 raeburn 5950: if ($context eq 'requestcourses') {
5951: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 5952: } elsif ($context eq 'requestauthor') {
5953: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5954: } else {
1.90 weissno 5955: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5956: }
1.1 raeburn 5957: }
5958: } else {
1.11 albertel 5959: $resulttext = '<span class="LC_error">'.
5960: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5961: }
1.3 raeburn 5962: return $resulttext;
1.1 raeburn 5963: }
5964:
1.3 raeburn 5965: sub modify_autoenroll {
5966: my ($dom,%domconfig) = @_;
1.1 raeburn 5967: my ($resulttext,%changes);
5968: my %currautoenroll;
5969: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5970: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5971: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5972: }
5973: }
5974: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5975: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5976: sender => 'Sender for notification messages',
5977: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5978: my @offon = ('off','on');
1.17 raeburn 5979: my $sender_uname = $env{'form.sender_uname'};
5980: my $sender_domain = $env{'form.sender_domain'};
5981: if ($sender_domain eq '') {
5982: $sender_uname = '';
5983: } elsif ($sender_uname eq '') {
5984: $sender_domain = '';
5985: }
1.129 raeburn 5986: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5987: my %autoenrollhash = (
1.129 raeburn 5988: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5989: 'sender_uname' => $sender_uname,
5990: 'sender_domain' => $sender_domain,
5991: 'co-owners' => $coowners,
1.1 raeburn 5992: }
5993: );
1.4 raeburn 5994: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5995: $dom);
1.1 raeburn 5996: if ($putresult eq 'ok') {
5997: if (exists($currautoenroll{'run'})) {
5998: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5999: $changes{'run'} = 1;
6000: }
6001: } elsif ($autorun) {
6002: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6003: $changes{'run'} = 1;
1.1 raeburn 6004: }
6005: }
1.17 raeburn 6006: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6007: $changes{'sender'} = 1;
6008: }
1.17 raeburn 6009: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6010: $changes{'sender'} = 1;
6011: }
1.129 raeburn 6012: if ($currautoenroll{'co-owners'} ne '') {
6013: if ($currautoenroll{'co-owners'} ne $coowners) {
6014: $changes{'coowners'} = 1;
6015: }
6016: } elsif ($coowners) {
6017: $changes{'coowners'} = 1;
6018: }
1.1 raeburn 6019: if (keys(%changes) > 0) {
6020: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6021: if ($changes{'run'}) {
1.1 raeburn 6022: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6023: }
6024: if ($changes{'sender'}) {
1.17 raeburn 6025: if ($sender_uname eq '' || $sender_domain eq '') {
6026: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6027: } else {
6028: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6029: }
1.1 raeburn 6030: }
1.129 raeburn 6031: if ($changes{'coowners'}) {
6032: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6033: &Apache::loncommon::devalidate_domconfig_cache($dom);
6034: }
1.1 raeburn 6035: $resulttext .= '</ul>';
6036: } else {
6037: $resulttext = &mt('No changes made to auto-enrollment settings');
6038: }
6039: } else {
1.11 albertel 6040: $resulttext = '<span class="LC_error">'.
6041: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6042: }
1.3 raeburn 6043: return $resulttext;
1.1 raeburn 6044: }
6045:
6046: sub modify_autoupdate {
1.3 raeburn 6047: my ($dom,%domconfig) = @_;
1.1 raeburn 6048: my ($resulttext,%currautoupdate,%fields,%changes);
6049: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6050: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6051: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6052: }
6053: }
6054: my @offon = ('off','on');
6055: my %title = &Apache::lonlocal::texthash (
6056: run => 'Auto-update:',
6057: classlists => 'Updates to user information in classlists?'
6058: );
1.44 raeburn 6059: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6060: my %fieldtitles = &Apache::lonlocal::texthash (
6061: id => 'Student/Employee ID',
1.20 raeburn 6062: permanentemail => 'E-mail address',
1.1 raeburn 6063: lastname => 'Last Name',
6064: firstname => 'First Name',
6065: middlename => 'Middle Name',
1.132 raeburn 6066: generation => 'Generation',
1.1 raeburn 6067: );
1.142 raeburn 6068: $othertitle = &mt('All users');
1.1 raeburn 6069: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6070: $othertitle = &mt('Other users');
1.1 raeburn 6071: }
6072: foreach my $key (keys(%env)) {
6073: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6074: my ($usertype,$item) = ($1,$2);
6075: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6076: if ($usertype eq 'default') {
6077: push(@{$fields{$1}},$2);
6078: } elsif (ref($types) eq 'ARRAY') {
6079: if (grep(/^\Q$usertype\E$/,@{$types})) {
6080: push(@{$fields{$1}},$2);
6081: }
6082: }
6083: }
1.1 raeburn 6084: }
6085: }
1.131 raeburn 6086: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6087: @lockablenames = sort(@lockablenames);
6088: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6089: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6090: if (@changed) {
6091: $changes{'lockablenames'} = 1;
6092: }
6093: } else {
6094: if (@lockablenames) {
6095: $changes{'lockablenames'} = 1;
6096: }
6097: }
1.1 raeburn 6098: my %updatehash = (
6099: autoupdate => { run => $env{'form.autoupdate_run'},
6100: classlists => $env{'form.classlists'},
6101: fields => {%fields},
1.131 raeburn 6102: lockablenames => \@lockablenames,
1.1 raeburn 6103: }
6104: );
6105: foreach my $key (keys(%currautoupdate)) {
6106: if (($key eq 'run') || ($key eq 'classlists')) {
6107: if (exists($updatehash{autoupdate}{$key})) {
6108: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6109: $changes{$key} = 1;
6110: }
6111: }
6112: } elsif ($key eq 'fields') {
6113: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6114: foreach my $item (@{$types},'default') {
1.1 raeburn 6115: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6116: my $change = 0;
6117: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6118: if (!exists($fields{$item})) {
6119: $change = 1;
1.132 raeburn 6120: last;
1.1 raeburn 6121: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6122: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6123: $change = 1;
1.132 raeburn 6124: last;
1.1 raeburn 6125: }
6126: }
6127: }
6128: if ($change) {
6129: push(@{$changes{$key}},$item);
6130: }
1.26 raeburn 6131: }
1.1 raeburn 6132: }
6133: }
1.131 raeburn 6134: } elsif ($key eq 'lockablenames') {
6135: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6136: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6137: if (@changed) {
6138: $changes{'lockablenames'} = 1;
6139: }
6140: } else {
6141: if (@lockablenames) {
6142: $changes{'lockablenames'} = 1;
6143: }
6144: }
6145: }
6146: }
6147: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6148: if (@lockablenames) {
6149: $changes{'lockablenames'} = 1;
1.1 raeburn 6150: }
6151: }
1.26 raeburn 6152: foreach my $item (@{$types},'default') {
6153: if (defined($fields{$item})) {
6154: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6155: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6156: my $change = 0;
6157: if (ref($fields{$item}) eq 'ARRAY') {
6158: foreach my $type (@{$fields{$item}}) {
6159: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6160: $change = 1;
6161: last;
6162: }
6163: }
6164: }
6165: if ($change) {
6166: push(@{$changes{'fields'}},$item);
6167: }
6168: } else {
1.26 raeburn 6169: push(@{$changes{'fields'}},$item);
6170: }
6171: } else {
6172: push(@{$changes{'fields'}},$item);
1.1 raeburn 6173: }
6174: }
6175: }
6176: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6177: $dom);
6178: if ($putresult eq 'ok') {
6179: if (keys(%changes) > 0) {
6180: $resulttext = &mt('Changes made:').'<ul>';
6181: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6182: if ($key eq 'lockablenames') {
6183: $resulttext .= '<li>';
6184: if (@lockablenames) {
6185: $usertypes->{'default'} = $othertitle;
6186: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6187: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6188: } else {
6189: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6190: }
6191: $resulttext .= '</li>';
6192: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6193: foreach my $item (@{$changes{$key}}) {
6194: my @newvalues;
6195: foreach my $type (@{$fields{$item}}) {
6196: push(@newvalues,$fieldtitles{$type});
6197: }
1.3 raeburn 6198: my $newvaluestr;
6199: if (@newvalues > 0) {
6200: $newvaluestr = join(', ',@newvalues);
6201: } else {
6202: $newvaluestr = &mt('none');
1.6 raeburn 6203: }
1.1 raeburn 6204: if ($item eq 'default') {
1.26 raeburn 6205: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6206: } else {
1.26 raeburn 6207: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6208: }
6209: }
6210: } else {
6211: my $newvalue;
6212: if ($key eq 'run') {
6213: $newvalue = $offon[$env{'form.autoupdate_run'}];
6214: } else {
6215: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6216: }
1.1 raeburn 6217: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6218: }
6219: }
6220: $resulttext .= '</ul>';
6221: } else {
1.3 raeburn 6222: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6223: }
6224: } else {
1.11 albertel 6225: $resulttext = '<span class="LC_error">'.
6226: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6227: }
1.3 raeburn 6228: return $resulttext;
1.1 raeburn 6229: }
6230:
1.125 raeburn 6231: sub modify_autocreate {
6232: my ($dom,%domconfig) = @_;
6233: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6234: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6235: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6236: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6237: }
6238: }
6239: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6240: req => 'Auto-creation of validated requests for official courses',
6241: xmldc => 'Identity of course creator of courses from XML files',
6242: );
6243: my @types = ('xml','req');
6244: foreach my $item (@types) {
6245: $newvals{$item} = $env{'form.autocreate_'.$item};
6246: $newvals{$item} =~ s/\D//g;
6247: $newvals{$item} = 0 if ($newvals{$item} eq '');
6248: }
6249: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6250: my %domcoords = &get_active_dcs($dom);
6251: unless (exists($domcoords{$newvals{'xmldc'}})) {
6252: $newvals{'xmldc'} = '';
6253: }
6254: %autocreatehash = (
6255: autocreate => { xml => $newvals{'xml'},
6256: req => $newvals{'req'},
6257: }
6258: );
6259: if ($newvals{'xmldc'} ne '') {
6260: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6261: }
6262: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6263: $dom);
6264: if ($putresult eq 'ok') {
6265: my @items = @types;
6266: if ($newvals{'xml'}) {
6267: push(@items,'xmldc');
6268: }
6269: foreach my $item (@items) {
6270: if (exists($currautocreate{$item})) {
6271: if ($currautocreate{$item} ne $newvals{$item}) {
6272: $changes{$item} = 1;
6273: }
6274: } elsif ($newvals{$item}) {
6275: $changes{$item} = 1;
6276: }
6277: }
6278: if (keys(%changes) > 0) {
6279: my @offon = ('off','on');
6280: $resulttext = &mt('Changes made:').'<ul>';
6281: foreach my $item (@types) {
6282: if ($changes{$item}) {
6283: my $newtxt = $offon[$newvals{$item}];
6284: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6285: }
6286: }
6287: if ($changes{'xmldc'}) {
6288: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6289: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
6290: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6291: }
6292: $resulttext .= '</ul>';
6293: } else {
6294: $resulttext = &mt('No changes made to auto-creation settings');
6295: }
6296: } else {
6297: $resulttext = '<span class="LC_error">'.
6298: &mt('An error occurred: [_1]',$putresult).'</span>';
6299: }
6300: return $resulttext;
6301: }
6302:
1.23 raeburn 6303: sub modify_directorysrch {
6304: my ($dom,%domconfig) = @_;
6305: my ($resulttext,%changes);
6306: my %currdirsrch;
6307: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6308: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6309: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6310: }
6311: }
6312: my %title = ( available => 'Directory search available',
1.24 raeburn 6313: localonly => 'Other domains can search',
1.23 raeburn 6314: searchby => 'Search types',
6315: searchtypes => 'Search latitude');
6316: my @offon = ('off','on');
1.24 raeburn 6317: my @otherdoms = ('Yes','No');
1.23 raeburn 6318:
1.25 raeburn 6319: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6320: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6321: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6322:
1.44 raeburn 6323: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6324: if (keys(%{$usertypes}) == 0) {
6325: @cansearch = ('default');
6326: } else {
6327: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6328: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6329: if (!grep(/^\Q$type\E$/,@cansearch)) {
6330: push(@{$changes{'cansearch'}},$type);
6331: }
1.23 raeburn 6332: }
1.26 raeburn 6333: foreach my $type (@cansearch) {
6334: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6335: push(@{$changes{'cansearch'}},$type);
6336: }
1.23 raeburn 6337: }
1.26 raeburn 6338: } else {
6339: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6340: }
6341: }
6342:
6343: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6344: foreach my $by (@{$currdirsrch{'searchby'}}) {
6345: if (!grep(/^\Q$by\E$/,@searchby)) {
6346: push(@{$changes{'searchby'}},$by);
6347: }
6348: }
6349: foreach my $by (@searchby) {
6350: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6351: push(@{$changes{'searchby'}},$by);
6352: }
6353: }
6354: } else {
6355: push(@{$changes{'searchby'}},@searchby);
6356: }
1.25 raeburn 6357:
6358: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6359: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6360: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6361: push(@{$changes{'searchtypes'}},$type);
6362: }
6363: }
6364: foreach my $type (@searchtypes) {
6365: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6366: push(@{$changes{'searchtypes'}},$type);
6367: }
6368: }
6369: } else {
6370: if (exists($currdirsrch{'searchtypes'})) {
6371: foreach my $type (@searchtypes) {
6372: if ($type ne $currdirsrch{'searchtypes'}) {
6373: push(@{$changes{'searchtypes'}},$type);
6374: }
6375: }
6376: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6377: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6378: }
6379: } else {
6380: push(@{$changes{'searchtypes'}},@searchtypes);
6381: }
6382: }
6383:
1.23 raeburn 6384: my %dirsrch_hash = (
6385: directorysrch => { available => $env{'form.dirsrch_available'},
6386: cansearch => \@cansearch,
1.24 raeburn 6387: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6388: searchby => \@searchby,
1.25 raeburn 6389: searchtypes => \@searchtypes,
1.23 raeburn 6390: }
6391: );
6392: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6393: $dom);
6394: if ($putresult eq 'ok') {
6395: if (exists($currdirsrch{'available'})) {
6396: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6397: $changes{'available'} = 1;
6398: }
6399: } else {
6400: if ($env{'form.dirsrch_available'} eq '1') {
6401: $changes{'available'} = 1;
6402: }
6403: }
1.24 raeburn 6404: if (exists($currdirsrch{'localonly'})) {
6405: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6406: $changes{'localonly'} = 1;
6407: }
6408: } else {
6409: if ($env{'form.dirsrch_localonly'} eq '1') {
6410: $changes{'localonly'} = 1;
6411: }
6412: }
1.23 raeburn 6413: if (keys(%changes) > 0) {
6414: $resulttext = &mt('Changes made:').'<ul>';
6415: if ($changes{'available'}) {
6416: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6417: }
1.24 raeburn 6418: if ($changes{'localonly'}) {
6419: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6420: }
6421:
1.23 raeburn 6422: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6423: my $chgtext;
1.26 raeburn 6424: if (ref($usertypes) eq 'HASH') {
6425: if (keys(%{$usertypes}) > 0) {
6426: foreach my $type (@{$types}) {
6427: if (grep(/^\Q$type\E$/,@cansearch)) {
6428: $chgtext .= $usertypes->{$type}.'; ';
6429: }
6430: }
6431: if (grep(/^default$/,@cansearch)) {
6432: $chgtext .= $othertitle;
6433: } else {
6434: $chgtext =~ s/\; $//;
6435: }
6436: $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23 raeburn 6437: }
6438: }
6439: }
6440: if (ref($changes{'searchby'}) eq 'ARRAY') {
6441: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6442: my $chgtext;
6443: foreach my $type (@{$titleorder}) {
6444: if (grep(/^\Q$type\E$/,@searchby)) {
6445: if (defined($searchtitles->{$type})) {
6446: $chgtext .= $searchtitles->{$type}.'; ';
6447: }
6448: }
6449: }
6450: $chgtext =~ s/\; $//;
6451: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6452: }
1.25 raeburn 6453: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6454: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6455: my $chgtext;
6456: foreach my $type (@{$srchtypeorder}) {
6457: if (grep(/^\Q$type\E$/,@searchtypes)) {
6458: if (defined($srchtypes_desc->{$type})) {
6459: $chgtext .= $srchtypes_desc->{$type}.'; ';
6460: }
6461: }
6462: }
6463: $chgtext =~ s/\; $//;
6464: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 6465: }
6466: $resulttext .= '</ul>';
6467: } else {
6468: $resulttext = &mt('No changes made to institution directory search settings');
6469: }
6470: } else {
6471: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6472: &mt('An error occurred: [_1]',$putresult).'</span>';
6473: }
6474: return $resulttext;
6475: }
6476:
1.28 raeburn 6477: sub modify_contacts {
6478: my ($dom,%domconfig) = @_;
6479: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6480: if (ref($domconfig{'contacts'}) eq 'HASH') {
6481: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6482: $currsetting{$key} = $domconfig{'contacts'}{$key};
6483: }
6484: }
1.134 raeburn 6485: my (%others,%to,%bcc);
1.28 raeburn 6486: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6487: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6488: 'requestsmail');
1.28 raeburn 6489: foreach my $type (@mailings) {
6490: @{$newsetting{$type}} =
6491: &Apache::loncommon::get_env_multiple('form.'.$type);
6492: foreach my $item (@contacts) {
6493: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6494: $contacts_hash{contacts}{$type}{$item} = 1;
6495: } else {
6496: $contacts_hash{contacts}{$type}{$item} = 0;
6497: }
6498: }
6499: $others{$type} = $env{'form.'.$type.'_others'};
6500: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6501: if ($type eq 'helpdeskmail') {
6502: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6503: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6504: }
1.28 raeburn 6505: }
6506: foreach my $item (@contacts) {
6507: $to{$item} = $env{'form.'.$item};
6508: $contacts_hash{'contacts'}{$item} = $to{$item};
6509: }
6510: if (keys(%currsetting) > 0) {
6511: foreach my $item (@contacts) {
6512: if ($to{$item} ne $currsetting{$item}) {
6513: $changes{$item} = 1;
6514: }
6515: }
6516: foreach my $type (@mailings) {
6517: foreach my $item (@contacts) {
6518: if (ref($currsetting{$type}) eq 'HASH') {
6519: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6520: push(@{$changes{$type}},$item);
6521: }
6522: } else {
6523: push(@{$changes{$type}},@{$newsetting{$type}});
6524: }
6525: }
6526: if ($others{$type} ne $currsetting{$type}{'others'}) {
6527: push(@{$changes{$type}},'others');
6528: }
1.134 raeburn 6529: if ($type eq 'helpdeskmail') {
6530: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6531: push(@{$changes{$type}},'bcc');
6532: }
6533: }
1.28 raeburn 6534: }
6535: } else {
6536: my %default;
6537: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6538: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6539: $default{'errormail'} = 'adminemail';
6540: $default{'packagesmail'} = 'adminemail';
6541: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6542: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6543: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6544: foreach my $item (@contacts) {
6545: if ($to{$item} ne $default{$item}) {
6546: $changes{$item} = 1;
6547: }
6548: }
6549: foreach my $type (@mailings) {
6550: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6551:
6552: push(@{$changes{$type}},@{$newsetting{$type}});
6553: }
6554: if ($others{$type} ne '') {
6555: push(@{$changes{$type}},'others');
1.134 raeburn 6556: }
6557: if ($type eq 'helpdeskmail') {
6558: if ($bcc{$type} ne '') {
6559: push(@{$changes{$type}},'bcc');
6560: }
6561: }
1.28 raeburn 6562: }
6563: }
6564: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6565: $dom);
6566: if ($putresult eq 'ok') {
6567: if (keys(%changes) > 0) {
6568: my ($titles,$short_titles) = &contact_titles();
6569: $resulttext = &mt('Changes made:').'<ul>';
6570: foreach my $item (@contacts) {
6571: if ($changes{$item}) {
6572: $resulttext .= '<li>'.$titles->{$item}.
6573: &mt(' set to: ').
6574: '<span class="LC_cusr_emph">'.
6575: $to{$item}.'</span></li>';
6576: }
6577: }
6578: foreach my $type (@mailings) {
6579: if (ref($changes{$type}) eq 'ARRAY') {
6580: $resulttext .= '<li>'.$titles->{$type}.': ';
6581: my @text;
6582: foreach my $item (@{$newsetting{$type}}) {
6583: push(@text,$short_titles->{$item});
6584: }
6585: if ($others{$type} ne '') {
6586: push(@text,$others{$type});
6587: }
6588: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6589: join(', ',@text).'</span>';
6590: if ($type eq 'helpdeskmail') {
6591: if ($bcc{$type} ne '') {
6592: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6593: }
6594: }
6595: $resulttext .= '</li>';
1.28 raeburn 6596: }
6597: }
6598: $resulttext .= '</ul>';
6599: } else {
1.34 raeburn 6600: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6601: }
6602: } else {
6603: $resulttext = '<span class="LC_error">'.
6604: &mt('An error occurred: [_1].',$putresult).'</span>';
6605: }
6606: return $resulttext;
6607: }
6608:
6609: sub modify_usercreation {
1.27 raeburn 6610: my ($dom,%domconfig) = @_;
1.34 raeburn 6611: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6612: my $warningmsg;
1.27 raeburn 6613: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6614: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6615: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6616: }
6617: }
6618: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6619: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6620: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6621: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6622: foreach my $item(@contexts) {
1.45 raeburn 6623: if ($item eq 'selfcreate') {
1.50 raeburn 6624: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6625: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6626: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6627: if (ref($cancreate{$item}) eq 'ARRAY') {
6628: if (grep(/^login$/,@{$cancreate{$item}})) {
6629: $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.');
6630: }
1.43 raeburn 6631: }
6632: }
1.50 raeburn 6633: } else {
6634: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6635: }
1.34 raeburn 6636: }
1.93 raeburn 6637: my ($othertitle,$usertypes,$types) =
6638: &Apache::loncommon::sorted_inst_types($dom);
6639: if (ref($types) eq 'ARRAY') {
6640: if (@{$types} > 0) {
6641: @{$cancreate{'statustocreate'}} =
6642: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6643: } else {
6644: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6645: }
6646: push(@contexts,'statustocreate');
6647: }
1.160.6.5 raeburn 6648: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6649: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6650: foreach my $item (@contexts) {
1.93 raeburn 6651: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6652: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6653: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6654: if (ref($cancreate{$item}) eq 'ARRAY') {
6655: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6656: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6657: push(@{$changes{'cancreate'}},$item);
6658: }
1.50 raeburn 6659: }
6660: }
6661: }
6662: } else {
6663: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6664: if (@{$cancreate{$item}} > 0) {
6665: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6666: push(@{$changes{'cancreate'}},$item);
6667: }
6668: }
6669: } else {
6670: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6671: if (@{$cancreate{$item}} < 3) {
6672: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6673: push(@{$changes{'cancreate'}},$item);
6674: }
6675: }
6676: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6677: if (@{$cancreate{$item}} > 0) {
6678: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6679: push(@{$changes{'cancreate'}},$item);
6680: }
6681: }
6682: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6683: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6684: push(@{$changes{'cancreate'}},$item);
6685: }
6686: }
6687: }
6688: }
6689: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6690: foreach my $type (@{$cancreate{$item}}) {
6691: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6692: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6693: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6694: push(@{$changes{'cancreate'}},$item);
6695: }
6696: }
6697: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6698: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6699: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6700: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6701: push(@{$changes{'cancreate'}},$item);
6702: }
6703: }
6704: }
6705: }
6706: }
6707: } else {
6708: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6709: push(@{$changes{'cancreate'}},$item);
6710: }
6711: }
1.27 raeburn 6712: }
1.34 raeburn 6713: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6714: foreach my $item (@contexts) {
1.43 raeburn 6715: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6716: if ($cancreate{$item} ne 'any') {
6717: push(@{$changes{'cancreate'}},$item);
6718: }
6719: } else {
6720: if ($cancreate{$item} ne 'none') {
6721: push(@{$changes{'cancreate'}},$item);
6722: }
1.27 raeburn 6723: }
6724: }
6725: } else {
1.43 raeburn 6726: foreach my $item (@contexts) {
1.34 raeburn 6727: push(@{$changes{'cancreate'}},$item);
6728: }
1.27 raeburn 6729: }
1.34 raeburn 6730:
1.27 raeburn 6731: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6732: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6733: if (!grep(/^\Q$type\E$/,@username_rule)) {
6734: push(@{$changes{'username_rule'}},$type);
6735: }
6736: }
6737: foreach my $type (@username_rule) {
6738: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6739: push(@{$changes{'username_rule'}},$type);
6740: }
6741: }
6742: } else {
6743: push(@{$changes{'username_rule'}},@username_rule);
6744: }
6745:
1.32 raeburn 6746: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6747: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6748: if (!grep(/^\Q$type\E$/,@id_rule)) {
6749: push(@{$changes{'id_rule'}},$type);
6750: }
6751: }
6752: foreach my $type (@id_rule) {
6753: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6754: push(@{$changes{'id_rule'}},$type);
6755: }
6756: }
6757: } else {
6758: push(@{$changes{'id_rule'}},@id_rule);
6759: }
6760:
1.43 raeburn 6761: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6762: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6763: if (!grep(/^\Q$type\E$/,@email_rule)) {
6764: push(@{$changes{'email_rule'}},$type);
6765: }
6766: }
6767: foreach my $type (@email_rule) {
6768: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6769: push(@{$changes{'email_rule'}},$type);
6770: }
6771: }
6772: } else {
6773: push(@{$changes{'email_rule'}},@email_rule);
6774: }
6775:
6776: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6777: my @authtypes = ('int','krb4','krb5','loc');
6778: my %authhash;
1.43 raeburn 6779: foreach my $item (@authen_contexts) {
1.28 raeburn 6780: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6781: foreach my $auth (@authtypes) {
6782: if (grep(/^\Q$auth\E$/,@authallowed)) {
6783: $authhash{$item}{$auth} = 1;
6784: } else {
6785: $authhash{$item}{$auth} = 0;
6786: }
6787: }
6788: }
6789: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6790: foreach my $item (@authen_contexts) {
1.28 raeburn 6791: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6792: foreach my $auth (@authtypes) {
6793: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6794: push(@{$changes{'authtypes'}},$item);
6795: last;
6796: }
6797: }
6798: }
6799: }
6800: } else {
1.43 raeburn 6801: foreach my $item (@authen_contexts) {
1.28 raeburn 6802: push(@{$changes{'authtypes'}},$item);
6803: }
6804: }
6805:
1.27 raeburn 6806: my %usercreation_hash = (
1.28 raeburn 6807: usercreation => {
1.34 raeburn 6808: cancreate => \%cancreate,
1.27 raeburn 6809: username_rule => \@username_rule,
1.32 raeburn 6810: id_rule => \@id_rule,
1.43 raeburn 6811: email_rule => \@email_rule,
1.32 raeburn 6812: authtypes => \%authhash,
1.27 raeburn 6813: }
6814: );
6815:
6816: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6817: $dom);
1.50 raeburn 6818:
6819: my %selfcreatetypes = (
6820: sso => 'users authenticated by institutional single sign on',
6821: login => 'users authenticated by institutional log-in',
6822: email => 'users who provide a valid e-mail address for use as the username',
6823: );
1.27 raeburn 6824: if ($putresult eq 'ok') {
6825: if (keys(%changes) > 0) {
6826: $resulttext = &mt('Changes made:').'<ul>';
6827: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6828: my %lt = &usercreation_types();
6829: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6830: my $chgtext;
1.160.6.5 raeburn 6831: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6832: $chgtext = $lt{$type}.', ';
6833: }
1.45 raeburn 6834: if ($type eq 'selfcreate') {
1.50 raeburn 6835: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6836: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6837: } else {
1.100 raeburn 6838: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6839: foreach my $case (@{$cancreate{$type}}) {
6840: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6841: }
6842: $chgtext .= '</ul>';
1.100 raeburn 6843: if (ref($cancreate{$type}) eq 'ARRAY') {
6844: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6845: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6846: if (@{$cancreate{'statustocreate'}} == 0) {
6847: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6848: }
6849: }
6850: }
6851: }
1.43 raeburn 6852: }
1.93 raeburn 6853: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6854: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6855: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6856: if (@{$cancreate{'selfcreate'}} > 0) {
6857: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6858:
6859: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6860: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6861: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6862: }
1.96 raeburn 6863: } elsif (ref($usertypes) eq 'HASH') {
6864: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6865: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6866: } else {
6867: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6868: }
6869: $chgtext .= '<ul>';
6870: foreach my $case (@{$cancreate{$type}}) {
6871: if ($case eq 'default') {
6872: $chgtext .= '<li>'.$othertitle.'</li>';
6873: } else {
6874: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6875: }
6876: }
1.100 raeburn 6877: $chgtext .= '</ul>';
6878: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6879: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6880: }
6881: }
6882: } else {
6883: if (@{$cancreate{$type}} == 0) {
6884: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6885: } else {
6886: $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 6887: }
6888: }
6889: }
1.160.6.5 raeburn 6890: } elsif ($type eq 'captcha') {
6891: if ($cancreate{$type} eq 'notused') {
6892: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6893: } else {
6894: my %captchas = &captcha_phrases();
6895: if ($captchas{$cancreate{$type}}) {
6896: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6897: } else {
6898: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6899: }
6900: }
6901: } elsif ($type eq 'recaptchakeys') {
6902: my ($privkey,$pubkey);
6903: if (ref($cancreate{$type}) eq 'HASH') {
6904: $pubkey = $cancreate{$type}{'public'};
6905: $privkey = $cancreate{$type}{'private'};
6906: }
6907: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6908: if (!$pubkey) {
6909: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6910: } else {
6911: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6912: }
6913: if (!$privkey) {
6914: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6915: } else {
6916: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6917: }
6918: $chgtext .= '</ul>';
1.43 raeburn 6919: } else {
6920: if ($cancreate{$type} eq 'none') {
6921: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6922: } elsif ($cancreate{$type} eq 'any') {
6923: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6924: } elsif ($cancreate{$type} eq 'official') {
6925: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6926: } elsif ($cancreate{$type} eq 'unofficial') {
6927: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6928: }
1.34 raeburn 6929: }
6930: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6931: }
6932: }
6933: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6934: my ($rules,$ruleorder) =
6935: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6936: my $chgtext = '<ul>';
6937: foreach my $type (@username_rule) {
6938: if (ref($rules->{$type}) eq 'HASH') {
6939: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6940: }
6941: }
6942: $chgtext .= '</ul>';
6943: if (@username_rule > 0) {
6944: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6945: } else {
1.28 raeburn 6946: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6947: }
6948: }
1.32 raeburn 6949: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6950: my ($idrules,$idruleorder) =
6951: &Apache::lonnet::inst_userrules($dom,'id');
6952: my $chgtext = '<ul>';
6953: foreach my $type (@id_rule) {
6954: if (ref($idrules->{$type}) eq 'HASH') {
6955: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6956: }
6957: }
6958: $chgtext .= '</ul>';
6959: if (@id_rule > 0) {
6960: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6961: } else {
6962: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6963: }
6964: }
1.43 raeburn 6965: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6966: my ($emailrules,$emailruleorder) =
6967: &Apache::lonnet::inst_userrules($dom,'email');
6968: my $chgtext = '<ul>';
6969: foreach my $type (@email_rule) {
6970: if (ref($emailrules->{$type}) eq 'HASH') {
6971: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6972: }
6973: }
6974: $chgtext .= '</ul>';
6975: if (@email_rule > 0) {
6976: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6977: } else {
6978: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6979: }
6980: }
6981:
1.28 raeburn 6982: my %authname = &authtype_names();
6983: my %context_title = &context_names();
6984: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6985: my $chgtext = '<ul>';
6986: foreach my $type (@{$changes{'authtypes'}}) {
6987: my @allowed;
6988: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6989: foreach my $auth (@authtypes) {
6990: if ($authhash{$type}{$auth}) {
6991: push(@allowed,$authname{$auth});
6992: }
6993: }
1.43 raeburn 6994: if (@allowed > 0) {
6995: $chgtext .= join(', ',@allowed).'</li>';
6996: } else {
6997: $chgtext .= &mt('none').'</li>';
6998: }
1.28 raeburn 6999: }
7000: $chgtext .= '</ul>';
7001: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7002: $resulttext .= '</li>';
7003: }
1.27 raeburn 7004: $resulttext .= '</ul>';
7005: } else {
1.28 raeburn 7006: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7007: }
7008: } else {
7009: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7010: &mt('An error occurred: [_1]',$putresult).'</span>';
7011: }
1.43 raeburn 7012: if ($warningmsg ne '') {
7013: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7014: }
1.23 raeburn 7015: return $resulttext;
7016: }
7017:
1.160.6.5 raeburn 7018: sub process_captcha {
7019: my ($container,$changes,$newsettings,$current) = @_;
7020: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7021: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7022: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7023: $newsettings->{'captcha'} = 'original';
7024: }
7025: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7026: if ($container eq 'cancreate') {
7027: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7028: push(@{$changes->{'cancreate'}},'captcha');
7029: } elsif (!defined($changes->{'cancreate'})) {
7030: $changes->{'cancreate'} = ['captcha'];
7031: }
7032: } else {
7033: $changes->{'captcha'} = 1;
7034: }
7035: }
7036: my ($newpub,$newpriv,$currpub,$currpriv);
7037: if ($newsettings->{'captcha'} eq 'recaptcha') {
7038: $newpub = $env{'form.'.$container.'_recaptchapub'};
7039: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7040: $newpub =~ s/\W//g;
7041: $newpriv =~ s/\W//g;
7042: $newsettings->{'recaptchakeys'} = {
7043: public => $newpub,
7044: private => $newpriv,
7045: };
7046: }
7047: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7048: $currpub = $current->{'recaptchakeys'}{'public'};
7049: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10! raeburn 7050: unless ($newsettings->{'captcha'} eq 'recaptcha') {
! 7051: $newsettings->{'recaptchakeys'} = {
! 7052: public => '',
! 7053: private => '',
! 7054: }
! 7055: }
1.160.6.5 raeburn 7056: }
7057: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7058: if ($container eq 'cancreate') {
7059: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7060: push(@{$changes->{'cancreate'}},'recaptchakeys');
7061: } elsif (!defined($changes->{'cancreate'})) {
7062: $changes->{'cancreate'} = ['recaptchakeys'];
7063: }
7064: } else {
7065: $changes->{'recaptchakeys'} = 1;
7066: }
7067: }
7068: return;
7069: }
7070:
1.33 raeburn 7071: sub modify_usermodification {
7072: my ($dom,%domconfig) = @_;
7073: my ($resulttext,%curr_usermodification,%changes);
7074: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7075: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7076: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7077: }
7078: }
1.63 raeburn 7079: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7080: my %context_title = (
7081: author => 'In author context',
7082: course => 'In course context',
1.63 raeburn 7083: selfcreate => 'When self creating account',
1.33 raeburn 7084: );
7085: my @fields = ('lastname','firstname','middlename','generation',
7086: 'permanentemail','id');
7087: my %roles = (
7088: author => ['ca','aa'],
7089: course => ['st','ep','ta','in','cr'],
7090: );
1.63 raeburn 7091: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7092: if (ref($types) eq 'ARRAY') {
7093: push(@{$types},'default');
7094: $usertypes->{'default'} = $othertitle;
7095: }
7096: $roles{'selfcreate'} = $types;
1.33 raeburn 7097: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7098: my %modifyhash;
7099: foreach my $context (@contexts) {
7100: foreach my $role (@{$roles{$context}}) {
7101: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7102: foreach my $item (@fields) {
7103: if (grep(/^\Q$item\E$/,@modifiable)) {
7104: $modifyhash{$context}{$role}{$item} = 1;
7105: } else {
7106: $modifyhash{$context}{$role}{$item} = 0;
7107: }
7108: }
7109: }
7110: if (ref($curr_usermodification{$context}) eq 'HASH') {
7111: foreach my $role (@{$roles{$context}}) {
7112: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7113: foreach my $field (@fields) {
7114: if ($modifyhash{$context}{$role}{$field} ne
7115: $curr_usermodification{$context}{$role}{$field}) {
7116: push(@{$changes{$context}},$role);
7117: last;
7118: }
7119: }
7120: }
7121: }
7122: } else {
7123: foreach my $context (@contexts) {
7124: foreach my $role (@{$roles{$context}}) {
7125: push(@{$changes{$context}},$role);
7126: }
7127: }
7128: }
7129: }
7130: my %usermodification_hash = (
7131: usermodification => \%modifyhash,
7132: );
7133: my $putresult = &Apache::lonnet::put_dom('configuration',
7134: \%usermodification_hash,$dom);
7135: if ($putresult eq 'ok') {
7136: if (keys(%changes) > 0) {
7137: $resulttext = &mt('Changes made: ').'<ul>';
7138: foreach my $context (@contexts) {
7139: if (ref($changes{$context}) eq 'ARRAY') {
7140: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7141: if (ref($changes{$context}) eq 'ARRAY') {
7142: foreach my $role (@{$changes{$context}}) {
7143: my $rolename;
1.63 raeburn 7144: if ($context eq 'selfcreate') {
7145: $rolename = $role;
7146: if (ref($usertypes) eq 'HASH') {
7147: if ($usertypes->{$role} ne '') {
7148: $rolename = $usertypes->{$role};
7149: }
7150: }
1.33 raeburn 7151: } else {
1.63 raeburn 7152: if ($role eq 'cr') {
7153: $rolename = &mt('Custom');
7154: } else {
7155: $rolename = &Apache::lonnet::plaintext($role);
7156: }
1.33 raeburn 7157: }
7158: my @modifiable;
1.63 raeburn 7159: if ($context eq 'selfcreate') {
1.126 bisitz 7160: $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 7161: } else {
7162: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7163: }
1.33 raeburn 7164: foreach my $field (@fields) {
7165: if ($modifyhash{$context}{$role}{$field}) {
7166: push(@modifiable,$fieldtitles{$field});
7167: }
7168: }
7169: if (@modifiable > 0) {
7170: $resulttext .= join(', ',@modifiable);
7171: } else {
7172: $resulttext .= &mt('none');
7173: }
7174: $resulttext .= '</li>';
7175: }
7176: $resulttext .= '</ul></li>';
7177: }
7178: }
7179: }
7180: $resulttext .= '</ul>';
7181: } else {
7182: $resulttext = &mt('No changes made to user modification settings');
7183: }
7184: } else {
7185: $resulttext = '<span class="LC_error">'.
7186: &mt('An error occurred: [_1]',$putresult).'</span>';
7187: }
7188: return $resulttext;
7189: }
7190:
1.43 raeburn 7191: sub modify_defaults {
7192: my ($dom,$r) = @_;
7193: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7194: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7195: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7196: my @authtypes = ('internal','krb4','krb5','localauth');
7197: foreach my $item (@items) {
7198: $newvalues{$item} = $env{'form.'.$item};
7199: if ($item eq 'auth_def') {
7200: if ($newvalues{$item} ne '') {
7201: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7202: push(@errors,$item);
7203: }
7204: }
7205: } elsif ($item eq 'lang_def') {
7206: if ($newvalues{$item} ne '') {
7207: if ($newvalues{$item} =~ /^(\w+)/) {
7208: my $langcode = $1;
1.103 raeburn 7209: if ($langcode ne 'x_chef') {
7210: if (code2language($langcode) eq '') {
7211: push(@errors,$item);
7212: }
1.43 raeburn 7213: }
7214: } else {
7215: push(@errors,$item);
7216: }
7217: }
1.54 raeburn 7218: } elsif ($item eq 'timezone_def') {
7219: if ($newvalues{$item} ne '') {
1.62 raeburn 7220: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7221: push(@errors,$item);
7222: }
7223: }
1.68 raeburn 7224: } elsif ($item eq 'datelocale_def') {
7225: if ($newvalues{$item} ne '') {
7226: my @datelocale_ids = DateTime::Locale->ids();
7227: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7228: push(@errors,$item);
7229: }
7230: }
1.141 raeburn 7231: } elsif ($item eq 'portal_def') {
7232: if ($newvalues{$item} ne '') {
7233: 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])\/?$/) {
7234: push(@errors,$item);
7235: }
7236: }
1.43 raeburn 7237: }
7238: if (grep(/^\Q$item\E$/,@errors)) {
7239: $newvalues{$item} = $domdefaults{$item};
7240: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7241: $changes{$item} = 1;
7242: }
1.72 raeburn 7243: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7244: }
7245: my %defaults_hash = (
1.72 raeburn 7246: defaults => \%newvalues,
7247: );
1.43 raeburn 7248: my $title = &defaults_titles();
7249: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7250: $dom);
7251: if ($putresult eq 'ok') {
7252: if (keys(%changes) > 0) {
7253: $resulttext = &mt('Changes made:').'<ul>';
7254: my $version = $r->dir_config('lonVersion');
7255: 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";
7256: foreach my $item (sort(keys(%changes))) {
7257: my $value = $env{'form.'.$item};
7258: if ($value eq '') {
7259: $value = &mt('none');
7260: } elsif ($item eq 'auth_def') {
7261: my %authnames = &authtype_names();
7262: my %shortauth = (
7263: internal => 'int',
7264: krb4 => 'krb4',
7265: krb5 => 'krb5',
7266: localauth => 'loc',
7267: );
7268: $value = $authnames{$shortauth{$value}};
7269: }
7270: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7271: $mailmsgtext .= "$title->{$item} set to $value\n";
7272: }
7273: $resulttext .= '</ul>';
7274: $mailmsgtext .= "\n";
7275: my $cachetime = 24*60*60;
1.72 raeburn 7276: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7277: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7278: my $sysmail = $r->dir_config('lonSysEMail');
7279: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7280: }
1.43 raeburn 7281: } else {
1.54 raeburn 7282: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7283: }
7284: } else {
7285: $resulttext = '<span class="LC_error">'.
7286: &mt('An error occurred: [_1]',$putresult).'</span>';
7287: }
7288: if (@errors > 0) {
7289: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7290: foreach my $item (@errors) {
7291: $resulttext .= ' "'.$title->{$item}.'",';
7292: }
7293: $resulttext =~ s/,$//;
7294: }
7295: return $resulttext;
7296: }
7297:
1.46 raeburn 7298: sub modify_scantron {
1.48 raeburn 7299: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7300: my ($resulttext,%confhash,%changes,$errors);
7301: my $custom = 'custom.tab';
7302: my $default = 'default.tab';
7303: my $servadm = $r->dir_config('lonAdmEMail');
7304: my ($configuserok,$author_ok,$switchserver) =
7305: &config_check($dom,$confname,$servadm);
7306: if ($env{'form.scantronformat.filename'} ne '') {
7307: my $error;
7308: if ($configuserok eq 'ok') {
7309: if ($switchserver) {
1.130 raeburn 7310: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7311: } else {
7312: if ($author_ok eq 'ok') {
7313: my ($result,$scantronurl) =
7314: &publishlogo($r,'upload','scantronformat',$dom,
7315: $confname,'scantron','','',$custom);
7316: if ($result eq 'ok') {
7317: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7318: $changes{'scantronformat'} = 1;
1.46 raeburn 7319: } else {
7320: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7321: }
7322: } else {
7323: $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);
7324: }
7325: }
7326: } else {
7327: $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);
7328: }
7329: if ($error) {
7330: &Apache::lonnet::logthis($error);
7331: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7332: }
7333: }
1.48 raeburn 7334: if (ref($domconfig{'scantron'}) eq 'HASH') {
7335: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7336: if ($env{'form.scantronformat_del'}) {
7337: $confhash{'scantron'}{'scantronformat'} = '';
7338: $changes{'scantronformat'} = 1;
1.46 raeburn 7339: }
7340: }
7341: }
7342: if (keys(%confhash) > 0) {
7343: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7344: $dom);
7345: if ($putresult eq 'ok') {
7346: if (keys(%changes) > 0) {
1.48 raeburn 7347: if (ref($confhash{'scantron'}) eq 'HASH') {
7348: $resulttext = &mt('Changes made:').'<ul>';
7349: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7350: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7351: } else {
1.130 raeburn 7352: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7353: }
1.48 raeburn 7354: $resulttext .= '</ul>';
7355: } else {
1.130 raeburn 7356: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7357: }
7358: $resulttext .= '</ul>';
7359: &Apache::loncommon::devalidate_domconfig_cache($dom);
7360: } else {
1.130 raeburn 7361: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7362: }
7363: } else {
7364: $resulttext = '<span class="LC_error">'.
7365: &mt('An error occurred: [_1]',$putresult).'</span>';
7366: }
7367: } else {
1.130 raeburn 7368: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7369: }
7370: if ($errors) {
7371: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7372: $errors.'</ul>';
7373: }
7374: return $resulttext;
7375: }
7376:
1.48 raeburn 7377: sub modify_coursecategories {
7378: my ($dom,%domconfig) = @_;
1.57 raeburn 7379: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7380: $cathash);
1.48 raeburn 7381: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7382: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7383: $cathash = $domconfig{'coursecategories'}{'cats'};
7384: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7385: $changes{'togglecats'} = 1;
7386: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7387: }
7388: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7389: $changes{'categorize'} = 1;
7390: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7391: }
1.120 raeburn 7392: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7393: $changes{'togglecatscomm'} = 1;
7394: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7395: }
7396: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7397: $changes{'categorizecomm'} = 1;
7398: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7399: }
1.57 raeburn 7400: } else {
7401: $changes{'togglecats'} = 1;
7402: $changes{'categorize'} = 1;
1.124 raeburn 7403: $changes{'togglecatscomm'} = 1;
7404: $changes{'categorizecomm'} = 1;
1.87 raeburn 7405: $domconfig{'coursecategories'} = {
7406: togglecats => $env{'form.togglecats'},
7407: categorize => $env{'form.categorize'},
1.124 raeburn 7408: togglecatscomm => $env{'form.togglecatscomm'},
7409: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7410: };
1.57 raeburn 7411: }
7412: if (ref($cathash) eq 'HASH') {
7413: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7414: push (@deletecategory,'instcode::0');
7415: }
1.120 raeburn 7416: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7417: push(@deletecategory,'communities::0');
7418: }
1.48 raeburn 7419: }
1.57 raeburn 7420: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7421: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7422: if (@deletecategory > 0) {
7423: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7424: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7425: foreach my $item (@deletecategory) {
1.57 raeburn 7426: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7427: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7428: $deletions{$item} = 1;
1.57 raeburn 7429: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7430: }
7431: }
7432: }
1.57 raeburn 7433: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7434: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7435: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7436: $reorderings{$item} = 1;
1.57 raeburn 7437: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7438: }
7439: if ($env{'form.addcategory_name_'.$item} ne '') {
7440: my $newcat = $env{'form.addcategory_name_'.$item};
7441: my $newdepth = $depth+1;
7442: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7443: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7444: $adds{$newitem} = 1;
7445: }
7446: if ($env{'form.subcat_'.$item} ne '') {
7447: my $newcat = $env{'form.subcat_'.$item};
7448: my $newdepth = $depth+1;
7449: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7450: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7451: $adds{$newitem} = 1;
7452: }
7453: }
7454: }
7455: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7456: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7457: my $newitem = 'instcode::0';
1.57 raeburn 7458: if ($cathash->{$newitem} eq '') {
7459: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7460: $adds{$newitem} = 1;
7461: }
7462: } else {
7463: my $newitem = 'instcode::0';
1.57 raeburn 7464: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7465: $adds{$newitem} = 1;
7466: }
7467: }
1.120 raeburn 7468: if ($env{'form.communities'} eq '1') {
7469: if (ref($cathash) eq 'HASH') {
7470: my $newitem = 'communities::0';
7471: if ($cathash->{$newitem} eq '') {
7472: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7473: $adds{$newitem} = 1;
7474: }
7475: } else {
7476: my $newitem = 'communities::0';
7477: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7478: $adds{$newitem} = 1;
7479: }
7480: }
1.48 raeburn 7481: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7482: if (($env{'form.addcategory_name'} ne 'instcode') &&
7483: ($env{'form.addcategory_name'} ne 'communities')) {
7484: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7485: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7486: $adds{$newitem} = 1;
7487: }
1.48 raeburn 7488: }
1.57 raeburn 7489: my $putresult;
1.48 raeburn 7490: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7491: if (keys(%deletions) > 0) {
7492: foreach my $key (keys(%deletions)) {
7493: if ($predelallitems{$key} ne '') {
7494: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7495: }
7496: }
7497: }
7498: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7499: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7500: if (ref($chkcats[0]) eq 'ARRAY') {
7501: my $depth = 0;
7502: my $chg = 0;
7503: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7504: my $name = $chkcats[0][$i];
7505: my $item;
7506: if ($name eq '') {
7507: $chg ++;
7508: } else {
7509: $item = &escape($name).'::0';
7510: if ($chg) {
1.57 raeburn 7511: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7512: }
7513: $depth ++;
1.57 raeburn 7514: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7515: $depth --;
7516: }
7517: }
7518: }
1.57 raeburn 7519: }
7520: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7521: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7522: if ($putresult eq 'ok') {
1.57 raeburn 7523: my %title = (
1.120 raeburn 7524: togglecats => 'Show/Hide a course in catalog',
7525: categorize => 'Assign a category to a course',
7526: togglecatscomm => 'Show/Hide a community in catalog',
7527: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7528: );
7529: my %level = (
1.120 raeburn 7530: dom => 'set in Domain ("Modify Course/Community")',
7531: crs => 'set in Course ("Course Configuration")',
7532: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7533: );
1.48 raeburn 7534: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7535: if ($changes{'togglecats'}) {
7536: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7537: }
7538: if ($changes{'categorize'}) {
7539: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7540: }
1.120 raeburn 7541: if ($changes{'togglecatscomm'}) {
7542: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7543: }
7544: if ($changes{'categorizecomm'}) {
7545: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7546: }
1.57 raeburn 7547: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7548: my $cathash;
7549: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7550: $cathash = $domconfig{'coursecategories'}{'cats'};
7551: } else {
7552: $cathash = {};
7553: }
7554: my (@cats,@trails,%allitems);
7555: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7556: if (keys(%deletions) > 0) {
7557: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7558: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7559: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7560: }
7561: $resulttext .= '</ul></li>';
7562: }
7563: if (keys(%reorderings) > 0) {
7564: my %sort_by_trail;
7565: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7566: foreach my $key (keys(%reorderings)) {
7567: if ($allitems{$key} ne '') {
7568: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7569: }
1.48 raeburn 7570: }
1.57 raeburn 7571: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7572: $resulttext .= '<li>'.$trails[$trail].'</li>';
7573: }
7574: $resulttext .= '</ul></li>';
1.48 raeburn 7575: }
1.57 raeburn 7576: if (keys(%adds) > 0) {
7577: my %sort_by_trail;
7578: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7579: foreach my $key (keys(%adds)) {
7580: if ($allitems{$key} ne '') {
7581: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7582: }
7583: }
7584: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7585: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7586: }
1.57 raeburn 7587: $resulttext .= '</ul></li>';
1.48 raeburn 7588: }
7589: }
7590: $resulttext .= '</ul>';
7591: } else {
7592: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7593: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7594: }
7595: } else {
1.120 raeburn 7596: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7597: }
7598: return $resulttext;
7599: }
7600:
1.69 raeburn 7601: sub modify_serverstatuses {
7602: my ($dom,%domconfig) = @_;
7603: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7604: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7605: %currserverstatus = %{$domconfig{'serverstatuses'}};
7606: }
7607: my @pages = &serverstatus_pages();
7608: foreach my $type (@pages) {
7609: $newserverstatus{$type}{'namedusers'} = '';
7610: $newserverstatus{$type}{'machines'} = '';
7611: if (defined($env{'form.'.$type.'_namedusers'})) {
7612: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7613: my @okusers;
7614: foreach my $user (@users) {
7615: my ($uname,$udom) = split(/:/,$user);
7616: if (($udom =~ /^$match_domain$/) &&
7617: (&Apache::lonnet::domain($udom)) &&
7618: ($uname =~ /^$match_username$/)) {
7619: if (!grep(/^\Q$user\E/,@okusers)) {
7620: push(@okusers,$user);
7621: }
7622: }
7623: }
7624: if (@okusers > 0) {
7625: @okusers = sort(@okusers);
7626: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7627: }
7628: }
7629: if (defined($env{'form.'.$type.'_machines'})) {
7630: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7631: my @okmachines;
7632: foreach my $ip (@machines) {
7633: my @parts = split(/\./,$ip);
7634: next if (@parts < 4);
7635: my $badip = 0;
7636: for (my $i=0; $i<4; $i++) {
7637: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7638: $badip = 1;
7639: last;
7640: }
7641: }
7642: if (!$badip) {
7643: push(@okmachines,$ip);
7644: }
7645: }
7646: @okmachines = sort(@okmachines);
7647: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7648: }
7649: }
7650: my %serverstatushash = (
7651: serverstatuses => \%newserverstatus,
7652: );
7653: foreach my $type (@pages) {
1.83 raeburn 7654: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7655: my (@current,@new);
1.83 raeburn 7656: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7657: if ($currserverstatus{$type}{$setting} ne '') {
7658: @current = split(/,/,$currserverstatus{$type}{$setting});
7659: }
7660: }
7661: if ($newserverstatus{$type}{$setting} ne '') {
7662: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7663: }
7664: if (@current > 0) {
7665: if (@new > 0) {
7666: foreach my $item (@current) {
7667: if (!grep(/^\Q$item\E$/,@new)) {
7668: $changes{$type}{$setting} = 1;
1.82 raeburn 7669: last;
7670: }
7671: }
1.84 raeburn 7672: foreach my $item (@new) {
7673: if (!grep(/^\Q$item\E$/,@current)) {
7674: $changes{$type}{$setting} = 1;
7675: last;
1.82 raeburn 7676: }
7677: }
7678: } else {
1.83 raeburn 7679: $changes{$type}{$setting} = 1;
1.69 raeburn 7680: }
1.83 raeburn 7681: } elsif (@new > 0) {
7682: $changes{$type}{$setting} = 1;
1.69 raeburn 7683: }
7684: }
7685: }
7686: if (keys(%changes) > 0) {
1.81 raeburn 7687: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7688: my $putresult = &Apache::lonnet::put_dom('configuration',
7689: \%serverstatushash,$dom);
7690: if ($putresult eq 'ok') {
7691: $resulttext .= &mt('Changes made:').'<ul>';
7692: foreach my $type (@pages) {
1.84 raeburn 7693: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7694: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7695: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7696: if ($newserverstatus{$type}{'namedusers'} eq '') {
7697: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7698: } else {
7699: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7700: }
1.84 raeburn 7701: }
7702: if ($changes{$type}{'machines'}) {
1.69 raeburn 7703: if ($newserverstatus{$type}{'machines'} eq '') {
7704: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7705: } else {
7706: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7707: }
7708:
7709: }
7710: $resulttext .= '</ul></li>';
7711: }
7712: }
7713: $resulttext .= '</ul>';
7714: } else {
7715: $resulttext = '<span class="LC_error">'.
7716: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7717:
7718: }
7719: } else {
7720: $resulttext = &mt('No changes made to access to server status pages');
7721: }
7722: return $resulttext;
7723: }
7724:
1.118 jms 7725: sub modify_helpsettings {
1.122 jms 7726: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7727: my ($resulttext,$errors,%changes,%helphash);
7728: my %defaultchecked = ('submitbugs' => 'on');
7729: my @offon = ('off','on');
1.118 jms 7730: my @toggles = ('submitbugs');
7731: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7732: foreach my $item (@toggles) {
1.160.6.5 raeburn 7733: if ($defaultchecked{$item} eq 'on') {
7734: if ($domconfig{'helpsettings'}{$item} eq '') {
7735: if ($env{'form.'.$item} eq '0') {
7736: $changes{$item} = 1;
7737: }
7738: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7739: $changes{$item} = 1;
7740: }
7741: } elsif ($defaultchecked{$item} eq 'off') {
7742: if ($domconfig{'helpsettings'}{$item} eq '') {
7743: if ($env{'form.'.$item} eq '1') {
7744: $changes{$item} = 1;
7745: }
7746: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7747: $changes{$item} = 1;
7748: }
7749: }
7750: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7751: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7752: }
7753: }
1.118 jms 7754: }
1.123 jms 7755: my $putresult;
7756: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7757: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7758: if ($putresult eq 'ok') {
7759: $resulttext = &mt('Changes made:').'<ul>';
7760: foreach my $item (sort(keys(%changes))) {
7761: if ($item eq 'submitbugs') {
7762: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7763: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7764: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7765: }
7766: }
7767: $resulttext .= '</ul>';
7768: } else {
7769: $resulttext = &mt('No changes made to help settings');
7770: $errors .= '<li><span class="LC_error">'.
7771: &mt('An error occurred storing the settings: [_1]',
7772: $putresult).'</span></li>';
7773: }
1.118 jms 7774: }
7775: if ($errors) {
1.160.6.5 raeburn 7776: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7777: $errors.'</ul>';
7778: }
7779: return $resulttext;
7780: }
7781:
1.121 raeburn 7782: sub modify_coursedefaults {
7783: my ($dom,%domconfig) = @_;
7784: my ($resulttext,$errors,%changes,%defaultshash);
7785: my %defaultchecked = ('canuse_pdfforms' => 'off');
7786: my @offon = ('off','on');
7787: my @toggles = ('canuse_pdfforms');
7788:
7789: $defaultshash{'coursedefaults'} = {};
7790:
7791: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7792: if ($domconfig{'coursedefaults'} eq '') {
7793: $domconfig{'coursedefaults'} = {};
7794: }
7795: }
7796:
7797: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7798: foreach my $item (@toggles) {
7799: if ($defaultchecked{$item} eq 'on') {
7800: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7801: ($env{'form.'.$item} eq '0')) {
7802: $changes{$item} = 1;
7803: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7804: $changes{$item} = 1;
7805: }
7806: } elsif ($defaultchecked{$item} eq 'off') {
7807: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7808: ($env{'form.'.$item} eq '1')) {
7809: $changes{$item} = 1;
7810: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7811: $changes{$item} = 1;
7812: }
7813: }
7814: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7815: }
1.139 raeburn 7816: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7817: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7818: $newdefresponder =~ s/\D//g;
7819: if ($newdefresponder eq '' || $newdefresponder < 1) {
7820: $newdefresponder = 1;
7821: }
7822: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7823: if ($currdefresponder ne $newdefresponder) {
7824: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7825: $changes{'anonsurvey_threshold'} = 1;
7826: }
7827: }
1.121 raeburn 7828: }
7829: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7830: $dom);
7831: if ($putresult eq 'ok') {
7832: if (keys(%changes) > 0) {
7833: if ($changes{'canuse_pdfforms'}) {
7834: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7835: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7836: my $cachetime = 24*60*60;
7837: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7838: }
7839: $resulttext = &mt('Changes made:').'<ul>';
7840: foreach my $item (sort(keys(%changes))) {
7841: if ($item eq 'canuse_pdfforms') {
7842: if ($env{'form.'.$item} eq '1') {
7843: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7844: } else {
7845: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7846: }
1.139 raeburn 7847: } elsif ($item eq 'anonsurvey_threshold') {
7848: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7849: }
1.121 raeburn 7850: }
7851: $resulttext .= '</ul>';
7852: } else {
7853: $resulttext = &mt('No changes made to course defaults');
7854: }
7855: } else {
7856: $resulttext = '<span class="LC_error">'.
7857: &mt('An error occurred: [_1]',$putresult).'</span>';
7858: }
7859: return $resulttext;
7860: }
7861:
1.137 raeburn 7862: sub modify_usersessions {
7863: my ($dom,%domconfig) = @_;
1.145 raeburn 7864: my @hostingtypes = ('version','excludedomain','includedomain');
7865: my @offloadtypes = ('primary','default');
7866: my %types = (
7867: remote => \@hostingtypes,
7868: hosted => \@hostingtypes,
7869: spares => \@offloadtypes,
7870: );
7871: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7872: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7873: my (%by_ip,%by_location,@intdoms);
7874: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7875: my @locations = sort(keys(%by_location));
1.137 raeburn 7876: my (%defaultshash,%changes);
7877: foreach my $prefix (@prefixes) {
7878: $defaultshash{'usersessions'}{$prefix} = {};
7879: }
7880: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7881: my $resulttext;
1.138 raeburn 7882: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7883: foreach my $prefix (@prefixes) {
1.145 raeburn 7884: next if ($prefix eq 'spares');
7885: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7886: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7887: if ($type eq 'version') {
7888: my $value = $env{'form.'.$prefix.'_'.$type};
7889: my $okvalue;
7890: if ($value ne '') {
7891: if (grep(/^\Q$value\E$/,@lcversions)) {
7892: $okvalue = $value;
7893: }
7894: }
7895: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7896: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7897: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7898: if ($inuse == 0) {
7899: $changes{$prefix}{$type} = 1;
7900: } else {
7901: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7902: $changes{$prefix}{$type} = 1;
7903: }
7904: if ($okvalue ne '') {
7905: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7906: }
7907: }
7908: } else {
7909: if (($inuse == 1) && ($okvalue ne '')) {
7910: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7911: $changes{$prefix}{$type} = 1;
7912: }
7913: }
7914: } else {
7915: if (($inuse == 1) && ($okvalue ne '')) {
7916: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7917: $changes{$prefix}{$type} = 1;
7918: }
7919: }
7920: } else {
7921: if (($inuse == 1) && ($okvalue ne '')) {
7922: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7923: $changes{$prefix}{$type} = 1;
7924: }
7925: }
7926: } else {
7927: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7928: my @okvals;
7929: foreach my $val (@vals) {
1.138 raeburn 7930: if ($val =~ /:/) {
7931: my @items = split(/:/,$val);
7932: foreach my $item (@items) {
7933: if (ref($by_location{$item}) eq 'ARRAY') {
7934: push(@okvals,$item);
7935: }
7936: }
7937: } else {
7938: if (ref($by_location{$val}) eq 'ARRAY') {
7939: push(@okvals,$val);
7940: }
1.137 raeburn 7941: }
7942: }
7943: @okvals = sort(@okvals);
7944: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7945: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7946: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7947: if ($inuse == 0) {
7948: $changes{$prefix}{$type} = 1;
7949: } else {
7950: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7951: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7952: if (@changed > 0) {
7953: $changes{$prefix}{$type} = 1;
7954: }
7955: }
7956: } else {
7957: if ($inuse == 1) {
7958: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7959: $changes{$prefix}{$type} = 1;
7960: }
7961: }
7962: } else {
7963: if ($inuse == 1) {
7964: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7965: $changes{$prefix}{$type} = 1;
7966: }
7967: }
7968: } else {
7969: if ($inuse == 1) {
7970: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7971: $changes{$prefix}{$type} = 1;
7972: }
7973: }
7974: }
7975: }
7976: }
1.145 raeburn 7977:
7978: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7979: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7980: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7981: my $savespares;
7982:
7983: foreach my $lonhost (sort(keys(%servers))) {
7984: my $serverhomeID =
7985: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 7986: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7987: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7988: my %spareschg;
7989: foreach my $type (@{$types{'spares'}}) {
7990: my @okspares;
7991: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7992: foreach my $server (@checked) {
1.152 raeburn 7993: if (&Apache::lonnet::hostname($server) ne '') {
7994: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7995: unless (grep(/^\Q$server\E$/,@okspares)) {
7996: push(@okspares,$server);
7997: }
1.145 raeburn 7998: }
7999: }
8000: }
8001: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8002: my $newspare;
1.152 raeburn 8003: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8004: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8005: $newspare = $new;
8006: }
8007: }
1.152 raeburn 8008: my @spares;
8009: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8010: @spares = sort(@okspares,$newspare);
8011: } else {
8012: @spares = sort(@okspares);
8013: }
8014: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8015: if (ref($spareid{$lonhost}) eq 'HASH') {
8016: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8017: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8018: if (@diffs > 0) {
8019: $spareschg{$type} = 1;
8020: }
8021: }
8022: }
8023: }
8024: if (keys(%spareschg) > 0) {
8025: $changes{'spares'}{$lonhost} = \%spareschg;
8026: }
8027: }
8028:
8029: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8030: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8031: if (ref($changes{'spares'}) eq 'HASH') {
8032: if (keys(%{$changes{'spares'}}) > 0) {
8033: $savespares = 1;
8034: }
8035: }
8036: } else {
8037: $savespares = 1;
8038: }
8039: }
8040:
1.147 raeburn 8041: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8042: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8043: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8044: $dom);
8045: if ($putresult eq 'ok') {
8046: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8047: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8048: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8049: }
8050: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8051: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8052: }
8053: }
8054: my $cachetime = 24*60*60;
8055: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8056: if (keys(%changes) > 0) {
8057: my %lt = &usersession_titles();
8058: $resulttext = &mt('Changes made:').'<ul>';
8059: foreach my $prefix (@prefixes) {
8060: if (ref($changes{$prefix}) eq 'HASH') {
8061: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8062: if ($prefix eq 'spares') {
8063: if (ref($changes{$prefix}) eq 'HASH') {
8064: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8065: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8066: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8067: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8068: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8069: foreach my $type (@{$types{$prefix}}) {
8070: if ($changes{$prefix}{$lonhost}{$type}) {
8071: my $offloadto = &mt('None');
8072: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8073: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8074: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8075: }
1.145 raeburn 8076: }
1.147 raeburn 8077: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8078: }
1.137 raeburn 8079: }
8080: }
1.147 raeburn 8081: $resulttext .= '</li>';
1.137 raeburn 8082: }
8083: }
1.147 raeburn 8084: } else {
8085: foreach my $type (@{$types{$prefix}}) {
8086: if (defined($changes{$prefix}{$type})) {
8087: my $newvalue;
8088: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8089: if (ref($defaultshash{'usersessions'}{$prefix})) {
8090: if ($type eq 'version') {
8091: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8092: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8093: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8094: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8095: }
1.145 raeburn 8096: }
8097: }
8098: }
1.147 raeburn 8099: if ($newvalue eq '') {
8100: if ($type eq 'version') {
8101: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8102: } else {
8103: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8104: }
1.145 raeburn 8105: } else {
1.147 raeburn 8106: if ($type eq 'version') {
8107: $newvalue .= ' '.&mt('(or later)');
8108: }
8109: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8110: }
1.137 raeburn 8111: }
8112: }
8113: }
1.147 raeburn 8114: $resulttext .= '</ul>';
1.137 raeburn 8115: }
8116: }
1.147 raeburn 8117: $resulttext .= '</ul>';
8118: } else {
8119: $resulttext = $nochgmsg;
1.137 raeburn 8120: }
8121: } else {
8122: $resulttext = '<span class="LC_error">'.
8123: &mt('An error occurred: [_1]',$putresult).'</span>';
8124: }
8125: } else {
1.147 raeburn 8126: $resulttext = $nochgmsg;
1.137 raeburn 8127: }
8128: return $resulttext;
8129: }
8130:
1.150 raeburn 8131: sub modify_loadbalancing {
8132: my ($dom,%domconfig) = @_;
8133: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8134: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8135: my ($othertitle,$usertypes,$types) =
8136: &Apache::loncommon::sorted_inst_types($dom);
8137: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8138: my @sparestypes = ('primary','default');
8139: my %typetitles = &sparestype_titles();
8140: my $resulttext;
1.160.6.7 raeburn 8141: my (%currbalancer,%currtargets,%currrules,%existing);
8142: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8143: %existing = %{$domconfig{'loadbalancing'}};
8144: }
8145: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8146: \%currtargets,\%currrules);
8147: my ($saveloadbalancing,%defaultshash,%changes);
8148: my ($alltypes,$othertypes,$titles) =
8149: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8150: my %ruletitles = &offloadtype_text();
8151: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8152: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8153: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8154: if ($balancer eq '') {
8155: next;
8156: }
8157: if (!exists($servers{$balancer})) {
8158: if (exists($currbalancer{$balancer})) {
8159: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8160: }
1.160.6.7 raeburn 8161: next;
8162: }
8163: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8164: push(@{$changes{'delete'}},$balancer);
8165: next;
8166: }
8167: if (!exists($currbalancer{$balancer})) {
8168: push(@{$changes{'add'}},$balancer);
8169: }
8170: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8171: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8172: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8173: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8174: $saveloadbalancing = 1;
8175: }
8176: foreach my $sparetype (@sparestypes) {
8177: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8178: my @offloadto;
8179: foreach my $target (@targets) {
8180: if (($servers{$target}) && ($target ne $balancer)) {
8181: if ($sparetype eq 'default') {
8182: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8183: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8184: }
8185: }
1.160.6.7 raeburn 8186: unless(grep(/^\Q$target\E$/,@offloadto)) {
8187: push(@offloadto,$target);
8188: }
1.150 raeburn 8189: }
1.160.6.7 raeburn 8190: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8191: }
8192: }
1.160.6.7 raeburn 8193: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8194: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8195: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8196: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8197: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8198: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8199: }
1.160.6.7 raeburn 8200: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8201: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8202: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8203: }
8204: }
8205: }
8206: } else {
1.160.6.7 raeburn 8207: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8208: foreach my $sparetype (@sparestypes) {
8209: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8210: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8211: $changes{'curr'}{$balancer}{'targets'} = 1;
8212: }
1.150 raeburn 8213: }
8214: }
1.160.6.7 raeburn 8215: }
1.150 raeburn 8216: }
8217: my $ishomedom;
1.160.6.7 raeburn 8218: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8219: $ishomedom = 1;
1.150 raeburn 8220: }
8221: if (ref($alltypes) eq 'ARRAY') {
8222: foreach my $type (@{$alltypes}) {
8223: my $rule;
1.160.6.7 raeburn 8224: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8225: (!$ishomedom)) {
1.160.6.7 raeburn 8226: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8227: }
8228: if ($rule eq 'specific') {
8229: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8230: }
1.160.6.7 raeburn 8231: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8232: if (ref($currrules{$balancer}) eq 'HASH') {
8233: if ($rule ne $currrules{$balancer}{$type}) {
8234: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8235: }
8236: } elsif ($rule ne '') {
1.160.6.7 raeburn 8237: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8238: }
8239: }
8240: }
1.160.6.7 raeburn 8241: }
8242: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8243: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8244: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8245: $defaultshash{'loadbalancing'} = {};
8246: }
8247: my $putresult = &Apache::lonnet::put_dom('configuration',
8248: \%defaultshash,$dom);
8249:
8250: if ($putresult eq 'ok') {
8251: if (keys(%changes) > 0) {
8252: if (ref($changes{'delete'}) eq 'ARRAY') {
8253: foreach my $balancer (sort(@{$changes{'delete'}})) {
8254: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8255: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8256: }
1.160.6.7 raeburn 8257: }
8258: if (ref($changes{'add'}) eq 'ARRAY') {
8259: foreach my $balancer (sort(@{$changes{'add'}})) {
8260: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8261: }
8262: }
8263: if (ref($changes{'curr'}) eq 'HASH') {
8264: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8265: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8266: if ($changes{'curr'}{$balancer}{'targets'}) {
8267: my %offloadstr;
8268: foreach my $sparetype (@sparestypes) {
8269: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8270: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8271: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8272: }
8273: }
1.150 raeburn 8274: }
1.160.6.7 raeburn 8275: if (keys(%offloadstr) == 0) {
8276: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8277: } else {
1.160.6.7 raeburn 8278: my $showoffload;
8279: foreach my $sparetype (@sparestypes) {
8280: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8281: if (defined($offloadstr{$sparetype})) {
8282: $showoffload .= $offloadstr{$sparetype};
8283: } else {
8284: $showoffload .= &mt('None');
8285: }
8286: $showoffload .= (' 'x3);
8287: }
8288: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8289: }
8290: }
8291: }
1.160.6.7 raeburn 8292: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8293: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8294: foreach my $type (@{$alltypes}) {
8295: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8296: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8297: my $balancetext;
8298: if ($rule eq '') {
8299: $balancetext = $ruletitles{'default'};
8300: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8301: $balancetext = $ruletitles{$rule};
8302: } else {
8303: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8304: }
8305: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8306: }
8307: }
8308: }
8309: }
1.160.6.7 raeburn 8310: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8311: }
1.160.6.7 raeburn 8312: }
8313: if ($resulttext ne '') {
8314: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8315: } else {
8316: $resulttext = $nochgmsg;
8317: }
8318: } else {
1.160.6.7 raeburn 8319: $resulttext = $nochgmsg;
1.150 raeburn 8320: }
8321: } else {
1.160.6.7 raeburn 8322: $resulttext = '<span class="LC_error">'.
8323: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8324: }
8325: } else {
1.160.6.7 raeburn 8326: $resulttext = $nochgmsg;
1.150 raeburn 8327: }
8328: return $resulttext;
8329: }
8330:
1.48 raeburn 8331: sub recurse_check {
8332: my ($chkcats,$categories,$depth,$name) = @_;
8333: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8334: my $chg = 0;
8335: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8336: my $category = $chkcats->[$depth]{$name}[$j];
8337: my $item;
8338: if ($category eq '') {
8339: $chg ++;
8340: } else {
8341: my $deeper = $depth + 1;
8342: $item = &escape($category).':'.&escape($name).':'.$depth;
8343: if ($chg) {
8344: $categories->{$item} -= $chg;
8345: }
8346: &recurse_check($chkcats,$categories,$deeper,$category);
8347: $deeper --;
8348: }
8349: }
8350: }
8351: return;
8352: }
8353:
8354: sub recurse_cat_deletes {
8355: my ($item,$coursecategories,$deletions) = @_;
8356: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8357: my $subdepth = $depth + 1;
8358: if (ref($coursecategories) eq 'HASH') {
8359: foreach my $subitem (keys(%{$coursecategories})) {
8360: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8361: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8362: delete($coursecategories->{$subitem});
8363: $deletions->{$subitem} = 1;
8364: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8365: }
8366: }
8367: }
8368: return;
8369: }
8370:
1.125 raeburn 8371: sub get_active_dcs {
8372: my ($dom) = @_;
8373: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8374: my %domcoords;
8375: my $numdcs = 0;
8376: my $now = time;
8377: foreach my $server (keys(%dompersonnel)) {
8378: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8379: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8380: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8381: if (($end eq '') || ($end == 0) || ($end > $now)) {
8382: if ($start <= $now) {
8383: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8384: }
8385: }
8386: }
8387: }
8388: return %domcoords;
8389: }
8390:
8391: sub active_dc_picker {
8392: my ($dom,$curr_dc) = @_;
8393: my %domcoords = &get_active_dcs($dom);
8394: my @dcs = sort(keys(%domcoords));
8395: my $numdcs = scalar(@dcs);
8396: my $datatable;
8397: my $numinrow = 2;
8398: if ($numdcs > 1) {
8399: $datatable = '<table>';
8400: for (my $i=0; $i<@dcs; $i++) {
8401: my $rem = $i%($numinrow);
8402: if ($rem == 0) {
8403: if ($i > 0) {
8404: $datatable .= '</tr>';
8405: }
8406: $datatable .= '<tr>';
8407: }
8408: my $check = ' ';
8409: if ($curr_dc eq '') {
8410: if (!$i) {
8411: $check = ' checked="checked" ';
8412: }
8413: } elsif ($dcs[$i] eq $curr_dc) {
8414: $check = ' checked="checked" ';
8415: }
8416: if ($i == @dcs - 1) {
8417: my $colsleft = $numinrow - $rem;
8418: if ($colsleft > 1) {
8419: $datatable .= '<td colspan="'.$colsleft.'">';
8420: } else {
8421: $datatable .= '<td>';
8422: }
8423: } else {
8424: $datatable .= '<td>';
8425: }
8426: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8427: $datatable .= '<span class="LC_nobreak"><label>'.
8428: '<input type="radio" name="autocreate_xmldc"'.
8429: ' value="'.$dcs[$i].'"'.$check.'/>'.
8430: &Apache::loncommon::plainname($dcname,$dcdom).
8431: '</label></span></td>';
8432: }
8433: $datatable .= '</tr></table>';
8434: } elsif (@dcs) {
8435: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8436: $dcs[0].'" />';
8437: }
8438: return ($numdcs,$datatable);
8439: }
8440:
1.137 raeburn 8441: sub usersession_titles {
8442: return &Apache::lonlocal::texthash(
8443: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8444: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8445: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8446: version => 'LON-CAPA version requirement',
1.138 raeburn 8447: excludedomain => 'Allow all, but exclude specific domains',
8448: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8449: primary => 'Primary (checked first)',
1.154 raeburn 8450: default => 'Default',
1.137 raeburn 8451: );
8452: }
8453:
1.152 raeburn 8454: sub id_for_thisdom {
8455: my (%servers) = @_;
8456: my %altids;
8457: foreach my $server (keys(%servers)) {
8458: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8459: if ($serverhome ne $server) {
8460: $altids{$serverhome} = $server;
8461: }
8462: }
8463: return %altids;
8464: }
8465:
1.150 raeburn 8466: sub count_servers {
8467: my ($currbalancer,%servers) = @_;
8468: my (@spares,$numspares);
8469: foreach my $lonhost (sort(keys(%servers))) {
8470: next if ($currbalancer eq $lonhost);
8471: push(@spares,$lonhost);
8472: }
8473: if ($currbalancer) {
8474: $numspares = scalar(@spares);
8475: } else {
8476: $numspares = scalar(@spares) - 1;
8477: }
8478: return ($numspares,@spares);
8479: }
8480:
8481: sub lonbalance_targets_js {
1.160.6.7 raeburn 8482: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8483: my $select = &mt('Select');
8484: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8485: if (ref($servers) eq 'HASH') {
8486: $alltargets = join("','",sort(keys(%{$servers})));
8487: my @homedoms;
8488: foreach my $server (sort(keys(%{$servers}))) {
8489: if (&Apache::lonnet::host_domain($server) eq $dom) {
8490: push(@homedoms,'1');
8491: } else {
8492: push(@homedoms,'0');
8493: }
8494: }
8495: $allishome = join("','",@homedoms);
8496: }
8497: if (ref($types) eq 'ARRAY') {
8498: if (@{$types} > 0) {
8499: @alltypes = @{$types};
8500: }
8501: }
8502: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8503: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8504: my (%currbalancer,%currtargets,%currrules,%existing);
8505: if (ref($settings) eq 'HASH') {
8506: %existing = %{$settings};
8507: }
8508: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8509: \%currtargets,\%currrules);
8510: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8511: return <<"END";
8512:
8513: <script type="text/javascript">
8514: // <![CDATA[
8515:
1.160.6.7 raeburn 8516: currBalancers = new Array('$balancers');
8517:
8518: function toggleTargets(balnum) {
8519: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8520: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8521: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8522: var prevbalancer = prevhostitem.value;
8523: var baltotal = document.getElementById('loadbalancing_total').value;
8524: prevhostitem.value = balancer;
8525: if (prevbalancer != '') {
8526: var prevIdx = currBalancers.indexOf(prevbalancer);
8527: if (prevIdx != -1) {
8528: currBalancers.splice(prevIdx,1);
8529: }
8530: }
1.150 raeburn 8531: if (balancer == '') {
1.160.6.7 raeburn 8532: hideSpares(balnum);
1.150 raeburn 8533: } else {
1.160.6.7 raeburn 8534: var currIdx = currBalancers.indexOf(balancer);
8535: if (currIdx == -1) {
8536: currBalancers.push(balancer);
8537: }
1.150 raeburn 8538: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8539: var ishomedom = homedoms[lonhostitem.selectedIndex];
8540: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8541: }
1.160.6.7 raeburn 8542: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8543: return;
8544: }
8545:
1.160.6.7 raeburn 8546: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8547: var alltargets = new Array('$alltargets');
8548: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8549: var offloadtypes = new Array('primary','default');
8550:
1.160.6.7 raeburn 8551: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8552: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8553:
1.151 raeburn 8554: for (var i=0; i<offloadtypes.length; i++) {
8555: var count = 0;
8556: for (var j=0; j<alltargets.length; j++) {
8557: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8558: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8559: item.value = alltargets[j];
8560: item.style.textAlign='left';
8561: item.style.textFace='normal';
8562: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8563: if (currBalancers.indexOf(alltargets[j]) == -1) {
8564: item.disabled = '';
8565: } else {
8566: item.disabled = 'disabled';
8567: item.checked = false;
8568: }
1.151 raeburn 8569: count ++;
8570: }
1.150 raeburn 8571: }
8572: }
1.151 raeburn 8573: for (var k=0; k<insttypes.length; k++) {
8574: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8575: if (ishomedom == 1) {
1.160.6.7 raeburn 8576: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8577: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8578: } else {
1.160.6.7 raeburn 8579: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8580: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8581:
8582: }
8583: } else {
1.160.6.7 raeburn 8584: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8585: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8586: }
1.151 raeburn 8587: if ((insttypes[k] != '_LC_external') &&
8588: ((insttypes[k] != '_LC_internetdom') ||
8589: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8590: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8591: item.options.length = 0;
8592: item.options[0] = new Option("","",true,true);
8593: var idx = 0;
1.151 raeburn 8594: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8595: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8596: idx ++;
8597: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8598:
1.150 raeburn 8599: }
8600: }
8601: }
8602: }
8603: return;
8604: }
8605:
1.160.6.7 raeburn 8606: function hideSpares(balnum) {
1.150 raeburn 8607: var alltargets = new Array('$alltargets');
8608: var insttypes = new Array('$allinsttypes');
8609: var offloadtypes = new Array('primary','default');
8610:
1.160.6.7 raeburn 8611: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8612: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8613:
8614: var total = alltargets.length - 1;
8615: for (var i=0; i<offloadtypes; i++) {
8616: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8617: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8618: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8619: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8620: }
1.150 raeburn 8621: }
8622: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8623: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8624: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8625: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8626: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8627: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8628: }
8629: }
8630: return;
8631: }
8632:
1.160.6.7 raeburn 8633: function checkOffloads(item,balnum,type) {
1.150 raeburn 8634: var alltargets = new Array('$alltargets');
8635: var offloadtypes = new Array('primary','default');
8636: if (item.checked) {
8637: var total = alltargets.length - 1;
8638: var other;
8639: if (type == offloadtypes[0]) {
1.151 raeburn 8640: other = offloadtypes[1];
1.150 raeburn 8641: } else {
1.151 raeburn 8642: other = offloadtypes[0];
1.150 raeburn 8643: }
8644: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8645: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8646: if (server == item.value) {
1.160.6.7 raeburn 8647: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8648: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8649: }
8650: }
8651: }
8652: }
8653: return;
8654: }
8655:
1.160.6.7 raeburn 8656: function singleServerToggle(balnum,type) {
8657: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8658: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 8659: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8660: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8661:
8662: } else {
1.160.6.7 raeburn 8663: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8664: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8665: }
8666: return;
8667: }
8668:
1.160.6.7 raeburn 8669: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8670: if (type == '_LC_external') {
8671: return;
8672: }
1.160.6.7 raeburn 8673: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8674: for (var i=0; i<typesRules.length; i++) {
8675: if (formname.elements[typesRules[i]].checked) {
8676: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 8677: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8678: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8679: } else {
1.160.6.7 raeburn 8680: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8681: }
8682: }
8683: }
8684: return;
8685: }
8686:
8687: function balancerDeleteChange(balnum) {
8688: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8689: var baltotal = document.getElementById('loadbalancing_total').value;
8690: var addtarget;
8691: var removetarget;
8692: var action = 'delete';
8693: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8694: var lonhost = hostitem.value;
8695: var currIdx = currBalancers.indexOf(lonhost);
8696: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8697: if (currIdx != -1) {
8698: currBalancers.splice(currIdx,1);
8699: }
8700: addtarget = lonhost;
8701: } else {
8702: if (currIdx == -1) {
8703: currBalancers.push(lonhost);
8704: }
8705: removetarget = lonhost;
8706: action = 'undelete';
8707: }
8708: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8709: }
8710: return;
8711: }
8712:
8713: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8714: if (baltotal > 1) {
8715: var offloadtypes = new Array('primary','default');
8716: var alltargets = new Array('$alltargets');
8717: var insttypes = new Array('$allinsttypes');
8718: for (var i=0; i<baltotal; i++) {
8719: if (i != balnum) {
8720: for (var j=0; j<offloadtypes.length; j++) {
8721: var total = alltargets.length - 1;
8722: for (var k=0; k<total; k++) {
8723: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8724: var server = serveritem.value;
8725: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8726: if (server == addtarget) {
8727: serveritem.disabled = '';
8728: }
8729: }
8730: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8731: if (server == removetarget) {
8732: serveritem.disabled = 'disabled';
8733: serveritem.checked = false;
8734: }
8735: }
8736: }
8737: }
8738: for (var j=0; j<insttypes.length; j++) {
8739: if (insttypes[j] != '_LC_external') {
8740: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8741: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8742: var currSel = singleserver.selectedIndex;
8743: var currVal = singleserver.options[currSel].value;
8744: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8745: var numoptions = singleserver.options.length;
8746: var needsnew = 1;
8747: for (var k=0; k<numoptions; k++) {
8748: if (singleserver.options[k] == addtarget) {
8749: needsnew = 0;
8750: break;
8751: }
8752: }
8753: if (needsnew == 1) {
8754: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8755: }
8756: }
8757: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8758: singleserver.options.length = 0;
8759: if ((currVal) && (currVal != removetarget)) {
8760: singleserver.options[0] = new Option("","",false,false);
8761: } else {
8762: singleserver.options[0] = new Option("","",true,true);
8763: }
8764: var idx = 0;
8765: for (var m=0; m<alltargets.length; m++) {
8766: if (currBalancers.indexOf(alltargets[m]) == -1) {
8767: idx ++;
8768: if (currVal == alltargets[m]) {
8769: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8770: } else {
8771: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8772: }
8773: }
8774: }
8775: }
8776: }
8777: }
8778: }
1.150 raeburn 8779: }
8780: }
8781: }
8782: return;
8783: }
8784:
1.152 raeburn 8785: // ]]>
8786: </script>
8787:
8788: END
8789: }
8790:
8791: sub new_spares_js {
8792: my @sparestypes = ('primary','default');
8793: my $types = join("','",@sparestypes);
8794: my $select = &mt('Select');
8795: return <<"END";
8796:
8797: <script type="text/javascript">
8798: // <![CDATA[
8799:
8800: function updateNewSpares(formname,lonhost) {
8801: var types = new Array('$types');
8802: var include = new Array();
8803: var exclude = new Array();
8804: for (var i=0; i<types.length; i++) {
8805: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8806: for (var j=0; j<spareboxes.length; j++) {
8807: if (formname.elements[spareboxes[j]].checked) {
8808: exclude.push(formname.elements[spareboxes[j]].value);
8809: } else {
8810: include.push(formname.elements[spareboxes[j]].value);
8811: }
8812: }
8813: }
8814: for (var i=0; i<types.length; i++) {
8815: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8816: var selIdx = newSpare.selectedIndex;
8817: var currnew = newSpare.options[selIdx].value;
8818: var okSpares = new Array();
8819: for (var j=0; j<newSpare.options.length; j++) {
8820: var possible = newSpare.options[j].value;
8821: if (possible != '') {
8822: if (exclude.indexOf(possible) == -1) {
8823: okSpares.push(possible);
8824: } else {
8825: if (currnew == possible) {
8826: selIdx = 0;
8827: }
8828: }
8829: }
8830: }
8831: for (var k=0; k<include.length; k++) {
8832: if (okSpares.indexOf(include[k]) == -1) {
8833: okSpares.push(include[k]);
8834: }
8835: }
8836: okSpares.sort();
8837: newSpare.options.length = 0;
8838: if (selIdx == 0) {
8839: newSpare.options[0] = new Option("$select","",true,true);
8840: } else {
8841: newSpare.options[0] = new Option("$select","",false,false);
8842: }
8843: for (var m=0; m<okSpares.length; m++) {
8844: var idx = m+1;
8845: var selThis = 0;
8846: if (selIdx != 0) {
8847: if (okSpares[m] == currnew) {
8848: selThis = 1;
8849: }
8850: }
8851: if (selThis == 1) {
8852: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8853: } else {
8854: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8855: }
8856: }
8857: }
8858: return;
8859: }
8860:
8861: function checkNewSpares(lonhost,type) {
8862: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8863: var chosen = newSpare.options[newSpare.selectedIndex].value;
8864: if (chosen != '') {
8865: var othertype;
8866: var othernewSpare;
8867: if (type == 'primary') {
8868: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8869: }
8870: if (type == 'default') {
8871: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8872: }
8873: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8874: othernewSpare.selectedIndex = 0;
8875: }
8876: }
8877: return;
8878: }
8879:
8880: // ]]>
8881: </script>
8882:
8883: END
8884:
8885: }
8886:
8887: sub common_domprefs_js {
8888: return <<"END";
8889:
8890: <script type="text/javascript">
8891: // <![CDATA[
8892:
1.150 raeburn 8893: function getIndicesByName(formname,item) {
1.152 raeburn 8894: var group = new Array();
1.150 raeburn 8895: for (var i=0;i<formname.elements.length;i++) {
8896: if (formname.elements[i].name == item) {
1.152 raeburn 8897: group.push(formname.elements[i].id);
1.150 raeburn 8898: }
8899: }
1.152 raeburn 8900: return group;
1.150 raeburn 8901: }
8902:
8903: // ]]>
8904: </script>
8905:
8906: END
1.152 raeburn 8907:
1.150 raeburn 8908: }
8909:
1.160.6.5 raeburn 8910: sub recaptcha_js {
8911: my %lt = &captcha_phrases();
8912: return <<"END";
8913:
8914: <script type="text/javascript">
8915: // <![CDATA[
8916:
8917: function updateCaptcha(caller,context) {
8918: var privitem;
8919: var pubitem;
8920: var privtext;
8921: var pubtext;
8922: if (document.getElementById(context+'_recaptchapub')) {
8923: pubitem = document.getElementById(context+'_recaptchapub');
8924: } else {
8925: return;
8926: }
8927: if (document.getElementById(context+'_recaptchapriv')) {
8928: privitem = document.getElementById(context+'_recaptchapriv');
8929: } else {
8930: return;
8931: }
8932: if (document.getElementById(context+'_recaptchapubtxt')) {
8933: pubtext = document.getElementById(context+'_recaptchapubtxt');
8934: } else {
8935: return;
8936: }
8937: if (document.getElementById(context+'_recaptchaprivtxt')) {
8938: privtext = document.getElementById(context+'_recaptchaprivtxt');
8939: } else {
8940: return;
8941: }
8942: if (caller.checked) {
8943: if (caller.value == 'recaptcha') {
8944: pubitem.type = 'text';
8945: privitem.type = 'text';
8946: pubitem.size = '40';
8947: privitem.size = '40';
8948: pubtext.innerHTML = "$lt{'pub'}";
8949: privtext.innerHTML = "$lt{'priv'}";
8950: } else {
8951: pubitem.type = 'hidden';
8952: privitem.type = 'hidden';
8953: pubtext.innerHTML = '';
8954: privtext.innerHTML = '';
8955: }
8956: }
8957: return;
8958: }
8959:
8960: // ]]>
8961: </script>
8962:
8963: END
8964:
8965: }
8966:
8967: sub captcha_phrases {
8968: return &Apache::lonlocal::texthash (
8969: priv => 'Private key',
8970: pub => 'Public key',
8971: original => 'original (CAPTCHA)',
8972: recaptcha => 'successor (ReCAPTCHA)',
8973: notused => 'unused',
8974: );
8975: }
8976:
1.3 raeburn 8977: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>