Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.2
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.2! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.1 2012/05/02 18:27:46 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
89: number of rows displayed on the page, and $action is the context (either quotas
90: or requestcourses).
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',
214: 'loadbalancing'],$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.1 raeburn 218: 'requestcourses','coursecategories','serverstatuses',
219: 'usersessions');
1.150 raeburn 220: if (keys(%servers) > 1) {
221: push(@prefs_order,'loadbalancing');
222: }
1.30 raeburn 223: my %prefs = (
224: 'rolecolors' =>
225: { text => 'Default color schemes',
1.67 raeburn 226: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 227: header => [{col1 => 'Student Settings',
228: col2 => '',},
229: {col1 => 'Coordinator Settings',
230: col2 => '',},
231: {col1 => 'Author Settings',
232: col2 => '',},
233: {col1 => 'Administrator Settings',
234: col2 => '',}],
235: },
1.110 raeburn 236: 'login' =>
1.30 raeburn 237: { text => 'Log-in page options',
1.67 raeburn 238: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 239: header => [{col1 => 'Item',
240: col2 => '',}],
241: },
1.110 raeburn 242:
1.43 raeburn 243: 'defaults' =>
1.141 raeburn 244: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 245: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 246: header => [{col1 => 'Setting',
247: col2 => 'Value'}],
248: },
1.30 raeburn 249: 'quotas' =>
1.133 raeburn 250: { text => 'User blogs, personal information pages, portfolios',
1.67 raeburn 251: help => 'Domain_Configuration_Quotas',
1.77 raeburn 252: header => [{col1 => 'User affiliation',
1.72 raeburn 253: col2 => 'Available tools',
254: col3 => 'Portfolio quota',}],
1.30 raeburn 255: },
256: 'autoenroll' =>
257: { text => 'Auto-enrollment settings',
1.67 raeburn 258: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 259: header => [{col1 => 'Configuration setting',
260: col2 => 'Value(s)'}],
261: },
262: 'autoupdate' =>
263: { text => 'Auto-update settings',
1.67 raeburn 264: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 265: header => [{col1 => 'Setting',
266: col2 => 'Value',},
1.131 raeburn 267: {col1 => 'Setting',
268: col2 => 'Affiliation'},
1.43 raeburn 269: {col1 => 'User population',
1.131 raeburn 270: col2 => 'Updateable user data'}],
1.30 raeburn 271: },
1.125 raeburn 272: 'autocreate' =>
273: { text => 'Auto-course creation settings',
274: help => 'Domain_Configuration_Auto_Creation',
275: header => [{col1 => 'Configuration Setting',
276: col2 => 'Value',}],
277: },
1.30 raeburn 278: 'directorysrch' =>
279: { text => 'Institutional directory searches',
1.67 raeburn 280: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 281: header => [{col1 => 'Setting',
282: col2 => 'Value',}],
283: },
284: 'contacts' =>
285: { text => 'Contact Information',
1.67 raeburn 286: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 287: header => [{col1 => 'Setting',
288: col2 => 'Value',}],
289: },
290:
291: 'usercreation' =>
292: { text => 'User creation',
1.67 raeburn 293: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 294: header => [{col1 => 'Format rule type',
295: col2 => 'Format rules in force'},
1.34 raeburn 296: {col1 => 'User account creation',
297: col2 => 'Usernames which may be created',},
1.30 raeburn 298: {col1 => 'Context',
1.43 raeburn 299: col2 => 'Assignable authentication types'}],
1.30 raeburn 300: },
1.69 raeburn 301: 'usermodification' =>
1.33 raeburn 302: { text => 'User modification',
1.67 raeburn 303: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 304: header => [{col1 => 'Target user has role',
305: col2 => 'User information updateable in author context'},
306: {col1 => 'Target user has role',
1.63 raeburn 307: col2 => 'User information updateable in course context'},
308: {col1 => "Status of user",
309: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 310: },
1.69 raeburn 311: 'scantron' =>
1.95 www 312: { text => 'Bubblesheet format file',
1.67 raeburn 313: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 314: header => [ {col1 => 'Item',
315: col2 => '',
316: }],
317: },
1.86 raeburn 318: 'requestcourses' =>
319: {text => 'Request creation of courses',
320: help => 'Domain_Configuration_Request_Courses',
321: header => [{col1 => 'User affiliation',
1.102 raeburn 322: col2 => 'Availability/Processing of requests',},
323: {col1 => 'Setting',
324: col2 => 'Value'}],
1.86 raeburn 325: },
1.69 raeburn 326: 'coursecategories' =>
1.120 raeburn 327: { text => 'Cataloging of courses/communities',
1.67 raeburn 328: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 329: header => [{col1 => 'Category settings',
1.57 raeburn 330: col2 => '',},
331: {col1 => 'Categories',
332: col2 => '',
333: }],
1.69 raeburn 334: },
335: 'serverstatuses' =>
1.77 raeburn 336: {text => 'Access to server status pages',
1.69 raeburn 337: help => 'Domain_Configuration_Server_Status',
338: header => [{col1 => 'Status Page',
339: col2 => 'Other named users',
340: col3 => 'Specific IPs',
341: }],
342: },
1.141 raeburn 343: 'usersessions' =>
1.145 raeburn 344: {text => 'User session hosting/offloading',
1.137 raeburn 345: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 346: header => [{col1 => 'Domain server',
347: col2 => 'Servers to offload sessions to when busy'},
348: {col1 => 'Hosting of users from other domains',
1.137 raeburn 349: col2 => 'Rules'},
350: {col1 => "Hosting domain's own users elsewhere",
351: col2 => 'Rules'}],
352: },
1.150 raeburn 353: 'loadbalancing' =>
354: {text => 'Dedicated Load Balancer',
355: help => 'Domain_Configuration_Load_Balancing',
356: header => [{col1 => 'Server',
357: col2 => 'Default destinations',
358: col3 => 'User affliation',
359: col4 => 'Overrides'},
360: ],
361: },
1.3 raeburn 362: );
1.110 raeburn 363: if (keys(%servers) > 1) {
364: $prefs{'login'} = { text => 'Log-in page options',
365: help => 'Domain_Configuration_Login_Page',
366: header => [{col1 => 'Log-in Service',
367: col2 => 'Server Setting',},
368: {col1 => 'Log-in Page Items',
369: col2 => ''}],
370: };
371: }
1.6 raeburn 372: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 373: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 374: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 375: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 376: text=>"Settings to display/modify"});
1.9 raeburn 377: my $confname = $dom.'-domainconfig';
1.3 raeburn 378: if ($phase eq 'process') {
1.91 raeburn 379: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 380: } elsif ($phase eq 'display') {
1.152 raeburn 381: my $js;
382: if (keys(%servers) > 1) {
383: my ($othertitle,$usertypes,$types) =
384: &Apache::loncommon::sorted_inst_types($dom);
385: $js = &lonbalance_targets_js($dom,$types,\%servers).
386: &new_spares_js().
1.153 raeburn 387: &common_domprefs_js().
388: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 389: }
1.150 raeburn 390: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 391: } else {
1.21 raeburn 392: if (keys(%domconfig) == 0) {
393: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 394: my @ids=&Apache::lonnet::current_machine_ids();
395: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 396: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 397: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 398: my $custom_img_count = 0;
399: foreach my $img (@loginimages) {
400: if ($designhash{$dom.'.login.'.$img} ne '') {
401: $custom_img_count ++;
402: }
403: }
404: foreach my $role (@roles) {
405: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
406: $custom_img_count ++;
407: }
408: }
409: if ($custom_img_count > 0) {
1.94 raeburn 410: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 411: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 412: $r->print(
413: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
414: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
415: &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 />'.
416: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
417: if ($switch_server) {
1.30 raeburn 418: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 419: }
1.91 raeburn 420: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 421: return OK;
422: }
423: }
424: }
1.91 raeburn 425: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 426: }
427: return OK;
428: }
429:
430: sub process_changes {
1.92 raeburn 431: my ($r,$dom,$confname,$action,$roles,$values) = @_;
432: my %domconfig;
433: if (ref($values) eq 'HASH') {
434: %domconfig = %{$values};
435: }
1.3 raeburn 436: my $output;
437: if ($action eq 'login') {
1.9 raeburn 438: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 439: } elsif ($action eq 'rolecolors') {
1.9 raeburn 440: $output = &modify_rolecolors($r,$dom,$confname,$roles,
441: %domconfig);
1.3 raeburn 442: } elsif ($action eq 'quotas') {
1.86 raeburn 443: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 444: } elsif ($action eq 'autoenroll') {
445: $output = &modify_autoenroll($dom,%domconfig);
446: } elsif ($action eq 'autoupdate') {
447: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 448: } elsif ($action eq 'autocreate') {
449: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 450: } elsif ($action eq 'directorysrch') {
451: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 452: } elsif ($action eq 'usercreation') {
1.28 raeburn 453: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 454: } elsif ($action eq 'usermodification') {
455: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 456: } elsif ($action eq 'contacts') {
457: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 458: } elsif ($action eq 'defaults') {
459: $output = &modify_defaults($dom,$r);
1.46 raeburn 460: } elsif ($action eq 'scantron') {
1.48 raeburn 461: $output = &modify_scantron($r,$dom,$confname,%domconfig);
462: } elsif ($action eq 'coursecategories') {
463: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 464: } elsif ($action eq 'serverstatuses') {
465: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 466: } elsif ($action eq 'requestcourses') {
467: $output = &modify_quotas($dom,$action,%domconfig);
1.137 raeburn 468: } elsif ($action eq 'usersessions') {
469: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 470: } elsif ($action eq 'loadbalancing') {
471: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 472: }
473: return $output;
474: }
475:
476: sub print_config_box {
1.9 raeburn 477: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 478: my $rowtotal = 0;
1.49 raeburn 479: my $output;
480: if ($action eq 'coursecategories') {
481: $output = &coursecategories_javascript($settings);
1.91 raeburn 482: }
1.49 raeburn 483: $output .=
1.30 raeburn 484: '<table class="LC_nested_outer">
1.3 raeburn 485: <tr>
1.66 raeburn 486: <th align="left" valign="middle"><span class="LC_nobreak">'.
487: &mt($item->{text}).' '.
488: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
489: '</tr>';
1.30 raeburn 490: $rowtotal ++;
1.110 raeburn 491: my $numheaders = 1;
492: if (ref($item->{'header'}) eq 'ARRAY') {
493: $numheaders = scalar(@{$item->{'header'}});
494: }
495: if ($numheaders > 1) {
1.64 raeburn 496: my $colspan = '';
1.145 raeburn 497: my $rightcolspan = '';
1.122 jms 498: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64 raeburn 499: $colspan = ' colspan="2"';
500: }
1.145 raeburn 501: if ($action eq 'usersessions') {
502: $rightcolspan = ' colspan="3"';
503: }
1.30 raeburn 504: $output .= '
1.3 raeburn 505: <tr>
506: <td>
507: <table class="LC_nested">
508: <tr class="LC_info_row">
1.59 bisitz 509: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 510: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 511: </tr>';
1.69 raeburn 512: $rowtotal ++;
1.6 raeburn 513: if ($action eq 'autoupdate') {
1.30 raeburn 514: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 515: } elsif ($action eq 'usercreation') {
1.33 raeburn 516: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
517: } elsif ($action eq 'usermodification') {
518: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 519: } elsif ($action eq 'coursecategories') {
520: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 521: } elsif ($action eq 'login') {
522: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
523: $colspan = ' colspan="2"';
1.102 raeburn 524: } elsif ($action eq 'requestcourses') {
525: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 526: } elsif ($action eq 'usersessions') {
527: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 528: } elsif ($action eq 'rolecolors') {
1.30 raeburn 529: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2! raeburn 530: }
1.30 raeburn 531: $output .= '
1.6 raeburn 532: </table>
533: </td>
534: </tr>
535: <tr>
536: <td>
537: <table class="LC_nested">
538: <tr class="LC_info_row">
1.59 bisitz 539: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 540: $output .= '
1.59 bisitz 541: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 542: </tr>';
543: $rowtotal ++;
1.6 raeburn 544: if ($action eq 'autoupdate') {
1.131 raeburn 545: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
546: </table>
547: </td>
548: </tr>
549: <tr>
550: <td>
551: <table class="LC_nested">
552: <tr class="LC_info_row">
553: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
554: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
555: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
556: $rowtotal ++;
1.28 raeburn 557: } elsif ($action eq 'usercreation') {
1.34 raeburn 558: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
559: </table>
560: </td>
561: </tr>
562: <tr>
563: <td>
564: <table class="LC_nested">
565: <tr class="LC_info_row">
1.59 bisitz 566: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
567: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 568: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
569: $rowtotal ++;
1.33 raeburn 570: } elsif ($action eq 'usermodification') {
1.63 raeburn 571: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
572: </table>
573: </td>
574: </tr>
575: <tr>
576: <td>
577: <table class="LC_nested">
578: <tr class="LC_info_row">
579: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
580: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
581: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
582: $rowtotal ++;
1.57 raeburn 583: } elsif ($action eq 'coursecategories') {
584: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 585: } elsif ($action eq 'login') {
586: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 587: } elsif ($action eq 'requestcourses') {
588: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122 jms 589: } elsif ($action eq 'helpsettings') {
590: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 591: } elsif ($action eq 'usersessions') {
1.145 raeburn 592: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
593: </table>
594: </td>
595: </tr>
596: <tr>
597: <td>
598: <table class="LC_nested">
599: <tr class="LC_info_row">
600: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
601: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
602: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
603: $rowtotal ++;
1.139 raeburn 604: } elsif ($action eq 'coursedefaults') {
605: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 606: } elsif ($action eq 'rolecolors') {
1.30 raeburn 607: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 608: </table>
609: </td>
610: </tr>
611: <tr>
612: <td>
613: <table class="LC_nested">
614: <tr class="LC_info_row">
1.69 raeburn 615: <td class="LC_left_item"'.$colspan.' valign="top">'.
616: &mt($item->{'header'}->[2]->{'col1'}).'</td>
617: <td class="LC_right_item" valign="top">'.
618: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 619: </tr>'.
1.30 raeburn 620: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 621: </table>
622: </td>
623: </tr>
624: <tr>
625: <td>
626: <table class="LC_nested">
627: <tr class="LC_info_row">
1.59 bisitz 628: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
629: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 630: </tr>'.
1.30 raeburn 631: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
632: $rowtotal += 2;
1.6 raeburn 633: }
1.3 raeburn 634: } else {
1.30 raeburn 635: $output .= '
1.3 raeburn 636: <tr>
637: <td>
638: <table class="LC_nested">
1.30 raeburn 639: <tr class="LC_info_row">';
1.24 raeburn 640: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 641: $output .= '
1.59 bisitz 642: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 643: } elsif ($action eq 'serverstatuses') {
644: $output .= '
645: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
646: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
647:
1.6 raeburn 648: } else {
1.30 raeburn 649: $output .= '
1.69 raeburn 650: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
651: }
1.72 raeburn 652: if (defined($item->{'header'}->[0]->{'col3'})) {
653: $output .= '<td class="LC_left_item" valign="top">'.
654: &mt($item->{'header'}->[0]->{'col2'});
655: if ($action eq 'serverstatuses') {
656: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
657: }
1.69 raeburn 658: } else {
659: $output .= '<td class="LC_right_item" valign="top">'.
660: &mt($item->{'header'}->[0]->{'col2'});
661: }
662: $output .= '</td>';
663: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 664: if (defined($item->{'header'}->[0]->{'col4'})) {
665: $output .= '<td class="LC_left_item" valign="top">'.
666: &mt($item->{'header'}->[0]->{'col3'});
667: } else {
668: $output .= '<td class="LC_right_item" valign="top">'.
669: &mt($item->{'header'}->[0]->{'col3'});
670: }
1.69 raeburn 671: if ($action eq 'serverstatuses') {
672: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
673: }
674: $output .= '</td>';
1.6 raeburn 675: }
1.150 raeburn 676: if ($item->{'header'}->[0]->{'col4'}) {
677: $output .= '<td class="LC_right_item" valign="top">'.
678: &mt($item->{'header'}->[0]->{'col4'});
679: }
1.69 raeburn 680: $output .= '</tr>';
1.48 raeburn 681: $rowtotal ++;
1.3 raeburn 682: if ($action eq 'login') {
1.110 raeburn 683: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
684: \$rowtotal);
1.3 raeburn 685: } elsif ($action eq 'quotas') {
1.86 raeburn 686: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 687: } elsif ($action eq 'autoenroll') {
1.30 raeburn 688: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 689: } elsif ($action eq 'autocreate') {
690: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 691: } elsif ($action eq 'directorysrch') {
1.30 raeburn 692: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 693: } elsif ($action eq 'contacts') {
1.30 raeburn 694: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 695: } elsif ($action eq 'defaults') {
696: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 697: } elsif ($action eq 'scantron') {
698: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 699: } elsif ($action eq 'serverstatuses') {
700: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 701: } elsif ($action eq 'helpsettings') {
1.122 jms 702: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150 raeburn 703: } elsif ($action eq 'loadbalancing') {
704: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 705: }
1.3 raeburn 706: }
1.30 raeburn 707: $output .= '
1.3 raeburn 708: </table>
709: </td>
710: </tr>
1.30 raeburn 711: </table><br />';
712: return ($output,$rowtotal);
1.1 raeburn 713: }
714:
1.3 raeburn 715: sub print_login {
1.110 raeburn 716: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
717: my ($css_class,$datatable);
1.6 raeburn 718: my %choices = &login_choices();
1.110 raeburn 719:
720: if ($position eq 'top') {
1.149 raeburn 721: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 722: my $choice = $choices{'disallowlogin'};
723: $css_class = ' class="LC_odd_row"';
1.128 raeburn 724: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 725: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 726: '<th>'.$choices{'server'}.'</th>'.
727: '<th>'.$choices{'serverpath'}.'</th>'.
728: '<th>'.$choices{'custompath'}.'</th>'.
729: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 730: my %disallowed;
731: if (ref($settings) eq 'HASH') {
732: if (ref($settings->{'loginvia'}) eq 'HASH') {
733: %disallowed = %{$settings->{'loginvia'}};
734: }
735: }
736: foreach my $lonhost (sort(keys(%servers))) {
737: my $direct = 'selected="selected"';
1.128 raeburn 738: if (ref($disallowed{$lonhost}) eq 'HASH') {
739: if ($disallowed{$lonhost}{'server'} ne '') {
740: $direct = '';
741: }
1.110 raeburn 742: }
1.115 raeburn 743: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 744: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 745: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
746: '</option>';
747: foreach my $hostid (keys(%servers)) {
1.115 raeburn 748: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 749: my $selected = '';
1.128 raeburn 750: if (ref($disallowed{$lonhost}) eq 'HASH') {
751: if ($hostid eq $disallowed{$lonhost}{'server'}) {
752: $selected = 'selected="selected"';
753: }
1.110 raeburn 754: }
755: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
756: $servers{$hostid}.'</option>';
757: }
1.128 raeburn 758: $datatable .= '</select></td>'.
759: '<td><select name="'.$lonhost.'_serverpath">';
760: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
761: my $pathname = $path;
762: if ($path eq 'custom') {
763: $pathname = &mt('Custom Path').' ->';
764: }
765: my $selected = '';
766: if (ref($disallowed{$lonhost}) eq 'HASH') {
767: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
768: $selected = 'selected="selected"';
769: }
770: } elsif ($path eq '') {
771: $selected = 'selected="selected"';
772: }
773: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
774: }
775: $datatable .= '</select></td>';
776: my ($custom,$exempt);
777: if (ref($disallowed{$lonhost}) eq 'HASH') {
778: $custom = $disallowed{$lonhost}{'custompath'};
779: $exempt = $disallowed{$lonhost}{'exempt'};
780: }
781: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
782: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
783: '</tr>';
1.110 raeburn 784: }
785: $datatable .= '</table></td></tr>';
786: return $datatable;
787: }
788:
1.42 raeburn 789: my %defaultchecked = (
1.43 raeburn 790: 'coursecatalog' => 'on',
791: 'adminmail' => 'off',
792: 'newuser' => 'off',
793: );
1.118 jms 794: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 795: my (%checkedon,%checkedoff);
796: foreach my $item (@toggles) {
797: if ($defaultchecked{$item} eq 'on') {
798: $checkedon{$item} = ' checked="checked" ';
799: $checkedoff{$item} = ' ';
800: } elsif ($defaultchecked{$item} eq 'off') {
801: $checkedoff{$item} = ' checked="checked" ';
802: $checkedon{$item} = ' ';
803: }
804: }
1.41 raeburn 805: my @images = ('img','logo','domlogo','login');
806: my @logintext = ('textcol','bgcol');
1.6 raeburn 807: my @bgs = ('pgbg','mainbg','sidebg');
808: my @links = ('link','alink','vlink');
1.7 albertel 809: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 810: my %defaultdesign = %Apache::loncommon::defaultdesign;
811: my (%is_custom,%designs);
812: my %defaults = (
813: font => $defaultdesign{'login.font'},
814: );
815: foreach my $item (@images) {
816: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 817: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 818: }
819: foreach my $item (@bgs) {
820: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
821: }
1.41 raeburn 822: foreach my $item (@logintext) {
823: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
824: }
1.6 raeburn 825: foreach my $item (@links) {
826: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
827: }
1.3 raeburn 828: if (ref($settings) eq 'HASH') {
1.42 raeburn 829: foreach my $item (@toggles) {
830: if ($settings->{$item} eq '1') {
831: $checkedon{$item} = ' checked="checked" ';
832: $checkedoff{$item} = ' ';
833: } elsif ($settings->{$item} eq '0') {
834: $checkedoff{$item} = ' checked="checked" ';
835: $checkedon{$item} = ' ';
836: }
1.1 raeburn 837: }
1.6 raeburn 838: foreach my $item (@images) {
1.70 raeburn 839: if (defined($settings->{$item})) {
1.6 raeburn 840: $designs{$item} = $settings->{$item};
841: $is_custom{$item} = 1;
842: }
1.70 raeburn 843: if (defined($settings->{'showlogo'}{$item})) {
844: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
845: }
1.6 raeburn 846: }
1.41 raeburn 847: foreach my $item (@logintext) {
848: if ($settings->{$item} ne '') {
849: $designs{'logintext'}{$item} = $settings->{$item};
850: $is_custom{$item} = 1;
851: }
852: }
1.6 raeburn 853: if ($settings->{'font'} ne '') {
854: $designs{'font'} = $settings->{'font'};
855: $is_custom{'font'} = 1;
856: }
857: foreach my $item (@bgs) {
858: if ($settings->{$item} ne '') {
859: $designs{'bgs'}{$item} = $settings->{$item};
860: $is_custom{$item} = 1;
861: }
862: }
863: foreach my $item (@links) {
864: if ($settings->{$item} ne '') {
865: $designs{'links'}{$item} = $settings->{$item};
866: $is_custom{$item} = 1;
867: }
868: }
869: } else {
870: if ($designhash{$dom.'.login.font'} ne '') {
871: $designs{'font'} = $designhash{$dom.'.login.font'};
872: $is_custom{'font'} = 1;
873: }
1.8 raeburn 874: foreach my $item (@images) {
875: if ($designhash{$dom.'.login.'.$item} ne '') {
876: $designs{$item} = $designhash{$dom.'.login.'.$item};
877: $is_custom{$item} = 1;
878: }
879: }
1.6 raeburn 880: foreach my $item (@bgs) {
881: if ($designhash{$dom.'.login.'.$item} ne '') {
882: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
883: $is_custom{$item} = 1;
884: }
885: }
886: foreach my $item (@links) {
887: if ($designhash{$dom.'.login.'.$item} ne '') {
888: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
889: $is_custom{$item} = 1;
890: }
891: }
1.1 raeburn 892: }
1.6 raeburn 893: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
894: logo => 'Institution Logo',
1.41 raeburn 895: domlogo => 'Domain Logo',
896: login => 'Login box');
1.6 raeburn 897: my $itemcount = 1;
1.42 raeburn 898: foreach my $item (@toggles) {
899: $css_class = $itemcount%2?' class="LC_odd_row"':'';
900: $datatable .=
901: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
902: '</td><td>'.
903: '<span class="LC_nobreak"><label><input type="radio" name="'.
904: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
905: '</label> <label><input type="radio" name="'.$item.'"'.
906: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
907: '</tr>';
908: $itemcount ++;
909: }
1.135 bisitz 910: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 911: $datatable .= '</tr></table></td></tr>';
912: return $datatable;
913: }
914:
915: sub login_choices {
916: my %choices =
917: &Apache::lonlocal::texthash (
1.116 bisitz 918: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 919: adminmail => "Display Administrator's E-mail Address?",
920: disallowlogin => "Login page requests redirected",
921: hostid => "Server",
1.128 raeburn 922: server => "Redirect to:",
923: serverpath => "Path",
924: custompath => "Custom",
925: exempt => "Exempt IP(s)",
1.110 raeburn 926: directlogin => "No redirect",
927: newuser => "Link to create a user account",
928: img => "Header",
929: logo => "Main Logo",
930: domlogo => "Domain Logo",
931: login => "Log-in Header",
932: textcol => "Text color",
933: bgcol => "Box color",
934: bgs => "Background colors",
935: links => "Link colors",
936: font => "Font color",
937: pgbg => "Header",
938: mainbg => "Page",
939: sidebg => "Login box",
940: link => "Link",
941: alink => "Active link",
942: vlink => "Visited link",
1.6 raeburn 943: );
944: return %choices;
945: }
946:
947: sub print_rolecolors {
1.30 raeburn 948: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 949: my %choices = &color_font_choices();
950: my @bgs = ('pgbg','tabbg','sidebg');
951: my @links = ('link','alink','vlink');
952: my @images = ('img');
953: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 954: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 955: my %defaultdesign = %Apache::loncommon::defaultdesign;
956: my (%is_custom,%designs);
957: my %defaults = (
958: img => $defaultdesign{$role.'.img'},
959: font => $defaultdesign{$role.'.font'},
1.97 tempelho 960: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 961: );
962: foreach my $item (@bgs) {
963: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
964: }
965: foreach my $item (@links) {
966: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
967: }
968: if (ref($settings) eq 'HASH') {
969: if (ref($settings->{$role}) eq 'HASH') {
970: if ($settings->{$role}->{'img'} ne '') {
971: $designs{'img'} = $settings->{$role}->{'img'};
972: $is_custom{'img'} = 1;
973: }
974: if ($settings->{$role}->{'font'} ne '') {
975: $designs{'font'} = $settings->{$role}->{'font'};
976: $is_custom{'font'} = 1;
977: }
1.97 tempelho 978: if ($settings->{$role}->{'fontmenu'} ne '') {
979: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
980: $is_custom{'fontmenu'} = 1;
981: }
1.6 raeburn 982: foreach my $item (@bgs) {
983: if ($settings->{$role}->{$item} ne '') {
984: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
985: $is_custom{$item} = 1;
986: }
987: }
988: foreach my $item (@links) {
989: if ($settings->{$role}->{$item} ne '') {
990: $designs{'links'}{$item} = $settings->{$role}->{$item};
991: $is_custom{$item} = 1;
992: }
993: }
994: }
995: } else {
996: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
997: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
998: $is_custom{'img'} = 1;
999: }
1.97 tempelho 1000: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1001: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1002: $is_custom{'fontmenu'} = 1;
1003: }
1.6 raeburn 1004: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1005: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1006: $is_custom{'font'} = 1;
1007: }
1008: foreach my $item (@bgs) {
1009: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1010: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1011: $is_custom{$item} = 1;
1012:
1013: }
1014: }
1015: foreach my $item (@links) {
1016: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1017: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1018: $is_custom{$item} = 1;
1019: }
1020: }
1021: }
1022: my $itemcount = 1;
1.30 raeburn 1023: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1024: $datatable .= '</tr></table></td></tr>';
1025: return $datatable;
1026: }
1027:
1028: sub display_color_options {
1.9 raeburn 1029: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1030: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1031: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1032: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1033: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1034: '<td>'.$choices->{'font'}.'</td>';
1035: if (!$is_custom->{'font'}) {
1.30 raeburn 1036: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1037: } else {
1038: $datatable .= '<td> </td>';
1039: }
1040: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1041: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1042: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1043: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1044: ' <span id="css_'.$role.'_font" style="background-color: '.
1045: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1046: '</span></td></tr>';
1.107 raeburn 1047: unless ($role eq 'login') {
1048: $datatable .= '<tr'.$css_class.'>'.
1049: '<td>'.$choices->{'fontmenu'}.'</td>';
1050: if (!$is_custom->{'fontmenu'}) {
1051: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1052: } else {
1053: $datatable .= '<td> </td>';
1054: }
1055: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1056: $datatable .= '<td><span class="LC_nobreak">'.
1057: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1058: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1059: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1060: $designs->{'fontmenu'}.';"> </span>'.
1061: '</span></td></tr>';
1.97 tempelho 1062: }
1.9 raeburn 1063: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1064: foreach my $img (@{$images}) {
1.18 albertel 1065: $itemcount ++;
1.6 raeburn 1066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1067: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1068: '<td>'.$choices->{$img};
1.41 raeburn 1069: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1070: if ($role eq 'login') {
1071: if ($img eq 'login') {
1072: $login_hdr_pick =
1.135 bisitz 1073: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1074: $logincolors =
1075: &login_text_colors($img,$role,$logintext,$phase,$choices,
1076: $designs);
1077: } elsif ($img ne 'domlogo') {
1078: $datatable.= &logo_display_options($img,$defaults,$designs);
1079: }
1080: }
1081: $datatable .= '</td>';
1.6 raeburn 1082: if ($designs->{$img} ne '') {
1083: $imgfile = $designs->{$img};
1.18 albertel 1084: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1085: } else {
1086: $imgfile = $defaults->{$img};
1087: }
1088: if ($imgfile) {
1.9 raeburn 1089: my ($showfile,$fullsize);
1090: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1091: my $urldir = $1;
1092: my $filename = $2;
1093: my @info = &Apache::lonnet::stat_file($designs->{$img});
1094: if (@info) {
1095: my $thumbfile = 'tn-'.$filename;
1096: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1097: if (@thumb) {
1098: $showfile = $urldir.'/'.$thumbfile;
1099: } else {
1100: $showfile = $imgfile;
1101: }
1102: } else {
1103: $showfile = '';
1104: }
1105: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1106: $showfile = $imgfile;
1.6 raeburn 1107: my $imgdir = $1;
1108: my $filename = $2;
1.159 raeburn 1109: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1110: $showfile = "/$imgdir/tn-".$filename;
1111: } else {
1.159 raeburn 1112: my $input = $londocroot.$imgfile;
1113: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1114: if (!-e $output) {
1.9 raeburn 1115: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1116: my ($fullwidth,$fullheight) = &check_dimensions($input);
1117: if ($fullwidth ne '' && $fullheight ne '') {
1118: if ($fullwidth > $width && $fullheight > $height) {
1119: my $size = $width.'x'.$height;
1120: system("convert -sample $size $input $output");
1.159 raeburn 1121: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1122: }
1123: }
1.6 raeburn 1124: }
1125: }
1.16 raeburn 1126: }
1.6 raeburn 1127: if ($showfile) {
1.40 raeburn 1128: if ($showfile =~ m{^/(adm|res)/}) {
1129: if ($showfile =~ m{^/res/}) {
1130: my $local_showfile =
1131: &Apache::lonnet::filelocation('',$showfile);
1132: &Apache::lonnet::repcopy($local_showfile);
1133: }
1134: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1135: }
1136: if ($imgfile) {
1137: if ($imgfile =~ m{^/(adm|res)/}) {
1138: if ($imgfile =~ m{^/res/}) {
1139: my $local_imgfile =
1140: &Apache::lonnet::filelocation('',$imgfile);
1141: &Apache::lonnet::repcopy($local_imgfile);
1142: }
1143: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1144: } else {
1145: $fullsize = $imgfile;
1146: }
1147: }
1.41 raeburn 1148: $datatable .= '<td>';
1149: if ($img eq 'login') {
1.135 bisitz 1150: $datatable .= $login_hdr_pick;
1151: }
1.41 raeburn 1152: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1153: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1154: } else {
1155: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1156: &mt('Upload:');
1157: }
1158: } else {
1159: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1160: &mt('Upload:');
1161: }
1.9 raeburn 1162: if ($switchserver) {
1163: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1164: } else {
1.135 bisitz 1165: if ($img ne 'login') { # suppress file selection for Log-in header
1166: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1167: }
1.9 raeburn 1168: }
1169: $datatable .= '</td></tr>';
1.6 raeburn 1170: }
1171: $itemcount ++;
1172: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1173: $datatable .= '<tr'.$css_class.'>'.
1174: '<td>'.$choices->{'bgs'}.'</td>';
1175: my $bgs_def;
1176: foreach my $item (@{$bgs}) {
1177: if (!$is_custom->{$item}) {
1.70 raeburn 1178: $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 1179: }
1180: }
1181: if ($bgs_def) {
1.8 raeburn 1182: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1183: } else {
1184: $datatable .= '<td> </td>';
1185: }
1186: $datatable .= '<td class="LC_right_item">'.
1187: '<table border="0"><tr>';
1188: foreach my $item (@{$bgs}) {
1189: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1190: $datatable .= '<td align="center">'.$link;
1191: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1192: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1193: }
1194: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1195: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1196: }
1197: $datatable .= '</tr></table></td></tr>';
1198: $itemcount ++;
1199: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1200: $datatable .= '<tr'.$css_class.'>'.
1201: '<td>'.$choices->{'links'}.'</td>';
1202: my $links_def;
1203: foreach my $item (@{$links}) {
1204: if (!$is_custom->{$item}) {
1.30 raeburn 1205: $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 1206: }
1207: }
1208: if ($links_def) {
1.8 raeburn 1209: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1210: } else {
1211: $datatable .= '<td> </td>';
1212: }
1213: $datatable .= '<td class="LC_right_item">'.
1214: '<table border="0"><tr>';
1215: foreach my $item (@{$links}) {
1.30 raeburn 1216: $datatable .= '<td align="center">'."\n".
1217: &color_pick($phase,$role,$item,$choices->{$item},
1218: $designs->{'links'}{$item});
1.6 raeburn 1219: if ($designs->{'links'}{$item}) {
1.30 raeburn 1220: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1221: }
1222: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1223: '" /></td>';
1224: }
1.30 raeburn 1225: $$rowtotal += $itemcount;
1.3 raeburn 1226: return $datatable;
1227: }
1228:
1.70 raeburn 1229: sub logo_display_options {
1230: my ($img,$defaults,$designs) = @_;
1231: my $checkedon;
1232: if (ref($defaults) eq 'HASH') {
1233: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1234: if ($defaults->{'showlogo'}{$img}) {
1235: $checkedon = 'checked="checked" ';
1236: }
1237: }
1238: }
1239: if (ref($designs) eq 'HASH') {
1240: if (ref($designs->{'showlogo'}) eq 'HASH') {
1241: if (defined($designs->{'showlogo'}{$img})) {
1242: if ($designs->{'showlogo'}{$img} == 0) {
1243: $checkedon = '';
1244: } elsif ($designs->{'showlogo'}{$img} == 1) {
1245: $checkedon = 'checked="checked" ';
1246: }
1247: }
1248: }
1249: }
1250: return '<br /><label> <input type="checkbox" name="'.
1251: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1252: &mt('show').'</label>'."\n";
1253: }
1254:
1.41 raeburn 1255: sub login_header_options {
1.135 bisitz 1256: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1257: my $output = '';
1.41 raeburn 1258: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1259: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1260: if (!$is_custom->{'textcol'}) {
1261: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1262: ' ';
1263: }
1264: if (!$is_custom->{'bgcol'}) {
1265: $output .= $choices->{'bgcol'}.': '.
1266: '<span id="css_'.$role.'_font" style="background-color: '.
1267: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1268: }
1269: $output .= '<br />';
1270: }
1271: $output .='<br />';
1272: return $output;
1273: }
1274:
1275: sub login_text_colors {
1276: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1277: my $color_menu = '<table border="0"><tr>';
1278: foreach my $item (@{$logintext}) {
1279: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1280: $color_menu .= '<td align="center">'.$link;
1281: if ($designs->{'logintext'}{$item}) {
1282: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1283: }
1284: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1285: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1286: '<td> </td>';
1287: }
1288: $color_menu .= '</tr></table><br />';
1289: return $color_menu;
1290: }
1291:
1292: sub image_changes {
1293: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1294: my $output;
1.135 bisitz 1295: if ($img eq 'login') {
1296: # suppress image for Log-in header
1297: } elsif (!$is_custom) {
1.70 raeburn 1298: if ($img ne 'domlogo') {
1.41 raeburn 1299: $output .= &mt('Default image:').'<br />';
1300: } else {
1301: $output .= &mt('Default in use:').'<br />';
1302: }
1303: }
1.135 bisitz 1304: if ($img eq 'login') { # suppress image for Log-in header
1305: $output .= '<td>'.$logincolors;
1.41 raeburn 1306: } else {
1.135 bisitz 1307: if ($img_import) {
1308: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1309: }
1310: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1311: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1312: if ($is_custom) {
1313: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1314: '<input type="checkbox" name="'.
1315: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1316: '</label> '.&mt('Replace:').'</span><br />';
1317: } else {
1318: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1319: }
1.41 raeburn 1320: }
1321: return $output;
1322: }
1323:
1.6 raeburn 1324: sub color_pick {
1325: my ($phase,$role,$item,$desc,$curcol) = @_;
1326: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1327: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1328: ');">'.$desc.'</a>';
1329: return $link;
1330: }
1331:
1.3 raeburn 1332: sub print_quotas {
1.86 raeburn 1333: my ($dom,$settings,$rowtotal,$action) = @_;
1334: my $context;
1335: if ($action eq 'quotas') {
1336: $context = 'tools';
1337: } else {
1338: $context = $action;
1339: }
1.101 raeburn 1340: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1341: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1342: my $typecount = 0;
1.101 raeburn 1343: my ($css_class,%titles);
1.86 raeburn 1344: if ($context eq 'requestcourses') {
1.98 raeburn 1345: @usertools = ('official','unofficial','community');
1.106 raeburn 1346: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1347: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1348: %titles = &courserequest_titles();
1.86 raeburn 1349: } else {
1350: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1351: %titles = &tool_titles();
1.86 raeburn 1352: }
1.26 raeburn 1353: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1354: foreach my $type (@{$types}) {
1.72 raeburn 1355: my $currdefquota;
1.86 raeburn 1356: unless ($context eq 'requestcourses') {
1357: if (ref($settings) eq 'HASH') {
1358: if (ref($settings->{defaultquota}) eq 'HASH') {
1359: $currdefquota = $settings->{defaultquota}->{$type};
1360: } else {
1361: $currdefquota = $settings->{$type};
1362: }
1.78 raeburn 1363: }
1.72 raeburn 1364: }
1.3 raeburn 1365: if (defined($usertypes->{$type})) {
1366: $typecount ++;
1367: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1368: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1369: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1370: '<td class="LC_left_item">';
1.101 raeburn 1371: if ($context eq 'requestcourses') {
1372: $datatable .= '<table><tr>';
1373: }
1374: my %cell;
1.72 raeburn 1375: foreach my $item (@usertools) {
1.101 raeburn 1376: if ($context eq 'requestcourses') {
1377: my ($curroption,$currlimit);
1378: if (ref($settings) eq 'HASH') {
1379: if (ref($settings->{$item}) eq 'HASH') {
1380: $curroption = $settings->{$item}->{$type};
1381: if ($curroption =~ /^autolimit=(\d*)$/) {
1382: $currlimit = $1;
1383: }
1384: }
1385: }
1386: if (!$curroption) {
1387: $curroption = 'norequest';
1388: }
1389: $datatable .= '<th>'.$titles{$item}.'</th>';
1390: foreach my $option (@options) {
1391: my $val = $option;
1392: if ($option eq 'norequest') {
1393: $val = 0;
1394: }
1395: if ($option eq 'validate') {
1396: my $canvalidate = 0;
1397: if (ref($validations{$item}) eq 'HASH') {
1398: if ($validations{$item}{$type}) {
1399: $canvalidate = 1;
1400: }
1401: }
1402: next if (!$canvalidate);
1403: }
1404: my $checked = '';
1405: if ($option eq $curroption) {
1406: $checked = ' checked="checked"';
1407: } elsif ($option eq 'autolimit') {
1408: if ($curroption =~ /^autolimit/) {
1409: $checked = ' checked="checked"';
1410: }
1411: }
1412: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1413: '<input type="radio" name="crsreq_'.$item.
1414: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1415: $titles{$option}.'</label>';
1.101 raeburn 1416: if ($option eq 'autolimit') {
1.127 raeburn 1417: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1418: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1419: 'value="'.$currlimit.'" />';
1.101 raeburn 1420: }
1.127 raeburn 1421: $cell{$item} .= '</span> ';
1.103 raeburn 1422: if ($option eq 'autolimit') {
1.127 raeburn 1423: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1424: }
1.101 raeburn 1425: }
1426: } else {
1427: my $checked = 'checked="checked" ';
1428: if (ref($settings) eq 'HASH') {
1429: if (ref($settings->{$item}) eq 'HASH') {
1430: if ($settings->{$item}->{$type} == 0) {
1431: $checked = '';
1432: } elsif ($settings->{$item}->{$type} == 1) {
1433: $checked = 'checked="checked" ';
1434: }
1.78 raeburn 1435: }
1.72 raeburn 1436: }
1.101 raeburn 1437: $datatable .= '<span class="LC_nobreak"><label>'.
1438: '<input type="checkbox" name="'.$context.'_'.$item.
1439: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1440: '</label></span> ';
1.72 raeburn 1441: }
1.101 raeburn 1442: }
1443: if ($context eq 'requestcourses') {
1444: $datatable .= '</tr><tr>';
1445: foreach my $item (@usertools) {
1.106 raeburn 1446: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1447: }
1448: $datatable .= '</tr></table>';
1.72 raeburn 1449: }
1.86 raeburn 1450: $datatable .= '</td>';
1451: unless ($context eq 'requestcourses') {
1452: $datatable .=
1453: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1454: '<input type="text" name="quota_'.$type.
1.72 raeburn 1455: '" value="'.$currdefquota.
1.86 raeburn 1456: '" size="5" /> Mb</span></td>';
1457: }
1458: $datatable .= '</tr>';
1.3 raeburn 1459: }
1460: }
1461: }
1.86 raeburn 1462: unless ($context eq 'requestcourses') {
1463: $defaultquota = '20';
1464: if (ref($settings) eq 'HASH') {
1465: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1466: $defaultquota = $settings->{'defaultquota'}->{'default'};
1467: } elsif (defined($settings->{'default'})) {
1468: $defaultquota = $settings->{'default'};
1469: }
1.3 raeburn 1470: }
1471: }
1472: $typecount ++;
1473: $css_class = $typecount%2?' class="LC_odd_row"':'';
1474: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1475: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1476: '<td class="LC_left_item">';
1.101 raeburn 1477: if ($context eq 'requestcourses') {
1478: $datatable .= '<table><tr>';
1479: }
1480: my %defcell;
1.72 raeburn 1481: foreach my $item (@usertools) {
1.101 raeburn 1482: if ($context eq 'requestcourses') {
1483: my ($curroption,$currlimit);
1484: if (ref($settings) eq 'HASH') {
1485: if (ref($settings->{$item}) eq 'HASH') {
1486: $curroption = $settings->{$item}->{'default'};
1487: if ($curroption =~ /^autolimit=(\d*)$/) {
1488: $currlimit = $1;
1489: }
1490: }
1491: }
1492: if (!$curroption) {
1493: $curroption = 'norequest';
1494: }
1495: $datatable .= '<th>'.$titles{$item}.'</th>';
1496: foreach my $option (@options) {
1497: my $val = $option;
1498: if ($option eq 'norequest') {
1499: $val = 0;
1500: }
1501: if ($option eq 'validate') {
1502: my $canvalidate = 0;
1503: if (ref($validations{$item}) eq 'HASH') {
1504: if ($validations{$item}{'default'}) {
1505: $canvalidate = 1;
1506: }
1507: }
1508: next if (!$canvalidate);
1509: }
1510: my $checked = '';
1511: if ($option eq $curroption) {
1512: $checked = ' checked="checked"';
1513: } elsif ($option eq 'autolimit') {
1514: if ($curroption =~ /^autolimit/) {
1515: $checked = ' checked="checked"';
1516: }
1517: }
1518: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1519: '<input type="radio" name="crsreq_'.$item.
1520: '_default" value="'.$val.'"'.$checked.' />'.
1521: $titles{$option}.'</label>';
1522: if ($option eq 'autolimit') {
1.127 raeburn 1523: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1524: $item.'_limit_default" size="1" '.
1525: 'value="'.$currlimit.'" />';
1526: }
1.127 raeburn 1527: $defcell{$item} .= '</span> ';
1.104 raeburn 1528: if ($option eq 'autolimit') {
1.127 raeburn 1529: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1530: }
1.101 raeburn 1531: }
1532: } else {
1533: my $checked = 'checked="checked" ';
1534: if (ref($settings) eq 'HASH') {
1535: if (ref($settings->{$item}) eq 'HASH') {
1536: if ($settings->{$item}->{'default'} == 0) {
1537: $checked = '';
1538: } elsif ($settings->{$item}->{'default'} == 1) {
1539: $checked = 'checked="checked" ';
1540: }
1.78 raeburn 1541: }
1.72 raeburn 1542: }
1.101 raeburn 1543: $datatable .= '<span class="LC_nobreak"><label>'.
1544: '<input type="checkbox" name="'.$context.'_'.$item.
1545: '" value="default" '.$checked.'/>'.$titles{$item}.
1546: '</label></span> ';
1547: }
1548: }
1549: if ($context eq 'requestcourses') {
1550: $datatable .= '</tr><tr>';
1551: foreach my $item (@usertools) {
1.106 raeburn 1552: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1553: }
1.101 raeburn 1554: $datatable .= '</tr></table>';
1.72 raeburn 1555: }
1.86 raeburn 1556: $datatable .= '</td>';
1557: unless ($context eq 'requestcourses') {
1558: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1559: '<input type="text" name="defaultquota" value="'.
1560: $defaultquota.'" size="5" /> Mb</span></td>';
1561: }
1562: $datatable .= '</tr>';
1.72 raeburn 1563: $typecount ++;
1564: $css_class = $typecount%2?' class="LC_odd_row"':'';
1565: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1566: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1567: if ($context eq 'requestcourses') {
1.109 raeburn 1568: $datatable .= &mt('(overrides affiliation, if set)').
1569: '</td>'.
1570: '<td class="LC_left_item">'.
1571: '<table><tr>';
1.101 raeburn 1572: } else {
1.109 raeburn 1573: $datatable .= &mt('(overrides affiliation, if checked)').
1574: '</td>'.
1575: '<td class="LC_left_item" colspan="2">'.
1576: '<br />';
1.101 raeburn 1577: }
1578: my %advcell;
1.72 raeburn 1579: foreach my $item (@usertools) {
1.101 raeburn 1580: if ($context eq 'requestcourses') {
1581: my ($curroption,$currlimit);
1582: if (ref($settings) eq 'HASH') {
1583: if (ref($settings->{$item}) eq 'HASH') {
1584: $curroption = $settings->{$item}->{'_LC_adv'};
1585: if ($curroption =~ /^autolimit=(\d*)$/) {
1586: $currlimit = $1;
1587: }
1588: }
1589: }
1590: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1591: my $checked = '';
1592: if ($curroption eq '') {
1593: $checked = ' checked="checked"';
1594: }
1595: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1596: '<input type="radio" name="crsreq_'.$item.
1597: '__LC_adv" value=""'.$checked.' />'.
1598: &mt('No override set').'</label></span> ';
1.101 raeburn 1599: foreach my $option (@options) {
1600: my $val = $option;
1601: if ($option eq 'norequest') {
1602: $val = 0;
1603: }
1604: if ($option eq 'validate') {
1605: my $canvalidate = 0;
1606: if (ref($validations{$item}) eq 'HASH') {
1607: if ($validations{$item}{'_LC_adv'}) {
1608: $canvalidate = 1;
1609: }
1610: }
1611: next if (!$canvalidate);
1612: }
1613: my $checked = '';
1.104 raeburn 1614: if ($val eq $curroption) {
1.101 raeburn 1615: $checked = ' checked="checked"';
1616: } elsif ($option eq 'autolimit') {
1617: if ($curroption =~ /^autolimit/) {
1618: $checked = ' checked="checked"';
1619: }
1620: }
1621: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1622: '<input type="radio" name="crsreq_'.$item.
1623: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1624: $titles{$option}.'</label>';
1625: if ($option eq 'autolimit') {
1.127 raeburn 1626: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1627: $item.'_limit__LC_adv" size="1" '.
1628: 'value="'.$currlimit.'" />';
1629: }
1.127 raeburn 1630: $advcell{$item} .= '</span> ';
1.104 raeburn 1631: if ($option eq 'autolimit') {
1.127 raeburn 1632: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1633: }
1.101 raeburn 1634: }
1635: } else {
1636: my $checked = 'checked="checked" ';
1637: if (ref($settings) eq 'HASH') {
1638: if (ref($settings->{$item}) eq 'HASH') {
1639: if ($settings->{$item}->{'_LC_adv'} == 0) {
1640: $checked = '';
1641: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1642: $checked = 'checked="checked" ';
1643: }
1.79 raeburn 1644: }
1.72 raeburn 1645: }
1.101 raeburn 1646: $datatable .= '<span class="LC_nobreak"><label>'.
1647: '<input type="checkbox" name="'.$context.'_'.$item.
1648: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1649: '</label></span> ';
1650: }
1651: }
1652: if ($context eq 'requestcourses') {
1653: $datatable .= '</tr><tr>';
1654: foreach my $item (@usertools) {
1.106 raeburn 1655: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1656: }
1.101 raeburn 1657: $datatable .= '</tr></table>';
1.72 raeburn 1658: }
1.98 raeburn 1659: $datatable .= '</td></tr>';
1.30 raeburn 1660: $$rowtotal += $typecount;
1.3 raeburn 1661: return $datatable;
1662: }
1663:
1.102 raeburn 1664: sub print_courserequestmail {
1665: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1666: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1667: $now = time;
1668: $rows = 0;
1669: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1670: foreach my $server (keys(%dompersonnel)) {
1671: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1672: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1673: if (!grep(/^$uname:$udom$/,@domcoord)) {
1674: push(@domcoord,$uname.':'.$udom);
1675: }
1676: }
1677: }
1678: if (ref($settings) eq 'HASH') {
1679: if (ref($settings->{'notify'}) eq 'HASH') {
1680: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1681: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1682: }
1683: }
1684: }
1.104 raeburn 1685: if (@currapproval) {
1686: foreach my $dc (@currapproval) {
1.102 raeburn 1687: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1688: push(@domcoord,$dc);
1689: }
1690: }
1691: }
1692: @domcoord = sort(@domcoord);
1693: my $numinrow = 4;
1694: my $numdc = @domcoord;
1695: my $css_class = 'class="LC_odd_row"';
1696: $datatable = '<tr'.$css_class.'>'.
1697: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1698: ' </td>'.
1699: ' <td class="LC_left_item">';
1700: if (@domcoord > 0) {
1701: $datatable .= '<table>';
1702: for (my $i=0; $i<$numdc; $i++) {
1703: my $rem = $i%($numinrow);
1704: if ($rem == 0) {
1705: if ($i > 0) {
1706: $datatable .= '</tr>';
1707: }
1708: $datatable .= '<tr>';
1709: $rows ++;
1710: }
1711: my $check = ' ';
1.104 raeburn 1712: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1713: $check = ' checked="checked" ';
1714: }
1715: my ($uname,$udom) = split(':',$domcoord[$i]);
1716: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1717: if ($i == $numdc-1) {
1718: my $colsleft = $numinrow-$rem;
1719: if ($colsleft > 1) {
1720: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1721: } else {
1722: $datatable .= '<td class="LC_left_item">';
1723: }
1724: } else {
1725: $datatable .= '<td class="LC_left_item">';
1726: }
1727: $datatable .= '<span class="LC_nobreak"><label>'.
1728: '<input type="checkbox" name="reqapprovalnotify" '.
1729: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1730: $fullname.'</label></span></td>';
1731: }
1732: $datatable .= '</tr></table>';
1733: } else {
1734: $datatable .= &mt('There are no active Domain Coordinators');
1735: $rows ++;
1736: }
1737: $datatable .='</td></tr>';
1738: $$rowtotal += $rows;
1739: return $datatable;
1740: }
1741:
1.3 raeburn 1742: sub print_autoenroll {
1.30 raeburn 1743: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1744: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1745: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1746: if (ref($settings) eq 'HASH') {
1747: if (exists($settings->{'run'})) {
1748: if ($settings->{'run'} eq '0') {
1749: $runoff = ' checked="checked" ';
1750: $runon = ' ';
1751: } else {
1752: $runon = ' checked="checked" ';
1753: $runoff = ' ';
1754: }
1755: } else {
1756: if ($autorun) {
1757: $runon = ' checked="checked" ';
1758: $runoff = ' ';
1759: } else {
1760: $runoff = ' checked="checked" ';
1761: $runon = ' ';
1762: }
1763: }
1.129 raeburn 1764: if (exists($settings->{'co-owners'})) {
1765: if ($settings->{'co-owners'} eq '0') {
1766: $coownersoff = ' checked="checked" ';
1767: $coownerson = ' ';
1768: } else {
1769: $coownerson = ' checked="checked" ';
1770: $coownersoff = ' ';
1771: }
1772: } else {
1773: $coownersoff = ' checked="checked" ';
1774: $coownerson = ' ';
1775: }
1.3 raeburn 1776: if (exists($settings->{'sender_domain'})) {
1777: $defdom = $settings->{'sender_domain'};
1778: }
1.14 raeburn 1779: } else {
1780: if ($autorun) {
1781: $runon = ' checked="checked" ';
1782: $runoff = ' ';
1783: } else {
1784: $runoff = ' checked="checked" ';
1785: $runon = ' ';
1786: }
1.3 raeburn 1787: }
1788: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1789: my $notif_sender;
1790: if (ref($settings) eq 'HASH') {
1791: $notif_sender = $settings->{'sender_uname'};
1792: }
1.3 raeburn 1793: my $datatable='<tr class="LC_odd_row">'.
1794: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1795: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1796: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1797: $runon.' value="1" />'.&mt('Yes').'</label> '.
1798: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1799: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1800: '</tr><tr>'.
1801: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1802: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1803: &mt('username').': '.
1804: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1805: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1806: ': '.$domform.'</span></td></tr>'.
1807: '<tr class="LC_odd_row">'.
1808: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1809: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1810: '<input type="radio" name="autoassign_coowners"'.
1811: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1812: '<label><input type="radio" name="autoassign_coowners"'.
1813: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1814: '</tr>';
1815: $$rowtotal += 3;
1.3 raeburn 1816: return $datatable;
1817: }
1818:
1819: sub print_autoupdate {
1.30 raeburn 1820: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1821: my $datatable;
1822: if ($position eq 'top') {
1823: my $updateon = ' ';
1824: my $updateoff = ' checked="checked" ';
1825: my $classlistson = ' ';
1826: my $classlistsoff = ' checked="checked" ';
1827: if (ref($settings) eq 'HASH') {
1828: if ($settings->{'run'} eq '1') {
1829: $updateon = $updateoff;
1830: $updateoff = ' ';
1831: }
1832: if ($settings->{'classlists'} eq '1') {
1833: $classlistson = $classlistsoff;
1834: $classlistsoff = ' ';
1835: }
1836: }
1837: my %title = (
1838: run => 'Auto-update active?',
1839: classlists => 'Update information in classlists?',
1840: );
1841: $datatable = '<tr class="LC_odd_row">'.
1842: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1843: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1844: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1845: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1846: '<label><input type="radio" name="autoupdate_run"'.
1847: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1848: '</tr><tr>'.
1849: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1850: '<td class="LC_right_item"><span class="LC_nobreak">'.
1851: '<label><input type="radio" name="classlists"'.
1852: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1853: '<label><input type="radio" name="classlists"'.
1854: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1855: '</tr>';
1.30 raeburn 1856: $$rowtotal += 2;
1.131 raeburn 1857: } elsif ($position eq 'middle') {
1858: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1859: my $numinrow = 3;
1860: my $locknamesettings;
1861: $datatable .= &insttypes_row($settings,$types,$usertypes,
1862: $dom,$numinrow,$othertitle,
1863: 'lockablenames');
1864: $$rowtotal ++;
1.3 raeburn 1865: } else {
1.44 raeburn 1866: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1867: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1868: 'permanentemail','id');
1.33 raeburn 1869: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1870: my $numrows = 0;
1.26 raeburn 1871: if (ref($types) eq 'ARRAY') {
1872: if (@{$types} > 0) {
1873: $datatable =
1874: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1875: \@fields,$types,\$numrows);
1.30 raeburn 1876: $$rowtotal += @{$types};
1.26 raeburn 1877: }
1.3 raeburn 1878: }
1879: $datatable .=
1880: &usertype_update_row($settings,{'default' => $othertitle},
1881: \%fieldtitles,\@fields,['default'],
1882: \$numrows);
1.30 raeburn 1883: $$rowtotal ++;
1.3 raeburn 1884: }
1885: return $datatable;
1886: }
1887:
1.125 raeburn 1888: sub print_autocreate {
1889: my ($dom,$settings,$rowtotal) = @_;
1890: my (%createon,%createoff);
1891: my $curr_dc;
1892: my @types = ('xml','req');
1893: if (ref($settings) eq 'HASH') {
1894: foreach my $item (@types) {
1895: $createoff{$item} = ' checked="checked" ';
1896: $createon{$item} = ' ';
1897: if (exists($settings->{$item})) {
1898: if ($settings->{$item}) {
1899: $createon{$item} = ' checked="checked" ';
1900: $createoff{$item} = ' ';
1901: }
1902: }
1903: }
1904: $curr_dc = $settings->{'xmldc'};
1905: } else {
1906: foreach my $item (@types) {
1907: $createoff{$item} = ' checked="checked" ';
1908: $createon{$item} = ' ';
1909: }
1910: }
1911: $$rowtotal += 2;
1912: my $datatable='<tr class="LC_odd_row">'.
1913: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1914: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1915: '<input type="radio" name="autocreate_xml"'.
1916: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1917: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 1918: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
1919: '</td></tr><tr>'.
1920: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1921: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1922: '<input type="radio" name="autocreate_req"'.
1923: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1924: '<label><input type="radio" name="autocreate_req"'.
1925: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 1926: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1927: if ($numdc > 1) {
1.143 raeburn 1928: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
1929: &mt('Course creation processed as: (choose Dom. Coord.)').
1930: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 1931: $$rowtotal ++ ;
1932: } else {
1.143 raeburn 1933: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 1934: }
1935: return $datatable;
1936: }
1937:
1.23 raeburn 1938: sub print_directorysrch {
1.30 raeburn 1939: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1940: my $srchon = ' ';
1941: my $srchoff = ' checked="checked" ';
1.25 raeburn 1942: my ($exacton,$containson,$beginson);
1.24 raeburn 1943: my $localon = ' ';
1944: my $localoff = ' checked="checked" ';
1.23 raeburn 1945: if (ref($settings) eq 'HASH') {
1946: if ($settings->{'available'} eq '1') {
1947: $srchon = $srchoff;
1948: $srchoff = ' ';
1949: }
1.24 raeburn 1950: if ($settings->{'localonly'} eq '1') {
1951: $localon = $localoff;
1952: $localoff = ' ';
1953: }
1.25 raeburn 1954: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1955: foreach my $type (@{$settings->{'searchtypes'}}) {
1956: if ($type eq 'exact') {
1957: $exacton = ' checked="checked" ';
1958: } elsif ($type eq 'contains') {
1959: $containson = ' checked="checked" ';
1960: } elsif ($type eq 'begins') {
1961: $beginson = ' checked="checked" ';
1962: }
1963: }
1964: } else {
1965: if ($settings->{'searchtypes'} eq 'exact') {
1966: $exacton = ' checked="checked" ';
1967: } elsif ($settings->{'searchtypes'} eq 'contains') {
1968: $containson = ' checked="checked" ';
1969: } elsif ($settings->{'searchtypes'} eq 'specify') {
1970: $exacton = ' checked="checked" ';
1971: $containson = ' checked="checked" ';
1972: }
1.23 raeburn 1973: }
1974: }
1975: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1976: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1977:
1978: my $numinrow = 4;
1.26 raeburn 1979: my $cansrchrow = 0;
1.23 raeburn 1980: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1981: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1982: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1983: '<input type="radio" name="dirsrch_available"'.
1984: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1985: '<label><input type="radio" name="dirsrch_available"'.
1986: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1987: '</tr><tr>'.
1.30 raeburn 1988: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1989: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1990: '<input type="radio" name="dirsrch_localonly"'.
1991: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1992: '<label><input type="radio" name="dirsrch_localonly"'.
1993: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1994: '</tr>';
1.30 raeburn 1995: $$rowtotal += 2;
1.26 raeburn 1996: if (ref($usertypes) eq 'HASH') {
1997: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 1998: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1999: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2000: $cansrchrow = 1;
2001: }
2002: }
2003: if ($cansrchrow) {
1.30 raeburn 2004: $$rowtotal ++;
1.26 raeburn 2005: $datatable .= '<tr>';
2006: } else {
2007: $datatable .= '<tr class="LC_odd_row">';
2008: }
1.30 raeburn 2009: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2010: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2011: foreach my $title (@{$titleorder}) {
2012: if (defined($searchtitles->{$title})) {
2013: my $check = ' ';
1.93 raeburn 2014: if (ref($settings) eq 'HASH') {
1.39 raeburn 2015: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2016: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2017: $check = ' checked="checked" ';
2018: }
1.25 raeburn 2019: }
2020: }
2021: $datatable .= '<td class="LC_left_item">'.
2022: '<span class="LC_nobreak"><label>'.
2023: '<input type="checkbox" name="searchby" '.
2024: 'value="'.$title.'"'.$check.'/>'.
2025: $searchtitles->{$title}.'</label></span></td>';
2026: }
2027: }
1.26 raeburn 2028: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2029: $$rowtotal ++;
1.26 raeburn 2030: if ($cansrchrow) {
2031: $datatable .= '<tr class="LC_odd_row">';
2032: } else {
2033: $datatable .= '<tr>';
2034: }
1.30 raeburn 2035: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2036: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2037: '<span class="LC_nobreak"><label>'.
2038: '<input type="checkbox" name="searchtypes" '.
2039: $exacton.' value="exact" />'.&mt('Exact match').
2040: '</label> '.
2041: '<label><input type="checkbox" name="searchtypes" '.
2042: $beginson.' value="begins" />'.&mt('Begins with').
2043: '</label> '.
2044: '<label><input type="checkbox" name="searchtypes" '.
2045: $containson.' value="contains" />'.&mt('Contains').
2046: '</label></span></td></tr>';
1.30 raeburn 2047: $$rowtotal ++;
1.25 raeburn 2048: return $datatable;
2049: }
2050:
1.28 raeburn 2051: sub print_contacts {
1.30 raeburn 2052: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2053: my $datatable;
2054: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2055: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2056: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2057: 'requestsmail');
1.28 raeburn 2058: foreach my $type (@mailings) {
2059: $otheremails{$type} = '';
2060: }
1.134 raeburn 2061: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2062: if (ref($settings) eq 'HASH') {
2063: foreach my $item (@contacts) {
2064: if (exists($settings->{$item})) {
2065: $to{$item} = $settings->{$item};
2066: }
2067: }
2068: foreach my $type (@mailings) {
2069: if (exists($settings->{$type})) {
2070: if (ref($settings->{$type}) eq 'HASH') {
2071: foreach my $item (@contacts) {
2072: if ($settings->{$type}{$item}) {
2073: $checked{$type}{$item} = ' checked="checked" ';
2074: }
2075: }
2076: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2077: if ($type eq 'helpdeskmail') {
2078: $bccemails{$type} = $settings->{$type}{'bcc'};
2079: }
1.28 raeburn 2080: }
1.89 raeburn 2081: } elsif ($type eq 'lonstatusmail') {
2082: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2083: }
2084: }
2085: } else {
2086: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2087: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2088: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2089: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2090: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2091: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2092: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2093: }
2094: my ($titles,$short_titles) = &contact_titles();
2095: my $rownum = 0;
2096: my $css_class;
2097: foreach my $item (@contacts) {
1.69 raeburn 2098: $rownum ++;
2099: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2100: $datatable .= '<tr'.$css_class.'>'.
2101: '<td><span class="LC_nobreak">'.$titles->{$item}.
2102: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2103: '<input type="text" name="'.$item.'" value="'.
2104: $to{$item}.'" /></td></tr>';
2105: }
2106: foreach my $type (@mailings) {
1.69 raeburn 2107: $rownum ++;
2108: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2109: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2110: '<td><span class="LC_nobreak">'.
2111: $titles->{$type}.': </span></td>'.
1.28 raeburn 2112: '<td class="LC_left_item">'.
2113: '<span class="LC_nobreak">';
2114: foreach my $item (@contacts) {
2115: $datatable .= '<label>'.
2116: '<input type="checkbox" name="'.$type.'"'.
2117: $checked{$type}{$item}.
2118: ' value="'.$item.'" />'.$short_titles->{$item}.
2119: '</label> ';
2120: }
2121: $datatable .= '</span><br />'.&mt('Others').': '.
2122: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2123: 'value="'.$otheremails{$type}.'" />';
2124: if ($type eq 'helpdeskmail') {
1.136 raeburn 2125: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2126: '<input type="text" name="'.$type.'_bcc" '.
2127: 'value="'.$bccemails{$type}.'" />';
2128: }
2129: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2130: }
1.30 raeburn 2131: $$rowtotal += $rownum;
1.28 raeburn 2132: return $datatable;
2133: }
2134:
1.118 jms 2135: sub print_helpsettings {
1.122 jms 2136:
2137: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2138: my ($css_class,$datatable);
2139:
2140: my $switchserver = &check_switchserver($dom,$confname);
2141:
2142: my $itemcount = 1;
2143:
2144: if ($position eq 'top') {
2145:
2146: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2147:
2148: %choices =
2149: &Apache::lonlocal::texthash (
2150: submitbugs => 'Display "Submit a bug" link?',
2151: );
2152:
2153: %defaultchecked = ('submitbugs' => 'on');
2154:
2155: @toggles = ('submitbugs',);
2156:
2157: foreach my $item (@toggles) {
2158: if ($defaultchecked{$item} eq 'on') {
2159: $checkedon{$item} = ' checked="checked" ';
2160: $checkedoff{$item} = ' ';
2161: } elsif ($defaultchecked{$item} eq 'off') {
2162: $checkedoff{$item} = ' checked="checked" ';
2163: $checkedon{$item} = ' ';
2164: }
2165: }
2166:
2167: if (ref($settings) eq 'HASH') {
2168: foreach my $item (@toggles) {
2169: if ($settings->{$item} eq '1') {
2170: $checkedon{$item} = ' checked="checked" ';
2171: $checkedoff{$item} = ' ';
2172: } elsif ($settings->{$item} eq '0') {
2173: $checkedoff{$item} = ' checked="checked" ';
2174: $checkedon{$item} = ' ';
2175: }
2176: }
2177: }
2178:
2179: foreach my $item (@toggles) {
2180: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2181: $datatable .=
2182: '<tr'.$css_class.'>
2183: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2184: <td><span class="LC_nobreak"> </span></td>
2185: <td class="LC_right_item"><span class="LC_nobreak">
2186: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2187: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2188: '</span></td>'.
2189: '</tr>';
2190: $itemcount ++;
2191: }
2192:
2193: } else {
2194:
2195: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2196:
2197: $datatable .= '<tr'.$css_class.'>';
2198:
2199: if (ref($settings) eq 'HASH') {
2200: if ($settings->{'loginhelpurl'} ne '') {
2201: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2202: $datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
2203: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2204: } else {
2205: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2206: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2207: }
2208: } else {
2209: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2210: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2211: }
2212:
2213: $datatable .= '<td width="33%"><span class="LC_right_item">';
2214: if ($switchserver) {
2215: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2216: } else {
2217: $datatable .= &mt('Upload Custom Login Page Help File:');
2218: $datatable .='<input type="file" name="loginhelpurl" />';
2219: }
2220: $datatable .= '</span></td></tr>';
2221:
2222: }
2223:
2224: return $datatable;
2225:
1.121 raeburn 2226: }
2227:
1.122 jms 2228:
1.121 raeburn 2229: sub radiobutton_prefs {
2230: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2231: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2232: (ref($choices) eq 'HASH'));
2233:
2234: my (%checkedon,%checkedoff,$datatable,$css_class);
2235:
2236: foreach my $item (@{$toggles}) {
2237: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2238: $checkedon{$item} = ' checked="checked" ';
2239: $checkedoff{$item} = ' ';
1.121 raeburn 2240: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2241: $checkedoff{$item} = ' checked="checked" ';
2242: $checkedon{$item} = ' ';
2243: }
2244: }
2245: if (ref($settings) eq 'HASH') {
1.121 raeburn 2246: foreach my $item (@{$toggles}) {
1.118 jms 2247: if ($settings->{$item} eq '1') {
2248: $checkedon{$item} = ' checked="checked" ';
2249: $checkedoff{$item} = ' ';
2250: } elsif ($settings->{$item} eq '0') {
2251: $checkedoff{$item} = ' checked="checked" ';
2252: $checkedon{$item} = ' ';
2253: }
2254: }
1.121 raeburn 2255: }
2256: foreach my $item (@{$toggles}) {
1.118 jms 2257: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2258: $datatable .=
2259: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2260: '</span></td>'.
2261: '<td class="LC_right_item"><span class="LC_nobreak">'.
2262: '<label><input type="radio" name="'.
2263: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2264: '</label> <label><input type="radio" name="'.$item.'" '.
2265: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2266: '</span></td>'.
2267: '</tr>';
2268: $itemcount ++;
1.121 raeburn 2269: }
2270: return ($datatable,$itemcount);
2271: }
2272:
2273: sub print_coursedefaults {
1.139 raeburn 2274: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2275: my ($css_class,$datatable);
2276: my $itemcount = 1;
1.139 raeburn 2277: if ($position eq 'top') {
2278: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2279: %choices =
2280: &Apache::lonlocal::texthash (
2281: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2282: );
2283: %defaultchecked = ('canuse_pdfforms' => 'off');
2284: @toggles = ('canuse_pdfforms',);
2285: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2286: \%choices,$itemcount);
1.139 raeburn 2287: $$rowtotal += $itemcount;
2288: } else {
2289: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2290: my %choices =
2291: &Apache::lonlocal::texthash (
2292: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2293: );
2294: my $currdefresponder;
2295: if (ref($settings) eq 'HASH') {
2296: $currdefresponder = $settings->{'anonsurvey_threshold'};
2297: }
2298: if (!$currdefresponder) {
2299: $currdefresponder = 10;
2300: } elsif ($currdefresponder < 1) {
2301: $currdefresponder = 1;
2302: }
2303: $datatable .=
2304: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2305: '</span></td>'.
2306: '<td class="LC_right_item"><span class="LC_nobreak">'.
2307: '<input type="text" name="anonsurvey_threshold"'.
2308: ' value="'.$currdefresponder.'" size="5" /></span>'.
2309: '</td></tr>';
2310: }
1.121 raeburn 2311: return $datatable;
1.118 jms 2312: }
2313:
1.137 raeburn 2314: sub print_usersessions {
2315: my ($position,$dom,$settings,$rowtotal) = @_;
2316: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2317: my (%by_ip,%by_location,@intdoms);
2318: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2319:
2320: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2321: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2322: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2323: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2324: my $itemcount = 1;
2325: if ($position eq 'top') {
1.152 raeburn 2326: if (keys(%serverhomes) > 1) {
1.145 raeburn 2327: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2328: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2329: } else {
1.140 raeburn 2330: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2331: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2332: }
1.137 raeburn 2333: } else {
1.145 raeburn 2334: if (keys(%by_location) == 0) {
2335: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2336: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2337: } else {
2338: my %lt = &usersession_titles();
2339: my $numinrow = 5;
2340: my $prefix;
2341: my @types;
2342: if ($position eq 'bottom') {
2343: $prefix = 'remote';
2344: @types = ('version','excludedomain','includedomain');
2345: } else {
2346: $prefix = 'hosted';
2347: @types = ('excludedomain','includedomain');
2348: }
2349: my (%current,%checkedon,%checkedoff);
2350: my @lcversions = &Apache::lonnet::all_loncaparevs();
2351: my @locations = sort(keys(%by_location));
2352: foreach my $type (@types) {
2353: $checkedon{$type} = '';
2354: $checkedoff{$type} = ' checked="checked"';
2355: }
2356: if (ref($settings) eq 'HASH') {
2357: if (ref($settings->{$prefix}) eq 'HASH') {
2358: foreach my $key (keys(%{$settings->{$prefix}})) {
2359: $current{$key} = $settings->{$prefix}{$key};
2360: if ($key eq 'version') {
2361: if ($current{$key} ne '') {
2362: $checkedon{$key} = ' checked="checked"';
2363: $checkedoff{$key} = '';
2364: }
2365: } elsif (ref($current{$key}) eq 'ARRAY') {
2366: $checkedon{$key} = ' checked="checked"';
2367: $checkedoff{$key} = '';
2368: }
1.137 raeburn 2369: }
2370: }
2371: }
1.145 raeburn 2372: foreach my $type (@types) {
2373: next if ($type ne 'version' && !@locations);
2374: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2375: $datatable .= '<tr'.$css_class.'>
2376: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2377: <span class="LC_nobreak">
2378: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2379: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2380: if ($type eq 'version') {
2381: my $selector = '<select name="'.$prefix.'_version">';
2382: foreach my $version (@lcversions) {
2383: my $selected = '';
2384: if ($current{'version'} eq $version) {
2385: $selected = ' selected="selected"';
2386: }
2387: $selector .= ' <option value="'.$version.'"'.
2388: $selected.'>'.$version.'</option>';
2389: }
2390: $selector .= '</select> ';
2391: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2392: } else {
2393: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2394: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2395: ' />'.(' 'x2).
2396: '<input type="button" value="'.&mt('uncheck all').'" '.
2397: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2398: "\n".
2399: '</div><div><table>';
2400: my $rem;
2401: for (my $i=0; $i<@locations; $i++) {
2402: my ($showloc,$value,$checkedtype);
2403: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2404: my $ip = $by_location{$locations[$i]}->[0];
2405: if (ref($by_ip{$ip}) eq 'ARRAY') {
2406: $value = join(':',@{$by_ip{$ip}});
2407: $showloc = join(', ',@{$by_ip{$ip}});
2408: if (ref($current{$type}) eq 'ARRAY') {
2409: foreach my $loc (@{$by_ip{$ip}}) {
2410: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2411: $checkedtype = ' checked="checked"';
2412: last;
2413: }
2414: }
1.138 raeburn 2415: }
2416: }
2417: }
1.145 raeburn 2418: $rem = $i%($numinrow);
2419: if ($rem == 0) {
2420: if ($i > 0) {
2421: $datatable .= '</tr>';
2422: }
2423: $datatable .= '<tr>';
2424: }
2425: $datatable .= '<td class="LC_left_item">'.
2426: '<span class="LC_nobreak"><label>'.
2427: '<input type="checkbox" name="'.$prefix.'_'.$type.
2428: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2429: '</label></span></td>';
1.137 raeburn 2430: }
1.145 raeburn 2431: $rem = @locations%($numinrow);
2432: my $colsleft = $numinrow - $rem;
2433: if ($colsleft > 1 ) {
2434: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2435: ' </td>';
2436: } elsif ($colsleft == 1) {
2437: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2438: }
1.145 raeburn 2439: $datatable .= '</tr></table>';
1.137 raeburn 2440: }
1.145 raeburn 2441: $datatable .= '</td></tr>';
2442: $itemcount ++;
1.137 raeburn 2443: }
2444: }
2445: }
2446: $$rowtotal += $itemcount;
2447: return $datatable;
2448: }
2449:
1.138 raeburn 2450: sub build_location_hashes {
2451: my ($intdoms,$by_ip,$by_location) = @_;
2452: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2453: (ref($by_location) eq 'HASH'));
2454: my %iphost = &Apache::lonnet::get_iphost();
2455: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2456: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2457: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2458: foreach my $id (@{$iphost{$primary_ip}}) {
2459: my $intdom = &Apache::lonnet::internet_dom($id);
2460: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2461: push(@{$intdoms},$intdom);
2462: }
2463: }
2464: }
2465: foreach my $ip (keys(%iphost)) {
2466: if (ref($iphost{$ip}) eq 'ARRAY') {
2467: foreach my $id (@{$iphost{$ip}}) {
2468: my $location = &Apache::lonnet::internet_dom($id);
2469: if ($location) {
2470: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2471: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2472: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2473: push(@{$by_ip->{$ip}},$location);
2474: }
2475: } else {
2476: $by_ip->{$ip} = [$location];
2477: }
2478: }
2479: }
2480: }
2481: }
2482: foreach my $ip (sort(keys(%{$by_ip}))) {
2483: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2484: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2485: my $first = $by_ip->{$ip}->[0];
2486: if (ref($by_location->{$first}) eq 'ARRAY') {
2487: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2488: push(@{$by_location->{$first}},$ip);
2489: }
2490: } else {
2491: $by_location->{$first} = [$ip];
2492: }
2493: }
2494: }
2495: return;
2496: }
2497:
1.145 raeburn 2498: sub current_offloads_to {
2499: my ($dom,$settings,$servers) = @_;
2500: my (%spareid,%otherdomconfigs);
1.152 raeburn 2501: if (ref($servers) eq 'HASH') {
1.145 raeburn 2502: foreach my $lonhost (sort(keys(%{$servers}))) {
2503: my $gotspares;
1.152 raeburn 2504: if (ref($settings) eq 'HASH') {
2505: if (ref($settings->{'spares'}) eq 'HASH') {
2506: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2507: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2508: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2509: $gotspares = 1;
2510: }
1.145 raeburn 2511: }
2512: }
2513: unless ($gotspares) {
2514: my $gotspares;
2515: my $serverhomeID =
2516: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2517: my $serverhomedom =
2518: &Apache::lonnet::host_domain($serverhomeID);
2519: if ($serverhomedom ne $dom) {
2520: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2521: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2522: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2523: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2524: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2525: $gotspares = 1;
2526: }
2527: }
2528: } else {
2529: $otherdomconfigs{$serverhomedom} =
2530: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2531: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2532: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2533: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2534: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2535: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2536: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2537: $gotspares = 1;
2538: }
2539: }
2540: }
2541: }
2542: }
2543: }
2544: }
2545: unless ($gotspares) {
2546: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2547: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2548: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2549: } else {
2550: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2551: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2552: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2553: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2554: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2555: } else {
1.150 raeburn 2556: my %what = (
2557: spareid => 1,
2558: );
2559: my ($result,$returnhash) =
2560: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2561: if ($result eq 'ok') {
2562: if (ref($returnhash) eq 'HASH') {
2563: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2564: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2565: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2566: }
2567: }
1.145 raeburn 2568: }
2569: }
2570: }
2571: }
2572: }
2573: }
2574: return %spareid;
2575: }
2576:
2577: sub spares_row {
1.152 raeburn 2578: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2579: my $css_class;
2580: my $numinrow = 4;
2581: my $itemcount = 1;
2582: my $datatable;
1.152 raeburn 2583: my %typetitles = &sparestype_titles();
2584: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2585: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2586: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2587: my ($othercontrol,$serverdom);
2588: if ($serverhome ne $server) {
2589: $serverdom = &Apache::lonnet::host_domain($serverhome);
2590: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2591: } else {
2592: $serverdom = &Apache::lonnet::host_domain($server);
2593: if ($serverdom ne $dom) {
2594: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2595: }
2596: }
2597: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2598: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2599: $datatable .= '<tr'.$css_class.'>
2600: <td rowspan="2">
1.152 raeburn 2601: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2602: my (%current,%canselect);
1.152 raeburn 2603: my @choices =
2604: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2605: foreach my $type ('primary','default') {
2606: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2607: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2608: my @spares = @{$spareid->{$server}{$type}};
2609: if (@spares > 0) {
1.152 raeburn 2610: if ($othercontrol) {
2611: $current{$type} = join(', ',@spares);
2612: } else {
2613: $current{$type} .= '<table>';
2614: my $numspares = scalar(@spares);
2615: for (my $i=0; $i<@spares; $i++) {
2616: my $rem = $i%($numinrow);
2617: if ($rem == 0) {
2618: if ($i > 0) {
2619: $current{$type} .= '</tr>';
2620: }
2621: $current{$type} .= '<tr>';
1.145 raeburn 2622: }
1.152 raeburn 2623: $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'".');" /> '.
2624: $spareid->{$server}{$type}[$i].
2625: '</label></td>'."\n";
2626: }
2627: my $rem = @spares%($numinrow);
2628: my $colsleft = $numinrow - $rem;
2629: if ($colsleft > 1 ) {
2630: $current{$type} .= '<td colspan="'.$colsleft.
2631: '" class="LC_left_item">'.
2632: ' </td>';
2633: } elsif ($colsleft == 1) {
2634: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2635: }
1.152 raeburn 2636: $current{$type} .= '</tr></table>';
1.150 raeburn 2637: }
1.145 raeburn 2638: }
2639: }
2640: if ($current{$type} eq '') {
2641: $current{$type} = &mt('None specified');
2642: }
1.152 raeburn 2643: if ($othercontrol) {
2644: if ($type eq 'primary') {
2645: $canselect{$type} = $othercontrol;
2646: }
2647: } else {
2648: $canselect{$type} =
2649: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2650: '<select name="newspare_'.$type.'_'.$server.'" '.
2651: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2652: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2653: if (@choices > 0) {
2654: foreach my $lonhost (@choices) {
2655: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2656: }
2657: }
2658: $canselect{$type} .= '</select>'."\n";
2659: }
2660: } else {
2661: $current{$type} = &mt('Could not be determined');
2662: if ($type eq 'primary') {
2663: $canselect{$type} = $othercontrol;
2664: }
1.145 raeburn 2665: }
1.152 raeburn 2666: if ($type eq 'default') {
2667: $datatable .= '<tr'.$css_class.'>';
2668: }
2669: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2670: '<td>'.$current{$type}.'</td>'."\n".
2671: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2672: }
2673: $itemcount ++;
2674: }
2675: }
2676: $$rowtotal += $itemcount;
2677: return $datatable;
2678: }
2679:
1.152 raeburn 2680: sub possible_newspares {
2681: my ($server,$currspares,$serverhomes,$altids) = @_;
2682: my $serverhostname = &Apache::lonnet::hostname($server);
2683: my %excluded;
2684: if ($serverhostname ne '') {
2685: %excluded = (
2686: $serverhostname => 1,
2687: );
2688: }
2689: if (ref($currspares) eq 'HASH') {
2690: foreach my $type (keys(%{$currspares})) {
2691: if (ref($currspares->{$type}) eq 'ARRAY') {
2692: if (@{$currspares->{$type}} > 0) {
2693: foreach my $curr (@{$currspares->{$type}}) {
2694: my $hostname = &Apache::lonnet::hostname($curr);
2695: $excluded{$hostname} = 1;
2696: }
2697: }
2698: }
2699: }
2700: }
2701: my @choices;
2702: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2703: if (keys(%{$serverhomes}) > 1) {
2704: foreach my $name (sort(keys(%{$serverhomes}))) {
2705: unless ($excluded{$name}) {
2706: if (exists($altids->{$serverhomes->{$name}})) {
2707: push(@choices,$altids->{$serverhomes->{$name}});
2708: } else {
2709: push(@choices,$serverhomes->{$name});
1.145 raeburn 2710: }
2711: }
2712: }
2713: }
2714: }
1.152 raeburn 2715: return sort(@choices);
1.145 raeburn 2716: }
2717:
1.150 raeburn 2718: sub print_loadbalancing {
2719: my ($dom,$settings,$rowtotal) = @_;
2720: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2721: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2722: my $numinrow = 1;
2723: my $datatable;
2724: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2725: my ($currbalancer,$currtargets,$currrules);
2726: if (keys(%servers) > 1) {
2727: if (ref($settings) eq 'HASH') {
2728: $currbalancer = $settings->{'lonhost'};
2729: $currtargets = $settings->{'targets'};
2730: $currrules = $settings->{'rules'};
2731: } else {
2732: ($currbalancer,$currtargets) =
2733: &Apache::lonnet::get_lonbalancer_config(\%servers);
2734: }
2735: } else {
2736: return;
2737: }
2738: my ($othertitle,$usertypes,$types) =
2739: &Apache::loncommon::sorted_inst_types($dom);
2740: my $rownum = 6;
2741: if (ref($types) eq 'ARRAY') {
2742: $rownum += scalar(@{$types});
2743: }
1.153 raeburn 2744: my $css_class = ' class="LC_odd_row"';
1.150 raeburn 2745: my $targets_div_style = 'display: none';
2746: my $disabled_div_style = 'display: block';
2747: my $homedom_div_style = 'display: none';
2748: $datatable = '<tr'.$css_class.'>'.
2749: '<td rowspan="'.$rownum.'" valign="top">'.
2750: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
2751: '<option value=""';
2752: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
2753: $datatable .= ' selected="selected"';
2754: } else {
2755: $targets_div_style = 'display: block';
2756: $disabled_div_style = 'display: none';
2757: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
2758: $homedom_div_style = 'display: block';
2759: }
2760: }
2761: $datatable .= '>'.&mt('None').'</option>'."\n";
2762: foreach my $lonhost (sort(keys(%servers))) {
2763: my $selected;
2764: if ($lonhost eq $currbalancer) {
2765: $selected .= ' selected="selected"';
2766: }
2767: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
2768: }
2769: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
2770: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
2771: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2772: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
2773: my @sparestypes = ('primary','default');
2774: my %typetitles = &sparestype_titles();
2775: foreach my $sparetype (@sparestypes) {
2776: my $targettable;
2777: for (my $i=0; $i<$numspares; $i++) {
2778: my $checked;
2779: if (ref($currtargets) eq 'HASH') {
2780: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
2781: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
2782: $checked = ' checked="checked"';
2783: }
2784: }
2785: }
2786: my $chkboxval;
2787: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
2788: $chkboxval = $spares[$i];
2789: }
2790: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
2791: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2792: '</span></label></td>';
2793: my $rem = $i%($numinrow);
2794: if ($rem == 0) {
2795: if ($i > 0) {
2796: $targettable .= '</tr>';
2797: }
2798: $targettable .= '<tr>';
2799: }
2800: }
2801: if ($targettable ne '') {
2802: my $rem = $numspares%($numinrow);
2803: my $colsleft = $numinrow - $rem;
2804: if ($colsleft > 1 ) {
2805: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2806: ' </td>';
2807: } elsif ($colsleft == 1) {
2808: $targettable .= '<td class="LC_left_item"> </td>';
2809: }
2810: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2811: '<table><tr>'.$targettable.'</table><br />';
2812: }
2813: }
2814: $datatable .= '</div></td></tr>'.
2815: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
2816: $usertypes,$types,\%servers,$currbalancer,
1.153 raeburn 2817: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2818: $$rowtotal += $rownum;
2819: return $datatable;
2820: }
2821:
2822: sub loadbalancing_rules {
2823: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153 raeburn 2824: $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150 raeburn 2825: my $output;
2826: my ($alltypes,$othertypes,$titles) =
2827: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
2828: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
2829: foreach my $type (@{$alltypes}) {
2830: my $current;
2831: if (ref($currrules) eq 'HASH') {
2832: $current = $currrules->{$type};
2833: }
2834: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2835: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
2836: $current = '';
2837: }
2838: }
2839: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
2840: $servers,$currbalancer,$dom,
1.153 raeburn 2841: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2842: }
2843: }
2844: return $output;
2845: }
2846:
2847: sub loadbalancing_titles {
2848: my ($dom,$intdom,$usertypes,$types) = @_;
2849: my %othertypes = (
2850: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
2851: '_LC_author' => &mt('Users from [_1] with author role',$dom),
2852: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
2853: '_LC_external' => &mt('Users not from [_1]',$intdom),
2854: );
2855: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
2856: if (ref($types) eq 'ARRAY') {
2857: unshift(@alltypes,@{$types},'default');
2858: }
2859: my %titles;
2860: foreach my $type (@alltypes) {
2861: if ($type =~ /^_LC_/) {
2862: $titles{$type} = $othertypes{$type};
2863: } elsif ($type eq 'default') {
2864: $titles{$type} = &mt('All users from [_1]',$dom);
2865: if (ref($types) eq 'ARRAY') {
2866: if (@{$types} > 0) {
2867: $titles{$type} = &mt('Other users from [_1]',$dom);
2868: }
2869: }
2870: } elsif (ref($usertypes) eq 'HASH') {
2871: $titles{$type} = $usertypes->{$type};
2872: }
2873: }
2874: return (\@alltypes,\%othertypes,\%titles);
2875: }
2876:
2877: sub loadbalance_rule_row {
2878: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153 raeburn 2879: $homedom_div_style,$css_class) = @_;
1.150 raeburn 2880: my @rulenames = ('default','homeserver');
2881: my %ruletitles = &offloadtype_text();
2882: if ($type eq '_LC_external') {
2883: push(@rulenames,'externalbalancer');
2884: } else {
2885: push(@rulenames,'specific');
2886: }
2887: my $style = $targets_div_style;
2888: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2889: $style = $homedom_div_style;
2890: }
2891: my $output =
1.153 raeburn 2892: '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150 raeburn 2893: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
2894: for (my $i=0; $i<@rulenames; $i++) {
2895: my $rule = $rulenames[$i];
2896: my ($checked,$extra);
2897: if ($rulenames[$i] eq 'default') {
2898: $rule = '';
2899: }
2900: if ($rulenames[$i] eq 'specific') {
2901: if (ref($servers) eq 'HASH') {
2902: my $default;
2903: if (($current ne '') && (exists($servers->{$current}))) {
2904: $checked = ' checked="checked"';
2905: }
2906: unless ($checked) {
2907: $default = ' selected="selected"';
2908: }
2909: $extra = ': <select name="loadbalancing_singleserver_'.$type.
2910: '" id="loadbalancing_singleserver_'.$type.
2911: '" onchange="singleServerToggle('."'$type'".')">'."\n".
2912: '<option value=""'.$default.'></option>'."\n";
2913: foreach my $lonhost (sort(keys(%{$servers}))) {
2914: next if ($lonhost eq $currbalancer);
2915: my $selected;
2916: if ($lonhost eq $current) {
2917: $selected = ' selected="selected"';
2918: }
2919: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
2920: }
2921: $extra .= '</select>';
2922: }
2923: } elsif ($rule eq $current) {
2924: $checked = ' checked="checked"';
2925: }
2926: $output .= '<span class="LC_nobreak"><label>'.
2927: '<input type="radio" name="loadbalancing_rules_'.$type.
2928: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
2929: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
2930: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
2931: '</label>'.$extra.'</span><br />'."\n";
2932: }
2933: $output .= '</div></td></tr>'."\n";
2934: return $output;
2935: }
2936:
2937: sub offloadtype_text {
2938: my %ruletitles = &Apache::lonlocal::texthash (
2939: 'default' => 'Offloads to default destinations',
2940: 'homeserver' => "Offloads to user's home server",
2941: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
2942: 'specific' => 'Offloads to specific server',
2943: );
2944: return %ruletitles;
2945: }
2946:
2947: sub sparestype_titles {
2948: my %typestitles = &Apache::lonlocal::texthash (
2949: 'primary' => 'primary',
2950: 'default' => 'default',
2951: );
2952: return %typestitles;
2953: }
2954:
1.28 raeburn 2955: sub contact_titles {
2956: my %titles = &Apache::lonlocal::texthash (
2957: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2958: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2959: 'errormail' => 'Error reports to be e-mailed to',
2960: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2961: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2962: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2963: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2964: );
2965: my %short_titles = &Apache::lonlocal::texthash (
2966: adminemail => 'Admin E-mail address',
2967: supportemail => 'Support E-mail',
2968: );
2969: return (\%titles,\%short_titles);
2970: }
2971:
1.72 raeburn 2972: sub tool_titles {
2973: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 2974: aboutme => 'Personal Information Page',
1.86 raeburn 2975: blog => 'Blog',
2976: portfolio => 'Portfolio',
1.88 bisitz 2977: official => 'Official courses (with institutional codes)',
2978: unofficial => 'Unofficial courses',
1.98 raeburn 2979: community => 'Communities',
1.86 raeburn 2980: );
1.72 raeburn 2981: return %titles;
2982: }
2983:
1.101 raeburn 2984: sub courserequest_titles {
2985: my %titles = &Apache::lonlocal::texthash (
2986: official => 'Official',
2987: unofficial => 'Unofficial',
2988: community => 'Communities',
2989: norequest => 'Not allowed',
1.104 raeburn 2990: approval => 'Approval by Dom. Coord.',
1.101 raeburn 2991: validate => 'With validation',
2992: autolimit => 'Numerical limit',
1.103 raeburn 2993: unlimited => '(blank for unlimited)',
1.101 raeburn 2994: );
2995: return %titles;
2996: }
2997:
2998: sub courserequest_conditions {
2999: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3000: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3001: validate => '(Processing of request subject to instittutional validation).',
3002: );
3003: return %conditions;
3004: }
3005:
3006:
1.27 raeburn 3007: sub print_usercreation {
1.30 raeburn 3008: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3009: my $numinrow = 4;
1.28 raeburn 3010: my $datatable;
3011: if ($position eq 'top') {
1.30 raeburn 3012: $$rowtotal ++;
1.34 raeburn 3013: my $rowcount = 0;
1.32 raeburn 3014: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3015: if (ref($rules) eq 'HASH') {
3016: if (keys(%{$rules}) > 0) {
1.32 raeburn 3017: $datatable .= &user_formats_row('username',$settings,$rules,
3018: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3019: $$rowtotal ++;
1.32 raeburn 3020: $rowcount ++;
3021: }
3022: }
3023: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3024: if (ref($idrules) eq 'HASH') {
3025: if (keys(%{$idrules}) > 0) {
3026: $datatable .= &user_formats_row('id',$settings,$idrules,
3027: $idruleorder,$numinrow,$rowcount);
3028: $$rowtotal ++;
3029: $rowcount ++;
1.28 raeburn 3030: }
3031: }
1.43 raeburn 3032: my ($emailrules,$emailruleorder) =
3033: &Apache::lonnet::inst_userrules($dom,'email');
3034: if (ref($emailrules) eq 'HASH') {
3035: if (keys(%{$emailrules}) > 0) {
3036: $datatable .= &user_formats_row('email',$settings,$emailrules,
3037: $emailruleorder,$numinrow,$rowcount);
3038: $$rowtotal ++;
3039: $rowcount ++;
3040: }
3041: }
1.39 raeburn 3042: if ($rowcount == 0) {
3043: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3044: $$rowtotal ++;
3045: $rowcount ++;
3046: }
1.34 raeburn 3047: } elsif ($position eq 'middle') {
1.100 raeburn 3048: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3049: my ($rules,$ruleorder) =
3050: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3051: my %lt = &usercreation_types();
3052: my %checked;
1.50 raeburn 3053: my @selfcreate;
1.34 raeburn 3054: if (ref($settings) eq 'HASH') {
3055: if (ref($settings->{'cancreate'}) eq 'HASH') {
3056: foreach my $item (@creators) {
3057: $checked{$item} = $settings->{'cancreate'}{$item};
3058: }
1.50 raeburn 3059: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3060: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3061: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3062: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3063: @selfcreate = ('email','login','sso');
3064: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3065: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3066: }
3067: }
1.34 raeburn 3068: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3069: foreach my $item (@creators) {
3070: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3071: $checked{$item} = 'none';
3072: }
3073: }
3074: }
3075: }
3076: my $rownum = 0;
3077: foreach my $item (@creators) {
3078: $rownum ++;
1.50 raeburn 3079: if ($item ne 'selfcreate') {
3080: if ($checked{$item} eq '') {
1.43 raeburn 3081: $checked{$item} = 'any';
3082: }
1.34 raeburn 3083: }
3084: my $css_class;
3085: if ($rownum%2) {
3086: $css_class = '';
3087: } else {
3088: $css_class = ' class="LC_odd_row" ';
3089: }
3090: $datatable .= '<tr'.$css_class.'>'.
3091: '<td><span class="LC_nobreak">'.$lt{$item}.
3092: '</span></td><td align="right">';
1.50 raeburn 3093: my @options;
1.45 raeburn 3094: if ($item eq 'selfcreate') {
1.43 raeburn 3095: push(@options,('email','login','sso'));
3096: } else {
1.50 raeburn 3097: @options = ('any');
1.43 raeburn 3098: if (ref($rules) eq 'HASH') {
3099: if (keys(%{$rules}) > 0) {
3100: push(@options,('official','unofficial'));
3101: }
1.37 raeburn 3102: }
1.50 raeburn 3103: push(@options,'none');
1.37 raeburn 3104: }
3105: foreach my $option (@options) {
1.50 raeburn 3106: my $type = 'radio';
1.34 raeburn 3107: my $check = ' ';
1.50 raeburn 3108: if ($item eq 'selfcreate') {
3109: $type = 'checkbox';
3110: if (grep(/^\Q$option\E$/,@selfcreate)) {
3111: $check = ' checked="checked" ';
3112: }
3113: } else {
3114: if ($checked{$item} eq $option) {
3115: $check = ' checked="checked" ';
3116: }
1.34 raeburn 3117: }
3118: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3119: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3120: $item.'" value="'.$option.'"'.$check.'/> '.
3121: $lt{$option}.'</label> </span>';
3122: }
3123: $datatable .= '</td></tr>';
3124: }
1.93 raeburn 3125: my ($othertitle,$usertypes,$types) =
3126: &Apache::loncommon::sorted_inst_types($dom);
3127: if (ref($usertypes) eq 'HASH') {
3128: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3129: my $createsettings;
3130: if (ref($settings) eq 'HASH') {
3131: $createsettings = $settings->{cancreate};
3132: }
3133: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3134: $dom,$numinrow,$othertitle,
3135: 'statustocreate');
3136: $$rowtotal ++;
3137: }
3138: }
1.28 raeburn 3139: } else {
3140: my @contexts = ('author','course','domain');
3141: my @authtypes = ('int','krb4','krb5','loc');
3142: my %checked;
3143: if (ref($settings) eq 'HASH') {
3144: if (ref($settings->{'authtypes'}) eq 'HASH') {
3145: foreach my $item (@contexts) {
3146: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3147: foreach my $auth (@authtypes) {
3148: if ($settings->{'authtypes'}{$item}{$auth}) {
3149: $checked{$item}{$auth} = ' checked="checked" ';
3150: }
3151: }
3152: }
3153: }
1.27 raeburn 3154: }
1.35 raeburn 3155: } else {
3156: foreach my $item (@contexts) {
1.36 raeburn 3157: foreach my $auth (@authtypes) {
1.35 raeburn 3158: $checked{$item}{$auth} = ' checked="checked" ';
3159: }
3160: }
1.27 raeburn 3161: }
1.28 raeburn 3162: my %title = &context_names();
3163: my %authname = &authtype_names();
3164: my $rownum = 0;
3165: my $css_class;
3166: foreach my $item (@contexts) {
3167: if ($rownum%2) {
3168: $css_class = '';
3169: } else {
3170: $css_class = ' class="LC_odd_row" ';
3171: }
1.30 raeburn 3172: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3173: '<td>'.$title{$item}.
3174: '</td><td class="LC_left_item">'.
3175: '<span class="LC_nobreak">';
3176: foreach my $auth (@authtypes) {
3177: $datatable .= '<label>'.
3178: '<input type="checkbox" name="'.$item.'_auth" '.
3179: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3180: $authname{$auth}.'</label> ';
3181: }
3182: $datatable .= '</span></td></tr>';
3183: $rownum ++;
1.27 raeburn 3184: }
1.30 raeburn 3185: $$rowtotal += $rownum;
1.27 raeburn 3186: }
3187: return $datatable;
3188: }
3189:
1.32 raeburn 3190: sub user_formats_row {
3191: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3192: my $output;
3193: my %text = (
3194: 'username' => 'new usernames',
3195: 'id' => 'IDs',
1.45 raeburn 3196: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3197: );
3198: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3199: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3200: '<td><span class="LC_nobreak">';
3201: if ($type eq 'email') {
3202: $output .= &mt("Formats disallowed for $text{$type}: ");
3203: } else {
3204: $output .= &mt("Format rules to check for $text{$type}: ");
3205: }
3206: $output .= '</span></td>'.
3207: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3208: my $rem;
3209: if (ref($ruleorder) eq 'ARRAY') {
3210: for (my $i=0; $i<@{$ruleorder}; $i++) {
3211: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3212: my $rem = $i%($numinrow);
3213: if ($rem == 0) {
3214: if ($i > 0) {
3215: $output .= '</tr>';
3216: }
3217: $output .= '<tr>';
3218: }
3219: my $check = ' ';
1.39 raeburn 3220: if (ref($settings) eq 'HASH') {
3221: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3222: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3223: $check = ' checked="checked" ';
3224: }
1.27 raeburn 3225: }
3226: }
3227: $output .= '<td class="LC_left_item">'.
3228: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3229: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3230: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3231: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3232: }
3233: }
3234: $rem = @{$ruleorder}%($numinrow);
3235: }
3236: my $colsleft = $numinrow - $rem;
3237: if ($colsleft > 1 ) {
3238: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3239: ' </td>';
3240: } elsif ($colsleft == 1) {
3241: $output .= '<td class="LC_left_item"> </td>';
3242: }
3243: $output .= '</tr></table></td></tr>';
3244: return $output;
3245: }
3246:
1.34 raeburn 3247: sub usercreation_types {
3248: my %lt = &Apache::lonlocal::texthash (
3249: author => 'When adding a co-author',
3250: course => 'When adding a user to a course',
1.100 raeburn 3251: requestcrs => 'When requesting a course',
1.45 raeburn 3252: selfcreate => 'User creates own account',
1.34 raeburn 3253: any => 'Any',
3254: official => 'Institutional only ',
3255: unofficial => 'Non-institutional only',
1.85 schafran 3256: email => 'E-mail address',
1.43 raeburn 3257: login => 'Institutional Login',
3258: sso => 'SSO',
1.34 raeburn 3259: none => 'None',
3260: );
3261: return %lt;
1.48 raeburn 3262: }
1.34 raeburn 3263:
1.28 raeburn 3264: sub authtype_names {
3265: my %lt = &Apache::lonlocal::texthash(
3266: int => 'Internal',
3267: krb4 => 'Kerberos 4',
3268: krb5 => 'Kerberos 5',
3269: loc => 'Local',
3270: );
3271: return %lt;
3272: }
3273:
3274: sub context_names {
3275: my %context_title = &Apache::lonlocal::texthash(
3276: author => 'Creating users when an Author',
3277: course => 'Creating users when in a course',
3278: domain => 'Creating users when a Domain Coordinator',
3279: );
3280: return %context_title;
3281: }
3282:
1.33 raeburn 3283: sub print_usermodification {
3284: my ($position,$dom,$settings,$rowtotal) = @_;
3285: my $numinrow = 4;
3286: my ($context,$datatable,$rowcount);
3287: if ($position eq 'top') {
3288: $rowcount = 0;
3289: $context = 'author';
3290: foreach my $role ('ca','aa') {
3291: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3292: $numinrow,$rowcount);
3293: $$rowtotal ++;
3294: $rowcount ++;
3295: }
1.63 raeburn 3296: } elsif ($position eq 'middle') {
1.33 raeburn 3297: $context = 'course';
3298: $rowcount = 0;
3299: foreach my $role ('st','ep','ta','in','cr') {
3300: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3301: $numinrow,$rowcount);
3302: $$rowtotal ++;
3303: $rowcount ++;
3304: }
1.63 raeburn 3305: } elsif ($position eq 'bottom') {
3306: $context = 'selfcreate';
3307: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3308: $usertypes->{'default'} = $othertitle;
3309: if (ref($types) eq 'ARRAY') {
3310: push(@{$types},'default');
3311: $usertypes->{'default'} = $othertitle;
3312: foreach my $status (@{$types}) {
3313: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3314: $numinrow,$rowcount,$usertypes);
3315: $$rowtotal ++;
3316: $rowcount ++;
3317: }
3318: }
1.33 raeburn 3319: }
3320: return $datatable;
3321: }
3322:
1.43 raeburn 3323: sub print_defaults {
3324: my ($dom,$rowtotal) = @_;
1.68 raeburn 3325: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3326: 'datelocale_def','portal_def');
1.43 raeburn 3327: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3328: my $titles = &defaults_titles($dom);
1.43 raeburn 3329: my $rownum = 0;
3330: my ($datatable,$css_class);
3331: foreach my $item (@items) {
3332: if ($rownum%2) {
3333: $css_class = '';
3334: } else {
3335: $css_class = ' class="LC_odd_row" ';
3336: }
3337: $datatable .= '<tr'.$css_class.'>'.
3338: '<td><span class="LC_nobreak">'.$titles->{$item}.
3339: '</span></td><td class="LC_right_item">';
3340: if ($item eq 'auth_def') {
3341: my @authtypes = ('internal','krb4','krb5','localauth');
3342: my %shortauth = (
3343: internal => 'int',
3344: krb4 => 'krb4',
3345: krb5 => 'krb5',
3346: localauth => 'loc'
3347: );
3348: my %authnames = &authtype_names();
3349: foreach my $auth (@authtypes) {
3350: my $checked = ' ';
3351: if ($domdefaults{$item} eq $auth) {
3352: $checked = ' checked="checked" ';
3353: }
3354: $datatable .= '<label><input type="radio" name="'.$item.
3355: '" value="'.$auth.'"'.$checked.'/>'.
3356: $authnames{$shortauth{$auth}}.'</label> ';
3357: }
1.54 raeburn 3358: } elsif ($item eq 'timezone_def') {
3359: my $includeempty = 1;
3360: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3361: } elsif ($item eq 'datelocale_def') {
3362: my $includeempty = 1;
3363: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 3364: } else {
1.141 raeburn 3365: my $size;
3366: if ($item eq 'portal_def') {
3367: $size = ' size="25"';
3368: }
1.43 raeburn 3369: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3370: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3371: }
3372: $datatable .= '</td></tr>';
3373: $rownum ++;
3374: }
3375: $$rowtotal += $rownum;
3376: return $datatable;
3377: }
3378:
3379: sub defaults_titles {
1.141 raeburn 3380: my ($dom) = @_;
1.43 raeburn 3381: my %titles = &Apache::lonlocal::texthash (
3382: 'auth_def' => 'Default authentication type',
3383: 'auth_arg_def' => 'Default authentication argument',
3384: 'lang_def' => 'Default language',
1.54 raeburn 3385: 'timezone_def' => 'Default timezone',
1.68 raeburn 3386: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3387: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3388: );
1.141 raeburn 3389: if ($dom) {
3390: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3391: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3392: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3393: $protocol = 'http' if ($protocol ne 'https');
3394: if ($uint_dom) {
3395: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3396: $uint_dom);
3397: }
3398: }
1.43 raeburn 3399: return (\%titles);
3400: }
3401:
1.46 raeburn 3402: sub print_scantronformat {
3403: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3404: my $itemcount = 1;
1.60 raeburn 3405: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3406: %confhash);
1.46 raeburn 3407: my $switchserver = &check_switchserver($dom,$confname);
3408: my %lt = &Apache::lonlocal::texthash (
1.95 www 3409: default => 'Default bubblesheet format file error',
3410: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3411: );
3412: my %scantronfiles = (
3413: default => 'default.tab',
3414: custom => 'custom.tab',
3415: );
3416: foreach my $key (keys(%scantronfiles)) {
3417: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3418: .$scantronfiles{$key};
3419: }
3420: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3421: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3422: if (!$switchserver) {
3423: my $servadm = $r->dir_config('lonAdmEMail');
3424: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3425: if ($configuserok eq 'ok') {
3426: if ($author_ok eq 'ok') {
3427: my %legacyfile = (
3428: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3429: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3430: );
3431: my %md5chk;
3432: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3433: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3434: chomp($md5chk{$type});
1.46 raeburn 3435: }
3436: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3437: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3438: ($scantronurls{$type},my $error) =
1.46 raeburn 3439: &legacy_scantronformat($r,$dom,$confname,
3440: $type,$legacyfile{$type},
3441: $scantronurls{$type},
3442: $scantronfiles{$type});
1.60 raeburn 3443: if ($error ne '') {
3444: $error{$type} = $error;
3445: }
3446: }
3447: if (keys(%error) == 0) {
3448: $is_custom = 1;
3449: $confhash{'scantron'}{'scantronformat'} =
3450: $scantronurls{'custom'};
3451: my $putresult =
3452: &Apache::lonnet::put_dom('configuration',
3453: \%confhash,$dom);
3454: if ($putresult ne 'ok') {
3455: $error{'custom'} =
3456: '<span class="LC_error">'.
3457: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3458: }
1.46 raeburn 3459: }
3460: } else {
1.60 raeburn 3461: ($scantronurls{'default'},my $error) =
1.46 raeburn 3462: &legacy_scantronformat($r,$dom,$confname,
3463: 'default',$legacyfile{'default'},
3464: $scantronurls{'default'},
3465: $scantronfiles{'default'});
1.60 raeburn 3466: if ($error eq '') {
3467: $confhash{'scantron'}{'scantronformat'} = '';
3468: my $putresult =
3469: &Apache::lonnet::put_dom('configuration',
3470: \%confhash,$dom);
3471: if ($putresult ne 'ok') {
3472: $error{'default'} =
3473: '<span class="LC_error">'.
3474: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3475: }
3476: } else {
3477: $error{'default'} = $error;
3478: }
1.46 raeburn 3479: }
3480: }
3481: }
3482: } else {
1.95 www 3483: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3484: }
3485: }
3486: if (ref($settings) eq 'HASH') {
3487: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3488: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3489: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3490: $scantronurl = '';
3491: } else {
3492: $scantronurl = $settings->{'scantronformat'};
3493: }
3494: $is_custom = 1;
3495: } else {
3496: $scantronurl = $scantronurls{'default'};
3497: }
3498: } else {
1.60 raeburn 3499: if ($is_custom) {
3500: $scantronurl = $scantronurls{'custom'};
3501: } else {
3502: $scantronurl = $scantronurls{'default'};
3503: }
1.46 raeburn 3504: }
3505: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3506: $datatable .= '<tr'.$css_class.'>';
3507: if (!$is_custom) {
1.65 raeburn 3508: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3509: '<span class="LC_nobreak">';
1.46 raeburn 3510: if ($scantronurl) {
3511: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3512: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3513: } else {
3514: $datatable = &mt('File unavailable for display');
3515: }
1.65 raeburn 3516: $datatable .= '</span></td>';
1.60 raeburn 3517: if (keys(%error) == 0) {
3518: $datatable .= '<td valign="bottom">';
3519: if (!$switchserver) {
3520: $datatable .= &mt('Upload:').'<br />';
3521: }
3522: } else {
3523: my $errorstr;
3524: foreach my $key (sort(keys(%error))) {
3525: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3526: }
3527: $datatable .= '<td>'.$errorstr;
3528: }
1.46 raeburn 3529: } else {
3530: if (keys(%error) > 0) {
3531: my $errorstr;
3532: foreach my $key (sort(keys(%error))) {
3533: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3534: }
1.60 raeburn 3535: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3536: } elsif ($scantronurl) {
1.65 raeburn 3537: $datatable .= '<td><span class="LC_nobreak">'.
3538: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3539: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3540: '<input type="checkbox" name="scantronformat_del"'.
3541: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3542: '<td><span class="LC_nobreak"> '.
3543: &mt('Replace:').'</span><br />';
1.46 raeburn 3544: }
3545: }
3546: if (keys(%error) == 0) {
3547: if ($switchserver) {
3548: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3549: } else {
1.65 raeburn 3550: $datatable .='<span class="LC_nobreak"> '.
3551: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3552: }
3553: }
3554: $datatable .= '</td></tr>';
3555: $$rowtotal ++;
3556: return $datatable;
3557: }
3558:
3559: sub legacy_scantronformat {
3560: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3561: my ($url,$error);
3562: my @statinfo = &Apache::lonnet::stat_file($newurl);
3563: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3564: (my $result,$url) =
3565: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3566: '','',$newfile);
3567: if ($result ne 'ok') {
1.130 raeburn 3568: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3569: }
3570: }
3571: return ($url,$error);
3572: }
1.43 raeburn 3573:
1.49 raeburn 3574: sub print_coursecategories {
1.57 raeburn 3575: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3576: my $datatable;
3577: if ($position eq 'top') {
3578: my $toggle_cats_crs = ' ';
3579: my $toggle_cats_dom = ' checked="checked" ';
3580: my $can_cat_crs = ' ';
3581: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3582: my $toggle_catscomm_comm = ' ';
3583: my $toggle_catscomm_dom = ' checked="checked" ';
3584: my $can_catcomm_comm = ' ';
3585: my $can_catcomm_dom = ' checked="checked" ';
3586:
1.57 raeburn 3587: if (ref($settings) eq 'HASH') {
3588: if ($settings->{'togglecats'} eq 'crs') {
3589: $toggle_cats_crs = $toggle_cats_dom;
3590: $toggle_cats_dom = ' ';
3591: }
3592: if ($settings->{'categorize'} eq 'crs') {
3593: $can_cat_crs = $can_cat_dom;
3594: $can_cat_dom = ' ';
3595: }
1.120 raeburn 3596: if ($settings->{'togglecatscomm'} eq 'comm') {
3597: $toggle_catscomm_comm = $toggle_catscomm_dom;
3598: $toggle_catscomm_dom = ' ';
3599: }
3600: if ($settings->{'categorizecomm'} eq 'comm') {
3601: $can_catcomm_comm = $can_catcomm_dom;
3602: $can_catcomm_dom = ' ';
3603: }
1.57 raeburn 3604: }
3605: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3606: togglecats => 'Show/Hide a course in catalog',
3607: togglecatscomm => 'Show/Hide a community in catalog',
3608: categorize => 'Assign a category to a course',
3609: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3610: );
3611: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3612: dom => 'Set in Domain',
3613: crs => 'Set in Course',
3614: comm => 'Set in Community',
1.57 raeburn 3615: );
3616: $datatable = '<tr class="LC_odd_row">'.
3617: '<td>'.$title{'togglecats'}.'</td>'.
3618: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3619: '<input type="radio" name="togglecats"'.
3620: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3621: '<label><input type="radio" name="togglecats"'.
3622: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3623: '</tr><tr>'.
3624: '<td>'.$title{'categorize'}.'</td>'.
3625: '<td class="LC_right_item"><span class="LC_nobreak">'.
3626: '<label><input type="radio" name="categorize"'.
3627: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3628: '<label><input type="radio" name="categorize"'.
3629: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3630: '</tr><tr class="LC_odd_row">'.
3631: '<td>'.$title{'togglecatscomm'}.'</td>'.
3632: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3633: '<input type="radio" name="togglecatscomm"'.
3634: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3635: '<label><input type="radio" name="togglecatscomm"'.
3636: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3637: '</tr><tr>'.
3638: '<td>'.$title{'categorizecomm'}.'</td>'.
3639: '<td class="LC_right_item"><span class="LC_nobreak">'.
3640: '<label><input type="radio" name="categorizecomm"'.
3641: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3642: '<label><input type="radio" name="categorizecomm"'.
3643: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3644: '</tr>';
1.120 raeburn 3645: $$rowtotal += 4;
1.57 raeburn 3646: } else {
3647: my $css_class;
3648: my $itemcount = 1;
3649: my $cathash;
3650: if (ref($settings) eq 'HASH') {
3651: $cathash = $settings->{'cats'};
3652: }
3653: if (ref($cathash) eq 'HASH') {
3654: my (@cats,@trails,%allitems,%idx,@jsarray);
3655: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3656: \%allitems,\%idx,\@jsarray);
3657: my $maxdepth = scalar(@cats);
3658: my $colattrib = '';
3659: if ($maxdepth > 2) {
3660: $colattrib = ' colspan="2" ';
3661: }
3662: my @path;
3663: if (@cats > 0) {
3664: if (ref($cats[0]) eq 'ARRAY') {
3665: my $numtop = @{$cats[0]};
3666: my $maxnum = $numtop;
1.120 raeburn 3667: my %default_names = (
3668: instcode => &mt('Official courses'),
3669: communities => &mt('Communities'),
3670: );
3671:
3672: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3673: ($cathash->{'instcode::0'} eq '') ||
3674: (!grep(/^communities$/,@{$cats[0]})) ||
3675: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3676: $maxnum ++;
3677: }
3678: my $lastidx;
3679: for (my $i=0; $i<$numtop; $i++) {
3680: my $parent = $cats[0][$i];
3681: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3682: my $item = &escape($parent).'::0';
3683: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3684: $lastidx = $idx{$item};
3685: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3686: .'<select name="'.$item.'"'.$chgstr.'>';
3687: for (my $k=0; $k<=$maxnum; $k++) {
3688: my $vpos = $k+1;
3689: my $selstr;
3690: if ($k == $i) {
3691: $selstr = ' selected="selected" ';
3692: }
3693: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3694: }
3695: $datatable .= '</select></td><td>';
1.120 raeburn 3696: if ($parent eq 'instcode' || $parent eq 'communities') {
3697: $datatable .= '<span class="LC_nobreak">'
3698: .$default_names{$parent}.'</span>';
3699: if ($parent eq 'instcode') {
3700: $datatable .= '<br /><span class="LC_nobreak">('
3701: .&mt('with institutional codes')
3702: .')</span></td><td'.$colattrib.'>';
3703: } else {
3704: $datatable .= '<table><tr><td>';
3705: }
3706: $datatable .= '<span class="LC_nobreak">'
3707: .'<label><input type="radio" name="'
3708: .$parent.'" value="1" checked="checked" />'
3709: .&mt('Display').'</label>';
3710: if ($parent eq 'instcode') {
3711: $datatable .= ' ';
3712: } else {
3713: $datatable .= '</span></td></tr><tr><td>'
3714: .'<span class="LC_nobreak">';
3715: }
3716: $datatable .= '<label><input type="radio" name="'
3717: .$parent.'" value="0" />'
3718: .&mt('Do not display').'</label></span>';
3719: if ($parent eq 'communities') {
3720: $datatable .= '</td></tr></table>';
3721: }
3722: $datatable .= '</td>';
1.57 raeburn 3723: } else {
3724: $datatable .= $parent
3725: .' <label><input type="checkbox" name="deletecategory" '
3726: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3727: }
3728: my $depth = 1;
3729: push(@path,$parent);
3730: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3731: pop(@path);
3732: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3733: $itemcount ++;
3734: }
1.48 raeburn 3735: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3736: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3737: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3738: for (my $k=0; $k<=$maxnum; $k++) {
3739: my $vpos = $k+1;
3740: my $selstr;
1.57 raeburn 3741: if ($k == $numtop) {
1.48 raeburn 3742: $selstr = ' selected="selected" ';
3743: }
3744: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3745: }
1.59 bisitz 3746: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3747: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3748: .'</tr>'."\n";
1.48 raeburn 3749: $itemcount ++;
1.120 raeburn 3750: foreach my $default ('instcode','communities') {
3751: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3752: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3753: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3754: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3755: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3756: for (my $k=0; $k<=$maxnum; $k++) {
3757: my $vpos = $k+1;
3758: my $selstr;
3759: if ($k == $maxnum) {
3760: $selstr = ' selected="selected" ';
3761: }
3762: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3763: }
1.120 raeburn 3764: $datatable .= '</select></span></td>'.
3765: '<td><span class="LC_nobreak">'.
3766: $default_names{$default}.'</span>';
3767: if ($default eq 'instcode') {
3768: $datatable .= '<br /><span class="LC_nobreak">('
3769: .&mt('with institutional codes').')</span>';
3770: }
3771: $datatable .= '</td>'
3772: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3773: .&mt('Display').'</label> '
3774: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3775: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3776: }
3777: }
3778: }
1.57 raeburn 3779: } else {
3780: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3781: }
3782: } else {
1.57 raeburn 3783: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3784: .&initialize_categories($itemcount);
1.48 raeburn 3785: }
1.57 raeburn 3786: $$rowtotal += $itemcount;
1.48 raeburn 3787: }
3788: return $datatable;
3789: }
3790:
1.69 raeburn 3791: sub print_serverstatuses {
3792: my ($dom,$settings,$rowtotal) = @_;
3793: my $datatable;
3794: my @pages = &serverstatus_pages();
3795: my (%namedaccess,%machineaccess);
3796: foreach my $type (@pages) {
3797: $namedaccess{$type} = '';
3798: $machineaccess{$type}= '';
3799: }
3800: if (ref($settings) eq 'HASH') {
3801: foreach my $type (@pages) {
3802: if (exists($settings->{$type})) {
3803: if (ref($settings->{$type}) eq 'HASH') {
3804: foreach my $key (keys(%{$settings->{$type}})) {
3805: if ($key eq 'namedusers') {
3806: $namedaccess{$type} = $settings->{$type}->{$key};
3807: } elsif ($key eq 'machines') {
3808: $machineaccess{$type} = $settings->{$type}->{$key};
3809: }
3810: }
3811: }
3812: }
3813: }
3814: }
1.81 raeburn 3815: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3816: my $rownum = 0;
3817: my $css_class;
3818: foreach my $type (@pages) {
3819: $rownum ++;
3820: $css_class = $rownum%2?' class="LC_odd_row"':'';
3821: $datatable .= '<tr'.$css_class.'>'.
3822: '<td><span class="LC_nobreak">'.
3823: $titles->{$type}.'</span></td>'.
3824: '<td class="LC_left_item">'.
3825: '<input type="text" name="'.$type.'_namedusers" '.
3826: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3827: '<td class="LC_right_item">'.
3828: '<span class="LC_nobreak">'.
3829: '<input type="text" name="'.$type.'_machines" '.
3830: 'value="'.$machineaccess{$type}.'" size="10" />'.
3831: '</td></tr>'."\n";
3832: }
3833: $$rowtotal += $rownum;
3834: return $datatable;
3835: }
3836:
3837: sub serverstatus_pages {
3838: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3839: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 3840: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 3841: }
3842:
1.49 raeburn 3843: sub coursecategories_javascript {
3844: my ($settings) = @_;
1.57 raeburn 3845: my ($output,$jstext,$cathash);
1.49 raeburn 3846: if (ref($settings) eq 'HASH') {
1.57 raeburn 3847: $cathash = $settings->{'cats'};
3848: }
3849: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3850: my (@cats,@jsarray,%idx);
1.57 raeburn 3851: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3852: if (@jsarray > 0) {
3853: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3854: for (my $i=0; $i<@jsarray; $i++) {
3855: if (ref($jsarray[$i]) eq 'ARRAY') {
3856: my $catstr = join('","',@{$jsarray[$i]});
3857: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3858: }
3859: }
3860: }
3861: } else {
3862: $jstext = ' var categories = Array(1);'."\n".
3863: ' categories[0] = Array("instcode_pos");'."\n";
3864: }
1.120 raeburn 3865: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3866: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3867: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3868: $output = <<"ENDSCRIPT";
3869: <script type="text/javascript">
1.109 raeburn 3870: // <![CDATA[
1.49 raeburn 3871: function reorderCats(form,parent,item,idx) {
3872: var changedVal;
3873: $jstext
3874: var newpos = 'addcategory_pos';
3875: var current = new Array;
3876: if (parent == '') {
3877: var has_instcode = 0;
3878: var maxtop = categories[idx].length;
3879: for (var j=0; j<maxtop; j++) {
3880: if (categories[idx][j] == 'instcode::0') {
3881: has_instcode == 1;
3882: }
3883: }
3884: if (has_instcode == 0) {
3885: categories[idx][maxtop] = 'instcode_pos';
3886: }
3887: } else {
3888: newpos += '_'+parent;
3889: }
3890: var maxh = 1 + categories[idx].length;
3891: var current = new Array;
3892: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3893: if (item == newpos) {
3894: changedVal = newitemVal;
3895: } else {
3896: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3897: current[newitemVal] = newpos;
3898: }
3899: for (var i=0; i<categories[idx].length; i++) {
3900: var elementName = categories[idx][i];
3901: if (elementName != item) {
3902: if (form.elements[elementName]) {
3903: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3904: current[currVal] = elementName;
3905: }
3906: }
3907: }
3908: var oldVal;
3909: for (var j=0; j<maxh; j++) {
3910: if (current[j] == undefined) {
3911: oldVal = j;
3912: }
3913: }
3914: if (oldVal < changedVal) {
3915: for (var k=oldVal+1; k<=changedVal ; k++) {
3916: var elementName = current[k];
3917: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3918: }
3919: } else {
3920: for (var k=changedVal; k<oldVal; k++) {
3921: var elementName = current[k];
3922: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3923: }
3924: }
3925: return;
3926: }
1.120 raeburn 3927:
3928: function categoryCheck(form) {
3929: if (form.elements['addcategory_name'].value == 'instcode') {
3930: alert('$instcode_reserved\\n$choose_again');
3931: return false;
3932: }
3933: if (form.elements['addcategory_name'].value == 'communities') {
3934: alert('$communities_reserved\\n$choose_again');
3935: return false;
3936: }
3937: return true;
3938: }
3939:
1.109 raeburn 3940: // ]]>
1.49 raeburn 3941: </script>
3942:
3943: ENDSCRIPT
3944: return $output;
3945: }
3946:
1.48 raeburn 3947: sub initialize_categories {
3948: my ($itemcount) = @_;
1.120 raeburn 3949: my ($datatable,$css_class,$chgstr);
3950: my %default_names = (
3951: instcode => 'Official courses (with institutional codes)',
3952: communities => 'Communities',
3953: );
3954: my $select0 = ' selected="selected"';
3955: my $select1 = '';
3956: foreach my $default ('instcode','communities') {
3957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3958: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3959: if ($default eq 'communities') {
3960: $select1 = $select0;
3961: $select0 = '';
3962: }
3963: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3964: .'<select name="'.$default.'_pos">'
3965: .'<option value="0"'.$select0.'>1</option>'
3966: .'<option value="1"'.$select1.'>2</option>'
3967: .'<option value="2">3</option></select> '
3968: .$default_names{$default}
3969: .'</span></td><td><span class="LC_nobreak">'
3970: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3971: .&mt('Display').'</label> <label>'
3972: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 3973: .'</label></span></td></tr>';
1.120 raeburn 3974: $itemcount ++;
3975: }
1.48 raeburn 3976: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 3977: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 3978: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 3979: .'<select name="addcategory_pos"'.$chgstr.'>'
3980: .'<option value="0">1</option>'
3981: .'<option value="1">2</option>'
3982: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 3983: .&mt('Add category').'</td><td>'.&mt('Name:')
3984: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
3985: return $datatable;
3986: }
3987:
3988: sub build_category_rows {
1.49 raeburn 3989: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
3990: my ($text,$name,$item,$chgstr);
1.48 raeburn 3991: if (ref($cats) eq 'ARRAY') {
3992: my $maxdepth = scalar(@{$cats});
3993: if (ref($cats->[$depth]) eq 'HASH') {
3994: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
3995: my $numchildren = @{$cats->[$depth]{$parent}};
3996: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3997: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 3998: my ($idxnum,$parent_name,$parent_item);
3999: my $higher = $depth - 1;
4000: if ($higher == 0) {
4001: $parent_name = &escape($parent).'::'.$higher;
4002: } else {
4003: if (ref($path) eq 'ARRAY') {
4004: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4005: }
4006: }
4007: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4008: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4009: if ($j < $numchildren) {
1.48 raeburn 4010: $name = $cats->[$depth]{$parent}[$j];
4011: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4012: $idxnum = $idx->{$item};
4013: } else {
4014: $name = $parent_name;
4015: $item = $parent_item;
1.48 raeburn 4016: }
1.49 raeburn 4017: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4018: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4019: for (my $i=0; $i<=$numchildren; $i++) {
4020: my $vpos = $i+1;
4021: my $selstr;
4022: if ($j == $i) {
4023: $selstr = ' selected="selected" ';
4024: }
4025: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4026: }
4027: $text .= '</select> ';
4028: if ($j < $numchildren) {
4029: my $deeper = $depth+1;
4030: $text .= $name.' '
4031: .'<label><input type="checkbox" name="deletecategory" value="'
4032: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4033: if(ref($path) eq 'ARRAY') {
4034: push(@{$path},$name);
1.49 raeburn 4035: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4036: pop(@{$path});
4037: }
4038: } else {
1.59 bisitz 4039: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4040: if ($j == $numchildren) {
4041: $text .= $name;
4042: } else {
4043: $text .= $item;
4044: }
4045: $text .= '" value="" />';
4046: }
4047: $text .= '</td></tr>';
4048: }
4049: $text .= '</table></td>';
4050: } else {
4051: my $higher = $depth-1;
4052: if ($higher == 0) {
4053: $name = &escape($parent).'::'.$higher;
4054: } else {
4055: if (ref($path) eq 'ARRAY') {
4056: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4057: }
4058: }
4059: my $colspan;
4060: if ($parent ne 'instcode') {
4061: $colspan = $maxdepth - $depth - 1;
4062: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4063: }
4064: }
4065: }
4066: }
4067: return $text;
4068: }
4069:
1.33 raeburn 4070: sub modifiable_userdata_row {
1.63 raeburn 4071: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4072: my $rolename;
1.63 raeburn 4073: if ($context eq 'selfcreate') {
4074: if (ref($usertypes) eq 'HASH') {
4075: $rolename = $usertypes->{$role};
4076: } else {
4077: $rolename = $role;
4078: }
1.33 raeburn 4079: } else {
1.63 raeburn 4080: if ($role eq 'cr') {
4081: $rolename = &mt('Custom role');
4082: } else {
4083: $rolename = &Apache::lonnet::plaintext($role);
4084: }
1.33 raeburn 4085: }
4086: my @fields = ('lastname','firstname','middlename','generation',
4087: 'permanentemail','id');
4088: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4089: my $output;
4090: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4091: $output = '<tr '.$css_class.'>'.
4092: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4093: '<td class="LC_left_item" colspan="2"><table>';
4094: my $rem;
4095: my %checks;
4096: if (ref($settings) eq 'HASH') {
4097: if (ref($settings->{$context}) eq 'HASH') {
4098: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4099: foreach my $field (@fields) {
4100: if ($settings->{$context}->{$role}->{$field}) {
4101: $checks{$field} = ' checked="checked" ';
4102: }
4103: }
4104: }
4105: }
4106: }
4107: for (my $i=0; $i<@fields; $i++) {
4108: my $rem = $i%($numinrow);
4109: if ($rem == 0) {
4110: if ($i > 0) {
4111: $output .= '</tr>';
4112: }
4113: $output .= '<tr>';
4114: }
4115: my $check = ' ';
4116: if (exists($checks{$fields[$i]})) {
4117: $check = $checks{$fields[$i]}
4118: } else {
4119: if ($role eq 'st') {
4120: if (ref($settings) ne 'HASH') {
4121: $check = ' checked="checked" ';
4122: }
4123: }
4124: }
4125: $output .= '<td class="LC_left_item">'.
4126: '<span class="LC_nobreak"><label>'.
4127: '<input type="checkbox" name="canmodify_'.$role.'" '.
4128: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4129: '</label></span></td>';
4130: $rem = @fields%($numinrow);
4131: }
4132: my $colsleft = $numinrow - $rem;
4133: if ($colsleft > 1 ) {
4134: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4135: ' </td>';
4136: } elsif ($colsleft == 1) {
4137: $output .= '<td class="LC_left_item"> </td>';
4138: }
4139: $output .= '</tr></table></td></tr>';
4140: return $output;
4141: }
1.28 raeburn 4142:
1.93 raeburn 4143: sub insttypes_row {
4144: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4145: my %lt = &Apache::lonlocal::texthash (
4146: cansearch => 'Users allowed to search',
4147: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4148: lockablenames => 'User preference to lock name',
1.93 raeburn 4149: );
4150: my $showdom;
4151: if ($context eq 'cansearch') {
4152: $showdom = ' ('.$dom.')';
4153: }
1.25 raeburn 4154: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4155: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 4156: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 4157: my $rem;
4158: if (ref($types) eq 'ARRAY') {
4159: for (my $i=0; $i<@{$types}; $i++) {
4160: if (defined($usertypes->{$types->[$i]})) {
4161: my $rem = $i%($numinrow);
4162: if ($rem == 0) {
4163: if ($i > 0) {
4164: $output .= '</tr>';
4165: }
4166: $output .= '<tr>';
1.23 raeburn 4167: }
1.26 raeburn 4168: my $check = ' ';
1.99 raeburn 4169: if (ref($settings) eq 'HASH') {
4170: if (ref($settings->{$context}) eq 'ARRAY') {
4171: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4172: $check = ' checked="checked" ';
4173: }
4174: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4175: $check = ' checked="checked" ';
4176: }
1.23 raeburn 4177: }
1.26 raeburn 4178: $output .= '<td class="LC_left_item">'.
4179: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4180: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4181: 'value="'.$types->[$i].'"'.$check.'/>'.
4182: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4183: }
4184: }
1.26 raeburn 4185: $rem = @{$types}%($numinrow);
1.23 raeburn 4186: }
4187: my $colsleft = $numinrow - $rem;
1.131 raeburn 4188: if (($rem == 0) && (@{$types} > 0)) {
4189: $output .= '<tr>';
4190: }
1.23 raeburn 4191: if ($colsleft > 1) {
1.25 raeburn 4192: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4193: } else {
1.25 raeburn 4194: $output .= '<td class="LC_left_item">';
1.23 raeburn 4195: }
4196: my $defcheck = ' ';
1.99 raeburn 4197: if (ref($settings) eq 'HASH') {
4198: if (ref($settings->{$context}) eq 'ARRAY') {
4199: if (grep(/^default$/,@{$settings->{$context}})) {
4200: $defcheck = ' checked="checked" ';
4201: }
4202: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4203: $defcheck = ' checked="checked" ';
4204: }
1.23 raeburn 4205: }
1.25 raeburn 4206: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4207: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4208: 'value="default"'.$defcheck.'/>'.
4209: $othertitle.'</label></span></td>'.
4210: '</tr></table></td></tr>';
4211: return $output;
1.23 raeburn 4212: }
4213:
4214: sub sorted_searchtitles {
4215: my %searchtitles = &Apache::lonlocal::texthash(
4216: 'uname' => 'username',
4217: 'lastname' => 'last name',
4218: 'lastfirst' => 'last name, first name',
4219: );
4220: my @titleorder = ('uname','lastname','lastfirst');
4221: return (\%searchtitles,\@titleorder);
4222: }
4223:
1.25 raeburn 4224: sub sorted_searchtypes {
4225: my %srchtypes_desc = (
4226: exact => 'is exact match',
4227: contains => 'contains ..',
4228: begins => 'begins with ..',
4229: );
4230: my @srchtypeorder = ('exact','begins','contains');
4231: return (\%srchtypes_desc,\@srchtypeorder);
4232: }
4233:
1.3 raeburn 4234: sub usertype_update_row {
4235: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4236: my $datatable;
4237: my $numinrow = 4;
4238: foreach my $type (@{$types}) {
4239: if (defined($usertypes->{$type})) {
4240: $$rownums ++;
4241: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4242: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4243: '</td><td class="LC_left_item"><table>';
4244: for (my $i=0; $i<@{$fields}; $i++) {
4245: my $rem = $i%($numinrow);
4246: if ($rem == 0) {
4247: if ($i > 0) {
4248: $datatable .= '</tr>';
4249: }
4250: $datatable .= '<tr>';
4251: }
4252: my $check = ' ';
1.39 raeburn 4253: if (ref($settings) eq 'HASH') {
4254: if (ref($settings->{'fields'}) eq 'HASH') {
4255: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4256: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4257: $check = ' checked="checked" ';
4258: }
1.3 raeburn 4259: }
4260: }
4261: }
4262:
4263: if ($i == @{$fields}-1) {
4264: my $colsleft = $numinrow - $rem;
4265: if ($colsleft > 1) {
4266: $datatable .= '<td colspan="'.$colsleft.'">';
4267: } else {
4268: $datatable .= '<td>';
4269: }
4270: } else {
4271: $datatable .= '<td>';
4272: }
1.8 raeburn 4273: $datatable .= '<span class="LC_nobreak"><label>'.
4274: '<input type="checkbox" name="updateable_'.$type.
4275: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4276: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4277: }
4278: $datatable .= '</tr></table></td></tr>';
4279: }
4280: }
4281: return $datatable;
1.1 raeburn 4282: }
4283:
4284: sub modify_login {
1.9 raeburn 4285: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 4286: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 4287: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 4288: adminmail => 'Display administrator E-mail address',
1.43 raeburn 4289: newuser => 'Link for visitors to create a user account',
1.41 raeburn 4290: loginheader => 'Log-in box header');
1.3 raeburn 4291: my @offon = ('off','on');
1.112 raeburn 4292: my %curr_loginvia;
4293: if (ref($domconfig{login}) eq 'HASH') {
4294: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4295: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4296: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4297: }
4298: }
4299: }
1.6 raeburn 4300: my %loginhash;
1.9 raeburn 4301: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4302: \%domconfig,\%loginhash);
1.118 jms 4303: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4304: foreach my $item (@toggles) {
4305: $loginhash{login}{$item} = $env{'form.'.$item};
4306: }
1.41 raeburn 4307: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4308: if (ref($colchanges{'login'}) eq 'HASH') {
4309: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4310: \%loginhash);
4311: }
1.110 raeburn 4312:
1.149 raeburn 4313: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4314: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4315: if (keys(%servers) > 1) {
4316: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4317: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4318: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4319: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4320: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4321: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4322: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4323: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4324: $changes{'loginvia'}{$lonhost} = 1;
4325: } else {
4326: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4327: $changes{'loginvia'}{$lonhost} = 1;
4328: }
4329: } else {
4330: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4331: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4332: $changes{'loginvia'}{$lonhost} = 1;
4333: }
4334: }
4335: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4336: foreach my $item (@loginvia_attribs) {
4337: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4338: }
4339: } else {
4340: foreach my $item (@loginvia_attribs) {
4341: my $new = $env{'form.'.$lonhost.'_'.$item};
4342: if (($item eq 'serverpath') && ($new eq 'custom')) {
4343: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4344: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4345: $new = '/';
4346: }
4347: }
4348: if (($item eq 'custompath') &&
4349: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4350: $new = '';
4351: }
4352: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4353: $changes{'loginvia'}{$lonhost} = 1;
4354: }
4355: if ($item eq 'exempt') {
4356: $new =~ s/^\s+//;
4357: $new =~ s/\s+$//;
4358: my @poss_ips = split(/\s*[,:]\s*/,$new);
4359: my @okips;
4360: foreach my $ip (@poss_ips) {
4361: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4362: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4363: push(@okips,$ip);
4364: }
4365: }
4366: }
4367: if (@okips > 0) {
4368: $new = join(',',@okips);
4369: } else {
4370: $new = '';
4371: }
4372: }
4373:
4374: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4375: }
4376: }
1.112 raeburn 4377: } else {
1.128 raeburn 4378: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4379: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4380: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4381: foreach my $item (@loginvia_attribs) {
4382: my $new = $env{'form.'.$lonhost.'_'.$item};
4383: if (($item eq 'serverpath') && ($new eq 'custom')) {
4384: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4385: $new = '/';
4386: }
4387: }
4388: if (($item eq 'custompath') &&
4389: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4390: $new = '';
4391: }
4392: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4393: }
1.110 raeburn 4394: }
4395: }
4396: }
4397: }
1.119 raeburn 4398:
1.1 raeburn 4399: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4400: $dom);
4401: if ($putresult eq 'ok') {
1.118 jms 4402: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4403: my %defaultchecked = (
4404: 'coursecatalog' => 'on',
4405: 'adminmail' => 'off',
1.43 raeburn 4406: 'newuser' => 'off',
1.42 raeburn 4407: );
1.55 raeburn 4408: if (ref($domconfig{'login'}) eq 'HASH') {
4409: foreach my $item (@toggles) {
4410: if ($defaultchecked{$item} eq 'on') {
4411: if (($domconfig{'login'}{$item} eq '0') &&
4412: ($env{'form.'.$item} eq '1')) {
4413: $changes{$item} = 1;
4414: } elsif (($domconfig{'login'}{$item} eq '' ||
4415: $domconfig{'login'}{$item} eq '1') &&
4416: ($env{'form.'.$item} eq '0')) {
4417: $changes{$item} = 1;
4418: }
4419: } elsif ($defaultchecked{$item} eq 'off') {
4420: if (($domconfig{'login'}{$item} eq '1') &&
4421: ($env{'form.'.$item} eq '0')) {
4422: $changes{$item} = 1;
4423: } elsif (($domconfig{'login'}{$item} eq '' ||
4424: $domconfig{'login'}{$item} eq '0') &&
4425: ($env{'form.'.$item} eq '1')) {
4426: $changes{$item} = 1;
4427: }
1.42 raeburn 4428: }
4429: }
1.41 raeburn 4430: }
1.6 raeburn 4431: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4432: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4433: $resulttext = &mt('Changes made:').'<ul>';
4434: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4435: if ($item eq 'loginvia') {
1.112 raeburn 4436: if (ref($changes{$item}) eq 'HASH') {
4437: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4438: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4439: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4440: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4441: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4442: $protocol = 'http' if ($protocol ne 'https');
4443: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4444:
4445: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4446: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4447: } else {
4448: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4449: }
4450: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4451: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4452: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4453: }
4454: $resulttext .= '</li>';
4455: } else {
4456: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4457: }
1.112 raeburn 4458: } else {
1.128 raeburn 4459: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4460: }
4461: }
1.128 raeburn 4462: $resulttext .= '</ul></li>';
1.112 raeburn 4463: }
1.41 raeburn 4464: } else {
4465: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4466: }
1.1 raeburn 4467: }
1.6 raeburn 4468: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4469: } else {
4470: $resulttext = &mt('No changes made to log-in page settings');
4471: }
4472: } else {
1.11 albertel 4473: $resulttext = '<span class="LC_error">'.
4474: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4475: }
1.6 raeburn 4476: if ($errors) {
1.9 raeburn 4477: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4478: $errors.'</ul>';
4479: }
4480: return $resulttext;
4481: }
4482:
4483: sub color_font_choices {
4484: my %choices =
4485: &Apache::lonlocal::texthash (
4486: img => "Header",
4487: bgs => "Background colors",
4488: links => "Link colors",
1.55 raeburn 4489: images => "Images",
1.6 raeburn 4490: font => "Font color",
1.97 tempelho 4491: fontmenu => "Font Menu",
1.76 raeburn 4492: pgbg => "Page",
1.6 raeburn 4493: tabbg => "Header",
4494: sidebg => "Border",
4495: link => "Link",
4496: alink => "Active link",
4497: vlink => "Visited link",
4498: );
4499: return %choices;
4500: }
4501:
4502: sub modify_rolecolors {
1.9 raeburn 4503: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4504: my ($resulttext,%rolehash);
4505: $rolehash{'rolecolors'} = {};
1.55 raeburn 4506: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4507: if ($domconfig{'rolecolors'} eq '') {
4508: $domconfig{'rolecolors'} = {};
4509: }
4510: }
1.9 raeburn 4511: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4512: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4513: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4514: $dom);
4515: if ($putresult eq 'ok') {
4516: if (keys(%changes) > 0) {
1.41 raeburn 4517: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4518: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4519: $rolehash{'rolecolors'});
4520: } else {
4521: $resulttext = &mt('No changes made to default color schemes');
4522: }
4523: } else {
1.11 albertel 4524: $resulttext = '<span class="LC_error">'.
4525: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4526: }
4527: if ($errors) {
4528: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4529: $errors.'</ul>';
4530: }
4531: return $resulttext;
4532: }
4533:
4534: sub modify_colors {
1.9 raeburn 4535: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4536: my (%changes,%choices);
1.51 raeburn 4537: my @bgs;
1.6 raeburn 4538: my @links = ('link','alink','vlink');
1.41 raeburn 4539: my @logintext;
1.6 raeburn 4540: my @images;
4541: my $servadm = $r->dir_config('lonAdmEMail');
4542: my $errors;
4543: foreach my $role (@{$roles}) {
4544: if ($role eq 'login') {
1.12 raeburn 4545: %choices = &login_choices();
1.41 raeburn 4546: @logintext = ('textcol','bgcol');
1.12 raeburn 4547: } else {
4548: %choices = &color_font_choices();
1.107 raeburn 4549: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4550: }
4551: if ($role eq 'login') {
1.41 raeburn 4552: @images = ('img','logo','domlogo','login');
1.51 raeburn 4553: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4554: } else {
4555: @images = ('img');
1.51 raeburn 4556: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4557: }
4558: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4559: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4560: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4561: }
1.46 raeburn 4562: my ($configuserok,$author_ok,$switchserver) =
4563: &config_check($dom,$confname,$servadm);
1.9 raeburn 4564: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4565: if (ref($domconfig->{$role}) ne 'HASH') {
4566: $domconfig->{$role} = {};
4567: }
1.8 raeburn 4568: foreach my $img (@images) {
1.70 raeburn 4569: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4570: if (defined($env{'form.login_showlogo_'.$img})) {
4571: $confhash->{$role}{'showlogo'}{$img} = 1;
4572: } else {
4573: $confhash->{$role}{'showlogo'}{$img} = 0;
4574: }
4575: }
1.18 albertel 4576: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4577: && !defined($domconfig->{$role}{$img})
4578: && !$env{'form.'.$role.'_del_'.$img}
4579: && $env{'form.'.$role.'_import_'.$img}) {
4580: # import the old configured image from the .tab setting
4581: # if they haven't provided a new one
4582: $domconfig->{$role}{$img} =
4583: $env{'form.'.$role.'_import_'.$img};
4584: }
1.6 raeburn 4585: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4586: my $error;
1.6 raeburn 4587: if ($configuserok eq 'ok') {
1.9 raeburn 4588: if ($switchserver) {
1.12 raeburn 4589: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4590: } else {
4591: if ($author_ok eq 'ok') {
4592: my ($result,$logourl) =
4593: &publishlogo($r,'upload',$role.'_'.$img,
4594: $dom,$confname,$img,$width,$height);
4595: if ($result eq 'ok') {
4596: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4597: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4598: } else {
1.12 raeburn 4599: $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 4600: }
4601: } else {
1.46 raeburn 4602: $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 4603: }
4604: }
4605: } else {
1.46 raeburn 4606: $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 4607: }
4608: if ($error) {
1.8 raeburn 4609: &Apache::lonnet::logthis($error);
1.11 albertel 4610: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4611: }
4612: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4613: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4614: my $error;
4615: if ($configuserok eq 'ok') {
4616: # is confname an author?
4617: if ($switchserver eq '') {
4618: if ($author_ok eq 'ok') {
4619: my ($result,$logourl) =
4620: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4621: $dom,$confname,$img,$width,$height);
4622: if ($result eq 'ok') {
4623: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4624: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4625: }
4626: }
4627: }
4628: }
1.6 raeburn 4629: }
4630: }
4631: }
4632: if (ref($domconfig) eq 'HASH') {
4633: if (ref($domconfig->{$role}) eq 'HASH') {
4634: foreach my $img (@images) {
4635: if ($domconfig->{$role}{$img} ne '') {
4636: if ($env{'form.'.$role.'_del_'.$img}) {
4637: $confhash->{$role}{$img} = '';
1.12 raeburn 4638: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4639: } else {
1.9 raeburn 4640: if ($confhash->{$role}{$img} eq '') {
4641: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4642: }
1.6 raeburn 4643: }
4644: } else {
4645: if ($env{'form.'.$role.'_del_'.$img}) {
4646: $confhash->{$role}{$img} = '';
1.12 raeburn 4647: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4648: }
4649: }
1.70 raeburn 4650: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4651: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4652: if ($confhash->{$role}{'showlogo'}{$img} ne
4653: $domconfig->{$role}{'showlogo'}{$img}) {
4654: $changes{$role}{'showlogo'}{$img} = 1;
4655: }
4656: } else {
4657: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4658: $changes{$role}{'showlogo'}{$img} = 1;
4659: }
4660: }
4661: }
4662: }
1.6 raeburn 4663: if ($domconfig->{$role}{'font'} ne '') {
4664: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4665: $changes{$role}{'font'} = 1;
4666: }
4667: } else {
4668: if ($confhash->{$role}{'font'}) {
4669: $changes{$role}{'font'} = 1;
4670: }
4671: }
1.107 raeburn 4672: if ($role ne 'login') {
4673: if ($domconfig->{$role}{'fontmenu'} ne '') {
4674: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4675: $changes{$role}{'fontmenu'} = 1;
4676: }
4677: } else {
4678: if ($confhash->{$role}{'fontmenu'}) {
4679: $changes{$role}{'fontmenu'} = 1;
4680: }
1.97 tempelho 4681: }
4682: }
1.6 raeburn 4683: foreach my $item (@bgs) {
4684: if ($domconfig->{$role}{$item} ne '') {
4685: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4686: $changes{$role}{'bgs'}{$item} = 1;
4687: }
4688: } else {
4689: if ($confhash->{$role}{$item}) {
4690: $changes{$role}{'bgs'}{$item} = 1;
4691: }
4692: }
4693: }
4694: foreach my $item (@links) {
4695: if ($domconfig->{$role}{$item} ne '') {
4696: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4697: $changes{$role}{'links'}{$item} = 1;
4698: }
4699: } else {
4700: if ($confhash->{$role}{$item}) {
4701: $changes{$role}{'links'}{$item} = 1;
4702: }
4703: }
4704: }
1.41 raeburn 4705: foreach my $item (@logintext) {
4706: if ($domconfig->{$role}{$item} ne '') {
4707: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4708: $changes{$role}{'logintext'}{$item} = 1;
4709: }
4710: } else {
4711: if ($confhash->{$role}{$item}) {
4712: $changes{$role}{'logintext'}{$item} = 1;
4713: }
4714: }
4715: }
1.6 raeburn 4716: } else {
4717: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4718: \@logintext,$confhash,\%changes);
1.6 raeburn 4719: }
4720: } else {
4721: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4722: \@logintext,$confhash,\%changes);
1.6 raeburn 4723: }
4724: }
4725: return ($errors,%changes);
4726: }
4727:
1.46 raeburn 4728: sub config_check {
4729: my ($dom,$confname,$servadm) = @_;
4730: my ($configuserok,$author_ok,$switchserver,%currroles);
4731: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4732: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4733: $confname,$servadm);
4734: if ($configuserok eq 'ok') {
4735: $switchserver = &check_switchserver($dom,$confname);
4736: if ($switchserver eq '') {
4737: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4738: }
4739: }
4740: return ($configuserok,$author_ok,$switchserver);
4741: }
4742:
1.6 raeburn 4743: sub default_change_checker {
1.41 raeburn 4744: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4745: foreach my $item (@{$links}) {
4746: if ($confhash->{$role}{$item}) {
4747: $changes->{$role}{'links'}{$item} = 1;
4748: }
4749: }
4750: foreach my $item (@{$bgs}) {
4751: if ($confhash->{$role}{$item}) {
4752: $changes->{$role}{'bgs'}{$item} = 1;
4753: }
4754: }
1.41 raeburn 4755: foreach my $item (@{$logintext}) {
4756: if ($confhash->{$role}{$item}) {
4757: $changes->{$role}{'logintext'}{$item} = 1;
4758: }
4759: }
1.6 raeburn 4760: foreach my $img (@{$images}) {
4761: if ($env{'form.'.$role.'_del_'.$img}) {
4762: $confhash->{$role}{$img} = '';
1.12 raeburn 4763: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4764: }
1.70 raeburn 4765: if ($role eq 'login') {
4766: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4767: $changes->{$role}{'showlogo'}{$img} = 1;
4768: }
4769: }
1.6 raeburn 4770: }
4771: if ($confhash->{$role}{'font'}) {
4772: $changes->{$role}{'font'} = 1;
4773: }
1.48 raeburn 4774: }
1.6 raeburn 4775:
4776: sub display_colorchgs {
4777: my ($dom,$changes,$roles,$confhash) = @_;
4778: my (%choices,$resulttext);
4779: if (!grep(/^login$/,@{$roles})) {
4780: $resulttext = &mt('Changes made:').'<br />';
4781: }
4782: foreach my $role (@{$roles}) {
4783: if ($role eq 'login') {
4784: %choices = &login_choices();
4785: } else {
4786: %choices = &color_font_choices();
4787: }
4788: if (ref($changes->{$role}) eq 'HASH') {
4789: if ($role ne 'login') {
4790: $resulttext .= '<h4>'.&mt($role).'</h4>';
4791: }
4792: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4793: if ($role ne 'login') {
4794: $resulttext .= '<ul>';
4795: }
4796: if (ref($changes->{$role}{$key}) eq 'HASH') {
4797: if ($role ne 'login') {
4798: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4799: }
4800: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4801: if (($role eq 'login') && ($key eq 'showlogo')) {
4802: if ($confhash->{$role}{$key}{$item}) {
4803: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4804: } else {
4805: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4806: }
4807: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4808: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4809: } else {
1.12 raeburn 4810: my $newitem = $confhash->{$role}{$item};
4811: if ($key eq 'images') {
4812: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4813: }
4814: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4815: }
4816: }
4817: if ($role ne 'login') {
4818: $resulttext .= '</ul></li>';
4819: }
4820: } else {
4821: if ($confhash->{$role}{$key} eq '') {
4822: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4823: } else {
4824: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4825: }
4826: }
4827: if ($role ne 'login') {
4828: $resulttext .= '</ul>';
4829: }
4830: }
4831: }
4832: }
1.3 raeburn 4833: return $resulttext;
1.1 raeburn 4834: }
4835:
1.9 raeburn 4836: sub thumb_dimensions {
4837: return ('200','50');
4838: }
4839:
1.16 raeburn 4840: sub check_dimensions {
4841: my ($inputfile) = @_;
4842: my ($fullwidth,$fullheight);
4843: if ($inputfile =~ m|^[/\w.\-]+$|) {
4844: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4845: my $imageinfo = <PIPE>;
4846: if (!close(PIPE)) {
4847: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4848: }
4849: chomp($imageinfo);
4850: my ($fullsize) =
1.21 raeburn 4851: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4852: if ($fullsize) {
4853: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4854: }
4855: }
4856: }
4857: return ($fullwidth,$fullheight);
4858: }
4859:
1.9 raeburn 4860: sub check_configuser {
4861: my ($uhome,$dom,$confname,$servadm) = @_;
4862: my ($configuserok,%currroles);
4863: if ($uhome eq 'no_host') {
4864: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4865: my $configpass = &LONCAPA::Enrollment::create_password();
4866: $configuserok =
4867: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4868: $configpass,'','','','','',undef,$servadm);
4869: } else {
4870: $configuserok = 'ok';
4871: %currroles =
4872: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4873: }
4874: return ($configuserok,%currroles);
4875: }
4876:
4877: sub check_authorstatus {
4878: my ($dom,$confname,%currroles) = @_;
4879: my $author_ok;
1.40 raeburn 4880: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4881: my $start = time;
4882: my $end = 0;
4883: $author_ok =
4884: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4885: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4886: } else {
4887: $author_ok = 'ok';
4888: }
4889: return $author_ok;
4890: }
4891:
4892: sub publishlogo {
1.46 raeburn 4893: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4894: my ($output,$fname,$logourl);
4895: if ($action eq 'upload') {
4896: $fname=$env{'form.'.$formname.'.filename'};
4897: chop($env{'form.'.$formname});
4898: } else {
4899: ($fname) = ($formname =~ /([^\/]+)$/);
4900: }
1.46 raeburn 4901: if ($savefileas ne '') {
4902: $fname = $savefileas;
4903: }
1.9 raeburn 4904: $fname=&Apache::lonnet::clean_filename($fname);
4905: # See if there is anything left
4906: unless ($fname) { return ('error: no uploaded file'); }
4907: $fname="$subdir/$fname";
1.158 raeburn 4908: my $filepath=$r->dir_config('lonDocRoot')."/priv/$dom/$confname";
1.9 raeburn 4909: my ($fnamepath,$file,$fetchthumb);
4910: $file=$fname;
4911: if ($fname=~m|/|) {
4912: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4913: }
4914: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4915: my $count;
4916: for ($count=4;$count<=$#parts;$count++) {
4917: $filepath.="/$parts[$count]";
4918: if ((-e $filepath)!=1) {
4919: mkdir($filepath,02770);
4920: }
4921: }
4922: # Check for bad extension and disallow upload
4923: if ($file=~/\.(\w+)$/ &&
4924: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4925: $output =
4926: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4927: } elsif ($file=~/\.(\w+)$/ &&
4928: !defined(&Apache::loncommon::fileembstyle($1))) {
4929: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4930: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4931: $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 4932: } elsif (-d "$filepath/$file") {
4933: $output = &mt('File name is a directory name - rename the file and re-upload');
4934: } else {
4935: my $source = $filepath.'/'.$file;
4936: my $logfile;
4937: if (!open($logfile,">>$source".'.log')) {
4938: return (&mt('No write permission to Construction Space'));
4939: }
4940: print $logfile
4941: "\n================= Publish ".localtime()." ================\n".
4942: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4943: # Save the file
4944: if (!open(FH,'>'.$source)) {
4945: &Apache::lonnet::logthis('Failed to create '.$source);
4946: return (&mt('Failed to create file'));
4947: }
4948: if ($action eq 'upload') {
4949: if (!print FH ($env{'form.'.$formname})) {
4950: &Apache::lonnet::logthis('Failed to write to '.$source);
4951: return (&mt('Failed to write file'));
4952: }
4953: } else {
4954: my $original = &Apache::lonnet::filelocation('',$formname);
4955: if(!copy($original,$source)) {
4956: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4957: return (&mt('Failed to write file'));
4958: }
4959: }
4960: close(FH);
4961: chmod(0660, $source); # Permissions to rw-rw---.
4962:
4963: my $docroot=$r->dir_config('lonDocRoot');
4964: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4965: my $copyfile=$targetdir.'/'.$file;
4966:
4967: my @parts=split(/\//,$targetdir);
4968: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4969: for (my $count=5;$count<=$#parts;$count++) {
4970: $path.="/$parts[$count]";
4971: if (!-e $path) {
4972: print $logfile "\nCreating directory ".$path;
4973: mkdir($path,02770);
4974: }
4975: }
4976: my $versionresult;
4977: if (-e $copyfile) {
4978: $versionresult = &logo_versioning($targetdir,$file,$logfile);
4979: } else {
4980: $versionresult = 'ok';
4981: }
4982: if ($versionresult eq 'ok') {
4983: if (copy($source,$copyfile)) {
4984: print $logfile "\nCopied original source to ".$copyfile."\n";
4985: $output = 'ok';
4986: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 4987: push(@{$modified_urls},[$copyfile,$source]);
4988: my $metaoutput =
4989: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
4990: unless ($registered_cleanup) {
4991: my $handlers = $r->get_handlers('PerlCleanupHandler');
4992: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
4993: $registered_cleanup=1;
4994: }
1.9 raeburn 4995: } else {
4996: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
4997: $output = &mt('Failed to copy file to RES space').", $!";
4998: }
4999: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5000: my $inputfile = $filepath.'/'.$file;
5001: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5002: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5003: if ($fullwidth ne '' && $fullheight ne '') {
5004: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5005: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5006: system("convert -sample $thumbsize $inputfile $outfile");
5007: chmod(0660, $filepath.'/tn-'.$file);
5008: if (-e $outfile) {
5009: my $copyfile=$targetdir.'/tn-'.$file;
5010: if (copy($outfile,$copyfile)) {
5011: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5012: my $thumb_metaoutput =
5013: &write_metadata($dom,$confname,$formname,
5014: $targetdir,'tn-'.$file,$logfile);
5015: push(@{$modified_urls},[$copyfile,$outfile]);
5016: unless ($registered_cleanup) {
5017: my $handlers = $r->get_handlers('PerlCleanupHandler');
5018: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5019: $registered_cleanup=1;
5020: }
1.16 raeburn 5021: } else {
5022: print $logfile "\nUnable to write ".$copyfile.
5023: ':'.$!."\n";
5024: }
5025: }
1.9 raeburn 5026: }
5027: }
5028: }
5029: } else {
5030: $output = $versionresult;
5031: }
5032: }
5033: return ($output,$logourl);
5034: }
5035:
5036: sub logo_versioning {
5037: my ($targetdir,$file,$logfile) = @_;
5038: my $target = $targetdir.'/'.$file;
5039: my ($maxversion,$fn,$extn,$output);
5040: $maxversion = 0;
5041: if ($file =~ /^(.+)\.(\w+)$/) {
5042: $fn=$1;
5043: $extn=$2;
5044: }
5045: opendir(DIR,$targetdir);
5046: while (my $filename=readdir(DIR)) {
5047: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5048: $maxversion=($1>$maxversion)?$1:$maxversion;
5049: }
5050: }
5051: $maxversion++;
5052: print $logfile "\nCreating old version ".$maxversion."\n";
5053: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5054: if (copy($target,$copyfile)) {
5055: print $logfile "Copied old target to ".$copyfile."\n";
5056: $copyfile=$copyfile.'.meta';
5057: if (copy($target.'.meta',$copyfile)) {
5058: print $logfile "Copied old target metadata to ".$copyfile."\n";
5059: $output = 'ok';
5060: } else {
5061: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5062: $output = &mt('Failed to copy old meta').", $!, ";
5063: }
5064: } else {
5065: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5066: $output = &mt('Failed to copy old target').", $!, ";
5067: }
5068: return $output;
5069: }
5070:
5071: sub write_metadata {
5072: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5073: my (%metadatafields,%metadatakeys,$output);
5074: $metadatafields{'title'}=$formname;
5075: $metadatafields{'creationdate'}=time;
5076: $metadatafields{'lastrevisiondate'}=time;
5077: $metadatafields{'copyright'}='public';
5078: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5079: $env{'user.domain'};
5080: $metadatafields{'authorspace'}=$confname.':'.$dom;
5081: $metadatafields{'domain'}=$dom;
5082: {
5083: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5084: my $mfh;
1.155 raeburn 5085: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5086: foreach (sort keys %metadatafields) {
5087: unless ($_=~/\./) {
5088: my $unikey=$_;
5089: $unikey=~/^([A-Za-z]+)/;
5090: my $tag=$1;
5091: $tag=~tr/A-Z/a-z/;
5092: print $mfh "\n\<$tag";
5093: foreach (split(/\,/,$metadatakeys{$unikey})) {
5094: my $value=$metadatafields{$unikey.'.'.$_};
5095: $value=~s/\"/\'\'/g;
5096: print $mfh ' '.$_.'="'.$value.'"';
5097: }
5098: print $mfh '>'.
5099: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5100: .'</'.$tag.'>';
5101: }
5102: }
5103: $output = 'ok';
5104: print $logfile "\nWrote metadata";
5105: close($mfh);
5106: } else {
5107: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5108: $output = &mt('Could not write metadata');
5109: }
5110: }
1.155 raeburn 5111: return $output;
5112: }
5113:
5114: sub notifysubscribed {
5115: foreach my $targetsource (@{$modified_urls}){
5116: next unless (ref($targetsource) eq 'ARRAY');
5117: my ($target,$source)=@{$targetsource};
5118: if ($source ne '') {
5119: if (open(my $logfh,'>>'.$source.'.log')) {
5120: print $logfh "\nCleanup phase: Notifications\n";
5121: my @subscribed=&subscribed_hosts($target);
5122: foreach my $subhost (@subscribed) {
5123: print $logfh "\nNotifying host ".$subhost.':';
5124: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5125: print $logfh $reply;
5126: }
5127: my @subscribedmeta=&subscribed_hosts("$target.meta");
5128: foreach my $subhost (@subscribedmeta) {
5129: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5130: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5131: $subhost);
5132: print $logfh $reply;
5133: }
5134: print $logfh "\n============ Done ============\n";
1.160 raeburn 5135: close($logfh);
1.155 raeburn 5136: }
5137: }
5138: }
5139: return OK;
5140: }
5141:
5142: sub subscribed_hosts {
5143: my ($target) = @_;
5144: my @subscribed;
5145: if (open(my $fh,"<$target.subscription")) {
5146: while (my $subline=<$fh>) {
5147: if ($subline =~ /^($match_lonid):/) {
5148: my $host = $1;
5149: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5150: unless (grep(/^\Q$host\E$/,@subscribed)) {
5151: push(@subscribed,$host);
5152: }
5153: }
5154: }
5155: }
5156: }
5157: return @subscribed;
1.9 raeburn 5158: }
5159:
5160: sub check_switchserver {
5161: my ($dom,$confname) = @_;
5162: my ($allowed,$switchserver);
5163: my $home = &Apache::lonnet::homeserver($confname,$dom);
5164: if ($home eq 'no_host') {
5165: $home = &Apache::lonnet::domain($dom,'primary');
5166: }
5167: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5168: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5169: if (!$allowed) {
5170: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5171: }
5172: return $switchserver;
5173: }
5174:
1.1 raeburn 5175: sub modify_quotas {
1.86 raeburn 5176: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5177: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5178: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5179: if ($action eq 'quotas') {
5180: $context = 'tools';
5181: } else {
5182: $context = $action;
5183: }
5184: if ($context eq 'requestcourses') {
1.98 raeburn 5185: @usertools = ('official','unofficial','community');
1.106 raeburn 5186: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5187: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5188: %titles = &courserequest_titles();
5189: $toolregexp = join('|',@usertools);
5190: %conditions = &courserequest_conditions();
1.86 raeburn 5191: } else {
5192: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 5193: %titles = &tool_titles();
1.86 raeburn 5194: }
1.72 raeburn 5195: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5196: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5197: foreach my $key (keys(%env)) {
1.101 raeburn 5198: if ($context eq 'requestcourses') {
5199: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5200: my $item = $1;
5201: my $type = $2;
5202: if ($type =~ /^limit_(.+)/) {
5203: $limithash{$item}{$1} = $env{$key};
5204: } else {
5205: $confhash{$item}{$type} = $env{$key};
5206: }
5207: }
5208: } else {
1.86 raeburn 5209: if ($key =~ /^form\.quota_(.+)$/) {
5210: $confhash{'defaultquota'}{$1} = $env{$key};
5211: }
1.101 raeburn 5212: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5213: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5214: }
1.72 raeburn 5215: }
5216: }
1.102 raeburn 5217: if ($context eq 'requestcourses') {
5218: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5219: @approvalnotify = sort(@approvalnotify);
5220: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5221: if (ref($domconfig{$action}) eq 'HASH') {
5222: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5223: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5224: $changes{'notify'}{'approval'} = 1;
5225: }
5226: } else {
1.144 raeburn 5227: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5228: $changes{'notify'}{'approval'} = 1;
5229: }
5230: }
5231: } else {
1.144 raeburn 5232: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5233: $changes{'notify'}{'approval'} = 1;
5234: }
5235: }
5236: } else {
1.86 raeburn 5237: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5238: }
1.72 raeburn 5239: foreach my $item (@usertools) {
5240: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5241: my $unset;
1.101 raeburn 5242: if ($context eq 'requestcourses') {
1.104 raeburn 5243: $unset = '0';
5244: if ($type eq '_LC_adv') {
5245: $unset = '';
5246: }
1.101 raeburn 5247: if ($confhash{$item}{$type} eq 'autolimit') {
5248: $confhash{$item}{$type} .= '=';
5249: unless ($limithash{$item}{$type} =~ /\D/) {
5250: $confhash{$item}{$type} .= $limithash{$item}{$type};
5251: }
5252: }
1.72 raeburn 5253: } else {
1.101 raeburn 5254: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5255: $confhash{$item}{$type} = 1;
5256: } else {
5257: $confhash{$item}{$type} = 0;
5258: }
1.72 raeburn 5259: }
1.86 raeburn 5260: if (ref($domconfig{$action}) eq 'HASH') {
5261: if (ref($domconfig{$action}{$item}) eq 'HASH') {
5262: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5263: $changes{$item}{$type} = 1;
5264: }
5265: } else {
5266: if ($context eq 'requestcourses') {
1.104 raeburn 5267: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5268: $changes{$item}{$type} = 1;
5269: }
5270: } else {
5271: if (!$confhash{$item}{$type}) {
5272: $changes{$item}{$type} = 1;
5273: }
5274: }
5275: }
5276: } else {
5277: if ($context eq 'requestcourses') {
1.104 raeburn 5278: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5279: $changes{$item}{$type} = 1;
5280: }
5281: } else {
5282: if (!$confhash{$item}{$type}) {
5283: $changes{$item}{$type} = 1;
5284: }
5285: }
5286: }
1.1 raeburn 5287: }
5288: }
1.86 raeburn 5289: unless ($context eq 'requestcourses') {
5290: if (ref($domconfig{'quotas'}) eq 'HASH') {
5291: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5292: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5293: if (exists($confhash{'defaultquota'}{$key})) {
5294: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5295: $changes{'defaultquota'}{$key} = 1;
5296: }
5297: } else {
5298: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5299: }
5300: }
1.86 raeburn 5301: } else {
5302: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5303: if (exists($confhash{'defaultquota'}{$key})) {
5304: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5305: $changes{'defaultquota'}{$key} = 1;
5306: }
5307: } else {
5308: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5309: }
1.1 raeburn 5310: }
5311: }
5312: }
1.86 raeburn 5313: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5314: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5315: if (ref($domconfig{'quotas'}) eq 'HASH') {
5316: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5317: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5318: $changes{'defaultquota'}{$key} = 1;
5319: }
5320: } else {
5321: if (!exists($domconfig{'quotas'}{$key})) {
5322: $changes{'defaultquota'}{$key} = 1;
5323: }
1.72 raeburn 5324: }
5325: } else {
1.86 raeburn 5326: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5327: }
1.1 raeburn 5328: }
5329: }
5330: }
1.72 raeburn 5331:
5332: foreach my $key (keys(%confhash)) {
5333: $domdefaults{$key} = $confhash{$key};
5334: }
5335:
1.1 raeburn 5336: my %quotahash = (
1.86 raeburn 5337: $action => { %confhash }
1.1 raeburn 5338: );
5339: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5340: $dom);
5341: if ($putresult eq 'ok') {
5342: if (keys(%changes) > 0) {
1.72 raeburn 5343: my $cachetime = 24*60*60;
5344: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5345:
1.1 raeburn 5346: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 5347: unless ($context eq 'requestcourses') {
5348: if (ref($changes{'defaultquota'}) eq 'HASH') {
5349: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5350: foreach my $type (@{$types},'default') {
5351: if (defined($changes{'defaultquota'}{$type})) {
5352: my $typetitle = $usertypes->{$type};
5353: if ($type eq 'default') {
5354: $typetitle = $othertitle;
5355: }
5356: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5357: }
5358: }
1.86 raeburn 5359: $resulttext .= '</ul></li>';
1.72 raeburn 5360: }
5361: }
1.80 raeburn 5362: my %newenv;
1.72 raeburn 5363: foreach my $item (@usertools) {
5364: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 5365: my $newacc =
5366: &Apache::lonnet::usertools_access($env{'user.name'},
5367: $env{'user.domain'},
1.86 raeburn 5368: $item,'reload',$context);
5369: if ($context eq 'requestcourses') {
1.108 raeburn 5370: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5371: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5372: }
5373: } else {
5374: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5375: $newenv{'environment.availabletools.'.$item} = $newacc;
5376: }
1.80 raeburn 5377: }
1.72 raeburn 5378: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5379: foreach my $type (@{$types},'default','_LC_adv') {
5380: if ($changes{$item}{$type}) {
5381: my $typetitle = $usertypes->{$type};
5382: if ($type eq 'default') {
5383: $typetitle = $othertitle;
5384: } elsif ($type eq '_LC_adv') {
5385: $typetitle = 'LON-CAPA Advanced Users';
5386: }
5387: if ($confhash{$item}{$type}) {
1.101 raeburn 5388: if ($context eq 'requestcourses') {
5389: my $cond;
5390: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
5391: if ($1 eq '') {
5392: $cond = &mt('(Automatic processing of any request).');
5393: } else {
5394: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5395: }
5396: } else {
5397: $cond = $conditions{$confhash{$item}{$type}};
5398: }
5399: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5400: } else {
5401: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5402: }
1.72 raeburn 5403: } else {
1.104 raeburn 5404: if ($type eq '_LC_adv') {
5405: if ($confhash{$item}{$type} eq '0') {
5406: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5407: } else {
5408: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5409: }
5410: } else {
5411: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5412: }
1.72 raeburn 5413: }
5414: }
1.26 raeburn 5415: }
1.72 raeburn 5416: $resulttext .= '</ul></li>';
1.26 raeburn 5417: }
1.1 raeburn 5418: }
1.102 raeburn 5419: if ($action eq 'requestcourses') {
5420: if (ref($changes{'notify'}) eq 'HASH') {
5421: if ($changes{'notify'}{'approval'}) {
5422: if (ref($confhash{'notify'}) eq 'HASH') {
5423: if ($confhash{'notify'}{'approval'}) {
5424: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5425: } else {
5426: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
5427: }
5428: }
5429: }
5430: }
5431: }
1.1 raeburn 5432: $resulttext .= '</ul>';
1.80 raeburn 5433: if (keys(%newenv)) {
5434: &Apache::lonnet::appenv(\%newenv);
5435: }
1.1 raeburn 5436: } else {
1.86 raeburn 5437: if ($context eq 'requestcourses') {
5438: $resulttext = &mt('No changes made to rights to request creation of courses.');
5439: } else {
1.90 weissno 5440: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5441: }
1.1 raeburn 5442: }
5443: } else {
1.11 albertel 5444: $resulttext = '<span class="LC_error">'.
5445: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5446: }
1.3 raeburn 5447: return $resulttext;
1.1 raeburn 5448: }
5449:
1.3 raeburn 5450: sub modify_autoenroll {
5451: my ($dom,%domconfig) = @_;
1.1 raeburn 5452: my ($resulttext,%changes);
5453: my %currautoenroll;
5454: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5455: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5456: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5457: }
5458: }
5459: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5460: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5461: sender => 'Sender for notification messages',
5462: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5463: my @offon = ('off','on');
1.17 raeburn 5464: my $sender_uname = $env{'form.sender_uname'};
5465: my $sender_domain = $env{'form.sender_domain'};
5466: if ($sender_domain eq '') {
5467: $sender_uname = '';
5468: } elsif ($sender_uname eq '') {
5469: $sender_domain = '';
5470: }
1.129 raeburn 5471: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5472: my %autoenrollhash = (
1.129 raeburn 5473: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5474: 'sender_uname' => $sender_uname,
5475: 'sender_domain' => $sender_domain,
5476: 'co-owners' => $coowners,
1.1 raeburn 5477: }
5478: );
1.4 raeburn 5479: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5480: $dom);
1.1 raeburn 5481: if ($putresult eq 'ok') {
5482: if (exists($currautoenroll{'run'})) {
5483: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5484: $changes{'run'} = 1;
5485: }
5486: } elsif ($autorun) {
5487: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 5488: $changes{'run'} = 1;
1.1 raeburn 5489: }
5490: }
1.17 raeburn 5491: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 5492: $changes{'sender'} = 1;
5493: }
1.17 raeburn 5494: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 5495: $changes{'sender'} = 1;
5496: }
1.129 raeburn 5497: if ($currautoenroll{'co-owners'} ne '') {
5498: if ($currautoenroll{'co-owners'} ne $coowners) {
5499: $changes{'coowners'} = 1;
5500: }
5501: } elsif ($coowners) {
5502: $changes{'coowners'} = 1;
5503: }
1.1 raeburn 5504: if (keys(%changes) > 0) {
5505: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5506: if ($changes{'run'}) {
1.1 raeburn 5507: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5508: }
5509: if ($changes{'sender'}) {
1.17 raeburn 5510: if ($sender_uname eq '' || $sender_domain eq '') {
5511: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5512: } else {
5513: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5514: }
1.1 raeburn 5515: }
1.129 raeburn 5516: if ($changes{'coowners'}) {
5517: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5518: &Apache::loncommon::devalidate_domconfig_cache($dom);
5519: }
1.1 raeburn 5520: $resulttext .= '</ul>';
5521: } else {
5522: $resulttext = &mt('No changes made to auto-enrollment settings');
5523: }
5524: } else {
1.11 albertel 5525: $resulttext = '<span class="LC_error">'.
5526: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5527: }
1.3 raeburn 5528: return $resulttext;
1.1 raeburn 5529: }
5530:
5531: sub modify_autoupdate {
1.3 raeburn 5532: my ($dom,%domconfig) = @_;
1.1 raeburn 5533: my ($resulttext,%currautoupdate,%fields,%changes);
5534: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5535: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5536: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5537: }
5538: }
5539: my @offon = ('off','on');
5540: my %title = &Apache::lonlocal::texthash (
5541: run => 'Auto-update:',
5542: classlists => 'Updates to user information in classlists?'
5543: );
1.44 raeburn 5544: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5545: my %fieldtitles = &Apache::lonlocal::texthash (
5546: id => 'Student/Employee ID',
1.20 raeburn 5547: permanentemail => 'E-mail address',
1.1 raeburn 5548: lastname => 'Last Name',
5549: firstname => 'First Name',
5550: middlename => 'Middle Name',
1.132 raeburn 5551: generation => 'Generation',
1.1 raeburn 5552: );
1.142 raeburn 5553: $othertitle = &mt('All users');
1.1 raeburn 5554: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5555: $othertitle = &mt('Other users');
1.1 raeburn 5556: }
5557: foreach my $key (keys(%env)) {
5558: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5559: my ($usertype,$item) = ($1,$2);
5560: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5561: if ($usertype eq 'default') {
5562: push(@{$fields{$1}},$2);
5563: } elsif (ref($types) eq 'ARRAY') {
5564: if (grep(/^\Q$usertype\E$/,@{$types})) {
5565: push(@{$fields{$1}},$2);
5566: }
5567: }
5568: }
1.1 raeburn 5569: }
5570: }
1.131 raeburn 5571: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5572: @lockablenames = sort(@lockablenames);
5573: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5574: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5575: if (@changed) {
5576: $changes{'lockablenames'} = 1;
5577: }
5578: } else {
5579: if (@lockablenames) {
5580: $changes{'lockablenames'} = 1;
5581: }
5582: }
1.1 raeburn 5583: my %updatehash = (
5584: autoupdate => { run => $env{'form.autoupdate_run'},
5585: classlists => $env{'form.classlists'},
5586: fields => {%fields},
1.131 raeburn 5587: lockablenames => \@lockablenames,
1.1 raeburn 5588: }
5589: );
5590: foreach my $key (keys(%currautoupdate)) {
5591: if (($key eq 'run') || ($key eq 'classlists')) {
5592: if (exists($updatehash{autoupdate}{$key})) {
5593: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5594: $changes{$key} = 1;
5595: }
5596: }
5597: } elsif ($key eq 'fields') {
5598: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5599: foreach my $item (@{$types},'default') {
1.1 raeburn 5600: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5601: my $change = 0;
5602: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5603: if (!exists($fields{$item})) {
5604: $change = 1;
1.132 raeburn 5605: last;
1.1 raeburn 5606: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5607: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5608: $change = 1;
1.132 raeburn 5609: last;
1.1 raeburn 5610: }
5611: }
5612: }
5613: if ($change) {
5614: push(@{$changes{$key}},$item);
5615: }
1.26 raeburn 5616: }
1.1 raeburn 5617: }
5618: }
1.131 raeburn 5619: } elsif ($key eq 'lockablenames') {
5620: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5621: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5622: if (@changed) {
5623: $changes{'lockablenames'} = 1;
5624: }
5625: } else {
5626: if (@lockablenames) {
5627: $changes{'lockablenames'} = 1;
5628: }
5629: }
5630: }
5631: }
5632: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5633: if (@lockablenames) {
5634: $changes{'lockablenames'} = 1;
1.1 raeburn 5635: }
5636: }
1.26 raeburn 5637: foreach my $item (@{$types},'default') {
5638: if (defined($fields{$item})) {
5639: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5640: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5641: my $change = 0;
5642: if (ref($fields{$item}) eq 'ARRAY') {
5643: foreach my $type (@{$fields{$item}}) {
5644: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5645: $change = 1;
5646: last;
5647: }
5648: }
5649: }
5650: if ($change) {
5651: push(@{$changes{'fields'}},$item);
5652: }
5653: } else {
1.26 raeburn 5654: push(@{$changes{'fields'}},$item);
5655: }
5656: } else {
5657: push(@{$changes{'fields'}},$item);
1.1 raeburn 5658: }
5659: }
5660: }
5661: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5662: $dom);
5663: if ($putresult eq 'ok') {
5664: if (keys(%changes) > 0) {
5665: $resulttext = &mt('Changes made:').'<ul>';
5666: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5667: if ($key eq 'lockablenames') {
5668: $resulttext .= '<li>';
5669: if (@lockablenames) {
5670: $usertypes->{'default'} = $othertitle;
5671: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5672: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5673: } else {
5674: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5675: }
5676: $resulttext .= '</li>';
5677: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5678: foreach my $item (@{$changes{$key}}) {
5679: my @newvalues;
5680: foreach my $type (@{$fields{$item}}) {
5681: push(@newvalues,$fieldtitles{$type});
5682: }
1.3 raeburn 5683: my $newvaluestr;
5684: if (@newvalues > 0) {
5685: $newvaluestr = join(', ',@newvalues);
5686: } else {
5687: $newvaluestr = &mt('none');
1.6 raeburn 5688: }
1.1 raeburn 5689: if ($item eq 'default') {
1.26 raeburn 5690: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5691: } else {
1.26 raeburn 5692: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5693: }
5694: }
5695: } else {
5696: my $newvalue;
5697: if ($key eq 'run') {
5698: $newvalue = $offon[$env{'form.autoupdate_run'}];
5699: } else {
5700: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5701: }
1.1 raeburn 5702: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5703: }
5704: }
5705: $resulttext .= '</ul>';
5706: } else {
1.3 raeburn 5707: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5708: }
5709: } else {
1.11 albertel 5710: $resulttext = '<span class="LC_error">'.
5711: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5712: }
1.3 raeburn 5713: return $resulttext;
1.1 raeburn 5714: }
5715:
1.125 raeburn 5716: sub modify_autocreate {
5717: my ($dom,%domconfig) = @_;
5718: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5719: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5720: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5721: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5722: }
5723: }
5724: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5725: req => 'Auto-creation of validated requests for official courses',
5726: xmldc => 'Identity of course creator of courses from XML files',
5727: );
5728: my @types = ('xml','req');
5729: foreach my $item (@types) {
5730: $newvals{$item} = $env{'form.autocreate_'.$item};
5731: $newvals{$item} =~ s/\D//g;
5732: $newvals{$item} = 0 if ($newvals{$item} eq '');
5733: }
5734: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5735: my %domcoords = &get_active_dcs($dom);
5736: unless (exists($domcoords{$newvals{'xmldc'}})) {
5737: $newvals{'xmldc'} = '';
5738: }
5739: %autocreatehash = (
5740: autocreate => { xml => $newvals{'xml'},
5741: req => $newvals{'req'},
5742: }
5743: );
5744: if ($newvals{'xmldc'} ne '') {
5745: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5746: }
5747: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5748: $dom);
5749: if ($putresult eq 'ok') {
5750: my @items = @types;
5751: if ($newvals{'xml'}) {
5752: push(@items,'xmldc');
5753: }
5754: foreach my $item (@items) {
5755: if (exists($currautocreate{$item})) {
5756: if ($currautocreate{$item} ne $newvals{$item}) {
5757: $changes{$item} = 1;
5758: }
5759: } elsif ($newvals{$item}) {
5760: $changes{$item} = 1;
5761: }
5762: }
5763: if (keys(%changes) > 0) {
5764: my @offon = ('off','on');
5765: $resulttext = &mt('Changes made:').'<ul>';
5766: foreach my $item (@types) {
5767: if ($changes{$item}) {
5768: my $newtxt = $offon[$newvals{$item}];
5769: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5770: }
5771: }
5772: if ($changes{'xmldc'}) {
5773: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5774: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5775: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5776: }
5777: $resulttext .= '</ul>';
5778: } else {
5779: $resulttext = &mt('No changes made to auto-creation settings');
5780: }
5781: } else {
5782: $resulttext = '<span class="LC_error">'.
5783: &mt('An error occurred: [_1]',$putresult).'</span>';
5784: }
5785: return $resulttext;
5786: }
5787:
1.23 raeburn 5788: sub modify_directorysrch {
5789: my ($dom,%domconfig) = @_;
5790: my ($resulttext,%changes);
5791: my %currdirsrch;
5792: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5793: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5794: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5795: }
5796: }
5797: my %title = ( available => 'Directory search available',
1.24 raeburn 5798: localonly => 'Other domains can search',
1.23 raeburn 5799: searchby => 'Search types',
5800: searchtypes => 'Search latitude');
5801: my @offon = ('off','on');
1.24 raeburn 5802: my @otherdoms = ('Yes','No');
1.23 raeburn 5803:
1.25 raeburn 5804: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5805: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5806: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5807:
1.44 raeburn 5808: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5809: if (keys(%{$usertypes}) == 0) {
5810: @cansearch = ('default');
5811: } else {
5812: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5813: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5814: if (!grep(/^\Q$type\E$/,@cansearch)) {
5815: push(@{$changes{'cansearch'}},$type);
5816: }
1.23 raeburn 5817: }
1.26 raeburn 5818: foreach my $type (@cansearch) {
5819: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5820: push(@{$changes{'cansearch'}},$type);
5821: }
1.23 raeburn 5822: }
1.26 raeburn 5823: } else {
5824: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5825: }
5826: }
5827:
5828: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5829: foreach my $by (@{$currdirsrch{'searchby'}}) {
5830: if (!grep(/^\Q$by\E$/,@searchby)) {
5831: push(@{$changes{'searchby'}},$by);
5832: }
5833: }
5834: foreach my $by (@searchby) {
5835: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5836: push(@{$changes{'searchby'}},$by);
5837: }
5838: }
5839: } else {
5840: push(@{$changes{'searchby'}},@searchby);
5841: }
1.25 raeburn 5842:
5843: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5844: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5845: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5846: push(@{$changes{'searchtypes'}},$type);
5847: }
5848: }
5849: foreach my $type (@searchtypes) {
5850: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5851: push(@{$changes{'searchtypes'}},$type);
5852: }
5853: }
5854: } else {
5855: if (exists($currdirsrch{'searchtypes'})) {
5856: foreach my $type (@searchtypes) {
5857: if ($type ne $currdirsrch{'searchtypes'}) {
5858: push(@{$changes{'searchtypes'}},$type);
5859: }
5860: }
5861: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5862: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5863: }
5864: } else {
5865: push(@{$changes{'searchtypes'}},@searchtypes);
5866: }
5867: }
5868:
1.23 raeburn 5869: my %dirsrch_hash = (
5870: directorysrch => { available => $env{'form.dirsrch_available'},
5871: cansearch => \@cansearch,
1.24 raeburn 5872: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5873: searchby => \@searchby,
1.25 raeburn 5874: searchtypes => \@searchtypes,
1.23 raeburn 5875: }
5876: );
5877: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5878: $dom);
5879: if ($putresult eq 'ok') {
5880: if (exists($currdirsrch{'available'})) {
5881: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5882: $changes{'available'} = 1;
5883: }
5884: } else {
5885: if ($env{'form.dirsrch_available'} eq '1') {
5886: $changes{'available'} = 1;
5887: }
5888: }
1.24 raeburn 5889: if (exists($currdirsrch{'localonly'})) {
5890: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5891: $changes{'localonly'} = 1;
5892: }
5893: } else {
5894: if ($env{'form.dirsrch_localonly'} eq '1') {
5895: $changes{'localonly'} = 1;
5896: }
5897: }
1.23 raeburn 5898: if (keys(%changes) > 0) {
5899: $resulttext = &mt('Changes made:').'<ul>';
5900: if ($changes{'available'}) {
5901: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5902: }
1.24 raeburn 5903: if ($changes{'localonly'}) {
5904: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5905: }
5906:
1.23 raeburn 5907: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5908: my $chgtext;
1.26 raeburn 5909: if (ref($usertypes) eq 'HASH') {
5910: if (keys(%{$usertypes}) > 0) {
5911: foreach my $type (@{$types}) {
5912: if (grep(/^\Q$type\E$/,@cansearch)) {
5913: $chgtext .= $usertypes->{$type}.'; ';
5914: }
5915: }
5916: if (grep(/^default$/,@cansearch)) {
5917: $chgtext .= $othertitle;
5918: } else {
5919: $chgtext =~ s/\; $//;
5920: }
5921: $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 5922: }
5923: }
5924: }
5925: if (ref($changes{'searchby'}) eq 'ARRAY') {
5926: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5927: my $chgtext;
5928: foreach my $type (@{$titleorder}) {
5929: if (grep(/^\Q$type\E$/,@searchby)) {
5930: if (defined($searchtitles->{$type})) {
5931: $chgtext .= $searchtitles->{$type}.'; ';
5932: }
5933: }
5934: }
5935: $chgtext =~ s/\; $//;
5936: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5937: }
1.25 raeburn 5938: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5939: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5940: my $chgtext;
5941: foreach my $type (@{$srchtypeorder}) {
5942: if (grep(/^\Q$type\E$/,@searchtypes)) {
5943: if (defined($srchtypes_desc->{$type})) {
5944: $chgtext .= $srchtypes_desc->{$type}.'; ';
5945: }
5946: }
5947: }
5948: $chgtext =~ s/\; $//;
5949: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5950: }
5951: $resulttext .= '</ul>';
5952: } else {
5953: $resulttext = &mt('No changes made to institution directory search settings');
5954: }
5955: } else {
5956: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5957: &mt('An error occurred: [_1]',$putresult).'</span>';
5958: }
5959: return $resulttext;
5960: }
5961:
1.28 raeburn 5962: sub modify_contacts {
5963: my ($dom,%domconfig) = @_;
5964: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5965: if (ref($domconfig{'contacts'}) eq 'HASH') {
5966: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5967: $currsetting{$key} = $domconfig{'contacts'}{$key};
5968: }
5969: }
1.134 raeburn 5970: my (%others,%to,%bcc);
1.28 raeburn 5971: my @contacts = ('supportemail','adminemail');
1.102 raeburn 5972: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5973: 'requestsmail');
1.28 raeburn 5974: foreach my $type (@mailings) {
5975: @{$newsetting{$type}} =
5976: &Apache::loncommon::get_env_multiple('form.'.$type);
5977: foreach my $item (@contacts) {
5978: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5979: $contacts_hash{contacts}{$type}{$item} = 1;
5980: } else {
5981: $contacts_hash{contacts}{$type}{$item} = 0;
5982: }
5983: }
5984: $others{$type} = $env{'form.'.$type.'_others'};
5985: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 5986: if ($type eq 'helpdeskmail') {
5987: $bcc{$type} = $env{'form.'.$type.'_bcc'};
5988: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
5989: }
1.28 raeburn 5990: }
5991: foreach my $item (@contacts) {
5992: $to{$item} = $env{'form.'.$item};
5993: $contacts_hash{'contacts'}{$item} = $to{$item};
5994: }
5995: if (keys(%currsetting) > 0) {
5996: foreach my $item (@contacts) {
5997: if ($to{$item} ne $currsetting{$item}) {
5998: $changes{$item} = 1;
5999: }
6000: }
6001: foreach my $type (@mailings) {
6002: foreach my $item (@contacts) {
6003: if (ref($currsetting{$type}) eq 'HASH') {
6004: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6005: push(@{$changes{$type}},$item);
6006: }
6007: } else {
6008: push(@{$changes{$type}},@{$newsetting{$type}});
6009: }
6010: }
6011: if ($others{$type} ne $currsetting{$type}{'others'}) {
6012: push(@{$changes{$type}},'others');
6013: }
1.134 raeburn 6014: if ($type eq 'helpdeskmail') {
6015: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6016: push(@{$changes{$type}},'bcc');
6017: }
6018: }
1.28 raeburn 6019: }
6020: } else {
6021: my %default;
6022: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6023: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6024: $default{'errormail'} = 'adminemail';
6025: $default{'packagesmail'} = 'adminemail';
6026: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6027: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6028: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6029: foreach my $item (@contacts) {
6030: if ($to{$item} ne $default{$item}) {
6031: $changes{$item} = 1;
6032: }
6033: }
6034: foreach my $type (@mailings) {
6035: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6036:
6037: push(@{$changes{$type}},@{$newsetting{$type}});
6038: }
6039: if ($others{$type} ne '') {
6040: push(@{$changes{$type}},'others');
1.134 raeburn 6041: }
6042: if ($type eq 'helpdeskmail') {
6043: if ($bcc{$type} ne '') {
6044: push(@{$changes{$type}},'bcc');
6045: }
6046: }
1.28 raeburn 6047: }
6048: }
6049: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6050: $dom);
6051: if ($putresult eq 'ok') {
6052: if (keys(%changes) > 0) {
6053: my ($titles,$short_titles) = &contact_titles();
6054: $resulttext = &mt('Changes made:').'<ul>';
6055: foreach my $item (@contacts) {
6056: if ($changes{$item}) {
6057: $resulttext .= '<li>'.$titles->{$item}.
6058: &mt(' set to: ').
6059: '<span class="LC_cusr_emph">'.
6060: $to{$item}.'</span></li>';
6061: }
6062: }
6063: foreach my $type (@mailings) {
6064: if (ref($changes{$type}) eq 'ARRAY') {
6065: $resulttext .= '<li>'.$titles->{$type}.': ';
6066: my @text;
6067: foreach my $item (@{$newsetting{$type}}) {
6068: push(@text,$short_titles->{$item});
6069: }
6070: if ($others{$type} ne '') {
6071: push(@text,$others{$type});
6072: }
6073: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6074: join(', ',@text).'</span>';
6075: if ($type eq 'helpdeskmail') {
6076: if ($bcc{$type} ne '') {
6077: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6078: }
6079: }
6080: $resulttext .= '</li>';
1.28 raeburn 6081: }
6082: }
6083: $resulttext .= '</ul>';
6084: } else {
1.34 raeburn 6085: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6086: }
6087: } else {
6088: $resulttext = '<span class="LC_error">'.
6089: &mt('An error occurred: [_1].',$putresult).'</span>';
6090: }
6091: return $resulttext;
6092: }
6093:
6094: sub modify_usercreation {
1.27 raeburn 6095: my ($dom,%domconfig) = @_;
1.34 raeburn 6096: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6097: my $warningmsg;
1.27 raeburn 6098: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6099: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6100: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6101: }
6102: }
6103: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6104: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6105: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6106: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6107: foreach my $item(@contexts) {
1.45 raeburn 6108: if ($item eq 'selfcreate') {
1.50 raeburn 6109: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6110: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6111: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6112: if (ref($cancreate{$item}) eq 'ARRAY') {
6113: if (grep(/^login$/,@{$cancreate{$item}})) {
6114: $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.');
6115: }
1.43 raeburn 6116: }
6117: }
1.50 raeburn 6118: } else {
6119: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6120: }
1.34 raeburn 6121: }
1.93 raeburn 6122: my ($othertitle,$usertypes,$types) =
6123: &Apache::loncommon::sorted_inst_types($dom);
6124: if (ref($types) eq 'ARRAY') {
6125: if (@{$types} > 0) {
6126: @{$cancreate{'statustocreate'}} =
6127: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6128: } else {
6129: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6130: }
6131: push(@contexts,'statustocreate');
6132: }
1.34 raeburn 6133: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6134: foreach my $item (@contexts) {
1.93 raeburn 6135: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6136: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6137: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6138: if (ref($cancreate{$item}) eq 'ARRAY') {
6139: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6140: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6141: push(@{$changes{'cancreate'}},$item);
6142: }
1.50 raeburn 6143: }
6144: }
6145: }
6146: } else {
6147: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6148: if (@{$cancreate{$item}} > 0) {
6149: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6150: push(@{$changes{'cancreate'}},$item);
6151: }
6152: }
6153: } else {
6154: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6155: if (@{$cancreate{$item}} < 3) {
6156: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6157: push(@{$changes{'cancreate'}},$item);
6158: }
6159: }
6160: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6161: if (@{$cancreate{$item}} > 0) {
6162: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6163: push(@{$changes{'cancreate'}},$item);
6164: }
6165: }
6166: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6167: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6168: push(@{$changes{'cancreate'}},$item);
6169: }
6170: }
6171: }
6172: }
6173: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6174: foreach my $type (@{$cancreate{$item}}) {
6175: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6176: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6177: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6178: push(@{$changes{'cancreate'}},$item);
6179: }
6180: }
6181: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6182: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6183: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6184: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6185: push(@{$changes{'cancreate'}},$item);
6186: }
6187: }
6188: }
6189: }
6190: }
6191: } else {
6192: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6193: push(@{$changes{'cancreate'}},$item);
6194: }
6195: }
1.27 raeburn 6196: }
1.34 raeburn 6197: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6198: foreach my $item (@contexts) {
1.43 raeburn 6199: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6200: if ($cancreate{$item} ne 'any') {
6201: push(@{$changes{'cancreate'}},$item);
6202: }
6203: } else {
6204: if ($cancreate{$item} ne 'none') {
6205: push(@{$changes{'cancreate'}},$item);
6206: }
1.27 raeburn 6207: }
6208: }
6209: } else {
1.43 raeburn 6210: foreach my $item (@contexts) {
1.34 raeburn 6211: push(@{$changes{'cancreate'}},$item);
6212: }
1.27 raeburn 6213: }
1.34 raeburn 6214:
1.27 raeburn 6215: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6216: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6217: if (!grep(/^\Q$type\E$/,@username_rule)) {
6218: push(@{$changes{'username_rule'}},$type);
6219: }
6220: }
6221: foreach my $type (@username_rule) {
6222: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6223: push(@{$changes{'username_rule'}},$type);
6224: }
6225: }
6226: } else {
6227: push(@{$changes{'username_rule'}},@username_rule);
6228: }
6229:
1.32 raeburn 6230: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6231: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6232: if (!grep(/^\Q$type\E$/,@id_rule)) {
6233: push(@{$changes{'id_rule'}},$type);
6234: }
6235: }
6236: foreach my $type (@id_rule) {
6237: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6238: push(@{$changes{'id_rule'}},$type);
6239: }
6240: }
6241: } else {
6242: push(@{$changes{'id_rule'}},@id_rule);
6243: }
6244:
1.43 raeburn 6245: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6246: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6247: if (!grep(/^\Q$type\E$/,@email_rule)) {
6248: push(@{$changes{'email_rule'}},$type);
6249: }
6250: }
6251: foreach my $type (@email_rule) {
6252: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6253: push(@{$changes{'email_rule'}},$type);
6254: }
6255: }
6256: } else {
6257: push(@{$changes{'email_rule'}},@email_rule);
6258: }
6259:
6260: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6261: my @authtypes = ('int','krb4','krb5','loc');
6262: my %authhash;
1.43 raeburn 6263: foreach my $item (@authen_contexts) {
1.28 raeburn 6264: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6265: foreach my $auth (@authtypes) {
6266: if (grep(/^\Q$auth\E$/,@authallowed)) {
6267: $authhash{$item}{$auth} = 1;
6268: } else {
6269: $authhash{$item}{$auth} = 0;
6270: }
6271: }
6272: }
6273: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6274: foreach my $item (@authen_contexts) {
1.28 raeburn 6275: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6276: foreach my $auth (@authtypes) {
6277: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6278: push(@{$changes{'authtypes'}},$item);
6279: last;
6280: }
6281: }
6282: }
6283: }
6284: } else {
1.43 raeburn 6285: foreach my $item (@authen_contexts) {
1.28 raeburn 6286: push(@{$changes{'authtypes'}},$item);
6287: }
6288: }
6289:
1.27 raeburn 6290: my %usercreation_hash = (
1.28 raeburn 6291: usercreation => {
1.34 raeburn 6292: cancreate => \%cancreate,
1.27 raeburn 6293: username_rule => \@username_rule,
1.32 raeburn 6294: id_rule => \@id_rule,
1.43 raeburn 6295: email_rule => \@email_rule,
1.32 raeburn 6296: authtypes => \%authhash,
1.27 raeburn 6297: }
6298: );
6299:
6300: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6301: $dom);
1.50 raeburn 6302:
6303: my %selfcreatetypes = (
6304: sso => 'users authenticated by institutional single sign on',
6305: login => 'users authenticated by institutional log-in',
6306: email => 'users who provide a valid e-mail address for use as the username',
6307: );
1.27 raeburn 6308: if ($putresult eq 'ok') {
6309: if (keys(%changes) > 0) {
6310: $resulttext = &mt('Changes made:').'<ul>';
6311: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6312: my %lt = &usercreation_types();
6313: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6314: my $chgtext;
6315: unless ($type eq 'statustocreate') {
6316: $chgtext = $lt{$type}.', ';
6317: }
1.45 raeburn 6318: if ($type eq 'selfcreate') {
1.50 raeburn 6319: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6320: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6321: } else {
1.100 raeburn 6322: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6323: foreach my $case (@{$cancreate{$type}}) {
6324: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6325: }
6326: $chgtext .= '</ul>';
1.100 raeburn 6327: if (ref($cancreate{$type}) eq 'ARRAY') {
6328: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6329: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6330: if (@{$cancreate{'statustocreate'}} == 0) {
6331: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6332: }
6333: }
6334: }
6335: }
1.43 raeburn 6336: }
1.93 raeburn 6337: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6338: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6339: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6340: if (@{$cancreate{'selfcreate'}} > 0) {
6341: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6342:
6343: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6344: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6345: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6346: }
1.96 raeburn 6347: } elsif (ref($usertypes) eq 'HASH') {
6348: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6349: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6350: } else {
6351: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6352: }
6353: $chgtext .= '<ul>';
6354: foreach my $case (@{$cancreate{$type}}) {
6355: if ($case eq 'default') {
6356: $chgtext .= '<li>'.$othertitle.'</li>';
6357: } else {
6358: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6359: }
6360: }
1.100 raeburn 6361: $chgtext .= '</ul>';
6362: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6363: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6364: }
6365: }
6366: } else {
6367: if (@{$cancreate{$type}} == 0) {
6368: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6369: } else {
6370: $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 6371: }
6372: }
6373: }
1.43 raeburn 6374: } else {
6375: if ($cancreate{$type} eq 'none') {
6376: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6377: } elsif ($cancreate{$type} eq 'any') {
6378: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6379: } elsif ($cancreate{$type} eq 'official') {
6380: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6381: } elsif ($cancreate{$type} eq 'unofficial') {
6382: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6383: }
1.34 raeburn 6384: }
6385: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6386: }
6387: }
6388: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6389: my ($rules,$ruleorder) =
6390: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6391: my $chgtext = '<ul>';
6392: foreach my $type (@username_rule) {
6393: if (ref($rules->{$type}) eq 'HASH') {
6394: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6395: }
6396: }
6397: $chgtext .= '</ul>';
6398: if (@username_rule > 0) {
6399: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6400: } else {
1.28 raeburn 6401: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6402: }
6403: }
1.32 raeburn 6404: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6405: my ($idrules,$idruleorder) =
6406: &Apache::lonnet::inst_userrules($dom,'id');
6407: my $chgtext = '<ul>';
6408: foreach my $type (@id_rule) {
6409: if (ref($idrules->{$type}) eq 'HASH') {
6410: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6411: }
6412: }
6413: $chgtext .= '</ul>';
6414: if (@id_rule > 0) {
6415: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6416: } else {
6417: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6418: }
6419: }
1.43 raeburn 6420: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6421: my ($emailrules,$emailruleorder) =
6422: &Apache::lonnet::inst_userrules($dom,'email');
6423: my $chgtext = '<ul>';
6424: foreach my $type (@email_rule) {
6425: if (ref($emailrules->{$type}) eq 'HASH') {
6426: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6427: }
6428: }
6429: $chgtext .= '</ul>';
6430: if (@email_rule > 0) {
6431: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6432: } else {
6433: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6434: }
6435: }
6436:
1.28 raeburn 6437: my %authname = &authtype_names();
6438: my %context_title = &context_names();
6439: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6440: my $chgtext = '<ul>';
6441: foreach my $type (@{$changes{'authtypes'}}) {
6442: my @allowed;
6443: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6444: foreach my $auth (@authtypes) {
6445: if ($authhash{$type}{$auth}) {
6446: push(@allowed,$authname{$auth});
6447: }
6448: }
1.43 raeburn 6449: if (@allowed > 0) {
6450: $chgtext .= join(', ',@allowed).'</li>';
6451: } else {
6452: $chgtext .= &mt('none').'</li>';
6453: }
1.28 raeburn 6454: }
6455: $chgtext .= '</ul>';
6456: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6457: $resulttext .= '</li>';
6458: }
1.27 raeburn 6459: $resulttext .= '</ul>';
6460: } else {
1.28 raeburn 6461: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 6462: }
6463: } else {
6464: $resulttext = '<span class="LC_error">'.
1.23 raeburn 6465: &mt('An error occurred: [_1]',$putresult).'</span>';
6466: }
1.43 raeburn 6467: if ($warningmsg ne '') {
6468: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6469: }
1.23 raeburn 6470: return $resulttext;
6471: }
6472:
1.33 raeburn 6473: sub modify_usermodification {
6474: my ($dom,%domconfig) = @_;
6475: my ($resulttext,%curr_usermodification,%changes);
6476: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6477: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6478: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6479: }
6480: }
1.63 raeburn 6481: my @contexts = ('author','course','selfcreate');
1.33 raeburn 6482: my %context_title = (
6483: author => 'In author context',
6484: course => 'In course context',
1.63 raeburn 6485: selfcreate => 'When self creating account',
1.33 raeburn 6486: );
6487: my @fields = ('lastname','firstname','middlename','generation',
6488: 'permanentemail','id');
6489: my %roles = (
6490: author => ['ca','aa'],
6491: course => ['st','ep','ta','in','cr'],
6492: );
1.63 raeburn 6493: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6494: if (ref($types) eq 'ARRAY') {
6495: push(@{$types},'default');
6496: $usertypes->{'default'} = $othertitle;
6497: }
6498: $roles{'selfcreate'} = $types;
1.33 raeburn 6499: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6500: my %modifyhash;
6501: foreach my $context (@contexts) {
6502: foreach my $role (@{$roles{$context}}) {
6503: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6504: foreach my $item (@fields) {
6505: if (grep(/^\Q$item\E$/,@modifiable)) {
6506: $modifyhash{$context}{$role}{$item} = 1;
6507: } else {
6508: $modifyhash{$context}{$role}{$item} = 0;
6509: }
6510: }
6511: }
6512: if (ref($curr_usermodification{$context}) eq 'HASH') {
6513: foreach my $role (@{$roles{$context}}) {
6514: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6515: foreach my $field (@fields) {
6516: if ($modifyhash{$context}{$role}{$field} ne
6517: $curr_usermodification{$context}{$role}{$field}) {
6518: push(@{$changes{$context}},$role);
6519: last;
6520: }
6521: }
6522: }
6523: }
6524: } else {
6525: foreach my $context (@contexts) {
6526: foreach my $role (@{$roles{$context}}) {
6527: push(@{$changes{$context}},$role);
6528: }
6529: }
6530: }
6531: }
6532: my %usermodification_hash = (
6533: usermodification => \%modifyhash,
6534: );
6535: my $putresult = &Apache::lonnet::put_dom('configuration',
6536: \%usermodification_hash,$dom);
6537: if ($putresult eq 'ok') {
6538: if (keys(%changes) > 0) {
6539: $resulttext = &mt('Changes made: ').'<ul>';
6540: foreach my $context (@contexts) {
6541: if (ref($changes{$context}) eq 'ARRAY') {
6542: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6543: if (ref($changes{$context}) eq 'ARRAY') {
6544: foreach my $role (@{$changes{$context}}) {
6545: my $rolename;
1.63 raeburn 6546: if ($context eq 'selfcreate') {
6547: $rolename = $role;
6548: if (ref($usertypes) eq 'HASH') {
6549: if ($usertypes->{$role} ne '') {
6550: $rolename = $usertypes->{$role};
6551: }
6552: }
1.33 raeburn 6553: } else {
1.63 raeburn 6554: if ($role eq 'cr') {
6555: $rolename = &mt('Custom');
6556: } else {
6557: $rolename = &Apache::lonnet::plaintext($role);
6558: }
1.33 raeburn 6559: }
6560: my @modifiable;
1.63 raeburn 6561: if ($context eq 'selfcreate') {
1.126 bisitz 6562: $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 6563: } else {
6564: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6565: }
1.33 raeburn 6566: foreach my $field (@fields) {
6567: if ($modifyhash{$context}{$role}{$field}) {
6568: push(@modifiable,$fieldtitles{$field});
6569: }
6570: }
6571: if (@modifiable > 0) {
6572: $resulttext .= join(', ',@modifiable);
6573: } else {
6574: $resulttext .= &mt('none');
6575: }
6576: $resulttext .= '</li>';
6577: }
6578: $resulttext .= '</ul></li>';
6579: }
6580: }
6581: }
6582: $resulttext .= '</ul>';
6583: } else {
6584: $resulttext = &mt('No changes made to user modification settings');
6585: }
6586: } else {
6587: $resulttext = '<span class="LC_error">'.
6588: &mt('An error occurred: [_1]',$putresult).'</span>';
6589: }
6590: return $resulttext;
6591: }
6592:
1.43 raeburn 6593: sub modify_defaults {
6594: my ($dom,$r) = @_;
6595: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6596: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6597: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6598: my @authtypes = ('internal','krb4','krb5','localauth');
6599: foreach my $item (@items) {
6600: $newvalues{$item} = $env{'form.'.$item};
6601: if ($item eq 'auth_def') {
6602: if ($newvalues{$item} ne '') {
6603: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6604: push(@errors,$item);
6605: }
6606: }
6607: } elsif ($item eq 'lang_def') {
6608: if ($newvalues{$item} ne '') {
6609: if ($newvalues{$item} =~ /^(\w+)/) {
6610: my $langcode = $1;
1.103 raeburn 6611: if ($langcode ne 'x_chef') {
6612: if (code2language($langcode) eq '') {
6613: push(@errors,$item);
6614: }
1.43 raeburn 6615: }
6616: } else {
6617: push(@errors,$item);
6618: }
6619: }
1.54 raeburn 6620: } elsif ($item eq 'timezone_def') {
6621: if ($newvalues{$item} ne '') {
1.62 raeburn 6622: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6623: push(@errors,$item);
6624: }
6625: }
1.68 raeburn 6626: } elsif ($item eq 'datelocale_def') {
6627: if ($newvalues{$item} ne '') {
6628: my @datelocale_ids = DateTime::Locale->ids();
6629: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6630: push(@errors,$item);
6631: }
6632: }
1.141 raeburn 6633: } elsif ($item eq 'portal_def') {
6634: if ($newvalues{$item} ne '') {
6635: 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])\/?$/) {
6636: push(@errors,$item);
6637: }
6638: }
1.43 raeburn 6639: }
6640: if (grep(/^\Q$item\E$/,@errors)) {
6641: $newvalues{$item} = $domdefaults{$item};
6642: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6643: $changes{$item} = 1;
6644: }
1.72 raeburn 6645: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6646: }
6647: my %defaults_hash = (
1.72 raeburn 6648: defaults => \%newvalues,
6649: );
1.43 raeburn 6650: my $title = &defaults_titles();
6651: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6652: $dom);
6653: if ($putresult eq 'ok') {
6654: if (keys(%changes) > 0) {
6655: $resulttext = &mt('Changes made:').'<ul>';
6656: my $version = $r->dir_config('lonVersion');
6657: 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";
6658: foreach my $item (sort(keys(%changes))) {
6659: my $value = $env{'form.'.$item};
6660: if ($value eq '') {
6661: $value = &mt('none');
6662: } elsif ($item eq 'auth_def') {
6663: my %authnames = &authtype_names();
6664: my %shortauth = (
6665: internal => 'int',
6666: krb4 => 'krb4',
6667: krb5 => 'krb5',
6668: localauth => 'loc',
6669: );
6670: $value = $authnames{$shortauth{$value}};
6671: }
6672: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6673: $mailmsgtext .= "$title->{$item} set to $value\n";
6674: }
6675: $resulttext .= '</ul>';
6676: $mailmsgtext .= "\n";
6677: my $cachetime = 24*60*60;
1.72 raeburn 6678: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6679: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6680: my $sysmail = $r->dir_config('lonSysEMail');
6681: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6682: }
1.43 raeburn 6683: } else {
1.54 raeburn 6684: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6685: }
6686: } else {
6687: $resulttext = '<span class="LC_error">'.
6688: &mt('An error occurred: [_1]',$putresult).'</span>';
6689: }
6690: if (@errors > 0) {
6691: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6692: foreach my $item (@errors) {
6693: $resulttext .= ' "'.$title->{$item}.'",';
6694: }
6695: $resulttext =~ s/,$//;
6696: }
6697: return $resulttext;
6698: }
6699:
1.46 raeburn 6700: sub modify_scantron {
1.48 raeburn 6701: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6702: my ($resulttext,%confhash,%changes,$errors);
6703: my $custom = 'custom.tab';
6704: my $default = 'default.tab';
6705: my $servadm = $r->dir_config('lonAdmEMail');
6706: my ($configuserok,$author_ok,$switchserver) =
6707: &config_check($dom,$confname,$servadm);
6708: if ($env{'form.scantronformat.filename'} ne '') {
6709: my $error;
6710: if ($configuserok eq 'ok') {
6711: if ($switchserver) {
1.130 raeburn 6712: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6713: } else {
6714: if ($author_ok eq 'ok') {
6715: my ($result,$scantronurl) =
6716: &publishlogo($r,'upload','scantronformat',$dom,
6717: $confname,'scantron','','',$custom);
6718: if ($result eq 'ok') {
6719: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6720: $changes{'scantronformat'} = 1;
1.46 raeburn 6721: } else {
6722: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6723: }
6724: } else {
6725: $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);
6726: }
6727: }
6728: } else {
6729: $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);
6730: }
6731: if ($error) {
6732: &Apache::lonnet::logthis($error);
6733: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6734: }
6735: }
1.48 raeburn 6736: if (ref($domconfig{'scantron'}) eq 'HASH') {
6737: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6738: if ($env{'form.scantronformat_del'}) {
6739: $confhash{'scantron'}{'scantronformat'} = '';
6740: $changes{'scantronformat'} = 1;
1.46 raeburn 6741: }
6742: }
6743: }
6744: if (keys(%confhash) > 0) {
6745: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6746: $dom);
6747: if ($putresult eq 'ok') {
6748: if (keys(%changes) > 0) {
1.48 raeburn 6749: if (ref($confhash{'scantron'}) eq 'HASH') {
6750: $resulttext = &mt('Changes made:').'<ul>';
6751: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6752: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6753: } else {
1.130 raeburn 6754: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6755: }
1.48 raeburn 6756: $resulttext .= '</ul>';
6757: } else {
1.130 raeburn 6758: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6759: }
6760: $resulttext .= '</ul>';
6761: &Apache::loncommon::devalidate_domconfig_cache($dom);
6762: } else {
1.130 raeburn 6763: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6764: }
6765: } else {
6766: $resulttext = '<span class="LC_error">'.
6767: &mt('An error occurred: [_1]',$putresult).'</span>';
6768: }
6769: } else {
1.130 raeburn 6770: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6771: }
6772: if ($errors) {
6773: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6774: $errors.'</ul>';
6775: }
6776: return $resulttext;
6777: }
6778:
1.48 raeburn 6779: sub modify_coursecategories {
6780: my ($dom,%domconfig) = @_;
1.57 raeburn 6781: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6782: $cathash);
1.48 raeburn 6783: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6784: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6785: $cathash = $domconfig{'coursecategories'}{'cats'};
6786: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6787: $changes{'togglecats'} = 1;
6788: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6789: }
6790: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6791: $changes{'categorize'} = 1;
6792: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6793: }
1.120 raeburn 6794: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6795: $changes{'togglecatscomm'} = 1;
6796: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6797: }
6798: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6799: $changes{'categorizecomm'} = 1;
6800: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6801: }
1.57 raeburn 6802: } else {
6803: $changes{'togglecats'} = 1;
6804: $changes{'categorize'} = 1;
1.124 raeburn 6805: $changes{'togglecatscomm'} = 1;
6806: $changes{'categorizecomm'} = 1;
1.87 raeburn 6807: $domconfig{'coursecategories'} = {
6808: togglecats => $env{'form.togglecats'},
6809: categorize => $env{'form.categorize'},
1.124 raeburn 6810: togglecatscomm => $env{'form.togglecatscomm'},
6811: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6812: };
1.57 raeburn 6813: }
6814: if (ref($cathash) eq 'HASH') {
6815: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6816: push (@deletecategory,'instcode::0');
6817: }
1.120 raeburn 6818: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6819: push(@deletecategory,'communities::0');
6820: }
1.48 raeburn 6821: }
1.57 raeburn 6822: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6823: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6824: if (@deletecategory > 0) {
6825: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6826: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6827: foreach my $item (@deletecategory) {
1.57 raeburn 6828: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6829: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6830: $deletions{$item} = 1;
1.57 raeburn 6831: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6832: }
6833: }
6834: }
1.57 raeburn 6835: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6836: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6837: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6838: $reorderings{$item} = 1;
1.57 raeburn 6839: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6840: }
6841: if ($env{'form.addcategory_name_'.$item} ne '') {
6842: my $newcat = $env{'form.addcategory_name_'.$item};
6843: my $newdepth = $depth+1;
6844: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6845: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6846: $adds{$newitem} = 1;
6847: }
6848: if ($env{'form.subcat_'.$item} ne '') {
6849: my $newcat = $env{'form.subcat_'.$item};
6850: my $newdepth = $depth+1;
6851: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6852: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6853: $adds{$newitem} = 1;
6854: }
6855: }
6856: }
6857: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6858: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6859: my $newitem = 'instcode::0';
1.57 raeburn 6860: if ($cathash->{$newitem} eq '') {
6861: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6862: $adds{$newitem} = 1;
6863: }
6864: } else {
6865: my $newitem = 'instcode::0';
1.57 raeburn 6866: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6867: $adds{$newitem} = 1;
6868: }
6869: }
1.120 raeburn 6870: if ($env{'form.communities'} eq '1') {
6871: if (ref($cathash) eq 'HASH') {
6872: my $newitem = 'communities::0';
6873: if ($cathash->{$newitem} eq '') {
6874: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6875: $adds{$newitem} = 1;
6876: }
6877: } else {
6878: my $newitem = 'communities::0';
6879: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6880: $adds{$newitem} = 1;
6881: }
6882: }
1.48 raeburn 6883: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6884: if (($env{'form.addcategory_name'} ne 'instcode') &&
6885: ($env{'form.addcategory_name'} ne 'communities')) {
6886: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6887: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6888: $adds{$newitem} = 1;
6889: }
1.48 raeburn 6890: }
1.57 raeburn 6891: my $putresult;
1.48 raeburn 6892: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6893: if (keys(%deletions) > 0) {
6894: foreach my $key (keys(%deletions)) {
6895: if ($predelallitems{$key} ne '') {
6896: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6897: }
6898: }
6899: }
6900: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6901: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6902: if (ref($chkcats[0]) eq 'ARRAY') {
6903: my $depth = 0;
6904: my $chg = 0;
6905: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6906: my $name = $chkcats[0][$i];
6907: my $item;
6908: if ($name eq '') {
6909: $chg ++;
6910: } else {
6911: $item = &escape($name).'::0';
6912: if ($chg) {
1.57 raeburn 6913: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6914: }
6915: $depth ++;
1.57 raeburn 6916: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6917: $depth --;
6918: }
6919: }
6920: }
1.57 raeburn 6921: }
6922: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6923: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6924: if ($putresult eq 'ok') {
1.57 raeburn 6925: my %title = (
1.120 raeburn 6926: togglecats => 'Show/Hide a course in catalog',
6927: categorize => 'Assign a category to a course',
6928: togglecatscomm => 'Show/Hide a community in catalog',
6929: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6930: );
6931: my %level = (
1.120 raeburn 6932: dom => 'set in Domain ("Modify Course/Community")',
6933: crs => 'set in Course ("Course Configuration")',
6934: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6935: );
1.48 raeburn 6936: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6937: if ($changes{'togglecats'}) {
6938: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6939: }
6940: if ($changes{'categorize'}) {
6941: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6942: }
1.120 raeburn 6943: if ($changes{'togglecatscomm'}) {
6944: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6945: }
6946: if ($changes{'categorizecomm'}) {
6947: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6948: }
1.57 raeburn 6949: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6950: my $cathash;
6951: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6952: $cathash = $domconfig{'coursecategories'}{'cats'};
6953: } else {
6954: $cathash = {};
6955: }
6956: my (@cats,@trails,%allitems);
6957: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6958: if (keys(%deletions) > 0) {
6959: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6960: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6961: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6962: }
6963: $resulttext .= '</ul></li>';
6964: }
6965: if (keys(%reorderings) > 0) {
6966: my %sort_by_trail;
6967: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6968: foreach my $key (keys(%reorderings)) {
6969: if ($allitems{$key} ne '') {
6970: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6971: }
1.48 raeburn 6972: }
1.57 raeburn 6973: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6974: $resulttext .= '<li>'.$trails[$trail].'</li>';
6975: }
6976: $resulttext .= '</ul></li>';
1.48 raeburn 6977: }
1.57 raeburn 6978: if (keys(%adds) > 0) {
6979: my %sort_by_trail;
6980: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6981: foreach my $key (keys(%adds)) {
6982: if ($allitems{$key} ne '') {
6983: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6984: }
6985: }
6986: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6987: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 6988: }
1.57 raeburn 6989: $resulttext .= '</ul></li>';
1.48 raeburn 6990: }
6991: }
6992: $resulttext .= '</ul>';
6993: } else {
6994: $resulttext = '<span class="LC_error">'.
1.57 raeburn 6995: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 6996: }
6997: } else {
1.120 raeburn 6998: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 6999: }
7000: return $resulttext;
7001: }
7002:
1.69 raeburn 7003: sub modify_serverstatuses {
7004: my ($dom,%domconfig) = @_;
7005: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7006: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7007: %currserverstatus = %{$domconfig{'serverstatuses'}};
7008: }
7009: my @pages = &serverstatus_pages();
7010: foreach my $type (@pages) {
7011: $newserverstatus{$type}{'namedusers'} = '';
7012: $newserverstatus{$type}{'machines'} = '';
7013: if (defined($env{'form.'.$type.'_namedusers'})) {
7014: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7015: my @okusers;
7016: foreach my $user (@users) {
7017: my ($uname,$udom) = split(/:/,$user);
7018: if (($udom =~ /^$match_domain$/) &&
7019: (&Apache::lonnet::domain($udom)) &&
7020: ($uname =~ /^$match_username$/)) {
7021: if (!grep(/^\Q$user\E/,@okusers)) {
7022: push(@okusers,$user);
7023: }
7024: }
7025: }
7026: if (@okusers > 0) {
7027: @okusers = sort(@okusers);
7028: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7029: }
7030: }
7031: if (defined($env{'form.'.$type.'_machines'})) {
7032: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7033: my @okmachines;
7034: foreach my $ip (@machines) {
7035: my @parts = split(/\./,$ip);
7036: next if (@parts < 4);
7037: my $badip = 0;
7038: for (my $i=0; $i<4; $i++) {
7039: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7040: $badip = 1;
7041: last;
7042: }
7043: }
7044: if (!$badip) {
7045: push(@okmachines,$ip);
7046: }
7047: }
7048: @okmachines = sort(@okmachines);
7049: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7050: }
7051: }
7052: my %serverstatushash = (
7053: serverstatuses => \%newserverstatus,
7054: );
7055: foreach my $type (@pages) {
1.83 raeburn 7056: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7057: my (@current,@new);
1.83 raeburn 7058: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7059: if ($currserverstatus{$type}{$setting} ne '') {
7060: @current = split(/,/,$currserverstatus{$type}{$setting});
7061: }
7062: }
7063: if ($newserverstatus{$type}{$setting} ne '') {
7064: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7065: }
7066: if (@current > 0) {
7067: if (@new > 0) {
7068: foreach my $item (@current) {
7069: if (!grep(/^\Q$item\E$/,@new)) {
7070: $changes{$type}{$setting} = 1;
1.82 raeburn 7071: last;
7072: }
7073: }
1.84 raeburn 7074: foreach my $item (@new) {
7075: if (!grep(/^\Q$item\E$/,@current)) {
7076: $changes{$type}{$setting} = 1;
7077: last;
1.82 raeburn 7078: }
7079: }
7080: } else {
1.83 raeburn 7081: $changes{$type}{$setting} = 1;
1.69 raeburn 7082: }
1.83 raeburn 7083: } elsif (@new > 0) {
7084: $changes{$type}{$setting} = 1;
1.69 raeburn 7085: }
7086: }
7087: }
7088: if (keys(%changes) > 0) {
1.81 raeburn 7089: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7090: my $putresult = &Apache::lonnet::put_dom('configuration',
7091: \%serverstatushash,$dom);
7092: if ($putresult eq 'ok') {
7093: $resulttext .= &mt('Changes made:').'<ul>';
7094: foreach my $type (@pages) {
1.84 raeburn 7095: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7096: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7097: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7098: if ($newserverstatus{$type}{'namedusers'} eq '') {
7099: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7100: } else {
7101: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7102: }
1.84 raeburn 7103: }
7104: if ($changes{$type}{'machines'}) {
1.69 raeburn 7105: if ($newserverstatus{$type}{'machines'} eq '') {
7106: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7107: } else {
7108: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7109: }
7110:
7111: }
7112: $resulttext .= '</ul></li>';
7113: }
7114: }
7115: $resulttext .= '</ul>';
7116: } else {
7117: $resulttext = '<span class="LC_error">'.
7118: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7119:
7120: }
7121: } else {
7122: $resulttext = &mt('No changes made to access to server status pages');
7123: }
7124: return $resulttext;
7125: }
7126:
1.118 jms 7127: sub modify_helpsettings {
1.122 jms 7128: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 7129: my ($resulttext,$errors,%changes,%helphash);
7130:
1.122 jms 7131: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7132: my $defaulthelpfile = 'defaulthelp.html';
7133: my $servadm = $r->dir_config('lonAdmEMail');
7134: my ($configuserok,$author_ok,$switchserver) =
7135: &config_check($dom,$confname,$servadm);
7136:
1.118 jms 7137: my %defaultchecked = ('submitbugs' => 'on');
7138: my @offon = ('off','on');
1.122 jms 7139: my %title = ( submitbugs => 'Display link for users to submit a bug',
7140: loginhelpurl => 'Unauthenticated login help page set to custom file');
7141:
1.118 jms 7142: my @toggles = ('submitbugs');
7143:
7144: $helphash{'helpsettings'} = {};
7145:
7146: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7147: if ($domconfig{'helpsettings'} eq '') {
7148: $domconfig{'helpsettings'} = {};
7149: }
7150: }
7151:
7152: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7153:
7154: foreach my $item (@toggles) {
7155:
7156: if ($defaultchecked{$item} eq 'on') {
7157: if (($domconfig{'helpsettings'}{$item} eq '') &&
7158: ($env{'form.'.$item} eq '0')) {
7159: $changes{$item} = 1;
7160: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7161: $changes{$item} = 1;
7162: }
7163: } elsif ($defaultchecked{$item} eq 'off') {
7164: if (($domconfig{'helpsettings'}{$item} eq '') &&
7165: ($env{'form.'.$item} eq '1')) {
7166: $changes{$item} = 1;
7167: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7168: $changes{$item} = 1;
7169: }
7170: }
7171: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7172: }
7173:
7174: if ($customhelpfile ne '') {
7175: my $error;
7176: if ($configuserok eq 'ok') {
7177: if ($switchserver) {
7178: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7179: } else {
7180: if ($author_ok eq 'ok') {
7181: my ($result,$loginhelpurl) =
7182: &publishlogo($r,'upload','loginhelpurl',$dom,
7183: $confname,'help','','',$customhelpfile);
7184: if ($result eq 'ok') {
7185: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7186: $changes{'loginhelpurl'} = 1;
7187: } else {
7188: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7189: }
7190: } else {
7191: $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].",$customhelpfile,$confname,$dom,$author_ok);
7192: }
7193: }
7194: } else {
7195: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
7196: }
7197: if ($error) {
7198: &Apache::lonnet::logthis($error);
7199: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7200: }
7201: }
7202:
7203: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7204: if ($env{'form.loginhelpurl_del'}) {
7205: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7206: $changes{'loginhelpurl'} = 1;
7207: }
7208: }
1.118 jms 7209: }
7210:
1.123 jms 7211:
7212: my $putresult;
7213:
7214: if (keys(%changes) > 0) {
7215: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7216: } else {
7217: $putresult = 'ok';
7218: }
1.118 jms 7219:
7220: if ($putresult eq 'ok') {
7221: if (keys(%changes) > 0) {
7222: $resulttext = &mt('Changes made:').'<ul>';
7223: foreach my $item (sort(keys(%changes))) {
7224: if ($item eq 'submitbugs') {
7225: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7226: }
1.122 jms 7227: if ($item eq 'loginhelpurl') {
7228: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7229: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7230: } else {
7231: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7232: }
7233: }
1.118 jms 7234: }
7235: $resulttext .= '</ul>';
7236: } else {
7237: $resulttext = &mt('No changes made to help settings');
7238: }
7239: } else {
7240: $resulttext = '<span class="LC_error">'.
7241: &mt('An error occurred: [_1]',$putresult).'</span>';
7242: }
7243: if ($errors) {
7244: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7245: $errors.'</ul>';
7246: }
7247: return $resulttext;
7248: }
7249:
1.121 raeburn 7250: sub modify_coursedefaults {
7251: my ($dom,%domconfig) = @_;
7252: my ($resulttext,$errors,%changes,%defaultshash);
7253: my %defaultchecked = ('canuse_pdfforms' => 'off');
7254: my @offon = ('off','on');
7255: my @toggles = ('canuse_pdfforms');
7256:
7257: $defaultshash{'coursedefaults'} = {};
7258:
7259: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7260: if ($domconfig{'coursedefaults'} eq '') {
7261: $domconfig{'coursedefaults'} = {};
7262: }
7263: }
7264:
7265: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7266: foreach my $item (@toggles) {
7267: if ($defaultchecked{$item} eq 'on') {
7268: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7269: ($env{'form.'.$item} eq '0')) {
7270: $changes{$item} = 1;
7271: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7272: $changes{$item} = 1;
7273: }
7274: } elsif ($defaultchecked{$item} eq 'off') {
7275: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7276: ($env{'form.'.$item} eq '1')) {
7277: $changes{$item} = 1;
7278: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7279: $changes{$item} = 1;
7280: }
7281: }
7282: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7283: }
1.139 raeburn 7284: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7285: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7286: $newdefresponder =~ s/\D//g;
7287: if ($newdefresponder eq '' || $newdefresponder < 1) {
7288: $newdefresponder = 1;
7289: }
7290: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7291: if ($currdefresponder ne $newdefresponder) {
7292: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7293: $changes{'anonsurvey_threshold'} = 1;
7294: }
7295: }
1.121 raeburn 7296: }
7297: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7298: $dom);
7299: if ($putresult eq 'ok') {
7300: if (keys(%changes) > 0) {
7301: if ($changes{'canuse_pdfforms'}) {
7302: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7303: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7304: my $cachetime = 24*60*60;
7305: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7306: }
7307: $resulttext = &mt('Changes made:').'<ul>';
7308: foreach my $item (sort(keys(%changes))) {
7309: if ($item eq 'canuse_pdfforms') {
7310: if ($env{'form.'.$item} eq '1') {
7311: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7312: } else {
7313: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7314: }
1.139 raeburn 7315: } elsif ($item eq 'anonsurvey_threshold') {
7316: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7317: }
1.121 raeburn 7318: }
7319: $resulttext .= '</ul>';
7320: } else {
7321: $resulttext = &mt('No changes made to course defaults');
7322: }
7323: } else {
7324: $resulttext = '<span class="LC_error">'.
7325: &mt('An error occurred: [_1]',$putresult).'</span>';
7326: }
7327: return $resulttext;
7328: }
7329:
1.137 raeburn 7330: sub modify_usersessions {
7331: my ($dom,%domconfig) = @_;
1.145 raeburn 7332: my @hostingtypes = ('version','excludedomain','includedomain');
7333: my @offloadtypes = ('primary','default');
7334: my %types = (
7335: remote => \@hostingtypes,
7336: hosted => \@hostingtypes,
7337: spares => \@offloadtypes,
7338: );
7339: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7340: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7341: my (%by_ip,%by_location,@intdoms);
7342: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7343: my @locations = sort(keys(%by_location));
1.137 raeburn 7344: my (%defaultshash,%changes);
7345: foreach my $prefix (@prefixes) {
7346: $defaultshash{'usersessions'}{$prefix} = {};
7347: }
7348: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7349: my $resulttext;
1.138 raeburn 7350: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7351: foreach my $prefix (@prefixes) {
1.145 raeburn 7352: next if ($prefix eq 'spares');
7353: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7354: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7355: if ($type eq 'version') {
7356: my $value = $env{'form.'.$prefix.'_'.$type};
7357: my $okvalue;
7358: if ($value ne '') {
7359: if (grep(/^\Q$value\E$/,@lcversions)) {
7360: $okvalue = $value;
7361: }
7362: }
7363: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7364: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7365: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7366: if ($inuse == 0) {
7367: $changes{$prefix}{$type} = 1;
7368: } else {
7369: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7370: $changes{$prefix}{$type} = 1;
7371: }
7372: if ($okvalue ne '') {
7373: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7374: }
7375: }
7376: } else {
7377: if (($inuse == 1) && ($okvalue ne '')) {
7378: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7379: $changes{$prefix}{$type} = 1;
7380: }
7381: }
7382: } else {
7383: if (($inuse == 1) && ($okvalue ne '')) {
7384: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7385: $changes{$prefix}{$type} = 1;
7386: }
7387: }
7388: } else {
7389: if (($inuse == 1) && ($okvalue ne '')) {
7390: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7391: $changes{$prefix}{$type} = 1;
7392: }
7393: }
7394: } else {
7395: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7396: my @okvals;
7397: foreach my $val (@vals) {
1.138 raeburn 7398: if ($val =~ /:/) {
7399: my @items = split(/:/,$val);
7400: foreach my $item (@items) {
7401: if (ref($by_location{$item}) eq 'ARRAY') {
7402: push(@okvals,$item);
7403: }
7404: }
7405: } else {
7406: if (ref($by_location{$val}) eq 'ARRAY') {
7407: push(@okvals,$val);
7408: }
1.137 raeburn 7409: }
7410: }
7411: @okvals = sort(@okvals);
7412: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7413: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7414: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7415: if ($inuse == 0) {
7416: $changes{$prefix}{$type} = 1;
7417: } else {
7418: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7419: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7420: if (@changed > 0) {
7421: $changes{$prefix}{$type} = 1;
7422: }
7423: }
7424: } else {
7425: if ($inuse == 1) {
7426: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7427: $changes{$prefix}{$type} = 1;
7428: }
7429: }
7430: } else {
7431: if ($inuse == 1) {
7432: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7433: $changes{$prefix}{$type} = 1;
7434: }
7435: }
7436: } else {
7437: if ($inuse == 1) {
7438: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7439: $changes{$prefix}{$type} = 1;
7440: }
7441: }
7442: }
7443: }
7444: }
1.145 raeburn 7445:
7446: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7447: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7448: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7449: my $savespares;
7450:
7451: foreach my $lonhost (sort(keys(%servers))) {
7452: my $serverhomeID =
7453: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 7454: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7455: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7456: my %spareschg;
7457: foreach my $type (@{$types{'spares'}}) {
7458: my @okspares;
7459: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7460: foreach my $server (@checked) {
1.152 raeburn 7461: if (&Apache::lonnet::hostname($server) ne '') {
7462: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7463: unless (grep(/^\Q$server\E$/,@okspares)) {
7464: push(@okspares,$server);
7465: }
1.145 raeburn 7466: }
7467: }
7468: }
7469: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7470: my $newspare;
1.152 raeburn 7471: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
7472: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 7473: $newspare = $new;
7474: }
7475: }
1.152 raeburn 7476: my @spares;
7477: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7478: @spares = sort(@okspares,$newspare);
7479: } else {
7480: @spares = sort(@okspares);
7481: }
7482: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 7483: if (ref($spareid{$lonhost}) eq 'HASH') {
7484: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 7485: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 7486: if (@diffs > 0) {
7487: $spareschg{$type} = 1;
7488: }
7489: }
7490: }
7491: }
7492: if (keys(%spareschg) > 0) {
7493: $changes{'spares'}{$lonhost} = \%spareschg;
7494: }
7495: }
7496:
7497: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7498: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7499: if (ref($changes{'spares'}) eq 'HASH') {
7500: if (keys(%{$changes{'spares'}}) > 0) {
7501: $savespares = 1;
7502: }
7503: }
7504: } else {
7505: $savespares = 1;
7506: }
7507: }
7508:
1.147 raeburn 7509: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7510: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 7511: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7512: $dom);
7513: if ($putresult eq 'ok') {
7514: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7515: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7516: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7517: }
7518: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7519: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7520: }
7521: }
7522: my $cachetime = 24*60*60;
7523: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 7524: if (keys(%changes) > 0) {
7525: my %lt = &usersession_titles();
7526: $resulttext = &mt('Changes made:').'<ul>';
7527: foreach my $prefix (@prefixes) {
7528: if (ref($changes{$prefix}) eq 'HASH') {
7529: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7530: if ($prefix eq 'spares') {
7531: if (ref($changes{$prefix}) eq 'HASH') {
7532: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7533: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 7534: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7535: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 7536: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7537: foreach my $type (@{$types{$prefix}}) {
7538: if ($changes{$prefix}{$lonhost}{$type}) {
7539: my $offloadto = &mt('None');
7540: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7541: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7542: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7543: }
1.145 raeburn 7544: }
1.147 raeburn 7545: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 7546: }
1.137 raeburn 7547: }
7548: }
1.147 raeburn 7549: $resulttext .= '</li>';
1.137 raeburn 7550: }
7551: }
1.147 raeburn 7552: } else {
7553: foreach my $type (@{$types{$prefix}}) {
7554: if (defined($changes{$prefix}{$type})) {
7555: my $newvalue;
7556: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7557: if (ref($defaultshash{'usersessions'}{$prefix})) {
7558: if ($type eq 'version') {
7559: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7560: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7561: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7562: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7563: }
1.145 raeburn 7564: }
7565: }
7566: }
1.147 raeburn 7567: if ($newvalue eq '') {
7568: if ($type eq 'version') {
7569: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7570: } else {
7571: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7572: }
1.145 raeburn 7573: } else {
1.147 raeburn 7574: if ($type eq 'version') {
7575: $newvalue .= ' '.&mt('(or later)');
7576: }
7577: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 7578: }
1.137 raeburn 7579: }
7580: }
7581: }
1.147 raeburn 7582: $resulttext .= '</ul>';
1.137 raeburn 7583: }
7584: }
1.147 raeburn 7585: $resulttext .= '</ul>';
7586: } else {
7587: $resulttext = $nochgmsg;
1.137 raeburn 7588: }
7589: } else {
7590: $resulttext = '<span class="LC_error">'.
7591: &mt('An error occurred: [_1]',$putresult).'</span>';
7592: }
7593: } else {
1.147 raeburn 7594: $resulttext = $nochgmsg;
1.137 raeburn 7595: }
7596: return $resulttext;
7597: }
7598:
1.150 raeburn 7599: sub modify_loadbalancing {
7600: my ($dom,%domconfig) = @_;
7601: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7602: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7603: my ($othertitle,$usertypes,$types) =
7604: &Apache::loncommon::sorted_inst_types($dom);
7605: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7606: my @sparestypes = ('primary','default');
7607: my %typetitles = &sparestype_titles();
7608: my $resulttext;
7609: if (keys(%servers) > 1) {
7610: my ($currbalancer,$currtargets,$currrules);
7611: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7612: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7613: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7614: $currrules = $domconfig{'loadbalancing'}{'rules'};
7615: } else {
7616: ($currbalancer,$currtargets) =
7617: &Apache::lonnet::get_lonbalancer_config(\%servers);
7618: }
7619: my ($saveloadbalancing,%defaultshash,%changes);
7620: my ($alltypes,$othertypes,$titles) =
7621: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7622: my %ruletitles = &offloadtype_text();
7623: my $balancer = $env{'form.loadbalancing_lonhost'};
7624: if (!$servers{$balancer}) {
7625: undef($balancer);
7626: }
7627: if ($currbalancer ne $balancer) {
7628: $changes{'lonhost'} = 1;
7629: }
7630: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7631: if ($balancer ne '') {
7632: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7633: $saveloadbalancing = 1;
7634: }
7635: foreach my $sparetype (@sparestypes) {
7636: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151 raeburn 7637: my @offloadto;
1.150 raeburn 7638: foreach my $target (@targets) {
7639: if (($servers{$target}) && ($target ne $balancer)) {
7640: if ($sparetype eq 'default') {
7641: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7642: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7643: }
7644: }
7645: unless(grep(/^\Q$target\E$/,@offloadto)) {
7646: push(@offloadto,$target);
7647: }
7648: }
7649: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7650: }
7651: }
7652: } else {
7653: foreach my $sparetype (@sparestypes) {
7654: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7655: }
7656: }
7657: if (ref($currtargets) eq 'HASH') {
7658: foreach my $sparetype (@sparestypes) {
7659: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7660: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7661: if (@targetdiffs > 0) {
7662: $changes{'targets'} = 1;
7663: }
7664: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7665: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7666: $changes{'targets'} = 1;
7667: }
7668: }
7669: }
7670: } else {
7671: foreach my $sparetype (@sparestypes) {
7672: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7673: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7674: $changes{'targets'} = 1;
7675: }
7676: }
7677: }
7678: }
7679: my $ishomedom;
7680: if ($balancer ne '') {
7681: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7682: $ishomedom = 1;
7683: }
7684: }
7685: if (ref($alltypes) eq 'ARRAY') {
7686: foreach my $type (@{$alltypes}) {
7687: my $rule;
7688: if ($balancer ne '') {
7689: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7690: (!$ishomedom)) {
7691: $rule = $env{'form.loadbalancing_rules_'.$type};
7692: }
7693: if ($rule eq 'specific') {
7694: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7695: }
7696: }
7697: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7698: if (ref($currrules) eq 'HASH') {
7699: if ($rule ne $currrules->{$type}) {
7700: $changes{'rules'}{$type} = 1;
7701: }
7702: } elsif ($rule ne '') {
7703: $changes{'rules'}{$type} = 1;
7704: }
7705: }
7706: }
7707: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7708: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
7709: my $putresult = &Apache::lonnet::put_dom('configuration',
7710: \%defaultshash,$dom);
7711: if ($putresult eq 'ok') {
7712: if (keys(%changes) > 0) {
7713: if ($changes{'lonhost'}) {
7714: if ($currbalancer ne '') {
7715: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
7716: }
7717: if ($balancer eq '') {
7718: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
7719: } else {
7720: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7721: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
7722: }
7723: } else {
7724: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7725: }
7726: if (($changes{'targets'}) && ($balancer ne '')) {
7727: my %offloadstr;
7728: foreach my $sparetype (@sparestypes) {
7729: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7730: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7731: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
7732: }
7733: }
7734: }
7735: if (keys(%offloadstr) == 0) {
7736: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
7737: } else {
7738: my $showoffload;
7739: foreach my $sparetype (@sparestypes) {
7740: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
7741: if (defined($offloadstr{$sparetype})) {
7742: $showoffload .= $offloadstr{$sparetype};
7743: } else {
7744: $showoffload .= &mt('None');
7745: }
7746: $showoffload .= (' 'x3);
7747: }
7748: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
7749: }
7750: }
7751: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
7752: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7753: foreach my $type (@{$alltypes}) {
7754: if ($changes{'rules'}{$type}) {
7755: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
7756: my $balancetext;
7757: if ($rule eq '') {
7758: $balancetext = $ruletitles{'default'};
7759: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
7760: $balancetext = $ruletitles{$rule};
7761: } else {
7762: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
7763: }
7764: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
7765: }
7766: }
7767: }
7768: }
7769: if ($resulttext ne '') {
7770: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
7771: } else {
7772: $resulttext = $nochgmsg;
7773: }
7774: } else {
7775: $resulttext = $nochgmsg;
7776: if ($balancer ne '') {
7777: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7778: }
7779: }
7780: } else {
7781: $resulttext = '<span class="LC_error">'.
7782: &mt('An error occurred: [_1]',$putresult).'</span>';
7783: }
7784: } else {
7785: $resulttext = $nochgmsg;
7786: }
7787: } else {
7788: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
7789: }
7790: return $resulttext;
7791: }
7792:
1.48 raeburn 7793: sub recurse_check {
7794: my ($chkcats,$categories,$depth,$name) = @_;
7795: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7796: my $chg = 0;
7797: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7798: my $category = $chkcats->[$depth]{$name}[$j];
7799: my $item;
7800: if ($category eq '') {
7801: $chg ++;
7802: } else {
7803: my $deeper = $depth + 1;
7804: $item = &escape($category).':'.&escape($name).':'.$depth;
7805: if ($chg) {
7806: $categories->{$item} -= $chg;
7807: }
7808: &recurse_check($chkcats,$categories,$deeper,$category);
7809: $deeper --;
7810: }
7811: }
7812: }
7813: return;
7814: }
7815:
7816: sub recurse_cat_deletes {
7817: my ($item,$coursecategories,$deletions) = @_;
7818: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7819: my $subdepth = $depth + 1;
7820: if (ref($coursecategories) eq 'HASH') {
7821: foreach my $subitem (keys(%{$coursecategories})) {
7822: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7823: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7824: delete($coursecategories->{$subitem});
7825: $deletions->{$subitem} = 1;
7826: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7827: }
7828: }
7829: }
7830: return;
7831: }
7832:
1.125 raeburn 7833: sub get_active_dcs {
7834: my ($dom) = @_;
7835: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7836: my %domcoords;
7837: my $numdcs = 0;
7838: my $now = time;
7839: foreach my $server (keys(%dompersonnel)) {
7840: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7841: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7842: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7843: if (($end eq '') || ($end == 0) || ($end > $now)) {
7844: if ($start <= $now) {
7845: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7846: }
7847: }
7848: }
7849: }
7850: return %domcoords;
7851: }
7852:
7853: sub active_dc_picker {
7854: my ($dom,$curr_dc) = @_;
7855: my %domcoords = &get_active_dcs($dom);
7856: my @dcs = sort(keys(%domcoords));
7857: my $numdcs = scalar(@dcs);
7858: my $datatable;
7859: my $numinrow = 2;
7860: if ($numdcs > 1) {
7861: $datatable = '<table>';
7862: for (my $i=0; $i<@dcs; $i++) {
7863: my $rem = $i%($numinrow);
7864: if ($rem == 0) {
7865: if ($i > 0) {
7866: $datatable .= '</tr>';
7867: }
7868: $datatable .= '<tr>';
7869: }
7870: my $check = ' ';
7871: if ($curr_dc eq '') {
7872: if (!$i) {
7873: $check = ' checked="checked" ';
7874: }
7875: } elsif ($dcs[$i] eq $curr_dc) {
7876: $check = ' checked="checked" ';
7877: }
7878: if ($i == @dcs - 1) {
7879: my $colsleft = $numinrow - $rem;
7880: if ($colsleft > 1) {
7881: $datatable .= '<td colspan="'.$colsleft.'">';
7882: } else {
7883: $datatable .= '<td>';
7884: }
7885: } else {
7886: $datatable .= '<td>';
7887: }
7888: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7889: $datatable .= '<span class="LC_nobreak"><label>'.
7890: '<input type="radio" name="autocreate_xmldc"'.
7891: ' value="'.$dcs[$i].'"'.$check.'/>'.
7892: &Apache::loncommon::plainname($dcname,$dcdom).
7893: '</label></span></td>';
7894: }
7895: $datatable .= '</tr></table>';
7896: } elsif (@dcs) {
7897: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7898: $dcs[0].'" />';
7899: }
7900: return ($numdcs,$datatable);
7901: }
7902:
1.137 raeburn 7903: sub usersession_titles {
7904: return &Apache::lonlocal::texthash(
7905: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7906: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 7907: spares => 'Servers offloaded to, when busy',
1.137 raeburn 7908: version => 'LON-CAPA version requirement',
1.138 raeburn 7909: excludedomain => 'Allow all, but exclude specific domains',
7910: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 7911: primary => 'Primary (checked first)',
1.154 raeburn 7912: default => 'Default',
1.137 raeburn 7913: );
7914: }
7915:
1.152 raeburn 7916: sub id_for_thisdom {
7917: my (%servers) = @_;
7918: my %altids;
7919: foreach my $server (keys(%servers)) {
7920: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7921: if ($serverhome ne $server) {
7922: $altids{$serverhome} = $server;
7923: }
7924: }
7925: return %altids;
7926: }
7927:
1.150 raeburn 7928: sub count_servers {
7929: my ($currbalancer,%servers) = @_;
7930: my (@spares,$numspares);
7931: foreach my $lonhost (sort(keys(%servers))) {
7932: next if ($currbalancer eq $lonhost);
7933: push(@spares,$lonhost);
7934: }
7935: if ($currbalancer) {
7936: $numspares = scalar(@spares);
7937: } else {
7938: $numspares = scalar(@spares) - 1;
7939: }
7940: return ($numspares,@spares);
7941: }
7942:
7943: sub lonbalance_targets_js {
7944: my ($dom,$types,$servers) = @_;
7945: my $select = &mt('Select');
7946: my ($alltargets,$allishome,$allinsttypes,@alltypes);
7947: if (ref($servers) eq 'HASH') {
7948: $alltargets = join("','",sort(keys(%{$servers})));
7949: my @homedoms;
7950: foreach my $server (sort(keys(%{$servers}))) {
7951: if (&Apache::lonnet::host_domain($server) eq $dom) {
7952: push(@homedoms,'1');
7953: } else {
7954: push(@homedoms,'0');
7955: }
7956: }
7957: $allishome = join("','",@homedoms);
7958: }
7959: if (ref($types) eq 'ARRAY') {
7960: if (@{$types} > 0) {
7961: @alltypes = @{$types};
7962: }
7963: }
7964: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
7965: $allinsttypes = join("','",@alltypes);
7966: return <<"END";
7967:
7968: <script type="text/javascript">
7969: // <![CDATA[
7970:
7971: function toggleTargets() {
7972: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
7973: if (balancer == '') {
7974: hideSpares();
7975: } else {
7976: var homedoms = new Array('$allishome');
7977: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
7978: showSpares(balancer,ishomedom);
7979: }
7980: return;
7981: }
7982:
7983: function showSpares(balancer,ishomedom) {
7984: var alltargets = new Array('$alltargets');
7985: var insttypes = new Array('$allinsttypes');
1.151 raeburn 7986: var offloadtypes = new Array('primary','default');
7987:
1.150 raeburn 7988: document.getElementById('loadbalancing_targets').style.display='block';
7989: document.getElementById('loadbalancing_disabled').style.display='none';
1.152 raeburn 7990:
1.151 raeburn 7991: for (var i=0; i<offloadtypes.length; i++) {
7992: var count = 0;
7993: for (var j=0; j<alltargets.length; j++) {
7994: if (alltargets[j] != balancer) {
7995: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
7996: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
7997: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
7998: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
7999: count ++;
8000: }
1.150 raeburn 8001: }
8002: }
1.151 raeburn 8003: for (var k=0; k<insttypes.length; k++) {
8004: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8005: if (ishomedom == 1) {
1.151 raeburn 8006: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8007: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8008: } else {
1.151 raeburn 8009: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8010: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150 raeburn 8011:
8012: }
8013: } else {
1.151 raeburn 8014: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8015: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8016: }
1.151 raeburn 8017: if ((insttypes[k] != '_LC_external') &&
8018: ((insttypes[k] != '_LC_internetdom') ||
8019: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8020: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8021: for (var m=0; m<alltargets.length; m++) {
8022: var idx = m+1;
8023: if (alltargets[m] != balancer) {
8024: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 8025: }
8026: }
8027: }
8028: }
8029: return;
8030: }
8031:
8032: function hideSpares() {
8033: var alltargets = new Array('$alltargets');
8034: var insttypes = new Array('$allinsttypes');
8035: var offloadtypes = new Array('primary','default');
8036:
8037: document.getElementById('loadbalancing_targets').style.display='none';
8038: document.getElementById('loadbalancing_disabled').style.display='block';
8039:
8040: var total = alltargets.length - 1;
8041: for (var i=0; i<offloadtypes; i++) {
8042: for (var j=0; j<total; j++) {
8043: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8044: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8045: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8046: }
1.150 raeburn 8047: }
8048: for (var k=0; k<insttypes.length; k++) {
1.151 raeburn 8049: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8050: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8051: if (insttypes[k] != '_LC_external') {
8052: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8053: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8054: }
8055: }
8056: return;
8057: }
8058:
8059: function checkOffloads(item,type) {
8060: var alltargets = new Array('$alltargets');
8061: var offloadtypes = new Array('primary','default');
8062: if (item.checked) {
8063: var total = alltargets.length - 1;
8064: var other;
8065: if (type == offloadtypes[0]) {
1.151 raeburn 8066: other = offloadtypes[1];
1.150 raeburn 8067: } else {
1.151 raeburn 8068: other = offloadtypes[0];
1.150 raeburn 8069: }
8070: for (var i=0; i<total; i++) {
8071: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8072: if (server == item.value) {
8073: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8074: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8075: }
8076: }
8077: }
8078: }
8079: return;
8080: }
8081:
8082: function singleServerToggle(type) {
8083: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8084: if (offloadtoSelIdx == 0) {
8085: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8086: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8087:
8088: } else {
8089: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8090: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8091: }
8092: return;
8093: }
8094:
8095: function balanceruleChange(formname,type) {
8096: if (type == '_LC_external') {
8097: return;
8098: }
8099: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8100: for (var i=0; i<typesRules.length; i++) {
8101: if (formname.elements[typesRules[i]].checked) {
8102: if (formname.elements[typesRules[i]].value != 'specific') {
8103: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8104: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8105: } else {
8106: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8107: }
8108: }
8109: }
8110: return;
8111: }
8112:
1.152 raeburn 8113: // ]]>
8114: </script>
8115:
8116: END
8117: }
8118:
8119: sub new_spares_js {
8120: my @sparestypes = ('primary','default');
8121: my $types = join("','",@sparestypes);
8122: my $select = &mt('Select');
8123: return <<"END";
8124:
8125: <script type="text/javascript">
8126: // <![CDATA[
8127:
8128: function updateNewSpares(formname,lonhost) {
8129: var types = new Array('$types');
8130: var include = new Array();
8131: var exclude = new Array();
8132: for (var i=0; i<types.length; i++) {
8133: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8134: for (var j=0; j<spareboxes.length; j++) {
8135: if (formname.elements[spareboxes[j]].checked) {
8136: exclude.push(formname.elements[spareboxes[j]].value);
8137: } else {
8138: include.push(formname.elements[spareboxes[j]].value);
8139: }
8140: }
8141: }
8142: for (var i=0; i<types.length; i++) {
8143: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8144: var selIdx = newSpare.selectedIndex;
8145: var currnew = newSpare.options[selIdx].value;
8146: var okSpares = new Array();
8147: for (var j=0; j<newSpare.options.length; j++) {
8148: var possible = newSpare.options[j].value;
8149: if (possible != '') {
8150: if (exclude.indexOf(possible) == -1) {
8151: okSpares.push(possible);
8152: } else {
8153: if (currnew == possible) {
8154: selIdx = 0;
8155: }
8156: }
8157: }
8158: }
8159: for (var k=0; k<include.length; k++) {
8160: if (okSpares.indexOf(include[k]) == -1) {
8161: okSpares.push(include[k]);
8162: }
8163: }
8164: okSpares.sort();
8165: newSpare.options.length = 0;
8166: if (selIdx == 0) {
8167: newSpare.options[0] = new Option("$select","",true,true);
8168: } else {
8169: newSpare.options[0] = new Option("$select","",false,false);
8170: }
8171: for (var m=0; m<okSpares.length; m++) {
8172: var idx = m+1;
8173: var selThis = 0;
8174: if (selIdx != 0) {
8175: if (okSpares[m] == currnew) {
8176: selThis = 1;
8177: }
8178: }
8179: if (selThis == 1) {
8180: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8181: } else {
8182: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8183: }
8184: }
8185: }
8186: return;
8187: }
8188:
8189: function checkNewSpares(lonhost,type) {
8190: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8191: var chosen = newSpare.options[newSpare.selectedIndex].value;
8192: if (chosen != '') {
8193: var othertype;
8194: var othernewSpare;
8195: if (type == 'primary') {
8196: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8197: }
8198: if (type == 'default') {
8199: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8200: }
8201: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8202: othernewSpare.selectedIndex = 0;
8203: }
8204: }
8205: return;
8206: }
8207:
8208: // ]]>
8209: </script>
8210:
8211: END
8212:
8213: }
8214:
8215: sub common_domprefs_js {
8216: return <<"END";
8217:
8218: <script type="text/javascript">
8219: // <![CDATA[
8220:
1.150 raeburn 8221: function getIndicesByName(formname,item) {
1.152 raeburn 8222: var group = new Array();
1.150 raeburn 8223: for (var i=0;i<formname.elements.length;i++) {
8224: if (formname.elements[i].name == item) {
1.152 raeburn 8225: group.push(formname.elements[i].id);
1.150 raeburn 8226: }
8227: }
1.152 raeburn 8228: return group;
1.150 raeburn 8229: }
8230:
8231: // ]]>
8232: </script>
8233:
8234: END
1.152 raeburn 8235:
1.150 raeburn 8236: }
8237:
1.3 raeburn 8238: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>