Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.7
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.7! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.6 2012/09/25 20:38:47 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
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: }
1166: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1167: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1168: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1169: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1170: ' <span id="css_'.$role.'_font" style="background-color: '.
1171: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1172: '</span></td></tr>';
1.107 raeburn 1173: unless ($role eq 'login') {
1174: $datatable .= '<tr'.$css_class.'>'.
1175: '<td>'.$choices->{'fontmenu'}.'</td>';
1176: if (!$is_custom->{'fontmenu'}) {
1177: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1178: } else {
1179: $datatable .= '<td> </td>';
1180: }
1181: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1182: $datatable .= '<td><span class="LC_nobreak">'.
1183: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1184: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1185: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1186: $designs->{'fontmenu'}.';"> </span>'.
1187: '</span></td></tr>';
1.97 tempelho 1188: }
1.9 raeburn 1189: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1190: foreach my $img (@{$images}) {
1.18 albertel 1191: $itemcount ++;
1.6 raeburn 1192: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1193: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1194: '<td>'.$choices->{$img};
1.41 raeburn 1195: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1196: if ($role eq 'login') {
1197: if ($img eq 'login') {
1198: $login_hdr_pick =
1.135 bisitz 1199: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1200: $logincolors =
1201: &login_text_colors($img,$role,$logintext,$phase,$choices,
1202: $designs);
1203: } elsif ($img ne 'domlogo') {
1204: $datatable.= &logo_display_options($img,$defaults,$designs);
1205: }
1206: }
1207: $datatable .= '</td>';
1.6 raeburn 1208: if ($designs->{$img} ne '') {
1209: $imgfile = $designs->{$img};
1.18 albertel 1210: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1211: } else {
1212: $imgfile = $defaults->{$img};
1213: }
1214: if ($imgfile) {
1.9 raeburn 1215: my ($showfile,$fullsize);
1216: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1217: my $urldir = $1;
1218: my $filename = $2;
1219: my @info = &Apache::lonnet::stat_file($designs->{$img});
1220: if (@info) {
1221: my $thumbfile = 'tn-'.$filename;
1222: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1223: if (@thumb) {
1224: $showfile = $urldir.'/'.$thumbfile;
1225: } else {
1226: $showfile = $imgfile;
1227: }
1228: } else {
1229: $showfile = '';
1230: }
1231: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1232: $showfile = $imgfile;
1.6 raeburn 1233: my $imgdir = $1;
1234: my $filename = $2;
1.159 raeburn 1235: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1236: $showfile = "/$imgdir/tn-".$filename;
1237: } else {
1.159 raeburn 1238: my $input = $londocroot.$imgfile;
1239: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1240: if (!-e $output) {
1.9 raeburn 1241: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1242: my ($fullwidth,$fullheight) = &check_dimensions($input);
1243: if ($fullwidth ne '' && $fullheight ne '') {
1244: if ($fullwidth > $width && $fullheight > $height) {
1245: my $size = $width.'x'.$height;
1246: system("convert -sample $size $input $output");
1.159 raeburn 1247: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1248: }
1249: }
1.6 raeburn 1250: }
1251: }
1.16 raeburn 1252: }
1.6 raeburn 1253: if ($showfile) {
1.40 raeburn 1254: if ($showfile =~ m{^/(adm|res)/}) {
1255: if ($showfile =~ m{^/res/}) {
1256: my $local_showfile =
1257: &Apache::lonnet::filelocation('',$showfile);
1258: &Apache::lonnet::repcopy($local_showfile);
1259: }
1260: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1261: }
1262: if ($imgfile) {
1263: if ($imgfile =~ m{^/(adm|res)/}) {
1264: if ($imgfile =~ m{^/res/}) {
1265: my $local_imgfile =
1266: &Apache::lonnet::filelocation('',$imgfile);
1267: &Apache::lonnet::repcopy($local_imgfile);
1268: }
1269: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1270: } else {
1271: $fullsize = $imgfile;
1272: }
1273: }
1.41 raeburn 1274: $datatable .= '<td>';
1275: if ($img eq 'login') {
1.135 bisitz 1276: $datatable .= $login_hdr_pick;
1277: }
1.41 raeburn 1278: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1279: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1280: } else {
1281: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1282: &mt('Upload:');
1283: }
1284: } else {
1285: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1286: &mt('Upload:');
1287: }
1.9 raeburn 1288: if ($switchserver) {
1289: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1290: } else {
1.135 bisitz 1291: if ($img ne 'login') { # suppress file selection for Log-in header
1292: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1293: }
1.9 raeburn 1294: }
1295: $datatable .= '</td></tr>';
1.6 raeburn 1296: }
1297: $itemcount ++;
1298: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1299: $datatable .= '<tr'.$css_class.'>'.
1300: '<td>'.$choices->{'bgs'}.'</td>';
1301: my $bgs_def;
1302: foreach my $item (@{$bgs}) {
1303: if (!$is_custom->{$item}) {
1.70 raeburn 1304: $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 1305: }
1306: }
1307: if ($bgs_def) {
1.8 raeburn 1308: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1309: } else {
1310: $datatable .= '<td> </td>';
1311: }
1312: $datatable .= '<td class="LC_right_item">'.
1313: '<table border="0"><tr>';
1314: foreach my $item (@{$bgs}) {
1315: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1316: $datatable .= '<td align="center">'.$link;
1317: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1318: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1319: }
1320: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1321: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1322: }
1323: $datatable .= '</tr></table></td></tr>';
1324: $itemcount ++;
1325: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1326: $datatable .= '<tr'.$css_class.'>'.
1327: '<td>'.$choices->{'links'}.'</td>';
1328: my $links_def;
1329: foreach my $item (@{$links}) {
1330: if (!$is_custom->{$item}) {
1.30 raeburn 1331: $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 1332: }
1333: }
1334: if ($links_def) {
1.8 raeburn 1335: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1336: } else {
1337: $datatable .= '<td> </td>';
1338: }
1339: $datatable .= '<td class="LC_right_item">'.
1340: '<table border="0"><tr>';
1341: foreach my $item (@{$links}) {
1.30 raeburn 1342: $datatable .= '<td align="center">'."\n".
1343: &color_pick($phase,$role,$item,$choices->{$item},
1344: $designs->{'links'}{$item});
1.6 raeburn 1345: if ($designs->{'links'}{$item}) {
1.30 raeburn 1346: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1347: }
1348: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1349: '" /></td>';
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') {
1689: if (ref($settings->{'requestauthor'}) eq 'HASH') {
1690: $curroption = $settings->{'requestauthor'};
1691: }
1692: }
1693: if (!$curroption) {
1694: $curroption = 'norequest';
1695: }
1696: foreach my $option (@options) {
1697: my $val = $option;
1698: if ($option eq 'norequest') {
1699: $val = 0;
1700: }
1701: my $checked = '';
1702: if ($option eq $curroption) {
1703: $checked = ' checked="checked"';
1704: }
1705: $datatable .= '<span class="LC_nobreak"><label>'.
1706: '<input type="radio" name="authorreq_default"'.
1707: ' value="'.$val.'"'.$checked.' />'.
1708: $titles{$option}.'</label></span> ';
1709: }
1.101 raeburn 1710: } else {
1711: my $checked = 'checked="checked" ';
1712: if (ref($settings) eq 'HASH') {
1713: if (ref($settings->{$item}) eq 'HASH') {
1714: if ($settings->{$item}->{'default'} == 0) {
1715: $checked = '';
1716: } elsif ($settings->{$item}->{'default'} == 1) {
1717: $checked = 'checked="checked" ';
1718: }
1.78 raeburn 1719: }
1.72 raeburn 1720: }
1.101 raeburn 1721: $datatable .= '<span class="LC_nobreak"><label>'.
1722: '<input type="checkbox" name="'.$context.'_'.$item.
1723: '" value="default" '.$checked.'/>'.$titles{$item}.
1724: '</label></span> ';
1725: }
1726: }
1727: if ($context eq 'requestcourses') {
1728: $datatable .= '</tr><tr>';
1729: foreach my $item (@usertools) {
1.106 raeburn 1730: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1731: }
1.101 raeburn 1732: $datatable .= '</tr></table>';
1.72 raeburn 1733: }
1.86 raeburn 1734: $datatable .= '</td>';
1.160.6.5 raeburn 1735: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1736: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1737: '<input type="text" name="defaultquota" value="'.
1738: $defaultquota.'" size="5" /> Mb</span></td>';
1739: }
1740: $datatable .= '</tr>';
1.72 raeburn 1741: $typecount ++;
1742: $css_class = $typecount%2?' class="LC_odd_row"':'';
1743: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1744: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1745: if ($context eq 'requestcourses') {
1.109 raeburn 1746: $datatable .= &mt('(overrides affiliation, if set)').
1747: '</td>'.
1748: '<td class="LC_left_item">'.
1749: '<table><tr>';
1.101 raeburn 1750: } else {
1.109 raeburn 1751: $datatable .= &mt('(overrides affiliation, if checked)').
1752: '</td>'.
1753: '<td class="LC_left_item" colspan="2">'.
1754: '<br />';
1.101 raeburn 1755: }
1756: my %advcell;
1.72 raeburn 1757: foreach my $item (@usertools) {
1.101 raeburn 1758: if ($context eq 'requestcourses') {
1759: my ($curroption,$currlimit);
1760: if (ref($settings) eq 'HASH') {
1761: if (ref($settings->{$item}) eq 'HASH') {
1762: $curroption = $settings->{$item}->{'_LC_adv'};
1763: if ($curroption =~ /^autolimit=(\d*)$/) {
1764: $currlimit = $1;
1765: }
1766: }
1767: }
1768: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1769: my $checked = '';
1770: if ($curroption eq '') {
1771: $checked = ' checked="checked"';
1772: }
1773: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1774: '<input type="radio" name="crsreq_'.$item.
1775: '__LC_adv" value=""'.$checked.' />'.
1776: &mt('No override set').'</label></span> ';
1.101 raeburn 1777: foreach my $option (@options) {
1778: my $val = $option;
1779: if ($option eq 'norequest') {
1780: $val = 0;
1781: }
1782: if ($option eq 'validate') {
1783: my $canvalidate = 0;
1784: if (ref($validations{$item}) eq 'HASH') {
1785: if ($validations{$item}{'_LC_adv'}) {
1786: $canvalidate = 1;
1787: }
1788: }
1789: next if (!$canvalidate);
1790: }
1791: my $checked = '';
1.104 raeburn 1792: if ($val eq $curroption) {
1.101 raeburn 1793: $checked = ' checked="checked"';
1794: } elsif ($option eq 'autolimit') {
1795: if ($curroption =~ /^autolimit/) {
1796: $checked = ' checked="checked"';
1797: }
1798: }
1799: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1800: '<input type="radio" name="crsreq_'.$item.
1801: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1802: $titles{$option}.'</label>';
1803: if ($option eq 'autolimit') {
1.127 raeburn 1804: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1805: $item.'_limit__LC_adv" size="1" '.
1806: 'value="'.$currlimit.'" />';
1807: }
1.127 raeburn 1808: $advcell{$item} .= '</span> ';
1.104 raeburn 1809: if ($option eq 'autolimit') {
1.127 raeburn 1810: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1811: }
1.101 raeburn 1812: }
1.160.6.5 raeburn 1813: } elsif ($context eq 'requestauthor') {
1814: my $curroption;
1815: if (ref($settings) eq 'HASH') {
1816: $curroption = $settings->{'_LC_adv'};
1817: }
1818: my $checked = '';
1819: if ($curroption eq '') {
1820: $checked = ' checked="checked"';
1821: }
1822: $datatable .= '<span class="LC_nobreak"><label>'.
1823: '<input type="radio" name="authorreq__LC_adv"'.
1824: ' value=""'.$checked.' />'.
1825: &mt('No override set').'</label></span> ';
1826: foreach my $option (@options) {
1827: my $val = $option;
1828: if ($option eq 'norequest') {
1829: $val = 0;
1830: }
1831: my $checked = '';
1832: if ($val eq $curroption) {
1833: $checked = ' checked="checked"';
1834: }
1835: $datatable .= '<span class="LC_nobreak"><label>'.
1836: '<input type="radio" name="crsreq_'.$item.
1837: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1838: $titles{$option}.'</label></span> ';
1839: }
1.101 raeburn 1840: } else {
1841: my $checked = 'checked="checked" ';
1842: if (ref($settings) eq 'HASH') {
1843: if (ref($settings->{$item}) eq 'HASH') {
1844: if ($settings->{$item}->{'_LC_adv'} == 0) {
1845: $checked = '';
1846: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1847: $checked = 'checked="checked" ';
1848: }
1.79 raeburn 1849: }
1.72 raeburn 1850: }
1.101 raeburn 1851: $datatable .= '<span class="LC_nobreak"><label>'.
1852: '<input type="checkbox" name="'.$context.'_'.$item.
1853: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1854: '</label></span> ';
1855: }
1856: }
1857: if ($context eq 'requestcourses') {
1858: $datatable .= '</tr><tr>';
1859: foreach my $item (@usertools) {
1.106 raeburn 1860: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1861: }
1.101 raeburn 1862: $datatable .= '</tr></table>';
1.72 raeburn 1863: }
1.98 raeburn 1864: $datatable .= '</td></tr>';
1.30 raeburn 1865: $$rowtotal += $typecount;
1.3 raeburn 1866: return $datatable;
1867: }
1868:
1.160.6.5 raeburn 1869: sub print_requestmail {
1870: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1871: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1872: $now = time;
1873: $rows = 0;
1874: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1875: foreach my $server (keys(%dompersonnel)) {
1876: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1877: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1878: if (!grep(/^$uname:$udom$/,@domcoord)) {
1879: push(@domcoord,$uname.':'.$udom);
1880: }
1881: }
1882: }
1883: if (ref($settings) eq 'HASH') {
1884: if (ref($settings->{'notify'}) eq 'HASH') {
1885: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1886: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1887: }
1888: }
1889: }
1.104 raeburn 1890: if (@currapproval) {
1891: foreach my $dc (@currapproval) {
1.102 raeburn 1892: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1893: push(@domcoord,$dc);
1894: }
1895: }
1896: }
1897: @domcoord = sort(@domcoord);
1898: my $numinrow = 4;
1899: my $numdc = @domcoord;
1900: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1901: my $text;
1902: if ($action eq 'requestcourses') {
1903: $text = &mt('Receive notification of course requests requiring approval');
1904: } else {
1905: $text = &mt('Receive notification of authoring space requests requiring approval')
1906: }
1907: $datatable = '<tr '.$css_class.'>'.
1908: ' <td>'.$text.'</td>'.
1.102 raeburn 1909: ' <td class="LC_left_item">';
1910: if (@domcoord > 0) {
1911: $datatable .= '<table>';
1912: for (my $i=0; $i<$numdc; $i++) {
1913: my $rem = $i%($numinrow);
1914: if ($rem == 0) {
1915: if ($i > 0) {
1916: $datatable .= '</tr>';
1917: }
1918: $datatable .= '<tr>';
1919: $rows ++;
1920: }
1921: my $check = ' ';
1.104 raeburn 1922: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1923: $check = ' checked="checked" ';
1924: }
1925: my ($uname,$udom) = split(':',$domcoord[$i]);
1926: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1927: if ($i == $numdc-1) {
1928: my $colsleft = $numinrow-$rem;
1929: if ($colsleft > 1) {
1930: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1931: } else {
1932: $datatable .= '<td class="LC_left_item">';
1933: }
1934: } else {
1935: $datatable .= '<td class="LC_left_item">';
1936: }
1937: $datatable .= '<span class="LC_nobreak"><label>'.
1938: '<input type="checkbox" name="reqapprovalnotify" '.
1939: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1940: $fullname.'</label></span></td>';
1941: }
1942: $datatable .= '</tr></table>';
1943: } else {
1944: $datatable .= &mt('There are no active Domain Coordinators');
1945: $rows ++;
1946: }
1947: $datatable .='</td></tr>';
1948: $$rowtotal += $rows;
1949: return $datatable;
1950: }
1951:
1.3 raeburn 1952: sub print_autoenroll {
1.30 raeburn 1953: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1954: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1955: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1956: if (ref($settings) eq 'HASH') {
1957: if (exists($settings->{'run'})) {
1958: if ($settings->{'run'} eq '0') {
1959: $runoff = ' checked="checked" ';
1960: $runon = ' ';
1961: } else {
1962: $runon = ' checked="checked" ';
1963: $runoff = ' ';
1964: }
1965: } else {
1966: if ($autorun) {
1967: $runon = ' checked="checked" ';
1968: $runoff = ' ';
1969: } else {
1970: $runoff = ' checked="checked" ';
1971: $runon = ' ';
1972: }
1973: }
1.129 raeburn 1974: if (exists($settings->{'co-owners'})) {
1975: if ($settings->{'co-owners'} eq '0') {
1976: $coownersoff = ' checked="checked" ';
1977: $coownerson = ' ';
1978: } else {
1979: $coownerson = ' checked="checked" ';
1980: $coownersoff = ' ';
1981: }
1982: } else {
1983: $coownersoff = ' checked="checked" ';
1984: $coownerson = ' ';
1985: }
1.3 raeburn 1986: if (exists($settings->{'sender_domain'})) {
1987: $defdom = $settings->{'sender_domain'};
1988: }
1.14 raeburn 1989: } else {
1990: if ($autorun) {
1991: $runon = ' checked="checked" ';
1992: $runoff = ' ';
1993: } else {
1994: $runoff = ' checked="checked" ';
1995: $runon = ' ';
1996: }
1.3 raeburn 1997: }
1998: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1999: my $notif_sender;
2000: if (ref($settings) eq 'HASH') {
2001: $notif_sender = $settings->{'sender_uname'};
2002: }
1.3 raeburn 2003: my $datatable='<tr class="LC_odd_row">'.
2004: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2005: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2006: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2007: $runon.' value="1" />'.&mt('Yes').'</label> '.
2008: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2009: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2010: '</tr><tr>'.
2011: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2012: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2013: &mt('username').': '.
2014: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2015: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2016: ': '.$domform.'</span></td></tr>'.
2017: '<tr class="LC_odd_row">'.
2018: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2019: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2020: '<input type="radio" name="autoassign_coowners"'.
2021: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2022: '<label><input type="radio" name="autoassign_coowners"'.
2023: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2024: '</tr>';
2025: $$rowtotal += 3;
1.3 raeburn 2026: return $datatable;
2027: }
2028:
2029: sub print_autoupdate {
1.30 raeburn 2030: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2031: my $datatable;
2032: if ($position eq 'top') {
2033: my $updateon = ' ';
2034: my $updateoff = ' checked="checked" ';
2035: my $classlistson = ' ';
2036: my $classlistsoff = ' checked="checked" ';
2037: if (ref($settings) eq 'HASH') {
2038: if ($settings->{'run'} eq '1') {
2039: $updateon = $updateoff;
2040: $updateoff = ' ';
2041: }
2042: if ($settings->{'classlists'} eq '1') {
2043: $classlistson = $classlistsoff;
2044: $classlistsoff = ' ';
2045: }
2046: }
2047: my %title = (
2048: run => 'Auto-update active?',
2049: classlists => 'Update information in classlists?',
2050: );
2051: $datatable = '<tr class="LC_odd_row">'.
2052: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2053: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2054: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2055: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2056: '<label><input type="radio" name="autoupdate_run"'.
2057: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2058: '</tr><tr>'.
2059: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2060: '<td class="LC_right_item"><span class="LC_nobreak">'.
2061: '<label><input type="radio" name="classlists"'.
2062: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2063: '<label><input type="radio" name="classlists"'.
2064: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2065: '</tr>';
1.30 raeburn 2066: $$rowtotal += 2;
1.131 raeburn 2067: } elsif ($position eq 'middle') {
2068: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2069: my $numinrow = 3;
2070: my $locknamesettings;
2071: $datatable .= &insttypes_row($settings,$types,$usertypes,
2072: $dom,$numinrow,$othertitle,
2073: 'lockablenames');
2074: $$rowtotal ++;
1.3 raeburn 2075: } else {
1.44 raeburn 2076: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2077: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2078: 'permanentemail','id');
1.33 raeburn 2079: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2080: my $numrows = 0;
1.26 raeburn 2081: if (ref($types) eq 'ARRAY') {
2082: if (@{$types} > 0) {
2083: $datatable =
2084: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2085: \@fields,$types,\$numrows);
1.30 raeburn 2086: $$rowtotal += @{$types};
1.26 raeburn 2087: }
1.3 raeburn 2088: }
2089: $datatable .=
2090: &usertype_update_row($settings,{'default' => $othertitle},
2091: \%fieldtitles,\@fields,['default'],
2092: \$numrows);
1.30 raeburn 2093: $$rowtotal ++;
1.3 raeburn 2094: }
2095: return $datatable;
2096: }
2097:
1.125 raeburn 2098: sub print_autocreate {
2099: my ($dom,$settings,$rowtotal) = @_;
2100: my (%createon,%createoff);
2101: my $curr_dc;
2102: my @types = ('xml','req');
2103: if (ref($settings) eq 'HASH') {
2104: foreach my $item (@types) {
2105: $createoff{$item} = ' checked="checked" ';
2106: $createon{$item} = ' ';
2107: if (exists($settings->{$item})) {
2108: if ($settings->{$item}) {
2109: $createon{$item} = ' checked="checked" ';
2110: $createoff{$item} = ' ';
2111: }
2112: }
2113: }
2114: $curr_dc = $settings->{'xmldc'};
2115: } else {
2116: foreach my $item (@types) {
2117: $createoff{$item} = ' checked="checked" ';
2118: $createon{$item} = ' ';
2119: }
2120: }
2121: $$rowtotal += 2;
2122: my $datatable='<tr class="LC_odd_row">'.
2123: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2124: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2125: '<input type="radio" name="autocreate_xml"'.
2126: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2127: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2128: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2129: '</td></tr><tr>'.
2130: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2131: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2132: '<input type="radio" name="autocreate_req"'.
2133: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2134: '<label><input type="radio" name="autocreate_req"'.
2135: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2136: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2137: if ($numdc > 1) {
1.143 raeburn 2138: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2139: &mt('Course creation processed as: (choose Dom. Coord.)').
2140: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2141: $$rowtotal ++ ;
2142: } else {
1.143 raeburn 2143: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2144: }
2145: return $datatable;
2146: }
2147:
1.23 raeburn 2148: sub print_directorysrch {
1.30 raeburn 2149: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2150: my $srchon = ' ';
2151: my $srchoff = ' checked="checked" ';
1.25 raeburn 2152: my ($exacton,$containson,$beginson);
1.24 raeburn 2153: my $localon = ' ';
2154: my $localoff = ' checked="checked" ';
1.23 raeburn 2155: if (ref($settings) eq 'HASH') {
2156: if ($settings->{'available'} eq '1') {
2157: $srchon = $srchoff;
2158: $srchoff = ' ';
2159: }
1.24 raeburn 2160: if ($settings->{'localonly'} eq '1') {
2161: $localon = $localoff;
2162: $localoff = ' ';
2163: }
1.25 raeburn 2164: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2165: foreach my $type (@{$settings->{'searchtypes'}}) {
2166: if ($type eq 'exact') {
2167: $exacton = ' checked="checked" ';
2168: } elsif ($type eq 'contains') {
2169: $containson = ' checked="checked" ';
2170: } elsif ($type eq 'begins') {
2171: $beginson = ' checked="checked" ';
2172: }
2173: }
2174: } else {
2175: if ($settings->{'searchtypes'} eq 'exact') {
2176: $exacton = ' checked="checked" ';
2177: } elsif ($settings->{'searchtypes'} eq 'contains') {
2178: $containson = ' checked="checked" ';
2179: } elsif ($settings->{'searchtypes'} eq 'specify') {
2180: $exacton = ' checked="checked" ';
2181: $containson = ' checked="checked" ';
2182: }
1.23 raeburn 2183: }
2184: }
2185: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2186: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2187:
2188: my $numinrow = 4;
1.26 raeburn 2189: my $cansrchrow = 0;
1.23 raeburn 2190: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2191: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2192: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2193: '<input type="radio" name="dirsrch_available"'.
2194: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2195: '<label><input type="radio" name="dirsrch_available"'.
2196: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2197: '</tr><tr>'.
1.30 raeburn 2198: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2199: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2200: '<input type="radio" name="dirsrch_localonly"'.
2201: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2202: '<label><input type="radio" name="dirsrch_localonly"'.
2203: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2204: '</tr>';
1.30 raeburn 2205: $$rowtotal += 2;
1.26 raeburn 2206: if (ref($usertypes) eq 'HASH') {
2207: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2208: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2209: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2210: $cansrchrow = 1;
2211: }
2212: }
2213: if ($cansrchrow) {
1.30 raeburn 2214: $$rowtotal ++;
1.26 raeburn 2215: $datatable .= '<tr>';
2216: } else {
2217: $datatable .= '<tr class="LC_odd_row">';
2218: }
1.30 raeburn 2219: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2220: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2221: foreach my $title (@{$titleorder}) {
2222: if (defined($searchtitles->{$title})) {
2223: my $check = ' ';
1.93 raeburn 2224: if (ref($settings) eq 'HASH') {
1.39 raeburn 2225: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2226: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2227: $check = ' checked="checked" ';
2228: }
1.25 raeburn 2229: }
2230: }
2231: $datatable .= '<td class="LC_left_item">'.
2232: '<span class="LC_nobreak"><label>'.
2233: '<input type="checkbox" name="searchby" '.
2234: 'value="'.$title.'"'.$check.'/>'.
2235: $searchtitles->{$title}.'</label></span></td>';
2236: }
2237: }
1.26 raeburn 2238: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2239: $$rowtotal ++;
1.26 raeburn 2240: if ($cansrchrow) {
2241: $datatable .= '<tr class="LC_odd_row">';
2242: } else {
2243: $datatable .= '<tr>';
2244: }
1.30 raeburn 2245: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2246: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2247: '<span class="LC_nobreak"><label>'.
2248: '<input type="checkbox" name="searchtypes" '.
2249: $exacton.' value="exact" />'.&mt('Exact match').
2250: '</label> '.
2251: '<label><input type="checkbox" name="searchtypes" '.
2252: $beginson.' value="begins" />'.&mt('Begins with').
2253: '</label> '.
2254: '<label><input type="checkbox" name="searchtypes" '.
2255: $containson.' value="contains" />'.&mt('Contains').
2256: '</label></span></td></tr>';
1.30 raeburn 2257: $$rowtotal ++;
1.25 raeburn 2258: return $datatable;
2259: }
2260:
1.28 raeburn 2261: sub print_contacts {
1.30 raeburn 2262: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2263: my $datatable;
2264: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2265: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2266: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2267: 'requestsmail');
1.28 raeburn 2268: foreach my $type (@mailings) {
2269: $otheremails{$type} = '';
2270: }
1.134 raeburn 2271: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2272: if (ref($settings) eq 'HASH') {
2273: foreach my $item (@contacts) {
2274: if (exists($settings->{$item})) {
2275: $to{$item} = $settings->{$item};
2276: }
2277: }
2278: foreach my $type (@mailings) {
2279: if (exists($settings->{$type})) {
2280: if (ref($settings->{$type}) eq 'HASH') {
2281: foreach my $item (@contacts) {
2282: if ($settings->{$type}{$item}) {
2283: $checked{$type}{$item} = ' checked="checked" ';
2284: }
2285: }
2286: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2287: if ($type eq 'helpdeskmail') {
2288: $bccemails{$type} = $settings->{$type}{'bcc'};
2289: }
1.28 raeburn 2290: }
1.89 raeburn 2291: } elsif ($type eq 'lonstatusmail') {
2292: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2293: }
2294: }
2295: } else {
2296: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2297: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2298: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2299: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2300: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2301: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2302: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2303: }
2304: my ($titles,$short_titles) = &contact_titles();
2305: my $rownum = 0;
2306: my $css_class;
2307: foreach my $item (@contacts) {
1.69 raeburn 2308: $rownum ++;
2309: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2310: $datatable .= '<tr'.$css_class.'>'.
2311: '<td><span class="LC_nobreak">'.$titles->{$item}.
2312: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2313: '<input type="text" name="'.$item.'" value="'.
2314: $to{$item}.'" /></td></tr>';
2315: }
2316: foreach my $type (@mailings) {
1.69 raeburn 2317: $rownum ++;
2318: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2319: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2320: '<td><span class="LC_nobreak">'.
2321: $titles->{$type}.': </span></td>'.
1.28 raeburn 2322: '<td class="LC_left_item">'.
2323: '<span class="LC_nobreak">';
2324: foreach my $item (@contacts) {
2325: $datatable .= '<label>'.
2326: '<input type="checkbox" name="'.$type.'"'.
2327: $checked{$type}{$item}.
2328: ' value="'.$item.'" />'.$short_titles->{$item}.
2329: '</label> ';
2330: }
2331: $datatable .= '</span><br />'.&mt('Others').': '.
2332: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2333: 'value="'.$otheremails{$type}.'" />';
2334: if ($type eq 'helpdeskmail') {
1.136 raeburn 2335: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2336: '<input type="text" name="'.$type.'_bcc" '.
2337: 'value="'.$bccemails{$type}.'" />';
2338: }
2339: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2340: }
1.30 raeburn 2341: $$rowtotal += $rownum;
1.28 raeburn 2342: return $datatable;
2343: }
2344:
1.118 jms 2345: sub print_helpsettings {
1.160.6.5 raeburn 2346: my ($dom,$confname,$settings,$rowtotal) = @_;
2347: my ($datatable,$itemcount);
2348: $itemcount = 1;
2349: my (%choices,%defaultchecked,@toggles);
2350: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2351: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2352: &mt('LON-CAPA bug tracker'),600,500));
2353: %defaultchecked = ('submitbugs' => 'on');
2354: @toggles = ('submitbugs',);
1.122 jms 2355:
1.160.6.5 raeburn 2356: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2357: \%choices,$itemcount);
2358: return $datatable;
1.121 raeburn 2359: }
2360:
2361: sub radiobutton_prefs {
2362: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2363: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2364: (ref($choices) eq 'HASH'));
2365:
2366: my (%checkedon,%checkedoff,$datatable,$css_class);
2367:
2368: foreach my $item (@{$toggles}) {
2369: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2370: $checkedon{$item} = ' checked="checked" ';
2371: $checkedoff{$item} = ' ';
1.121 raeburn 2372: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2373: $checkedoff{$item} = ' checked="checked" ';
2374: $checkedon{$item} = ' ';
2375: }
2376: }
2377: if (ref($settings) eq 'HASH') {
1.121 raeburn 2378: foreach my $item (@{$toggles}) {
1.118 jms 2379: if ($settings->{$item} eq '1') {
2380: $checkedon{$item} = ' checked="checked" ';
2381: $checkedoff{$item} = ' ';
2382: } elsif ($settings->{$item} eq '0') {
2383: $checkedoff{$item} = ' checked="checked" ';
2384: $checkedon{$item} = ' ';
2385: }
2386: }
1.121 raeburn 2387: }
2388: foreach my $item (@{$toggles}) {
1.118 jms 2389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2390: $datatable .=
2391: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2392: '</span></td>'.
2393: '<td class="LC_right_item"><span class="LC_nobreak">'.
2394: '<label><input type="radio" name="'.
2395: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2396: '</label> <label><input type="radio" name="'.$item.'" '.
2397: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2398: '</span></td>'.
2399: '</tr>';
2400: $itemcount ++;
1.121 raeburn 2401: }
2402: return ($datatable,$itemcount);
2403: }
2404:
2405: sub print_coursedefaults {
1.139 raeburn 2406: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2407: my ($css_class,$datatable);
2408: my $itemcount = 1;
1.139 raeburn 2409: if ($position eq 'top') {
2410: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2411: %choices =
2412: &Apache::lonlocal::texthash (
2413: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2414: );
2415: %defaultchecked = ('canuse_pdfforms' => 'off');
2416: @toggles = ('canuse_pdfforms',);
2417: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2418: \%choices,$itemcount);
1.139 raeburn 2419: $$rowtotal += $itemcount;
2420: } else {
2421: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2422: my %choices =
2423: &Apache::lonlocal::texthash (
2424: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2425: );
2426: my $currdefresponder;
2427: if (ref($settings) eq 'HASH') {
2428: $currdefresponder = $settings->{'anonsurvey_threshold'};
2429: }
2430: if (!$currdefresponder) {
2431: $currdefresponder = 10;
2432: } elsif ($currdefresponder < 1) {
2433: $currdefresponder = 1;
2434: }
2435: $datatable .=
2436: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2437: '</span></td>'.
2438: '<td class="LC_right_item"><span class="LC_nobreak">'.
2439: '<input type="text" name="anonsurvey_threshold"'.
2440: ' value="'.$currdefresponder.'" size="5" /></span>'.
2441: '</td></tr>';
2442: }
1.121 raeburn 2443: return $datatable;
1.118 jms 2444: }
2445:
1.137 raeburn 2446: sub print_usersessions {
2447: my ($position,$dom,$settings,$rowtotal) = @_;
2448: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2449: my (%by_ip,%by_location,@intdoms);
2450: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2451:
2452: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2453: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2454: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2455: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2456: my $itemcount = 1;
2457: if ($position eq 'top') {
1.152 raeburn 2458: if (keys(%serverhomes) > 1) {
1.145 raeburn 2459: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2460: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2461: } else {
1.140 raeburn 2462: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2463: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2464: }
1.137 raeburn 2465: } else {
1.145 raeburn 2466: if (keys(%by_location) == 0) {
2467: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2468: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2469: } else {
2470: my %lt = &usersession_titles();
2471: my $numinrow = 5;
2472: my $prefix;
2473: my @types;
2474: if ($position eq 'bottom') {
2475: $prefix = 'remote';
2476: @types = ('version','excludedomain','includedomain');
2477: } else {
2478: $prefix = 'hosted';
2479: @types = ('excludedomain','includedomain');
2480: }
2481: my (%current,%checkedon,%checkedoff);
2482: my @lcversions = &Apache::lonnet::all_loncaparevs();
2483: my @locations = sort(keys(%by_location));
2484: foreach my $type (@types) {
2485: $checkedon{$type} = '';
2486: $checkedoff{$type} = ' checked="checked"';
2487: }
2488: if (ref($settings) eq 'HASH') {
2489: if (ref($settings->{$prefix}) eq 'HASH') {
2490: foreach my $key (keys(%{$settings->{$prefix}})) {
2491: $current{$key} = $settings->{$prefix}{$key};
2492: if ($key eq 'version') {
2493: if ($current{$key} ne '') {
2494: $checkedon{$key} = ' checked="checked"';
2495: $checkedoff{$key} = '';
2496: }
2497: } elsif (ref($current{$key}) eq 'ARRAY') {
2498: $checkedon{$key} = ' checked="checked"';
2499: $checkedoff{$key} = '';
2500: }
1.137 raeburn 2501: }
2502: }
2503: }
1.145 raeburn 2504: foreach my $type (@types) {
2505: next if ($type ne 'version' && !@locations);
2506: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2507: $datatable .= '<tr'.$css_class.'>
2508: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2509: <span class="LC_nobreak">
2510: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2511: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2512: if ($type eq 'version') {
2513: my $selector = '<select name="'.$prefix.'_version">';
2514: foreach my $version (@lcversions) {
2515: my $selected = '';
2516: if ($current{'version'} eq $version) {
2517: $selected = ' selected="selected"';
2518: }
2519: $selector .= ' <option value="'.$version.'"'.
2520: $selected.'>'.$version.'</option>';
2521: }
2522: $selector .= '</select> ';
2523: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2524: } else {
2525: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2526: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2527: ' />'.(' 'x2).
2528: '<input type="button" value="'.&mt('uncheck all').'" '.
2529: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2530: "\n".
2531: '</div><div><table>';
2532: my $rem;
2533: for (my $i=0; $i<@locations; $i++) {
2534: my ($showloc,$value,$checkedtype);
2535: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2536: my $ip = $by_location{$locations[$i]}->[0];
2537: if (ref($by_ip{$ip}) eq 'ARRAY') {
2538: $value = join(':',@{$by_ip{$ip}});
2539: $showloc = join(', ',@{$by_ip{$ip}});
2540: if (ref($current{$type}) eq 'ARRAY') {
2541: foreach my $loc (@{$by_ip{$ip}}) {
2542: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2543: $checkedtype = ' checked="checked"';
2544: last;
2545: }
2546: }
1.138 raeburn 2547: }
2548: }
2549: }
1.145 raeburn 2550: $rem = $i%($numinrow);
2551: if ($rem == 0) {
2552: if ($i > 0) {
2553: $datatable .= '</tr>';
2554: }
2555: $datatable .= '<tr>';
2556: }
2557: $datatable .= '<td class="LC_left_item">'.
2558: '<span class="LC_nobreak"><label>'.
2559: '<input type="checkbox" name="'.$prefix.'_'.$type.
2560: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2561: '</label></span></td>';
1.137 raeburn 2562: }
1.145 raeburn 2563: $rem = @locations%($numinrow);
2564: my $colsleft = $numinrow - $rem;
2565: if ($colsleft > 1 ) {
2566: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2567: ' </td>';
2568: } elsif ($colsleft == 1) {
2569: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2570: }
1.145 raeburn 2571: $datatable .= '</tr></table>';
1.137 raeburn 2572: }
1.145 raeburn 2573: $datatable .= '</td></tr>';
2574: $itemcount ++;
1.137 raeburn 2575: }
2576: }
2577: }
2578: $$rowtotal += $itemcount;
2579: return $datatable;
2580: }
2581:
1.138 raeburn 2582: sub build_location_hashes {
2583: my ($intdoms,$by_ip,$by_location) = @_;
2584: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2585: (ref($by_location) eq 'HASH'));
2586: my %iphost = &Apache::lonnet::get_iphost();
2587: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2588: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2589: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2590: foreach my $id (@{$iphost{$primary_ip}}) {
2591: my $intdom = &Apache::lonnet::internet_dom($id);
2592: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2593: push(@{$intdoms},$intdom);
2594: }
2595: }
2596: }
2597: foreach my $ip (keys(%iphost)) {
2598: if (ref($iphost{$ip}) eq 'ARRAY') {
2599: foreach my $id (@{$iphost{$ip}}) {
2600: my $location = &Apache::lonnet::internet_dom($id);
2601: if ($location) {
2602: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2603: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2604: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2605: push(@{$by_ip->{$ip}},$location);
2606: }
2607: } else {
2608: $by_ip->{$ip} = [$location];
2609: }
2610: }
2611: }
2612: }
2613: }
2614: foreach my $ip (sort(keys(%{$by_ip}))) {
2615: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2616: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2617: my $first = $by_ip->{$ip}->[0];
2618: if (ref($by_location->{$first}) eq 'ARRAY') {
2619: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2620: push(@{$by_location->{$first}},$ip);
2621: }
2622: } else {
2623: $by_location->{$first} = [$ip];
2624: }
2625: }
2626: }
2627: return;
2628: }
2629:
1.145 raeburn 2630: sub current_offloads_to {
2631: my ($dom,$settings,$servers) = @_;
2632: my (%spareid,%otherdomconfigs);
1.152 raeburn 2633: if (ref($servers) eq 'HASH') {
1.145 raeburn 2634: foreach my $lonhost (sort(keys(%{$servers}))) {
2635: my $gotspares;
1.152 raeburn 2636: if (ref($settings) eq 'HASH') {
2637: if (ref($settings->{'spares'}) eq 'HASH') {
2638: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2639: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2640: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2641: $gotspares = 1;
2642: }
1.145 raeburn 2643: }
2644: }
2645: unless ($gotspares) {
2646: my $gotspares;
2647: my $serverhomeID =
2648: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2649: my $serverhomedom =
2650: &Apache::lonnet::host_domain($serverhomeID);
2651: if ($serverhomedom ne $dom) {
2652: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2653: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2654: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2655: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2656: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2657: $gotspares = 1;
2658: }
2659: }
2660: } else {
2661: $otherdomconfigs{$serverhomedom} =
2662: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2663: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2664: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2665: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2666: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2667: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2668: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2669: $gotspares = 1;
2670: }
2671: }
2672: }
2673: }
2674: }
2675: }
2676: }
2677: unless ($gotspares) {
2678: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2679: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2680: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2681: } else {
2682: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2683: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2684: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2685: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2686: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2687: } else {
1.150 raeburn 2688: my %what = (
2689: spareid => 1,
2690: );
2691: my ($result,$returnhash) =
2692: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2693: if ($result eq 'ok') {
2694: if (ref($returnhash) eq 'HASH') {
2695: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2696: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2697: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2698: }
2699: }
1.145 raeburn 2700: }
2701: }
2702: }
2703: }
2704: }
2705: }
2706: return %spareid;
2707: }
2708:
2709: sub spares_row {
1.152 raeburn 2710: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2711: my $css_class;
2712: my $numinrow = 4;
2713: my $itemcount = 1;
2714: my $datatable;
1.152 raeburn 2715: my %typetitles = &sparestype_titles();
2716: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2717: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2718: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2719: my ($othercontrol,$serverdom);
2720: if ($serverhome ne $server) {
2721: $serverdom = &Apache::lonnet::host_domain($serverhome);
2722: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2723: } else {
2724: $serverdom = &Apache::lonnet::host_domain($server);
2725: if ($serverdom ne $dom) {
2726: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2727: }
2728: }
2729: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2730: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2731: $datatable .= '<tr'.$css_class.'>
2732: <td rowspan="2">
1.152 raeburn 2733: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2734: my (%current,%canselect);
1.152 raeburn 2735: my @choices =
2736: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2737: foreach my $type ('primary','default') {
2738: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2739: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2740: my @spares = @{$spareid->{$server}{$type}};
2741: if (@spares > 0) {
1.152 raeburn 2742: if ($othercontrol) {
2743: $current{$type} = join(', ',@spares);
2744: } else {
2745: $current{$type} .= '<table>';
2746: my $numspares = scalar(@spares);
2747: for (my $i=0; $i<@spares; $i++) {
2748: my $rem = $i%($numinrow);
2749: if ($rem == 0) {
2750: if ($i > 0) {
2751: $current{$type} .= '</tr>';
2752: }
2753: $current{$type} .= '<tr>';
1.145 raeburn 2754: }
1.152 raeburn 2755: $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'".');" /> '.
2756: $spareid->{$server}{$type}[$i].
2757: '</label></td>'."\n";
2758: }
2759: my $rem = @spares%($numinrow);
2760: my $colsleft = $numinrow - $rem;
2761: if ($colsleft > 1 ) {
2762: $current{$type} .= '<td colspan="'.$colsleft.
2763: '" class="LC_left_item">'.
2764: ' </td>';
2765: } elsif ($colsleft == 1) {
2766: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2767: }
1.152 raeburn 2768: $current{$type} .= '</tr></table>';
1.150 raeburn 2769: }
1.145 raeburn 2770: }
2771: }
2772: if ($current{$type} eq '') {
2773: $current{$type} = &mt('None specified');
2774: }
1.152 raeburn 2775: if ($othercontrol) {
2776: if ($type eq 'primary') {
2777: $canselect{$type} = $othercontrol;
2778: }
2779: } else {
2780: $canselect{$type} =
2781: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2782: '<select name="newspare_'.$type.'_'.$server.'" '.
2783: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2784: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2785: if (@choices > 0) {
2786: foreach my $lonhost (@choices) {
2787: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2788: }
2789: }
2790: $canselect{$type} .= '</select>'."\n";
2791: }
2792: } else {
2793: $current{$type} = &mt('Could not be determined');
2794: if ($type eq 'primary') {
2795: $canselect{$type} = $othercontrol;
2796: }
1.145 raeburn 2797: }
1.152 raeburn 2798: if ($type eq 'default') {
2799: $datatable .= '<tr'.$css_class.'>';
2800: }
2801: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2802: '<td>'.$current{$type}.'</td>'."\n".
2803: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2804: }
2805: $itemcount ++;
2806: }
2807: }
2808: $$rowtotal += $itemcount;
2809: return $datatable;
2810: }
2811:
1.152 raeburn 2812: sub possible_newspares {
2813: my ($server,$currspares,$serverhomes,$altids) = @_;
2814: my $serverhostname = &Apache::lonnet::hostname($server);
2815: my %excluded;
2816: if ($serverhostname ne '') {
2817: %excluded = (
2818: $serverhostname => 1,
2819: );
2820: }
2821: if (ref($currspares) eq 'HASH') {
2822: foreach my $type (keys(%{$currspares})) {
2823: if (ref($currspares->{$type}) eq 'ARRAY') {
2824: if (@{$currspares->{$type}} > 0) {
2825: foreach my $curr (@{$currspares->{$type}}) {
2826: my $hostname = &Apache::lonnet::hostname($curr);
2827: $excluded{$hostname} = 1;
2828: }
2829: }
2830: }
2831: }
2832: }
2833: my @choices;
2834: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2835: if (keys(%{$serverhomes}) > 1) {
2836: foreach my $name (sort(keys(%{$serverhomes}))) {
2837: unless ($excluded{$name}) {
2838: if (exists($altids->{$serverhomes->{$name}})) {
2839: push(@choices,$altids->{$serverhomes->{$name}});
2840: } else {
2841: push(@choices,$serverhomes->{$name});
1.145 raeburn 2842: }
2843: }
2844: }
2845: }
2846: }
1.152 raeburn 2847: return sort(@choices);
1.145 raeburn 2848: }
2849:
1.150 raeburn 2850: sub print_loadbalancing {
2851: my ($dom,$settings,$rowtotal) = @_;
2852: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2853: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2854: my $numinrow = 1;
2855: my $datatable;
2856: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7! raeburn 2857: my (%currbalancer,%currtargets,%currrules,%existing);
! 2858: if (ref($settings) eq 'HASH') {
! 2859: %existing = %{$settings};
! 2860: }
! 2861: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
! 2862: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
! 2863: \%currtargets,\%currrules);
1.150 raeburn 2864: } else {
2865: return;
2866: }
2867: my ($othertitle,$usertypes,$types) =
2868: &Apache::loncommon::sorted_inst_types($dom);
2869: my $rownum = 6;
2870: if (ref($types) eq 'ARRAY') {
2871: $rownum += scalar(@{$types});
2872: }
1.160.6.7! raeburn 2873: my @css_class = ('LC_odd_row','LC_even_row');
! 2874: my $balnum = 0;
! 2875: my $islast;
! 2876: my (@toshow,$disabledtext);
! 2877: if (keys(%currbalancer) > 0) {
! 2878: @toshow = sort(keys(%currbalancer));
! 2879: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
! 2880: push(@toshow,'');
! 2881: }
! 2882: } else {
! 2883: @toshow = ('');
! 2884: $disabledtext = &mt('No existing load balancer');
! 2885: }
! 2886: foreach my $lonhost (@toshow) {
! 2887: if ($balnum == scalar(@toshow)-1) {
! 2888: $islast = 1;
! 2889: } else {
! 2890: $islast = 0;
! 2891: }
! 2892: my $cssidx = $balnum%2;
! 2893: my $targets_div_style = 'display: none';
! 2894: my $disabled_div_style = 'display: block';
! 2895: my $homedom_div_style = 'display: none';
! 2896: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
! 2897: '<td rowspan="'.$rownum.'" valign="top">'.
! 2898: '<p>';
! 2899: if ($lonhost eq '') {
! 2900: $datatable .= '<span class="LC_nobreak">';
! 2901: if (keys(%currbalancer) > 0) {
! 2902: $datatable .= &mt('Add balancer:');
! 2903: } else {
! 2904: $datatable .= &mt('Enable balancer:');
! 2905: }
! 2906: $datatable .= ' '.
! 2907: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
! 2908: ' id="loadbalancing_lonhost_'.$balnum.'"'.
! 2909: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
! 2910: '<option value="" selected="selected">'.&mt('None').
! 2911: '</option>'."\n";
! 2912: foreach my $server (sort(keys(%servers))) {
! 2913: next if ($currbalancer{$server});
! 2914: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
! 2915: }
! 2916: $datatable .=
! 2917: '</select>'."\n".
! 2918: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
! 2919: } else {
! 2920: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
! 2921: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
! 2922: &mt('Stop balancing').'</label>'.
! 2923: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
! 2924: $targets_div_style = 'display: block';
! 2925: $disabled_div_style = 'display: none';
! 2926: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
! 2927: $homedom_div_style = 'display: block';
! 2928: }
! 2929: }
! 2930: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
! 2931: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
! 2932: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
! 2933: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
! 2934: my ($numspares,@spares) = &count_servers($lonhost,%servers);
! 2935: my @sparestypes = ('primary','default');
! 2936: my %typetitles = &sparestype_titles();
! 2937: foreach my $sparetype (@sparestypes) {
! 2938: my $targettable;
! 2939: for (my $i=0; $i<$numspares; $i++) {
! 2940: my $checked;
! 2941: if (ref($currtargets{$lonhost}) eq 'HASH') {
! 2942: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
! 2943: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
! 2944: $checked = ' checked="checked"';
! 2945: }
! 2946: }
! 2947: }
! 2948: my ($chkboxval,$disabled);
! 2949: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
! 2950: $chkboxval = $spares[$i];
! 2951: }
! 2952: if (exists($currbalancer{$spares[$i]})) {
! 2953: $disabled = ' disabled="disabled"';
! 2954: }
! 2955: $targettable .=
! 2956: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
! 2957: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
! 2958: '</span></label></td>';
! 2959: my $rem = $i%($numinrow);
! 2960: if ($rem == 0) {
! 2961: if (($i > 0) && ($i < $numspares-1)) {
! 2962: $targettable .= '</tr>';
! 2963: }
! 2964: if ($i < $numspares-1) {
! 2965: $targettable .= '<tr>';
1.150 raeburn 2966: }
2967: }
2968: }
1.160.6.7! raeburn 2969: if ($targettable ne '') {
! 2970: my $rem = $numspares%($numinrow);
! 2971: my $colsleft = $numinrow - $rem;
! 2972: if ($colsleft > 1 ) {
! 2973: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
! 2974: ' </td>';
! 2975: } elsif ($colsleft == 1) {
! 2976: $targettable .= '<td class="LC_left_item"> </td>';
! 2977: }
! 2978: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
! 2979: '<table><tr>'.$targettable.'</tr></table><br />';
! 2980: }
! 2981: }
! 2982: my $cssidx = $balnum%2;
! 2983: $datatable .= '</div></td></tr>'.
! 2984: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
! 2985: $othertitle,$usertypes,$types,\%servers,
! 2986: \%currbalancer,$lonhost,
! 2987: $targets_div_style,$homedom_div_style,
! 2988: $css_class[$cssidx],$balnum,$islast);
! 2989: $$rowtotal += $rownum;
! 2990: $balnum ++;
! 2991: }
! 2992: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
! 2993: return $datatable;
! 2994: }
! 2995:
! 2996: sub get_loadbalancers_config {
! 2997: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
! 2998: return unless ((ref($servers) eq 'HASH') &&
! 2999: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
! 3000: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
! 3001: if (keys(%{$existing}) > 0) {
! 3002: my $oldlonhost;
! 3003: foreach my $key (sort(keys(%{$existing}))) {
! 3004: if ($key eq 'lonhost') {
! 3005: $oldlonhost = $existing->{'lonhost'};
! 3006: $currbalancer->{$oldlonhost} = 1;
! 3007: } elsif ($key eq 'targets') {
! 3008: if ($oldlonhost) {
! 3009: $currtargets->{$oldlonhost} = $existing->{'targets'};
! 3010: }
! 3011: } elsif ($key eq 'rules') {
! 3012: if ($oldlonhost) {
! 3013: $currrules->{$oldlonhost} = $existing->{'rules'};
! 3014: }
! 3015: } elsif (ref($existing->{$key}) eq 'HASH') {
! 3016: $currbalancer->{$key} = 1;
! 3017: $currtargets->{$key} = $existing->{$key}{'targets'};
! 3018: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3019: }
3020: }
1.160.6.7! raeburn 3021: } else {
! 3022: my ($balancerref,$targetsref) =
! 3023: &Apache::lonnet::get_lonbalancer_config($servers);
! 3024: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
! 3025: foreach my $server (sort(keys(%{$balancerref}))) {
! 3026: $currbalancer->{$server} = 1;
! 3027: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3028: }
3029: }
3030: }
1.160.6.7! raeburn 3031: return;
1.150 raeburn 3032: }
3033:
3034: sub loadbalancing_rules {
3035: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7! raeburn 3036: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
! 3037: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3038: my $output;
1.160.6.7! raeburn 3039: my $num = 0;
! 3040: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3041: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3042: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3043: foreach my $type (@{$alltypes}) {
1.160.6.7! raeburn 3044: $num ++;
1.150 raeburn 3045: my $current;
3046: if (ref($currrules) eq 'HASH') {
3047: $current = $currrules->{$type};
3048: }
3049: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7! raeburn 3050: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3051: $current = '';
3052: }
3053: }
3054: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7! raeburn 3055: $servers,$currbalancer,$lonhost,$dom,
! 3056: $targets_div_style,$homedom_div_style,
! 3057: $css_class,$balnum,$num,$islast);
1.150 raeburn 3058: }
3059: }
3060: return $output;
3061: }
3062:
3063: sub loadbalancing_titles {
3064: my ($dom,$intdom,$usertypes,$types) = @_;
3065: my %othertypes = (
3066: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3067: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3068: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3069: '_LC_external' => &mt('Users not from [_1]',$intdom),
3070: );
3071: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3072: if (ref($types) eq 'ARRAY') {
3073: unshift(@alltypes,@{$types},'default');
3074: }
3075: my %titles;
3076: foreach my $type (@alltypes) {
3077: if ($type =~ /^_LC_/) {
3078: $titles{$type} = $othertypes{$type};
3079: } elsif ($type eq 'default') {
3080: $titles{$type} = &mt('All users from [_1]',$dom);
3081: if (ref($types) eq 'ARRAY') {
3082: if (@{$types} > 0) {
3083: $titles{$type} = &mt('Other users from [_1]',$dom);
3084: }
3085: }
3086: } elsif (ref($usertypes) eq 'HASH') {
3087: $titles{$type} = $usertypes->{$type};
3088: }
3089: }
3090: return (\@alltypes,\%othertypes,\%titles);
3091: }
3092:
3093: sub loadbalance_rule_row {
1.160.6.7! raeburn 3094: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
! 3095: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3096: my @rulenames = ('default','homeserver');
3097: my %ruletitles = &offloadtype_text();
3098: if ($type eq '_LC_external') {
3099: push(@rulenames,'externalbalancer');
3100: } else {
3101: push(@rulenames,'specific');
3102: }
1.160.6.3 raeburn 3103: push(@rulenames,'none');
1.150 raeburn 3104: my $style = $targets_div_style;
3105: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3106: $style = $homedom_div_style;
3107: }
1.160.6.7! raeburn 3108: my $space;
! 3109: if ($islast && $num == 1) {
! 3110: $space = '<div display="inline-block"> </div>';
! 3111: }
! 3112: my $output =
! 3113: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
! 3114: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
! 3115: '<td valaign="top">'.$space.
! 3116: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3117: for (my $i=0; $i<@rulenames; $i++) {
3118: my $rule = $rulenames[$i];
3119: my ($checked,$extra);
3120: if ($rulenames[$i] eq 'default') {
3121: $rule = '';
3122: }
3123: if ($rulenames[$i] eq 'specific') {
3124: if (ref($servers) eq 'HASH') {
3125: my $default;
3126: if (($current ne '') && (exists($servers->{$current}))) {
3127: $checked = ' checked="checked"';
3128: }
3129: unless ($checked) {
3130: $default = ' selected="selected"';
3131: }
1.160.6.7! raeburn 3132: $extra =
! 3133: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
! 3134: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
! 3135: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
! 3136: '<option value=""'.$default.'></option>'."\n";
! 3137: foreach my $server (sort(keys(%{$servers}))) {
! 3138: if (ref($currbalancer) eq 'HASH') {
! 3139: next if (exists($currbalancer->{$server}));
! 3140: }
1.150 raeburn 3141: my $selected;
1.160.6.7! raeburn 3142: if ($server eq $current) {
1.150 raeburn 3143: $selected = ' selected="selected"';
3144: }
1.160.6.7! raeburn 3145: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3146: }
3147: $extra .= '</select>';
3148: }
3149: } elsif ($rule eq $current) {
3150: $checked = ' checked="checked"';
3151: }
3152: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7! raeburn 3153: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
! 3154: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
! 3155: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3156: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3157: '</label>'.$extra.'</span><br />'."\n";
3158: }
3159: $output .= '</div></td></tr>'."\n";
3160: return $output;
3161: }
3162:
3163: sub offloadtype_text {
3164: my %ruletitles = &Apache::lonlocal::texthash (
3165: 'default' => 'Offloads to default destinations',
3166: 'homeserver' => "Offloads to user's home server",
3167: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3168: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3169: 'none' => 'No offload',
1.150 raeburn 3170: );
3171: return %ruletitles;
3172: }
3173:
3174: sub sparestype_titles {
3175: my %typestitles = &Apache::lonlocal::texthash (
3176: 'primary' => 'primary',
3177: 'default' => 'default',
3178: );
3179: return %typestitles;
3180: }
3181:
1.28 raeburn 3182: sub contact_titles {
3183: my %titles = &Apache::lonlocal::texthash (
3184: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3185: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3186: 'errormail' => 'Error reports to be e-mailed to',
3187: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3188: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3189: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3190: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3191: );
3192: my %short_titles = &Apache::lonlocal::texthash (
3193: adminemail => 'Admin E-mail address',
3194: supportemail => 'Support E-mail',
3195: );
3196: return (\%titles,\%short_titles);
3197: }
3198:
1.72 raeburn 3199: sub tool_titles {
3200: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3201: aboutme => 'Personal web page',
1.86 raeburn 3202: blog => 'Blog',
1.160.6.4 raeburn 3203: webdav => 'WebDAV',
1.86 raeburn 3204: portfolio => 'Portfolio',
1.88 bisitz 3205: official => 'Official courses (with institutional codes)',
3206: unofficial => 'Unofficial courses',
1.98 raeburn 3207: community => 'Communities',
1.86 raeburn 3208: );
1.72 raeburn 3209: return %titles;
3210: }
3211:
1.101 raeburn 3212: sub courserequest_titles {
3213: my %titles = &Apache::lonlocal::texthash (
3214: official => 'Official',
3215: unofficial => 'Unofficial',
3216: community => 'Communities',
3217: norequest => 'Not allowed',
1.104 raeburn 3218: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3219: validate => 'With validation',
3220: autolimit => 'Numerical limit',
1.103 raeburn 3221: unlimited => '(blank for unlimited)',
1.101 raeburn 3222: );
3223: return %titles;
3224: }
3225:
1.160.6.5 raeburn 3226: sub authorrequest_titles {
3227: my %titles = &Apache::lonlocal::texthash (
3228: norequest => 'Not allowed',
3229: approval => 'Approval by Dom. Coord.',
3230: automatic => 'Automatic approval',
3231: );
3232: return %titles;
3233: }
3234:
1.101 raeburn 3235: sub courserequest_conditions {
3236: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3237: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3238: validate => '(Processing of request subject to instittutional validation).',
3239: );
3240: return %conditions;
3241: }
3242:
3243:
1.27 raeburn 3244: sub print_usercreation {
1.30 raeburn 3245: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3246: my $numinrow = 4;
1.28 raeburn 3247: my $datatable;
3248: if ($position eq 'top') {
1.30 raeburn 3249: $$rowtotal ++;
1.34 raeburn 3250: my $rowcount = 0;
1.32 raeburn 3251: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3252: if (ref($rules) eq 'HASH') {
3253: if (keys(%{$rules}) > 0) {
1.32 raeburn 3254: $datatable .= &user_formats_row('username',$settings,$rules,
3255: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3256: $$rowtotal ++;
1.32 raeburn 3257: $rowcount ++;
3258: }
3259: }
3260: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3261: if (ref($idrules) eq 'HASH') {
3262: if (keys(%{$idrules}) > 0) {
3263: $datatable .= &user_formats_row('id',$settings,$idrules,
3264: $idruleorder,$numinrow,$rowcount);
3265: $$rowtotal ++;
3266: $rowcount ++;
1.28 raeburn 3267: }
3268: }
1.43 raeburn 3269: my ($emailrules,$emailruleorder) =
3270: &Apache::lonnet::inst_userrules($dom,'email');
3271: if (ref($emailrules) eq 'HASH') {
3272: if (keys(%{$emailrules}) > 0) {
3273: $datatable .= &user_formats_row('email',$settings,$emailrules,
3274: $emailruleorder,$numinrow,$rowcount);
3275: $$rowtotal ++;
3276: $rowcount ++;
3277: }
3278: }
1.39 raeburn 3279: if ($rowcount == 0) {
3280: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3281: $$rowtotal ++;
3282: $rowcount ++;
3283: }
1.34 raeburn 3284: } elsif ($position eq 'middle') {
1.100 raeburn 3285: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3286: my ($rules,$ruleorder) =
3287: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3288: my %lt = &usercreation_types();
3289: my %checked;
1.50 raeburn 3290: my @selfcreate;
1.34 raeburn 3291: if (ref($settings) eq 'HASH') {
3292: if (ref($settings->{'cancreate'}) eq 'HASH') {
3293: foreach my $item (@creators) {
3294: $checked{$item} = $settings->{'cancreate'}{$item};
3295: }
1.50 raeburn 3296: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3297: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3298: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3299: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3300: @selfcreate = ('email','login','sso');
3301: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3302: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3303: }
3304: }
1.34 raeburn 3305: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3306: foreach my $item (@creators) {
3307: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3308: $checked{$item} = 'none';
3309: }
3310: }
3311: }
3312: }
3313: my $rownum = 0;
3314: foreach my $item (@creators) {
3315: $rownum ++;
1.50 raeburn 3316: if ($item ne 'selfcreate') {
3317: if ($checked{$item} eq '') {
1.43 raeburn 3318: $checked{$item} = 'any';
3319: }
1.34 raeburn 3320: }
3321: my $css_class;
3322: if ($rownum%2) {
3323: $css_class = '';
3324: } else {
3325: $css_class = ' class="LC_odd_row" ';
3326: }
3327: $datatable .= '<tr'.$css_class.'>'.
3328: '<td><span class="LC_nobreak">'.$lt{$item}.
3329: '</span></td><td align="right">';
1.50 raeburn 3330: my @options;
1.45 raeburn 3331: if ($item eq 'selfcreate') {
1.43 raeburn 3332: push(@options,('email','login','sso'));
3333: } else {
1.50 raeburn 3334: @options = ('any');
1.43 raeburn 3335: if (ref($rules) eq 'HASH') {
3336: if (keys(%{$rules}) > 0) {
3337: push(@options,('official','unofficial'));
3338: }
1.37 raeburn 3339: }
1.50 raeburn 3340: push(@options,'none');
1.37 raeburn 3341: }
3342: foreach my $option (@options) {
1.50 raeburn 3343: my $type = 'radio';
1.34 raeburn 3344: my $check = ' ';
1.50 raeburn 3345: if ($item eq 'selfcreate') {
3346: $type = 'checkbox';
3347: if (grep(/^\Q$option\E$/,@selfcreate)) {
3348: $check = ' checked="checked" ';
3349: }
3350: } else {
3351: if ($checked{$item} eq $option) {
3352: $check = ' checked="checked" ';
3353: }
1.34 raeburn 3354: }
3355: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3356: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3357: $item.'" value="'.$option.'"'.$check.'/> '.
3358: $lt{$option}.'</label> </span>';
3359: }
3360: $datatable .= '</td></tr>';
3361: }
1.93 raeburn 3362: my ($othertitle,$usertypes,$types) =
3363: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3364: my $createsettings;
3365: if (ref($settings) eq 'HASH') {
3366: $createsettings = $settings->{cancreate};
3367: }
1.93 raeburn 3368: if (ref($usertypes) eq 'HASH') {
3369: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3370: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3371: $dom,$numinrow,$othertitle,
3372: 'statustocreate');
3373: $$rowtotal ++;
1.160.6.5 raeburn 3374: $rownum ++;
1.93 raeburn 3375: }
3376: }
1.160.6.5 raeburn 3377: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3378: } else {
3379: my @contexts = ('author','course','domain');
3380: my @authtypes = ('int','krb4','krb5','loc');
3381: my %checked;
3382: if (ref($settings) eq 'HASH') {
3383: if (ref($settings->{'authtypes'}) eq 'HASH') {
3384: foreach my $item (@contexts) {
3385: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3386: foreach my $auth (@authtypes) {
3387: if ($settings->{'authtypes'}{$item}{$auth}) {
3388: $checked{$item}{$auth} = ' checked="checked" ';
3389: }
3390: }
3391: }
3392: }
1.27 raeburn 3393: }
1.35 raeburn 3394: } else {
3395: foreach my $item (@contexts) {
1.36 raeburn 3396: foreach my $auth (@authtypes) {
1.35 raeburn 3397: $checked{$item}{$auth} = ' checked="checked" ';
3398: }
3399: }
1.27 raeburn 3400: }
1.28 raeburn 3401: my %title = &context_names();
3402: my %authname = &authtype_names();
3403: my $rownum = 0;
3404: my $css_class;
3405: foreach my $item (@contexts) {
3406: if ($rownum%2) {
3407: $css_class = '';
3408: } else {
3409: $css_class = ' class="LC_odd_row" ';
3410: }
1.30 raeburn 3411: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3412: '<td>'.$title{$item}.
3413: '</td><td class="LC_left_item">'.
3414: '<span class="LC_nobreak">';
3415: foreach my $auth (@authtypes) {
3416: $datatable .= '<label>'.
3417: '<input type="checkbox" name="'.$item.'_auth" '.
3418: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3419: $authname{$auth}.'</label> ';
3420: }
3421: $datatable .= '</span></td></tr>';
3422: $rownum ++;
1.27 raeburn 3423: }
1.30 raeburn 3424: $$rowtotal += $rownum;
1.27 raeburn 3425: }
3426: return $datatable;
3427: }
3428:
1.160.6.5 raeburn 3429: sub captcha_choice {
3430: my ($context,$settings,$itemcount) = @_;
3431: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3432: my %lt = &captcha_phrases();
3433: $keyentry = 'hidden';
3434: if ($context eq 'cancreate') {
3435: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3436: } elsif ($context eq 'login') {
3437: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3438: }
3439: if (ref($settings) eq 'HASH') {
3440: if ($settings->{'captcha'}) {
3441: $checked{$settings->{'captcha'}} = ' checked="checked"';
3442: } else {
3443: $checked{'original'} = ' checked="checked"';
3444: }
3445: if ($settings->{'captcha'} eq 'recaptcha') {
3446: $pubtext = $lt{'pub'};
3447: $privtext = $lt{'priv'};
3448: $keyentry = 'text';
3449: }
3450: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3451: $currpub = $settings->{'recaptchakeys'}{'public'};
3452: $currpriv = $settings->{'recaptchakeys'}{'private'};
3453: }
3454: } else {
3455: $checked{'original'} = ' checked="checked"';
3456: }
3457: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3458: my $output = '<tr'.$css_class.'>'.
3459: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3460: '<table><tr><td>'."\n";
3461: foreach my $option ('original','recaptcha','notused') {
3462: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3463: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3464: $lt{$option}.'</label></span>';
3465: unless ($option eq 'notused') {
3466: $output .= (' 'x2)."\n";
3467: }
3468: }
3469: #
3470: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3471: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3472: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3473: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3474: #
3475: $output .= '</td></tr>'."\n".
3476: '<tr><td>'."\n".
3477: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3478: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3479: $currpub.'" size="40" /></span><br />'."\n".
3480: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3481: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3482: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3483: '</td></tr>';
3484: return $output;
3485: }
3486:
1.32 raeburn 3487: sub user_formats_row {
3488: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3489: my $output;
3490: my %text = (
3491: 'username' => 'new usernames',
3492: 'id' => 'IDs',
1.45 raeburn 3493: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3494: );
3495: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3496: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3497: '<td><span class="LC_nobreak">';
3498: if ($type eq 'email') {
3499: $output .= &mt("Formats disallowed for $text{$type}: ");
3500: } else {
3501: $output .= &mt("Format rules to check for $text{$type}: ");
3502: }
3503: $output .= '</span></td>'.
3504: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3505: my $rem;
3506: if (ref($ruleorder) eq 'ARRAY') {
3507: for (my $i=0; $i<@{$ruleorder}; $i++) {
3508: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3509: my $rem = $i%($numinrow);
3510: if ($rem == 0) {
3511: if ($i > 0) {
3512: $output .= '</tr>';
3513: }
3514: $output .= '<tr>';
3515: }
3516: my $check = ' ';
1.39 raeburn 3517: if (ref($settings) eq 'HASH') {
3518: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3519: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3520: $check = ' checked="checked" ';
3521: }
1.27 raeburn 3522: }
3523: }
3524: $output .= '<td class="LC_left_item">'.
3525: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3526: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3527: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3528: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3529: }
3530: }
3531: $rem = @{$ruleorder}%($numinrow);
3532: }
3533: my $colsleft = $numinrow - $rem;
3534: if ($colsleft > 1 ) {
3535: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3536: ' </td>';
3537: } elsif ($colsleft == 1) {
3538: $output .= '<td class="LC_left_item"> </td>';
3539: }
3540: $output .= '</tr></table></td></tr>';
3541: return $output;
3542: }
3543:
1.34 raeburn 3544: sub usercreation_types {
3545: my %lt = &Apache::lonlocal::texthash (
3546: author => 'When adding a co-author',
3547: course => 'When adding a user to a course',
1.100 raeburn 3548: requestcrs => 'When requesting a course',
1.45 raeburn 3549: selfcreate => 'User creates own account',
1.34 raeburn 3550: any => 'Any',
3551: official => 'Institutional only ',
3552: unofficial => 'Non-institutional only',
1.85 schafran 3553: email => 'E-mail address',
1.43 raeburn 3554: login => 'Institutional Login',
3555: sso => 'SSO',
1.34 raeburn 3556: none => 'None',
3557: );
3558: return %lt;
1.48 raeburn 3559: }
1.34 raeburn 3560:
1.28 raeburn 3561: sub authtype_names {
3562: my %lt = &Apache::lonlocal::texthash(
3563: int => 'Internal',
3564: krb4 => 'Kerberos 4',
3565: krb5 => 'Kerberos 5',
3566: loc => 'Local',
3567: );
3568: return %lt;
3569: }
3570:
3571: sub context_names {
3572: my %context_title = &Apache::lonlocal::texthash(
3573: author => 'Creating users when an Author',
3574: course => 'Creating users when in a course',
3575: domain => 'Creating users when a Domain Coordinator',
3576: );
3577: return %context_title;
3578: }
3579:
1.33 raeburn 3580: sub print_usermodification {
3581: my ($position,$dom,$settings,$rowtotal) = @_;
3582: my $numinrow = 4;
3583: my ($context,$datatable,$rowcount);
3584: if ($position eq 'top') {
3585: $rowcount = 0;
3586: $context = 'author';
3587: foreach my $role ('ca','aa') {
3588: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3589: $numinrow,$rowcount);
3590: $$rowtotal ++;
3591: $rowcount ++;
3592: }
1.63 raeburn 3593: } elsif ($position eq 'middle') {
1.33 raeburn 3594: $context = 'course';
3595: $rowcount = 0;
3596: foreach my $role ('st','ep','ta','in','cr') {
3597: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3598: $numinrow,$rowcount);
3599: $$rowtotal ++;
3600: $rowcount ++;
3601: }
1.63 raeburn 3602: } elsif ($position eq 'bottom') {
3603: $context = 'selfcreate';
3604: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3605: $usertypes->{'default'} = $othertitle;
3606: if (ref($types) eq 'ARRAY') {
3607: push(@{$types},'default');
3608: $usertypes->{'default'} = $othertitle;
3609: foreach my $status (@{$types}) {
3610: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3611: $numinrow,$rowcount,$usertypes);
3612: $$rowtotal ++;
3613: $rowcount ++;
3614: }
3615: }
1.33 raeburn 3616: }
3617: return $datatable;
3618: }
3619:
1.43 raeburn 3620: sub print_defaults {
3621: my ($dom,$rowtotal) = @_;
1.68 raeburn 3622: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3623: 'datelocale_def','portal_def');
1.43 raeburn 3624: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3625: my $titles = &defaults_titles($dom);
1.43 raeburn 3626: my $rownum = 0;
3627: my ($datatable,$css_class);
3628: foreach my $item (@items) {
3629: if ($rownum%2) {
3630: $css_class = '';
3631: } else {
3632: $css_class = ' class="LC_odd_row" ';
3633: }
3634: $datatable .= '<tr'.$css_class.'>'.
3635: '<td><span class="LC_nobreak">'.$titles->{$item}.
3636: '</span></td><td class="LC_right_item">';
3637: if ($item eq 'auth_def') {
3638: my @authtypes = ('internal','krb4','krb5','localauth');
3639: my %shortauth = (
3640: internal => 'int',
3641: krb4 => 'krb4',
3642: krb5 => 'krb5',
3643: localauth => 'loc'
3644: );
3645: my %authnames = &authtype_names();
3646: foreach my $auth (@authtypes) {
3647: my $checked = ' ';
3648: if ($domdefaults{$item} eq $auth) {
3649: $checked = ' checked="checked" ';
3650: }
3651: $datatable .= '<label><input type="radio" name="'.$item.
3652: '" value="'.$auth.'"'.$checked.'/>'.
3653: $authnames{$shortauth{$auth}}.'</label> ';
3654: }
1.54 raeburn 3655: } elsif ($item eq 'timezone_def') {
3656: my $includeempty = 1;
3657: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3658: } elsif ($item eq 'datelocale_def') {
3659: my $includeempty = 1;
3660: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3661: } elsif ($item eq 'lang_def') {
3662: my %langchoices = &get_languages_hash();
3663: $langchoices{''} = 'No language preference';
3664: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3665: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3666: \%langchoices);
1.43 raeburn 3667: } else {
1.141 raeburn 3668: my $size;
3669: if ($item eq 'portal_def') {
3670: $size = ' size="25"';
3671: }
1.43 raeburn 3672: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3673: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3674: }
3675: $datatable .= '</td></tr>';
3676: $rownum ++;
3677: }
3678: $$rowtotal += $rownum;
3679: return $datatable;
3680: }
3681:
1.160.6.5 raeburn 3682: sub get_languages_hash {
3683: my %langchoices;
3684: foreach my $id (&Apache::loncommon::languageids()) {
3685: my $code = &Apache::loncommon::supportedlanguagecode($id);
3686: if ($code ne '') {
3687: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3688: }
3689: }
3690: return %langchoices;
3691: }
3692:
1.43 raeburn 3693: sub defaults_titles {
1.141 raeburn 3694: my ($dom) = @_;
1.43 raeburn 3695: my %titles = &Apache::lonlocal::texthash (
3696: 'auth_def' => 'Default authentication type',
3697: 'auth_arg_def' => 'Default authentication argument',
3698: 'lang_def' => 'Default language',
1.54 raeburn 3699: 'timezone_def' => 'Default timezone',
1.68 raeburn 3700: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3701: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3702: );
1.141 raeburn 3703: if ($dom) {
3704: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3705: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3706: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3707: $protocol = 'http' if ($protocol ne 'https');
3708: if ($uint_dom) {
3709: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3710: $uint_dom);
3711: }
3712: }
1.43 raeburn 3713: return (\%titles);
3714: }
3715:
1.46 raeburn 3716: sub print_scantronformat {
3717: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3718: my $itemcount = 1;
1.60 raeburn 3719: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3720: %confhash);
1.46 raeburn 3721: my $switchserver = &check_switchserver($dom,$confname);
3722: my %lt = &Apache::lonlocal::texthash (
1.95 www 3723: default => 'Default bubblesheet format file error',
3724: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3725: );
3726: my %scantronfiles = (
3727: default => 'default.tab',
3728: custom => 'custom.tab',
3729: );
3730: foreach my $key (keys(%scantronfiles)) {
3731: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3732: .$scantronfiles{$key};
3733: }
3734: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3735: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3736: if (!$switchserver) {
3737: my $servadm = $r->dir_config('lonAdmEMail');
3738: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3739: if ($configuserok eq 'ok') {
3740: if ($author_ok eq 'ok') {
3741: my %legacyfile = (
3742: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3743: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3744: );
3745: my %md5chk;
3746: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3747: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3748: chomp($md5chk{$type});
1.46 raeburn 3749: }
3750: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3751: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3752: ($scantronurls{$type},my $error) =
1.46 raeburn 3753: &legacy_scantronformat($r,$dom,$confname,
3754: $type,$legacyfile{$type},
3755: $scantronurls{$type},
3756: $scantronfiles{$type});
1.60 raeburn 3757: if ($error ne '') {
3758: $error{$type} = $error;
3759: }
3760: }
3761: if (keys(%error) == 0) {
3762: $is_custom = 1;
3763: $confhash{'scantron'}{'scantronformat'} =
3764: $scantronurls{'custom'};
3765: my $putresult =
3766: &Apache::lonnet::put_dom('configuration',
3767: \%confhash,$dom);
3768: if ($putresult ne 'ok') {
3769: $error{'custom'} =
3770: '<span class="LC_error">'.
3771: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3772: }
1.46 raeburn 3773: }
3774: } else {
1.60 raeburn 3775: ($scantronurls{'default'},my $error) =
1.46 raeburn 3776: &legacy_scantronformat($r,$dom,$confname,
3777: 'default',$legacyfile{'default'},
3778: $scantronurls{'default'},
3779: $scantronfiles{'default'});
1.60 raeburn 3780: if ($error eq '') {
3781: $confhash{'scantron'}{'scantronformat'} = '';
3782: my $putresult =
3783: &Apache::lonnet::put_dom('configuration',
3784: \%confhash,$dom);
3785: if ($putresult ne 'ok') {
3786: $error{'default'} =
3787: '<span class="LC_error">'.
3788: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3789: }
3790: } else {
3791: $error{'default'} = $error;
3792: }
1.46 raeburn 3793: }
3794: }
3795: }
3796: } else {
1.95 www 3797: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3798: }
3799: }
3800: if (ref($settings) eq 'HASH') {
3801: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3802: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3803: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3804: $scantronurl = '';
3805: } else {
3806: $scantronurl = $settings->{'scantronformat'};
3807: }
3808: $is_custom = 1;
3809: } else {
3810: $scantronurl = $scantronurls{'default'};
3811: }
3812: } else {
1.60 raeburn 3813: if ($is_custom) {
3814: $scantronurl = $scantronurls{'custom'};
3815: } else {
3816: $scantronurl = $scantronurls{'default'};
3817: }
1.46 raeburn 3818: }
3819: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3820: $datatable .= '<tr'.$css_class.'>';
3821: if (!$is_custom) {
1.65 raeburn 3822: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3823: '<span class="LC_nobreak">';
1.46 raeburn 3824: if ($scantronurl) {
3825: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3826: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3827: } else {
3828: $datatable = &mt('File unavailable for display');
3829: }
1.65 raeburn 3830: $datatable .= '</span></td>';
1.60 raeburn 3831: if (keys(%error) == 0) {
3832: $datatable .= '<td valign="bottom">';
3833: if (!$switchserver) {
3834: $datatable .= &mt('Upload:').'<br />';
3835: }
3836: } else {
3837: my $errorstr;
3838: foreach my $key (sort(keys(%error))) {
3839: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3840: }
3841: $datatable .= '<td>'.$errorstr;
3842: }
1.46 raeburn 3843: } else {
3844: if (keys(%error) > 0) {
3845: my $errorstr;
3846: foreach my $key (sort(keys(%error))) {
3847: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3848: }
1.60 raeburn 3849: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3850: } elsif ($scantronurl) {
1.65 raeburn 3851: $datatable .= '<td><span class="LC_nobreak">'.
3852: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3853: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3854: '<input type="checkbox" name="scantronformat_del"'.
3855: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3856: '<td><span class="LC_nobreak"> '.
3857: &mt('Replace:').'</span><br />';
1.46 raeburn 3858: }
3859: }
3860: if (keys(%error) == 0) {
3861: if ($switchserver) {
3862: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3863: } else {
1.65 raeburn 3864: $datatable .='<span class="LC_nobreak"> '.
3865: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3866: }
3867: }
3868: $datatable .= '</td></tr>';
3869: $$rowtotal ++;
3870: return $datatable;
3871: }
3872:
3873: sub legacy_scantronformat {
3874: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3875: my ($url,$error);
3876: my @statinfo = &Apache::lonnet::stat_file($newurl);
3877: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3878: (my $result,$url) =
3879: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3880: '','',$newfile);
3881: if ($result ne 'ok') {
1.130 raeburn 3882: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3883: }
3884: }
3885: return ($url,$error);
3886: }
1.43 raeburn 3887:
1.49 raeburn 3888: sub print_coursecategories {
1.57 raeburn 3889: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3890: my $datatable;
3891: if ($position eq 'top') {
3892: my $toggle_cats_crs = ' ';
3893: my $toggle_cats_dom = ' checked="checked" ';
3894: my $can_cat_crs = ' ';
3895: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3896: my $toggle_catscomm_comm = ' ';
3897: my $toggle_catscomm_dom = ' checked="checked" ';
3898: my $can_catcomm_comm = ' ';
3899: my $can_catcomm_dom = ' checked="checked" ';
3900:
1.57 raeburn 3901: if (ref($settings) eq 'HASH') {
3902: if ($settings->{'togglecats'} eq 'crs') {
3903: $toggle_cats_crs = $toggle_cats_dom;
3904: $toggle_cats_dom = ' ';
3905: }
3906: if ($settings->{'categorize'} eq 'crs') {
3907: $can_cat_crs = $can_cat_dom;
3908: $can_cat_dom = ' ';
3909: }
1.120 raeburn 3910: if ($settings->{'togglecatscomm'} eq 'comm') {
3911: $toggle_catscomm_comm = $toggle_catscomm_dom;
3912: $toggle_catscomm_dom = ' ';
3913: }
3914: if ($settings->{'categorizecomm'} eq 'comm') {
3915: $can_catcomm_comm = $can_catcomm_dom;
3916: $can_catcomm_dom = ' ';
3917: }
1.57 raeburn 3918: }
3919: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3920: togglecats => 'Show/Hide a course in catalog',
3921: togglecatscomm => 'Show/Hide a community in catalog',
3922: categorize => 'Assign a category to a course',
3923: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3924: );
3925: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3926: dom => 'Set in Domain',
3927: crs => 'Set in Course',
3928: comm => 'Set in Community',
1.57 raeburn 3929: );
3930: $datatable = '<tr class="LC_odd_row">'.
3931: '<td>'.$title{'togglecats'}.'</td>'.
3932: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3933: '<input type="radio" name="togglecats"'.
3934: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3935: '<label><input type="radio" name="togglecats"'.
3936: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3937: '</tr><tr>'.
3938: '<td>'.$title{'categorize'}.'</td>'.
3939: '<td class="LC_right_item"><span class="LC_nobreak">'.
3940: '<label><input type="radio" name="categorize"'.
3941: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3942: '<label><input type="radio" name="categorize"'.
3943: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3944: '</tr><tr class="LC_odd_row">'.
3945: '<td>'.$title{'togglecatscomm'}.'</td>'.
3946: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3947: '<input type="radio" name="togglecatscomm"'.
3948: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3949: '<label><input type="radio" name="togglecatscomm"'.
3950: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3951: '</tr><tr>'.
3952: '<td>'.$title{'categorizecomm'}.'</td>'.
3953: '<td class="LC_right_item"><span class="LC_nobreak">'.
3954: '<label><input type="radio" name="categorizecomm"'.
3955: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3956: '<label><input type="radio" name="categorizecomm"'.
3957: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3958: '</tr>';
1.120 raeburn 3959: $$rowtotal += 4;
1.57 raeburn 3960: } else {
3961: my $css_class;
3962: my $itemcount = 1;
3963: my $cathash;
3964: if (ref($settings) eq 'HASH') {
3965: $cathash = $settings->{'cats'};
3966: }
3967: if (ref($cathash) eq 'HASH') {
3968: my (@cats,@trails,%allitems,%idx,@jsarray);
3969: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3970: \%allitems,\%idx,\@jsarray);
3971: my $maxdepth = scalar(@cats);
3972: my $colattrib = '';
3973: if ($maxdepth > 2) {
3974: $colattrib = ' colspan="2" ';
3975: }
3976: my @path;
3977: if (@cats > 0) {
3978: if (ref($cats[0]) eq 'ARRAY') {
3979: my $numtop = @{$cats[0]};
3980: my $maxnum = $numtop;
1.120 raeburn 3981: my %default_names = (
3982: instcode => &mt('Official courses'),
3983: communities => &mt('Communities'),
3984: );
3985:
3986: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3987: ($cathash->{'instcode::0'} eq '') ||
3988: (!grep(/^communities$/,@{$cats[0]})) ||
3989: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3990: $maxnum ++;
3991: }
3992: my $lastidx;
3993: for (my $i=0; $i<$numtop; $i++) {
3994: my $parent = $cats[0][$i];
3995: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3996: my $item = &escape($parent).'::0';
3997: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3998: $lastidx = $idx{$item};
3999: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4000: .'<select name="'.$item.'"'.$chgstr.'>';
4001: for (my $k=0; $k<=$maxnum; $k++) {
4002: my $vpos = $k+1;
4003: my $selstr;
4004: if ($k == $i) {
4005: $selstr = ' selected="selected" ';
4006: }
4007: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4008: }
4009: $datatable .= '</select></td><td>';
1.120 raeburn 4010: if ($parent eq 'instcode' || $parent eq 'communities') {
4011: $datatable .= '<span class="LC_nobreak">'
4012: .$default_names{$parent}.'</span>';
4013: if ($parent eq 'instcode') {
4014: $datatable .= '<br /><span class="LC_nobreak">('
4015: .&mt('with institutional codes')
4016: .')</span></td><td'.$colattrib.'>';
4017: } else {
4018: $datatable .= '<table><tr><td>';
4019: }
4020: $datatable .= '<span class="LC_nobreak">'
4021: .'<label><input type="radio" name="'
4022: .$parent.'" value="1" checked="checked" />'
4023: .&mt('Display').'</label>';
4024: if ($parent eq 'instcode') {
4025: $datatable .= ' ';
4026: } else {
4027: $datatable .= '</span></td></tr><tr><td>'
4028: .'<span class="LC_nobreak">';
4029: }
4030: $datatable .= '<label><input type="radio" name="'
4031: .$parent.'" value="0" />'
4032: .&mt('Do not display').'</label></span>';
4033: if ($parent eq 'communities') {
4034: $datatable .= '</td></tr></table>';
4035: }
4036: $datatable .= '</td>';
1.57 raeburn 4037: } else {
4038: $datatable .= $parent
4039: .' <label><input type="checkbox" name="deletecategory" '
4040: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4041: }
4042: my $depth = 1;
4043: push(@path,$parent);
4044: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4045: pop(@path);
4046: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4047: $itemcount ++;
4048: }
1.48 raeburn 4049: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4050: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4051: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4052: for (my $k=0; $k<=$maxnum; $k++) {
4053: my $vpos = $k+1;
4054: my $selstr;
1.57 raeburn 4055: if ($k == $numtop) {
1.48 raeburn 4056: $selstr = ' selected="selected" ';
4057: }
4058: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4059: }
1.59 bisitz 4060: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4061: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4062: .'</tr>'."\n";
1.48 raeburn 4063: $itemcount ++;
1.120 raeburn 4064: foreach my $default ('instcode','communities') {
4065: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4067: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4068: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4069: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4070: for (my $k=0; $k<=$maxnum; $k++) {
4071: my $vpos = $k+1;
4072: my $selstr;
4073: if ($k == $maxnum) {
4074: $selstr = ' selected="selected" ';
4075: }
4076: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4077: }
1.120 raeburn 4078: $datatable .= '</select></span></td>'.
4079: '<td><span class="LC_nobreak">'.
4080: $default_names{$default}.'</span>';
4081: if ($default eq 'instcode') {
4082: $datatable .= '<br /><span class="LC_nobreak">('
4083: .&mt('with institutional codes').')</span>';
4084: }
4085: $datatable .= '</td>'
4086: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4087: .&mt('Display').'</label> '
4088: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4089: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4090: }
4091: }
4092: }
1.57 raeburn 4093: } else {
4094: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4095: }
4096: } else {
1.57 raeburn 4097: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4098: .&initialize_categories($itemcount);
1.48 raeburn 4099: }
1.57 raeburn 4100: $$rowtotal += $itemcount;
1.48 raeburn 4101: }
4102: return $datatable;
4103: }
4104:
1.69 raeburn 4105: sub print_serverstatuses {
4106: my ($dom,$settings,$rowtotal) = @_;
4107: my $datatable;
4108: my @pages = &serverstatus_pages();
4109: my (%namedaccess,%machineaccess);
4110: foreach my $type (@pages) {
4111: $namedaccess{$type} = '';
4112: $machineaccess{$type}= '';
4113: }
4114: if (ref($settings) eq 'HASH') {
4115: foreach my $type (@pages) {
4116: if (exists($settings->{$type})) {
4117: if (ref($settings->{$type}) eq 'HASH') {
4118: foreach my $key (keys(%{$settings->{$type}})) {
4119: if ($key eq 'namedusers') {
4120: $namedaccess{$type} = $settings->{$type}->{$key};
4121: } elsif ($key eq 'machines') {
4122: $machineaccess{$type} = $settings->{$type}->{$key};
4123: }
4124: }
4125: }
4126: }
4127: }
4128: }
1.81 raeburn 4129: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4130: my $rownum = 0;
4131: my $css_class;
4132: foreach my $type (@pages) {
4133: $rownum ++;
4134: $css_class = $rownum%2?' class="LC_odd_row"':'';
4135: $datatable .= '<tr'.$css_class.'>'.
4136: '<td><span class="LC_nobreak">'.
4137: $titles->{$type}.'</span></td>'.
4138: '<td class="LC_left_item">'.
4139: '<input type="text" name="'.$type.'_namedusers" '.
4140: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4141: '<td class="LC_right_item">'.
4142: '<span class="LC_nobreak">'.
4143: '<input type="text" name="'.$type.'_machines" '.
4144: 'value="'.$machineaccess{$type}.'" size="10" />'.
4145: '</td></tr>'."\n";
4146: }
4147: $$rowtotal += $rownum;
4148: return $datatable;
4149: }
4150:
4151: sub serverstatus_pages {
4152: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4153: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4154: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4155: }
4156:
1.49 raeburn 4157: sub coursecategories_javascript {
4158: my ($settings) = @_;
1.57 raeburn 4159: my ($output,$jstext,$cathash);
1.49 raeburn 4160: if (ref($settings) eq 'HASH') {
1.57 raeburn 4161: $cathash = $settings->{'cats'};
4162: }
4163: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4164: my (@cats,@jsarray,%idx);
1.57 raeburn 4165: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4166: if (@jsarray > 0) {
4167: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4168: for (my $i=0; $i<@jsarray; $i++) {
4169: if (ref($jsarray[$i]) eq 'ARRAY') {
4170: my $catstr = join('","',@{$jsarray[$i]});
4171: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4172: }
4173: }
4174: }
4175: } else {
4176: $jstext = ' var categories = Array(1);'."\n".
4177: ' categories[0] = Array("instcode_pos");'."\n";
4178: }
1.120 raeburn 4179: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4180: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4181: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4182: $output = <<"ENDSCRIPT";
4183: <script type="text/javascript">
1.109 raeburn 4184: // <![CDATA[
1.49 raeburn 4185: function reorderCats(form,parent,item,idx) {
4186: var changedVal;
4187: $jstext
4188: var newpos = 'addcategory_pos';
4189: var current = new Array;
4190: if (parent == '') {
4191: var has_instcode = 0;
4192: var maxtop = categories[idx].length;
4193: for (var j=0; j<maxtop; j++) {
4194: if (categories[idx][j] == 'instcode::0') {
4195: has_instcode == 1;
4196: }
4197: }
4198: if (has_instcode == 0) {
4199: categories[idx][maxtop] = 'instcode_pos';
4200: }
4201: } else {
4202: newpos += '_'+parent;
4203: }
4204: var maxh = 1 + categories[idx].length;
4205: var current = new Array;
4206: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4207: if (item == newpos) {
4208: changedVal = newitemVal;
4209: } else {
4210: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4211: current[newitemVal] = newpos;
4212: }
4213: for (var i=0; i<categories[idx].length; i++) {
4214: var elementName = categories[idx][i];
4215: if (elementName != item) {
4216: if (form.elements[elementName]) {
4217: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4218: current[currVal] = elementName;
4219: }
4220: }
4221: }
4222: var oldVal;
4223: for (var j=0; j<maxh; j++) {
4224: if (current[j] == undefined) {
4225: oldVal = j;
4226: }
4227: }
4228: if (oldVal < changedVal) {
4229: for (var k=oldVal+1; k<=changedVal ; k++) {
4230: var elementName = current[k];
4231: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4232: }
4233: } else {
4234: for (var k=changedVal; k<oldVal; k++) {
4235: var elementName = current[k];
4236: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4237: }
4238: }
4239: return;
4240: }
1.120 raeburn 4241:
4242: function categoryCheck(form) {
4243: if (form.elements['addcategory_name'].value == 'instcode') {
4244: alert('$instcode_reserved\\n$choose_again');
4245: return false;
4246: }
4247: if (form.elements['addcategory_name'].value == 'communities') {
4248: alert('$communities_reserved\\n$choose_again');
4249: return false;
4250: }
4251: return true;
4252: }
4253:
1.109 raeburn 4254: // ]]>
1.49 raeburn 4255: </script>
4256:
4257: ENDSCRIPT
4258: return $output;
4259: }
4260:
1.48 raeburn 4261: sub initialize_categories {
4262: my ($itemcount) = @_;
1.120 raeburn 4263: my ($datatable,$css_class,$chgstr);
4264: my %default_names = (
4265: instcode => 'Official courses (with institutional codes)',
4266: communities => 'Communities',
4267: );
4268: my $select0 = ' selected="selected"';
4269: my $select1 = '';
4270: foreach my $default ('instcode','communities') {
4271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4272: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4273: if ($default eq 'communities') {
4274: $select1 = $select0;
4275: $select0 = '';
4276: }
4277: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4278: .'<select name="'.$default.'_pos">'
4279: .'<option value="0"'.$select0.'>1</option>'
4280: .'<option value="1"'.$select1.'>2</option>'
4281: .'<option value="2">3</option></select> '
4282: .$default_names{$default}
4283: .'</span></td><td><span class="LC_nobreak">'
4284: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4285: .&mt('Display').'</label> <label>'
4286: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4287: .'</label></span></td></tr>';
1.120 raeburn 4288: $itemcount ++;
4289: }
1.48 raeburn 4290: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4291: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4292: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4293: .'<select name="addcategory_pos"'.$chgstr.'>'
4294: .'<option value="0">1</option>'
4295: .'<option value="1">2</option>'
4296: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4297: .&mt('Add category').'</td><td>'.&mt('Name:')
4298: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4299: return $datatable;
4300: }
4301:
4302: sub build_category_rows {
1.49 raeburn 4303: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4304: my ($text,$name,$item,$chgstr);
1.48 raeburn 4305: if (ref($cats) eq 'ARRAY') {
4306: my $maxdepth = scalar(@{$cats});
4307: if (ref($cats->[$depth]) eq 'HASH') {
4308: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4309: my $numchildren = @{$cats->[$depth]{$parent}};
4310: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4311: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4312: my ($idxnum,$parent_name,$parent_item);
4313: my $higher = $depth - 1;
4314: if ($higher == 0) {
4315: $parent_name = &escape($parent).'::'.$higher;
4316: } else {
4317: if (ref($path) eq 'ARRAY') {
4318: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4319: }
4320: }
4321: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4322: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4323: if ($j < $numchildren) {
1.48 raeburn 4324: $name = $cats->[$depth]{$parent}[$j];
4325: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4326: $idxnum = $idx->{$item};
4327: } else {
4328: $name = $parent_name;
4329: $item = $parent_item;
1.48 raeburn 4330: }
1.49 raeburn 4331: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4332: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4333: for (my $i=0; $i<=$numchildren; $i++) {
4334: my $vpos = $i+1;
4335: my $selstr;
4336: if ($j == $i) {
4337: $selstr = ' selected="selected" ';
4338: }
4339: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4340: }
4341: $text .= '</select> ';
4342: if ($j < $numchildren) {
4343: my $deeper = $depth+1;
4344: $text .= $name.' '
4345: .'<label><input type="checkbox" name="deletecategory" value="'
4346: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4347: if(ref($path) eq 'ARRAY') {
4348: push(@{$path},$name);
1.49 raeburn 4349: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4350: pop(@{$path});
4351: }
4352: } else {
1.59 bisitz 4353: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4354: if ($j == $numchildren) {
4355: $text .= $name;
4356: } else {
4357: $text .= $item;
4358: }
4359: $text .= '" value="" />';
4360: }
4361: $text .= '</td></tr>';
4362: }
4363: $text .= '</table></td>';
4364: } else {
4365: my $higher = $depth-1;
4366: if ($higher == 0) {
4367: $name = &escape($parent).'::'.$higher;
4368: } else {
4369: if (ref($path) eq 'ARRAY') {
4370: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4371: }
4372: }
4373: my $colspan;
4374: if ($parent ne 'instcode') {
4375: $colspan = $maxdepth - $depth - 1;
4376: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4377: }
4378: }
4379: }
4380: }
4381: return $text;
4382: }
4383:
1.33 raeburn 4384: sub modifiable_userdata_row {
1.63 raeburn 4385: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4386: my $rolename;
1.63 raeburn 4387: if ($context eq 'selfcreate') {
4388: if (ref($usertypes) eq 'HASH') {
4389: $rolename = $usertypes->{$role};
4390: } else {
4391: $rolename = $role;
4392: }
1.33 raeburn 4393: } else {
1.63 raeburn 4394: if ($role eq 'cr') {
4395: $rolename = &mt('Custom role');
4396: } else {
4397: $rolename = &Apache::lonnet::plaintext($role);
4398: }
1.33 raeburn 4399: }
4400: my @fields = ('lastname','firstname','middlename','generation',
4401: 'permanentemail','id');
4402: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4403: my $output;
4404: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4405: $output = '<tr '.$css_class.'>'.
4406: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4407: '<td class="LC_left_item" colspan="2"><table>';
4408: my $rem;
4409: my %checks;
4410: if (ref($settings) eq 'HASH') {
4411: if (ref($settings->{$context}) eq 'HASH') {
4412: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4413: foreach my $field (@fields) {
4414: if ($settings->{$context}->{$role}->{$field}) {
4415: $checks{$field} = ' checked="checked" ';
4416: }
4417: }
4418: }
4419: }
4420: }
4421: for (my $i=0; $i<@fields; $i++) {
4422: my $rem = $i%($numinrow);
4423: if ($rem == 0) {
4424: if ($i > 0) {
4425: $output .= '</tr>';
4426: }
4427: $output .= '<tr>';
4428: }
4429: my $check = ' ';
4430: if (exists($checks{$fields[$i]})) {
4431: $check = $checks{$fields[$i]}
4432: } else {
4433: if ($role eq 'st') {
4434: if (ref($settings) ne 'HASH') {
4435: $check = ' checked="checked" ';
4436: }
4437: }
4438: }
4439: $output .= '<td class="LC_left_item">'.
4440: '<span class="LC_nobreak"><label>'.
4441: '<input type="checkbox" name="canmodify_'.$role.'" '.
4442: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4443: '</label></span></td>';
4444: $rem = @fields%($numinrow);
4445: }
4446: my $colsleft = $numinrow - $rem;
4447: if ($colsleft > 1 ) {
4448: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4449: ' </td>';
4450: } elsif ($colsleft == 1) {
4451: $output .= '<td class="LC_left_item"> </td>';
4452: }
4453: $output .= '</tr></table></td></tr>';
4454: return $output;
4455: }
1.28 raeburn 4456:
1.93 raeburn 4457: sub insttypes_row {
4458: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4459: my %lt = &Apache::lonlocal::texthash (
4460: cansearch => 'Users allowed to search',
4461: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4462: lockablenames => 'User preference to lock name',
1.93 raeburn 4463: );
4464: my $showdom;
4465: if ($context eq 'cansearch') {
4466: $showdom = ' ('.$dom.')';
4467: }
1.160.6.5 raeburn 4468: my $class = 'LC_left_item';
4469: if ($context eq 'statustocreate') {
4470: $class = 'LC_right_item';
4471: }
1.25 raeburn 4472: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4473: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4474: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4475: my $rem;
4476: if (ref($types) eq 'ARRAY') {
4477: for (my $i=0; $i<@{$types}; $i++) {
4478: if (defined($usertypes->{$types->[$i]})) {
4479: my $rem = $i%($numinrow);
4480: if ($rem == 0) {
4481: if ($i > 0) {
4482: $output .= '</tr>';
4483: }
4484: $output .= '<tr>';
1.23 raeburn 4485: }
1.26 raeburn 4486: my $check = ' ';
1.99 raeburn 4487: if (ref($settings) eq 'HASH') {
4488: if (ref($settings->{$context}) eq 'ARRAY') {
4489: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4490: $check = ' checked="checked" ';
4491: }
4492: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4493: $check = ' checked="checked" ';
4494: }
1.23 raeburn 4495: }
1.26 raeburn 4496: $output .= '<td class="LC_left_item">'.
4497: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4498: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4499: 'value="'.$types->[$i].'"'.$check.'/>'.
4500: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4501: }
4502: }
1.26 raeburn 4503: $rem = @{$types}%($numinrow);
1.23 raeburn 4504: }
4505: my $colsleft = $numinrow - $rem;
1.131 raeburn 4506: if (($rem == 0) && (@{$types} > 0)) {
4507: $output .= '<tr>';
4508: }
1.23 raeburn 4509: if ($colsleft > 1) {
1.25 raeburn 4510: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4511: } else {
1.25 raeburn 4512: $output .= '<td class="LC_left_item">';
1.23 raeburn 4513: }
4514: my $defcheck = ' ';
1.99 raeburn 4515: if (ref($settings) eq 'HASH') {
4516: if (ref($settings->{$context}) eq 'ARRAY') {
4517: if (grep(/^default$/,@{$settings->{$context}})) {
4518: $defcheck = ' checked="checked" ';
4519: }
4520: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4521: $defcheck = ' checked="checked" ';
4522: }
1.23 raeburn 4523: }
1.25 raeburn 4524: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4525: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4526: 'value="default"'.$defcheck.'/>'.
4527: $othertitle.'</label></span></td>'.
4528: '</tr></table></td></tr>';
4529: return $output;
1.23 raeburn 4530: }
4531:
4532: sub sorted_searchtitles {
4533: my %searchtitles = &Apache::lonlocal::texthash(
4534: 'uname' => 'username',
4535: 'lastname' => 'last name',
4536: 'lastfirst' => 'last name, first name',
4537: );
4538: my @titleorder = ('uname','lastname','lastfirst');
4539: return (\%searchtitles,\@titleorder);
4540: }
4541:
1.25 raeburn 4542: sub sorted_searchtypes {
4543: my %srchtypes_desc = (
4544: exact => 'is exact match',
4545: contains => 'contains ..',
4546: begins => 'begins with ..',
4547: );
4548: my @srchtypeorder = ('exact','begins','contains');
4549: return (\%srchtypes_desc,\@srchtypeorder);
4550: }
4551:
1.3 raeburn 4552: sub usertype_update_row {
4553: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4554: my $datatable;
4555: my $numinrow = 4;
4556: foreach my $type (@{$types}) {
4557: if (defined($usertypes->{$type})) {
4558: $$rownums ++;
4559: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4560: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4561: '</td><td class="LC_left_item"><table>';
4562: for (my $i=0; $i<@{$fields}; $i++) {
4563: my $rem = $i%($numinrow);
4564: if ($rem == 0) {
4565: if ($i > 0) {
4566: $datatable .= '</tr>';
4567: }
4568: $datatable .= '<tr>';
4569: }
4570: my $check = ' ';
1.39 raeburn 4571: if (ref($settings) eq 'HASH') {
4572: if (ref($settings->{'fields'}) eq 'HASH') {
4573: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4574: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4575: $check = ' checked="checked" ';
4576: }
1.3 raeburn 4577: }
4578: }
4579: }
4580:
4581: if ($i == @{$fields}-1) {
4582: my $colsleft = $numinrow - $rem;
4583: if ($colsleft > 1) {
4584: $datatable .= '<td colspan="'.$colsleft.'">';
4585: } else {
4586: $datatable .= '<td>';
4587: }
4588: } else {
4589: $datatable .= '<td>';
4590: }
1.8 raeburn 4591: $datatable .= '<span class="LC_nobreak"><label>'.
4592: '<input type="checkbox" name="updateable_'.$type.
4593: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4594: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4595: }
4596: $datatable .= '</tr></table></td></tr>';
4597: }
4598: }
4599: return $datatable;
1.1 raeburn 4600: }
4601:
4602: sub modify_login {
1.9 raeburn 4603: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4604: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4605: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4606: %title = ( coursecatalog => 'Display course catalog',
4607: adminmail => 'Display administrator E-mail address',
4608: newuser => 'Link for visitors to create a user account',
4609: loginheader => 'Log-in box header');
4610: @offon = ('off','on');
1.112 raeburn 4611: if (ref($domconfig{login}) eq 'HASH') {
4612: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4613: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4614: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4615: }
4616: }
4617: }
1.9 raeburn 4618: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4619: \%domconfig,\%loginhash);
1.118 jms 4620: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4621: foreach my $item (@toggles) {
4622: $loginhash{login}{$item} = $env{'form.'.$item};
4623: }
1.41 raeburn 4624: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4625: if (ref($colchanges{'login'}) eq 'HASH') {
4626: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4627: \%loginhash);
4628: }
1.110 raeburn 4629:
1.149 raeburn 4630: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4631: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4632: if (keys(%servers) > 1) {
4633: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4634: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4635: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4636: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4637: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4638: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4639: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4640: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4641: $changes{'loginvia'}{$lonhost} = 1;
4642: } else {
4643: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4644: $changes{'loginvia'}{$lonhost} = 1;
4645: }
4646: } else {
4647: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4648: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4649: $changes{'loginvia'}{$lonhost} = 1;
4650: }
4651: }
4652: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4653: foreach my $item (@loginvia_attribs) {
4654: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4655: }
4656: } else {
4657: foreach my $item (@loginvia_attribs) {
4658: my $new = $env{'form.'.$lonhost.'_'.$item};
4659: if (($item eq 'serverpath') && ($new eq 'custom')) {
4660: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4661: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4662: $new = '/';
4663: }
4664: }
4665: if (($item eq 'custompath') &&
4666: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4667: $new = '';
4668: }
4669: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4670: $changes{'loginvia'}{$lonhost} = 1;
4671: }
4672: if ($item eq 'exempt') {
4673: $new =~ s/^\s+//;
4674: $new =~ s/\s+$//;
4675: my @poss_ips = split(/\s*[,:]\s*/,$new);
4676: my @okips;
4677: foreach my $ip (@poss_ips) {
4678: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4679: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4680: push(@okips,$ip);
4681: }
4682: }
4683: }
4684: if (@okips > 0) {
4685: $new = join(',',@okips);
4686: } else {
4687: $new = '';
4688: }
4689: }
4690: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4691: }
4692: }
1.112 raeburn 4693: } else {
1.128 raeburn 4694: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4695: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4696: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4697: foreach my $item (@loginvia_attribs) {
4698: my $new = $env{'form.'.$lonhost.'_'.$item};
4699: if (($item eq 'serverpath') && ($new eq 'custom')) {
4700: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4701: $new = '/';
4702: }
4703: }
4704: if (($item eq 'custompath') &&
4705: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4706: $new = '';
4707: }
4708: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4709: }
1.110 raeburn 4710: }
4711: }
4712: }
4713: }
1.119 raeburn 4714:
1.160.6.5 raeburn 4715: my $servadm = $r->dir_config('lonAdmEMail');
4716: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4717: if (ref($domconfig{'login'}) eq 'HASH') {
4718: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4719: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4720: if ($lang eq 'nolang') {
4721: push(@currlangs,$lang);
4722: } elsif (defined($langchoices{$lang})) {
4723: push(@currlangs,$lang);
4724: } else {
4725: next;
4726: }
4727: }
4728: }
4729: }
4730: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4731: if (@currlangs > 0) {
4732: foreach my $lang (@currlangs) {
4733: if (grep(/^\Q$lang\E$/,@delurls)) {
4734: $changes{'helpurl'}{$lang} = 1;
4735: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4736: $changes{'helpurl'}{$lang} = 1;
4737: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4738: push(@newlangs,$lang);
4739: } else {
4740: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4741: }
4742: }
4743: }
4744: unless (grep(/^nolang$/,@currlangs)) {
4745: if ($env{'form.loginhelpurl_nolang.filename'}) {
4746: $changes{'helpurl'}{'nolang'} = 1;
4747: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4748: push(@newlangs,'nolang');
4749: }
4750: }
4751: if ($env{'form.loginhelpurl_add_lang'}) {
4752: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4753: ($env{'form.loginhelpurl_add_file.filename'})) {
4754: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4755: $addedfile = $env{'form.loginhelpurl_add_lang'};
4756: }
4757: }
4758: if ((@newlangs > 0) || ($addedfile)) {
4759: my $error;
4760: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4761: if ($configuserok eq 'ok') {
4762: if ($switchserver) {
4763: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4764: } elsif ($author_ok eq 'ok') {
4765: my @allnew = @newlangs;
4766: if ($addedfile ne '') {
4767: push(@allnew,$addedfile);
4768: }
4769: foreach my $lang (@allnew) {
4770: my $formelem = 'loginhelpurl_'.$lang;
4771: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4772: $formelem = 'loginhelpurl_add_file';
4773: }
4774: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4775: "help/$lang",'','',$newfile{$lang});
4776: if ($result eq 'ok') {
4777: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4778: $changes{'helpurl'}{$lang} = 1;
4779: } else {
4780: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4781: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4782: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4783: (!grep(/^\Q$lang\E$/,@delurls))) {
4784:
4785: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4786: }
4787: }
4788: }
4789: } else {
4790: $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);
4791: }
4792: } else {
4793: $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);
4794: }
4795: if ($error) {
4796: &Apache::lonnet::logthis($error);
4797: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4798: }
4799: }
4800: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4801:
4802: my $defaulthelpfile = '/adm/loginproblems.html';
4803: my $defaulttext = &mt('Default in use');
4804:
1.1 raeburn 4805: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4806: $dom);
4807: if ($putresult eq 'ok') {
1.118 jms 4808: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4809: my %defaultchecked = (
4810: 'coursecatalog' => 'on',
4811: 'adminmail' => 'off',
1.43 raeburn 4812: 'newuser' => 'off',
1.42 raeburn 4813: );
1.55 raeburn 4814: if (ref($domconfig{'login'}) eq 'HASH') {
4815: foreach my $item (@toggles) {
4816: if ($defaultchecked{$item} eq 'on') {
4817: if (($domconfig{'login'}{$item} eq '0') &&
4818: ($env{'form.'.$item} eq '1')) {
4819: $changes{$item} = 1;
4820: } elsif (($domconfig{'login'}{$item} eq '' ||
4821: $domconfig{'login'}{$item} eq '1') &&
4822: ($env{'form.'.$item} eq '0')) {
4823: $changes{$item} = 1;
4824: }
4825: } elsif ($defaultchecked{$item} eq 'off') {
4826: if (($domconfig{'login'}{$item} eq '1') &&
4827: ($env{'form.'.$item} eq '0')) {
4828: $changes{$item} = 1;
4829: } elsif (($domconfig{'login'}{$item} eq '' ||
4830: $domconfig{'login'}{$item} eq '0') &&
4831: ($env{'form.'.$item} eq '1')) {
4832: $changes{$item} = 1;
4833: }
1.42 raeburn 4834: }
4835: }
1.41 raeburn 4836: }
1.6 raeburn 4837: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4838: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4839: $resulttext = &mt('Changes made:').'<ul>';
4840: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4841: if ($item eq 'loginvia') {
1.112 raeburn 4842: if (ref($changes{$item}) eq 'HASH') {
4843: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4844: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4845: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4846: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4847: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4848: $protocol = 'http' if ($protocol ne 'https');
4849: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4850:
4851: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4852: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4853: } else {
4854: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4855: }
4856: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4857: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4858: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4859: }
4860: $resulttext .= '</li>';
4861: } else {
4862: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4863: }
1.112 raeburn 4864: } else {
1.128 raeburn 4865: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4866: }
4867: }
1.128 raeburn 4868: $resulttext .= '</ul></li>';
1.112 raeburn 4869: }
1.160.6.5 raeburn 4870: } elsif ($item eq 'helpurl') {
4871: if (ref($changes{$item}) eq 'HASH') {
4872: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4873: if (grep(/^\Q$lang\E$/,@delurls)) {
4874: my ($chg,$link);
4875: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4876: if ($lang eq 'nolang') {
4877: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4878: } else {
4879: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4880: }
4881: $resulttext .= '<li>'.$chg.'</li>';
4882: } else {
4883: my $chg;
4884: if ($lang eq 'nolang') {
4885: $chg = &mt('custom log-in help file for no preferred language');
4886: } else {
4887: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4888: }
4889: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4890: $loginhash{'login'}{'helpurl'}{$lang}.
4891: '?inhibitmenu=yes',$chg,600,500).
4892: '</li>';
4893: }
4894: }
4895: }
4896: } elsif ($item eq 'captcha') {
4897: if (ref($loginhash{'login'}) eq 'HASH') {
4898: my $chgtxt;
4899: if ($loginhash{'login'}{$item} eq 'notused') {
4900: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4901: } else {
4902: my %captchas = &captcha_phrases();
4903: if ($captchas{$loginhash{'login'}{$item}}) {
4904: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4905: } else {
4906: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4907: }
4908: }
4909: $resulttext .= '<li>'.$chgtxt.'</li>';
4910: }
4911: } elsif ($item eq 'recaptchakeys') {
4912: if (ref($loginhash{'login'}) eq 'HASH') {
4913: my ($privkey,$pubkey);
4914: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4915: $pubkey = $loginhash{'login'}{$item}{'public'};
4916: $privkey = $loginhash{'login'}{$item}{'private'};
4917: }
4918: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4919: if (!$pubkey) {
4920: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4921: } else {
4922: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4923: }
4924: if (!$privkey) {
4925: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4926: } else {
4927: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4928: }
4929: $chgtxt .= '</ul>';
4930: $resulttext .= '<li>'.$chgtxt.'</li>';
4931: }
1.41 raeburn 4932: } else {
4933: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4934: }
1.1 raeburn 4935: }
1.6 raeburn 4936: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4937: } else {
4938: $resulttext = &mt('No changes made to log-in page settings');
4939: }
4940: } else {
1.11 albertel 4941: $resulttext = '<span class="LC_error">'.
4942: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4943: }
1.6 raeburn 4944: if ($errors) {
1.9 raeburn 4945: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4946: $errors.'</ul>';
4947: }
4948: return $resulttext;
4949: }
4950:
4951: sub color_font_choices {
4952: my %choices =
4953: &Apache::lonlocal::texthash (
4954: img => "Header",
4955: bgs => "Background colors",
4956: links => "Link colors",
1.55 raeburn 4957: images => "Images",
1.6 raeburn 4958: font => "Font color",
1.97 tempelho 4959: fontmenu => "Font Menu",
1.76 raeburn 4960: pgbg => "Page",
1.6 raeburn 4961: tabbg => "Header",
4962: sidebg => "Border",
4963: link => "Link",
4964: alink => "Active link",
4965: vlink => "Visited link",
4966: );
4967: return %choices;
4968: }
4969:
4970: sub modify_rolecolors {
1.9 raeburn 4971: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4972: my ($resulttext,%rolehash);
4973: $rolehash{'rolecolors'} = {};
1.55 raeburn 4974: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4975: if ($domconfig{'rolecolors'} eq '') {
4976: $domconfig{'rolecolors'} = {};
4977: }
4978: }
1.9 raeburn 4979: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4980: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4981: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4982: $dom);
4983: if ($putresult eq 'ok') {
4984: if (keys(%changes) > 0) {
1.41 raeburn 4985: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4986: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4987: $rolehash{'rolecolors'});
4988: } else {
4989: $resulttext = &mt('No changes made to default color schemes');
4990: }
4991: } else {
1.11 albertel 4992: $resulttext = '<span class="LC_error">'.
4993: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4994: }
4995: if ($errors) {
4996: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4997: $errors.'</ul>';
4998: }
4999: return $resulttext;
5000: }
5001:
5002: sub modify_colors {
1.9 raeburn 5003: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5004: my (%changes,%choices);
1.51 raeburn 5005: my @bgs;
1.6 raeburn 5006: my @links = ('link','alink','vlink');
1.41 raeburn 5007: my @logintext;
1.6 raeburn 5008: my @images;
5009: my $servadm = $r->dir_config('lonAdmEMail');
5010: my $errors;
5011: foreach my $role (@{$roles}) {
5012: if ($role eq 'login') {
1.12 raeburn 5013: %choices = &login_choices();
1.41 raeburn 5014: @logintext = ('textcol','bgcol');
1.12 raeburn 5015: } else {
5016: %choices = &color_font_choices();
1.107 raeburn 5017: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5018: }
5019: if ($role eq 'login') {
1.41 raeburn 5020: @images = ('img','logo','domlogo','login');
1.51 raeburn 5021: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5022: } else {
5023: @images = ('img');
1.51 raeburn 5024: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5025: }
5026: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5027: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5028: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5029: }
1.46 raeburn 5030: my ($configuserok,$author_ok,$switchserver) =
5031: &config_check($dom,$confname,$servadm);
1.9 raeburn 5032: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5033: if (ref($domconfig->{$role}) ne 'HASH') {
5034: $domconfig->{$role} = {};
5035: }
1.8 raeburn 5036: foreach my $img (@images) {
1.70 raeburn 5037: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5038: if (defined($env{'form.login_showlogo_'.$img})) {
5039: $confhash->{$role}{'showlogo'}{$img} = 1;
5040: } else {
5041: $confhash->{$role}{'showlogo'}{$img} = 0;
5042: }
5043: }
1.18 albertel 5044: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5045: && !defined($domconfig->{$role}{$img})
5046: && !$env{'form.'.$role.'_del_'.$img}
5047: && $env{'form.'.$role.'_import_'.$img}) {
5048: # import the old configured image from the .tab setting
5049: # if they haven't provided a new one
5050: $domconfig->{$role}{$img} =
5051: $env{'form.'.$role.'_import_'.$img};
5052: }
1.6 raeburn 5053: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5054: my $error;
1.6 raeburn 5055: if ($configuserok eq 'ok') {
1.9 raeburn 5056: if ($switchserver) {
1.12 raeburn 5057: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5058: } else {
5059: if ($author_ok eq 'ok') {
5060: my ($result,$logourl) =
5061: &publishlogo($r,'upload',$role.'_'.$img,
5062: $dom,$confname,$img,$width,$height);
5063: if ($result eq 'ok') {
5064: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5065: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5066: } else {
1.12 raeburn 5067: $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 5068: }
5069: } else {
1.46 raeburn 5070: $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 5071: }
5072: }
5073: } else {
1.46 raeburn 5074: $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 5075: }
5076: if ($error) {
1.8 raeburn 5077: &Apache::lonnet::logthis($error);
1.11 albertel 5078: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5079: }
5080: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5081: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5082: my $error;
5083: if ($configuserok eq 'ok') {
5084: # is confname an author?
5085: if ($switchserver eq '') {
5086: if ($author_ok eq 'ok') {
5087: my ($result,$logourl) =
5088: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5089: $dom,$confname,$img,$width,$height);
5090: if ($result eq 'ok') {
5091: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5092: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5093: }
5094: }
5095: }
5096: }
1.6 raeburn 5097: }
5098: }
5099: }
5100: if (ref($domconfig) eq 'HASH') {
5101: if (ref($domconfig->{$role}) eq 'HASH') {
5102: foreach my $img (@images) {
5103: if ($domconfig->{$role}{$img} ne '') {
5104: if ($env{'form.'.$role.'_del_'.$img}) {
5105: $confhash->{$role}{$img} = '';
1.12 raeburn 5106: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5107: } else {
1.9 raeburn 5108: if ($confhash->{$role}{$img} eq '') {
5109: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5110: }
1.6 raeburn 5111: }
5112: } else {
5113: if ($env{'form.'.$role.'_del_'.$img}) {
5114: $confhash->{$role}{$img} = '';
1.12 raeburn 5115: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5116: }
5117: }
1.70 raeburn 5118: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5119: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5120: if ($confhash->{$role}{'showlogo'}{$img} ne
5121: $domconfig->{$role}{'showlogo'}{$img}) {
5122: $changes{$role}{'showlogo'}{$img} = 1;
5123: }
5124: } else {
5125: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5126: $changes{$role}{'showlogo'}{$img} = 1;
5127: }
5128: }
5129: }
5130: }
1.6 raeburn 5131: if ($domconfig->{$role}{'font'} ne '') {
5132: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5133: $changes{$role}{'font'} = 1;
5134: }
5135: } else {
5136: if ($confhash->{$role}{'font'}) {
5137: $changes{$role}{'font'} = 1;
5138: }
5139: }
1.107 raeburn 5140: if ($role ne 'login') {
5141: if ($domconfig->{$role}{'fontmenu'} ne '') {
5142: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5143: $changes{$role}{'fontmenu'} = 1;
5144: }
5145: } else {
5146: if ($confhash->{$role}{'fontmenu'}) {
5147: $changes{$role}{'fontmenu'} = 1;
5148: }
1.97 tempelho 5149: }
5150: }
1.6 raeburn 5151: foreach my $item (@bgs) {
5152: if ($domconfig->{$role}{$item} ne '') {
5153: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5154: $changes{$role}{'bgs'}{$item} = 1;
5155: }
5156: } else {
5157: if ($confhash->{$role}{$item}) {
5158: $changes{$role}{'bgs'}{$item} = 1;
5159: }
5160: }
5161: }
5162: foreach my $item (@links) {
5163: if ($domconfig->{$role}{$item} ne '') {
5164: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5165: $changes{$role}{'links'}{$item} = 1;
5166: }
5167: } else {
5168: if ($confhash->{$role}{$item}) {
5169: $changes{$role}{'links'}{$item} = 1;
5170: }
5171: }
5172: }
1.41 raeburn 5173: foreach my $item (@logintext) {
5174: if ($domconfig->{$role}{$item} ne '') {
5175: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5176: $changes{$role}{'logintext'}{$item} = 1;
5177: }
5178: } else {
5179: if ($confhash->{$role}{$item}) {
5180: $changes{$role}{'logintext'}{$item} = 1;
5181: }
5182: }
5183: }
1.6 raeburn 5184: } else {
5185: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5186: \@logintext,$confhash,\%changes);
1.6 raeburn 5187: }
5188: } else {
5189: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5190: \@logintext,$confhash,\%changes);
1.6 raeburn 5191: }
5192: }
5193: return ($errors,%changes);
5194: }
5195:
1.46 raeburn 5196: sub config_check {
5197: my ($dom,$confname,$servadm) = @_;
5198: my ($configuserok,$author_ok,$switchserver,%currroles);
5199: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5200: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5201: $confname,$servadm);
5202: if ($configuserok eq 'ok') {
5203: $switchserver = &check_switchserver($dom,$confname);
5204: if ($switchserver eq '') {
5205: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5206: }
5207: }
5208: return ($configuserok,$author_ok,$switchserver);
5209: }
5210:
1.6 raeburn 5211: sub default_change_checker {
1.41 raeburn 5212: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5213: foreach my $item (@{$links}) {
5214: if ($confhash->{$role}{$item}) {
5215: $changes->{$role}{'links'}{$item} = 1;
5216: }
5217: }
5218: foreach my $item (@{$bgs}) {
5219: if ($confhash->{$role}{$item}) {
5220: $changes->{$role}{'bgs'}{$item} = 1;
5221: }
5222: }
1.41 raeburn 5223: foreach my $item (@{$logintext}) {
5224: if ($confhash->{$role}{$item}) {
5225: $changes->{$role}{'logintext'}{$item} = 1;
5226: }
5227: }
1.6 raeburn 5228: foreach my $img (@{$images}) {
5229: if ($env{'form.'.$role.'_del_'.$img}) {
5230: $confhash->{$role}{$img} = '';
1.12 raeburn 5231: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5232: }
1.70 raeburn 5233: if ($role eq 'login') {
5234: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5235: $changes->{$role}{'showlogo'}{$img} = 1;
5236: }
5237: }
1.6 raeburn 5238: }
5239: if ($confhash->{$role}{'font'}) {
5240: $changes->{$role}{'font'} = 1;
5241: }
1.48 raeburn 5242: }
1.6 raeburn 5243:
5244: sub display_colorchgs {
5245: my ($dom,$changes,$roles,$confhash) = @_;
5246: my (%choices,$resulttext);
5247: if (!grep(/^login$/,@{$roles})) {
5248: $resulttext = &mt('Changes made:').'<br />';
5249: }
5250: foreach my $role (@{$roles}) {
5251: if ($role eq 'login') {
5252: %choices = &login_choices();
5253: } else {
5254: %choices = &color_font_choices();
5255: }
5256: if (ref($changes->{$role}) eq 'HASH') {
5257: if ($role ne 'login') {
5258: $resulttext .= '<h4>'.&mt($role).'</h4>';
5259: }
5260: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5261: if ($role ne 'login') {
5262: $resulttext .= '<ul>';
5263: }
5264: if (ref($changes->{$role}{$key}) eq 'HASH') {
5265: if ($role ne 'login') {
5266: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5267: }
5268: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5269: if (($role eq 'login') && ($key eq 'showlogo')) {
5270: if ($confhash->{$role}{$key}{$item}) {
5271: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5272: } else {
5273: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5274: }
5275: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5276: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5277: } else {
1.12 raeburn 5278: my $newitem = $confhash->{$role}{$item};
5279: if ($key eq 'images') {
5280: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5281: }
5282: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5283: }
5284: }
5285: if ($role ne 'login') {
5286: $resulttext .= '</ul></li>';
5287: }
5288: } else {
5289: if ($confhash->{$role}{$key} eq '') {
5290: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5291: } else {
5292: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5293: }
5294: }
5295: if ($role ne 'login') {
5296: $resulttext .= '</ul>';
5297: }
5298: }
5299: }
5300: }
1.3 raeburn 5301: return $resulttext;
1.1 raeburn 5302: }
5303:
1.9 raeburn 5304: sub thumb_dimensions {
5305: return ('200','50');
5306: }
5307:
1.16 raeburn 5308: sub check_dimensions {
5309: my ($inputfile) = @_;
5310: my ($fullwidth,$fullheight);
5311: if ($inputfile =~ m|^[/\w.\-]+$|) {
5312: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5313: my $imageinfo = <PIPE>;
5314: if (!close(PIPE)) {
5315: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5316: }
5317: chomp($imageinfo);
5318: my ($fullsize) =
1.21 raeburn 5319: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5320: if ($fullsize) {
5321: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5322: }
5323: }
5324: }
5325: return ($fullwidth,$fullheight);
5326: }
5327:
1.9 raeburn 5328: sub check_configuser {
5329: my ($uhome,$dom,$confname,$servadm) = @_;
5330: my ($configuserok,%currroles);
5331: if ($uhome eq 'no_host') {
5332: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5333: my $configpass = &LONCAPA::Enrollment::create_password();
5334: $configuserok =
5335: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5336: $configpass,'','','','','',undef,$servadm);
5337: } else {
5338: $configuserok = 'ok';
5339: %currroles =
5340: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5341: }
5342: return ($configuserok,%currroles);
5343: }
5344:
5345: sub check_authorstatus {
5346: my ($dom,$confname,%currroles) = @_;
5347: my $author_ok;
1.40 raeburn 5348: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5349: my $start = time;
5350: my $end = 0;
5351: $author_ok =
5352: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5353: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5354: } else {
5355: $author_ok = 'ok';
5356: }
5357: return $author_ok;
5358: }
5359:
5360: sub publishlogo {
1.46 raeburn 5361: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5362: my ($output,$fname,$logourl);
5363: if ($action eq 'upload') {
5364: $fname=$env{'form.'.$formname.'.filename'};
5365: chop($env{'form.'.$formname});
5366: } else {
5367: ($fname) = ($formname =~ /([^\/]+)$/);
5368: }
1.46 raeburn 5369: if ($savefileas ne '') {
5370: $fname = $savefileas;
5371: }
1.9 raeburn 5372: $fname=&Apache::lonnet::clean_filename($fname);
5373: # See if there is anything left
5374: unless ($fname) { return ('error: no uploaded file'); }
5375: $fname="$subdir/$fname";
1.160.6.5 raeburn 5376: my $docroot=$r->dir_config('lonDocRoot');
5377: my $filepath="$docroot/priv";
5378: my $relpath = "$dom/$confname";
1.9 raeburn 5379: my ($fnamepath,$file,$fetchthumb);
5380: $file=$fname;
5381: if ($fname=~m|/|) {
5382: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5383: }
1.160.6.5 raeburn 5384: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5385: my $count;
1.160.6.5 raeburn 5386: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5387: $filepath.="/$parts[$count]";
5388: if ((-e $filepath)!=1) {
5389: mkdir($filepath,02770);
5390: }
5391: }
5392: # Check for bad extension and disallow upload
5393: if ($file=~/\.(\w+)$/ &&
5394: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5395: $output =
5396: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5397: } elsif ($file=~/\.(\w+)$/ &&
5398: !defined(&Apache::loncommon::fileembstyle($1))) {
5399: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5400: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5401: $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 5402: } elsif (-d "$filepath/$file") {
5403: $output = &mt('File name is a directory name - rename the file and re-upload');
5404: } else {
5405: my $source = $filepath.'/'.$file;
5406: my $logfile;
5407: if (!open($logfile,">>$source".'.log')) {
5408: return (&mt('No write permission to Construction Space'));
5409: }
5410: print $logfile
5411: "\n================= Publish ".localtime()." ================\n".
5412: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5413: # Save the file
5414: if (!open(FH,'>'.$source)) {
5415: &Apache::lonnet::logthis('Failed to create '.$source);
5416: return (&mt('Failed to create file'));
5417: }
5418: if ($action eq 'upload') {
5419: if (!print FH ($env{'form.'.$formname})) {
5420: &Apache::lonnet::logthis('Failed to write to '.$source);
5421: return (&mt('Failed to write file'));
5422: }
5423: } else {
5424: my $original = &Apache::lonnet::filelocation('',$formname);
5425: if(!copy($original,$source)) {
5426: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5427: return (&mt('Failed to write file'));
5428: }
5429: }
5430: close(FH);
5431: chmod(0660, $source); # Permissions to rw-rw---.
5432:
5433: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5434: my $copyfile=$targetdir.'/'.$file;
5435:
5436: my @parts=split(/\//,$targetdir);
5437: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5438: for (my $count=5;$count<=$#parts;$count++) {
5439: $path.="/$parts[$count]";
5440: if (!-e $path) {
5441: print $logfile "\nCreating directory ".$path;
5442: mkdir($path,02770);
5443: }
5444: }
5445: my $versionresult;
5446: if (-e $copyfile) {
5447: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5448: } else {
5449: $versionresult = 'ok';
5450: }
5451: if ($versionresult eq 'ok') {
5452: if (copy($source,$copyfile)) {
5453: print $logfile "\nCopied original source to ".$copyfile."\n";
5454: $output = 'ok';
5455: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5456: push(@{$modified_urls},[$copyfile,$source]);
5457: my $metaoutput =
5458: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5459: unless ($registered_cleanup) {
5460: my $handlers = $r->get_handlers('PerlCleanupHandler');
5461: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5462: $registered_cleanup=1;
5463: }
1.9 raeburn 5464: } else {
5465: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5466: $output = &mt('Failed to copy file to RES space').", $!";
5467: }
5468: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5469: my $inputfile = $filepath.'/'.$file;
5470: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5471: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5472: if ($fullwidth ne '' && $fullheight ne '') {
5473: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5474: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5475: system("convert -sample $thumbsize $inputfile $outfile");
5476: chmod(0660, $filepath.'/tn-'.$file);
5477: if (-e $outfile) {
5478: my $copyfile=$targetdir.'/tn-'.$file;
5479: if (copy($outfile,$copyfile)) {
5480: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5481: my $thumb_metaoutput =
5482: &write_metadata($dom,$confname,$formname,
5483: $targetdir,'tn-'.$file,$logfile);
5484: push(@{$modified_urls},[$copyfile,$outfile]);
5485: unless ($registered_cleanup) {
5486: my $handlers = $r->get_handlers('PerlCleanupHandler');
5487: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5488: $registered_cleanup=1;
5489: }
1.16 raeburn 5490: } else {
5491: print $logfile "\nUnable to write ".$copyfile.
5492: ':'.$!."\n";
5493: }
5494: }
1.9 raeburn 5495: }
5496: }
5497: }
5498: } else {
5499: $output = $versionresult;
5500: }
5501: }
5502: return ($output,$logourl);
5503: }
5504:
5505: sub logo_versioning {
5506: my ($targetdir,$file,$logfile) = @_;
5507: my $target = $targetdir.'/'.$file;
5508: my ($maxversion,$fn,$extn,$output);
5509: $maxversion = 0;
5510: if ($file =~ /^(.+)\.(\w+)$/) {
5511: $fn=$1;
5512: $extn=$2;
5513: }
5514: opendir(DIR,$targetdir);
5515: while (my $filename=readdir(DIR)) {
5516: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5517: $maxversion=($1>$maxversion)?$1:$maxversion;
5518: }
5519: }
5520: $maxversion++;
5521: print $logfile "\nCreating old version ".$maxversion."\n";
5522: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5523: if (copy($target,$copyfile)) {
5524: print $logfile "Copied old target to ".$copyfile."\n";
5525: $copyfile=$copyfile.'.meta';
5526: if (copy($target.'.meta',$copyfile)) {
5527: print $logfile "Copied old target metadata to ".$copyfile."\n";
5528: $output = 'ok';
5529: } else {
5530: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5531: $output = &mt('Failed to copy old meta').", $!, ";
5532: }
5533: } else {
5534: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5535: $output = &mt('Failed to copy old target').", $!, ";
5536: }
5537: return $output;
5538: }
5539:
5540: sub write_metadata {
5541: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5542: my (%metadatafields,%metadatakeys,$output);
5543: $metadatafields{'title'}=$formname;
5544: $metadatafields{'creationdate'}=time;
5545: $metadatafields{'lastrevisiondate'}=time;
5546: $metadatafields{'copyright'}='public';
5547: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5548: $env{'user.domain'};
5549: $metadatafields{'authorspace'}=$confname.':'.$dom;
5550: $metadatafields{'domain'}=$dom;
5551: {
5552: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5553: my $mfh;
1.155 raeburn 5554: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5555: foreach (sort keys %metadatafields) {
5556: unless ($_=~/\./) {
5557: my $unikey=$_;
5558: $unikey=~/^([A-Za-z]+)/;
5559: my $tag=$1;
5560: $tag=~tr/A-Z/a-z/;
5561: print $mfh "\n\<$tag";
5562: foreach (split(/\,/,$metadatakeys{$unikey})) {
5563: my $value=$metadatafields{$unikey.'.'.$_};
5564: $value=~s/\"/\'\'/g;
5565: print $mfh ' '.$_.'="'.$value.'"';
5566: }
5567: print $mfh '>'.
5568: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5569: .'</'.$tag.'>';
5570: }
5571: }
5572: $output = 'ok';
5573: print $logfile "\nWrote metadata";
5574: close($mfh);
5575: } else {
5576: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5577: $output = &mt('Could not write metadata');
5578: }
5579: }
1.155 raeburn 5580: return $output;
5581: }
5582:
5583: sub notifysubscribed {
5584: foreach my $targetsource (@{$modified_urls}){
5585: next unless (ref($targetsource) eq 'ARRAY');
5586: my ($target,$source)=@{$targetsource};
5587: if ($source ne '') {
5588: if (open(my $logfh,'>>'.$source.'.log')) {
5589: print $logfh "\nCleanup phase: Notifications\n";
5590: my @subscribed=&subscribed_hosts($target);
5591: foreach my $subhost (@subscribed) {
5592: print $logfh "\nNotifying host ".$subhost.':';
5593: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5594: print $logfh $reply;
5595: }
5596: my @subscribedmeta=&subscribed_hosts("$target.meta");
5597: foreach my $subhost (@subscribedmeta) {
5598: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5599: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5600: $subhost);
5601: print $logfh $reply;
5602: }
5603: print $logfh "\n============ Done ============\n";
1.160 raeburn 5604: close($logfh);
1.155 raeburn 5605: }
5606: }
5607: }
5608: return OK;
5609: }
5610:
5611: sub subscribed_hosts {
5612: my ($target) = @_;
5613: my @subscribed;
5614: if (open(my $fh,"<$target.subscription")) {
5615: while (my $subline=<$fh>) {
5616: if ($subline =~ /^($match_lonid):/) {
5617: my $host = $1;
5618: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5619: unless (grep(/^\Q$host\E$/,@subscribed)) {
5620: push(@subscribed,$host);
5621: }
5622: }
5623: }
5624: }
5625: }
5626: return @subscribed;
1.9 raeburn 5627: }
5628:
5629: sub check_switchserver {
5630: my ($dom,$confname) = @_;
5631: my ($allowed,$switchserver);
5632: my $home = &Apache::lonnet::homeserver($confname,$dom);
5633: if ($home eq 'no_host') {
5634: $home = &Apache::lonnet::domain($dom,'primary');
5635: }
5636: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5637: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5638: if (!$allowed) {
5639: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5640: }
5641: return $switchserver;
5642: }
5643:
1.1 raeburn 5644: sub modify_quotas {
1.86 raeburn 5645: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5646: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5647: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5648: if ($action eq 'quotas') {
5649: $context = 'tools';
5650: } else {
5651: $context = $action;
5652: }
5653: if ($context eq 'requestcourses') {
1.98 raeburn 5654: @usertools = ('official','unofficial','community');
1.106 raeburn 5655: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5656: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5657: %titles = &courserequest_titles();
5658: $toolregexp = join('|',@usertools);
5659: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5660: } elsif ($context eq 'requestauthor') {
5661: @usertools = ('author');
5662: %titles = &authorrequest_titles();
1.86 raeburn 5663: } else {
1.160.6.4 raeburn 5664: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5665: %titles = &tool_titles();
1.86 raeburn 5666: }
1.72 raeburn 5667: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5668: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5669: foreach my $key (keys(%env)) {
1.101 raeburn 5670: if ($context eq 'requestcourses') {
5671: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5672: my $item = $1;
5673: my $type = $2;
5674: if ($type =~ /^limit_(.+)/) {
5675: $limithash{$item}{$1} = $env{$key};
5676: } else {
5677: $confhash{$item}{$type} = $env{$key};
5678: }
5679: }
1.160.6.5 raeburn 5680: } elsif ($context eq 'requestauthor') {
5681: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5682: $confhash{$1} = $env{$key};
5683: }
1.101 raeburn 5684: } else {
1.86 raeburn 5685: if ($key =~ /^form\.quota_(.+)$/) {
5686: $confhash{'defaultquota'}{$1} = $env{$key};
5687: }
1.101 raeburn 5688: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5689: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5690: }
1.72 raeburn 5691: }
5692: }
1.160.6.5 raeburn 5693: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5694: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5695: @approvalnotify = sort(@approvalnotify);
5696: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5697: if (ref($domconfig{$action}) eq 'HASH') {
5698: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5699: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5700: $changes{'notify'}{'approval'} = 1;
5701: }
5702: } else {
1.144 raeburn 5703: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5704: $changes{'notify'}{'approval'} = 1;
5705: }
5706: }
5707: } else {
1.144 raeburn 5708: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5709: $changes{'notify'}{'approval'} = 1;
5710: }
5711: }
5712: } else {
1.86 raeburn 5713: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5714: }
1.72 raeburn 5715: foreach my $item (@usertools) {
5716: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5717: my $unset;
1.101 raeburn 5718: if ($context eq 'requestcourses') {
1.104 raeburn 5719: $unset = '0';
5720: if ($type eq '_LC_adv') {
5721: $unset = '';
5722: }
1.101 raeburn 5723: if ($confhash{$item}{$type} eq 'autolimit') {
5724: $confhash{$item}{$type} .= '=';
5725: unless ($limithash{$item}{$type} =~ /\D/) {
5726: $confhash{$item}{$type} .= $limithash{$item}{$type};
5727: }
5728: }
1.160.6.5 raeburn 5729: } elsif ($context eq 'requestauthor') {
5730: $unset = '0';
5731: if ($type eq '_LC_adv') {
5732: $unset = '';
5733: }
1.72 raeburn 5734: } else {
1.101 raeburn 5735: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5736: $confhash{$item}{$type} = 1;
5737: } else {
5738: $confhash{$item}{$type} = 0;
5739: }
1.72 raeburn 5740: }
1.86 raeburn 5741: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5742: if ($action eq 'requestauthor') {
5743: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5744: $changes{$type} = 1;
5745: }
5746: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5747: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5748: $changes{$item}{$type} = 1;
5749: }
5750: } else {
5751: if ($context eq 'requestcourses') {
1.104 raeburn 5752: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5753: $changes{$item}{$type} = 1;
5754: }
5755: } else {
5756: if (!$confhash{$item}{$type}) {
5757: $changes{$item}{$type} = 1;
5758: }
5759: }
5760: }
5761: } else {
5762: if ($context eq 'requestcourses') {
1.104 raeburn 5763: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5764: $changes{$item}{$type} = 1;
5765: }
1.160.6.5 raeburn 5766: } elsif ($context eq 'requestauthor') {
5767: if ($confhash{$type} ne $unset) {
5768: $changes{$type} = 1;
5769: }
1.72 raeburn 5770: } else {
5771: if (!$confhash{$item}{$type}) {
5772: $changes{$item}{$type} = 1;
5773: }
5774: }
5775: }
1.1 raeburn 5776: }
5777: }
1.160.6.5 raeburn 5778: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5779: if (ref($domconfig{'quotas'}) eq 'HASH') {
5780: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5781: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5782: if (exists($confhash{'defaultquota'}{$key})) {
5783: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5784: $changes{'defaultquota'}{$key} = 1;
5785: }
5786: } else {
5787: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5788: }
5789: }
1.86 raeburn 5790: } else {
5791: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5792: if (exists($confhash{'defaultquota'}{$key})) {
5793: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5794: $changes{'defaultquota'}{$key} = 1;
5795: }
5796: } else {
5797: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5798: }
1.1 raeburn 5799: }
5800: }
5801: }
1.86 raeburn 5802: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5803: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5804: if (ref($domconfig{'quotas'}) eq 'HASH') {
5805: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5806: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5807: $changes{'defaultquota'}{$key} = 1;
5808: }
5809: } else {
5810: if (!exists($domconfig{'quotas'}{$key})) {
5811: $changes{'defaultquota'}{$key} = 1;
5812: }
1.72 raeburn 5813: }
5814: } else {
1.86 raeburn 5815: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5816: }
1.1 raeburn 5817: }
5818: }
5819: }
1.72 raeburn 5820:
1.160.6.5 raeburn 5821: if ($context eq 'requestauthor') {
5822: $domdefaults{'requestauthor'} = \%confhash;
5823: } else {
5824: foreach my $key (keys(%confhash)) {
5825: $domdefaults{$key} = $confhash{$key};
5826: }
1.72 raeburn 5827: }
1.160.6.5 raeburn 5828:
1.1 raeburn 5829: my %quotahash = (
1.86 raeburn 5830: $action => { %confhash }
1.1 raeburn 5831: );
5832: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5833: $dom);
5834: if ($putresult eq 'ok') {
5835: if (keys(%changes) > 0) {
1.72 raeburn 5836: my $cachetime = 24*60*60;
5837: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5838:
1.1 raeburn 5839: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 5840: unless (($context eq 'requestcourses') ||
5841: ($context eq 'requestauthor')) {
1.86 raeburn 5842: if (ref($changes{'defaultquota'}) eq 'HASH') {
5843: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5844: foreach my $type (@{$types},'default') {
5845: if (defined($changes{'defaultquota'}{$type})) {
5846: my $typetitle = $usertypes->{$type};
5847: if ($type eq 'default') {
5848: $typetitle = $othertitle;
5849: }
5850: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5851: }
5852: }
1.86 raeburn 5853: $resulttext .= '</ul></li>';
1.72 raeburn 5854: }
5855: }
1.80 raeburn 5856: my %newenv;
1.72 raeburn 5857: foreach my $item (@usertools) {
1.160.6.5 raeburn 5858: my (%haschgs,%inconf);
5859: if ($context eq 'requestauthor') {
5860: %haschgs = %changes;
5861: %inconf = %confhash;
5862: } else {
5863: if (ref($changes{$item}) eq 'HASH') {
5864: %haschgs = %{$changes{$item}};
5865: }
5866: if (ref($confhash{$item}) eq 'HASH') {
5867: %inconf = %{$confhash{$item}};
5868: }
5869: }
5870: if (keys(%haschgs) > 0) {
1.80 raeburn 5871: my $newacc =
5872: &Apache::lonnet::usertools_access($env{'user.name'},
5873: $env{'user.domain'},
1.86 raeburn 5874: $item,'reload',$context);
1.160.6.5 raeburn 5875: if (($context eq 'requestcourses') ||
5876: ($context eq 'requestauthor')) {
1.108 raeburn 5877: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5878: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5879: }
5880: } else {
5881: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5882: $newenv{'environment.availabletools.'.$item} = $newacc;
5883: }
1.80 raeburn 5884: }
1.160.6.5 raeburn 5885: unless ($context eq 'requestauthor') {
5886: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5887: }
1.72 raeburn 5888: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 5889: if ($haschgs{$type}) {
1.72 raeburn 5890: my $typetitle = $usertypes->{$type};
5891: if ($type eq 'default') {
5892: $typetitle = $othertitle;
5893: } elsif ($type eq '_LC_adv') {
5894: $typetitle = 'LON-CAPA Advanced Users';
5895: }
1.160.6.5 raeburn 5896: if ($inconf{$type}) {
1.101 raeburn 5897: if ($context eq 'requestcourses') {
5898: my $cond;
1.160.6.5 raeburn 5899: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5900: if ($1 eq '') {
5901: $cond = &mt('(Automatic processing of any request).');
5902: } else {
5903: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5904: }
5905: } else {
1.160.6.5 raeburn 5906: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5907: }
5908: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5909: } else {
5910: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5911: }
1.72 raeburn 5912: } else {
1.104 raeburn 5913: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 5914: if ($inconf{$type} eq '0') {
1.104 raeburn 5915: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5916: } else {
5917: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5918: }
5919: } else {
5920: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5921: }
1.72 raeburn 5922: }
5923: }
1.26 raeburn 5924: }
1.160.6.5 raeburn 5925: unless ($context eq 'requestauthor') {
5926: $resulttext .= '</ul></li>';
5927: }
1.26 raeburn 5928: }
1.1 raeburn 5929: }
1.160.6.5 raeburn 5930: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5931: if (ref($changes{'notify'}) eq 'HASH') {
5932: if ($changes{'notify'}{'approval'}) {
5933: if (ref($confhash{'notify'}) eq 'HASH') {
5934: if ($confhash{'notify'}{'approval'}) {
5935: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5936: } else {
1.160.6.5 raeburn 5937: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5938: }
5939: }
5940: }
5941: }
5942: }
1.1 raeburn 5943: $resulttext .= '</ul>';
1.80 raeburn 5944: if (keys(%newenv)) {
5945: &Apache::lonnet::appenv(\%newenv);
5946: }
1.1 raeburn 5947: } else {
1.86 raeburn 5948: if ($context eq 'requestcourses') {
5949: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 5950: } elsif ($context eq 'requestauthor') {
5951: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5952: } else {
1.90 weissno 5953: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5954: }
1.1 raeburn 5955: }
5956: } else {
1.11 albertel 5957: $resulttext = '<span class="LC_error">'.
5958: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5959: }
1.3 raeburn 5960: return $resulttext;
1.1 raeburn 5961: }
5962:
1.3 raeburn 5963: sub modify_autoenroll {
5964: my ($dom,%domconfig) = @_;
1.1 raeburn 5965: my ($resulttext,%changes);
5966: my %currautoenroll;
5967: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5968: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5969: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5970: }
5971: }
5972: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5973: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5974: sender => 'Sender for notification messages',
5975: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5976: my @offon = ('off','on');
1.17 raeburn 5977: my $sender_uname = $env{'form.sender_uname'};
5978: my $sender_domain = $env{'form.sender_domain'};
5979: if ($sender_domain eq '') {
5980: $sender_uname = '';
5981: } elsif ($sender_uname eq '') {
5982: $sender_domain = '';
5983: }
1.129 raeburn 5984: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5985: my %autoenrollhash = (
1.129 raeburn 5986: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5987: 'sender_uname' => $sender_uname,
5988: 'sender_domain' => $sender_domain,
5989: 'co-owners' => $coowners,
1.1 raeburn 5990: }
5991: );
1.4 raeburn 5992: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5993: $dom);
1.1 raeburn 5994: if ($putresult eq 'ok') {
5995: if (exists($currautoenroll{'run'})) {
5996: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5997: $changes{'run'} = 1;
5998: }
5999: } elsif ($autorun) {
6000: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6001: $changes{'run'} = 1;
1.1 raeburn 6002: }
6003: }
1.17 raeburn 6004: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6005: $changes{'sender'} = 1;
6006: }
1.17 raeburn 6007: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6008: $changes{'sender'} = 1;
6009: }
1.129 raeburn 6010: if ($currautoenroll{'co-owners'} ne '') {
6011: if ($currautoenroll{'co-owners'} ne $coowners) {
6012: $changes{'coowners'} = 1;
6013: }
6014: } elsif ($coowners) {
6015: $changes{'coowners'} = 1;
6016: }
1.1 raeburn 6017: if (keys(%changes) > 0) {
6018: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6019: if ($changes{'run'}) {
1.1 raeburn 6020: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6021: }
6022: if ($changes{'sender'}) {
1.17 raeburn 6023: if ($sender_uname eq '' || $sender_domain eq '') {
6024: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6025: } else {
6026: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6027: }
1.1 raeburn 6028: }
1.129 raeburn 6029: if ($changes{'coowners'}) {
6030: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6031: &Apache::loncommon::devalidate_domconfig_cache($dom);
6032: }
1.1 raeburn 6033: $resulttext .= '</ul>';
6034: } else {
6035: $resulttext = &mt('No changes made to auto-enrollment settings');
6036: }
6037: } else {
1.11 albertel 6038: $resulttext = '<span class="LC_error">'.
6039: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6040: }
1.3 raeburn 6041: return $resulttext;
1.1 raeburn 6042: }
6043:
6044: sub modify_autoupdate {
1.3 raeburn 6045: my ($dom,%domconfig) = @_;
1.1 raeburn 6046: my ($resulttext,%currautoupdate,%fields,%changes);
6047: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6048: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6049: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6050: }
6051: }
6052: my @offon = ('off','on');
6053: my %title = &Apache::lonlocal::texthash (
6054: run => 'Auto-update:',
6055: classlists => 'Updates to user information in classlists?'
6056: );
1.44 raeburn 6057: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6058: my %fieldtitles = &Apache::lonlocal::texthash (
6059: id => 'Student/Employee ID',
1.20 raeburn 6060: permanentemail => 'E-mail address',
1.1 raeburn 6061: lastname => 'Last Name',
6062: firstname => 'First Name',
6063: middlename => 'Middle Name',
1.132 raeburn 6064: generation => 'Generation',
1.1 raeburn 6065: );
1.142 raeburn 6066: $othertitle = &mt('All users');
1.1 raeburn 6067: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6068: $othertitle = &mt('Other users');
1.1 raeburn 6069: }
6070: foreach my $key (keys(%env)) {
6071: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6072: my ($usertype,$item) = ($1,$2);
6073: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6074: if ($usertype eq 'default') {
6075: push(@{$fields{$1}},$2);
6076: } elsif (ref($types) eq 'ARRAY') {
6077: if (grep(/^\Q$usertype\E$/,@{$types})) {
6078: push(@{$fields{$1}},$2);
6079: }
6080: }
6081: }
1.1 raeburn 6082: }
6083: }
1.131 raeburn 6084: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6085: @lockablenames = sort(@lockablenames);
6086: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6087: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6088: if (@changed) {
6089: $changes{'lockablenames'} = 1;
6090: }
6091: } else {
6092: if (@lockablenames) {
6093: $changes{'lockablenames'} = 1;
6094: }
6095: }
1.1 raeburn 6096: my %updatehash = (
6097: autoupdate => { run => $env{'form.autoupdate_run'},
6098: classlists => $env{'form.classlists'},
6099: fields => {%fields},
1.131 raeburn 6100: lockablenames => \@lockablenames,
1.1 raeburn 6101: }
6102: );
6103: foreach my $key (keys(%currautoupdate)) {
6104: if (($key eq 'run') || ($key eq 'classlists')) {
6105: if (exists($updatehash{autoupdate}{$key})) {
6106: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6107: $changes{$key} = 1;
6108: }
6109: }
6110: } elsif ($key eq 'fields') {
6111: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6112: foreach my $item (@{$types},'default') {
1.1 raeburn 6113: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6114: my $change = 0;
6115: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6116: if (!exists($fields{$item})) {
6117: $change = 1;
1.132 raeburn 6118: last;
1.1 raeburn 6119: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6120: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6121: $change = 1;
1.132 raeburn 6122: last;
1.1 raeburn 6123: }
6124: }
6125: }
6126: if ($change) {
6127: push(@{$changes{$key}},$item);
6128: }
1.26 raeburn 6129: }
1.1 raeburn 6130: }
6131: }
1.131 raeburn 6132: } elsif ($key eq 'lockablenames') {
6133: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6134: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6135: if (@changed) {
6136: $changes{'lockablenames'} = 1;
6137: }
6138: } else {
6139: if (@lockablenames) {
6140: $changes{'lockablenames'} = 1;
6141: }
6142: }
6143: }
6144: }
6145: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6146: if (@lockablenames) {
6147: $changes{'lockablenames'} = 1;
1.1 raeburn 6148: }
6149: }
1.26 raeburn 6150: foreach my $item (@{$types},'default') {
6151: if (defined($fields{$item})) {
6152: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6153: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6154: my $change = 0;
6155: if (ref($fields{$item}) eq 'ARRAY') {
6156: foreach my $type (@{$fields{$item}}) {
6157: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6158: $change = 1;
6159: last;
6160: }
6161: }
6162: }
6163: if ($change) {
6164: push(@{$changes{'fields'}},$item);
6165: }
6166: } else {
1.26 raeburn 6167: push(@{$changes{'fields'}},$item);
6168: }
6169: } else {
6170: push(@{$changes{'fields'}},$item);
1.1 raeburn 6171: }
6172: }
6173: }
6174: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6175: $dom);
6176: if ($putresult eq 'ok') {
6177: if (keys(%changes) > 0) {
6178: $resulttext = &mt('Changes made:').'<ul>';
6179: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6180: if ($key eq 'lockablenames') {
6181: $resulttext .= '<li>';
6182: if (@lockablenames) {
6183: $usertypes->{'default'} = $othertitle;
6184: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6185: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6186: } else {
6187: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6188: }
6189: $resulttext .= '</li>';
6190: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6191: foreach my $item (@{$changes{$key}}) {
6192: my @newvalues;
6193: foreach my $type (@{$fields{$item}}) {
6194: push(@newvalues,$fieldtitles{$type});
6195: }
1.3 raeburn 6196: my $newvaluestr;
6197: if (@newvalues > 0) {
6198: $newvaluestr = join(', ',@newvalues);
6199: } else {
6200: $newvaluestr = &mt('none');
1.6 raeburn 6201: }
1.1 raeburn 6202: if ($item eq 'default') {
1.26 raeburn 6203: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6204: } else {
1.26 raeburn 6205: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6206: }
6207: }
6208: } else {
6209: my $newvalue;
6210: if ($key eq 'run') {
6211: $newvalue = $offon[$env{'form.autoupdate_run'}];
6212: } else {
6213: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6214: }
1.1 raeburn 6215: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6216: }
6217: }
6218: $resulttext .= '</ul>';
6219: } else {
1.3 raeburn 6220: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6221: }
6222: } else {
1.11 albertel 6223: $resulttext = '<span class="LC_error">'.
6224: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6225: }
1.3 raeburn 6226: return $resulttext;
1.1 raeburn 6227: }
6228:
1.125 raeburn 6229: sub modify_autocreate {
6230: my ($dom,%domconfig) = @_;
6231: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6232: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6233: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6234: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6235: }
6236: }
6237: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6238: req => 'Auto-creation of validated requests for official courses',
6239: xmldc => 'Identity of course creator of courses from XML files',
6240: );
6241: my @types = ('xml','req');
6242: foreach my $item (@types) {
6243: $newvals{$item} = $env{'form.autocreate_'.$item};
6244: $newvals{$item} =~ s/\D//g;
6245: $newvals{$item} = 0 if ($newvals{$item} eq '');
6246: }
6247: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6248: my %domcoords = &get_active_dcs($dom);
6249: unless (exists($domcoords{$newvals{'xmldc'}})) {
6250: $newvals{'xmldc'} = '';
6251: }
6252: %autocreatehash = (
6253: autocreate => { xml => $newvals{'xml'},
6254: req => $newvals{'req'},
6255: }
6256: );
6257: if ($newvals{'xmldc'} ne '') {
6258: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6259: }
6260: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6261: $dom);
6262: if ($putresult eq 'ok') {
6263: my @items = @types;
6264: if ($newvals{'xml'}) {
6265: push(@items,'xmldc');
6266: }
6267: foreach my $item (@items) {
6268: if (exists($currautocreate{$item})) {
6269: if ($currautocreate{$item} ne $newvals{$item}) {
6270: $changes{$item} = 1;
6271: }
6272: } elsif ($newvals{$item}) {
6273: $changes{$item} = 1;
6274: }
6275: }
6276: if (keys(%changes) > 0) {
6277: my @offon = ('off','on');
6278: $resulttext = &mt('Changes made:').'<ul>';
6279: foreach my $item (@types) {
6280: if ($changes{$item}) {
6281: my $newtxt = $offon[$newvals{$item}];
6282: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6283: }
6284: }
6285: if ($changes{'xmldc'}) {
6286: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6287: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
6288: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6289: }
6290: $resulttext .= '</ul>';
6291: } else {
6292: $resulttext = &mt('No changes made to auto-creation settings');
6293: }
6294: } else {
6295: $resulttext = '<span class="LC_error">'.
6296: &mt('An error occurred: [_1]',$putresult).'</span>';
6297: }
6298: return $resulttext;
6299: }
6300:
1.23 raeburn 6301: sub modify_directorysrch {
6302: my ($dom,%domconfig) = @_;
6303: my ($resulttext,%changes);
6304: my %currdirsrch;
6305: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6306: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6307: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6308: }
6309: }
6310: my %title = ( available => 'Directory search available',
1.24 raeburn 6311: localonly => 'Other domains can search',
1.23 raeburn 6312: searchby => 'Search types',
6313: searchtypes => 'Search latitude');
6314: my @offon = ('off','on');
1.24 raeburn 6315: my @otherdoms = ('Yes','No');
1.23 raeburn 6316:
1.25 raeburn 6317: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6318: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6319: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6320:
1.44 raeburn 6321: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6322: if (keys(%{$usertypes}) == 0) {
6323: @cansearch = ('default');
6324: } else {
6325: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6326: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6327: if (!grep(/^\Q$type\E$/,@cansearch)) {
6328: push(@{$changes{'cansearch'}},$type);
6329: }
1.23 raeburn 6330: }
1.26 raeburn 6331: foreach my $type (@cansearch) {
6332: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6333: push(@{$changes{'cansearch'}},$type);
6334: }
1.23 raeburn 6335: }
1.26 raeburn 6336: } else {
6337: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6338: }
6339: }
6340:
6341: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6342: foreach my $by (@{$currdirsrch{'searchby'}}) {
6343: if (!grep(/^\Q$by\E$/,@searchby)) {
6344: push(@{$changes{'searchby'}},$by);
6345: }
6346: }
6347: foreach my $by (@searchby) {
6348: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6349: push(@{$changes{'searchby'}},$by);
6350: }
6351: }
6352: } else {
6353: push(@{$changes{'searchby'}},@searchby);
6354: }
1.25 raeburn 6355:
6356: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6357: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6358: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6359: push(@{$changes{'searchtypes'}},$type);
6360: }
6361: }
6362: foreach my $type (@searchtypes) {
6363: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6364: push(@{$changes{'searchtypes'}},$type);
6365: }
6366: }
6367: } else {
6368: if (exists($currdirsrch{'searchtypes'})) {
6369: foreach my $type (@searchtypes) {
6370: if ($type ne $currdirsrch{'searchtypes'}) {
6371: push(@{$changes{'searchtypes'}},$type);
6372: }
6373: }
6374: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6375: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6376: }
6377: } else {
6378: push(@{$changes{'searchtypes'}},@searchtypes);
6379: }
6380: }
6381:
1.23 raeburn 6382: my %dirsrch_hash = (
6383: directorysrch => { available => $env{'form.dirsrch_available'},
6384: cansearch => \@cansearch,
1.24 raeburn 6385: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6386: searchby => \@searchby,
1.25 raeburn 6387: searchtypes => \@searchtypes,
1.23 raeburn 6388: }
6389: );
6390: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6391: $dom);
6392: if ($putresult eq 'ok') {
6393: if (exists($currdirsrch{'available'})) {
6394: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6395: $changes{'available'} = 1;
6396: }
6397: } else {
6398: if ($env{'form.dirsrch_available'} eq '1') {
6399: $changes{'available'} = 1;
6400: }
6401: }
1.24 raeburn 6402: if (exists($currdirsrch{'localonly'})) {
6403: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6404: $changes{'localonly'} = 1;
6405: }
6406: } else {
6407: if ($env{'form.dirsrch_localonly'} eq '1') {
6408: $changes{'localonly'} = 1;
6409: }
6410: }
1.23 raeburn 6411: if (keys(%changes) > 0) {
6412: $resulttext = &mt('Changes made:').'<ul>';
6413: if ($changes{'available'}) {
6414: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6415: }
1.24 raeburn 6416: if ($changes{'localonly'}) {
6417: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6418: }
6419:
1.23 raeburn 6420: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6421: my $chgtext;
1.26 raeburn 6422: if (ref($usertypes) eq 'HASH') {
6423: if (keys(%{$usertypes}) > 0) {
6424: foreach my $type (@{$types}) {
6425: if (grep(/^\Q$type\E$/,@cansearch)) {
6426: $chgtext .= $usertypes->{$type}.'; ';
6427: }
6428: }
6429: if (grep(/^default$/,@cansearch)) {
6430: $chgtext .= $othertitle;
6431: } else {
6432: $chgtext =~ s/\; $//;
6433: }
6434: $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 6435: }
6436: }
6437: }
6438: if (ref($changes{'searchby'}) eq 'ARRAY') {
6439: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6440: my $chgtext;
6441: foreach my $type (@{$titleorder}) {
6442: if (grep(/^\Q$type\E$/,@searchby)) {
6443: if (defined($searchtitles->{$type})) {
6444: $chgtext .= $searchtitles->{$type}.'; ';
6445: }
6446: }
6447: }
6448: $chgtext =~ s/\; $//;
6449: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6450: }
1.25 raeburn 6451: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6452: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6453: my $chgtext;
6454: foreach my $type (@{$srchtypeorder}) {
6455: if (grep(/^\Q$type\E$/,@searchtypes)) {
6456: if (defined($srchtypes_desc->{$type})) {
6457: $chgtext .= $srchtypes_desc->{$type}.'; ';
6458: }
6459: }
6460: }
6461: $chgtext =~ s/\; $//;
6462: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 6463: }
6464: $resulttext .= '</ul>';
6465: } else {
6466: $resulttext = &mt('No changes made to institution directory search settings');
6467: }
6468: } else {
6469: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6470: &mt('An error occurred: [_1]',$putresult).'</span>';
6471: }
6472: return $resulttext;
6473: }
6474:
1.28 raeburn 6475: sub modify_contacts {
6476: my ($dom,%domconfig) = @_;
6477: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6478: if (ref($domconfig{'contacts'}) eq 'HASH') {
6479: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6480: $currsetting{$key} = $domconfig{'contacts'}{$key};
6481: }
6482: }
1.134 raeburn 6483: my (%others,%to,%bcc);
1.28 raeburn 6484: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6485: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6486: 'requestsmail');
1.28 raeburn 6487: foreach my $type (@mailings) {
6488: @{$newsetting{$type}} =
6489: &Apache::loncommon::get_env_multiple('form.'.$type);
6490: foreach my $item (@contacts) {
6491: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6492: $contacts_hash{contacts}{$type}{$item} = 1;
6493: } else {
6494: $contacts_hash{contacts}{$type}{$item} = 0;
6495: }
6496: }
6497: $others{$type} = $env{'form.'.$type.'_others'};
6498: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6499: if ($type eq 'helpdeskmail') {
6500: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6501: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6502: }
1.28 raeburn 6503: }
6504: foreach my $item (@contacts) {
6505: $to{$item} = $env{'form.'.$item};
6506: $contacts_hash{'contacts'}{$item} = $to{$item};
6507: }
6508: if (keys(%currsetting) > 0) {
6509: foreach my $item (@contacts) {
6510: if ($to{$item} ne $currsetting{$item}) {
6511: $changes{$item} = 1;
6512: }
6513: }
6514: foreach my $type (@mailings) {
6515: foreach my $item (@contacts) {
6516: if (ref($currsetting{$type}) eq 'HASH') {
6517: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6518: push(@{$changes{$type}},$item);
6519: }
6520: } else {
6521: push(@{$changes{$type}},@{$newsetting{$type}});
6522: }
6523: }
6524: if ($others{$type} ne $currsetting{$type}{'others'}) {
6525: push(@{$changes{$type}},'others');
6526: }
1.134 raeburn 6527: if ($type eq 'helpdeskmail') {
6528: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6529: push(@{$changes{$type}},'bcc');
6530: }
6531: }
1.28 raeburn 6532: }
6533: } else {
6534: my %default;
6535: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6536: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6537: $default{'errormail'} = 'adminemail';
6538: $default{'packagesmail'} = 'adminemail';
6539: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6540: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6541: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6542: foreach my $item (@contacts) {
6543: if ($to{$item} ne $default{$item}) {
6544: $changes{$item} = 1;
6545: }
6546: }
6547: foreach my $type (@mailings) {
6548: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6549:
6550: push(@{$changes{$type}},@{$newsetting{$type}});
6551: }
6552: if ($others{$type} ne '') {
6553: push(@{$changes{$type}},'others');
1.134 raeburn 6554: }
6555: if ($type eq 'helpdeskmail') {
6556: if ($bcc{$type} ne '') {
6557: push(@{$changes{$type}},'bcc');
6558: }
6559: }
1.28 raeburn 6560: }
6561: }
6562: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6563: $dom);
6564: if ($putresult eq 'ok') {
6565: if (keys(%changes) > 0) {
6566: my ($titles,$short_titles) = &contact_titles();
6567: $resulttext = &mt('Changes made:').'<ul>';
6568: foreach my $item (@contacts) {
6569: if ($changes{$item}) {
6570: $resulttext .= '<li>'.$titles->{$item}.
6571: &mt(' set to: ').
6572: '<span class="LC_cusr_emph">'.
6573: $to{$item}.'</span></li>';
6574: }
6575: }
6576: foreach my $type (@mailings) {
6577: if (ref($changes{$type}) eq 'ARRAY') {
6578: $resulttext .= '<li>'.$titles->{$type}.': ';
6579: my @text;
6580: foreach my $item (@{$newsetting{$type}}) {
6581: push(@text,$short_titles->{$item});
6582: }
6583: if ($others{$type} ne '') {
6584: push(@text,$others{$type});
6585: }
6586: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6587: join(', ',@text).'</span>';
6588: if ($type eq 'helpdeskmail') {
6589: if ($bcc{$type} ne '') {
6590: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6591: }
6592: }
6593: $resulttext .= '</li>';
1.28 raeburn 6594: }
6595: }
6596: $resulttext .= '</ul>';
6597: } else {
1.34 raeburn 6598: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6599: }
6600: } else {
6601: $resulttext = '<span class="LC_error">'.
6602: &mt('An error occurred: [_1].',$putresult).'</span>';
6603: }
6604: return $resulttext;
6605: }
6606:
6607: sub modify_usercreation {
1.27 raeburn 6608: my ($dom,%domconfig) = @_;
1.34 raeburn 6609: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6610: my $warningmsg;
1.27 raeburn 6611: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6612: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6613: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6614: }
6615: }
6616: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6617: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6618: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6619: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6620: foreach my $item(@contexts) {
1.45 raeburn 6621: if ($item eq 'selfcreate') {
1.50 raeburn 6622: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6623: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6624: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6625: if (ref($cancreate{$item}) eq 'ARRAY') {
6626: if (grep(/^login$/,@{$cancreate{$item}})) {
6627: $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.');
6628: }
1.43 raeburn 6629: }
6630: }
1.50 raeburn 6631: } else {
6632: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6633: }
1.34 raeburn 6634: }
1.93 raeburn 6635: my ($othertitle,$usertypes,$types) =
6636: &Apache::loncommon::sorted_inst_types($dom);
6637: if (ref($types) eq 'ARRAY') {
6638: if (@{$types} > 0) {
6639: @{$cancreate{'statustocreate'}} =
6640: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6641: } else {
6642: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6643: }
6644: push(@contexts,'statustocreate');
6645: }
1.160.6.5 raeburn 6646: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6647: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6648: foreach my $item (@contexts) {
1.93 raeburn 6649: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6650: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6651: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6652: if (ref($cancreate{$item}) eq 'ARRAY') {
6653: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6654: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6655: push(@{$changes{'cancreate'}},$item);
6656: }
1.50 raeburn 6657: }
6658: }
6659: }
6660: } else {
6661: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6662: if (@{$cancreate{$item}} > 0) {
6663: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6664: push(@{$changes{'cancreate'}},$item);
6665: }
6666: }
6667: } else {
6668: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6669: if (@{$cancreate{$item}} < 3) {
6670: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6671: push(@{$changes{'cancreate'}},$item);
6672: }
6673: }
6674: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6675: if (@{$cancreate{$item}} > 0) {
6676: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6677: push(@{$changes{'cancreate'}},$item);
6678: }
6679: }
6680: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6681: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6682: push(@{$changes{'cancreate'}},$item);
6683: }
6684: }
6685: }
6686: }
6687: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6688: foreach my $type (@{$cancreate{$item}}) {
6689: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6690: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6691: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6692: push(@{$changes{'cancreate'}},$item);
6693: }
6694: }
6695: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6696: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6697: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6698: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6699: push(@{$changes{'cancreate'}},$item);
6700: }
6701: }
6702: }
6703: }
6704: }
6705: } else {
6706: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6707: push(@{$changes{'cancreate'}},$item);
6708: }
6709: }
1.27 raeburn 6710: }
1.34 raeburn 6711: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6712: foreach my $item (@contexts) {
1.43 raeburn 6713: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6714: if ($cancreate{$item} ne 'any') {
6715: push(@{$changes{'cancreate'}},$item);
6716: }
6717: } else {
6718: if ($cancreate{$item} ne 'none') {
6719: push(@{$changes{'cancreate'}},$item);
6720: }
1.27 raeburn 6721: }
6722: }
6723: } else {
1.43 raeburn 6724: foreach my $item (@contexts) {
1.34 raeburn 6725: push(@{$changes{'cancreate'}},$item);
6726: }
1.27 raeburn 6727: }
1.34 raeburn 6728:
1.27 raeburn 6729: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6730: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6731: if (!grep(/^\Q$type\E$/,@username_rule)) {
6732: push(@{$changes{'username_rule'}},$type);
6733: }
6734: }
6735: foreach my $type (@username_rule) {
6736: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6737: push(@{$changes{'username_rule'}},$type);
6738: }
6739: }
6740: } else {
6741: push(@{$changes{'username_rule'}},@username_rule);
6742: }
6743:
1.32 raeburn 6744: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6745: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6746: if (!grep(/^\Q$type\E$/,@id_rule)) {
6747: push(@{$changes{'id_rule'}},$type);
6748: }
6749: }
6750: foreach my $type (@id_rule) {
6751: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6752: push(@{$changes{'id_rule'}},$type);
6753: }
6754: }
6755: } else {
6756: push(@{$changes{'id_rule'}},@id_rule);
6757: }
6758:
1.43 raeburn 6759: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6760: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6761: if (!grep(/^\Q$type\E$/,@email_rule)) {
6762: push(@{$changes{'email_rule'}},$type);
6763: }
6764: }
6765: foreach my $type (@email_rule) {
6766: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6767: push(@{$changes{'email_rule'}},$type);
6768: }
6769: }
6770: } else {
6771: push(@{$changes{'email_rule'}},@email_rule);
6772: }
6773:
6774: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6775: my @authtypes = ('int','krb4','krb5','loc');
6776: my %authhash;
1.43 raeburn 6777: foreach my $item (@authen_contexts) {
1.28 raeburn 6778: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6779: foreach my $auth (@authtypes) {
6780: if (grep(/^\Q$auth\E$/,@authallowed)) {
6781: $authhash{$item}{$auth} = 1;
6782: } else {
6783: $authhash{$item}{$auth} = 0;
6784: }
6785: }
6786: }
6787: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6788: foreach my $item (@authen_contexts) {
1.28 raeburn 6789: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6790: foreach my $auth (@authtypes) {
6791: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6792: push(@{$changes{'authtypes'}},$item);
6793: last;
6794: }
6795: }
6796: }
6797: }
6798: } else {
1.43 raeburn 6799: foreach my $item (@authen_contexts) {
1.28 raeburn 6800: push(@{$changes{'authtypes'}},$item);
6801: }
6802: }
6803:
1.27 raeburn 6804: my %usercreation_hash = (
1.28 raeburn 6805: usercreation => {
1.34 raeburn 6806: cancreate => \%cancreate,
1.27 raeburn 6807: username_rule => \@username_rule,
1.32 raeburn 6808: id_rule => \@id_rule,
1.43 raeburn 6809: email_rule => \@email_rule,
1.32 raeburn 6810: authtypes => \%authhash,
1.27 raeburn 6811: }
6812: );
6813:
6814: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6815: $dom);
1.50 raeburn 6816:
6817: my %selfcreatetypes = (
6818: sso => 'users authenticated by institutional single sign on',
6819: login => 'users authenticated by institutional log-in',
6820: email => 'users who provide a valid e-mail address for use as the username',
6821: );
1.27 raeburn 6822: if ($putresult eq 'ok') {
6823: if (keys(%changes) > 0) {
6824: $resulttext = &mt('Changes made:').'<ul>';
6825: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6826: my %lt = &usercreation_types();
6827: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6828: my $chgtext;
1.160.6.5 raeburn 6829: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6830: $chgtext = $lt{$type}.', ';
6831: }
1.45 raeburn 6832: if ($type eq 'selfcreate') {
1.50 raeburn 6833: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6834: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6835: } else {
1.100 raeburn 6836: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6837: foreach my $case (@{$cancreate{$type}}) {
6838: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6839: }
6840: $chgtext .= '</ul>';
1.100 raeburn 6841: if (ref($cancreate{$type}) eq 'ARRAY') {
6842: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6843: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6844: if (@{$cancreate{'statustocreate'}} == 0) {
6845: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6846: }
6847: }
6848: }
6849: }
1.43 raeburn 6850: }
1.93 raeburn 6851: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6852: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6853: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6854: if (@{$cancreate{'selfcreate'}} > 0) {
6855: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6856:
6857: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6858: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6859: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6860: }
1.96 raeburn 6861: } elsif (ref($usertypes) eq 'HASH') {
6862: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6863: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6864: } else {
6865: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6866: }
6867: $chgtext .= '<ul>';
6868: foreach my $case (@{$cancreate{$type}}) {
6869: if ($case eq 'default') {
6870: $chgtext .= '<li>'.$othertitle.'</li>';
6871: } else {
6872: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6873: }
6874: }
1.100 raeburn 6875: $chgtext .= '</ul>';
6876: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6877: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6878: }
6879: }
6880: } else {
6881: if (@{$cancreate{$type}} == 0) {
6882: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6883: } else {
6884: $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 6885: }
6886: }
6887: }
1.160.6.5 raeburn 6888: } elsif ($type eq 'captcha') {
6889: if ($cancreate{$type} eq 'notused') {
6890: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6891: } else {
6892: my %captchas = &captcha_phrases();
6893: if ($captchas{$cancreate{$type}}) {
6894: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6895: } else {
6896: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6897: }
6898: }
6899: } elsif ($type eq 'recaptchakeys') {
6900: my ($privkey,$pubkey);
6901: if (ref($cancreate{$type}) eq 'HASH') {
6902: $pubkey = $cancreate{$type}{'public'};
6903: $privkey = $cancreate{$type}{'private'};
6904: }
6905: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6906: if (!$pubkey) {
6907: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6908: } else {
6909: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6910: }
6911: if (!$privkey) {
6912: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6913: } else {
6914: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6915: }
6916: $chgtext .= '</ul>';
1.43 raeburn 6917: } else {
6918: if ($cancreate{$type} eq 'none') {
6919: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6920: } elsif ($cancreate{$type} eq 'any') {
6921: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6922: } elsif ($cancreate{$type} eq 'official') {
6923: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6924: } elsif ($cancreate{$type} eq 'unofficial') {
6925: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6926: }
1.34 raeburn 6927: }
6928: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6929: }
6930: }
6931: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6932: my ($rules,$ruleorder) =
6933: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6934: my $chgtext = '<ul>';
6935: foreach my $type (@username_rule) {
6936: if (ref($rules->{$type}) eq 'HASH') {
6937: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6938: }
6939: }
6940: $chgtext .= '</ul>';
6941: if (@username_rule > 0) {
6942: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6943: } else {
1.28 raeburn 6944: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6945: }
6946: }
1.32 raeburn 6947: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6948: my ($idrules,$idruleorder) =
6949: &Apache::lonnet::inst_userrules($dom,'id');
6950: my $chgtext = '<ul>';
6951: foreach my $type (@id_rule) {
6952: if (ref($idrules->{$type}) eq 'HASH') {
6953: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6954: }
6955: }
6956: $chgtext .= '</ul>';
6957: if (@id_rule > 0) {
6958: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6959: } else {
6960: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6961: }
6962: }
1.43 raeburn 6963: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6964: my ($emailrules,$emailruleorder) =
6965: &Apache::lonnet::inst_userrules($dom,'email');
6966: my $chgtext = '<ul>';
6967: foreach my $type (@email_rule) {
6968: if (ref($emailrules->{$type}) eq 'HASH') {
6969: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6970: }
6971: }
6972: $chgtext .= '</ul>';
6973: if (@email_rule > 0) {
6974: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6975: } else {
6976: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6977: }
6978: }
6979:
1.28 raeburn 6980: my %authname = &authtype_names();
6981: my %context_title = &context_names();
6982: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6983: my $chgtext = '<ul>';
6984: foreach my $type (@{$changes{'authtypes'}}) {
6985: my @allowed;
6986: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6987: foreach my $auth (@authtypes) {
6988: if ($authhash{$type}{$auth}) {
6989: push(@allowed,$authname{$auth});
6990: }
6991: }
1.43 raeburn 6992: if (@allowed > 0) {
6993: $chgtext .= join(', ',@allowed).'</li>';
6994: } else {
6995: $chgtext .= &mt('none').'</li>';
6996: }
1.28 raeburn 6997: }
6998: $chgtext .= '</ul>';
6999: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7000: $resulttext .= '</li>';
7001: }
1.27 raeburn 7002: $resulttext .= '</ul>';
7003: } else {
1.28 raeburn 7004: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7005: }
7006: } else {
7007: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7008: &mt('An error occurred: [_1]',$putresult).'</span>';
7009: }
1.43 raeburn 7010: if ($warningmsg ne '') {
7011: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7012: }
1.23 raeburn 7013: return $resulttext;
7014: }
7015:
1.160.6.5 raeburn 7016: sub process_captcha {
7017: my ($container,$changes,$newsettings,$current) = @_;
7018: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7019: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7020: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7021: $newsettings->{'captcha'} = 'original';
7022: }
7023: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7024: if ($container eq 'cancreate') {
7025: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7026: push(@{$changes->{'cancreate'}},'captcha');
7027: } elsif (!defined($changes->{'cancreate'})) {
7028: $changes->{'cancreate'} = ['captcha'];
7029: }
7030: } else {
7031: $changes->{'captcha'} = 1;
7032: }
7033: }
7034: my ($newpub,$newpriv,$currpub,$currpriv);
7035: if ($newsettings->{'captcha'} eq 'recaptcha') {
7036: $newpub = $env{'form.'.$container.'_recaptchapub'};
7037: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7038: $newpub =~ s/\W//g;
7039: $newpriv =~ s/\W//g;
7040: $newsettings->{'recaptchakeys'} = {
7041: public => $newpub,
7042: private => $newpriv,
7043: };
7044: }
7045: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7046: $currpub = $current->{'recaptchakeys'}{'public'};
7047: $currpriv = $current->{'recaptchakeys'}{'private'};
7048: $newsettings->{'recaptchakeys'} = {
7049: public => '',
7050: private => '',
7051: }
7052: }
7053: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7054: if ($container eq 'cancreate') {
7055: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7056: push(@{$changes->{'cancreate'}},'recaptchakeys');
7057: } elsif (!defined($changes->{'cancreate'})) {
7058: $changes->{'cancreate'} = ['recaptchakeys'];
7059: }
7060: } else {
7061: $changes->{'recaptchakeys'} = 1;
7062: }
7063: }
7064: return;
7065: }
7066:
1.33 raeburn 7067: sub modify_usermodification {
7068: my ($dom,%domconfig) = @_;
7069: my ($resulttext,%curr_usermodification,%changes);
7070: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7071: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7072: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7073: }
7074: }
1.63 raeburn 7075: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7076: my %context_title = (
7077: author => 'In author context',
7078: course => 'In course context',
1.63 raeburn 7079: selfcreate => 'When self creating account',
1.33 raeburn 7080: );
7081: my @fields = ('lastname','firstname','middlename','generation',
7082: 'permanentemail','id');
7083: my %roles = (
7084: author => ['ca','aa'],
7085: course => ['st','ep','ta','in','cr'],
7086: );
1.63 raeburn 7087: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7088: if (ref($types) eq 'ARRAY') {
7089: push(@{$types},'default');
7090: $usertypes->{'default'} = $othertitle;
7091: }
7092: $roles{'selfcreate'} = $types;
1.33 raeburn 7093: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7094: my %modifyhash;
7095: foreach my $context (@contexts) {
7096: foreach my $role (@{$roles{$context}}) {
7097: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7098: foreach my $item (@fields) {
7099: if (grep(/^\Q$item\E$/,@modifiable)) {
7100: $modifyhash{$context}{$role}{$item} = 1;
7101: } else {
7102: $modifyhash{$context}{$role}{$item} = 0;
7103: }
7104: }
7105: }
7106: if (ref($curr_usermodification{$context}) eq 'HASH') {
7107: foreach my $role (@{$roles{$context}}) {
7108: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7109: foreach my $field (@fields) {
7110: if ($modifyhash{$context}{$role}{$field} ne
7111: $curr_usermodification{$context}{$role}{$field}) {
7112: push(@{$changes{$context}},$role);
7113: last;
7114: }
7115: }
7116: }
7117: }
7118: } else {
7119: foreach my $context (@contexts) {
7120: foreach my $role (@{$roles{$context}}) {
7121: push(@{$changes{$context}},$role);
7122: }
7123: }
7124: }
7125: }
7126: my %usermodification_hash = (
7127: usermodification => \%modifyhash,
7128: );
7129: my $putresult = &Apache::lonnet::put_dom('configuration',
7130: \%usermodification_hash,$dom);
7131: if ($putresult eq 'ok') {
7132: if (keys(%changes) > 0) {
7133: $resulttext = &mt('Changes made: ').'<ul>';
7134: foreach my $context (@contexts) {
7135: if (ref($changes{$context}) eq 'ARRAY') {
7136: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7137: if (ref($changes{$context}) eq 'ARRAY') {
7138: foreach my $role (@{$changes{$context}}) {
7139: my $rolename;
1.63 raeburn 7140: if ($context eq 'selfcreate') {
7141: $rolename = $role;
7142: if (ref($usertypes) eq 'HASH') {
7143: if ($usertypes->{$role} ne '') {
7144: $rolename = $usertypes->{$role};
7145: }
7146: }
1.33 raeburn 7147: } else {
1.63 raeburn 7148: if ($role eq 'cr') {
7149: $rolename = &mt('Custom');
7150: } else {
7151: $rolename = &Apache::lonnet::plaintext($role);
7152: }
1.33 raeburn 7153: }
7154: my @modifiable;
1.63 raeburn 7155: if ($context eq 'selfcreate') {
1.126 bisitz 7156: $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 7157: } else {
7158: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7159: }
1.33 raeburn 7160: foreach my $field (@fields) {
7161: if ($modifyhash{$context}{$role}{$field}) {
7162: push(@modifiable,$fieldtitles{$field});
7163: }
7164: }
7165: if (@modifiable > 0) {
7166: $resulttext .= join(', ',@modifiable);
7167: } else {
7168: $resulttext .= &mt('none');
7169: }
7170: $resulttext .= '</li>';
7171: }
7172: $resulttext .= '</ul></li>';
7173: }
7174: }
7175: }
7176: $resulttext .= '</ul>';
7177: } else {
7178: $resulttext = &mt('No changes made to user modification settings');
7179: }
7180: } else {
7181: $resulttext = '<span class="LC_error">'.
7182: &mt('An error occurred: [_1]',$putresult).'</span>';
7183: }
7184: return $resulttext;
7185: }
7186:
1.43 raeburn 7187: sub modify_defaults {
7188: my ($dom,$r) = @_;
7189: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7190: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7191: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7192: my @authtypes = ('internal','krb4','krb5','localauth');
7193: foreach my $item (@items) {
7194: $newvalues{$item} = $env{'form.'.$item};
7195: if ($item eq 'auth_def') {
7196: if ($newvalues{$item} ne '') {
7197: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7198: push(@errors,$item);
7199: }
7200: }
7201: } elsif ($item eq 'lang_def') {
7202: if ($newvalues{$item} ne '') {
7203: if ($newvalues{$item} =~ /^(\w+)/) {
7204: my $langcode = $1;
1.103 raeburn 7205: if ($langcode ne 'x_chef') {
7206: if (code2language($langcode) eq '') {
7207: push(@errors,$item);
7208: }
1.43 raeburn 7209: }
7210: } else {
7211: push(@errors,$item);
7212: }
7213: }
1.54 raeburn 7214: } elsif ($item eq 'timezone_def') {
7215: if ($newvalues{$item} ne '') {
1.62 raeburn 7216: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7217: push(@errors,$item);
7218: }
7219: }
1.68 raeburn 7220: } elsif ($item eq 'datelocale_def') {
7221: if ($newvalues{$item} ne '') {
7222: my @datelocale_ids = DateTime::Locale->ids();
7223: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7224: push(@errors,$item);
7225: }
7226: }
1.141 raeburn 7227: } elsif ($item eq 'portal_def') {
7228: if ($newvalues{$item} ne '') {
7229: 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])\/?$/) {
7230: push(@errors,$item);
7231: }
7232: }
1.43 raeburn 7233: }
7234: if (grep(/^\Q$item\E$/,@errors)) {
7235: $newvalues{$item} = $domdefaults{$item};
7236: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7237: $changes{$item} = 1;
7238: }
1.72 raeburn 7239: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7240: }
7241: my %defaults_hash = (
1.72 raeburn 7242: defaults => \%newvalues,
7243: );
1.43 raeburn 7244: my $title = &defaults_titles();
7245: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7246: $dom);
7247: if ($putresult eq 'ok') {
7248: if (keys(%changes) > 0) {
7249: $resulttext = &mt('Changes made:').'<ul>';
7250: my $version = $r->dir_config('lonVersion');
7251: 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";
7252: foreach my $item (sort(keys(%changes))) {
7253: my $value = $env{'form.'.$item};
7254: if ($value eq '') {
7255: $value = &mt('none');
7256: } elsif ($item eq 'auth_def') {
7257: my %authnames = &authtype_names();
7258: my %shortauth = (
7259: internal => 'int',
7260: krb4 => 'krb4',
7261: krb5 => 'krb5',
7262: localauth => 'loc',
7263: );
7264: $value = $authnames{$shortauth{$value}};
7265: }
7266: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7267: $mailmsgtext .= "$title->{$item} set to $value\n";
7268: }
7269: $resulttext .= '</ul>';
7270: $mailmsgtext .= "\n";
7271: my $cachetime = 24*60*60;
1.72 raeburn 7272: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7273: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7274: my $sysmail = $r->dir_config('lonSysEMail');
7275: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7276: }
1.43 raeburn 7277: } else {
1.54 raeburn 7278: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7279: }
7280: } else {
7281: $resulttext = '<span class="LC_error">'.
7282: &mt('An error occurred: [_1]',$putresult).'</span>';
7283: }
7284: if (@errors > 0) {
7285: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7286: foreach my $item (@errors) {
7287: $resulttext .= ' "'.$title->{$item}.'",';
7288: }
7289: $resulttext =~ s/,$//;
7290: }
7291: return $resulttext;
7292: }
7293:
1.46 raeburn 7294: sub modify_scantron {
1.48 raeburn 7295: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7296: my ($resulttext,%confhash,%changes,$errors);
7297: my $custom = 'custom.tab';
7298: my $default = 'default.tab';
7299: my $servadm = $r->dir_config('lonAdmEMail');
7300: my ($configuserok,$author_ok,$switchserver) =
7301: &config_check($dom,$confname,$servadm);
7302: if ($env{'form.scantronformat.filename'} ne '') {
7303: my $error;
7304: if ($configuserok eq 'ok') {
7305: if ($switchserver) {
1.130 raeburn 7306: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7307: } else {
7308: if ($author_ok eq 'ok') {
7309: my ($result,$scantronurl) =
7310: &publishlogo($r,'upload','scantronformat',$dom,
7311: $confname,'scantron','','',$custom);
7312: if ($result eq 'ok') {
7313: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7314: $changes{'scantronformat'} = 1;
1.46 raeburn 7315: } else {
7316: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7317: }
7318: } else {
7319: $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);
7320: }
7321: }
7322: } else {
7323: $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);
7324: }
7325: if ($error) {
7326: &Apache::lonnet::logthis($error);
7327: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7328: }
7329: }
1.48 raeburn 7330: if (ref($domconfig{'scantron'}) eq 'HASH') {
7331: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7332: if ($env{'form.scantronformat_del'}) {
7333: $confhash{'scantron'}{'scantronformat'} = '';
7334: $changes{'scantronformat'} = 1;
1.46 raeburn 7335: }
7336: }
7337: }
7338: if (keys(%confhash) > 0) {
7339: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7340: $dom);
7341: if ($putresult eq 'ok') {
7342: if (keys(%changes) > 0) {
1.48 raeburn 7343: if (ref($confhash{'scantron'}) eq 'HASH') {
7344: $resulttext = &mt('Changes made:').'<ul>';
7345: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7346: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7347: } else {
1.130 raeburn 7348: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7349: }
1.48 raeburn 7350: $resulttext .= '</ul>';
7351: } else {
1.130 raeburn 7352: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7353: }
7354: $resulttext .= '</ul>';
7355: &Apache::loncommon::devalidate_domconfig_cache($dom);
7356: } else {
1.130 raeburn 7357: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7358: }
7359: } else {
7360: $resulttext = '<span class="LC_error">'.
7361: &mt('An error occurred: [_1]',$putresult).'</span>';
7362: }
7363: } else {
1.130 raeburn 7364: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7365: }
7366: if ($errors) {
7367: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7368: $errors.'</ul>';
7369: }
7370: return $resulttext;
7371: }
7372:
1.48 raeburn 7373: sub modify_coursecategories {
7374: my ($dom,%domconfig) = @_;
1.57 raeburn 7375: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7376: $cathash);
1.48 raeburn 7377: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7378: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7379: $cathash = $domconfig{'coursecategories'}{'cats'};
7380: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7381: $changes{'togglecats'} = 1;
7382: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7383: }
7384: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7385: $changes{'categorize'} = 1;
7386: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7387: }
1.120 raeburn 7388: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7389: $changes{'togglecatscomm'} = 1;
7390: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7391: }
7392: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7393: $changes{'categorizecomm'} = 1;
7394: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7395: }
1.57 raeburn 7396: } else {
7397: $changes{'togglecats'} = 1;
7398: $changes{'categorize'} = 1;
1.124 raeburn 7399: $changes{'togglecatscomm'} = 1;
7400: $changes{'categorizecomm'} = 1;
1.87 raeburn 7401: $domconfig{'coursecategories'} = {
7402: togglecats => $env{'form.togglecats'},
7403: categorize => $env{'form.categorize'},
1.124 raeburn 7404: togglecatscomm => $env{'form.togglecatscomm'},
7405: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7406: };
1.57 raeburn 7407: }
7408: if (ref($cathash) eq 'HASH') {
7409: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7410: push (@deletecategory,'instcode::0');
7411: }
1.120 raeburn 7412: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7413: push(@deletecategory,'communities::0');
7414: }
1.48 raeburn 7415: }
1.57 raeburn 7416: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7417: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7418: if (@deletecategory > 0) {
7419: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7420: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7421: foreach my $item (@deletecategory) {
1.57 raeburn 7422: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7423: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7424: $deletions{$item} = 1;
1.57 raeburn 7425: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7426: }
7427: }
7428: }
1.57 raeburn 7429: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7430: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7431: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7432: $reorderings{$item} = 1;
1.57 raeburn 7433: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7434: }
7435: if ($env{'form.addcategory_name_'.$item} ne '') {
7436: my $newcat = $env{'form.addcategory_name_'.$item};
7437: my $newdepth = $depth+1;
7438: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7439: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7440: $adds{$newitem} = 1;
7441: }
7442: if ($env{'form.subcat_'.$item} ne '') {
7443: my $newcat = $env{'form.subcat_'.$item};
7444: my $newdepth = $depth+1;
7445: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7446: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7447: $adds{$newitem} = 1;
7448: }
7449: }
7450: }
7451: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7452: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7453: my $newitem = 'instcode::0';
1.57 raeburn 7454: if ($cathash->{$newitem} eq '') {
7455: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7456: $adds{$newitem} = 1;
7457: }
7458: } else {
7459: my $newitem = 'instcode::0';
1.57 raeburn 7460: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7461: $adds{$newitem} = 1;
7462: }
7463: }
1.120 raeburn 7464: if ($env{'form.communities'} eq '1') {
7465: if (ref($cathash) eq 'HASH') {
7466: my $newitem = 'communities::0';
7467: if ($cathash->{$newitem} eq '') {
7468: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7469: $adds{$newitem} = 1;
7470: }
7471: } else {
7472: my $newitem = 'communities::0';
7473: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7474: $adds{$newitem} = 1;
7475: }
7476: }
1.48 raeburn 7477: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7478: if (($env{'form.addcategory_name'} ne 'instcode') &&
7479: ($env{'form.addcategory_name'} ne 'communities')) {
7480: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7481: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7482: $adds{$newitem} = 1;
7483: }
1.48 raeburn 7484: }
1.57 raeburn 7485: my $putresult;
1.48 raeburn 7486: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7487: if (keys(%deletions) > 0) {
7488: foreach my $key (keys(%deletions)) {
7489: if ($predelallitems{$key} ne '') {
7490: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7491: }
7492: }
7493: }
7494: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7495: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7496: if (ref($chkcats[0]) eq 'ARRAY') {
7497: my $depth = 0;
7498: my $chg = 0;
7499: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7500: my $name = $chkcats[0][$i];
7501: my $item;
7502: if ($name eq '') {
7503: $chg ++;
7504: } else {
7505: $item = &escape($name).'::0';
7506: if ($chg) {
1.57 raeburn 7507: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7508: }
7509: $depth ++;
1.57 raeburn 7510: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7511: $depth --;
7512: }
7513: }
7514: }
1.57 raeburn 7515: }
7516: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7517: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7518: if ($putresult eq 'ok') {
1.57 raeburn 7519: my %title = (
1.120 raeburn 7520: togglecats => 'Show/Hide a course in catalog',
7521: categorize => 'Assign a category to a course',
7522: togglecatscomm => 'Show/Hide a community in catalog',
7523: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7524: );
7525: my %level = (
1.120 raeburn 7526: dom => 'set in Domain ("Modify Course/Community")',
7527: crs => 'set in Course ("Course Configuration")',
7528: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7529: );
1.48 raeburn 7530: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7531: if ($changes{'togglecats'}) {
7532: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7533: }
7534: if ($changes{'categorize'}) {
7535: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7536: }
1.120 raeburn 7537: if ($changes{'togglecatscomm'}) {
7538: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7539: }
7540: if ($changes{'categorizecomm'}) {
7541: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7542: }
1.57 raeburn 7543: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7544: my $cathash;
7545: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7546: $cathash = $domconfig{'coursecategories'}{'cats'};
7547: } else {
7548: $cathash = {};
7549: }
7550: my (@cats,@trails,%allitems);
7551: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7552: if (keys(%deletions) > 0) {
7553: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7554: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7555: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7556: }
7557: $resulttext .= '</ul></li>';
7558: }
7559: if (keys(%reorderings) > 0) {
7560: my %sort_by_trail;
7561: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7562: foreach my $key (keys(%reorderings)) {
7563: if ($allitems{$key} ne '') {
7564: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7565: }
1.48 raeburn 7566: }
1.57 raeburn 7567: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7568: $resulttext .= '<li>'.$trails[$trail].'</li>';
7569: }
7570: $resulttext .= '</ul></li>';
1.48 raeburn 7571: }
1.57 raeburn 7572: if (keys(%adds) > 0) {
7573: my %sort_by_trail;
7574: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7575: foreach my $key (keys(%adds)) {
7576: if ($allitems{$key} ne '') {
7577: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7578: }
7579: }
7580: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7581: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7582: }
1.57 raeburn 7583: $resulttext .= '</ul></li>';
1.48 raeburn 7584: }
7585: }
7586: $resulttext .= '</ul>';
7587: } else {
7588: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7589: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7590: }
7591: } else {
1.120 raeburn 7592: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7593: }
7594: return $resulttext;
7595: }
7596:
1.69 raeburn 7597: sub modify_serverstatuses {
7598: my ($dom,%domconfig) = @_;
7599: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7600: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7601: %currserverstatus = %{$domconfig{'serverstatuses'}};
7602: }
7603: my @pages = &serverstatus_pages();
7604: foreach my $type (@pages) {
7605: $newserverstatus{$type}{'namedusers'} = '';
7606: $newserverstatus{$type}{'machines'} = '';
7607: if (defined($env{'form.'.$type.'_namedusers'})) {
7608: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7609: my @okusers;
7610: foreach my $user (@users) {
7611: my ($uname,$udom) = split(/:/,$user);
7612: if (($udom =~ /^$match_domain$/) &&
7613: (&Apache::lonnet::domain($udom)) &&
7614: ($uname =~ /^$match_username$/)) {
7615: if (!grep(/^\Q$user\E/,@okusers)) {
7616: push(@okusers,$user);
7617: }
7618: }
7619: }
7620: if (@okusers > 0) {
7621: @okusers = sort(@okusers);
7622: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7623: }
7624: }
7625: if (defined($env{'form.'.$type.'_machines'})) {
7626: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7627: my @okmachines;
7628: foreach my $ip (@machines) {
7629: my @parts = split(/\./,$ip);
7630: next if (@parts < 4);
7631: my $badip = 0;
7632: for (my $i=0; $i<4; $i++) {
7633: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7634: $badip = 1;
7635: last;
7636: }
7637: }
7638: if (!$badip) {
7639: push(@okmachines,$ip);
7640: }
7641: }
7642: @okmachines = sort(@okmachines);
7643: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7644: }
7645: }
7646: my %serverstatushash = (
7647: serverstatuses => \%newserverstatus,
7648: );
7649: foreach my $type (@pages) {
1.83 raeburn 7650: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7651: my (@current,@new);
1.83 raeburn 7652: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7653: if ($currserverstatus{$type}{$setting} ne '') {
7654: @current = split(/,/,$currserverstatus{$type}{$setting});
7655: }
7656: }
7657: if ($newserverstatus{$type}{$setting} ne '') {
7658: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7659: }
7660: if (@current > 0) {
7661: if (@new > 0) {
7662: foreach my $item (@current) {
7663: if (!grep(/^\Q$item\E$/,@new)) {
7664: $changes{$type}{$setting} = 1;
1.82 raeburn 7665: last;
7666: }
7667: }
1.84 raeburn 7668: foreach my $item (@new) {
7669: if (!grep(/^\Q$item\E$/,@current)) {
7670: $changes{$type}{$setting} = 1;
7671: last;
1.82 raeburn 7672: }
7673: }
7674: } else {
1.83 raeburn 7675: $changes{$type}{$setting} = 1;
1.69 raeburn 7676: }
1.83 raeburn 7677: } elsif (@new > 0) {
7678: $changes{$type}{$setting} = 1;
1.69 raeburn 7679: }
7680: }
7681: }
7682: if (keys(%changes) > 0) {
1.81 raeburn 7683: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7684: my $putresult = &Apache::lonnet::put_dom('configuration',
7685: \%serverstatushash,$dom);
7686: if ($putresult eq 'ok') {
7687: $resulttext .= &mt('Changes made:').'<ul>';
7688: foreach my $type (@pages) {
1.84 raeburn 7689: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7690: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7691: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7692: if ($newserverstatus{$type}{'namedusers'} eq '') {
7693: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7694: } else {
7695: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7696: }
1.84 raeburn 7697: }
7698: if ($changes{$type}{'machines'}) {
1.69 raeburn 7699: if ($newserverstatus{$type}{'machines'} eq '') {
7700: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7701: } else {
7702: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7703: }
7704:
7705: }
7706: $resulttext .= '</ul></li>';
7707: }
7708: }
7709: $resulttext .= '</ul>';
7710: } else {
7711: $resulttext = '<span class="LC_error">'.
7712: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7713:
7714: }
7715: } else {
7716: $resulttext = &mt('No changes made to access to server status pages');
7717: }
7718: return $resulttext;
7719: }
7720:
1.118 jms 7721: sub modify_helpsettings {
1.122 jms 7722: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7723: my ($resulttext,$errors,%changes,%helphash);
7724: my %defaultchecked = ('submitbugs' => 'on');
7725: my @offon = ('off','on');
1.118 jms 7726: my @toggles = ('submitbugs');
7727: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7728: foreach my $item (@toggles) {
1.160.6.5 raeburn 7729: if ($defaultchecked{$item} eq 'on') {
7730: if ($domconfig{'helpsettings'}{$item} eq '') {
7731: if ($env{'form.'.$item} eq '0') {
7732: $changes{$item} = 1;
7733: }
7734: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7735: $changes{$item} = 1;
7736: }
7737: } elsif ($defaultchecked{$item} eq 'off') {
7738: if ($domconfig{'helpsettings'}{$item} eq '') {
7739: if ($env{'form.'.$item} eq '1') {
7740: $changes{$item} = 1;
7741: }
7742: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7743: $changes{$item} = 1;
7744: }
7745: }
7746: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7747: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7748: }
7749: }
1.118 jms 7750: }
1.123 jms 7751: my $putresult;
7752: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7753: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7754: if ($putresult eq 'ok') {
7755: $resulttext = &mt('Changes made:').'<ul>';
7756: foreach my $item (sort(keys(%changes))) {
7757: if ($item eq 'submitbugs') {
7758: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7759: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7760: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7761: }
7762: }
7763: $resulttext .= '</ul>';
7764: } else {
7765: $resulttext = &mt('No changes made to help settings');
7766: $errors .= '<li><span class="LC_error">'.
7767: &mt('An error occurred storing the settings: [_1]',
7768: $putresult).'</span></li>';
7769: }
1.118 jms 7770: }
7771: if ($errors) {
1.160.6.5 raeburn 7772: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7773: $errors.'</ul>';
7774: }
7775: return $resulttext;
7776: }
7777:
1.121 raeburn 7778: sub modify_coursedefaults {
7779: my ($dom,%domconfig) = @_;
7780: my ($resulttext,$errors,%changes,%defaultshash);
7781: my %defaultchecked = ('canuse_pdfforms' => 'off');
7782: my @offon = ('off','on');
7783: my @toggles = ('canuse_pdfforms');
7784:
7785: $defaultshash{'coursedefaults'} = {};
7786:
7787: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7788: if ($domconfig{'coursedefaults'} eq '') {
7789: $domconfig{'coursedefaults'} = {};
7790: }
7791: }
7792:
7793: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7794: foreach my $item (@toggles) {
7795: if ($defaultchecked{$item} eq 'on') {
7796: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7797: ($env{'form.'.$item} eq '0')) {
7798: $changes{$item} = 1;
7799: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7800: $changes{$item} = 1;
7801: }
7802: } elsif ($defaultchecked{$item} eq 'off') {
7803: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7804: ($env{'form.'.$item} eq '1')) {
7805: $changes{$item} = 1;
7806: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7807: $changes{$item} = 1;
7808: }
7809: }
7810: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7811: }
1.139 raeburn 7812: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7813: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7814: $newdefresponder =~ s/\D//g;
7815: if ($newdefresponder eq '' || $newdefresponder < 1) {
7816: $newdefresponder = 1;
7817: }
7818: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7819: if ($currdefresponder ne $newdefresponder) {
7820: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7821: $changes{'anonsurvey_threshold'} = 1;
7822: }
7823: }
1.121 raeburn 7824: }
7825: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7826: $dom);
7827: if ($putresult eq 'ok') {
7828: if (keys(%changes) > 0) {
7829: if ($changes{'canuse_pdfforms'}) {
7830: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7831: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7832: my $cachetime = 24*60*60;
7833: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7834: }
7835: $resulttext = &mt('Changes made:').'<ul>';
7836: foreach my $item (sort(keys(%changes))) {
7837: if ($item eq 'canuse_pdfforms') {
7838: if ($env{'form.'.$item} eq '1') {
7839: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7840: } else {
7841: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7842: }
1.139 raeburn 7843: } elsif ($item eq 'anonsurvey_threshold') {
7844: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7845: }
1.121 raeburn 7846: }
7847: $resulttext .= '</ul>';
7848: } else {
7849: $resulttext = &mt('No changes made to course defaults');
7850: }
7851: } else {
7852: $resulttext = '<span class="LC_error">'.
7853: &mt('An error occurred: [_1]',$putresult).'</span>';
7854: }
7855: return $resulttext;
7856: }
7857:
1.137 raeburn 7858: sub modify_usersessions {
7859: my ($dom,%domconfig) = @_;
1.145 raeburn 7860: my @hostingtypes = ('version','excludedomain','includedomain');
7861: my @offloadtypes = ('primary','default');
7862: my %types = (
7863: remote => \@hostingtypes,
7864: hosted => \@hostingtypes,
7865: spares => \@offloadtypes,
7866: );
7867: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7868: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7869: my (%by_ip,%by_location,@intdoms);
7870: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7871: my @locations = sort(keys(%by_location));
1.137 raeburn 7872: my (%defaultshash,%changes);
7873: foreach my $prefix (@prefixes) {
7874: $defaultshash{'usersessions'}{$prefix} = {};
7875: }
7876: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7877: my $resulttext;
1.138 raeburn 7878: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7879: foreach my $prefix (@prefixes) {
1.145 raeburn 7880: next if ($prefix eq 'spares');
7881: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7882: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7883: if ($type eq 'version') {
7884: my $value = $env{'form.'.$prefix.'_'.$type};
7885: my $okvalue;
7886: if ($value ne '') {
7887: if (grep(/^\Q$value\E$/,@lcversions)) {
7888: $okvalue = $value;
7889: }
7890: }
7891: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7892: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7893: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7894: if ($inuse == 0) {
7895: $changes{$prefix}{$type} = 1;
7896: } else {
7897: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7898: $changes{$prefix}{$type} = 1;
7899: }
7900: if ($okvalue ne '') {
7901: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7902: }
7903: }
7904: } else {
7905: if (($inuse == 1) && ($okvalue ne '')) {
7906: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7907: $changes{$prefix}{$type} = 1;
7908: }
7909: }
7910: } else {
7911: if (($inuse == 1) && ($okvalue ne '')) {
7912: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7913: $changes{$prefix}{$type} = 1;
7914: }
7915: }
7916: } else {
7917: if (($inuse == 1) && ($okvalue ne '')) {
7918: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7919: $changes{$prefix}{$type} = 1;
7920: }
7921: }
7922: } else {
7923: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7924: my @okvals;
7925: foreach my $val (@vals) {
1.138 raeburn 7926: if ($val =~ /:/) {
7927: my @items = split(/:/,$val);
7928: foreach my $item (@items) {
7929: if (ref($by_location{$item}) eq 'ARRAY') {
7930: push(@okvals,$item);
7931: }
7932: }
7933: } else {
7934: if (ref($by_location{$val}) eq 'ARRAY') {
7935: push(@okvals,$val);
7936: }
1.137 raeburn 7937: }
7938: }
7939: @okvals = sort(@okvals);
7940: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7941: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7942: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7943: if ($inuse == 0) {
7944: $changes{$prefix}{$type} = 1;
7945: } else {
7946: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7947: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7948: if (@changed > 0) {
7949: $changes{$prefix}{$type} = 1;
7950: }
7951: }
7952: } else {
7953: if ($inuse == 1) {
7954: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7955: $changes{$prefix}{$type} = 1;
7956: }
7957: }
7958: } else {
7959: if ($inuse == 1) {
7960: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7961: $changes{$prefix}{$type} = 1;
7962: }
7963: }
7964: } else {
7965: if ($inuse == 1) {
7966: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7967: $changes{$prefix}{$type} = 1;
7968: }
7969: }
7970: }
7971: }
7972: }
1.145 raeburn 7973:
7974: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7975: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7976: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7977: my $savespares;
7978:
7979: foreach my $lonhost (sort(keys(%servers))) {
7980: my $serverhomeID =
7981: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 7982: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7983: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7984: my %spareschg;
7985: foreach my $type (@{$types{'spares'}}) {
7986: my @okspares;
7987: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7988: foreach my $server (@checked) {
1.152 raeburn 7989: if (&Apache::lonnet::hostname($server) ne '') {
7990: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7991: unless (grep(/^\Q$server\E$/,@okspares)) {
7992: push(@okspares,$server);
7993: }
1.145 raeburn 7994: }
7995: }
7996: }
7997: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7998: my $newspare;
1.152 raeburn 7999: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8000: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8001: $newspare = $new;
8002: }
8003: }
1.152 raeburn 8004: my @spares;
8005: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8006: @spares = sort(@okspares,$newspare);
8007: } else {
8008: @spares = sort(@okspares);
8009: }
8010: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8011: if (ref($spareid{$lonhost}) eq 'HASH') {
8012: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8013: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8014: if (@diffs > 0) {
8015: $spareschg{$type} = 1;
8016: }
8017: }
8018: }
8019: }
8020: if (keys(%spareschg) > 0) {
8021: $changes{'spares'}{$lonhost} = \%spareschg;
8022: }
8023: }
8024:
8025: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8026: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8027: if (ref($changes{'spares'}) eq 'HASH') {
8028: if (keys(%{$changes{'spares'}}) > 0) {
8029: $savespares = 1;
8030: }
8031: }
8032: } else {
8033: $savespares = 1;
8034: }
8035: }
8036:
1.147 raeburn 8037: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8038: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8039: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8040: $dom);
8041: if ($putresult eq 'ok') {
8042: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8043: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8044: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8045: }
8046: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8047: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8048: }
8049: }
8050: my $cachetime = 24*60*60;
8051: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8052: if (keys(%changes) > 0) {
8053: my %lt = &usersession_titles();
8054: $resulttext = &mt('Changes made:').'<ul>';
8055: foreach my $prefix (@prefixes) {
8056: if (ref($changes{$prefix}) eq 'HASH') {
8057: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8058: if ($prefix eq 'spares') {
8059: if (ref($changes{$prefix}) eq 'HASH') {
8060: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8061: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8062: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8063: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8064: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8065: foreach my $type (@{$types{$prefix}}) {
8066: if ($changes{$prefix}{$lonhost}{$type}) {
8067: my $offloadto = &mt('None');
8068: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8069: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8070: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8071: }
1.145 raeburn 8072: }
1.147 raeburn 8073: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8074: }
1.137 raeburn 8075: }
8076: }
1.147 raeburn 8077: $resulttext .= '</li>';
1.137 raeburn 8078: }
8079: }
1.147 raeburn 8080: } else {
8081: foreach my $type (@{$types{$prefix}}) {
8082: if (defined($changes{$prefix}{$type})) {
8083: my $newvalue;
8084: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8085: if (ref($defaultshash{'usersessions'}{$prefix})) {
8086: if ($type eq 'version') {
8087: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8088: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8089: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8090: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8091: }
1.145 raeburn 8092: }
8093: }
8094: }
1.147 raeburn 8095: if ($newvalue eq '') {
8096: if ($type eq 'version') {
8097: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8098: } else {
8099: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8100: }
1.145 raeburn 8101: } else {
1.147 raeburn 8102: if ($type eq 'version') {
8103: $newvalue .= ' '.&mt('(or later)');
8104: }
8105: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8106: }
1.137 raeburn 8107: }
8108: }
8109: }
1.147 raeburn 8110: $resulttext .= '</ul>';
1.137 raeburn 8111: }
8112: }
1.147 raeburn 8113: $resulttext .= '</ul>';
8114: } else {
8115: $resulttext = $nochgmsg;
1.137 raeburn 8116: }
8117: } else {
8118: $resulttext = '<span class="LC_error">'.
8119: &mt('An error occurred: [_1]',$putresult).'</span>';
8120: }
8121: } else {
1.147 raeburn 8122: $resulttext = $nochgmsg;
1.137 raeburn 8123: }
8124: return $resulttext;
8125: }
8126:
1.150 raeburn 8127: sub modify_loadbalancing {
8128: my ($dom,%domconfig) = @_;
8129: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8130: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8131: my ($othertitle,$usertypes,$types) =
8132: &Apache::loncommon::sorted_inst_types($dom);
8133: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8134: my @sparestypes = ('primary','default');
8135: my %typetitles = &sparestype_titles();
8136: my $resulttext;
1.160.6.7! raeburn 8137: my (%currbalancer,%currtargets,%currrules,%existing);
! 8138: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
! 8139: %existing = %{$domconfig{'loadbalancing'}};
! 8140: }
! 8141: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
! 8142: \%currtargets,\%currrules);
! 8143: my ($saveloadbalancing,%defaultshash,%changes);
! 8144: my ($alltypes,$othertypes,$titles) =
! 8145: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
! 8146: my %ruletitles = &offloadtype_text();
! 8147: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
! 8148: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
! 8149: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
! 8150: if ($balancer eq '') {
! 8151: next;
! 8152: }
! 8153: if (!exists($servers{$balancer})) {
! 8154: if (exists($currbalancer{$balancer})) {
! 8155: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8156: }
1.160.6.7! raeburn 8157: next;
! 8158: }
! 8159: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
! 8160: push(@{$changes{'delete'}},$balancer);
! 8161: next;
! 8162: }
! 8163: if (!exists($currbalancer{$balancer})) {
! 8164: push(@{$changes{'add'}},$balancer);
! 8165: }
! 8166: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
! 8167: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
! 8168: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
! 8169: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
! 8170: $saveloadbalancing = 1;
! 8171: }
! 8172: foreach my $sparetype (@sparestypes) {
! 8173: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
! 8174: my @offloadto;
! 8175: foreach my $target (@targets) {
! 8176: if (($servers{$target}) && ($target ne $balancer)) {
! 8177: if ($sparetype eq 'default') {
! 8178: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
! 8179: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8180: }
8181: }
1.160.6.7! raeburn 8182: unless(grep(/^\Q$target\E$/,@offloadto)) {
! 8183: push(@offloadto,$target);
! 8184: }
1.150 raeburn 8185: }
1.160.6.7! raeburn 8186: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8187: }
8188: }
1.160.6.7! raeburn 8189: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8190: foreach my $sparetype (@sparestypes) {
1.160.6.7! raeburn 8191: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
! 8192: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8193: if (@targetdiffs > 0) {
1.160.6.7! raeburn 8194: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8195: }
1.160.6.7! raeburn 8196: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
! 8197: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
! 8198: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8199: }
8200: }
8201: }
8202: } else {
1.160.6.7! raeburn 8203: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
! 8204: foreach my $sparetype (@sparestypes) {
! 8205: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
! 8206: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
! 8207: $changes{'curr'}{$balancer}{'targets'} = 1;
! 8208: }
1.150 raeburn 8209: }
8210: }
1.160.6.7! raeburn 8211: }
1.150 raeburn 8212: }
8213: my $ishomedom;
1.160.6.7! raeburn 8214: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
! 8215: $ishomedom = 1;
1.150 raeburn 8216: }
8217: if (ref($alltypes) eq 'ARRAY') {
8218: foreach my $type (@{$alltypes}) {
8219: my $rule;
1.160.6.7! raeburn 8220: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8221: (!$ishomedom)) {
1.160.6.7! raeburn 8222: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
! 8223: }
! 8224: if ($rule eq 'specific') {
! 8225: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8226: }
1.160.6.7! raeburn 8227: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
! 8228: if (ref($currrules{$balancer}) eq 'HASH') {
! 8229: if ($rule ne $currrules{$balancer}{$type}) {
! 8230: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8231: }
8232: } elsif ($rule ne '') {
1.160.6.7! raeburn 8233: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8234: }
8235: }
8236: }
1.160.6.7! raeburn 8237: }
! 8238: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
! 8239: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
! 8240: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
! 8241: $defaultshash{'loadbalancing'} = {};
! 8242: }
! 8243: my $putresult = &Apache::lonnet::put_dom('configuration',
! 8244: \%defaultshash,$dom);
! 8245:
! 8246: if ($putresult eq 'ok') {
! 8247: if (keys(%changes) > 0) {
! 8248: if (ref($changes{'delete'}) eq 'ARRAY') {
! 8249: foreach my $balancer (sort(@{$changes{'delete'}})) {
! 8250: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8251: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8252: }
1.160.6.7! raeburn 8253: }
! 8254: if (ref($changes{'add'}) eq 'ARRAY') {
! 8255: foreach my $balancer (sort(@{$changes{'add'}})) {
! 8256: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
! 8257: }
! 8258: }
! 8259: if (ref($changes{'curr'}) eq 'HASH') {
! 8260: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
! 8261: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
! 8262: if ($changes{'curr'}{$balancer}{'targets'}) {
! 8263: my %offloadstr;
! 8264: foreach my $sparetype (@sparestypes) {
! 8265: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
! 8266: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
! 8267: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
! 8268: }
! 8269: }
1.150 raeburn 8270: }
1.160.6.7! raeburn 8271: if (keys(%offloadstr) == 0) {
! 8272: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8273: } else {
1.160.6.7! raeburn 8274: my $showoffload;
! 8275: foreach my $sparetype (@sparestypes) {
! 8276: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
! 8277: if (defined($offloadstr{$sparetype})) {
! 8278: $showoffload .= $offloadstr{$sparetype};
! 8279: } else {
! 8280: $showoffload .= &mt('None');
! 8281: }
! 8282: $showoffload .= (' 'x3);
! 8283: }
! 8284: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8285: }
8286: }
8287: }
1.160.6.7! raeburn 8288: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
! 8289: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
! 8290: foreach my $type (@{$alltypes}) {
! 8291: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
! 8292: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
! 8293: my $balancetext;
! 8294: if ($rule eq '') {
! 8295: $balancetext = $ruletitles{'default'};
! 8296: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
! 8297: $balancetext = $ruletitles{$rule};
! 8298: } else {
! 8299: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
! 8300: }
! 8301: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8302: }
8303: }
8304: }
8305: }
1.160.6.7! raeburn 8306: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8307: }
1.160.6.7! raeburn 8308: }
! 8309: if ($resulttext ne '') {
! 8310: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8311: } else {
8312: $resulttext = $nochgmsg;
8313: }
8314: } else {
1.160.6.7! raeburn 8315: $resulttext = $nochgmsg;
1.150 raeburn 8316: }
8317: } else {
1.160.6.7! raeburn 8318: $resulttext = '<span class="LC_error">'.
! 8319: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8320: }
8321: } else {
1.160.6.7! raeburn 8322: $resulttext = $nochgmsg;
1.150 raeburn 8323: }
8324: return $resulttext;
8325: }
8326:
1.48 raeburn 8327: sub recurse_check {
8328: my ($chkcats,$categories,$depth,$name) = @_;
8329: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8330: my $chg = 0;
8331: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8332: my $category = $chkcats->[$depth]{$name}[$j];
8333: my $item;
8334: if ($category eq '') {
8335: $chg ++;
8336: } else {
8337: my $deeper = $depth + 1;
8338: $item = &escape($category).':'.&escape($name).':'.$depth;
8339: if ($chg) {
8340: $categories->{$item} -= $chg;
8341: }
8342: &recurse_check($chkcats,$categories,$deeper,$category);
8343: $deeper --;
8344: }
8345: }
8346: }
8347: return;
8348: }
8349:
8350: sub recurse_cat_deletes {
8351: my ($item,$coursecategories,$deletions) = @_;
8352: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8353: my $subdepth = $depth + 1;
8354: if (ref($coursecategories) eq 'HASH') {
8355: foreach my $subitem (keys(%{$coursecategories})) {
8356: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8357: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8358: delete($coursecategories->{$subitem});
8359: $deletions->{$subitem} = 1;
8360: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8361: }
8362: }
8363: }
8364: return;
8365: }
8366:
1.125 raeburn 8367: sub get_active_dcs {
8368: my ($dom) = @_;
8369: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8370: my %domcoords;
8371: my $numdcs = 0;
8372: my $now = time;
8373: foreach my $server (keys(%dompersonnel)) {
8374: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8375: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8376: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8377: if (($end eq '') || ($end == 0) || ($end > $now)) {
8378: if ($start <= $now) {
8379: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8380: }
8381: }
8382: }
8383: }
8384: return %domcoords;
8385: }
8386:
8387: sub active_dc_picker {
8388: my ($dom,$curr_dc) = @_;
8389: my %domcoords = &get_active_dcs($dom);
8390: my @dcs = sort(keys(%domcoords));
8391: my $numdcs = scalar(@dcs);
8392: my $datatable;
8393: my $numinrow = 2;
8394: if ($numdcs > 1) {
8395: $datatable = '<table>';
8396: for (my $i=0; $i<@dcs; $i++) {
8397: my $rem = $i%($numinrow);
8398: if ($rem == 0) {
8399: if ($i > 0) {
8400: $datatable .= '</tr>';
8401: }
8402: $datatable .= '<tr>';
8403: }
8404: my $check = ' ';
8405: if ($curr_dc eq '') {
8406: if (!$i) {
8407: $check = ' checked="checked" ';
8408: }
8409: } elsif ($dcs[$i] eq $curr_dc) {
8410: $check = ' checked="checked" ';
8411: }
8412: if ($i == @dcs - 1) {
8413: my $colsleft = $numinrow - $rem;
8414: if ($colsleft > 1) {
8415: $datatable .= '<td colspan="'.$colsleft.'">';
8416: } else {
8417: $datatable .= '<td>';
8418: }
8419: } else {
8420: $datatable .= '<td>';
8421: }
8422: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8423: $datatable .= '<span class="LC_nobreak"><label>'.
8424: '<input type="radio" name="autocreate_xmldc"'.
8425: ' value="'.$dcs[$i].'"'.$check.'/>'.
8426: &Apache::loncommon::plainname($dcname,$dcdom).
8427: '</label></span></td>';
8428: }
8429: $datatable .= '</tr></table>';
8430: } elsif (@dcs) {
8431: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8432: $dcs[0].'" />';
8433: }
8434: return ($numdcs,$datatable);
8435: }
8436:
1.137 raeburn 8437: sub usersession_titles {
8438: return &Apache::lonlocal::texthash(
8439: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8440: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8441: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8442: version => 'LON-CAPA version requirement',
1.138 raeburn 8443: excludedomain => 'Allow all, but exclude specific domains',
8444: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8445: primary => 'Primary (checked first)',
1.154 raeburn 8446: default => 'Default',
1.137 raeburn 8447: );
8448: }
8449:
1.152 raeburn 8450: sub id_for_thisdom {
8451: my (%servers) = @_;
8452: my %altids;
8453: foreach my $server (keys(%servers)) {
8454: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8455: if ($serverhome ne $server) {
8456: $altids{$serverhome} = $server;
8457: }
8458: }
8459: return %altids;
8460: }
8461:
1.150 raeburn 8462: sub count_servers {
8463: my ($currbalancer,%servers) = @_;
8464: my (@spares,$numspares);
8465: foreach my $lonhost (sort(keys(%servers))) {
8466: next if ($currbalancer eq $lonhost);
8467: push(@spares,$lonhost);
8468: }
8469: if ($currbalancer) {
8470: $numspares = scalar(@spares);
8471: } else {
8472: $numspares = scalar(@spares) - 1;
8473: }
8474: return ($numspares,@spares);
8475: }
8476:
8477: sub lonbalance_targets_js {
1.160.6.7! raeburn 8478: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8479: my $select = &mt('Select');
8480: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8481: if (ref($servers) eq 'HASH') {
8482: $alltargets = join("','",sort(keys(%{$servers})));
8483: my @homedoms;
8484: foreach my $server (sort(keys(%{$servers}))) {
8485: if (&Apache::lonnet::host_domain($server) eq $dom) {
8486: push(@homedoms,'1');
8487: } else {
8488: push(@homedoms,'0');
8489: }
8490: }
8491: $allishome = join("','",@homedoms);
8492: }
8493: if (ref($types) eq 'ARRAY') {
8494: if (@{$types} > 0) {
8495: @alltypes = @{$types};
8496: }
8497: }
8498: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8499: $allinsttypes = join("','",@alltypes);
1.160.6.7! raeburn 8500: my (%currbalancer,%currtargets,%currrules,%existing);
! 8501: if (ref($settings) eq 'HASH') {
! 8502: %existing = %{$settings};
! 8503: }
! 8504: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
! 8505: \%currtargets,\%currrules);
! 8506: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8507: return <<"END";
8508:
8509: <script type="text/javascript">
8510: // <![CDATA[
8511:
1.160.6.7! raeburn 8512: currBalancers = new Array('$balancers');
! 8513:
! 8514: function toggleTargets(balnum) {
! 8515: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
! 8516: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
! 8517: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
! 8518: var prevbalancer = prevhostitem.value;
! 8519: var baltotal = document.getElementById('loadbalancing_total').value;
! 8520: prevhostitem.value = balancer;
! 8521: if (prevbalancer != '') {
! 8522: var prevIdx = currBalancers.indexOf(prevbalancer);
! 8523: if (prevIdx != -1) {
! 8524: currBalancers.splice(prevIdx,1);
! 8525: }
! 8526: }
1.150 raeburn 8527: if (balancer == '') {
1.160.6.7! raeburn 8528: hideSpares(balnum);
1.150 raeburn 8529: } else {
1.160.6.7! raeburn 8530: var currIdx = currBalancers.indexOf(balancer);
! 8531: if (currIdx == -1) {
! 8532: currBalancers.push(balancer);
! 8533: }
1.150 raeburn 8534: var homedoms = new Array('$allishome');
1.160.6.7! raeburn 8535: var ishomedom = homedoms[lonhostitem.selectedIndex];
! 8536: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8537: }
1.160.6.7! raeburn 8538: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8539: return;
8540: }
8541:
1.160.6.7! raeburn 8542: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8543: var alltargets = new Array('$alltargets');
8544: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8545: var offloadtypes = new Array('primary','default');
8546:
1.160.6.7! raeburn 8547: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
! 8548: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8549:
1.151 raeburn 8550: for (var i=0; i<offloadtypes.length; i++) {
8551: var count = 0;
8552: for (var j=0; j<alltargets.length; j++) {
8553: if (alltargets[j] != balancer) {
1.160.6.7! raeburn 8554: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
! 8555: item.value = alltargets[j];
! 8556: item.style.textAlign='left';
! 8557: item.style.textFace='normal';
! 8558: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
! 8559: if (currBalancers.indexOf(alltargets[j]) == -1) {
! 8560: item.disabled = '';
! 8561: } else {
! 8562: item.disabled = 'disabled';
! 8563: item.checked = false;
! 8564: }
1.151 raeburn 8565: count ++;
8566: }
1.150 raeburn 8567: }
8568: }
1.151 raeburn 8569: for (var k=0; k<insttypes.length; k++) {
8570: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8571: if (ishomedom == 1) {
1.160.6.7! raeburn 8572: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
! 8573: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8574: } else {
1.160.6.7! raeburn 8575: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
! 8576: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8577:
8578: }
8579: } else {
1.160.6.7! raeburn 8580: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
! 8581: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8582: }
1.151 raeburn 8583: if ((insttypes[k] != '_LC_external') &&
8584: ((insttypes[k] != '_LC_internetdom') ||
8585: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7! raeburn 8586: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
! 8587: item.options.length = 0;
! 8588: item.options[0] = new Option("","",true,true);
! 8589: var idx = 0;
1.151 raeburn 8590: for (var m=0; m<alltargets.length; m++) {
1.160.6.7! raeburn 8591: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
! 8592: idx ++;
! 8593: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
! 8594:
1.150 raeburn 8595: }
8596: }
8597: }
8598: }
8599: return;
8600: }
8601:
1.160.6.7! raeburn 8602: function hideSpares(balnum) {
1.150 raeburn 8603: var alltargets = new Array('$alltargets');
8604: var insttypes = new Array('$allinsttypes');
8605: var offloadtypes = new Array('primary','default');
8606:
1.160.6.7! raeburn 8607: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
! 8608: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8609:
8610: var total = alltargets.length - 1;
8611: for (var i=0; i<offloadtypes; i++) {
8612: for (var j=0; j<total; j++) {
1.160.6.7! raeburn 8613: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
! 8614: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
! 8615: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8616: }
1.150 raeburn 8617: }
8618: for (var k=0; k<insttypes.length; k++) {
1.160.6.7! raeburn 8619: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
! 8620: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8621: if (insttypes[k] != '_LC_external') {
1.160.6.7! raeburn 8622: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
! 8623: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8624: }
8625: }
8626: return;
8627: }
8628:
1.160.6.7! raeburn 8629: function checkOffloads(item,balnum,type) {
1.150 raeburn 8630: var alltargets = new Array('$alltargets');
8631: var offloadtypes = new Array('primary','default');
8632: if (item.checked) {
8633: var total = alltargets.length - 1;
8634: var other;
8635: if (type == offloadtypes[0]) {
1.151 raeburn 8636: other = offloadtypes[1];
1.150 raeburn 8637: } else {
1.151 raeburn 8638: other = offloadtypes[0];
1.150 raeburn 8639: }
8640: for (var i=0; i<total; i++) {
1.160.6.7! raeburn 8641: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8642: if (server == item.value) {
1.160.6.7! raeburn 8643: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
! 8644: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8645: }
8646: }
8647: }
8648: }
8649: return;
8650: }
8651:
1.160.6.7! raeburn 8652: function singleServerToggle(balnum,type) {
! 8653: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8654: if (offloadtoSelIdx == 0) {
1.160.6.7! raeburn 8655: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
! 8656: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8657:
8658: } else {
1.160.6.7! raeburn 8659: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
! 8660: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8661: }
8662: return;
8663: }
8664:
1.160.6.7! raeburn 8665: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8666: if (type == '_LC_external') {
8667: return;
8668: }
1.160.6.7! raeburn 8669: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8670: for (var i=0; i<typesRules.length; i++) {
8671: if (formname.elements[typesRules[i]].checked) {
8672: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7! raeburn 8673: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
! 8674: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8675: } else {
1.160.6.7! raeburn 8676: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
! 8677: }
! 8678: }
! 8679: }
! 8680: return;
! 8681: }
! 8682:
! 8683: function balancerDeleteChange(balnum) {
! 8684: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
! 8685: var baltotal = document.getElementById('loadbalancing_total').value;
! 8686: var addtarget;
! 8687: var removetarget;
! 8688: var action = 'delete';
! 8689: if (document.getElementById('loadbalancing_delete_'+balnum)) {
! 8690: var lonhost = hostitem.value;
! 8691: var currIdx = currBalancers.indexOf(lonhost);
! 8692: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
! 8693: if (currIdx != -1) {
! 8694: currBalancers.splice(currIdx,1);
! 8695: }
! 8696: addtarget = lonhost;
! 8697: } else {
! 8698: if (currIdx == -1) {
! 8699: currBalancers.push(lonhost);
! 8700: }
! 8701: removetarget = lonhost;
! 8702: action = 'undelete';
! 8703: }
! 8704: balancerChange(balnum,baltotal,action,addtarget,removetarget);
! 8705: }
! 8706: return;
! 8707: }
! 8708:
! 8709: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
! 8710: if (baltotal > 1) {
! 8711: var offloadtypes = new Array('primary','default');
! 8712: var alltargets = new Array('$alltargets');
! 8713: var insttypes = new Array('$allinsttypes');
! 8714: for (var i=0; i<baltotal; i++) {
! 8715: if (i != balnum) {
! 8716: for (var j=0; j<offloadtypes.length; j++) {
! 8717: var total = alltargets.length - 1;
! 8718: for (var k=0; k<total; k++) {
! 8719: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
! 8720: var server = serveritem.value;
! 8721: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
! 8722: if (server == addtarget) {
! 8723: serveritem.disabled = '';
! 8724: }
! 8725: }
! 8726: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
! 8727: if (server == removetarget) {
! 8728: serveritem.disabled = 'disabled';
! 8729: serveritem.checked = false;
! 8730: }
! 8731: }
! 8732: }
! 8733: }
! 8734: for (var j=0; j<insttypes.length; j++) {
! 8735: if (insttypes[j] != '_LC_external') {
! 8736: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
! 8737: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
! 8738: var currSel = singleserver.selectedIndex;
! 8739: var currVal = singleserver.options[currSel].value;
! 8740: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
! 8741: var numoptions = singleserver.options.length;
! 8742: var needsnew = 1;
! 8743: for (var k=0; k<numoptions; k++) {
! 8744: if (singleserver.options[k] == addtarget) {
! 8745: needsnew = 0;
! 8746: break;
! 8747: }
! 8748: }
! 8749: if (needsnew == 1) {
! 8750: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
! 8751: }
! 8752: }
! 8753: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
! 8754: singleserver.options.length = 0;
! 8755: if ((currVal) && (currVal != removetarget)) {
! 8756: singleserver.options[0] = new Option("","",false,false);
! 8757: } else {
! 8758: singleserver.options[0] = new Option("","",true,true);
! 8759: }
! 8760: var idx = 0;
! 8761: for (var m=0; m<alltargets.length; m++) {
! 8762: if (currBalancers.indexOf(alltargets[m]) == -1) {
! 8763: idx ++;
! 8764: if (currVal == alltargets[m]) {
! 8765: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
! 8766: } else {
! 8767: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
! 8768: }
! 8769: }
! 8770: }
! 8771: }
! 8772: }
! 8773: }
! 8774: }
1.150 raeburn 8775: }
8776: }
8777: }
8778: return;
8779: }
8780:
1.152 raeburn 8781: // ]]>
8782: </script>
8783:
8784: END
8785: }
8786:
8787: sub new_spares_js {
8788: my @sparestypes = ('primary','default');
8789: my $types = join("','",@sparestypes);
8790: my $select = &mt('Select');
8791: return <<"END";
8792:
8793: <script type="text/javascript">
8794: // <![CDATA[
8795:
8796: function updateNewSpares(formname,lonhost) {
8797: var types = new Array('$types');
8798: var include = new Array();
8799: var exclude = new Array();
8800: for (var i=0; i<types.length; i++) {
8801: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8802: for (var j=0; j<spareboxes.length; j++) {
8803: if (formname.elements[spareboxes[j]].checked) {
8804: exclude.push(formname.elements[spareboxes[j]].value);
8805: } else {
8806: include.push(formname.elements[spareboxes[j]].value);
8807: }
8808: }
8809: }
8810: for (var i=0; i<types.length; i++) {
8811: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8812: var selIdx = newSpare.selectedIndex;
8813: var currnew = newSpare.options[selIdx].value;
8814: var okSpares = new Array();
8815: for (var j=0; j<newSpare.options.length; j++) {
8816: var possible = newSpare.options[j].value;
8817: if (possible != '') {
8818: if (exclude.indexOf(possible) == -1) {
8819: okSpares.push(possible);
8820: } else {
8821: if (currnew == possible) {
8822: selIdx = 0;
8823: }
8824: }
8825: }
8826: }
8827: for (var k=0; k<include.length; k++) {
8828: if (okSpares.indexOf(include[k]) == -1) {
8829: okSpares.push(include[k]);
8830: }
8831: }
8832: okSpares.sort();
8833: newSpare.options.length = 0;
8834: if (selIdx == 0) {
8835: newSpare.options[0] = new Option("$select","",true,true);
8836: } else {
8837: newSpare.options[0] = new Option("$select","",false,false);
8838: }
8839: for (var m=0; m<okSpares.length; m++) {
8840: var idx = m+1;
8841: var selThis = 0;
8842: if (selIdx != 0) {
8843: if (okSpares[m] == currnew) {
8844: selThis = 1;
8845: }
8846: }
8847: if (selThis == 1) {
8848: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8849: } else {
8850: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8851: }
8852: }
8853: }
8854: return;
8855: }
8856:
8857: function checkNewSpares(lonhost,type) {
8858: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8859: var chosen = newSpare.options[newSpare.selectedIndex].value;
8860: if (chosen != '') {
8861: var othertype;
8862: var othernewSpare;
8863: if (type == 'primary') {
8864: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8865: }
8866: if (type == 'default') {
8867: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8868: }
8869: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8870: othernewSpare.selectedIndex = 0;
8871: }
8872: }
8873: return;
8874: }
8875:
8876: // ]]>
8877: </script>
8878:
8879: END
8880:
8881: }
8882:
8883: sub common_domprefs_js {
8884: return <<"END";
8885:
8886: <script type="text/javascript">
8887: // <![CDATA[
8888:
1.150 raeburn 8889: function getIndicesByName(formname,item) {
1.152 raeburn 8890: var group = new Array();
1.150 raeburn 8891: for (var i=0;i<formname.elements.length;i++) {
8892: if (formname.elements[i].name == item) {
1.152 raeburn 8893: group.push(formname.elements[i].id);
1.150 raeburn 8894: }
8895: }
1.152 raeburn 8896: return group;
1.150 raeburn 8897: }
8898:
8899: // ]]>
8900: </script>
8901:
8902: END
1.152 raeburn 8903:
1.150 raeburn 8904: }
8905:
1.160.6.5 raeburn 8906: sub recaptcha_js {
8907: my %lt = &captcha_phrases();
8908: return <<"END";
8909:
8910: <script type="text/javascript">
8911: // <![CDATA[
8912:
8913: function updateCaptcha(caller,context) {
8914: var privitem;
8915: var pubitem;
8916: var privtext;
8917: var pubtext;
8918: if (document.getElementById(context+'_recaptchapub')) {
8919: pubitem = document.getElementById(context+'_recaptchapub');
8920: } else {
8921: return;
8922: }
8923: if (document.getElementById(context+'_recaptchapriv')) {
8924: privitem = document.getElementById(context+'_recaptchapriv');
8925: } else {
8926: return;
8927: }
8928: if (document.getElementById(context+'_recaptchapubtxt')) {
8929: pubtext = document.getElementById(context+'_recaptchapubtxt');
8930: } else {
8931: return;
8932: }
8933: if (document.getElementById(context+'_recaptchaprivtxt')) {
8934: privtext = document.getElementById(context+'_recaptchaprivtxt');
8935: } else {
8936: return;
8937: }
8938: if (caller.checked) {
8939: if (caller.value == 'recaptcha') {
8940: pubitem.type = 'text';
8941: privitem.type = 'text';
8942: pubitem.size = '40';
8943: privitem.size = '40';
8944: pubtext.innerHTML = "$lt{'pub'}";
8945: privtext.innerHTML = "$lt{'priv'}";
8946: } else {
8947: pubitem.type = 'hidden';
8948: privitem.type = 'hidden';
8949: pubtext.innerHTML = '';
8950: privtext.innerHTML = '';
8951: }
8952: }
8953: return;
8954: }
8955:
8956: // ]]>
8957: </script>
8958:
8959: END
8960:
8961: }
8962:
8963: sub captcha_phrases {
8964: return &Apache::lonlocal::texthash (
8965: priv => 'Private key',
8966: pub => 'Public key',
8967: original => 'original (CAPTCHA)',
8968: recaptcha => 'successor (ReCAPTCHA)',
8969: notused => 'unused',
8970: );
8971: }
8972:
1.3 raeburn 8973: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>