Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.1
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.1! raeburn 4: # $Id: domainprefs.pm,v 1.160 2011/11/30 18:31:04 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);
530: $output .= '
1.6 raeburn 531: </table>
532: </td>
533: </tr>
534: <tr>
535: <td>
536: <table class="LC_nested">
537: <tr class="LC_info_row">
1.59 bisitz 538: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 539: $output .= '
1.59 bisitz 540: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 541: </tr>';
542: $rowtotal ++;
1.6 raeburn 543: if ($action eq 'autoupdate') {
1.131 raeburn 544: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
545: </table>
546: </td>
547: </tr>
548: <tr>
549: <td>
550: <table class="LC_nested">
551: <tr class="LC_info_row">
552: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
553: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
554: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
555: $rowtotal ++;
1.28 raeburn 556: } elsif ($action eq 'usercreation') {
1.34 raeburn 557: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
558: </table>
559: </td>
560: </tr>
561: <tr>
562: <td>
563: <table class="LC_nested">
564: <tr class="LC_info_row">
1.59 bisitz 565: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
566: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 567: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
568: $rowtotal ++;
1.33 raeburn 569: } elsif ($action eq 'usermodification') {
1.63 raeburn 570: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
571: </table>
572: </td>
573: </tr>
574: <tr>
575: <td>
576: <table class="LC_nested">
577: <tr class="LC_info_row">
578: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
579: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
580: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
581: $rowtotal ++;
1.57 raeburn 582: } elsif ($action eq 'coursecategories') {
583: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 584: } elsif ($action eq 'login') {
585: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 586: } elsif ($action eq 'requestcourses') {
587: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122 jms 588: } elsif ($action eq 'helpsettings') {
589: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 590: } elsif ($action eq 'usersessions') {
1.145 raeburn 591: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
592: </table>
593: </td>
594: </tr>
595: <tr>
596: <td>
597: <table class="LC_nested">
598: <tr class="LC_info_row">
599: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
600: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
601: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
602: $rowtotal ++;
1.139 raeburn 603: } elsif ($action eq 'coursedefaults') {
604: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 605: } elsif ($action eq 'rolecolors') {
1.30 raeburn 606: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 607: </table>
608: </td>
609: </tr>
610: <tr>
611: <td>
612: <table class="LC_nested">
613: <tr class="LC_info_row">
1.69 raeburn 614: <td class="LC_left_item"'.$colspan.' valign="top">'.
615: &mt($item->{'header'}->[2]->{'col1'}).'</td>
616: <td class="LC_right_item" valign="top">'.
617: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 618: </tr>'.
1.30 raeburn 619: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 620: </table>
621: </td>
622: </tr>
623: <tr>
624: <td>
625: <table class="LC_nested">
626: <tr class="LC_info_row">
1.59 bisitz 627: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
628: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 629: </tr>'.
1.30 raeburn 630: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
631: $rowtotal += 2;
1.6 raeburn 632: }
1.3 raeburn 633: } else {
1.30 raeburn 634: $output .= '
1.3 raeburn 635: <tr>
636: <td>
637: <table class="LC_nested">
1.30 raeburn 638: <tr class="LC_info_row">';
1.24 raeburn 639: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 640: $output .= '
1.59 bisitz 641: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 642: } elsif ($action eq 'serverstatuses') {
643: $output .= '
644: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
645: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
646:
1.6 raeburn 647: } else {
1.30 raeburn 648: $output .= '
1.69 raeburn 649: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
650: }
1.72 raeburn 651: if (defined($item->{'header'}->[0]->{'col3'})) {
652: $output .= '<td class="LC_left_item" valign="top">'.
653: &mt($item->{'header'}->[0]->{'col2'});
654: if ($action eq 'serverstatuses') {
655: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
656: }
1.69 raeburn 657: } else {
658: $output .= '<td class="LC_right_item" valign="top">'.
659: &mt($item->{'header'}->[0]->{'col2'});
660: }
661: $output .= '</td>';
662: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 663: if (defined($item->{'header'}->[0]->{'col4'})) {
664: $output .= '<td class="LC_left_item" valign="top">'.
665: &mt($item->{'header'}->[0]->{'col3'});
666: } else {
667: $output .= '<td class="LC_right_item" valign="top">'.
668: &mt($item->{'header'}->[0]->{'col3'});
669: }
1.69 raeburn 670: if ($action eq 'serverstatuses') {
671: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
672: }
673: $output .= '</td>';
1.6 raeburn 674: }
1.150 raeburn 675: if ($item->{'header'}->[0]->{'col4'}) {
676: $output .= '<td class="LC_right_item" valign="top">'.
677: &mt($item->{'header'}->[0]->{'col4'});
678: }
1.69 raeburn 679: $output .= '</tr>';
1.48 raeburn 680: $rowtotal ++;
1.3 raeburn 681: if ($action eq 'login') {
1.110 raeburn 682: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
683: \$rowtotal);
1.3 raeburn 684: } elsif ($action eq 'quotas') {
1.86 raeburn 685: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 686: } elsif ($action eq 'autoenroll') {
1.30 raeburn 687: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 688: } elsif ($action eq 'autocreate') {
689: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 690: } elsif ($action eq 'directorysrch') {
1.30 raeburn 691: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 692: } elsif ($action eq 'contacts') {
1.30 raeburn 693: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 694: } elsif ($action eq 'defaults') {
695: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 696: } elsif ($action eq 'scantron') {
697: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 698: } elsif ($action eq 'serverstatuses') {
699: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 700: } elsif ($action eq 'helpsettings') {
1.122 jms 701: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150 raeburn 702: } elsif ($action eq 'loadbalancing') {
703: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 704: }
1.3 raeburn 705: }
1.30 raeburn 706: $output .= '
1.3 raeburn 707: </table>
708: </td>
709: </tr>
1.30 raeburn 710: </table><br />';
711: return ($output,$rowtotal);
1.1 raeburn 712: }
713:
1.3 raeburn 714: sub print_login {
1.110 raeburn 715: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
716: my ($css_class,$datatable);
1.6 raeburn 717: my %choices = &login_choices();
1.110 raeburn 718:
719: if ($position eq 'top') {
1.149 raeburn 720: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 721: my $choice = $choices{'disallowlogin'};
722: $css_class = ' class="LC_odd_row"';
1.128 raeburn 723: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 724: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 725: '<th>'.$choices{'server'}.'</th>'.
726: '<th>'.$choices{'serverpath'}.'</th>'.
727: '<th>'.$choices{'custompath'}.'</th>'.
728: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 729: my %disallowed;
730: if (ref($settings) eq 'HASH') {
731: if (ref($settings->{'loginvia'}) eq 'HASH') {
732: %disallowed = %{$settings->{'loginvia'}};
733: }
734: }
735: foreach my $lonhost (sort(keys(%servers))) {
736: my $direct = 'selected="selected"';
1.128 raeburn 737: if (ref($disallowed{$lonhost}) eq 'HASH') {
738: if ($disallowed{$lonhost}{'server'} ne '') {
739: $direct = '';
740: }
1.110 raeburn 741: }
1.115 raeburn 742: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 743: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 744: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
745: '</option>';
746: foreach my $hostid (keys(%servers)) {
1.115 raeburn 747: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 748: my $selected = '';
1.128 raeburn 749: if (ref($disallowed{$lonhost}) eq 'HASH') {
750: if ($hostid eq $disallowed{$lonhost}{'server'}) {
751: $selected = 'selected="selected"';
752: }
1.110 raeburn 753: }
754: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
755: $servers{$hostid}.'</option>';
756: }
1.128 raeburn 757: $datatable .= '</select></td>'.
758: '<td><select name="'.$lonhost.'_serverpath">';
759: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
760: my $pathname = $path;
761: if ($path eq 'custom') {
762: $pathname = &mt('Custom Path').' ->';
763: }
764: my $selected = '';
765: if (ref($disallowed{$lonhost}) eq 'HASH') {
766: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
767: $selected = 'selected="selected"';
768: }
769: } elsif ($path eq '') {
770: $selected = 'selected="selected"';
771: }
772: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
773: }
774: $datatable .= '</select></td>';
775: my ($custom,$exempt);
776: if (ref($disallowed{$lonhost}) eq 'HASH') {
777: $custom = $disallowed{$lonhost}{'custompath'};
778: $exempt = $disallowed{$lonhost}{'exempt'};
779: }
780: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
781: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
782: '</tr>';
1.110 raeburn 783: }
784: $datatable .= '</table></td></tr>';
785: return $datatable;
786: }
787:
1.42 raeburn 788: my %defaultchecked = (
1.43 raeburn 789: 'coursecatalog' => 'on',
790: 'adminmail' => 'off',
791: 'newuser' => 'off',
792: );
1.118 jms 793: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 794: my (%checkedon,%checkedoff);
795: foreach my $item (@toggles) {
796: if ($defaultchecked{$item} eq 'on') {
797: $checkedon{$item} = ' checked="checked" ';
798: $checkedoff{$item} = ' ';
799: } elsif ($defaultchecked{$item} eq 'off') {
800: $checkedoff{$item} = ' checked="checked" ';
801: $checkedon{$item} = ' ';
802: }
803: }
1.41 raeburn 804: my @images = ('img','logo','domlogo','login');
805: my @logintext = ('textcol','bgcol');
1.6 raeburn 806: my @bgs = ('pgbg','mainbg','sidebg');
807: my @links = ('link','alink','vlink');
1.7 albertel 808: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 809: my %defaultdesign = %Apache::loncommon::defaultdesign;
810: my (%is_custom,%designs);
811: my %defaults = (
812: font => $defaultdesign{'login.font'},
813: );
814: foreach my $item (@images) {
815: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 816: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 817: }
818: foreach my $item (@bgs) {
819: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
820: }
1.41 raeburn 821: foreach my $item (@logintext) {
822: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
823: }
1.6 raeburn 824: foreach my $item (@links) {
825: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
826: }
1.3 raeburn 827: if (ref($settings) eq 'HASH') {
1.42 raeburn 828: foreach my $item (@toggles) {
829: if ($settings->{$item} eq '1') {
830: $checkedon{$item} = ' checked="checked" ';
831: $checkedoff{$item} = ' ';
832: } elsif ($settings->{$item} eq '0') {
833: $checkedoff{$item} = ' checked="checked" ';
834: $checkedon{$item} = ' ';
835: }
1.1 raeburn 836: }
1.6 raeburn 837: foreach my $item (@images) {
1.70 raeburn 838: if (defined($settings->{$item})) {
1.6 raeburn 839: $designs{$item} = $settings->{$item};
840: $is_custom{$item} = 1;
841: }
1.70 raeburn 842: if (defined($settings->{'showlogo'}{$item})) {
843: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
844: }
1.6 raeburn 845: }
1.41 raeburn 846: foreach my $item (@logintext) {
847: if ($settings->{$item} ne '') {
848: $designs{'logintext'}{$item} = $settings->{$item};
849: $is_custom{$item} = 1;
850: }
851: }
1.6 raeburn 852: if ($settings->{'font'} ne '') {
853: $designs{'font'} = $settings->{'font'};
854: $is_custom{'font'} = 1;
855: }
856: foreach my $item (@bgs) {
857: if ($settings->{$item} ne '') {
858: $designs{'bgs'}{$item} = $settings->{$item};
859: $is_custom{$item} = 1;
860: }
861: }
862: foreach my $item (@links) {
863: if ($settings->{$item} ne '') {
864: $designs{'links'}{$item} = $settings->{$item};
865: $is_custom{$item} = 1;
866: }
867: }
868: } else {
869: if ($designhash{$dom.'.login.font'} ne '') {
870: $designs{'font'} = $designhash{$dom.'.login.font'};
871: $is_custom{'font'} = 1;
872: }
1.8 raeburn 873: foreach my $item (@images) {
874: if ($designhash{$dom.'.login.'.$item} ne '') {
875: $designs{$item} = $designhash{$dom.'.login.'.$item};
876: $is_custom{$item} = 1;
877: }
878: }
1.6 raeburn 879: foreach my $item (@bgs) {
880: if ($designhash{$dom.'.login.'.$item} ne '') {
881: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
882: $is_custom{$item} = 1;
883: }
884: }
885: foreach my $item (@links) {
886: if ($designhash{$dom.'.login.'.$item} ne '') {
887: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
888: $is_custom{$item} = 1;
889: }
890: }
1.1 raeburn 891: }
1.6 raeburn 892: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
893: logo => 'Institution Logo',
1.41 raeburn 894: domlogo => 'Domain Logo',
895: login => 'Login box');
1.6 raeburn 896: my $itemcount = 1;
1.42 raeburn 897: foreach my $item (@toggles) {
898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
899: $datatable .=
900: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
901: '</td><td>'.
902: '<span class="LC_nobreak"><label><input type="radio" name="'.
903: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
904: '</label> <label><input type="radio" name="'.$item.'"'.
905: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
906: '</tr>';
907: $itemcount ++;
908: }
1.135 bisitz 909: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 910: $datatable .= '</tr></table></td></tr>';
911: return $datatable;
912: }
913:
914: sub login_choices {
915: my %choices =
916: &Apache::lonlocal::texthash (
1.116 bisitz 917: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 918: adminmail => "Display Administrator's E-mail Address?",
919: disallowlogin => "Login page requests redirected",
920: hostid => "Server",
1.128 raeburn 921: server => "Redirect to:",
922: serverpath => "Path",
923: custompath => "Custom",
924: exempt => "Exempt IP(s)",
1.110 raeburn 925: directlogin => "No redirect",
926: newuser => "Link to create a user account",
927: img => "Header",
928: logo => "Main Logo",
929: domlogo => "Domain Logo",
930: login => "Log-in Header",
931: textcol => "Text color",
932: bgcol => "Box color",
933: bgs => "Background colors",
934: links => "Link colors",
935: font => "Font color",
936: pgbg => "Header",
937: mainbg => "Page",
938: sidebg => "Login box",
939: link => "Link",
940: alink => "Active link",
941: vlink => "Visited link",
1.6 raeburn 942: );
943: return %choices;
944: }
945:
946: sub print_rolecolors {
1.30 raeburn 947: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 948: my %choices = &color_font_choices();
949: my @bgs = ('pgbg','tabbg','sidebg');
950: my @links = ('link','alink','vlink');
951: my @images = ('img');
952: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 953: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 954: my %defaultdesign = %Apache::loncommon::defaultdesign;
955: my (%is_custom,%designs);
956: my %defaults = (
957: img => $defaultdesign{$role.'.img'},
958: font => $defaultdesign{$role.'.font'},
1.97 tempelho 959: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 960: );
961: foreach my $item (@bgs) {
962: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
963: }
964: foreach my $item (@links) {
965: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
966: }
967: if (ref($settings) eq 'HASH') {
968: if (ref($settings->{$role}) eq 'HASH') {
969: if ($settings->{$role}->{'img'} ne '') {
970: $designs{'img'} = $settings->{$role}->{'img'};
971: $is_custom{'img'} = 1;
972: }
973: if ($settings->{$role}->{'font'} ne '') {
974: $designs{'font'} = $settings->{$role}->{'font'};
975: $is_custom{'font'} = 1;
976: }
1.97 tempelho 977: if ($settings->{$role}->{'fontmenu'} ne '') {
978: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
979: $is_custom{'fontmenu'} = 1;
980: }
1.6 raeburn 981: foreach my $item (@bgs) {
982: if ($settings->{$role}->{$item} ne '') {
983: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
984: $is_custom{$item} = 1;
985: }
986: }
987: foreach my $item (@links) {
988: if ($settings->{$role}->{$item} ne '') {
989: $designs{'links'}{$item} = $settings->{$role}->{$item};
990: $is_custom{$item} = 1;
991: }
992: }
993: }
994: } else {
995: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
996: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
997: $is_custom{'img'} = 1;
998: }
1.97 tempelho 999: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1000: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1001: $is_custom{'fontmenu'} = 1;
1002: }
1.6 raeburn 1003: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1004: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1005: $is_custom{'font'} = 1;
1006: }
1007: foreach my $item (@bgs) {
1008: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1009: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1010: $is_custom{$item} = 1;
1011:
1012: }
1013: }
1014: foreach my $item (@links) {
1015: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1016: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1017: $is_custom{$item} = 1;
1018: }
1019: }
1020: }
1021: my $itemcount = 1;
1.30 raeburn 1022: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1023: $datatable .= '</tr></table></td></tr>';
1024: return $datatable;
1025: }
1026:
1027: sub display_color_options {
1.9 raeburn 1028: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1029: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1030: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1031: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1032: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1033: '<td>'.$choices->{'font'}.'</td>';
1034: if (!$is_custom->{'font'}) {
1.30 raeburn 1035: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1036: } else {
1037: $datatable .= '<td> </td>';
1038: }
1039: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1040: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1041: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1042: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1043: ' <span id="css_'.$role.'_font" style="background-color: '.
1044: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1045: '</span></td></tr>';
1.107 raeburn 1046: unless ($role eq 'login') {
1047: $datatable .= '<tr'.$css_class.'>'.
1048: '<td>'.$choices->{'fontmenu'}.'</td>';
1049: if (!$is_custom->{'fontmenu'}) {
1050: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1051: } else {
1052: $datatable .= '<td> </td>';
1053: }
1054: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1055: $datatable .= '<td><span class="LC_nobreak">'.
1056: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1057: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1058: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1059: $designs->{'fontmenu'}.';"> </span>'.
1060: '</span></td></tr>';
1.97 tempelho 1061: }
1.9 raeburn 1062: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1063: foreach my $img (@{$images}) {
1.18 albertel 1064: $itemcount ++;
1.6 raeburn 1065: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1066: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1067: '<td>'.$choices->{$img};
1.41 raeburn 1068: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1069: if ($role eq 'login') {
1070: if ($img eq 'login') {
1071: $login_hdr_pick =
1.135 bisitz 1072: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1073: $logincolors =
1074: &login_text_colors($img,$role,$logintext,$phase,$choices,
1075: $designs);
1076: } elsif ($img ne 'domlogo') {
1077: $datatable.= &logo_display_options($img,$defaults,$designs);
1078: }
1079: }
1080: $datatable .= '</td>';
1.6 raeburn 1081: if ($designs->{$img} ne '') {
1082: $imgfile = $designs->{$img};
1.18 albertel 1083: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1084: } else {
1085: $imgfile = $defaults->{$img};
1086: }
1087: if ($imgfile) {
1.9 raeburn 1088: my ($showfile,$fullsize);
1089: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1090: my $urldir = $1;
1091: my $filename = $2;
1092: my @info = &Apache::lonnet::stat_file($designs->{$img});
1093: if (@info) {
1094: my $thumbfile = 'tn-'.$filename;
1095: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1096: if (@thumb) {
1097: $showfile = $urldir.'/'.$thumbfile;
1098: } else {
1099: $showfile = $imgfile;
1100: }
1101: } else {
1102: $showfile = '';
1103: }
1104: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1105: $showfile = $imgfile;
1.6 raeburn 1106: my $imgdir = $1;
1107: my $filename = $2;
1.159 raeburn 1108: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1109: $showfile = "/$imgdir/tn-".$filename;
1110: } else {
1.159 raeburn 1111: my $input = $londocroot.$imgfile;
1112: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1113: if (!-e $output) {
1.9 raeburn 1114: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1115: my ($fullwidth,$fullheight) = &check_dimensions($input);
1116: if ($fullwidth ne '' && $fullheight ne '') {
1117: if ($fullwidth > $width && $fullheight > $height) {
1118: my $size = $width.'x'.$height;
1119: system("convert -sample $size $input $output");
1.159 raeburn 1120: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1121: }
1122: }
1.6 raeburn 1123: }
1124: }
1.16 raeburn 1125: }
1.6 raeburn 1126: if ($showfile) {
1.40 raeburn 1127: if ($showfile =~ m{^/(adm|res)/}) {
1128: if ($showfile =~ m{^/res/}) {
1129: my $local_showfile =
1130: &Apache::lonnet::filelocation('',$showfile);
1131: &Apache::lonnet::repcopy($local_showfile);
1132: }
1133: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1134: }
1135: if ($imgfile) {
1136: if ($imgfile =~ m{^/(adm|res)/}) {
1137: if ($imgfile =~ m{^/res/}) {
1138: my $local_imgfile =
1139: &Apache::lonnet::filelocation('',$imgfile);
1140: &Apache::lonnet::repcopy($local_imgfile);
1141: }
1142: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1143: } else {
1144: $fullsize = $imgfile;
1145: }
1146: }
1.41 raeburn 1147: $datatable .= '<td>';
1148: if ($img eq 'login') {
1.135 bisitz 1149: $datatable .= $login_hdr_pick;
1150: }
1.41 raeburn 1151: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1152: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1153: } else {
1154: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1155: &mt('Upload:');
1156: }
1157: } else {
1158: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1159: &mt('Upload:');
1160: }
1.9 raeburn 1161: if ($switchserver) {
1162: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1163: } else {
1.135 bisitz 1164: if ($img ne 'login') { # suppress file selection for Log-in header
1165: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1166: }
1.9 raeburn 1167: }
1168: $datatable .= '</td></tr>';
1.6 raeburn 1169: }
1170: $itemcount ++;
1171: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1172: $datatable .= '<tr'.$css_class.'>'.
1173: '<td>'.$choices->{'bgs'}.'</td>';
1174: my $bgs_def;
1175: foreach my $item (@{$bgs}) {
1176: if (!$is_custom->{$item}) {
1.70 raeburn 1177: $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 1178: }
1179: }
1180: if ($bgs_def) {
1.8 raeburn 1181: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1182: } else {
1183: $datatable .= '<td> </td>';
1184: }
1185: $datatable .= '<td class="LC_right_item">'.
1186: '<table border="0"><tr>';
1187: foreach my $item (@{$bgs}) {
1188: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1189: $datatable .= '<td align="center">'.$link;
1190: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1191: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1192: }
1193: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1194: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1195: }
1196: $datatable .= '</tr></table></td></tr>';
1197: $itemcount ++;
1198: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1199: $datatable .= '<tr'.$css_class.'>'.
1200: '<td>'.$choices->{'links'}.'</td>';
1201: my $links_def;
1202: foreach my $item (@{$links}) {
1203: if (!$is_custom->{$item}) {
1.30 raeburn 1204: $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 1205: }
1206: }
1207: if ($links_def) {
1.8 raeburn 1208: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1209: } else {
1210: $datatable .= '<td> </td>';
1211: }
1212: $datatable .= '<td class="LC_right_item">'.
1213: '<table border="0"><tr>';
1214: foreach my $item (@{$links}) {
1.30 raeburn 1215: $datatable .= '<td align="center">'."\n".
1216: &color_pick($phase,$role,$item,$choices->{$item},
1217: $designs->{'links'}{$item});
1.6 raeburn 1218: if ($designs->{'links'}{$item}) {
1.30 raeburn 1219: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1220: }
1221: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1222: '" /></td>';
1223: }
1.30 raeburn 1224: $$rowtotal += $itemcount;
1.3 raeburn 1225: return $datatable;
1226: }
1227:
1.70 raeburn 1228: sub logo_display_options {
1229: my ($img,$defaults,$designs) = @_;
1230: my $checkedon;
1231: if (ref($defaults) eq 'HASH') {
1232: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1233: if ($defaults->{'showlogo'}{$img}) {
1234: $checkedon = 'checked="checked" ';
1235: }
1236: }
1237: }
1238: if (ref($designs) eq 'HASH') {
1239: if (ref($designs->{'showlogo'}) eq 'HASH') {
1240: if (defined($designs->{'showlogo'}{$img})) {
1241: if ($designs->{'showlogo'}{$img} == 0) {
1242: $checkedon = '';
1243: } elsif ($designs->{'showlogo'}{$img} == 1) {
1244: $checkedon = 'checked="checked" ';
1245: }
1246: }
1247: }
1248: }
1249: return '<br /><label> <input type="checkbox" name="'.
1250: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1251: &mt('show').'</label>'."\n";
1252: }
1253:
1.41 raeburn 1254: sub login_header_options {
1.135 bisitz 1255: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1256: my $output = '';
1.41 raeburn 1257: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1258: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1259: if (!$is_custom->{'textcol'}) {
1260: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1261: ' ';
1262: }
1263: if (!$is_custom->{'bgcol'}) {
1264: $output .= $choices->{'bgcol'}.': '.
1265: '<span id="css_'.$role.'_font" style="background-color: '.
1266: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1267: }
1268: $output .= '<br />';
1269: }
1270: $output .='<br />';
1271: return $output;
1272: }
1273:
1274: sub login_text_colors {
1275: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1276: my $color_menu = '<table border="0"><tr>';
1277: foreach my $item (@{$logintext}) {
1278: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1279: $color_menu .= '<td align="center">'.$link;
1280: if ($designs->{'logintext'}{$item}) {
1281: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1282: }
1283: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1284: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1285: '<td> </td>';
1286: }
1287: $color_menu .= '</tr></table><br />';
1288: return $color_menu;
1289: }
1290:
1291: sub image_changes {
1292: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1293: my $output;
1.135 bisitz 1294: if ($img eq 'login') {
1295: # suppress image for Log-in header
1296: } elsif (!$is_custom) {
1.70 raeburn 1297: if ($img ne 'domlogo') {
1.41 raeburn 1298: $output .= &mt('Default image:').'<br />';
1299: } else {
1300: $output .= &mt('Default in use:').'<br />';
1301: }
1302: }
1.135 bisitz 1303: if ($img eq 'login') { # suppress image for Log-in header
1304: $output .= '<td>'.$logincolors;
1.41 raeburn 1305: } else {
1.135 bisitz 1306: if ($img_import) {
1307: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1308: }
1309: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1310: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1311: if ($is_custom) {
1312: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1313: '<input type="checkbox" name="'.
1314: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1315: '</label> '.&mt('Replace:').'</span><br />';
1316: } else {
1317: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1318: }
1.41 raeburn 1319: }
1320: return $output;
1321: }
1322:
1.6 raeburn 1323: sub color_pick {
1324: my ($phase,$role,$item,$desc,$curcol) = @_;
1325: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1326: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1327: ');">'.$desc.'</a>';
1328: return $link;
1329: }
1330:
1.3 raeburn 1331: sub print_quotas {
1.86 raeburn 1332: my ($dom,$settings,$rowtotal,$action) = @_;
1333: my $context;
1334: if ($action eq 'quotas') {
1335: $context = 'tools';
1336: } else {
1337: $context = $action;
1338: }
1.101 raeburn 1339: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1340: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1341: my $typecount = 0;
1.101 raeburn 1342: my ($css_class,%titles);
1.86 raeburn 1343: if ($context eq 'requestcourses') {
1.98 raeburn 1344: @usertools = ('official','unofficial','community');
1.106 raeburn 1345: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1346: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1347: %titles = &courserequest_titles();
1.86 raeburn 1348: } else {
1349: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1350: %titles = &tool_titles();
1.86 raeburn 1351: }
1.26 raeburn 1352: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1353: foreach my $type (@{$types}) {
1.72 raeburn 1354: my $currdefquota;
1.86 raeburn 1355: unless ($context eq 'requestcourses') {
1356: if (ref($settings) eq 'HASH') {
1357: if (ref($settings->{defaultquota}) eq 'HASH') {
1358: $currdefquota = $settings->{defaultquota}->{$type};
1359: } else {
1360: $currdefquota = $settings->{$type};
1361: }
1.78 raeburn 1362: }
1.72 raeburn 1363: }
1.3 raeburn 1364: if (defined($usertypes->{$type})) {
1365: $typecount ++;
1366: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1367: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1368: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1369: '<td class="LC_left_item">';
1.101 raeburn 1370: if ($context eq 'requestcourses') {
1371: $datatable .= '<table><tr>';
1372: }
1373: my %cell;
1.72 raeburn 1374: foreach my $item (@usertools) {
1.101 raeburn 1375: if ($context eq 'requestcourses') {
1376: my ($curroption,$currlimit);
1377: if (ref($settings) eq 'HASH') {
1378: if (ref($settings->{$item}) eq 'HASH') {
1379: $curroption = $settings->{$item}->{$type};
1380: if ($curroption =~ /^autolimit=(\d*)$/) {
1381: $currlimit = $1;
1382: }
1383: }
1384: }
1385: if (!$curroption) {
1386: $curroption = 'norequest';
1387: }
1388: $datatable .= '<th>'.$titles{$item}.'</th>';
1389: foreach my $option (@options) {
1390: my $val = $option;
1391: if ($option eq 'norequest') {
1392: $val = 0;
1393: }
1394: if ($option eq 'validate') {
1395: my $canvalidate = 0;
1396: if (ref($validations{$item}) eq 'HASH') {
1397: if ($validations{$item}{$type}) {
1398: $canvalidate = 1;
1399: }
1400: }
1401: next if (!$canvalidate);
1402: }
1403: my $checked = '';
1404: if ($option eq $curroption) {
1405: $checked = ' checked="checked"';
1406: } elsif ($option eq 'autolimit') {
1407: if ($curroption =~ /^autolimit/) {
1408: $checked = ' checked="checked"';
1409: }
1410: }
1411: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1412: '<input type="radio" name="crsreq_'.$item.
1413: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1414: $titles{$option}.'</label>';
1.101 raeburn 1415: if ($option eq 'autolimit') {
1.127 raeburn 1416: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1417: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1418: 'value="'.$currlimit.'" />';
1.101 raeburn 1419: }
1.127 raeburn 1420: $cell{$item} .= '</span> ';
1.103 raeburn 1421: if ($option eq 'autolimit') {
1.127 raeburn 1422: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1423: }
1.101 raeburn 1424: }
1425: } else {
1426: my $checked = 'checked="checked" ';
1427: if (ref($settings) eq 'HASH') {
1428: if (ref($settings->{$item}) eq 'HASH') {
1429: if ($settings->{$item}->{$type} == 0) {
1430: $checked = '';
1431: } elsif ($settings->{$item}->{$type} == 1) {
1432: $checked = 'checked="checked" ';
1433: }
1.78 raeburn 1434: }
1.72 raeburn 1435: }
1.101 raeburn 1436: $datatable .= '<span class="LC_nobreak"><label>'.
1437: '<input type="checkbox" name="'.$context.'_'.$item.
1438: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1439: '</label></span> ';
1.72 raeburn 1440: }
1.101 raeburn 1441: }
1442: if ($context eq 'requestcourses') {
1443: $datatable .= '</tr><tr>';
1444: foreach my $item (@usertools) {
1.106 raeburn 1445: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1446: }
1447: $datatable .= '</tr></table>';
1.72 raeburn 1448: }
1.86 raeburn 1449: $datatable .= '</td>';
1450: unless ($context eq 'requestcourses') {
1451: $datatable .=
1452: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1453: '<input type="text" name="quota_'.$type.
1.72 raeburn 1454: '" value="'.$currdefquota.
1.86 raeburn 1455: '" size="5" /> Mb</span></td>';
1456: }
1457: $datatable .= '</tr>';
1.3 raeburn 1458: }
1459: }
1460: }
1.86 raeburn 1461: unless ($context eq 'requestcourses') {
1462: $defaultquota = '20';
1463: if (ref($settings) eq 'HASH') {
1464: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1465: $defaultquota = $settings->{'defaultquota'}->{'default'};
1466: } elsif (defined($settings->{'default'})) {
1467: $defaultquota = $settings->{'default'};
1468: }
1.3 raeburn 1469: }
1470: }
1471: $typecount ++;
1472: $css_class = $typecount%2?' class="LC_odd_row"':'';
1473: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1474: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1475: '<td class="LC_left_item">';
1.101 raeburn 1476: if ($context eq 'requestcourses') {
1477: $datatable .= '<table><tr>';
1478: }
1479: my %defcell;
1.72 raeburn 1480: foreach my $item (@usertools) {
1.101 raeburn 1481: if ($context eq 'requestcourses') {
1482: my ($curroption,$currlimit);
1483: if (ref($settings) eq 'HASH') {
1484: if (ref($settings->{$item}) eq 'HASH') {
1485: $curroption = $settings->{$item}->{'default'};
1486: if ($curroption =~ /^autolimit=(\d*)$/) {
1487: $currlimit = $1;
1488: }
1489: }
1490: }
1491: if (!$curroption) {
1492: $curroption = 'norequest';
1493: }
1494: $datatable .= '<th>'.$titles{$item}.'</th>';
1495: foreach my $option (@options) {
1496: my $val = $option;
1497: if ($option eq 'norequest') {
1498: $val = 0;
1499: }
1500: if ($option eq 'validate') {
1501: my $canvalidate = 0;
1502: if (ref($validations{$item}) eq 'HASH') {
1503: if ($validations{$item}{'default'}) {
1504: $canvalidate = 1;
1505: }
1506: }
1507: next if (!$canvalidate);
1508: }
1509: my $checked = '';
1510: if ($option eq $curroption) {
1511: $checked = ' checked="checked"';
1512: } elsif ($option eq 'autolimit') {
1513: if ($curroption =~ /^autolimit/) {
1514: $checked = ' checked="checked"';
1515: }
1516: }
1517: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1518: '<input type="radio" name="crsreq_'.$item.
1519: '_default" value="'.$val.'"'.$checked.' />'.
1520: $titles{$option}.'</label>';
1521: if ($option eq 'autolimit') {
1.127 raeburn 1522: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1523: $item.'_limit_default" size="1" '.
1524: 'value="'.$currlimit.'" />';
1525: }
1.127 raeburn 1526: $defcell{$item} .= '</span> ';
1.104 raeburn 1527: if ($option eq 'autolimit') {
1.127 raeburn 1528: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1529: }
1.101 raeburn 1530: }
1531: } else {
1532: my $checked = 'checked="checked" ';
1533: if (ref($settings) eq 'HASH') {
1534: if (ref($settings->{$item}) eq 'HASH') {
1535: if ($settings->{$item}->{'default'} == 0) {
1536: $checked = '';
1537: } elsif ($settings->{$item}->{'default'} == 1) {
1538: $checked = 'checked="checked" ';
1539: }
1.78 raeburn 1540: }
1.72 raeburn 1541: }
1.101 raeburn 1542: $datatable .= '<span class="LC_nobreak"><label>'.
1543: '<input type="checkbox" name="'.$context.'_'.$item.
1544: '" value="default" '.$checked.'/>'.$titles{$item}.
1545: '</label></span> ';
1546: }
1547: }
1548: if ($context eq 'requestcourses') {
1549: $datatable .= '</tr><tr>';
1550: foreach my $item (@usertools) {
1.106 raeburn 1551: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1552: }
1.101 raeburn 1553: $datatable .= '</tr></table>';
1.72 raeburn 1554: }
1.86 raeburn 1555: $datatable .= '</td>';
1556: unless ($context eq 'requestcourses') {
1557: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1558: '<input type="text" name="defaultquota" value="'.
1559: $defaultquota.'" size="5" /> Mb</span></td>';
1560: }
1561: $datatable .= '</tr>';
1.72 raeburn 1562: $typecount ++;
1563: $css_class = $typecount%2?' class="LC_odd_row"':'';
1564: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1565: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1566: if ($context eq 'requestcourses') {
1.109 raeburn 1567: $datatable .= &mt('(overrides affiliation, if set)').
1568: '</td>'.
1569: '<td class="LC_left_item">'.
1570: '<table><tr>';
1.101 raeburn 1571: } else {
1.109 raeburn 1572: $datatable .= &mt('(overrides affiliation, if checked)').
1573: '</td>'.
1574: '<td class="LC_left_item" colspan="2">'.
1575: '<br />';
1.101 raeburn 1576: }
1577: my %advcell;
1.72 raeburn 1578: foreach my $item (@usertools) {
1.101 raeburn 1579: if ($context eq 'requestcourses') {
1580: my ($curroption,$currlimit);
1581: if (ref($settings) eq 'HASH') {
1582: if (ref($settings->{$item}) eq 'HASH') {
1583: $curroption = $settings->{$item}->{'_LC_adv'};
1584: if ($curroption =~ /^autolimit=(\d*)$/) {
1585: $currlimit = $1;
1586: }
1587: }
1588: }
1589: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1590: my $checked = '';
1591: if ($curroption eq '') {
1592: $checked = ' checked="checked"';
1593: }
1594: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1595: '<input type="radio" name="crsreq_'.$item.
1596: '__LC_adv" value=""'.$checked.' />'.
1597: &mt('No override set').'</label></span> ';
1.101 raeburn 1598: foreach my $option (@options) {
1599: my $val = $option;
1600: if ($option eq 'norequest') {
1601: $val = 0;
1602: }
1603: if ($option eq 'validate') {
1604: my $canvalidate = 0;
1605: if (ref($validations{$item}) eq 'HASH') {
1606: if ($validations{$item}{'_LC_adv'}) {
1607: $canvalidate = 1;
1608: }
1609: }
1610: next if (!$canvalidate);
1611: }
1612: my $checked = '';
1.104 raeburn 1613: if ($val eq $curroption) {
1.101 raeburn 1614: $checked = ' checked="checked"';
1615: } elsif ($option eq 'autolimit') {
1616: if ($curroption =~ /^autolimit/) {
1617: $checked = ' checked="checked"';
1618: }
1619: }
1620: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1621: '<input type="radio" name="crsreq_'.$item.
1622: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1623: $titles{$option}.'</label>';
1624: if ($option eq 'autolimit') {
1.127 raeburn 1625: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1626: $item.'_limit__LC_adv" size="1" '.
1627: 'value="'.$currlimit.'" />';
1628: }
1.127 raeburn 1629: $advcell{$item} .= '</span> ';
1.104 raeburn 1630: if ($option eq 'autolimit') {
1.127 raeburn 1631: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1632: }
1.101 raeburn 1633: }
1634: } else {
1635: my $checked = 'checked="checked" ';
1636: if (ref($settings) eq 'HASH') {
1637: if (ref($settings->{$item}) eq 'HASH') {
1638: if ($settings->{$item}->{'_LC_adv'} == 0) {
1639: $checked = '';
1640: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1641: $checked = 'checked="checked" ';
1642: }
1.79 raeburn 1643: }
1.72 raeburn 1644: }
1.101 raeburn 1645: $datatable .= '<span class="LC_nobreak"><label>'.
1646: '<input type="checkbox" name="'.$context.'_'.$item.
1647: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1648: '</label></span> ';
1649: }
1650: }
1651: if ($context eq 'requestcourses') {
1652: $datatable .= '</tr><tr>';
1653: foreach my $item (@usertools) {
1.106 raeburn 1654: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1655: }
1.101 raeburn 1656: $datatable .= '</tr></table>';
1.72 raeburn 1657: }
1.98 raeburn 1658: $datatable .= '</td></tr>';
1.30 raeburn 1659: $$rowtotal += $typecount;
1.3 raeburn 1660: return $datatable;
1661: }
1662:
1.102 raeburn 1663: sub print_courserequestmail {
1664: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1665: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1666: $now = time;
1667: $rows = 0;
1668: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1669: foreach my $server (keys(%dompersonnel)) {
1670: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1671: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1672: if (!grep(/^$uname:$udom$/,@domcoord)) {
1673: push(@domcoord,$uname.':'.$udom);
1674: }
1675: }
1676: }
1677: if (ref($settings) eq 'HASH') {
1678: if (ref($settings->{'notify'}) eq 'HASH') {
1679: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1680: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1681: }
1682: }
1683: }
1.104 raeburn 1684: if (@currapproval) {
1685: foreach my $dc (@currapproval) {
1.102 raeburn 1686: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1687: push(@domcoord,$dc);
1688: }
1689: }
1690: }
1691: @domcoord = sort(@domcoord);
1692: my $numinrow = 4;
1693: my $numdc = @domcoord;
1694: my $css_class = 'class="LC_odd_row"';
1695: $datatable = '<tr'.$css_class.'>'.
1696: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1697: ' </td>'.
1698: ' <td class="LC_left_item">';
1699: if (@domcoord > 0) {
1700: $datatable .= '<table>';
1701: for (my $i=0; $i<$numdc; $i++) {
1702: my $rem = $i%($numinrow);
1703: if ($rem == 0) {
1704: if ($i > 0) {
1705: $datatable .= '</tr>';
1706: }
1707: $datatable .= '<tr>';
1708: $rows ++;
1709: }
1710: my $check = ' ';
1.104 raeburn 1711: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1712: $check = ' checked="checked" ';
1713: }
1714: my ($uname,$udom) = split(':',$domcoord[$i]);
1715: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1716: if ($i == $numdc-1) {
1717: my $colsleft = $numinrow-$rem;
1718: if ($colsleft > 1) {
1719: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1720: } else {
1721: $datatable .= '<td class="LC_left_item">';
1722: }
1723: } else {
1724: $datatable .= '<td class="LC_left_item">';
1725: }
1726: $datatable .= '<span class="LC_nobreak"><label>'.
1727: '<input type="checkbox" name="reqapprovalnotify" '.
1728: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1729: $fullname.'</label></span></td>';
1730: }
1731: $datatable .= '</tr></table>';
1732: } else {
1733: $datatable .= &mt('There are no active Domain Coordinators');
1734: $rows ++;
1735: }
1736: $datatable .='</td></tr>';
1737: $$rowtotal += $rows;
1738: return $datatable;
1739: }
1740:
1.3 raeburn 1741: sub print_autoenroll {
1.30 raeburn 1742: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1743: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1744: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1745: if (ref($settings) eq 'HASH') {
1746: if (exists($settings->{'run'})) {
1747: if ($settings->{'run'} eq '0') {
1748: $runoff = ' checked="checked" ';
1749: $runon = ' ';
1750: } else {
1751: $runon = ' checked="checked" ';
1752: $runoff = ' ';
1753: }
1754: } else {
1755: if ($autorun) {
1756: $runon = ' checked="checked" ';
1757: $runoff = ' ';
1758: } else {
1759: $runoff = ' checked="checked" ';
1760: $runon = ' ';
1761: }
1762: }
1.129 raeburn 1763: if (exists($settings->{'co-owners'})) {
1764: if ($settings->{'co-owners'} eq '0') {
1765: $coownersoff = ' checked="checked" ';
1766: $coownerson = ' ';
1767: } else {
1768: $coownerson = ' checked="checked" ';
1769: $coownersoff = ' ';
1770: }
1771: } else {
1772: $coownersoff = ' checked="checked" ';
1773: $coownerson = ' ';
1774: }
1.3 raeburn 1775: if (exists($settings->{'sender_domain'})) {
1776: $defdom = $settings->{'sender_domain'};
1777: }
1.14 raeburn 1778: } else {
1779: if ($autorun) {
1780: $runon = ' checked="checked" ';
1781: $runoff = ' ';
1782: } else {
1783: $runoff = ' checked="checked" ';
1784: $runon = ' ';
1785: }
1.3 raeburn 1786: }
1787: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1788: my $notif_sender;
1789: if (ref($settings) eq 'HASH') {
1790: $notif_sender = $settings->{'sender_uname'};
1791: }
1.3 raeburn 1792: my $datatable='<tr class="LC_odd_row">'.
1793: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1794: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1795: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1796: $runon.' value="1" />'.&mt('Yes').'</label> '.
1797: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1798: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1799: '</tr><tr>'.
1800: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1801: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1802: &mt('username').': '.
1803: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1804: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1805: ': '.$domform.'</span></td></tr>'.
1806: '<tr class="LC_odd_row">'.
1807: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1808: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1809: '<input type="radio" name="autoassign_coowners"'.
1810: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1811: '<label><input type="radio" name="autoassign_coowners"'.
1812: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1813: '</tr>';
1814: $$rowtotal += 3;
1.3 raeburn 1815: return $datatable;
1816: }
1817:
1818: sub print_autoupdate {
1.30 raeburn 1819: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1820: my $datatable;
1821: if ($position eq 'top') {
1822: my $updateon = ' ';
1823: my $updateoff = ' checked="checked" ';
1824: my $classlistson = ' ';
1825: my $classlistsoff = ' checked="checked" ';
1826: if (ref($settings) eq 'HASH') {
1827: if ($settings->{'run'} eq '1') {
1828: $updateon = $updateoff;
1829: $updateoff = ' ';
1830: }
1831: if ($settings->{'classlists'} eq '1') {
1832: $classlistson = $classlistsoff;
1833: $classlistsoff = ' ';
1834: }
1835: }
1836: my %title = (
1837: run => 'Auto-update active?',
1838: classlists => 'Update information in classlists?',
1839: );
1840: $datatable = '<tr class="LC_odd_row">'.
1841: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1842: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1843: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1844: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1845: '<label><input type="radio" name="autoupdate_run"'.
1846: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1847: '</tr><tr>'.
1848: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1849: '<td class="LC_right_item"><span class="LC_nobreak">'.
1850: '<label><input type="radio" name="classlists"'.
1851: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1852: '<label><input type="radio" name="classlists"'.
1853: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1854: '</tr>';
1.30 raeburn 1855: $$rowtotal += 2;
1.131 raeburn 1856: } elsif ($position eq 'middle') {
1857: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1858: my $numinrow = 3;
1859: my $locknamesettings;
1860: $datatable .= &insttypes_row($settings,$types,$usertypes,
1861: $dom,$numinrow,$othertitle,
1862: 'lockablenames');
1863: $$rowtotal ++;
1.3 raeburn 1864: } else {
1.44 raeburn 1865: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1866: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1867: 'permanentemail','id');
1.33 raeburn 1868: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1869: my $numrows = 0;
1.26 raeburn 1870: if (ref($types) eq 'ARRAY') {
1871: if (@{$types} > 0) {
1872: $datatable =
1873: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1874: \@fields,$types,\$numrows);
1.30 raeburn 1875: $$rowtotal += @{$types};
1.26 raeburn 1876: }
1.3 raeburn 1877: }
1878: $datatable .=
1879: &usertype_update_row($settings,{'default' => $othertitle},
1880: \%fieldtitles,\@fields,['default'],
1881: \$numrows);
1.30 raeburn 1882: $$rowtotal ++;
1.3 raeburn 1883: }
1884: return $datatable;
1885: }
1886:
1.125 raeburn 1887: sub print_autocreate {
1888: my ($dom,$settings,$rowtotal) = @_;
1889: my (%createon,%createoff);
1890: my $curr_dc;
1891: my @types = ('xml','req');
1892: if (ref($settings) eq 'HASH') {
1893: foreach my $item (@types) {
1894: $createoff{$item} = ' checked="checked" ';
1895: $createon{$item} = ' ';
1896: if (exists($settings->{$item})) {
1897: if ($settings->{$item}) {
1898: $createon{$item} = ' checked="checked" ';
1899: $createoff{$item} = ' ';
1900: }
1901: }
1902: }
1903: $curr_dc = $settings->{'xmldc'};
1904: } else {
1905: foreach my $item (@types) {
1906: $createoff{$item} = ' checked="checked" ';
1907: $createon{$item} = ' ';
1908: }
1909: }
1910: $$rowtotal += 2;
1911: my $datatable='<tr class="LC_odd_row">'.
1912: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1913: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1914: '<input type="radio" name="autocreate_xml"'.
1915: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1916: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 1917: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
1918: '</td></tr><tr>'.
1919: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1920: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1921: '<input type="radio" name="autocreate_req"'.
1922: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1923: '<label><input type="radio" name="autocreate_req"'.
1924: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 1925: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1926: if ($numdc > 1) {
1.143 raeburn 1927: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
1928: &mt('Course creation processed as: (choose Dom. Coord.)').
1929: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 1930: $$rowtotal ++ ;
1931: } else {
1.143 raeburn 1932: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 1933: }
1934: return $datatable;
1935: }
1936:
1.23 raeburn 1937: sub print_directorysrch {
1.30 raeburn 1938: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1939: my $srchon = ' ';
1940: my $srchoff = ' checked="checked" ';
1.25 raeburn 1941: my ($exacton,$containson,$beginson);
1.24 raeburn 1942: my $localon = ' ';
1943: my $localoff = ' checked="checked" ';
1.23 raeburn 1944: if (ref($settings) eq 'HASH') {
1945: if ($settings->{'available'} eq '1') {
1946: $srchon = $srchoff;
1947: $srchoff = ' ';
1948: }
1.24 raeburn 1949: if ($settings->{'localonly'} eq '1') {
1950: $localon = $localoff;
1951: $localoff = ' ';
1952: }
1.25 raeburn 1953: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1954: foreach my $type (@{$settings->{'searchtypes'}}) {
1955: if ($type eq 'exact') {
1956: $exacton = ' checked="checked" ';
1957: } elsif ($type eq 'contains') {
1958: $containson = ' checked="checked" ';
1959: } elsif ($type eq 'begins') {
1960: $beginson = ' checked="checked" ';
1961: }
1962: }
1963: } else {
1964: if ($settings->{'searchtypes'} eq 'exact') {
1965: $exacton = ' checked="checked" ';
1966: } elsif ($settings->{'searchtypes'} eq 'contains') {
1967: $containson = ' checked="checked" ';
1968: } elsif ($settings->{'searchtypes'} eq 'specify') {
1969: $exacton = ' checked="checked" ';
1970: $containson = ' checked="checked" ';
1971: }
1.23 raeburn 1972: }
1973: }
1974: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1975: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1976:
1977: my $numinrow = 4;
1.26 raeburn 1978: my $cansrchrow = 0;
1.23 raeburn 1979: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1980: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1981: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1982: '<input type="radio" name="dirsrch_available"'.
1983: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1984: '<label><input type="radio" name="dirsrch_available"'.
1985: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1986: '</tr><tr>'.
1.30 raeburn 1987: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1988: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1989: '<input type="radio" name="dirsrch_localonly"'.
1990: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1991: '<label><input type="radio" name="dirsrch_localonly"'.
1992: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1993: '</tr>';
1.30 raeburn 1994: $$rowtotal += 2;
1.26 raeburn 1995: if (ref($usertypes) eq 'HASH') {
1996: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 1997: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1998: $numinrow,$othertitle,'cansearch');
1.26 raeburn 1999: $cansrchrow = 1;
2000: }
2001: }
2002: if ($cansrchrow) {
1.30 raeburn 2003: $$rowtotal ++;
1.26 raeburn 2004: $datatable .= '<tr>';
2005: } else {
2006: $datatable .= '<tr class="LC_odd_row">';
2007: }
1.30 raeburn 2008: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2009: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2010: foreach my $title (@{$titleorder}) {
2011: if (defined($searchtitles->{$title})) {
2012: my $check = ' ';
1.93 raeburn 2013: if (ref($settings) eq 'HASH') {
1.39 raeburn 2014: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2015: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2016: $check = ' checked="checked" ';
2017: }
1.25 raeburn 2018: }
2019: }
2020: $datatable .= '<td class="LC_left_item">'.
2021: '<span class="LC_nobreak"><label>'.
2022: '<input type="checkbox" name="searchby" '.
2023: 'value="'.$title.'"'.$check.'/>'.
2024: $searchtitles->{$title}.'</label></span></td>';
2025: }
2026: }
1.26 raeburn 2027: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2028: $$rowtotal ++;
1.26 raeburn 2029: if ($cansrchrow) {
2030: $datatable .= '<tr class="LC_odd_row">';
2031: } else {
2032: $datatable .= '<tr>';
2033: }
1.30 raeburn 2034: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2035: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2036: '<span class="LC_nobreak"><label>'.
2037: '<input type="checkbox" name="searchtypes" '.
2038: $exacton.' value="exact" />'.&mt('Exact match').
2039: '</label> '.
2040: '<label><input type="checkbox" name="searchtypes" '.
2041: $beginson.' value="begins" />'.&mt('Begins with').
2042: '</label> '.
2043: '<label><input type="checkbox" name="searchtypes" '.
2044: $containson.' value="contains" />'.&mt('Contains').
2045: '</label></span></td></tr>';
1.30 raeburn 2046: $$rowtotal ++;
1.25 raeburn 2047: return $datatable;
2048: }
2049:
1.28 raeburn 2050: sub print_contacts {
1.30 raeburn 2051: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2052: my $datatable;
2053: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2054: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2055: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2056: 'requestsmail');
1.28 raeburn 2057: foreach my $type (@mailings) {
2058: $otheremails{$type} = '';
2059: }
1.134 raeburn 2060: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2061: if (ref($settings) eq 'HASH') {
2062: foreach my $item (@contacts) {
2063: if (exists($settings->{$item})) {
2064: $to{$item} = $settings->{$item};
2065: }
2066: }
2067: foreach my $type (@mailings) {
2068: if (exists($settings->{$type})) {
2069: if (ref($settings->{$type}) eq 'HASH') {
2070: foreach my $item (@contacts) {
2071: if ($settings->{$type}{$item}) {
2072: $checked{$type}{$item} = ' checked="checked" ';
2073: }
2074: }
2075: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2076: if ($type eq 'helpdeskmail') {
2077: $bccemails{$type} = $settings->{$type}{'bcc'};
2078: }
1.28 raeburn 2079: }
1.89 raeburn 2080: } elsif ($type eq 'lonstatusmail') {
2081: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2082: }
2083: }
2084: } else {
2085: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2086: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2087: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2088: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2089: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2090: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2091: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2092: }
2093: my ($titles,$short_titles) = &contact_titles();
2094: my $rownum = 0;
2095: my $css_class;
2096: foreach my $item (@contacts) {
1.69 raeburn 2097: $rownum ++;
2098: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2099: $datatable .= '<tr'.$css_class.'>'.
2100: '<td><span class="LC_nobreak">'.$titles->{$item}.
2101: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2102: '<input type="text" name="'.$item.'" value="'.
2103: $to{$item}.'" /></td></tr>';
2104: }
2105: foreach my $type (@mailings) {
1.69 raeburn 2106: $rownum ++;
2107: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2108: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2109: '<td><span class="LC_nobreak">'.
2110: $titles->{$type}.': </span></td>'.
1.28 raeburn 2111: '<td class="LC_left_item">'.
2112: '<span class="LC_nobreak">';
2113: foreach my $item (@contacts) {
2114: $datatable .= '<label>'.
2115: '<input type="checkbox" name="'.$type.'"'.
2116: $checked{$type}{$item}.
2117: ' value="'.$item.'" />'.$short_titles->{$item}.
2118: '</label> ';
2119: }
2120: $datatable .= '</span><br />'.&mt('Others').': '.
2121: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2122: 'value="'.$otheremails{$type}.'" />';
2123: if ($type eq 'helpdeskmail') {
1.136 raeburn 2124: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2125: '<input type="text" name="'.$type.'_bcc" '.
2126: 'value="'.$bccemails{$type}.'" />';
2127: }
2128: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2129: }
1.30 raeburn 2130: $$rowtotal += $rownum;
1.28 raeburn 2131: return $datatable;
2132: }
2133:
1.118 jms 2134: sub print_helpsettings {
1.122 jms 2135:
2136: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2137: my ($css_class,$datatable);
2138:
2139: my $switchserver = &check_switchserver($dom,$confname);
2140:
2141: my $itemcount = 1;
2142:
2143: if ($position eq 'top') {
2144:
2145: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2146:
2147: %choices =
2148: &Apache::lonlocal::texthash (
2149: submitbugs => 'Display "Submit a bug" link?',
2150: );
2151:
2152: %defaultchecked = ('submitbugs' => 'on');
2153:
2154: @toggles = ('submitbugs',);
2155:
2156: foreach my $item (@toggles) {
2157: if ($defaultchecked{$item} eq 'on') {
2158: $checkedon{$item} = ' checked="checked" ';
2159: $checkedoff{$item} = ' ';
2160: } elsif ($defaultchecked{$item} eq 'off') {
2161: $checkedoff{$item} = ' checked="checked" ';
2162: $checkedon{$item} = ' ';
2163: }
2164: }
2165:
2166: if (ref($settings) eq 'HASH') {
2167: foreach my $item (@toggles) {
2168: if ($settings->{$item} eq '1') {
2169: $checkedon{$item} = ' checked="checked" ';
2170: $checkedoff{$item} = ' ';
2171: } elsif ($settings->{$item} eq '0') {
2172: $checkedoff{$item} = ' checked="checked" ';
2173: $checkedon{$item} = ' ';
2174: }
2175: }
2176: }
2177:
2178: foreach my $item (@toggles) {
2179: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2180: $datatable .=
2181: '<tr'.$css_class.'>
2182: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2183: <td><span class="LC_nobreak"> </span></td>
2184: <td class="LC_right_item"><span class="LC_nobreak">
2185: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2186: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2187: '</span></td>'.
2188: '</tr>';
2189: $itemcount ++;
2190: }
2191:
2192: } else {
2193:
2194: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2195:
2196: $datatable .= '<tr'.$css_class.'>';
2197:
2198: if (ref($settings) eq 'HASH') {
2199: if ($settings->{'loginhelpurl'} ne '') {
2200: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2201: $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>';
2202: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2203: } else {
2204: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2205: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2206: }
2207: } else {
2208: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2209: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2210: }
2211:
2212: $datatable .= '<td width="33%"><span class="LC_right_item">';
2213: if ($switchserver) {
2214: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2215: } else {
2216: $datatable .= &mt('Upload Custom Login Page Help File:');
2217: $datatable .='<input type="file" name="loginhelpurl" />';
2218: }
2219: $datatable .= '</span></td></tr>';
2220:
2221: }
2222:
2223: return $datatable;
2224:
1.121 raeburn 2225: }
2226:
1.122 jms 2227:
1.121 raeburn 2228: sub radiobutton_prefs {
2229: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2230: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2231: (ref($choices) eq 'HASH'));
2232:
2233: my (%checkedon,%checkedoff,$datatable,$css_class);
2234:
2235: foreach my $item (@{$toggles}) {
2236: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2237: $checkedon{$item} = ' checked="checked" ';
2238: $checkedoff{$item} = ' ';
1.121 raeburn 2239: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2240: $checkedoff{$item} = ' checked="checked" ';
2241: $checkedon{$item} = ' ';
2242: }
2243: }
2244: if (ref($settings) eq 'HASH') {
1.121 raeburn 2245: foreach my $item (@{$toggles}) {
1.118 jms 2246: if ($settings->{$item} eq '1') {
2247: $checkedon{$item} = ' checked="checked" ';
2248: $checkedoff{$item} = ' ';
2249: } elsif ($settings->{$item} eq '0') {
2250: $checkedoff{$item} = ' checked="checked" ';
2251: $checkedon{$item} = ' ';
2252: }
2253: }
1.121 raeburn 2254: }
2255: foreach my $item (@{$toggles}) {
1.118 jms 2256: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2257: $datatable .=
2258: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2259: '</span></td>'.
2260: '<td class="LC_right_item"><span class="LC_nobreak">'.
2261: '<label><input type="radio" name="'.
2262: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2263: '</label> <label><input type="radio" name="'.$item.'" '.
2264: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2265: '</span></td>'.
2266: '</tr>';
2267: $itemcount ++;
1.121 raeburn 2268: }
2269: return ($datatable,$itemcount);
2270: }
2271:
2272: sub print_coursedefaults {
1.139 raeburn 2273: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2274: my ($css_class,$datatable);
2275: my $itemcount = 1;
1.139 raeburn 2276: if ($position eq 'top') {
2277: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2278: %choices =
2279: &Apache::lonlocal::texthash (
2280: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2281: );
2282: %defaultchecked = ('canuse_pdfforms' => 'off');
2283: @toggles = ('canuse_pdfforms',);
2284: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2285: \%choices,$itemcount);
1.139 raeburn 2286: $$rowtotal += $itemcount;
2287: } else {
2288: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2289: my %choices =
2290: &Apache::lonlocal::texthash (
2291: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2292: );
2293: my $currdefresponder;
2294: if (ref($settings) eq 'HASH') {
2295: $currdefresponder = $settings->{'anonsurvey_threshold'};
2296: }
2297: if (!$currdefresponder) {
2298: $currdefresponder = 10;
2299: } elsif ($currdefresponder < 1) {
2300: $currdefresponder = 1;
2301: }
2302: $datatable .=
2303: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2304: '</span></td>'.
2305: '<td class="LC_right_item"><span class="LC_nobreak">'.
2306: '<input type="text" name="anonsurvey_threshold"'.
2307: ' value="'.$currdefresponder.'" size="5" /></span>'.
2308: '</td></tr>';
2309: }
1.121 raeburn 2310: return $datatable;
1.118 jms 2311: }
2312:
1.137 raeburn 2313: sub print_usersessions {
2314: my ($position,$dom,$settings,$rowtotal) = @_;
2315: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2316: my (%by_ip,%by_location,@intdoms);
2317: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2318:
2319: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2320: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2321: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2322: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2323: my $itemcount = 1;
2324: if ($position eq 'top') {
1.152 raeburn 2325: if (keys(%serverhomes) > 1) {
1.145 raeburn 2326: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2327: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2328: } else {
1.140 raeburn 2329: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2330: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2331: }
1.137 raeburn 2332: } else {
1.145 raeburn 2333: if (keys(%by_location) == 0) {
2334: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2335: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2336: } else {
2337: my %lt = &usersession_titles();
2338: my $numinrow = 5;
2339: my $prefix;
2340: my @types;
2341: if ($position eq 'bottom') {
2342: $prefix = 'remote';
2343: @types = ('version','excludedomain','includedomain');
2344: } else {
2345: $prefix = 'hosted';
2346: @types = ('excludedomain','includedomain');
2347: }
2348: my (%current,%checkedon,%checkedoff);
2349: my @lcversions = &Apache::lonnet::all_loncaparevs();
2350: my @locations = sort(keys(%by_location));
2351: foreach my $type (@types) {
2352: $checkedon{$type} = '';
2353: $checkedoff{$type} = ' checked="checked"';
2354: }
2355: if (ref($settings) eq 'HASH') {
2356: if (ref($settings->{$prefix}) eq 'HASH') {
2357: foreach my $key (keys(%{$settings->{$prefix}})) {
2358: $current{$key} = $settings->{$prefix}{$key};
2359: if ($key eq 'version') {
2360: if ($current{$key} ne '') {
2361: $checkedon{$key} = ' checked="checked"';
2362: $checkedoff{$key} = '';
2363: }
2364: } elsif (ref($current{$key}) eq 'ARRAY') {
2365: $checkedon{$key} = ' checked="checked"';
2366: $checkedoff{$key} = '';
2367: }
1.137 raeburn 2368: }
2369: }
2370: }
1.145 raeburn 2371: foreach my $type (@types) {
2372: next if ($type ne 'version' && !@locations);
2373: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2374: $datatable .= '<tr'.$css_class.'>
2375: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2376: <span class="LC_nobreak">
2377: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2378: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2379: if ($type eq 'version') {
2380: my $selector = '<select name="'.$prefix.'_version">';
2381: foreach my $version (@lcversions) {
2382: my $selected = '';
2383: if ($current{'version'} eq $version) {
2384: $selected = ' selected="selected"';
2385: }
2386: $selector .= ' <option value="'.$version.'"'.
2387: $selected.'>'.$version.'</option>';
2388: }
2389: $selector .= '</select> ';
2390: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2391: } else {
2392: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2393: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2394: ' />'.(' 'x2).
2395: '<input type="button" value="'.&mt('uncheck all').'" '.
2396: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2397: "\n".
2398: '</div><div><table>';
2399: my $rem;
2400: for (my $i=0; $i<@locations; $i++) {
2401: my ($showloc,$value,$checkedtype);
2402: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2403: my $ip = $by_location{$locations[$i]}->[0];
2404: if (ref($by_ip{$ip}) eq 'ARRAY') {
2405: $value = join(':',@{$by_ip{$ip}});
2406: $showloc = join(', ',@{$by_ip{$ip}});
2407: if (ref($current{$type}) eq 'ARRAY') {
2408: foreach my $loc (@{$by_ip{$ip}}) {
2409: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2410: $checkedtype = ' checked="checked"';
2411: last;
2412: }
2413: }
1.138 raeburn 2414: }
2415: }
2416: }
1.145 raeburn 2417: $rem = $i%($numinrow);
2418: if ($rem == 0) {
2419: if ($i > 0) {
2420: $datatable .= '</tr>';
2421: }
2422: $datatable .= '<tr>';
2423: }
2424: $datatable .= '<td class="LC_left_item">'.
2425: '<span class="LC_nobreak"><label>'.
2426: '<input type="checkbox" name="'.$prefix.'_'.$type.
2427: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2428: '</label></span></td>';
1.137 raeburn 2429: }
1.145 raeburn 2430: $rem = @locations%($numinrow);
2431: my $colsleft = $numinrow - $rem;
2432: if ($colsleft > 1 ) {
2433: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2434: ' </td>';
2435: } elsif ($colsleft == 1) {
2436: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2437: }
1.145 raeburn 2438: $datatable .= '</tr></table>';
1.137 raeburn 2439: }
1.145 raeburn 2440: $datatable .= '</td></tr>';
2441: $itemcount ++;
1.137 raeburn 2442: }
2443: }
2444: }
2445: $$rowtotal += $itemcount;
2446: return $datatable;
2447: }
2448:
1.138 raeburn 2449: sub build_location_hashes {
2450: my ($intdoms,$by_ip,$by_location) = @_;
2451: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2452: (ref($by_location) eq 'HASH'));
2453: my %iphost = &Apache::lonnet::get_iphost();
2454: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2455: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2456: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2457: foreach my $id (@{$iphost{$primary_ip}}) {
2458: my $intdom = &Apache::lonnet::internet_dom($id);
2459: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2460: push(@{$intdoms},$intdom);
2461: }
2462: }
2463: }
2464: foreach my $ip (keys(%iphost)) {
2465: if (ref($iphost{$ip}) eq 'ARRAY') {
2466: foreach my $id (@{$iphost{$ip}}) {
2467: my $location = &Apache::lonnet::internet_dom($id);
2468: if ($location) {
2469: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2470: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2471: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2472: push(@{$by_ip->{$ip}},$location);
2473: }
2474: } else {
2475: $by_ip->{$ip} = [$location];
2476: }
2477: }
2478: }
2479: }
2480: }
2481: foreach my $ip (sort(keys(%{$by_ip}))) {
2482: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2483: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2484: my $first = $by_ip->{$ip}->[0];
2485: if (ref($by_location->{$first}) eq 'ARRAY') {
2486: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2487: push(@{$by_location->{$first}},$ip);
2488: }
2489: } else {
2490: $by_location->{$first} = [$ip];
2491: }
2492: }
2493: }
2494: return;
2495: }
2496:
1.145 raeburn 2497: sub current_offloads_to {
2498: my ($dom,$settings,$servers) = @_;
2499: my (%spareid,%otherdomconfigs);
1.152 raeburn 2500: if (ref($servers) eq 'HASH') {
1.145 raeburn 2501: foreach my $lonhost (sort(keys(%{$servers}))) {
2502: my $gotspares;
1.152 raeburn 2503: if (ref($settings) eq 'HASH') {
2504: if (ref($settings->{'spares'}) eq 'HASH') {
2505: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2506: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2507: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2508: $gotspares = 1;
2509: }
1.145 raeburn 2510: }
2511: }
2512: unless ($gotspares) {
2513: my $gotspares;
2514: my $serverhomeID =
2515: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2516: my $serverhomedom =
2517: &Apache::lonnet::host_domain($serverhomeID);
2518: if ($serverhomedom ne $dom) {
2519: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2520: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2521: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2522: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2523: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2524: $gotspares = 1;
2525: }
2526: }
2527: } else {
2528: $otherdomconfigs{$serverhomedom} =
2529: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2530: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2531: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2532: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2533: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2534: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2535: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2536: $gotspares = 1;
2537: }
2538: }
2539: }
2540: }
2541: }
2542: }
2543: }
2544: unless ($gotspares) {
2545: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2546: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2547: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2548: } else {
2549: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2550: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2551: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2552: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2553: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2554: } else {
1.150 raeburn 2555: my %what = (
2556: spareid => 1,
2557: );
2558: my ($result,$returnhash) =
2559: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2560: if ($result eq 'ok') {
2561: if (ref($returnhash) eq 'HASH') {
2562: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2563: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2564: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2565: }
2566: }
1.145 raeburn 2567: }
2568: }
2569: }
2570: }
2571: }
2572: }
2573: return %spareid;
2574: }
2575:
2576: sub spares_row {
1.152 raeburn 2577: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2578: my $css_class;
2579: my $numinrow = 4;
2580: my $itemcount = 1;
2581: my $datatable;
1.152 raeburn 2582: my %typetitles = &sparestype_titles();
2583: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2584: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2585: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2586: my ($othercontrol,$serverdom);
2587: if ($serverhome ne $server) {
2588: $serverdom = &Apache::lonnet::host_domain($serverhome);
2589: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2590: } else {
2591: $serverdom = &Apache::lonnet::host_domain($server);
2592: if ($serverdom ne $dom) {
2593: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2594: }
2595: }
2596: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2597: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2598: $datatable .= '<tr'.$css_class.'>
2599: <td rowspan="2">
1.152 raeburn 2600: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2601: my (%current,%canselect);
1.152 raeburn 2602: my @choices =
2603: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2604: foreach my $type ('primary','default') {
2605: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2606: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2607: my @spares = @{$spareid->{$server}{$type}};
2608: if (@spares > 0) {
1.152 raeburn 2609: if ($othercontrol) {
2610: $current{$type} = join(', ',@spares);
2611: } else {
2612: $current{$type} .= '<table>';
2613: my $numspares = scalar(@spares);
2614: for (my $i=0; $i<@spares; $i++) {
2615: my $rem = $i%($numinrow);
2616: if ($rem == 0) {
2617: if ($i > 0) {
2618: $current{$type} .= '</tr>';
2619: }
2620: $current{$type} .= '<tr>';
1.145 raeburn 2621: }
1.152 raeburn 2622: $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'".');" /> '.
2623: $spareid->{$server}{$type}[$i].
2624: '</label></td>'."\n";
2625: }
2626: my $rem = @spares%($numinrow);
2627: my $colsleft = $numinrow - $rem;
2628: if ($colsleft > 1 ) {
2629: $current{$type} .= '<td colspan="'.$colsleft.
2630: '" class="LC_left_item">'.
2631: ' </td>';
2632: } elsif ($colsleft == 1) {
2633: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2634: }
1.152 raeburn 2635: $current{$type} .= '</tr></table>';
1.150 raeburn 2636: }
1.145 raeburn 2637: }
2638: }
2639: if ($current{$type} eq '') {
2640: $current{$type} = &mt('None specified');
2641: }
1.152 raeburn 2642: if ($othercontrol) {
2643: if ($type eq 'primary') {
2644: $canselect{$type} = $othercontrol;
2645: }
2646: } else {
2647: $canselect{$type} =
2648: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2649: '<select name="newspare_'.$type.'_'.$server.'" '.
2650: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2651: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2652: if (@choices > 0) {
2653: foreach my $lonhost (@choices) {
2654: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2655: }
2656: }
2657: $canselect{$type} .= '</select>'."\n";
2658: }
2659: } else {
2660: $current{$type} = &mt('Could not be determined');
2661: if ($type eq 'primary') {
2662: $canselect{$type} = $othercontrol;
2663: }
1.145 raeburn 2664: }
1.152 raeburn 2665: if ($type eq 'default') {
2666: $datatable .= '<tr'.$css_class.'>';
2667: }
2668: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2669: '<td>'.$current{$type}.'</td>'."\n".
2670: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2671: }
2672: $itemcount ++;
2673: }
2674: }
2675: $$rowtotal += $itemcount;
2676: return $datatable;
2677: }
2678:
1.152 raeburn 2679: sub possible_newspares {
2680: my ($server,$currspares,$serverhomes,$altids) = @_;
2681: my $serverhostname = &Apache::lonnet::hostname($server);
2682: my %excluded;
2683: if ($serverhostname ne '') {
2684: %excluded = (
2685: $serverhostname => 1,
2686: );
2687: }
2688: if (ref($currspares) eq 'HASH') {
2689: foreach my $type (keys(%{$currspares})) {
2690: if (ref($currspares->{$type}) eq 'ARRAY') {
2691: if (@{$currspares->{$type}} > 0) {
2692: foreach my $curr (@{$currspares->{$type}}) {
2693: my $hostname = &Apache::lonnet::hostname($curr);
2694: $excluded{$hostname} = 1;
2695: }
2696: }
2697: }
2698: }
2699: }
2700: my @choices;
2701: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2702: if (keys(%{$serverhomes}) > 1) {
2703: foreach my $name (sort(keys(%{$serverhomes}))) {
2704: unless ($excluded{$name}) {
2705: if (exists($altids->{$serverhomes->{$name}})) {
2706: push(@choices,$altids->{$serverhomes->{$name}});
2707: } else {
2708: push(@choices,$serverhomes->{$name});
1.145 raeburn 2709: }
2710: }
2711: }
2712: }
2713: }
1.152 raeburn 2714: return sort(@choices);
1.145 raeburn 2715: }
2716:
1.150 raeburn 2717: sub print_loadbalancing {
2718: my ($dom,$settings,$rowtotal) = @_;
2719: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2720: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2721: my $numinrow = 1;
2722: my $datatable;
2723: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2724: my ($currbalancer,$currtargets,$currrules);
2725: if (keys(%servers) > 1) {
2726: if (ref($settings) eq 'HASH') {
2727: $currbalancer = $settings->{'lonhost'};
2728: $currtargets = $settings->{'targets'};
2729: $currrules = $settings->{'rules'};
2730: } else {
2731: ($currbalancer,$currtargets) =
2732: &Apache::lonnet::get_lonbalancer_config(\%servers);
2733: }
2734: } else {
2735: return;
2736: }
2737: my ($othertitle,$usertypes,$types) =
2738: &Apache::loncommon::sorted_inst_types($dom);
2739: my $rownum = 6;
2740: if (ref($types) eq 'ARRAY') {
2741: $rownum += scalar(@{$types});
2742: }
1.153 raeburn 2743: my $css_class = ' class="LC_odd_row"';
1.150 raeburn 2744: my $targets_div_style = 'display: none';
2745: my $disabled_div_style = 'display: block';
2746: my $homedom_div_style = 'display: none';
2747: $datatable = '<tr'.$css_class.'>'.
2748: '<td rowspan="'.$rownum.'" valign="top">'.
2749: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
2750: '<option value=""';
2751: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
2752: $datatable .= ' selected="selected"';
2753: } else {
2754: $targets_div_style = 'display: block';
2755: $disabled_div_style = 'display: none';
2756: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
2757: $homedom_div_style = 'display: block';
2758: }
2759: }
2760: $datatable .= '>'.&mt('None').'</option>'."\n";
2761: foreach my $lonhost (sort(keys(%servers))) {
2762: my $selected;
2763: if ($lonhost eq $currbalancer) {
2764: $selected .= ' selected="selected"';
2765: }
2766: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
2767: }
2768: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
2769: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
2770: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2771: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
2772: my @sparestypes = ('primary','default');
2773: my %typetitles = &sparestype_titles();
2774: foreach my $sparetype (@sparestypes) {
2775: my $targettable;
2776: for (my $i=0; $i<$numspares; $i++) {
2777: my $checked;
2778: if (ref($currtargets) eq 'HASH') {
2779: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
2780: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
2781: $checked = ' checked="checked"';
2782: }
2783: }
2784: }
2785: my $chkboxval;
2786: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
2787: $chkboxval = $spares[$i];
2788: }
2789: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
2790: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2791: '</span></label></td>';
2792: my $rem = $i%($numinrow);
2793: if ($rem == 0) {
2794: if ($i > 0) {
2795: $targettable .= '</tr>';
2796: }
2797: $targettable .= '<tr>';
2798: }
2799: }
2800: if ($targettable ne '') {
2801: my $rem = $numspares%($numinrow);
2802: my $colsleft = $numinrow - $rem;
2803: if ($colsleft > 1 ) {
2804: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2805: ' </td>';
2806: } elsif ($colsleft == 1) {
2807: $targettable .= '<td class="LC_left_item"> </td>';
2808: }
2809: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2810: '<table><tr>'.$targettable.'</table><br />';
2811: }
2812: }
2813: $datatable .= '</div></td></tr>'.
2814: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
2815: $usertypes,$types,\%servers,$currbalancer,
1.153 raeburn 2816: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2817: $$rowtotal += $rownum;
2818: return $datatable;
2819: }
2820:
2821: sub loadbalancing_rules {
2822: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153 raeburn 2823: $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150 raeburn 2824: my $output;
2825: my ($alltypes,$othertypes,$titles) =
2826: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
2827: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
2828: foreach my $type (@{$alltypes}) {
2829: my $current;
2830: if (ref($currrules) eq 'HASH') {
2831: $current = $currrules->{$type};
2832: }
2833: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2834: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
2835: $current = '';
2836: }
2837: }
2838: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
2839: $servers,$currbalancer,$dom,
1.153 raeburn 2840: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2841: }
2842: }
2843: return $output;
2844: }
2845:
2846: sub loadbalancing_titles {
2847: my ($dom,$intdom,$usertypes,$types) = @_;
2848: my %othertypes = (
2849: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
2850: '_LC_author' => &mt('Users from [_1] with author role',$dom),
2851: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
2852: '_LC_external' => &mt('Users not from [_1]',$intdom),
2853: );
2854: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
2855: if (ref($types) eq 'ARRAY') {
2856: unshift(@alltypes,@{$types},'default');
2857: }
2858: my %titles;
2859: foreach my $type (@alltypes) {
2860: if ($type =~ /^_LC_/) {
2861: $titles{$type} = $othertypes{$type};
2862: } elsif ($type eq 'default') {
2863: $titles{$type} = &mt('All users from [_1]',$dom);
2864: if (ref($types) eq 'ARRAY') {
2865: if (@{$types} > 0) {
2866: $titles{$type} = &mt('Other users from [_1]',$dom);
2867: }
2868: }
2869: } elsif (ref($usertypes) eq 'HASH') {
2870: $titles{$type} = $usertypes->{$type};
2871: }
2872: }
2873: return (\@alltypes,\%othertypes,\%titles);
2874: }
2875:
2876: sub loadbalance_rule_row {
2877: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153 raeburn 2878: $homedom_div_style,$css_class) = @_;
1.150 raeburn 2879: my @rulenames = ('default','homeserver');
2880: my %ruletitles = &offloadtype_text();
2881: if ($type eq '_LC_external') {
2882: push(@rulenames,'externalbalancer');
2883: } else {
2884: push(@rulenames,'specific');
2885: }
2886: my $style = $targets_div_style;
2887: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2888: $style = $homedom_div_style;
2889: }
2890: my $output =
1.153 raeburn 2891: '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150 raeburn 2892: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
2893: for (my $i=0; $i<@rulenames; $i++) {
2894: my $rule = $rulenames[$i];
2895: my ($checked,$extra);
2896: if ($rulenames[$i] eq 'default') {
2897: $rule = '';
2898: }
2899: if ($rulenames[$i] eq 'specific') {
2900: if (ref($servers) eq 'HASH') {
2901: my $default;
2902: if (($current ne '') && (exists($servers->{$current}))) {
2903: $checked = ' checked="checked"';
2904: }
2905: unless ($checked) {
2906: $default = ' selected="selected"';
2907: }
2908: $extra = ': <select name="loadbalancing_singleserver_'.$type.
2909: '" id="loadbalancing_singleserver_'.$type.
2910: '" onchange="singleServerToggle('."'$type'".')">'."\n".
2911: '<option value=""'.$default.'></option>'."\n";
2912: foreach my $lonhost (sort(keys(%{$servers}))) {
2913: next if ($lonhost eq $currbalancer);
2914: my $selected;
2915: if ($lonhost eq $current) {
2916: $selected = ' selected="selected"';
2917: }
2918: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
2919: }
2920: $extra .= '</select>';
2921: }
2922: } elsif ($rule eq $current) {
2923: $checked = ' checked="checked"';
2924: }
2925: $output .= '<span class="LC_nobreak"><label>'.
2926: '<input type="radio" name="loadbalancing_rules_'.$type.
2927: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
2928: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
2929: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
2930: '</label>'.$extra.'</span><br />'."\n";
2931: }
2932: $output .= '</div></td></tr>'."\n";
2933: return $output;
2934: }
2935:
2936: sub offloadtype_text {
2937: my %ruletitles = &Apache::lonlocal::texthash (
2938: 'default' => 'Offloads to default destinations',
2939: 'homeserver' => "Offloads to user's home server",
2940: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
2941: 'specific' => 'Offloads to specific server',
2942: );
2943: return %ruletitles;
2944: }
2945:
2946: sub sparestype_titles {
2947: my %typestitles = &Apache::lonlocal::texthash (
2948: 'primary' => 'primary',
2949: 'default' => 'default',
2950: );
2951: return %typestitles;
2952: }
2953:
1.28 raeburn 2954: sub contact_titles {
2955: my %titles = &Apache::lonlocal::texthash (
2956: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2957: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2958: 'errormail' => 'Error reports to be e-mailed to',
2959: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2960: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2961: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2962: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2963: );
2964: my %short_titles = &Apache::lonlocal::texthash (
2965: adminemail => 'Admin E-mail address',
2966: supportemail => 'Support E-mail',
2967: );
2968: return (\%titles,\%short_titles);
2969: }
2970:
1.72 raeburn 2971: sub tool_titles {
2972: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 2973: aboutme => 'Personal Information Page',
1.86 raeburn 2974: blog => 'Blog',
2975: portfolio => 'Portfolio',
1.88 bisitz 2976: official => 'Official courses (with institutional codes)',
2977: unofficial => 'Unofficial courses',
1.98 raeburn 2978: community => 'Communities',
1.86 raeburn 2979: );
1.72 raeburn 2980: return %titles;
2981: }
2982:
1.101 raeburn 2983: sub courserequest_titles {
2984: my %titles = &Apache::lonlocal::texthash (
2985: official => 'Official',
2986: unofficial => 'Unofficial',
2987: community => 'Communities',
2988: norequest => 'Not allowed',
1.104 raeburn 2989: approval => 'Approval by Dom. Coord.',
1.101 raeburn 2990: validate => 'With validation',
2991: autolimit => 'Numerical limit',
1.103 raeburn 2992: unlimited => '(blank for unlimited)',
1.101 raeburn 2993: );
2994: return %titles;
2995: }
2996:
2997: sub courserequest_conditions {
2998: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 2999: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3000: validate => '(Processing of request subject to instittutional validation).',
3001: );
3002: return %conditions;
3003: }
3004:
3005:
1.27 raeburn 3006: sub print_usercreation {
1.30 raeburn 3007: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3008: my $numinrow = 4;
1.28 raeburn 3009: my $datatable;
3010: if ($position eq 'top') {
1.30 raeburn 3011: $$rowtotal ++;
1.34 raeburn 3012: my $rowcount = 0;
1.32 raeburn 3013: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3014: if (ref($rules) eq 'HASH') {
3015: if (keys(%{$rules}) > 0) {
1.32 raeburn 3016: $datatable .= &user_formats_row('username',$settings,$rules,
3017: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3018: $$rowtotal ++;
1.32 raeburn 3019: $rowcount ++;
3020: }
3021: }
3022: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3023: if (ref($idrules) eq 'HASH') {
3024: if (keys(%{$idrules}) > 0) {
3025: $datatable .= &user_formats_row('id',$settings,$idrules,
3026: $idruleorder,$numinrow,$rowcount);
3027: $$rowtotal ++;
3028: $rowcount ++;
1.28 raeburn 3029: }
3030: }
1.43 raeburn 3031: my ($emailrules,$emailruleorder) =
3032: &Apache::lonnet::inst_userrules($dom,'email');
3033: if (ref($emailrules) eq 'HASH') {
3034: if (keys(%{$emailrules}) > 0) {
3035: $datatable .= &user_formats_row('email',$settings,$emailrules,
3036: $emailruleorder,$numinrow,$rowcount);
3037: $$rowtotal ++;
3038: $rowcount ++;
3039: }
3040: }
1.39 raeburn 3041: if ($rowcount == 0) {
3042: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3043: $$rowtotal ++;
3044: $rowcount ++;
3045: }
1.34 raeburn 3046: } elsif ($position eq 'middle') {
1.100 raeburn 3047: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3048: my ($rules,$ruleorder) =
3049: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3050: my %lt = &usercreation_types();
3051: my %checked;
1.50 raeburn 3052: my @selfcreate;
1.34 raeburn 3053: if (ref($settings) eq 'HASH') {
3054: if (ref($settings->{'cancreate'}) eq 'HASH') {
3055: foreach my $item (@creators) {
3056: $checked{$item} = $settings->{'cancreate'}{$item};
3057: }
1.50 raeburn 3058: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3059: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3060: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3061: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3062: @selfcreate = ('email','login','sso');
3063: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3064: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3065: }
3066: }
1.34 raeburn 3067: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3068: foreach my $item (@creators) {
3069: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3070: $checked{$item} = 'none';
3071: }
3072: }
3073: }
3074: }
3075: my $rownum = 0;
3076: foreach my $item (@creators) {
3077: $rownum ++;
1.50 raeburn 3078: if ($item ne 'selfcreate') {
3079: if ($checked{$item} eq '') {
1.43 raeburn 3080: $checked{$item} = 'any';
3081: }
1.34 raeburn 3082: }
3083: my $css_class;
3084: if ($rownum%2) {
3085: $css_class = '';
3086: } else {
3087: $css_class = ' class="LC_odd_row" ';
3088: }
3089: $datatable .= '<tr'.$css_class.'>'.
3090: '<td><span class="LC_nobreak">'.$lt{$item}.
3091: '</span></td><td align="right">';
1.50 raeburn 3092: my @options;
1.45 raeburn 3093: if ($item eq 'selfcreate') {
1.43 raeburn 3094: push(@options,('email','login','sso'));
3095: } else {
1.50 raeburn 3096: @options = ('any');
1.43 raeburn 3097: if (ref($rules) eq 'HASH') {
3098: if (keys(%{$rules}) > 0) {
3099: push(@options,('official','unofficial'));
3100: }
1.37 raeburn 3101: }
1.50 raeburn 3102: push(@options,'none');
1.37 raeburn 3103: }
3104: foreach my $option (@options) {
1.50 raeburn 3105: my $type = 'radio';
1.34 raeburn 3106: my $check = ' ';
1.50 raeburn 3107: if ($item eq 'selfcreate') {
3108: $type = 'checkbox';
3109: if (grep(/^\Q$option\E$/,@selfcreate)) {
3110: $check = ' checked="checked" ';
3111: }
3112: } else {
3113: if ($checked{$item} eq $option) {
3114: $check = ' checked="checked" ';
3115: }
1.34 raeburn 3116: }
3117: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3118: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3119: $item.'" value="'.$option.'"'.$check.'/> '.
3120: $lt{$option}.'</label> </span>';
3121: }
3122: $datatable .= '</td></tr>';
3123: }
1.93 raeburn 3124: my ($othertitle,$usertypes,$types) =
3125: &Apache::loncommon::sorted_inst_types($dom);
3126: if (ref($usertypes) eq 'HASH') {
3127: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3128: my $createsettings;
3129: if (ref($settings) eq 'HASH') {
3130: $createsettings = $settings->{cancreate};
3131: }
3132: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3133: $dom,$numinrow,$othertitle,
3134: 'statustocreate');
3135: $$rowtotal ++;
3136: }
3137: }
1.28 raeburn 3138: } else {
3139: my @contexts = ('author','course','domain');
3140: my @authtypes = ('int','krb4','krb5','loc');
3141: my %checked;
3142: if (ref($settings) eq 'HASH') {
3143: if (ref($settings->{'authtypes'}) eq 'HASH') {
3144: foreach my $item (@contexts) {
3145: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3146: foreach my $auth (@authtypes) {
3147: if ($settings->{'authtypes'}{$item}{$auth}) {
3148: $checked{$item}{$auth} = ' checked="checked" ';
3149: }
3150: }
3151: }
3152: }
1.27 raeburn 3153: }
1.35 raeburn 3154: } else {
3155: foreach my $item (@contexts) {
1.36 raeburn 3156: foreach my $auth (@authtypes) {
1.35 raeburn 3157: $checked{$item}{$auth} = ' checked="checked" ';
3158: }
3159: }
1.27 raeburn 3160: }
1.28 raeburn 3161: my %title = &context_names();
3162: my %authname = &authtype_names();
3163: my $rownum = 0;
3164: my $css_class;
3165: foreach my $item (@contexts) {
3166: if ($rownum%2) {
3167: $css_class = '';
3168: } else {
3169: $css_class = ' class="LC_odd_row" ';
3170: }
1.30 raeburn 3171: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3172: '<td>'.$title{$item}.
3173: '</td><td class="LC_left_item">'.
3174: '<span class="LC_nobreak">';
3175: foreach my $auth (@authtypes) {
3176: $datatable .= '<label>'.
3177: '<input type="checkbox" name="'.$item.'_auth" '.
3178: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3179: $authname{$auth}.'</label> ';
3180: }
3181: $datatable .= '</span></td></tr>';
3182: $rownum ++;
1.27 raeburn 3183: }
1.30 raeburn 3184: $$rowtotal += $rownum;
1.27 raeburn 3185: }
3186: return $datatable;
3187: }
3188:
1.32 raeburn 3189: sub user_formats_row {
3190: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3191: my $output;
3192: my %text = (
3193: 'username' => 'new usernames',
3194: 'id' => 'IDs',
1.45 raeburn 3195: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3196: );
3197: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3198: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3199: '<td><span class="LC_nobreak">';
3200: if ($type eq 'email') {
3201: $output .= &mt("Formats disallowed for $text{$type}: ");
3202: } else {
3203: $output .= &mt("Format rules to check for $text{$type}: ");
3204: }
3205: $output .= '</span></td>'.
3206: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3207: my $rem;
3208: if (ref($ruleorder) eq 'ARRAY') {
3209: for (my $i=0; $i<@{$ruleorder}; $i++) {
3210: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3211: my $rem = $i%($numinrow);
3212: if ($rem == 0) {
3213: if ($i > 0) {
3214: $output .= '</tr>';
3215: }
3216: $output .= '<tr>';
3217: }
3218: my $check = ' ';
1.39 raeburn 3219: if (ref($settings) eq 'HASH') {
3220: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3221: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3222: $check = ' checked="checked" ';
3223: }
1.27 raeburn 3224: }
3225: }
3226: $output .= '<td class="LC_left_item">'.
3227: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3228: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3229: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3230: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3231: }
3232: }
3233: $rem = @{$ruleorder}%($numinrow);
3234: }
3235: my $colsleft = $numinrow - $rem;
3236: if ($colsleft > 1 ) {
3237: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3238: ' </td>';
3239: } elsif ($colsleft == 1) {
3240: $output .= '<td class="LC_left_item"> </td>';
3241: }
3242: $output .= '</tr></table></td></tr>';
3243: return $output;
3244: }
3245:
1.34 raeburn 3246: sub usercreation_types {
3247: my %lt = &Apache::lonlocal::texthash (
3248: author => 'When adding a co-author',
3249: course => 'When adding a user to a course',
1.100 raeburn 3250: requestcrs => 'When requesting a course',
1.45 raeburn 3251: selfcreate => 'User creates own account',
1.34 raeburn 3252: any => 'Any',
3253: official => 'Institutional only ',
3254: unofficial => 'Non-institutional only',
1.85 schafran 3255: email => 'E-mail address',
1.43 raeburn 3256: login => 'Institutional Login',
3257: sso => 'SSO',
1.34 raeburn 3258: none => 'None',
3259: );
3260: return %lt;
1.48 raeburn 3261: }
1.34 raeburn 3262:
1.28 raeburn 3263: sub authtype_names {
3264: my %lt = &Apache::lonlocal::texthash(
3265: int => 'Internal',
3266: krb4 => 'Kerberos 4',
3267: krb5 => 'Kerberos 5',
3268: loc => 'Local',
3269: );
3270: return %lt;
3271: }
3272:
3273: sub context_names {
3274: my %context_title = &Apache::lonlocal::texthash(
3275: author => 'Creating users when an Author',
3276: course => 'Creating users when in a course',
3277: domain => 'Creating users when a Domain Coordinator',
3278: );
3279: return %context_title;
3280: }
3281:
1.33 raeburn 3282: sub print_usermodification {
3283: my ($position,$dom,$settings,$rowtotal) = @_;
3284: my $numinrow = 4;
3285: my ($context,$datatable,$rowcount);
3286: if ($position eq 'top') {
3287: $rowcount = 0;
3288: $context = 'author';
3289: foreach my $role ('ca','aa') {
3290: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3291: $numinrow,$rowcount);
3292: $$rowtotal ++;
3293: $rowcount ++;
3294: }
1.63 raeburn 3295: } elsif ($position eq 'middle') {
1.33 raeburn 3296: $context = 'course';
3297: $rowcount = 0;
3298: foreach my $role ('st','ep','ta','in','cr') {
3299: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3300: $numinrow,$rowcount);
3301: $$rowtotal ++;
3302: $rowcount ++;
3303: }
1.63 raeburn 3304: } elsif ($position eq 'bottom') {
3305: $context = 'selfcreate';
3306: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3307: $usertypes->{'default'} = $othertitle;
3308: if (ref($types) eq 'ARRAY') {
3309: push(@{$types},'default');
3310: $usertypes->{'default'} = $othertitle;
3311: foreach my $status (@{$types}) {
3312: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3313: $numinrow,$rowcount,$usertypes);
3314: $$rowtotal ++;
3315: $rowcount ++;
3316: }
3317: }
1.33 raeburn 3318: }
3319: return $datatable;
3320: }
3321:
1.43 raeburn 3322: sub print_defaults {
3323: my ($dom,$rowtotal) = @_;
1.68 raeburn 3324: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3325: 'datelocale_def','portal_def');
1.43 raeburn 3326: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3327: my $titles = &defaults_titles($dom);
1.43 raeburn 3328: my $rownum = 0;
3329: my ($datatable,$css_class);
3330: foreach my $item (@items) {
3331: if ($rownum%2) {
3332: $css_class = '';
3333: } else {
3334: $css_class = ' class="LC_odd_row" ';
3335: }
3336: $datatable .= '<tr'.$css_class.'>'.
3337: '<td><span class="LC_nobreak">'.$titles->{$item}.
3338: '</span></td><td class="LC_right_item">';
3339: if ($item eq 'auth_def') {
3340: my @authtypes = ('internal','krb4','krb5','localauth');
3341: my %shortauth = (
3342: internal => 'int',
3343: krb4 => 'krb4',
3344: krb5 => 'krb5',
3345: localauth => 'loc'
3346: );
3347: my %authnames = &authtype_names();
3348: foreach my $auth (@authtypes) {
3349: my $checked = ' ';
3350: if ($domdefaults{$item} eq $auth) {
3351: $checked = ' checked="checked" ';
3352: }
3353: $datatable .= '<label><input type="radio" name="'.$item.
3354: '" value="'.$auth.'"'.$checked.'/>'.
3355: $authnames{$shortauth{$auth}}.'</label> ';
3356: }
1.54 raeburn 3357: } elsif ($item eq 'timezone_def') {
3358: my $includeempty = 1;
3359: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3360: } elsif ($item eq 'datelocale_def') {
3361: my $includeempty = 1;
3362: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 3363: } else {
1.141 raeburn 3364: my $size;
3365: if ($item eq 'portal_def') {
3366: $size = ' size="25"';
3367: }
1.43 raeburn 3368: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3369: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3370: }
3371: $datatable .= '</td></tr>';
3372: $rownum ++;
3373: }
3374: $$rowtotal += $rownum;
3375: return $datatable;
3376: }
3377:
3378: sub defaults_titles {
1.141 raeburn 3379: my ($dom) = @_;
1.43 raeburn 3380: my %titles = &Apache::lonlocal::texthash (
3381: 'auth_def' => 'Default authentication type',
3382: 'auth_arg_def' => 'Default authentication argument',
3383: 'lang_def' => 'Default language',
1.54 raeburn 3384: 'timezone_def' => 'Default timezone',
1.68 raeburn 3385: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3386: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3387: );
1.141 raeburn 3388: if ($dom) {
3389: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3390: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3391: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3392: $protocol = 'http' if ($protocol ne 'https');
3393: if ($uint_dom) {
3394: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3395: $uint_dom);
3396: }
3397: }
1.43 raeburn 3398: return (\%titles);
3399: }
3400:
1.46 raeburn 3401: sub print_scantronformat {
3402: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3403: my $itemcount = 1;
1.60 raeburn 3404: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3405: %confhash);
1.46 raeburn 3406: my $switchserver = &check_switchserver($dom,$confname);
3407: my %lt = &Apache::lonlocal::texthash (
1.95 www 3408: default => 'Default bubblesheet format file error',
3409: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3410: );
3411: my %scantronfiles = (
3412: default => 'default.tab',
3413: custom => 'custom.tab',
3414: );
3415: foreach my $key (keys(%scantronfiles)) {
3416: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3417: .$scantronfiles{$key};
3418: }
3419: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3420: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3421: if (!$switchserver) {
3422: my $servadm = $r->dir_config('lonAdmEMail');
3423: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3424: if ($configuserok eq 'ok') {
3425: if ($author_ok eq 'ok') {
3426: my %legacyfile = (
3427: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3428: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3429: );
3430: my %md5chk;
3431: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3432: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3433: chomp($md5chk{$type});
1.46 raeburn 3434: }
3435: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3436: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3437: ($scantronurls{$type},my $error) =
1.46 raeburn 3438: &legacy_scantronformat($r,$dom,$confname,
3439: $type,$legacyfile{$type},
3440: $scantronurls{$type},
3441: $scantronfiles{$type});
1.60 raeburn 3442: if ($error ne '') {
3443: $error{$type} = $error;
3444: }
3445: }
3446: if (keys(%error) == 0) {
3447: $is_custom = 1;
3448: $confhash{'scantron'}{'scantronformat'} =
3449: $scantronurls{'custom'};
3450: my $putresult =
3451: &Apache::lonnet::put_dom('configuration',
3452: \%confhash,$dom);
3453: if ($putresult ne 'ok') {
3454: $error{'custom'} =
3455: '<span class="LC_error">'.
3456: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3457: }
1.46 raeburn 3458: }
3459: } else {
1.60 raeburn 3460: ($scantronurls{'default'},my $error) =
1.46 raeburn 3461: &legacy_scantronformat($r,$dom,$confname,
3462: 'default',$legacyfile{'default'},
3463: $scantronurls{'default'},
3464: $scantronfiles{'default'});
1.60 raeburn 3465: if ($error eq '') {
3466: $confhash{'scantron'}{'scantronformat'} = '';
3467: my $putresult =
3468: &Apache::lonnet::put_dom('configuration',
3469: \%confhash,$dom);
3470: if ($putresult ne 'ok') {
3471: $error{'default'} =
3472: '<span class="LC_error">'.
3473: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3474: }
3475: } else {
3476: $error{'default'} = $error;
3477: }
1.46 raeburn 3478: }
3479: }
3480: }
3481: } else {
1.95 www 3482: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3483: }
3484: }
3485: if (ref($settings) eq 'HASH') {
3486: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3487: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3488: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3489: $scantronurl = '';
3490: } else {
3491: $scantronurl = $settings->{'scantronformat'};
3492: }
3493: $is_custom = 1;
3494: } else {
3495: $scantronurl = $scantronurls{'default'};
3496: }
3497: } else {
1.60 raeburn 3498: if ($is_custom) {
3499: $scantronurl = $scantronurls{'custom'};
3500: } else {
3501: $scantronurl = $scantronurls{'default'};
3502: }
1.46 raeburn 3503: }
3504: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3505: $datatable .= '<tr'.$css_class.'>';
3506: if (!$is_custom) {
1.65 raeburn 3507: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3508: '<span class="LC_nobreak">';
1.46 raeburn 3509: if ($scantronurl) {
3510: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3511: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3512: } else {
3513: $datatable = &mt('File unavailable for display');
3514: }
1.65 raeburn 3515: $datatable .= '</span></td>';
1.60 raeburn 3516: if (keys(%error) == 0) {
3517: $datatable .= '<td valign="bottom">';
3518: if (!$switchserver) {
3519: $datatable .= &mt('Upload:').'<br />';
3520: }
3521: } else {
3522: my $errorstr;
3523: foreach my $key (sort(keys(%error))) {
3524: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3525: }
3526: $datatable .= '<td>'.$errorstr;
3527: }
1.46 raeburn 3528: } else {
3529: if (keys(%error) > 0) {
3530: my $errorstr;
3531: foreach my $key (sort(keys(%error))) {
3532: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3533: }
1.60 raeburn 3534: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3535: } elsif ($scantronurl) {
1.65 raeburn 3536: $datatable .= '<td><span class="LC_nobreak">'.
3537: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3538: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3539: '<input type="checkbox" name="scantronformat_del"'.
3540: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3541: '<td><span class="LC_nobreak"> '.
3542: &mt('Replace:').'</span><br />';
1.46 raeburn 3543: }
3544: }
3545: if (keys(%error) == 0) {
3546: if ($switchserver) {
3547: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3548: } else {
1.65 raeburn 3549: $datatable .='<span class="LC_nobreak"> '.
3550: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3551: }
3552: }
3553: $datatable .= '</td></tr>';
3554: $$rowtotal ++;
3555: return $datatable;
3556: }
3557:
3558: sub legacy_scantronformat {
3559: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3560: my ($url,$error);
3561: my @statinfo = &Apache::lonnet::stat_file($newurl);
3562: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3563: (my $result,$url) =
3564: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3565: '','',$newfile);
3566: if ($result ne 'ok') {
1.130 raeburn 3567: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3568: }
3569: }
3570: return ($url,$error);
3571: }
1.43 raeburn 3572:
1.49 raeburn 3573: sub print_coursecategories {
1.57 raeburn 3574: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3575: my $datatable;
3576: if ($position eq 'top') {
3577: my $toggle_cats_crs = ' ';
3578: my $toggle_cats_dom = ' checked="checked" ';
3579: my $can_cat_crs = ' ';
3580: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3581: my $toggle_catscomm_comm = ' ';
3582: my $toggle_catscomm_dom = ' checked="checked" ';
3583: my $can_catcomm_comm = ' ';
3584: my $can_catcomm_dom = ' checked="checked" ';
3585:
1.57 raeburn 3586: if (ref($settings) eq 'HASH') {
3587: if ($settings->{'togglecats'} eq 'crs') {
3588: $toggle_cats_crs = $toggle_cats_dom;
3589: $toggle_cats_dom = ' ';
3590: }
3591: if ($settings->{'categorize'} eq 'crs') {
3592: $can_cat_crs = $can_cat_dom;
3593: $can_cat_dom = ' ';
3594: }
1.120 raeburn 3595: if ($settings->{'togglecatscomm'} eq 'comm') {
3596: $toggle_catscomm_comm = $toggle_catscomm_dom;
3597: $toggle_catscomm_dom = ' ';
3598: }
3599: if ($settings->{'categorizecomm'} eq 'comm') {
3600: $can_catcomm_comm = $can_catcomm_dom;
3601: $can_catcomm_dom = ' ';
3602: }
1.57 raeburn 3603: }
3604: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3605: togglecats => 'Show/Hide a course in catalog',
3606: togglecatscomm => 'Show/Hide a community in catalog',
3607: categorize => 'Assign a category to a course',
3608: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3609: );
3610: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3611: dom => 'Set in Domain',
3612: crs => 'Set in Course',
3613: comm => 'Set in Community',
1.57 raeburn 3614: );
3615: $datatable = '<tr class="LC_odd_row">'.
3616: '<td>'.$title{'togglecats'}.'</td>'.
3617: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3618: '<input type="radio" name="togglecats"'.
3619: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3620: '<label><input type="radio" name="togglecats"'.
3621: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3622: '</tr><tr>'.
3623: '<td>'.$title{'categorize'}.'</td>'.
3624: '<td class="LC_right_item"><span class="LC_nobreak">'.
3625: '<label><input type="radio" name="categorize"'.
3626: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3627: '<label><input type="radio" name="categorize"'.
3628: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3629: '</tr><tr class="LC_odd_row">'.
3630: '<td>'.$title{'togglecatscomm'}.'</td>'.
3631: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3632: '<input type="radio" name="togglecatscomm"'.
3633: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3634: '<label><input type="radio" name="togglecatscomm"'.
3635: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3636: '</tr><tr>'.
3637: '<td>'.$title{'categorizecomm'}.'</td>'.
3638: '<td class="LC_right_item"><span class="LC_nobreak">'.
3639: '<label><input type="radio" name="categorizecomm"'.
3640: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3641: '<label><input type="radio" name="categorizecomm"'.
3642: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3643: '</tr>';
1.120 raeburn 3644: $$rowtotal += 4;
1.57 raeburn 3645: } else {
3646: my $css_class;
3647: my $itemcount = 1;
3648: my $cathash;
3649: if (ref($settings) eq 'HASH') {
3650: $cathash = $settings->{'cats'};
3651: }
3652: if (ref($cathash) eq 'HASH') {
3653: my (@cats,@trails,%allitems,%idx,@jsarray);
3654: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3655: \%allitems,\%idx,\@jsarray);
3656: my $maxdepth = scalar(@cats);
3657: my $colattrib = '';
3658: if ($maxdepth > 2) {
3659: $colattrib = ' colspan="2" ';
3660: }
3661: my @path;
3662: if (@cats > 0) {
3663: if (ref($cats[0]) eq 'ARRAY') {
3664: my $numtop = @{$cats[0]};
3665: my $maxnum = $numtop;
1.120 raeburn 3666: my %default_names = (
3667: instcode => &mt('Official courses'),
3668: communities => &mt('Communities'),
3669: );
3670:
3671: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3672: ($cathash->{'instcode::0'} eq '') ||
3673: (!grep(/^communities$/,@{$cats[0]})) ||
3674: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3675: $maxnum ++;
3676: }
3677: my $lastidx;
3678: for (my $i=0; $i<$numtop; $i++) {
3679: my $parent = $cats[0][$i];
3680: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3681: my $item = &escape($parent).'::0';
3682: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3683: $lastidx = $idx{$item};
3684: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3685: .'<select name="'.$item.'"'.$chgstr.'>';
3686: for (my $k=0; $k<=$maxnum; $k++) {
3687: my $vpos = $k+1;
3688: my $selstr;
3689: if ($k == $i) {
3690: $selstr = ' selected="selected" ';
3691: }
3692: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3693: }
3694: $datatable .= '</select></td><td>';
1.120 raeburn 3695: if ($parent eq 'instcode' || $parent eq 'communities') {
3696: $datatable .= '<span class="LC_nobreak">'
3697: .$default_names{$parent}.'</span>';
3698: if ($parent eq 'instcode') {
3699: $datatable .= '<br /><span class="LC_nobreak">('
3700: .&mt('with institutional codes')
3701: .')</span></td><td'.$colattrib.'>';
3702: } else {
3703: $datatable .= '<table><tr><td>';
3704: }
3705: $datatable .= '<span class="LC_nobreak">'
3706: .'<label><input type="radio" name="'
3707: .$parent.'" value="1" checked="checked" />'
3708: .&mt('Display').'</label>';
3709: if ($parent eq 'instcode') {
3710: $datatable .= ' ';
3711: } else {
3712: $datatable .= '</span></td></tr><tr><td>'
3713: .'<span class="LC_nobreak">';
3714: }
3715: $datatable .= '<label><input type="radio" name="'
3716: .$parent.'" value="0" />'
3717: .&mt('Do not display').'</label></span>';
3718: if ($parent eq 'communities') {
3719: $datatable .= '</td></tr></table>';
3720: }
3721: $datatable .= '</td>';
1.57 raeburn 3722: } else {
3723: $datatable .= $parent
3724: .' <label><input type="checkbox" name="deletecategory" '
3725: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3726: }
3727: my $depth = 1;
3728: push(@path,$parent);
3729: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3730: pop(@path);
3731: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3732: $itemcount ++;
3733: }
1.48 raeburn 3734: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3735: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3736: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3737: for (my $k=0; $k<=$maxnum; $k++) {
3738: my $vpos = $k+1;
3739: my $selstr;
1.57 raeburn 3740: if ($k == $numtop) {
1.48 raeburn 3741: $selstr = ' selected="selected" ';
3742: }
3743: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3744: }
1.59 bisitz 3745: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3746: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3747: .'</tr>'."\n";
1.48 raeburn 3748: $itemcount ++;
1.120 raeburn 3749: foreach my $default ('instcode','communities') {
3750: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3751: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3752: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3753: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3754: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3755: for (my $k=0; $k<=$maxnum; $k++) {
3756: my $vpos = $k+1;
3757: my $selstr;
3758: if ($k == $maxnum) {
3759: $selstr = ' selected="selected" ';
3760: }
3761: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3762: }
1.120 raeburn 3763: $datatable .= '</select></span></td>'.
3764: '<td><span class="LC_nobreak">'.
3765: $default_names{$default}.'</span>';
3766: if ($default eq 'instcode') {
3767: $datatable .= '<br /><span class="LC_nobreak">('
3768: .&mt('with institutional codes').')</span>';
3769: }
3770: $datatable .= '</td>'
3771: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3772: .&mt('Display').'</label> '
3773: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3774: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3775: }
3776: }
3777: }
1.57 raeburn 3778: } else {
3779: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3780: }
3781: } else {
1.57 raeburn 3782: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3783: .&initialize_categories($itemcount);
1.48 raeburn 3784: }
1.57 raeburn 3785: $$rowtotal += $itemcount;
1.48 raeburn 3786: }
3787: return $datatable;
3788: }
3789:
1.69 raeburn 3790: sub print_serverstatuses {
3791: my ($dom,$settings,$rowtotal) = @_;
3792: my $datatable;
3793: my @pages = &serverstatus_pages();
3794: my (%namedaccess,%machineaccess);
3795: foreach my $type (@pages) {
3796: $namedaccess{$type} = '';
3797: $machineaccess{$type}= '';
3798: }
3799: if (ref($settings) eq 'HASH') {
3800: foreach my $type (@pages) {
3801: if (exists($settings->{$type})) {
3802: if (ref($settings->{$type}) eq 'HASH') {
3803: foreach my $key (keys(%{$settings->{$type}})) {
3804: if ($key eq 'namedusers') {
3805: $namedaccess{$type} = $settings->{$type}->{$key};
3806: } elsif ($key eq 'machines') {
3807: $machineaccess{$type} = $settings->{$type}->{$key};
3808: }
3809: }
3810: }
3811: }
3812: }
3813: }
1.81 raeburn 3814: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3815: my $rownum = 0;
3816: my $css_class;
3817: foreach my $type (@pages) {
3818: $rownum ++;
3819: $css_class = $rownum%2?' class="LC_odd_row"':'';
3820: $datatable .= '<tr'.$css_class.'>'.
3821: '<td><span class="LC_nobreak">'.
3822: $titles->{$type}.'</span></td>'.
3823: '<td class="LC_left_item">'.
3824: '<input type="text" name="'.$type.'_namedusers" '.
3825: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3826: '<td class="LC_right_item">'.
3827: '<span class="LC_nobreak">'.
3828: '<input type="text" name="'.$type.'_machines" '.
3829: 'value="'.$machineaccess{$type}.'" size="10" />'.
3830: '</td></tr>'."\n";
3831: }
3832: $$rowtotal += $rownum;
3833: return $datatable;
3834: }
3835:
3836: sub serverstatus_pages {
3837: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3838: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 3839: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 3840: }
3841:
1.49 raeburn 3842: sub coursecategories_javascript {
3843: my ($settings) = @_;
1.57 raeburn 3844: my ($output,$jstext,$cathash);
1.49 raeburn 3845: if (ref($settings) eq 'HASH') {
1.57 raeburn 3846: $cathash = $settings->{'cats'};
3847: }
3848: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3849: my (@cats,@jsarray,%idx);
1.57 raeburn 3850: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3851: if (@jsarray > 0) {
3852: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3853: for (my $i=0; $i<@jsarray; $i++) {
3854: if (ref($jsarray[$i]) eq 'ARRAY') {
3855: my $catstr = join('","',@{$jsarray[$i]});
3856: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3857: }
3858: }
3859: }
3860: } else {
3861: $jstext = ' var categories = Array(1);'."\n".
3862: ' categories[0] = Array("instcode_pos");'."\n";
3863: }
1.120 raeburn 3864: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3865: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3866: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3867: $output = <<"ENDSCRIPT";
3868: <script type="text/javascript">
1.109 raeburn 3869: // <![CDATA[
1.49 raeburn 3870: function reorderCats(form,parent,item,idx) {
3871: var changedVal;
3872: $jstext
3873: var newpos = 'addcategory_pos';
3874: var current = new Array;
3875: if (parent == '') {
3876: var has_instcode = 0;
3877: var maxtop = categories[idx].length;
3878: for (var j=0; j<maxtop; j++) {
3879: if (categories[idx][j] == 'instcode::0') {
3880: has_instcode == 1;
3881: }
3882: }
3883: if (has_instcode == 0) {
3884: categories[idx][maxtop] = 'instcode_pos';
3885: }
3886: } else {
3887: newpos += '_'+parent;
3888: }
3889: var maxh = 1 + categories[idx].length;
3890: var current = new Array;
3891: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3892: if (item == newpos) {
3893: changedVal = newitemVal;
3894: } else {
3895: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3896: current[newitemVal] = newpos;
3897: }
3898: for (var i=0; i<categories[idx].length; i++) {
3899: var elementName = categories[idx][i];
3900: if (elementName != item) {
3901: if (form.elements[elementName]) {
3902: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3903: current[currVal] = elementName;
3904: }
3905: }
3906: }
3907: var oldVal;
3908: for (var j=0; j<maxh; j++) {
3909: if (current[j] == undefined) {
3910: oldVal = j;
3911: }
3912: }
3913: if (oldVal < changedVal) {
3914: for (var k=oldVal+1; k<=changedVal ; k++) {
3915: var elementName = current[k];
3916: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3917: }
3918: } else {
3919: for (var k=changedVal; k<oldVal; k++) {
3920: var elementName = current[k];
3921: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3922: }
3923: }
3924: return;
3925: }
1.120 raeburn 3926:
3927: function categoryCheck(form) {
3928: if (form.elements['addcategory_name'].value == 'instcode') {
3929: alert('$instcode_reserved\\n$choose_again');
3930: return false;
3931: }
3932: if (form.elements['addcategory_name'].value == 'communities') {
3933: alert('$communities_reserved\\n$choose_again');
3934: return false;
3935: }
3936: return true;
3937: }
3938:
1.109 raeburn 3939: // ]]>
1.49 raeburn 3940: </script>
3941:
3942: ENDSCRIPT
3943: return $output;
3944: }
3945:
1.48 raeburn 3946: sub initialize_categories {
3947: my ($itemcount) = @_;
1.120 raeburn 3948: my ($datatable,$css_class,$chgstr);
3949: my %default_names = (
3950: instcode => 'Official courses (with institutional codes)',
3951: communities => 'Communities',
3952: );
3953: my $select0 = ' selected="selected"';
3954: my $select1 = '';
3955: foreach my $default ('instcode','communities') {
3956: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3957: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3958: if ($default eq 'communities') {
3959: $select1 = $select0;
3960: $select0 = '';
3961: }
3962: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3963: .'<select name="'.$default.'_pos">'
3964: .'<option value="0"'.$select0.'>1</option>'
3965: .'<option value="1"'.$select1.'>2</option>'
3966: .'<option value="2">3</option></select> '
3967: .$default_names{$default}
3968: .'</span></td><td><span class="LC_nobreak">'
3969: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3970: .&mt('Display').'</label> <label>'
3971: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 3972: .'</label></span></td></tr>';
1.120 raeburn 3973: $itemcount ++;
3974: }
1.48 raeburn 3975: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 3976: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 3977: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 3978: .'<select name="addcategory_pos"'.$chgstr.'>'
3979: .'<option value="0">1</option>'
3980: .'<option value="1">2</option>'
3981: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 3982: .&mt('Add category').'</td><td>'.&mt('Name:')
3983: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
3984: return $datatable;
3985: }
3986:
3987: sub build_category_rows {
1.49 raeburn 3988: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
3989: my ($text,$name,$item,$chgstr);
1.48 raeburn 3990: if (ref($cats) eq 'ARRAY') {
3991: my $maxdepth = scalar(@{$cats});
3992: if (ref($cats->[$depth]) eq 'HASH') {
3993: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
3994: my $numchildren = @{$cats->[$depth]{$parent}};
3995: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3996: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 3997: my ($idxnum,$parent_name,$parent_item);
3998: my $higher = $depth - 1;
3999: if ($higher == 0) {
4000: $parent_name = &escape($parent).'::'.$higher;
4001: } else {
4002: if (ref($path) eq 'ARRAY') {
4003: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4004: }
4005: }
4006: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4007: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4008: if ($j < $numchildren) {
1.48 raeburn 4009: $name = $cats->[$depth]{$parent}[$j];
4010: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4011: $idxnum = $idx->{$item};
4012: } else {
4013: $name = $parent_name;
4014: $item = $parent_item;
1.48 raeburn 4015: }
1.49 raeburn 4016: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4017: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4018: for (my $i=0; $i<=$numchildren; $i++) {
4019: my $vpos = $i+1;
4020: my $selstr;
4021: if ($j == $i) {
4022: $selstr = ' selected="selected" ';
4023: }
4024: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4025: }
4026: $text .= '</select> ';
4027: if ($j < $numchildren) {
4028: my $deeper = $depth+1;
4029: $text .= $name.' '
4030: .'<label><input type="checkbox" name="deletecategory" value="'
4031: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4032: if(ref($path) eq 'ARRAY') {
4033: push(@{$path},$name);
1.49 raeburn 4034: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4035: pop(@{$path});
4036: }
4037: } else {
1.59 bisitz 4038: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4039: if ($j == $numchildren) {
4040: $text .= $name;
4041: } else {
4042: $text .= $item;
4043: }
4044: $text .= '" value="" />';
4045: }
4046: $text .= '</td></tr>';
4047: }
4048: $text .= '</table></td>';
4049: } else {
4050: my $higher = $depth-1;
4051: if ($higher == 0) {
4052: $name = &escape($parent).'::'.$higher;
4053: } else {
4054: if (ref($path) eq 'ARRAY') {
4055: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4056: }
4057: }
4058: my $colspan;
4059: if ($parent ne 'instcode') {
4060: $colspan = $maxdepth - $depth - 1;
4061: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4062: }
4063: }
4064: }
4065: }
4066: return $text;
4067: }
4068:
1.33 raeburn 4069: sub modifiable_userdata_row {
1.63 raeburn 4070: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4071: my $rolename;
1.63 raeburn 4072: if ($context eq 'selfcreate') {
4073: if (ref($usertypes) eq 'HASH') {
4074: $rolename = $usertypes->{$role};
4075: } else {
4076: $rolename = $role;
4077: }
1.33 raeburn 4078: } else {
1.63 raeburn 4079: if ($role eq 'cr') {
4080: $rolename = &mt('Custom role');
4081: } else {
4082: $rolename = &Apache::lonnet::plaintext($role);
4083: }
1.33 raeburn 4084: }
4085: my @fields = ('lastname','firstname','middlename','generation',
4086: 'permanentemail','id');
4087: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4088: my $output;
4089: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4090: $output = '<tr '.$css_class.'>'.
4091: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4092: '<td class="LC_left_item" colspan="2"><table>';
4093: my $rem;
4094: my %checks;
4095: if (ref($settings) eq 'HASH') {
4096: if (ref($settings->{$context}) eq 'HASH') {
4097: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4098: foreach my $field (@fields) {
4099: if ($settings->{$context}->{$role}->{$field}) {
4100: $checks{$field} = ' checked="checked" ';
4101: }
4102: }
4103: }
4104: }
4105: }
4106: for (my $i=0; $i<@fields; $i++) {
4107: my $rem = $i%($numinrow);
4108: if ($rem == 0) {
4109: if ($i > 0) {
4110: $output .= '</tr>';
4111: }
4112: $output .= '<tr>';
4113: }
4114: my $check = ' ';
4115: if (exists($checks{$fields[$i]})) {
4116: $check = $checks{$fields[$i]}
4117: } else {
4118: if ($role eq 'st') {
4119: if (ref($settings) ne 'HASH') {
4120: $check = ' checked="checked" ';
4121: }
4122: }
4123: }
4124: $output .= '<td class="LC_left_item">'.
4125: '<span class="LC_nobreak"><label>'.
4126: '<input type="checkbox" name="canmodify_'.$role.'" '.
4127: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4128: '</label></span></td>';
4129: $rem = @fields%($numinrow);
4130: }
4131: my $colsleft = $numinrow - $rem;
4132: if ($colsleft > 1 ) {
4133: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4134: ' </td>';
4135: } elsif ($colsleft == 1) {
4136: $output .= '<td class="LC_left_item"> </td>';
4137: }
4138: $output .= '</tr></table></td></tr>';
4139: return $output;
4140: }
1.28 raeburn 4141:
1.93 raeburn 4142: sub insttypes_row {
4143: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4144: my %lt = &Apache::lonlocal::texthash (
4145: cansearch => 'Users allowed to search',
4146: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4147: lockablenames => 'User preference to lock name',
1.93 raeburn 4148: );
4149: my $showdom;
4150: if ($context eq 'cansearch') {
4151: $showdom = ' ('.$dom.')';
4152: }
1.25 raeburn 4153: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4154: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 4155: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 4156: my $rem;
4157: if (ref($types) eq 'ARRAY') {
4158: for (my $i=0; $i<@{$types}; $i++) {
4159: if (defined($usertypes->{$types->[$i]})) {
4160: my $rem = $i%($numinrow);
4161: if ($rem == 0) {
4162: if ($i > 0) {
4163: $output .= '</tr>';
4164: }
4165: $output .= '<tr>';
1.23 raeburn 4166: }
1.26 raeburn 4167: my $check = ' ';
1.99 raeburn 4168: if (ref($settings) eq 'HASH') {
4169: if (ref($settings->{$context}) eq 'ARRAY') {
4170: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4171: $check = ' checked="checked" ';
4172: }
4173: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4174: $check = ' checked="checked" ';
4175: }
1.23 raeburn 4176: }
1.26 raeburn 4177: $output .= '<td class="LC_left_item">'.
4178: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4179: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4180: 'value="'.$types->[$i].'"'.$check.'/>'.
4181: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4182: }
4183: }
1.26 raeburn 4184: $rem = @{$types}%($numinrow);
1.23 raeburn 4185: }
4186: my $colsleft = $numinrow - $rem;
1.131 raeburn 4187: if (($rem == 0) && (@{$types} > 0)) {
4188: $output .= '<tr>';
4189: }
1.23 raeburn 4190: if ($colsleft > 1) {
1.25 raeburn 4191: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4192: } else {
1.25 raeburn 4193: $output .= '<td class="LC_left_item">';
1.23 raeburn 4194: }
4195: my $defcheck = ' ';
1.99 raeburn 4196: if (ref($settings) eq 'HASH') {
4197: if (ref($settings->{$context}) eq 'ARRAY') {
4198: if (grep(/^default$/,@{$settings->{$context}})) {
4199: $defcheck = ' checked="checked" ';
4200: }
4201: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4202: $defcheck = ' checked="checked" ';
4203: }
1.23 raeburn 4204: }
1.25 raeburn 4205: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4206: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4207: 'value="default"'.$defcheck.'/>'.
4208: $othertitle.'</label></span></td>'.
4209: '</tr></table></td></tr>';
4210: return $output;
1.23 raeburn 4211: }
4212:
4213: sub sorted_searchtitles {
4214: my %searchtitles = &Apache::lonlocal::texthash(
4215: 'uname' => 'username',
4216: 'lastname' => 'last name',
4217: 'lastfirst' => 'last name, first name',
4218: );
4219: my @titleorder = ('uname','lastname','lastfirst');
4220: return (\%searchtitles,\@titleorder);
4221: }
4222:
1.25 raeburn 4223: sub sorted_searchtypes {
4224: my %srchtypes_desc = (
4225: exact => 'is exact match',
4226: contains => 'contains ..',
4227: begins => 'begins with ..',
4228: );
4229: my @srchtypeorder = ('exact','begins','contains');
4230: return (\%srchtypes_desc,\@srchtypeorder);
4231: }
4232:
1.3 raeburn 4233: sub usertype_update_row {
4234: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4235: my $datatable;
4236: my $numinrow = 4;
4237: foreach my $type (@{$types}) {
4238: if (defined($usertypes->{$type})) {
4239: $$rownums ++;
4240: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4241: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4242: '</td><td class="LC_left_item"><table>';
4243: for (my $i=0; $i<@{$fields}; $i++) {
4244: my $rem = $i%($numinrow);
4245: if ($rem == 0) {
4246: if ($i > 0) {
4247: $datatable .= '</tr>';
4248: }
4249: $datatable .= '<tr>';
4250: }
4251: my $check = ' ';
1.39 raeburn 4252: if (ref($settings) eq 'HASH') {
4253: if (ref($settings->{'fields'}) eq 'HASH') {
4254: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4255: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4256: $check = ' checked="checked" ';
4257: }
1.3 raeburn 4258: }
4259: }
4260: }
4261:
4262: if ($i == @{$fields}-1) {
4263: my $colsleft = $numinrow - $rem;
4264: if ($colsleft > 1) {
4265: $datatable .= '<td colspan="'.$colsleft.'">';
4266: } else {
4267: $datatable .= '<td>';
4268: }
4269: } else {
4270: $datatable .= '<td>';
4271: }
1.8 raeburn 4272: $datatable .= '<span class="LC_nobreak"><label>'.
4273: '<input type="checkbox" name="updateable_'.$type.
4274: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4275: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4276: }
4277: $datatable .= '</tr></table></td></tr>';
4278: }
4279: }
4280: return $datatable;
1.1 raeburn 4281: }
4282:
4283: sub modify_login {
1.9 raeburn 4284: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 4285: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 4286: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 4287: adminmail => 'Display administrator E-mail address',
1.43 raeburn 4288: newuser => 'Link for visitors to create a user account',
1.41 raeburn 4289: loginheader => 'Log-in box header');
1.3 raeburn 4290: my @offon = ('off','on');
1.112 raeburn 4291: my %curr_loginvia;
4292: if (ref($domconfig{login}) eq 'HASH') {
4293: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4294: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4295: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4296: }
4297: }
4298: }
1.6 raeburn 4299: my %loginhash;
1.9 raeburn 4300: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4301: \%domconfig,\%loginhash);
1.118 jms 4302: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4303: foreach my $item (@toggles) {
4304: $loginhash{login}{$item} = $env{'form.'.$item};
4305: }
1.41 raeburn 4306: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4307: if (ref($colchanges{'login'}) eq 'HASH') {
4308: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4309: \%loginhash);
4310: }
1.110 raeburn 4311:
1.149 raeburn 4312: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4313: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4314: if (keys(%servers) > 1) {
4315: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4316: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4317: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4318: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4319: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4320: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4321: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4322: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4323: $changes{'loginvia'}{$lonhost} = 1;
4324: } else {
4325: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4326: $changes{'loginvia'}{$lonhost} = 1;
4327: }
4328: } else {
4329: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4330: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4331: $changes{'loginvia'}{$lonhost} = 1;
4332: }
4333: }
4334: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4335: foreach my $item (@loginvia_attribs) {
4336: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4337: }
4338: } else {
4339: foreach my $item (@loginvia_attribs) {
4340: my $new = $env{'form.'.$lonhost.'_'.$item};
4341: if (($item eq 'serverpath') && ($new eq 'custom')) {
4342: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4343: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4344: $new = '/';
4345: }
4346: }
4347: if (($item eq 'custompath') &&
4348: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4349: $new = '';
4350: }
4351: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4352: $changes{'loginvia'}{$lonhost} = 1;
4353: }
4354: if ($item eq 'exempt') {
4355: $new =~ s/^\s+//;
4356: $new =~ s/\s+$//;
4357: my @poss_ips = split(/\s*[,:]\s*/,$new);
4358: my @okips;
4359: foreach my $ip (@poss_ips) {
4360: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4361: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4362: push(@okips,$ip);
4363: }
4364: }
4365: }
4366: if (@okips > 0) {
4367: $new = join(',',@okips);
4368: } else {
4369: $new = '';
4370: }
4371: }
4372:
4373: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4374: }
4375: }
1.112 raeburn 4376: } else {
1.128 raeburn 4377: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4378: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4379: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4380: foreach my $item (@loginvia_attribs) {
4381: my $new = $env{'form.'.$lonhost.'_'.$item};
4382: if (($item eq 'serverpath') && ($new eq 'custom')) {
4383: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4384: $new = '/';
4385: }
4386: }
4387: if (($item eq 'custompath') &&
4388: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4389: $new = '';
4390: }
4391: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4392: }
1.110 raeburn 4393: }
4394: }
4395: }
4396: }
1.119 raeburn 4397:
1.1 raeburn 4398: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4399: $dom);
4400: if ($putresult eq 'ok') {
1.118 jms 4401: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4402: my %defaultchecked = (
4403: 'coursecatalog' => 'on',
4404: 'adminmail' => 'off',
1.43 raeburn 4405: 'newuser' => 'off',
1.42 raeburn 4406: );
1.55 raeburn 4407: if (ref($domconfig{'login'}) eq 'HASH') {
4408: foreach my $item (@toggles) {
4409: if ($defaultchecked{$item} eq 'on') {
4410: if (($domconfig{'login'}{$item} eq '0') &&
4411: ($env{'form.'.$item} eq '1')) {
4412: $changes{$item} = 1;
4413: } elsif (($domconfig{'login'}{$item} eq '' ||
4414: $domconfig{'login'}{$item} eq '1') &&
4415: ($env{'form.'.$item} eq '0')) {
4416: $changes{$item} = 1;
4417: }
4418: } elsif ($defaultchecked{$item} eq 'off') {
4419: if (($domconfig{'login'}{$item} eq '1') &&
4420: ($env{'form.'.$item} eq '0')) {
4421: $changes{$item} = 1;
4422: } elsif (($domconfig{'login'}{$item} eq '' ||
4423: $domconfig{'login'}{$item} eq '0') &&
4424: ($env{'form.'.$item} eq '1')) {
4425: $changes{$item} = 1;
4426: }
1.42 raeburn 4427: }
4428: }
1.41 raeburn 4429: }
1.6 raeburn 4430: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4431: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4432: $resulttext = &mt('Changes made:').'<ul>';
4433: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4434: if ($item eq 'loginvia') {
1.112 raeburn 4435: if (ref($changes{$item}) eq 'HASH') {
4436: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4437: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4438: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4439: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4440: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4441: $protocol = 'http' if ($protocol ne 'https');
4442: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4443:
4444: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4445: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4446: } else {
4447: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4448: }
4449: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4450: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4451: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4452: }
4453: $resulttext .= '</li>';
4454: } else {
4455: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4456: }
1.112 raeburn 4457: } else {
1.128 raeburn 4458: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4459: }
4460: }
1.128 raeburn 4461: $resulttext .= '</ul></li>';
1.112 raeburn 4462: }
1.41 raeburn 4463: } else {
4464: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4465: }
1.1 raeburn 4466: }
1.6 raeburn 4467: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4468: } else {
4469: $resulttext = &mt('No changes made to log-in page settings');
4470: }
4471: } else {
1.11 albertel 4472: $resulttext = '<span class="LC_error">'.
4473: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4474: }
1.6 raeburn 4475: if ($errors) {
1.9 raeburn 4476: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4477: $errors.'</ul>';
4478: }
4479: return $resulttext;
4480: }
4481:
4482: sub color_font_choices {
4483: my %choices =
4484: &Apache::lonlocal::texthash (
4485: img => "Header",
4486: bgs => "Background colors",
4487: links => "Link colors",
1.55 raeburn 4488: images => "Images",
1.6 raeburn 4489: font => "Font color",
1.97 tempelho 4490: fontmenu => "Font Menu",
1.76 raeburn 4491: pgbg => "Page",
1.6 raeburn 4492: tabbg => "Header",
4493: sidebg => "Border",
4494: link => "Link",
4495: alink => "Active link",
4496: vlink => "Visited link",
4497: );
4498: return %choices;
4499: }
4500:
4501: sub modify_rolecolors {
1.9 raeburn 4502: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4503: my ($resulttext,%rolehash);
4504: $rolehash{'rolecolors'} = {};
1.55 raeburn 4505: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4506: if ($domconfig{'rolecolors'} eq '') {
4507: $domconfig{'rolecolors'} = {};
4508: }
4509: }
1.9 raeburn 4510: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4511: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4512: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4513: $dom);
4514: if ($putresult eq 'ok') {
4515: if (keys(%changes) > 0) {
1.41 raeburn 4516: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4517: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4518: $rolehash{'rolecolors'});
4519: } else {
4520: $resulttext = &mt('No changes made to default color schemes');
4521: }
4522: } else {
1.11 albertel 4523: $resulttext = '<span class="LC_error">'.
4524: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4525: }
4526: if ($errors) {
4527: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4528: $errors.'</ul>';
4529: }
4530: return $resulttext;
4531: }
4532:
4533: sub modify_colors {
1.9 raeburn 4534: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4535: my (%changes,%choices);
1.51 raeburn 4536: my @bgs;
1.6 raeburn 4537: my @links = ('link','alink','vlink');
1.41 raeburn 4538: my @logintext;
1.6 raeburn 4539: my @images;
4540: my $servadm = $r->dir_config('lonAdmEMail');
4541: my $errors;
4542: foreach my $role (@{$roles}) {
4543: if ($role eq 'login') {
1.12 raeburn 4544: %choices = &login_choices();
1.41 raeburn 4545: @logintext = ('textcol','bgcol');
1.12 raeburn 4546: } else {
4547: %choices = &color_font_choices();
1.107 raeburn 4548: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4549: }
4550: if ($role eq 'login') {
1.41 raeburn 4551: @images = ('img','logo','domlogo','login');
1.51 raeburn 4552: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4553: } else {
4554: @images = ('img');
1.51 raeburn 4555: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4556: }
4557: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4558: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4559: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4560: }
1.46 raeburn 4561: my ($configuserok,$author_ok,$switchserver) =
4562: &config_check($dom,$confname,$servadm);
1.9 raeburn 4563: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4564: if (ref($domconfig->{$role}) ne 'HASH') {
4565: $domconfig->{$role} = {};
4566: }
1.8 raeburn 4567: foreach my $img (@images) {
1.70 raeburn 4568: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4569: if (defined($env{'form.login_showlogo_'.$img})) {
4570: $confhash->{$role}{'showlogo'}{$img} = 1;
4571: } else {
4572: $confhash->{$role}{'showlogo'}{$img} = 0;
4573: }
4574: }
1.18 albertel 4575: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4576: && !defined($domconfig->{$role}{$img})
4577: && !$env{'form.'.$role.'_del_'.$img}
4578: && $env{'form.'.$role.'_import_'.$img}) {
4579: # import the old configured image from the .tab setting
4580: # if they haven't provided a new one
4581: $domconfig->{$role}{$img} =
4582: $env{'form.'.$role.'_import_'.$img};
4583: }
1.6 raeburn 4584: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4585: my $error;
1.6 raeburn 4586: if ($configuserok eq 'ok') {
1.9 raeburn 4587: if ($switchserver) {
1.12 raeburn 4588: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4589: } else {
4590: if ($author_ok eq 'ok') {
4591: my ($result,$logourl) =
4592: &publishlogo($r,'upload',$role.'_'.$img,
4593: $dom,$confname,$img,$width,$height);
4594: if ($result eq 'ok') {
4595: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4596: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4597: } else {
1.12 raeburn 4598: $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 4599: }
4600: } else {
1.46 raeburn 4601: $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 4602: }
4603: }
4604: } else {
1.46 raeburn 4605: $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 4606: }
4607: if ($error) {
1.8 raeburn 4608: &Apache::lonnet::logthis($error);
1.11 albertel 4609: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4610: }
4611: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4612: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4613: my $error;
4614: if ($configuserok eq 'ok') {
4615: # is confname an author?
4616: if ($switchserver eq '') {
4617: if ($author_ok eq 'ok') {
4618: my ($result,$logourl) =
4619: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4620: $dom,$confname,$img,$width,$height);
4621: if ($result eq 'ok') {
4622: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4623: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4624: }
4625: }
4626: }
4627: }
1.6 raeburn 4628: }
4629: }
4630: }
4631: if (ref($domconfig) eq 'HASH') {
4632: if (ref($domconfig->{$role}) eq 'HASH') {
4633: foreach my $img (@images) {
4634: if ($domconfig->{$role}{$img} ne '') {
4635: if ($env{'form.'.$role.'_del_'.$img}) {
4636: $confhash->{$role}{$img} = '';
1.12 raeburn 4637: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4638: } else {
1.9 raeburn 4639: if ($confhash->{$role}{$img} eq '') {
4640: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4641: }
1.6 raeburn 4642: }
4643: } else {
4644: if ($env{'form.'.$role.'_del_'.$img}) {
4645: $confhash->{$role}{$img} = '';
1.12 raeburn 4646: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4647: }
4648: }
1.70 raeburn 4649: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4650: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4651: if ($confhash->{$role}{'showlogo'}{$img} ne
4652: $domconfig->{$role}{'showlogo'}{$img}) {
4653: $changes{$role}{'showlogo'}{$img} = 1;
4654: }
4655: } else {
4656: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4657: $changes{$role}{'showlogo'}{$img} = 1;
4658: }
4659: }
4660: }
4661: }
1.6 raeburn 4662: if ($domconfig->{$role}{'font'} ne '') {
4663: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4664: $changes{$role}{'font'} = 1;
4665: }
4666: } else {
4667: if ($confhash->{$role}{'font'}) {
4668: $changes{$role}{'font'} = 1;
4669: }
4670: }
1.107 raeburn 4671: if ($role ne 'login') {
4672: if ($domconfig->{$role}{'fontmenu'} ne '') {
4673: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4674: $changes{$role}{'fontmenu'} = 1;
4675: }
4676: } else {
4677: if ($confhash->{$role}{'fontmenu'}) {
4678: $changes{$role}{'fontmenu'} = 1;
4679: }
1.97 tempelho 4680: }
4681: }
1.6 raeburn 4682: foreach my $item (@bgs) {
4683: if ($domconfig->{$role}{$item} ne '') {
4684: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4685: $changes{$role}{'bgs'}{$item} = 1;
4686: }
4687: } else {
4688: if ($confhash->{$role}{$item}) {
4689: $changes{$role}{'bgs'}{$item} = 1;
4690: }
4691: }
4692: }
4693: foreach my $item (@links) {
4694: if ($domconfig->{$role}{$item} ne '') {
4695: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4696: $changes{$role}{'links'}{$item} = 1;
4697: }
4698: } else {
4699: if ($confhash->{$role}{$item}) {
4700: $changes{$role}{'links'}{$item} = 1;
4701: }
4702: }
4703: }
1.41 raeburn 4704: foreach my $item (@logintext) {
4705: if ($domconfig->{$role}{$item} ne '') {
4706: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4707: $changes{$role}{'logintext'}{$item} = 1;
4708: }
4709: } else {
4710: if ($confhash->{$role}{$item}) {
4711: $changes{$role}{'logintext'}{$item} = 1;
4712: }
4713: }
4714: }
1.6 raeburn 4715: } else {
4716: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4717: \@logintext,$confhash,\%changes);
1.6 raeburn 4718: }
4719: } else {
4720: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4721: \@logintext,$confhash,\%changes);
1.6 raeburn 4722: }
4723: }
4724: return ($errors,%changes);
4725: }
4726:
1.46 raeburn 4727: sub config_check {
4728: my ($dom,$confname,$servadm) = @_;
4729: my ($configuserok,$author_ok,$switchserver,%currroles);
4730: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4731: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4732: $confname,$servadm);
4733: if ($configuserok eq 'ok') {
4734: $switchserver = &check_switchserver($dom,$confname);
4735: if ($switchserver eq '') {
4736: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4737: }
4738: }
4739: return ($configuserok,$author_ok,$switchserver);
4740: }
4741:
1.6 raeburn 4742: sub default_change_checker {
1.41 raeburn 4743: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4744: foreach my $item (@{$links}) {
4745: if ($confhash->{$role}{$item}) {
4746: $changes->{$role}{'links'}{$item} = 1;
4747: }
4748: }
4749: foreach my $item (@{$bgs}) {
4750: if ($confhash->{$role}{$item}) {
4751: $changes->{$role}{'bgs'}{$item} = 1;
4752: }
4753: }
1.41 raeburn 4754: foreach my $item (@{$logintext}) {
4755: if ($confhash->{$role}{$item}) {
4756: $changes->{$role}{'logintext'}{$item} = 1;
4757: }
4758: }
1.6 raeburn 4759: foreach my $img (@{$images}) {
4760: if ($env{'form.'.$role.'_del_'.$img}) {
4761: $confhash->{$role}{$img} = '';
1.12 raeburn 4762: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4763: }
1.70 raeburn 4764: if ($role eq 'login') {
4765: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4766: $changes->{$role}{'showlogo'}{$img} = 1;
4767: }
4768: }
1.6 raeburn 4769: }
4770: if ($confhash->{$role}{'font'}) {
4771: $changes->{$role}{'font'} = 1;
4772: }
1.48 raeburn 4773: }
1.6 raeburn 4774:
4775: sub display_colorchgs {
4776: my ($dom,$changes,$roles,$confhash) = @_;
4777: my (%choices,$resulttext);
4778: if (!grep(/^login$/,@{$roles})) {
4779: $resulttext = &mt('Changes made:').'<br />';
4780: }
4781: foreach my $role (@{$roles}) {
4782: if ($role eq 'login') {
4783: %choices = &login_choices();
4784: } else {
4785: %choices = &color_font_choices();
4786: }
4787: if (ref($changes->{$role}) eq 'HASH') {
4788: if ($role ne 'login') {
4789: $resulttext .= '<h4>'.&mt($role).'</h4>';
4790: }
4791: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4792: if ($role ne 'login') {
4793: $resulttext .= '<ul>';
4794: }
4795: if (ref($changes->{$role}{$key}) eq 'HASH') {
4796: if ($role ne 'login') {
4797: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4798: }
4799: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4800: if (($role eq 'login') && ($key eq 'showlogo')) {
4801: if ($confhash->{$role}{$key}{$item}) {
4802: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4803: } else {
4804: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4805: }
4806: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4807: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4808: } else {
1.12 raeburn 4809: my $newitem = $confhash->{$role}{$item};
4810: if ($key eq 'images') {
4811: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4812: }
4813: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4814: }
4815: }
4816: if ($role ne 'login') {
4817: $resulttext .= '</ul></li>';
4818: }
4819: } else {
4820: if ($confhash->{$role}{$key} eq '') {
4821: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4822: } else {
4823: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4824: }
4825: }
4826: if ($role ne 'login') {
4827: $resulttext .= '</ul>';
4828: }
4829: }
4830: }
4831: }
1.3 raeburn 4832: return $resulttext;
1.1 raeburn 4833: }
4834:
1.9 raeburn 4835: sub thumb_dimensions {
4836: return ('200','50');
4837: }
4838:
1.16 raeburn 4839: sub check_dimensions {
4840: my ($inputfile) = @_;
4841: my ($fullwidth,$fullheight);
4842: if ($inputfile =~ m|^[/\w.\-]+$|) {
4843: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4844: my $imageinfo = <PIPE>;
4845: if (!close(PIPE)) {
4846: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4847: }
4848: chomp($imageinfo);
4849: my ($fullsize) =
1.21 raeburn 4850: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4851: if ($fullsize) {
4852: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4853: }
4854: }
4855: }
4856: return ($fullwidth,$fullheight);
4857: }
4858:
1.9 raeburn 4859: sub check_configuser {
4860: my ($uhome,$dom,$confname,$servadm) = @_;
4861: my ($configuserok,%currroles);
4862: if ($uhome eq 'no_host') {
4863: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4864: my $configpass = &LONCAPA::Enrollment::create_password();
4865: $configuserok =
4866: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4867: $configpass,'','','','','',undef,$servadm);
4868: } else {
4869: $configuserok = 'ok';
4870: %currroles =
4871: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4872: }
4873: return ($configuserok,%currroles);
4874: }
4875:
4876: sub check_authorstatus {
4877: my ($dom,$confname,%currroles) = @_;
4878: my $author_ok;
1.40 raeburn 4879: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4880: my $start = time;
4881: my $end = 0;
4882: $author_ok =
4883: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4884: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4885: } else {
4886: $author_ok = 'ok';
4887: }
4888: return $author_ok;
4889: }
4890:
4891: sub publishlogo {
1.46 raeburn 4892: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4893: my ($output,$fname,$logourl);
4894: if ($action eq 'upload') {
4895: $fname=$env{'form.'.$formname.'.filename'};
4896: chop($env{'form.'.$formname});
4897: } else {
4898: ($fname) = ($formname =~ /([^\/]+)$/);
4899: }
1.46 raeburn 4900: if ($savefileas ne '') {
4901: $fname = $savefileas;
4902: }
1.9 raeburn 4903: $fname=&Apache::lonnet::clean_filename($fname);
4904: # See if there is anything left
4905: unless ($fname) { return ('error: no uploaded file'); }
4906: $fname="$subdir/$fname";
1.158 raeburn 4907: my $filepath=$r->dir_config('lonDocRoot')."/priv/$dom/$confname";
1.9 raeburn 4908: my ($fnamepath,$file,$fetchthumb);
4909: $file=$fname;
4910: if ($fname=~m|/|) {
4911: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4912: }
4913: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4914: my $count;
4915: for ($count=4;$count<=$#parts;$count++) {
4916: $filepath.="/$parts[$count]";
4917: if ((-e $filepath)!=1) {
4918: mkdir($filepath,02770);
4919: }
4920: }
4921: # Check for bad extension and disallow upload
4922: if ($file=~/\.(\w+)$/ &&
4923: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4924: $output =
4925: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4926: } elsif ($file=~/\.(\w+)$/ &&
4927: !defined(&Apache::loncommon::fileembstyle($1))) {
4928: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4929: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4930: $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 4931: } elsif (-d "$filepath/$file") {
4932: $output = &mt('File name is a directory name - rename the file and re-upload');
4933: } else {
4934: my $source = $filepath.'/'.$file;
4935: my $logfile;
4936: if (!open($logfile,">>$source".'.log')) {
4937: return (&mt('No write permission to Construction Space'));
4938: }
4939: print $logfile
4940: "\n================= Publish ".localtime()." ================\n".
4941: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4942: # Save the file
4943: if (!open(FH,'>'.$source)) {
4944: &Apache::lonnet::logthis('Failed to create '.$source);
4945: return (&mt('Failed to create file'));
4946: }
4947: if ($action eq 'upload') {
4948: if (!print FH ($env{'form.'.$formname})) {
4949: &Apache::lonnet::logthis('Failed to write to '.$source);
4950: return (&mt('Failed to write file'));
4951: }
4952: } else {
4953: my $original = &Apache::lonnet::filelocation('',$formname);
4954: if(!copy($original,$source)) {
4955: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4956: return (&mt('Failed to write file'));
4957: }
4958: }
4959: close(FH);
4960: chmod(0660, $source); # Permissions to rw-rw---.
4961:
4962: my $docroot=$r->dir_config('lonDocRoot');
4963: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4964: my $copyfile=$targetdir.'/'.$file;
4965:
4966: my @parts=split(/\//,$targetdir);
4967: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4968: for (my $count=5;$count<=$#parts;$count++) {
4969: $path.="/$parts[$count]";
4970: if (!-e $path) {
4971: print $logfile "\nCreating directory ".$path;
4972: mkdir($path,02770);
4973: }
4974: }
4975: my $versionresult;
4976: if (-e $copyfile) {
4977: $versionresult = &logo_versioning($targetdir,$file,$logfile);
4978: } else {
4979: $versionresult = 'ok';
4980: }
4981: if ($versionresult eq 'ok') {
4982: if (copy($source,$copyfile)) {
4983: print $logfile "\nCopied original source to ".$copyfile."\n";
4984: $output = 'ok';
4985: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 4986: push(@{$modified_urls},[$copyfile,$source]);
4987: my $metaoutput =
4988: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
4989: unless ($registered_cleanup) {
4990: my $handlers = $r->get_handlers('PerlCleanupHandler');
4991: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
4992: $registered_cleanup=1;
4993: }
1.9 raeburn 4994: } else {
4995: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
4996: $output = &mt('Failed to copy file to RES space').", $!";
4997: }
4998: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
4999: my $inputfile = $filepath.'/'.$file;
5000: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5001: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5002: if ($fullwidth ne '' && $fullheight ne '') {
5003: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5004: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5005: system("convert -sample $thumbsize $inputfile $outfile");
5006: chmod(0660, $filepath.'/tn-'.$file);
5007: if (-e $outfile) {
5008: my $copyfile=$targetdir.'/tn-'.$file;
5009: if (copy($outfile,$copyfile)) {
5010: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5011: my $thumb_metaoutput =
5012: &write_metadata($dom,$confname,$formname,
5013: $targetdir,'tn-'.$file,$logfile);
5014: push(@{$modified_urls},[$copyfile,$outfile]);
5015: unless ($registered_cleanup) {
5016: my $handlers = $r->get_handlers('PerlCleanupHandler');
5017: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5018: $registered_cleanup=1;
5019: }
1.16 raeburn 5020: } else {
5021: print $logfile "\nUnable to write ".$copyfile.
5022: ':'.$!."\n";
5023: }
5024: }
1.9 raeburn 5025: }
5026: }
5027: }
5028: } else {
5029: $output = $versionresult;
5030: }
5031: }
5032: return ($output,$logourl);
5033: }
5034:
5035: sub logo_versioning {
5036: my ($targetdir,$file,$logfile) = @_;
5037: my $target = $targetdir.'/'.$file;
5038: my ($maxversion,$fn,$extn,$output);
5039: $maxversion = 0;
5040: if ($file =~ /^(.+)\.(\w+)$/) {
5041: $fn=$1;
5042: $extn=$2;
5043: }
5044: opendir(DIR,$targetdir);
5045: while (my $filename=readdir(DIR)) {
5046: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5047: $maxversion=($1>$maxversion)?$1:$maxversion;
5048: }
5049: }
5050: $maxversion++;
5051: print $logfile "\nCreating old version ".$maxversion."\n";
5052: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5053: if (copy($target,$copyfile)) {
5054: print $logfile "Copied old target to ".$copyfile."\n";
5055: $copyfile=$copyfile.'.meta';
5056: if (copy($target.'.meta',$copyfile)) {
5057: print $logfile "Copied old target metadata to ".$copyfile."\n";
5058: $output = 'ok';
5059: } else {
5060: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5061: $output = &mt('Failed to copy old meta').", $!, ";
5062: }
5063: } else {
5064: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5065: $output = &mt('Failed to copy old target').", $!, ";
5066: }
5067: return $output;
5068: }
5069:
5070: sub write_metadata {
5071: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5072: my (%metadatafields,%metadatakeys,$output);
5073: $metadatafields{'title'}=$formname;
5074: $metadatafields{'creationdate'}=time;
5075: $metadatafields{'lastrevisiondate'}=time;
5076: $metadatafields{'copyright'}='public';
5077: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5078: $env{'user.domain'};
5079: $metadatafields{'authorspace'}=$confname.':'.$dom;
5080: $metadatafields{'domain'}=$dom;
5081: {
5082: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5083: my $mfh;
1.155 raeburn 5084: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5085: foreach (sort keys %metadatafields) {
5086: unless ($_=~/\./) {
5087: my $unikey=$_;
5088: $unikey=~/^([A-Za-z]+)/;
5089: my $tag=$1;
5090: $tag=~tr/A-Z/a-z/;
5091: print $mfh "\n\<$tag";
5092: foreach (split(/\,/,$metadatakeys{$unikey})) {
5093: my $value=$metadatafields{$unikey.'.'.$_};
5094: $value=~s/\"/\'\'/g;
5095: print $mfh ' '.$_.'="'.$value.'"';
5096: }
5097: print $mfh '>'.
5098: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5099: .'</'.$tag.'>';
5100: }
5101: }
5102: $output = 'ok';
5103: print $logfile "\nWrote metadata";
5104: close($mfh);
5105: } else {
5106: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5107: $output = &mt('Could not write metadata');
5108: }
5109: }
1.155 raeburn 5110: return $output;
5111: }
5112:
5113: sub notifysubscribed {
5114: foreach my $targetsource (@{$modified_urls}){
5115: next unless (ref($targetsource) eq 'ARRAY');
5116: my ($target,$source)=@{$targetsource};
5117: if ($source ne '') {
5118: if (open(my $logfh,'>>'.$source.'.log')) {
5119: print $logfh "\nCleanup phase: Notifications\n";
5120: my @subscribed=&subscribed_hosts($target);
5121: foreach my $subhost (@subscribed) {
5122: print $logfh "\nNotifying host ".$subhost.':';
5123: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5124: print $logfh $reply;
5125: }
5126: my @subscribedmeta=&subscribed_hosts("$target.meta");
5127: foreach my $subhost (@subscribedmeta) {
5128: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5129: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5130: $subhost);
5131: print $logfh $reply;
5132: }
5133: print $logfh "\n============ Done ============\n";
1.160 raeburn 5134: close($logfh);
1.155 raeburn 5135: }
5136: }
5137: }
5138: return OK;
5139: }
5140:
5141: sub subscribed_hosts {
5142: my ($target) = @_;
5143: my @subscribed;
5144: if (open(my $fh,"<$target.subscription")) {
5145: while (my $subline=<$fh>) {
5146: if ($subline =~ /^($match_lonid):/) {
5147: my $host = $1;
5148: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5149: unless (grep(/^\Q$host\E$/,@subscribed)) {
5150: push(@subscribed,$host);
5151: }
5152: }
5153: }
5154: }
5155: }
5156: return @subscribed;
1.9 raeburn 5157: }
5158:
5159: sub check_switchserver {
5160: my ($dom,$confname) = @_;
5161: my ($allowed,$switchserver);
5162: my $home = &Apache::lonnet::homeserver($confname,$dom);
5163: if ($home eq 'no_host') {
5164: $home = &Apache::lonnet::domain($dom,'primary');
5165: }
5166: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5167: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5168: if (!$allowed) {
5169: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5170: }
5171: return $switchserver;
5172: }
5173:
1.1 raeburn 5174: sub modify_quotas {
1.86 raeburn 5175: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5176: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5177: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5178: if ($action eq 'quotas') {
5179: $context = 'tools';
5180: } else {
5181: $context = $action;
5182: }
5183: if ($context eq 'requestcourses') {
1.98 raeburn 5184: @usertools = ('official','unofficial','community');
1.106 raeburn 5185: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5186: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5187: %titles = &courserequest_titles();
5188: $toolregexp = join('|',@usertools);
5189: %conditions = &courserequest_conditions();
1.86 raeburn 5190: } else {
5191: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 5192: %titles = &tool_titles();
1.86 raeburn 5193: }
1.72 raeburn 5194: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5195: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5196: foreach my $key (keys(%env)) {
1.101 raeburn 5197: if ($context eq 'requestcourses') {
5198: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5199: my $item = $1;
5200: my $type = $2;
5201: if ($type =~ /^limit_(.+)/) {
5202: $limithash{$item}{$1} = $env{$key};
5203: } else {
5204: $confhash{$item}{$type} = $env{$key};
5205: }
5206: }
5207: } else {
1.86 raeburn 5208: if ($key =~ /^form\.quota_(.+)$/) {
5209: $confhash{'defaultquota'}{$1} = $env{$key};
5210: }
1.101 raeburn 5211: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5212: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5213: }
1.72 raeburn 5214: }
5215: }
1.102 raeburn 5216: if ($context eq 'requestcourses') {
5217: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5218: @approvalnotify = sort(@approvalnotify);
5219: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5220: if (ref($domconfig{$action}) eq 'HASH') {
5221: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5222: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5223: $changes{'notify'}{'approval'} = 1;
5224: }
5225: } else {
1.144 raeburn 5226: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5227: $changes{'notify'}{'approval'} = 1;
5228: }
5229: }
5230: } else {
1.144 raeburn 5231: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5232: $changes{'notify'}{'approval'} = 1;
5233: }
5234: }
5235: } else {
1.86 raeburn 5236: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5237: }
1.72 raeburn 5238: foreach my $item (@usertools) {
5239: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5240: my $unset;
1.101 raeburn 5241: if ($context eq 'requestcourses') {
1.104 raeburn 5242: $unset = '0';
5243: if ($type eq '_LC_adv') {
5244: $unset = '';
5245: }
1.101 raeburn 5246: if ($confhash{$item}{$type} eq 'autolimit') {
5247: $confhash{$item}{$type} .= '=';
5248: unless ($limithash{$item}{$type} =~ /\D/) {
5249: $confhash{$item}{$type} .= $limithash{$item}{$type};
5250: }
5251: }
1.72 raeburn 5252: } else {
1.101 raeburn 5253: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5254: $confhash{$item}{$type} = 1;
5255: } else {
5256: $confhash{$item}{$type} = 0;
5257: }
1.72 raeburn 5258: }
1.86 raeburn 5259: if (ref($domconfig{$action}) eq 'HASH') {
5260: if (ref($domconfig{$action}{$item}) eq 'HASH') {
5261: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5262: $changes{$item}{$type} = 1;
5263: }
5264: } else {
5265: if ($context eq 'requestcourses') {
1.104 raeburn 5266: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5267: $changes{$item}{$type} = 1;
5268: }
5269: } else {
5270: if (!$confhash{$item}{$type}) {
5271: $changes{$item}{$type} = 1;
5272: }
5273: }
5274: }
5275: } else {
5276: if ($context eq 'requestcourses') {
1.104 raeburn 5277: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5278: $changes{$item}{$type} = 1;
5279: }
5280: } else {
5281: if (!$confhash{$item}{$type}) {
5282: $changes{$item}{$type} = 1;
5283: }
5284: }
5285: }
1.1 raeburn 5286: }
5287: }
1.86 raeburn 5288: unless ($context eq 'requestcourses') {
5289: if (ref($domconfig{'quotas'}) eq 'HASH') {
5290: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5291: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5292: if (exists($confhash{'defaultquota'}{$key})) {
5293: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5294: $changes{'defaultquota'}{$key} = 1;
5295: }
5296: } else {
5297: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5298: }
5299: }
1.86 raeburn 5300: } else {
5301: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5302: if (exists($confhash{'defaultquota'}{$key})) {
5303: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5304: $changes{'defaultquota'}{$key} = 1;
5305: }
5306: } else {
5307: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5308: }
1.1 raeburn 5309: }
5310: }
5311: }
1.86 raeburn 5312: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5313: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5314: if (ref($domconfig{'quotas'}) eq 'HASH') {
5315: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5316: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5317: $changes{'defaultquota'}{$key} = 1;
5318: }
5319: } else {
5320: if (!exists($domconfig{'quotas'}{$key})) {
5321: $changes{'defaultquota'}{$key} = 1;
5322: }
1.72 raeburn 5323: }
5324: } else {
1.86 raeburn 5325: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5326: }
1.1 raeburn 5327: }
5328: }
5329: }
1.72 raeburn 5330:
5331: foreach my $key (keys(%confhash)) {
5332: $domdefaults{$key} = $confhash{$key};
5333: }
5334:
1.1 raeburn 5335: my %quotahash = (
1.86 raeburn 5336: $action => { %confhash }
1.1 raeburn 5337: );
5338: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5339: $dom);
5340: if ($putresult eq 'ok') {
5341: if (keys(%changes) > 0) {
1.72 raeburn 5342: my $cachetime = 24*60*60;
5343: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5344:
1.1 raeburn 5345: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 5346: unless ($context eq 'requestcourses') {
5347: if (ref($changes{'defaultquota'}) eq 'HASH') {
5348: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5349: foreach my $type (@{$types},'default') {
5350: if (defined($changes{'defaultquota'}{$type})) {
5351: my $typetitle = $usertypes->{$type};
5352: if ($type eq 'default') {
5353: $typetitle = $othertitle;
5354: }
5355: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5356: }
5357: }
1.86 raeburn 5358: $resulttext .= '</ul></li>';
1.72 raeburn 5359: }
5360: }
1.80 raeburn 5361: my %newenv;
1.72 raeburn 5362: foreach my $item (@usertools) {
5363: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 5364: my $newacc =
5365: &Apache::lonnet::usertools_access($env{'user.name'},
5366: $env{'user.domain'},
1.86 raeburn 5367: $item,'reload',$context);
5368: if ($context eq 'requestcourses') {
1.108 raeburn 5369: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5370: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5371: }
5372: } else {
5373: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5374: $newenv{'environment.availabletools.'.$item} = $newacc;
5375: }
1.80 raeburn 5376: }
1.72 raeburn 5377: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5378: foreach my $type (@{$types},'default','_LC_adv') {
5379: if ($changes{$item}{$type}) {
5380: my $typetitle = $usertypes->{$type};
5381: if ($type eq 'default') {
5382: $typetitle = $othertitle;
5383: } elsif ($type eq '_LC_adv') {
5384: $typetitle = 'LON-CAPA Advanced Users';
5385: }
5386: if ($confhash{$item}{$type}) {
1.101 raeburn 5387: if ($context eq 'requestcourses') {
5388: my $cond;
5389: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
5390: if ($1 eq '') {
5391: $cond = &mt('(Automatic processing of any request).');
5392: } else {
5393: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5394: }
5395: } else {
5396: $cond = $conditions{$confhash{$item}{$type}};
5397: }
5398: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5399: } else {
5400: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5401: }
1.72 raeburn 5402: } else {
1.104 raeburn 5403: if ($type eq '_LC_adv') {
5404: if ($confhash{$item}{$type} eq '0') {
5405: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5406: } else {
5407: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5408: }
5409: } else {
5410: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5411: }
1.72 raeburn 5412: }
5413: }
1.26 raeburn 5414: }
1.72 raeburn 5415: $resulttext .= '</ul></li>';
1.26 raeburn 5416: }
1.1 raeburn 5417: }
1.102 raeburn 5418: if ($action eq 'requestcourses') {
5419: if (ref($changes{'notify'}) eq 'HASH') {
5420: if ($changes{'notify'}{'approval'}) {
5421: if (ref($confhash{'notify'}) eq 'HASH') {
5422: if ($confhash{'notify'}{'approval'}) {
5423: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5424: } else {
5425: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
5426: }
5427: }
5428: }
5429: }
5430: }
1.1 raeburn 5431: $resulttext .= '</ul>';
1.80 raeburn 5432: if (keys(%newenv)) {
5433: &Apache::lonnet::appenv(\%newenv);
5434: }
1.1 raeburn 5435: } else {
1.86 raeburn 5436: if ($context eq 'requestcourses') {
5437: $resulttext = &mt('No changes made to rights to request creation of courses.');
5438: } else {
1.90 weissno 5439: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5440: }
1.1 raeburn 5441: }
5442: } else {
1.11 albertel 5443: $resulttext = '<span class="LC_error">'.
5444: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5445: }
1.3 raeburn 5446: return $resulttext;
1.1 raeburn 5447: }
5448:
1.3 raeburn 5449: sub modify_autoenroll {
5450: my ($dom,%domconfig) = @_;
1.1 raeburn 5451: my ($resulttext,%changes);
5452: my %currautoenroll;
5453: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5454: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5455: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5456: }
5457: }
5458: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5459: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5460: sender => 'Sender for notification messages',
5461: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5462: my @offon = ('off','on');
1.17 raeburn 5463: my $sender_uname = $env{'form.sender_uname'};
5464: my $sender_domain = $env{'form.sender_domain'};
5465: if ($sender_domain eq '') {
5466: $sender_uname = '';
5467: } elsif ($sender_uname eq '') {
5468: $sender_domain = '';
5469: }
1.129 raeburn 5470: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5471: my %autoenrollhash = (
1.129 raeburn 5472: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5473: 'sender_uname' => $sender_uname,
5474: 'sender_domain' => $sender_domain,
5475: 'co-owners' => $coowners,
1.1 raeburn 5476: }
5477: );
1.4 raeburn 5478: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5479: $dom);
1.1 raeburn 5480: if ($putresult eq 'ok') {
5481: if (exists($currautoenroll{'run'})) {
5482: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5483: $changes{'run'} = 1;
5484: }
5485: } elsif ($autorun) {
5486: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 5487: $changes{'run'} = 1;
1.1 raeburn 5488: }
5489: }
1.17 raeburn 5490: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 5491: $changes{'sender'} = 1;
5492: }
1.17 raeburn 5493: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 5494: $changes{'sender'} = 1;
5495: }
1.129 raeburn 5496: if ($currautoenroll{'co-owners'} ne '') {
5497: if ($currautoenroll{'co-owners'} ne $coowners) {
5498: $changes{'coowners'} = 1;
5499: }
5500: } elsif ($coowners) {
5501: $changes{'coowners'} = 1;
5502: }
1.1 raeburn 5503: if (keys(%changes) > 0) {
5504: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5505: if ($changes{'run'}) {
1.1 raeburn 5506: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5507: }
5508: if ($changes{'sender'}) {
1.17 raeburn 5509: if ($sender_uname eq '' || $sender_domain eq '') {
5510: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5511: } else {
5512: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5513: }
1.1 raeburn 5514: }
1.129 raeburn 5515: if ($changes{'coowners'}) {
5516: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5517: &Apache::loncommon::devalidate_domconfig_cache($dom);
5518: }
1.1 raeburn 5519: $resulttext .= '</ul>';
5520: } else {
5521: $resulttext = &mt('No changes made to auto-enrollment settings');
5522: }
5523: } else {
1.11 albertel 5524: $resulttext = '<span class="LC_error">'.
5525: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5526: }
1.3 raeburn 5527: return $resulttext;
1.1 raeburn 5528: }
5529:
5530: sub modify_autoupdate {
1.3 raeburn 5531: my ($dom,%domconfig) = @_;
1.1 raeburn 5532: my ($resulttext,%currautoupdate,%fields,%changes);
5533: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5534: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5535: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5536: }
5537: }
5538: my @offon = ('off','on');
5539: my %title = &Apache::lonlocal::texthash (
5540: run => 'Auto-update:',
5541: classlists => 'Updates to user information in classlists?'
5542: );
1.44 raeburn 5543: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5544: my %fieldtitles = &Apache::lonlocal::texthash (
5545: id => 'Student/Employee ID',
1.20 raeburn 5546: permanentemail => 'E-mail address',
1.1 raeburn 5547: lastname => 'Last Name',
5548: firstname => 'First Name',
5549: middlename => 'Middle Name',
1.132 raeburn 5550: generation => 'Generation',
1.1 raeburn 5551: );
1.142 raeburn 5552: $othertitle = &mt('All users');
1.1 raeburn 5553: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5554: $othertitle = &mt('Other users');
1.1 raeburn 5555: }
5556: foreach my $key (keys(%env)) {
5557: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5558: my ($usertype,$item) = ($1,$2);
5559: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5560: if ($usertype eq 'default') {
5561: push(@{$fields{$1}},$2);
5562: } elsif (ref($types) eq 'ARRAY') {
5563: if (grep(/^\Q$usertype\E$/,@{$types})) {
5564: push(@{$fields{$1}},$2);
5565: }
5566: }
5567: }
1.1 raeburn 5568: }
5569: }
1.131 raeburn 5570: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5571: @lockablenames = sort(@lockablenames);
5572: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5573: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5574: if (@changed) {
5575: $changes{'lockablenames'} = 1;
5576: }
5577: } else {
5578: if (@lockablenames) {
5579: $changes{'lockablenames'} = 1;
5580: }
5581: }
1.1 raeburn 5582: my %updatehash = (
5583: autoupdate => { run => $env{'form.autoupdate_run'},
5584: classlists => $env{'form.classlists'},
5585: fields => {%fields},
1.131 raeburn 5586: lockablenames => \@lockablenames,
1.1 raeburn 5587: }
5588: );
5589: foreach my $key (keys(%currautoupdate)) {
5590: if (($key eq 'run') || ($key eq 'classlists')) {
5591: if (exists($updatehash{autoupdate}{$key})) {
5592: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5593: $changes{$key} = 1;
5594: }
5595: }
5596: } elsif ($key eq 'fields') {
5597: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5598: foreach my $item (@{$types},'default') {
1.1 raeburn 5599: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5600: my $change = 0;
5601: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5602: if (!exists($fields{$item})) {
5603: $change = 1;
1.132 raeburn 5604: last;
1.1 raeburn 5605: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5606: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5607: $change = 1;
1.132 raeburn 5608: last;
1.1 raeburn 5609: }
5610: }
5611: }
5612: if ($change) {
5613: push(@{$changes{$key}},$item);
5614: }
1.26 raeburn 5615: }
1.1 raeburn 5616: }
5617: }
1.131 raeburn 5618: } elsif ($key eq 'lockablenames') {
5619: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5620: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5621: if (@changed) {
5622: $changes{'lockablenames'} = 1;
5623: }
5624: } else {
5625: if (@lockablenames) {
5626: $changes{'lockablenames'} = 1;
5627: }
5628: }
5629: }
5630: }
5631: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5632: if (@lockablenames) {
5633: $changes{'lockablenames'} = 1;
1.1 raeburn 5634: }
5635: }
1.26 raeburn 5636: foreach my $item (@{$types},'default') {
5637: if (defined($fields{$item})) {
5638: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5639: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5640: my $change = 0;
5641: if (ref($fields{$item}) eq 'ARRAY') {
5642: foreach my $type (@{$fields{$item}}) {
5643: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5644: $change = 1;
5645: last;
5646: }
5647: }
5648: }
5649: if ($change) {
5650: push(@{$changes{'fields'}},$item);
5651: }
5652: } else {
1.26 raeburn 5653: push(@{$changes{'fields'}},$item);
5654: }
5655: } else {
5656: push(@{$changes{'fields'}},$item);
1.1 raeburn 5657: }
5658: }
5659: }
5660: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5661: $dom);
5662: if ($putresult eq 'ok') {
5663: if (keys(%changes) > 0) {
5664: $resulttext = &mt('Changes made:').'<ul>';
5665: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5666: if ($key eq 'lockablenames') {
5667: $resulttext .= '<li>';
5668: if (@lockablenames) {
5669: $usertypes->{'default'} = $othertitle;
5670: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5671: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5672: } else {
5673: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5674: }
5675: $resulttext .= '</li>';
5676: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5677: foreach my $item (@{$changes{$key}}) {
5678: my @newvalues;
5679: foreach my $type (@{$fields{$item}}) {
5680: push(@newvalues,$fieldtitles{$type});
5681: }
1.3 raeburn 5682: my $newvaluestr;
5683: if (@newvalues > 0) {
5684: $newvaluestr = join(', ',@newvalues);
5685: } else {
5686: $newvaluestr = &mt('none');
1.6 raeburn 5687: }
1.1 raeburn 5688: if ($item eq 'default') {
1.26 raeburn 5689: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5690: } else {
1.26 raeburn 5691: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5692: }
5693: }
5694: } else {
5695: my $newvalue;
5696: if ($key eq 'run') {
5697: $newvalue = $offon[$env{'form.autoupdate_run'}];
5698: } else {
5699: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5700: }
1.1 raeburn 5701: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5702: }
5703: }
5704: $resulttext .= '</ul>';
5705: } else {
1.3 raeburn 5706: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5707: }
5708: } else {
1.11 albertel 5709: $resulttext = '<span class="LC_error">'.
5710: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5711: }
1.3 raeburn 5712: return $resulttext;
1.1 raeburn 5713: }
5714:
1.125 raeburn 5715: sub modify_autocreate {
5716: my ($dom,%domconfig) = @_;
5717: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5718: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5719: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5720: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5721: }
5722: }
5723: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5724: req => 'Auto-creation of validated requests for official courses',
5725: xmldc => 'Identity of course creator of courses from XML files',
5726: );
5727: my @types = ('xml','req');
5728: foreach my $item (@types) {
5729: $newvals{$item} = $env{'form.autocreate_'.$item};
5730: $newvals{$item} =~ s/\D//g;
5731: $newvals{$item} = 0 if ($newvals{$item} eq '');
5732: }
5733: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5734: my %domcoords = &get_active_dcs($dom);
5735: unless (exists($domcoords{$newvals{'xmldc'}})) {
5736: $newvals{'xmldc'} = '';
5737: }
5738: %autocreatehash = (
5739: autocreate => { xml => $newvals{'xml'},
5740: req => $newvals{'req'},
5741: }
5742: );
5743: if ($newvals{'xmldc'} ne '') {
5744: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5745: }
5746: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5747: $dom);
5748: if ($putresult eq 'ok') {
5749: my @items = @types;
5750: if ($newvals{'xml'}) {
5751: push(@items,'xmldc');
5752: }
5753: foreach my $item (@items) {
5754: if (exists($currautocreate{$item})) {
5755: if ($currautocreate{$item} ne $newvals{$item}) {
5756: $changes{$item} = 1;
5757: }
5758: } elsif ($newvals{$item}) {
5759: $changes{$item} = 1;
5760: }
5761: }
5762: if (keys(%changes) > 0) {
5763: my @offon = ('off','on');
5764: $resulttext = &mt('Changes made:').'<ul>';
5765: foreach my $item (@types) {
5766: if ($changes{$item}) {
5767: my $newtxt = $offon[$newvals{$item}];
5768: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5769: }
5770: }
5771: if ($changes{'xmldc'}) {
5772: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5773: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5774: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5775: }
5776: $resulttext .= '</ul>';
5777: } else {
5778: $resulttext = &mt('No changes made to auto-creation settings');
5779: }
5780: } else {
5781: $resulttext = '<span class="LC_error">'.
5782: &mt('An error occurred: [_1]',$putresult).'</span>';
5783: }
5784: return $resulttext;
5785: }
5786:
1.23 raeburn 5787: sub modify_directorysrch {
5788: my ($dom,%domconfig) = @_;
5789: my ($resulttext,%changes);
5790: my %currdirsrch;
5791: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5792: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5793: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5794: }
5795: }
5796: my %title = ( available => 'Directory search available',
1.24 raeburn 5797: localonly => 'Other domains can search',
1.23 raeburn 5798: searchby => 'Search types',
5799: searchtypes => 'Search latitude');
5800: my @offon = ('off','on');
1.24 raeburn 5801: my @otherdoms = ('Yes','No');
1.23 raeburn 5802:
1.25 raeburn 5803: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5804: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5805: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5806:
1.44 raeburn 5807: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5808: if (keys(%{$usertypes}) == 0) {
5809: @cansearch = ('default');
5810: } else {
5811: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5812: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5813: if (!grep(/^\Q$type\E$/,@cansearch)) {
5814: push(@{$changes{'cansearch'}},$type);
5815: }
1.23 raeburn 5816: }
1.26 raeburn 5817: foreach my $type (@cansearch) {
5818: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5819: push(@{$changes{'cansearch'}},$type);
5820: }
1.23 raeburn 5821: }
1.26 raeburn 5822: } else {
5823: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5824: }
5825: }
5826:
5827: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5828: foreach my $by (@{$currdirsrch{'searchby'}}) {
5829: if (!grep(/^\Q$by\E$/,@searchby)) {
5830: push(@{$changes{'searchby'}},$by);
5831: }
5832: }
5833: foreach my $by (@searchby) {
5834: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5835: push(@{$changes{'searchby'}},$by);
5836: }
5837: }
5838: } else {
5839: push(@{$changes{'searchby'}},@searchby);
5840: }
1.25 raeburn 5841:
5842: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5843: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5844: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5845: push(@{$changes{'searchtypes'}},$type);
5846: }
5847: }
5848: foreach my $type (@searchtypes) {
5849: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5850: push(@{$changes{'searchtypes'}},$type);
5851: }
5852: }
5853: } else {
5854: if (exists($currdirsrch{'searchtypes'})) {
5855: foreach my $type (@searchtypes) {
5856: if ($type ne $currdirsrch{'searchtypes'}) {
5857: push(@{$changes{'searchtypes'}},$type);
5858: }
5859: }
5860: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5861: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5862: }
5863: } else {
5864: push(@{$changes{'searchtypes'}},@searchtypes);
5865: }
5866: }
5867:
1.23 raeburn 5868: my %dirsrch_hash = (
5869: directorysrch => { available => $env{'form.dirsrch_available'},
5870: cansearch => \@cansearch,
1.24 raeburn 5871: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5872: searchby => \@searchby,
1.25 raeburn 5873: searchtypes => \@searchtypes,
1.23 raeburn 5874: }
5875: );
5876: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5877: $dom);
5878: if ($putresult eq 'ok') {
5879: if (exists($currdirsrch{'available'})) {
5880: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5881: $changes{'available'} = 1;
5882: }
5883: } else {
5884: if ($env{'form.dirsrch_available'} eq '1') {
5885: $changes{'available'} = 1;
5886: }
5887: }
1.24 raeburn 5888: if (exists($currdirsrch{'localonly'})) {
5889: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5890: $changes{'localonly'} = 1;
5891: }
5892: } else {
5893: if ($env{'form.dirsrch_localonly'} eq '1') {
5894: $changes{'localonly'} = 1;
5895: }
5896: }
1.23 raeburn 5897: if (keys(%changes) > 0) {
5898: $resulttext = &mt('Changes made:').'<ul>';
5899: if ($changes{'available'}) {
5900: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5901: }
1.24 raeburn 5902: if ($changes{'localonly'}) {
5903: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5904: }
5905:
1.23 raeburn 5906: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5907: my $chgtext;
1.26 raeburn 5908: if (ref($usertypes) eq 'HASH') {
5909: if (keys(%{$usertypes}) > 0) {
5910: foreach my $type (@{$types}) {
5911: if (grep(/^\Q$type\E$/,@cansearch)) {
5912: $chgtext .= $usertypes->{$type}.'; ';
5913: }
5914: }
5915: if (grep(/^default$/,@cansearch)) {
5916: $chgtext .= $othertitle;
5917: } else {
5918: $chgtext =~ s/\; $//;
5919: }
5920: $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 5921: }
5922: }
5923: }
5924: if (ref($changes{'searchby'}) eq 'ARRAY') {
5925: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5926: my $chgtext;
5927: foreach my $type (@{$titleorder}) {
5928: if (grep(/^\Q$type\E$/,@searchby)) {
5929: if (defined($searchtitles->{$type})) {
5930: $chgtext .= $searchtitles->{$type}.'; ';
5931: }
5932: }
5933: }
5934: $chgtext =~ s/\; $//;
5935: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5936: }
1.25 raeburn 5937: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5938: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5939: my $chgtext;
5940: foreach my $type (@{$srchtypeorder}) {
5941: if (grep(/^\Q$type\E$/,@searchtypes)) {
5942: if (defined($srchtypes_desc->{$type})) {
5943: $chgtext .= $srchtypes_desc->{$type}.'; ';
5944: }
5945: }
5946: }
5947: $chgtext =~ s/\; $//;
5948: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5949: }
5950: $resulttext .= '</ul>';
5951: } else {
5952: $resulttext = &mt('No changes made to institution directory search settings');
5953: }
5954: } else {
5955: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5956: &mt('An error occurred: [_1]',$putresult).'</span>';
5957: }
5958: return $resulttext;
5959: }
5960:
1.28 raeburn 5961: sub modify_contacts {
5962: my ($dom,%domconfig) = @_;
5963: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5964: if (ref($domconfig{'contacts'}) eq 'HASH') {
5965: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5966: $currsetting{$key} = $domconfig{'contacts'}{$key};
5967: }
5968: }
1.134 raeburn 5969: my (%others,%to,%bcc);
1.28 raeburn 5970: my @contacts = ('supportemail','adminemail');
1.102 raeburn 5971: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5972: 'requestsmail');
1.28 raeburn 5973: foreach my $type (@mailings) {
5974: @{$newsetting{$type}} =
5975: &Apache::loncommon::get_env_multiple('form.'.$type);
5976: foreach my $item (@contacts) {
5977: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5978: $contacts_hash{contacts}{$type}{$item} = 1;
5979: } else {
5980: $contacts_hash{contacts}{$type}{$item} = 0;
5981: }
5982: }
5983: $others{$type} = $env{'form.'.$type.'_others'};
5984: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 5985: if ($type eq 'helpdeskmail') {
5986: $bcc{$type} = $env{'form.'.$type.'_bcc'};
5987: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
5988: }
1.28 raeburn 5989: }
5990: foreach my $item (@contacts) {
5991: $to{$item} = $env{'form.'.$item};
5992: $contacts_hash{'contacts'}{$item} = $to{$item};
5993: }
5994: if (keys(%currsetting) > 0) {
5995: foreach my $item (@contacts) {
5996: if ($to{$item} ne $currsetting{$item}) {
5997: $changes{$item} = 1;
5998: }
5999: }
6000: foreach my $type (@mailings) {
6001: foreach my $item (@contacts) {
6002: if (ref($currsetting{$type}) eq 'HASH') {
6003: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6004: push(@{$changes{$type}},$item);
6005: }
6006: } else {
6007: push(@{$changes{$type}},@{$newsetting{$type}});
6008: }
6009: }
6010: if ($others{$type} ne $currsetting{$type}{'others'}) {
6011: push(@{$changes{$type}},'others');
6012: }
1.134 raeburn 6013: if ($type eq 'helpdeskmail') {
6014: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6015: push(@{$changes{$type}},'bcc');
6016: }
6017: }
1.28 raeburn 6018: }
6019: } else {
6020: my %default;
6021: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6022: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6023: $default{'errormail'} = 'adminemail';
6024: $default{'packagesmail'} = 'adminemail';
6025: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6026: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6027: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6028: foreach my $item (@contacts) {
6029: if ($to{$item} ne $default{$item}) {
6030: $changes{$item} = 1;
6031: }
6032: }
6033: foreach my $type (@mailings) {
6034: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6035:
6036: push(@{$changes{$type}},@{$newsetting{$type}});
6037: }
6038: if ($others{$type} ne '') {
6039: push(@{$changes{$type}},'others');
1.134 raeburn 6040: }
6041: if ($type eq 'helpdeskmail') {
6042: if ($bcc{$type} ne '') {
6043: push(@{$changes{$type}},'bcc');
6044: }
6045: }
1.28 raeburn 6046: }
6047: }
6048: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6049: $dom);
6050: if ($putresult eq 'ok') {
6051: if (keys(%changes) > 0) {
6052: my ($titles,$short_titles) = &contact_titles();
6053: $resulttext = &mt('Changes made:').'<ul>';
6054: foreach my $item (@contacts) {
6055: if ($changes{$item}) {
6056: $resulttext .= '<li>'.$titles->{$item}.
6057: &mt(' set to: ').
6058: '<span class="LC_cusr_emph">'.
6059: $to{$item}.'</span></li>';
6060: }
6061: }
6062: foreach my $type (@mailings) {
6063: if (ref($changes{$type}) eq 'ARRAY') {
6064: $resulttext .= '<li>'.$titles->{$type}.': ';
6065: my @text;
6066: foreach my $item (@{$newsetting{$type}}) {
6067: push(@text,$short_titles->{$item});
6068: }
6069: if ($others{$type} ne '') {
6070: push(@text,$others{$type});
6071: }
6072: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6073: join(', ',@text).'</span>';
6074: if ($type eq 'helpdeskmail') {
6075: if ($bcc{$type} ne '') {
6076: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6077: }
6078: }
6079: $resulttext .= '</li>';
1.28 raeburn 6080: }
6081: }
6082: $resulttext .= '</ul>';
6083: } else {
1.34 raeburn 6084: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6085: }
6086: } else {
6087: $resulttext = '<span class="LC_error">'.
6088: &mt('An error occurred: [_1].',$putresult).'</span>';
6089: }
6090: return $resulttext;
6091: }
6092:
6093: sub modify_usercreation {
1.27 raeburn 6094: my ($dom,%domconfig) = @_;
1.34 raeburn 6095: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6096: my $warningmsg;
1.27 raeburn 6097: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6098: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6099: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6100: }
6101: }
6102: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6103: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6104: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6105: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6106: foreach my $item(@contexts) {
1.45 raeburn 6107: if ($item eq 'selfcreate') {
1.50 raeburn 6108: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6109: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6110: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6111: if (ref($cancreate{$item}) eq 'ARRAY') {
6112: if (grep(/^login$/,@{$cancreate{$item}})) {
6113: $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.');
6114: }
1.43 raeburn 6115: }
6116: }
1.50 raeburn 6117: } else {
6118: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6119: }
1.34 raeburn 6120: }
1.93 raeburn 6121: my ($othertitle,$usertypes,$types) =
6122: &Apache::loncommon::sorted_inst_types($dom);
6123: if (ref($types) eq 'ARRAY') {
6124: if (@{$types} > 0) {
6125: @{$cancreate{'statustocreate'}} =
6126: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6127: } else {
6128: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6129: }
6130: push(@contexts,'statustocreate');
6131: }
1.34 raeburn 6132: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6133: foreach my $item (@contexts) {
1.93 raeburn 6134: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6135: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6136: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6137: if (ref($cancreate{$item}) eq 'ARRAY') {
6138: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6139: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6140: push(@{$changes{'cancreate'}},$item);
6141: }
1.50 raeburn 6142: }
6143: }
6144: }
6145: } else {
6146: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6147: if (@{$cancreate{$item}} > 0) {
6148: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6149: push(@{$changes{'cancreate'}},$item);
6150: }
6151: }
6152: } else {
6153: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6154: if (@{$cancreate{$item}} < 3) {
6155: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6156: push(@{$changes{'cancreate'}},$item);
6157: }
6158: }
6159: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6160: if (@{$cancreate{$item}} > 0) {
6161: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6162: push(@{$changes{'cancreate'}},$item);
6163: }
6164: }
6165: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6166: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6167: push(@{$changes{'cancreate'}},$item);
6168: }
6169: }
6170: }
6171: }
6172: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6173: foreach my $type (@{$cancreate{$item}}) {
6174: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6175: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6176: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6177: push(@{$changes{'cancreate'}},$item);
6178: }
6179: }
6180: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6181: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6182: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6183: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6184: push(@{$changes{'cancreate'}},$item);
6185: }
6186: }
6187: }
6188: }
6189: }
6190: } else {
6191: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6192: push(@{$changes{'cancreate'}},$item);
6193: }
6194: }
1.27 raeburn 6195: }
1.34 raeburn 6196: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6197: foreach my $item (@contexts) {
1.43 raeburn 6198: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6199: if ($cancreate{$item} ne 'any') {
6200: push(@{$changes{'cancreate'}},$item);
6201: }
6202: } else {
6203: if ($cancreate{$item} ne 'none') {
6204: push(@{$changes{'cancreate'}},$item);
6205: }
1.27 raeburn 6206: }
6207: }
6208: } else {
1.43 raeburn 6209: foreach my $item (@contexts) {
1.34 raeburn 6210: push(@{$changes{'cancreate'}},$item);
6211: }
1.27 raeburn 6212: }
1.34 raeburn 6213:
1.27 raeburn 6214: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6215: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6216: if (!grep(/^\Q$type\E$/,@username_rule)) {
6217: push(@{$changes{'username_rule'}},$type);
6218: }
6219: }
6220: foreach my $type (@username_rule) {
6221: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6222: push(@{$changes{'username_rule'}},$type);
6223: }
6224: }
6225: } else {
6226: push(@{$changes{'username_rule'}},@username_rule);
6227: }
6228:
1.32 raeburn 6229: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6230: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6231: if (!grep(/^\Q$type\E$/,@id_rule)) {
6232: push(@{$changes{'id_rule'}},$type);
6233: }
6234: }
6235: foreach my $type (@id_rule) {
6236: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6237: push(@{$changes{'id_rule'}},$type);
6238: }
6239: }
6240: } else {
6241: push(@{$changes{'id_rule'}},@id_rule);
6242: }
6243:
1.43 raeburn 6244: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6245: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6246: if (!grep(/^\Q$type\E$/,@email_rule)) {
6247: push(@{$changes{'email_rule'}},$type);
6248: }
6249: }
6250: foreach my $type (@email_rule) {
6251: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6252: push(@{$changes{'email_rule'}},$type);
6253: }
6254: }
6255: } else {
6256: push(@{$changes{'email_rule'}},@email_rule);
6257: }
6258:
6259: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6260: my @authtypes = ('int','krb4','krb5','loc');
6261: my %authhash;
1.43 raeburn 6262: foreach my $item (@authen_contexts) {
1.28 raeburn 6263: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6264: foreach my $auth (@authtypes) {
6265: if (grep(/^\Q$auth\E$/,@authallowed)) {
6266: $authhash{$item}{$auth} = 1;
6267: } else {
6268: $authhash{$item}{$auth} = 0;
6269: }
6270: }
6271: }
6272: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6273: foreach my $item (@authen_contexts) {
1.28 raeburn 6274: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6275: foreach my $auth (@authtypes) {
6276: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6277: push(@{$changes{'authtypes'}},$item);
6278: last;
6279: }
6280: }
6281: }
6282: }
6283: } else {
1.43 raeburn 6284: foreach my $item (@authen_contexts) {
1.28 raeburn 6285: push(@{$changes{'authtypes'}},$item);
6286: }
6287: }
6288:
1.27 raeburn 6289: my %usercreation_hash = (
1.28 raeburn 6290: usercreation => {
1.34 raeburn 6291: cancreate => \%cancreate,
1.27 raeburn 6292: username_rule => \@username_rule,
1.32 raeburn 6293: id_rule => \@id_rule,
1.43 raeburn 6294: email_rule => \@email_rule,
1.32 raeburn 6295: authtypes => \%authhash,
1.27 raeburn 6296: }
6297: );
6298:
6299: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6300: $dom);
1.50 raeburn 6301:
6302: my %selfcreatetypes = (
6303: sso => 'users authenticated by institutional single sign on',
6304: login => 'users authenticated by institutional log-in',
6305: email => 'users who provide a valid e-mail address for use as the username',
6306: );
1.27 raeburn 6307: if ($putresult eq 'ok') {
6308: if (keys(%changes) > 0) {
6309: $resulttext = &mt('Changes made:').'<ul>';
6310: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6311: my %lt = &usercreation_types();
6312: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6313: my $chgtext;
6314: unless ($type eq 'statustocreate') {
6315: $chgtext = $lt{$type}.', ';
6316: }
1.45 raeburn 6317: if ($type eq 'selfcreate') {
1.50 raeburn 6318: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6319: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6320: } else {
1.100 raeburn 6321: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6322: foreach my $case (@{$cancreate{$type}}) {
6323: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6324: }
6325: $chgtext .= '</ul>';
1.100 raeburn 6326: if (ref($cancreate{$type}) eq 'ARRAY') {
6327: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6328: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6329: if (@{$cancreate{'statustocreate'}} == 0) {
6330: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6331: }
6332: }
6333: }
6334: }
1.43 raeburn 6335: }
1.93 raeburn 6336: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6337: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6338: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6339: if (@{$cancreate{'selfcreate'}} > 0) {
6340: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6341:
6342: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6343: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6344: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6345: }
1.96 raeburn 6346: } elsif (ref($usertypes) eq 'HASH') {
6347: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6348: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6349: } else {
6350: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6351: }
6352: $chgtext .= '<ul>';
6353: foreach my $case (@{$cancreate{$type}}) {
6354: if ($case eq 'default') {
6355: $chgtext .= '<li>'.$othertitle.'</li>';
6356: } else {
6357: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6358: }
6359: }
1.100 raeburn 6360: $chgtext .= '</ul>';
6361: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6362: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6363: }
6364: }
6365: } else {
6366: if (@{$cancreate{$type}} == 0) {
6367: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6368: } else {
6369: $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 6370: }
6371: }
6372: }
1.43 raeburn 6373: } else {
6374: if ($cancreate{$type} eq 'none') {
6375: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6376: } elsif ($cancreate{$type} eq 'any') {
6377: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6378: } elsif ($cancreate{$type} eq 'official') {
6379: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6380: } elsif ($cancreate{$type} eq 'unofficial') {
6381: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6382: }
1.34 raeburn 6383: }
6384: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6385: }
6386: }
6387: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6388: my ($rules,$ruleorder) =
6389: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6390: my $chgtext = '<ul>';
6391: foreach my $type (@username_rule) {
6392: if (ref($rules->{$type}) eq 'HASH') {
6393: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6394: }
6395: }
6396: $chgtext .= '</ul>';
6397: if (@username_rule > 0) {
6398: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6399: } else {
1.28 raeburn 6400: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6401: }
6402: }
1.32 raeburn 6403: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6404: my ($idrules,$idruleorder) =
6405: &Apache::lonnet::inst_userrules($dom,'id');
6406: my $chgtext = '<ul>';
6407: foreach my $type (@id_rule) {
6408: if (ref($idrules->{$type}) eq 'HASH') {
6409: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6410: }
6411: }
6412: $chgtext .= '</ul>';
6413: if (@id_rule > 0) {
6414: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6415: } else {
6416: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6417: }
6418: }
1.43 raeburn 6419: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6420: my ($emailrules,$emailruleorder) =
6421: &Apache::lonnet::inst_userrules($dom,'email');
6422: my $chgtext = '<ul>';
6423: foreach my $type (@email_rule) {
6424: if (ref($emailrules->{$type}) eq 'HASH') {
6425: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6426: }
6427: }
6428: $chgtext .= '</ul>';
6429: if (@email_rule > 0) {
6430: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6431: } else {
6432: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6433: }
6434: }
6435:
1.28 raeburn 6436: my %authname = &authtype_names();
6437: my %context_title = &context_names();
6438: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6439: my $chgtext = '<ul>';
6440: foreach my $type (@{$changes{'authtypes'}}) {
6441: my @allowed;
6442: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6443: foreach my $auth (@authtypes) {
6444: if ($authhash{$type}{$auth}) {
6445: push(@allowed,$authname{$auth});
6446: }
6447: }
1.43 raeburn 6448: if (@allowed > 0) {
6449: $chgtext .= join(', ',@allowed).'</li>';
6450: } else {
6451: $chgtext .= &mt('none').'</li>';
6452: }
1.28 raeburn 6453: }
6454: $chgtext .= '</ul>';
6455: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6456: $resulttext .= '</li>';
6457: }
1.27 raeburn 6458: $resulttext .= '</ul>';
6459: } else {
1.28 raeburn 6460: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 6461: }
6462: } else {
6463: $resulttext = '<span class="LC_error">'.
1.23 raeburn 6464: &mt('An error occurred: [_1]',$putresult).'</span>';
6465: }
1.43 raeburn 6466: if ($warningmsg ne '') {
6467: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6468: }
1.23 raeburn 6469: return $resulttext;
6470: }
6471:
1.33 raeburn 6472: sub modify_usermodification {
6473: my ($dom,%domconfig) = @_;
6474: my ($resulttext,%curr_usermodification,%changes);
6475: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6476: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6477: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6478: }
6479: }
1.63 raeburn 6480: my @contexts = ('author','course','selfcreate');
1.33 raeburn 6481: my %context_title = (
6482: author => 'In author context',
6483: course => 'In course context',
1.63 raeburn 6484: selfcreate => 'When self creating account',
1.33 raeburn 6485: );
6486: my @fields = ('lastname','firstname','middlename','generation',
6487: 'permanentemail','id');
6488: my %roles = (
6489: author => ['ca','aa'],
6490: course => ['st','ep','ta','in','cr'],
6491: );
1.63 raeburn 6492: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6493: if (ref($types) eq 'ARRAY') {
6494: push(@{$types},'default');
6495: $usertypes->{'default'} = $othertitle;
6496: }
6497: $roles{'selfcreate'} = $types;
1.33 raeburn 6498: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6499: my %modifyhash;
6500: foreach my $context (@contexts) {
6501: foreach my $role (@{$roles{$context}}) {
6502: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6503: foreach my $item (@fields) {
6504: if (grep(/^\Q$item\E$/,@modifiable)) {
6505: $modifyhash{$context}{$role}{$item} = 1;
6506: } else {
6507: $modifyhash{$context}{$role}{$item} = 0;
6508: }
6509: }
6510: }
6511: if (ref($curr_usermodification{$context}) eq 'HASH') {
6512: foreach my $role (@{$roles{$context}}) {
6513: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6514: foreach my $field (@fields) {
6515: if ($modifyhash{$context}{$role}{$field} ne
6516: $curr_usermodification{$context}{$role}{$field}) {
6517: push(@{$changes{$context}},$role);
6518: last;
6519: }
6520: }
6521: }
6522: }
6523: } else {
6524: foreach my $context (@contexts) {
6525: foreach my $role (@{$roles{$context}}) {
6526: push(@{$changes{$context}},$role);
6527: }
6528: }
6529: }
6530: }
6531: my %usermodification_hash = (
6532: usermodification => \%modifyhash,
6533: );
6534: my $putresult = &Apache::lonnet::put_dom('configuration',
6535: \%usermodification_hash,$dom);
6536: if ($putresult eq 'ok') {
6537: if (keys(%changes) > 0) {
6538: $resulttext = &mt('Changes made: ').'<ul>';
6539: foreach my $context (@contexts) {
6540: if (ref($changes{$context}) eq 'ARRAY') {
6541: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6542: if (ref($changes{$context}) eq 'ARRAY') {
6543: foreach my $role (@{$changes{$context}}) {
6544: my $rolename;
1.63 raeburn 6545: if ($context eq 'selfcreate') {
6546: $rolename = $role;
6547: if (ref($usertypes) eq 'HASH') {
6548: if ($usertypes->{$role} ne '') {
6549: $rolename = $usertypes->{$role};
6550: }
6551: }
1.33 raeburn 6552: } else {
1.63 raeburn 6553: if ($role eq 'cr') {
6554: $rolename = &mt('Custom');
6555: } else {
6556: $rolename = &Apache::lonnet::plaintext($role);
6557: }
1.33 raeburn 6558: }
6559: my @modifiable;
1.63 raeburn 6560: if ($context eq 'selfcreate') {
1.126 bisitz 6561: $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 6562: } else {
6563: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6564: }
1.33 raeburn 6565: foreach my $field (@fields) {
6566: if ($modifyhash{$context}{$role}{$field}) {
6567: push(@modifiable,$fieldtitles{$field});
6568: }
6569: }
6570: if (@modifiable > 0) {
6571: $resulttext .= join(', ',@modifiable);
6572: } else {
6573: $resulttext .= &mt('none');
6574: }
6575: $resulttext .= '</li>';
6576: }
6577: $resulttext .= '</ul></li>';
6578: }
6579: }
6580: }
6581: $resulttext .= '</ul>';
6582: } else {
6583: $resulttext = &mt('No changes made to user modification settings');
6584: }
6585: } else {
6586: $resulttext = '<span class="LC_error">'.
6587: &mt('An error occurred: [_1]',$putresult).'</span>';
6588: }
6589: return $resulttext;
6590: }
6591:
1.43 raeburn 6592: sub modify_defaults {
6593: my ($dom,$r) = @_;
6594: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6595: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6596: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6597: my @authtypes = ('internal','krb4','krb5','localauth');
6598: foreach my $item (@items) {
6599: $newvalues{$item} = $env{'form.'.$item};
6600: if ($item eq 'auth_def') {
6601: if ($newvalues{$item} ne '') {
6602: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6603: push(@errors,$item);
6604: }
6605: }
6606: } elsif ($item eq 'lang_def') {
6607: if ($newvalues{$item} ne '') {
6608: if ($newvalues{$item} =~ /^(\w+)/) {
6609: my $langcode = $1;
1.103 raeburn 6610: if ($langcode ne 'x_chef') {
6611: if (code2language($langcode) eq '') {
6612: push(@errors,$item);
6613: }
1.43 raeburn 6614: }
6615: } else {
6616: push(@errors,$item);
6617: }
6618: }
1.54 raeburn 6619: } elsif ($item eq 'timezone_def') {
6620: if ($newvalues{$item} ne '') {
1.62 raeburn 6621: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6622: push(@errors,$item);
6623: }
6624: }
1.68 raeburn 6625: } elsif ($item eq 'datelocale_def') {
6626: if ($newvalues{$item} ne '') {
6627: my @datelocale_ids = DateTime::Locale->ids();
6628: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6629: push(@errors,$item);
6630: }
6631: }
1.141 raeburn 6632: } elsif ($item eq 'portal_def') {
6633: if ($newvalues{$item} ne '') {
6634: 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])\/?$/) {
6635: push(@errors,$item);
6636: }
6637: }
1.43 raeburn 6638: }
6639: if (grep(/^\Q$item\E$/,@errors)) {
6640: $newvalues{$item} = $domdefaults{$item};
6641: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6642: $changes{$item} = 1;
6643: }
1.72 raeburn 6644: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6645: }
6646: my %defaults_hash = (
1.72 raeburn 6647: defaults => \%newvalues,
6648: );
1.43 raeburn 6649: my $title = &defaults_titles();
6650: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6651: $dom);
6652: if ($putresult eq 'ok') {
6653: if (keys(%changes) > 0) {
6654: $resulttext = &mt('Changes made:').'<ul>';
6655: my $version = $r->dir_config('lonVersion');
6656: 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";
6657: foreach my $item (sort(keys(%changes))) {
6658: my $value = $env{'form.'.$item};
6659: if ($value eq '') {
6660: $value = &mt('none');
6661: } elsif ($item eq 'auth_def') {
6662: my %authnames = &authtype_names();
6663: my %shortauth = (
6664: internal => 'int',
6665: krb4 => 'krb4',
6666: krb5 => 'krb5',
6667: localauth => 'loc',
6668: );
6669: $value = $authnames{$shortauth{$value}};
6670: }
6671: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6672: $mailmsgtext .= "$title->{$item} set to $value\n";
6673: }
6674: $resulttext .= '</ul>';
6675: $mailmsgtext .= "\n";
6676: my $cachetime = 24*60*60;
1.72 raeburn 6677: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6678: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6679: my $sysmail = $r->dir_config('lonSysEMail');
6680: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6681: }
1.43 raeburn 6682: } else {
1.54 raeburn 6683: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6684: }
6685: } else {
6686: $resulttext = '<span class="LC_error">'.
6687: &mt('An error occurred: [_1]',$putresult).'</span>';
6688: }
6689: if (@errors > 0) {
6690: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6691: foreach my $item (@errors) {
6692: $resulttext .= ' "'.$title->{$item}.'",';
6693: }
6694: $resulttext =~ s/,$//;
6695: }
6696: return $resulttext;
6697: }
6698:
1.46 raeburn 6699: sub modify_scantron {
1.48 raeburn 6700: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6701: my ($resulttext,%confhash,%changes,$errors);
6702: my $custom = 'custom.tab';
6703: my $default = 'default.tab';
6704: my $servadm = $r->dir_config('lonAdmEMail');
6705: my ($configuserok,$author_ok,$switchserver) =
6706: &config_check($dom,$confname,$servadm);
6707: if ($env{'form.scantronformat.filename'} ne '') {
6708: my $error;
6709: if ($configuserok eq 'ok') {
6710: if ($switchserver) {
1.130 raeburn 6711: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6712: } else {
6713: if ($author_ok eq 'ok') {
6714: my ($result,$scantronurl) =
6715: &publishlogo($r,'upload','scantronformat',$dom,
6716: $confname,'scantron','','',$custom);
6717: if ($result eq 'ok') {
6718: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6719: $changes{'scantronformat'} = 1;
1.46 raeburn 6720: } else {
6721: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6722: }
6723: } else {
6724: $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);
6725: }
6726: }
6727: } else {
6728: $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);
6729: }
6730: if ($error) {
6731: &Apache::lonnet::logthis($error);
6732: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6733: }
6734: }
1.48 raeburn 6735: if (ref($domconfig{'scantron'}) eq 'HASH') {
6736: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6737: if ($env{'form.scantronformat_del'}) {
6738: $confhash{'scantron'}{'scantronformat'} = '';
6739: $changes{'scantronformat'} = 1;
1.46 raeburn 6740: }
6741: }
6742: }
6743: if (keys(%confhash) > 0) {
6744: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6745: $dom);
6746: if ($putresult eq 'ok') {
6747: if (keys(%changes) > 0) {
1.48 raeburn 6748: if (ref($confhash{'scantron'}) eq 'HASH') {
6749: $resulttext = &mt('Changes made:').'<ul>';
6750: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6751: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6752: } else {
1.130 raeburn 6753: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6754: }
1.48 raeburn 6755: $resulttext .= '</ul>';
6756: } else {
1.130 raeburn 6757: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6758: }
6759: $resulttext .= '</ul>';
6760: &Apache::loncommon::devalidate_domconfig_cache($dom);
6761: } else {
1.130 raeburn 6762: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6763: }
6764: } else {
6765: $resulttext = '<span class="LC_error">'.
6766: &mt('An error occurred: [_1]',$putresult).'</span>';
6767: }
6768: } else {
1.130 raeburn 6769: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6770: }
6771: if ($errors) {
6772: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6773: $errors.'</ul>';
6774: }
6775: return $resulttext;
6776: }
6777:
1.48 raeburn 6778: sub modify_coursecategories {
6779: my ($dom,%domconfig) = @_;
1.57 raeburn 6780: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6781: $cathash);
1.48 raeburn 6782: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6783: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6784: $cathash = $domconfig{'coursecategories'}{'cats'};
6785: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6786: $changes{'togglecats'} = 1;
6787: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6788: }
6789: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6790: $changes{'categorize'} = 1;
6791: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6792: }
1.120 raeburn 6793: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6794: $changes{'togglecatscomm'} = 1;
6795: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6796: }
6797: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6798: $changes{'categorizecomm'} = 1;
6799: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6800: }
1.57 raeburn 6801: } else {
6802: $changes{'togglecats'} = 1;
6803: $changes{'categorize'} = 1;
1.124 raeburn 6804: $changes{'togglecatscomm'} = 1;
6805: $changes{'categorizecomm'} = 1;
1.87 raeburn 6806: $domconfig{'coursecategories'} = {
6807: togglecats => $env{'form.togglecats'},
6808: categorize => $env{'form.categorize'},
1.124 raeburn 6809: togglecatscomm => $env{'form.togglecatscomm'},
6810: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6811: };
1.57 raeburn 6812: }
6813: if (ref($cathash) eq 'HASH') {
6814: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6815: push (@deletecategory,'instcode::0');
6816: }
1.120 raeburn 6817: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6818: push(@deletecategory,'communities::0');
6819: }
1.48 raeburn 6820: }
1.57 raeburn 6821: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6822: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6823: if (@deletecategory > 0) {
6824: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6825: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6826: foreach my $item (@deletecategory) {
1.57 raeburn 6827: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6828: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6829: $deletions{$item} = 1;
1.57 raeburn 6830: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6831: }
6832: }
6833: }
1.57 raeburn 6834: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6835: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6836: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6837: $reorderings{$item} = 1;
1.57 raeburn 6838: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6839: }
6840: if ($env{'form.addcategory_name_'.$item} ne '') {
6841: my $newcat = $env{'form.addcategory_name_'.$item};
6842: my $newdepth = $depth+1;
6843: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6844: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6845: $adds{$newitem} = 1;
6846: }
6847: if ($env{'form.subcat_'.$item} ne '') {
6848: my $newcat = $env{'form.subcat_'.$item};
6849: my $newdepth = $depth+1;
6850: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6851: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6852: $adds{$newitem} = 1;
6853: }
6854: }
6855: }
6856: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6857: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6858: my $newitem = 'instcode::0';
1.57 raeburn 6859: if ($cathash->{$newitem} eq '') {
6860: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6861: $adds{$newitem} = 1;
6862: }
6863: } else {
6864: my $newitem = 'instcode::0';
1.57 raeburn 6865: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6866: $adds{$newitem} = 1;
6867: }
6868: }
1.120 raeburn 6869: if ($env{'form.communities'} eq '1') {
6870: if (ref($cathash) eq 'HASH') {
6871: my $newitem = 'communities::0';
6872: if ($cathash->{$newitem} eq '') {
6873: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6874: $adds{$newitem} = 1;
6875: }
6876: } else {
6877: my $newitem = 'communities::0';
6878: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6879: $adds{$newitem} = 1;
6880: }
6881: }
1.48 raeburn 6882: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6883: if (($env{'form.addcategory_name'} ne 'instcode') &&
6884: ($env{'form.addcategory_name'} ne 'communities')) {
6885: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6886: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6887: $adds{$newitem} = 1;
6888: }
1.48 raeburn 6889: }
1.57 raeburn 6890: my $putresult;
1.48 raeburn 6891: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6892: if (keys(%deletions) > 0) {
6893: foreach my $key (keys(%deletions)) {
6894: if ($predelallitems{$key} ne '') {
6895: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6896: }
6897: }
6898: }
6899: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6900: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6901: if (ref($chkcats[0]) eq 'ARRAY') {
6902: my $depth = 0;
6903: my $chg = 0;
6904: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6905: my $name = $chkcats[0][$i];
6906: my $item;
6907: if ($name eq '') {
6908: $chg ++;
6909: } else {
6910: $item = &escape($name).'::0';
6911: if ($chg) {
1.57 raeburn 6912: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6913: }
6914: $depth ++;
1.57 raeburn 6915: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6916: $depth --;
6917: }
6918: }
6919: }
1.57 raeburn 6920: }
6921: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6922: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6923: if ($putresult eq 'ok') {
1.57 raeburn 6924: my %title = (
1.120 raeburn 6925: togglecats => 'Show/Hide a course in catalog',
6926: categorize => 'Assign a category to a course',
6927: togglecatscomm => 'Show/Hide a community in catalog',
6928: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6929: );
6930: my %level = (
1.120 raeburn 6931: dom => 'set in Domain ("Modify Course/Community")',
6932: crs => 'set in Course ("Course Configuration")',
6933: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6934: );
1.48 raeburn 6935: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6936: if ($changes{'togglecats'}) {
6937: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6938: }
6939: if ($changes{'categorize'}) {
6940: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6941: }
1.120 raeburn 6942: if ($changes{'togglecatscomm'}) {
6943: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6944: }
6945: if ($changes{'categorizecomm'}) {
6946: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6947: }
1.57 raeburn 6948: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6949: my $cathash;
6950: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6951: $cathash = $domconfig{'coursecategories'}{'cats'};
6952: } else {
6953: $cathash = {};
6954: }
6955: my (@cats,@trails,%allitems);
6956: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6957: if (keys(%deletions) > 0) {
6958: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6959: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6960: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6961: }
6962: $resulttext .= '</ul></li>';
6963: }
6964: if (keys(%reorderings) > 0) {
6965: my %sort_by_trail;
6966: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6967: foreach my $key (keys(%reorderings)) {
6968: if ($allitems{$key} ne '') {
6969: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6970: }
1.48 raeburn 6971: }
1.57 raeburn 6972: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6973: $resulttext .= '<li>'.$trails[$trail].'</li>';
6974: }
6975: $resulttext .= '</ul></li>';
1.48 raeburn 6976: }
1.57 raeburn 6977: if (keys(%adds) > 0) {
6978: my %sort_by_trail;
6979: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6980: foreach my $key (keys(%adds)) {
6981: if ($allitems{$key} ne '') {
6982: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6983: }
6984: }
6985: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6986: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 6987: }
1.57 raeburn 6988: $resulttext .= '</ul></li>';
1.48 raeburn 6989: }
6990: }
6991: $resulttext .= '</ul>';
6992: } else {
6993: $resulttext = '<span class="LC_error">'.
1.57 raeburn 6994: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 6995: }
6996: } else {
1.120 raeburn 6997: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 6998: }
6999: return $resulttext;
7000: }
7001:
1.69 raeburn 7002: sub modify_serverstatuses {
7003: my ($dom,%domconfig) = @_;
7004: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7005: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7006: %currserverstatus = %{$domconfig{'serverstatuses'}};
7007: }
7008: my @pages = &serverstatus_pages();
7009: foreach my $type (@pages) {
7010: $newserverstatus{$type}{'namedusers'} = '';
7011: $newserverstatus{$type}{'machines'} = '';
7012: if (defined($env{'form.'.$type.'_namedusers'})) {
7013: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7014: my @okusers;
7015: foreach my $user (@users) {
7016: my ($uname,$udom) = split(/:/,$user);
7017: if (($udom =~ /^$match_domain$/) &&
7018: (&Apache::lonnet::domain($udom)) &&
7019: ($uname =~ /^$match_username$/)) {
7020: if (!grep(/^\Q$user\E/,@okusers)) {
7021: push(@okusers,$user);
7022: }
7023: }
7024: }
7025: if (@okusers > 0) {
7026: @okusers = sort(@okusers);
7027: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7028: }
7029: }
7030: if (defined($env{'form.'.$type.'_machines'})) {
7031: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7032: my @okmachines;
7033: foreach my $ip (@machines) {
7034: my @parts = split(/\./,$ip);
7035: next if (@parts < 4);
7036: my $badip = 0;
7037: for (my $i=0; $i<4; $i++) {
7038: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7039: $badip = 1;
7040: last;
7041: }
7042: }
7043: if (!$badip) {
7044: push(@okmachines,$ip);
7045: }
7046: }
7047: @okmachines = sort(@okmachines);
7048: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7049: }
7050: }
7051: my %serverstatushash = (
7052: serverstatuses => \%newserverstatus,
7053: );
7054: foreach my $type (@pages) {
1.83 raeburn 7055: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7056: my (@current,@new);
1.83 raeburn 7057: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7058: if ($currserverstatus{$type}{$setting} ne '') {
7059: @current = split(/,/,$currserverstatus{$type}{$setting});
7060: }
7061: }
7062: if ($newserverstatus{$type}{$setting} ne '') {
7063: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7064: }
7065: if (@current > 0) {
7066: if (@new > 0) {
7067: foreach my $item (@current) {
7068: if (!grep(/^\Q$item\E$/,@new)) {
7069: $changes{$type}{$setting} = 1;
1.82 raeburn 7070: last;
7071: }
7072: }
1.84 raeburn 7073: foreach my $item (@new) {
7074: if (!grep(/^\Q$item\E$/,@current)) {
7075: $changes{$type}{$setting} = 1;
7076: last;
1.82 raeburn 7077: }
7078: }
7079: } else {
1.83 raeburn 7080: $changes{$type}{$setting} = 1;
1.69 raeburn 7081: }
1.83 raeburn 7082: } elsif (@new > 0) {
7083: $changes{$type}{$setting} = 1;
1.69 raeburn 7084: }
7085: }
7086: }
7087: if (keys(%changes) > 0) {
1.81 raeburn 7088: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7089: my $putresult = &Apache::lonnet::put_dom('configuration',
7090: \%serverstatushash,$dom);
7091: if ($putresult eq 'ok') {
7092: $resulttext .= &mt('Changes made:').'<ul>';
7093: foreach my $type (@pages) {
1.84 raeburn 7094: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7095: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7096: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7097: if ($newserverstatus{$type}{'namedusers'} eq '') {
7098: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7099: } else {
7100: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7101: }
1.84 raeburn 7102: }
7103: if ($changes{$type}{'machines'}) {
1.69 raeburn 7104: if ($newserverstatus{$type}{'machines'} eq '') {
7105: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7106: } else {
7107: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7108: }
7109:
7110: }
7111: $resulttext .= '</ul></li>';
7112: }
7113: }
7114: $resulttext .= '</ul>';
7115: } else {
7116: $resulttext = '<span class="LC_error">'.
7117: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7118:
7119: }
7120: } else {
7121: $resulttext = &mt('No changes made to access to server status pages');
7122: }
7123: return $resulttext;
7124: }
7125:
1.118 jms 7126: sub modify_helpsettings {
1.122 jms 7127: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 7128: my ($resulttext,$errors,%changes,%helphash);
7129:
1.122 jms 7130: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7131: my $defaulthelpfile = 'defaulthelp.html';
7132: my $servadm = $r->dir_config('lonAdmEMail');
7133: my ($configuserok,$author_ok,$switchserver) =
7134: &config_check($dom,$confname,$servadm);
7135:
1.118 jms 7136: my %defaultchecked = ('submitbugs' => 'on');
7137: my @offon = ('off','on');
1.122 jms 7138: my %title = ( submitbugs => 'Display link for users to submit a bug',
7139: loginhelpurl => 'Unauthenticated login help page set to custom file');
7140:
1.118 jms 7141: my @toggles = ('submitbugs');
7142:
7143: $helphash{'helpsettings'} = {};
7144:
7145: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7146: if ($domconfig{'helpsettings'} eq '') {
7147: $domconfig{'helpsettings'} = {};
7148: }
7149: }
7150:
7151: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7152:
7153: foreach my $item (@toggles) {
7154:
7155: if ($defaultchecked{$item} eq 'on') {
7156: if (($domconfig{'helpsettings'}{$item} eq '') &&
7157: ($env{'form.'.$item} eq '0')) {
7158: $changes{$item} = 1;
7159: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7160: $changes{$item} = 1;
7161: }
7162: } elsif ($defaultchecked{$item} eq 'off') {
7163: if (($domconfig{'helpsettings'}{$item} eq '') &&
7164: ($env{'form.'.$item} eq '1')) {
7165: $changes{$item} = 1;
7166: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7167: $changes{$item} = 1;
7168: }
7169: }
7170: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7171: }
7172:
7173: if ($customhelpfile ne '') {
7174: my $error;
7175: if ($configuserok eq 'ok') {
7176: if ($switchserver) {
7177: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7178: } else {
7179: if ($author_ok eq 'ok') {
7180: my ($result,$loginhelpurl) =
7181: &publishlogo($r,'upload','loginhelpurl',$dom,
7182: $confname,'help','','',$customhelpfile);
7183: if ($result eq 'ok') {
7184: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7185: $changes{'loginhelpurl'} = 1;
7186: } else {
7187: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7188: }
7189: } else {
7190: $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);
7191: }
7192: }
7193: } else {
7194: $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);
7195: }
7196: if ($error) {
7197: &Apache::lonnet::logthis($error);
7198: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7199: }
7200: }
7201:
7202: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7203: if ($env{'form.loginhelpurl_del'}) {
7204: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7205: $changes{'loginhelpurl'} = 1;
7206: }
7207: }
1.118 jms 7208: }
7209:
1.123 jms 7210:
7211: my $putresult;
7212:
7213: if (keys(%changes) > 0) {
7214: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7215: } else {
7216: $putresult = 'ok';
7217: }
1.118 jms 7218:
7219: if ($putresult eq 'ok') {
7220: if (keys(%changes) > 0) {
7221: $resulttext = &mt('Changes made:').'<ul>';
7222: foreach my $item (sort(keys(%changes))) {
7223: if ($item eq 'submitbugs') {
7224: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7225: }
1.122 jms 7226: if ($item eq 'loginhelpurl') {
7227: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7228: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7229: } else {
7230: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7231: }
7232: }
1.118 jms 7233: }
7234: $resulttext .= '</ul>';
7235: } else {
7236: $resulttext = &mt('No changes made to help settings');
7237: }
7238: } else {
7239: $resulttext = '<span class="LC_error">'.
7240: &mt('An error occurred: [_1]',$putresult).'</span>';
7241: }
7242: if ($errors) {
7243: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7244: $errors.'</ul>';
7245: }
7246: return $resulttext;
7247: }
7248:
1.121 raeburn 7249: sub modify_coursedefaults {
7250: my ($dom,%domconfig) = @_;
7251: my ($resulttext,$errors,%changes,%defaultshash);
7252: my %defaultchecked = ('canuse_pdfforms' => 'off');
7253: my @offon = ('off','on');
7254: my @toggles = ('canuse_pdfforms');
7255:
7256: $defaultshash{'coursedefaults'} = {};
7257:
7258: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7259: if ($domconfig{'coursedefaults'} eq '') {
7260: $domconfig{'coursedefaults'} = {};
7261: }
7262: }
7263:
7264: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7265: foreach my $item (@toggles) {
7266: if ($defaultchecked{$item} eq 'on') {
7267: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7268: ($env{'form.'.$item} eq '0')) {
7269: $changes{$item} = 1;
7270: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7271: $changes{$item} = 1;
7272: }
7273: } elsif ($defaultchecked{$item} eq 'off') {
7274: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7275: ($env{'form.'.$item} eq '1')) {
7276: $changes{$item} = 1;
7277: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7278: $changes{$item} = 1;
7279: }
7280: }
7281: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7282: }
1.139 raeburn 7283: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7284: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7285: $newdefresponder =~ s/\D//g;
7286: if ($newdefresponder eq '' || $newdefresponder < 1) {
7287: $newdefresponder = 1;
7288: }
7289: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7290: if ($currdefresponder ne $newdefresponder) {
7291: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7292: $changes{'anonsurvey_threshold'} = 1;
7293: }
7294: }
1.121 raeburn 7295: }
7296: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7297: $dom);
7298: if ($putresult eq 'ok') {
7299: if (keys(%changes) > 0) {
7300: if ($changes{'canuse_pdfforms'}) {
7301: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7302: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7303: my $cachetime = 24*60*60;
7304: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7305: }
7306: $resulttext = &mt('Changes made:').'<ul>';
7307: foreach my $item (sort(keys(%changes))) {
7308: if ($item eq 'canuse_pdfforms') {
7309: if ($env{'form.'.$item} eq '1') {
7310: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7311: } else {
7312: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7313: }
1.139 raeburn 7314: } elsif ($item eq 'anonsurvey_threshold') {
7315: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7316: }
1.121 raeburn 7317: }
7318: $resulttext .= '</ul>';
7319: } else {
7320: $resulttext = &mt('No changes made to course defaults');
7321: }
7322: } else {
7323: $resulttext = '<span class="LC_error">'.
7324: &mt('An error occurred: [_1]',$putresult).'</span>';
7325: }
7326: return $resulttext;
7327: }
7328:
1.137 raeburn 7329: sub modify_usersessions {
7330: my ($dom,%domconfig) = @_;
1.145 raeburn 7331: my @hostingtypes = ('version','excludedomain','includedomain');
7332: my @offloadtypes = ('primary','default');
7333: my %types = (
7334: remote => \@hostingtypes,
7335: hosted => \@hostingtypes,
7336: spares => \@offloadtypes,
7337: );
7338: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7339: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7340: my (%by_ip,%by_location,@intdoms);
7341: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7342: my @locations = sort(keys(%by_location));
1.137 raeburn 7343: my (%defaultshash,%changes);
7344: foreach my $prefix (@prefixes) {
7345: $defaultshash{'usersessions'}{$prefix} = {};
7346: }
7347: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7348: my $resulttext;
1.138 raeburn 7349: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7350: foreach my $prefix (@prefixes) {
1.145 raeburn 7351: next if ($prefix eq 'spares');
7352: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7353: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7354: if ($type eq 'version') {
7355: my $value = $env{'form.'.$prefix.'_'.$type};
7356: my $okvalue;
7357: if ($value ne '') {
7358: if (grep(/^\Q$value\E$/,@lcversions)) {
7359: $okvalue = $value;
7360: }
7361: }
7362: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7363: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7364: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7365: if ($inuse == 0) {
7366: $changes{$prefix}{$type} = 1;
7367: } else {
7368: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7369: $changes{$prefix}{$type} = 1;
7370: }
7371: if ($okvalue ne '') {
7372: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7373: }
7374: }
7375: } else {
7376: if (($inuse == 1) && ($okvalue ne '')) {
7377: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7378: $changes{$prefix}{$type} = 1;
7379: }
7380: }
7381: } else {
7382: if (($inuse == 1) && ($okvalue ne '')) {
7383: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7384: $changes{$prefix}{$type} = 1;
7385: }
7386: }
7387: } else {
7388: if (($inuse == 1) && ($okvalue ne '')) {
7389: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7390: $changes{$prefix}{$type} = 1;
7391: }
7392: }
7393: } else {
7394: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7395: my @okvals;
7396: foreach my $val (@vals) {
1.138 raeburn 7397: if ($val =~ /:/) {
7398: my @items = split(/:/,$val);
7399: foreach my $item (@items) {
7400: if (ref($by_location{$item}) eq 'ARRAY') {
7401: push(@okvals,$item);
7402: }
7403: }
7404: } else {
7405: if (ref($by_location{$val}) eq 'ARRAY') {
7406: push(@okvals,$val);
7407: }
1.137 raeburn 7408: }
7409: }
7410: @okvals = sort(@okvals);
7411: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7412: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7413: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7414: if ($inuse == 0) {
7415: $changes{$prefix}{$type} = 1;
7416: } else {
7417: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7418: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7419: if (@changed > 0) {
7420: $changes{$prefix}{$type} = 1;
7421: }
7422: }
7423: } else {
7424: if ($inuse == 1) {
7425: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7426: $changes{$prefix}{$type} = 1;
7427: }
7428: }
7429: } else {
7430: if ($inuse == 1) {
7431: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7432: $changes{$prefix}{$type} = 1;
7433: }
7434: }
7435: } else {
7436: if ($inuse == 1) {
7437: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7438: $changes{$prefix}{$type} = 1;
7439: }
7440: }
7441: }
7442: }
7443: }
1.145 raeburn 7444:
7445: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7446: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7447: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7448: my $savespares;
7449:
7450: foreach my $lonhost (sort(keys(%servers))) {
7451: my $serverhomeID =
7452: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 7453: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7454: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7455: my %spareschg;
7456: foreach my $type (@{$types{'spares'}}) {
7457: my @okspares;
7458: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7459: foreach my $server (@checked) {
1.152 raeburn 7460: if (&Apache::lonnet::hostname($server) ne '') {
7461: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7462: unless (grep(/^\Q$server\E$/,@okspares)) {
7463: push(@okspares,$server);
7464: }
1.145 raeburn 7465: }
7466: }
7467: }
7468: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7469: my $newspare;
1.152 raeburn 7470: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
7471: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 7472: $newspare = $new;
7473: }
7474: }
1.152 raeburn 7475: my @spares;
7476: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7477: @spares = sort(@okspares,$newspare);
7478: } else {
7479: @spares = sort(@okspares);
7480: }
7481: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 7482: if (ref($spareid{$lonhost}) eq 'HASH') {
7483: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 7484: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 7485: if (@diffs > 0) {
7486: $spareschg{$type} = 1;
7487: }
7488: }
7489: }
7490: }
7491: if (keys(%spareschg) > 0) {
7492: $changes{'spares'}{$lonhost} = \%spareschg;
7493: }
7494: }
7495:
7496: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7497: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7498: if (ref($changes{'spares'}) eq 'HASH') {
7499: if (keys(%{$changes{'spares'}}) > 0) {
7500: $savespares = 1;
7501: }
7502: }
7503: } else {
7504: $savespares = 1;
7505: }
7506: }
7507:
1.147 raeburn 7508: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7509: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 7510: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7511: $dom);
7512: if ($putresult eq 'ok') {
7513: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7514: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7515: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7516: }
7517: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7518: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7519: }
7520: }
7521: my $cachetime = 24*60*60;
7522: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 7523: if (keys(%changes) > 0) {
7524: my %lt = &usersession_titles();
7525: $resulttext = &mt('Changes made:').'<ul>';
7526: foreach my $prefix (@prefixes) {
7527: if (ref($changes{$prefix}) eq 'HASH') {
7528: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7529: if ($prefix eq 'spares') {
7530: if (ref($changes{$prefix}) eq 'HASH') {
7531: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7532: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 7533: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7534: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 7535: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7536: foreach my $type (@{$types{$prefix}}) {
7537: if ($changes{$prefix}{$lonhost}{$type}) {
7538: my $offloadto = &mt('None');
7539: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7540: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7541: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7542: }
1.145 raeburn 7543: }
1.147 raeburn 7544: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 7545: }
1.137 raeburn 7546: }
7547: }
1.147 raeburn 7548: $resulttext .= '</li>';
1.137 raeburn 7549: }
7550: }
1.147 raeburn 7551: } else {
7552: foreach my $type (@{$types{$prefix}}) {
7553: if (defined($changes{$prefix}{$type})) {
7554: my $newvalue;
7555: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7556: if (ref($defaultshash{'usersessions'}{$prefix})) {
7557: if ($type eq 'version') {
7558: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7559: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7560: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7561: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7562: }
1.145 raeburn 7563: }
7564: }
7565: }
1.147 raeburn 7566: if ($newvalue eq '') {
7567: if ($type eq 'version') {
7568: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7569: } else {
7570: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7571: }
1.145 raeburn 7572: } else {
1.147 raeburn 7573: if ($type eq 'version') {
7574: $newvalue .= ' '.&mt('(or later)');
7575: }
7576: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 7577: }
1.137 raeburn 7578: }
7579: }
7580: }
1.147 raeburn 7581: $resulttext .= '</ul>';
1.137 raeburn 7582: }
7583: }
1.147 raeburn 7584: $resulttext .= '</ul>';
7585: } else {
7586: $resulttext = $nochgmsg;
1.137 raeburn 7587: }
7588: } else {
7589: $resulttext = '<span class="LC_error">'.
7590: &mt('An error occurred: [_1]',$putresult).'</span>';
7591: }
7592: } else {
1.147 raeburn 7593: $resulttext = $nochgmsg;
1.137 raeburn 7594: }
7595: return $resulttext;
7596: }
7597:
1.150 raeburn 7598: sub modify_loadbalancing {
7599: my ($dom,%domconfig) = @_;
7600: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7601: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7602: my ($othertitle,$usertypes,$types) =
7603: &Apache::loncommon::sorted_inst_types($dom);
7604: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7605: my @sparestypes = ('primary','default');
7606: my %typetitles = &sparestype_titles();
7607: my $resulttext;
7608: if (keys(%servers) > 1) {
7609: my ($currbalancer,$currtargets,$currrules);
7610: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7611: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7612: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7613: $currrules = $domconfig{'loadbalancing'}{'rules'};
7614: } else {
7615: ($currbalancer,$currtargets) =
7616: &Apache::lonnet::get_lonbalancer_config(\%servers);
7617: }
7618: my ($saveloadbalancing,%defaultshash,%changes);
7619: my ($alltypes,$othertypes,$titles) =
7620: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7621: my %ruletitles = &offloadtype_text();
7622: my $balancer = $env{'form.loadbalancing_lonhost'};
7623: if (!$servers{$balancer}) {
7624: undef($balancer);
7625: }
7626: if ($currbalancer ne $balancer) {
7627: $changes{'lonhost'} = 1;
7628: }
7629: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7630: if ($balancer ne '') {
7631: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7632: $saveloadbalancing = 1;
7633: }
7634: foreach my $sparetype (@sparestypes) {
7635: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151 raeburn 7636: my @offloadto;
1.150 raeburn 7637: foreach my $target (@targets) {
7638: if (($servers{$target}) && ($target ne $balancer)) {
7639: if ($sparetype eq 'default') {
7640: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7641: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7642: }
7643: }
7644: unless(grep(/^\Q$target\E$/,@offloadto)) {
7645: push(@offloadto,$target);
7646: }
7647: }
7648: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7649: }
7650: }
7651: } else {
7652: foreach my $sparetype (@sparestypes) {
7653: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7654: }
7655: }
7656: if (ref($currtargets) eq 'HASH') {
7657: foreach my $sparetype (@sparestypes) {
7658: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7659: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7660: if (@targetdiffs > 0) {
7661: $changes{'targets'} = 1;
7662: }
7663: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7664: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7665: $changes{'targets'} = 1;
7666: }
7667: }
7668: }
7669: } else {
7670: foreach my $sparetype (@sparestypes) {
7671: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7672: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7673: $changes{'targets'} = 1;
7674: }
7675: }
7676: }
7677: }
7678: my $ishomedom;
7679: if ($balancer ne '') {
7680: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7681: $ishomedom = 1;
7682: }
7683: }
7684: if (ref($alltypes) eq 'ARRAY') {
7685: foreach my $type (@{$alltypes}) {
7686: my $rule;
7687: if ($balancer ne '') {
7688: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7689: (!$ishomedom)) {
7690: $rule = $env{'form.loadbalancing_rules_'.$type};
7691: }
7692: if ($rule eq 'specific') {
7693: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7694: }
7695: }
7696: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7697: if (ref($currrules) eq 'HASH') {
7698: if ($rule ne $currrules->{$type}) {
7699: $changes{'rules'}{$type} = 1;
7700: }
7701: } elsif ($rule ne '') {
7702: $changes{'rules'}{$type} = 1;
7703: }
7704: }
7705: }
7706: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7707: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
7708: my $putresult = &Apache::lonnet::put_dom('configuration',
7709: \%defaultshash,$dom);
7710: if ($putresult eq 'ok') {
7711: if (keys(%changes) > 0) {
7712: if ($changes{'lonhost'}) {
7713: if ($currbalancer ne '') {
7714: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
7715: }
7716: if ($balancer eq '') {
7717: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
7718: } else {
7719: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7720: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
7721: }
7722: } else {
7723: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7724: }
7725: if (($changes{'targets'}) && ($balancer ne '')) {
7726: my %offloadstr;
7727: foreach my $sparetype (@sparestypes) {
7728: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7729: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7730: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
7731: }
7732: }
7733: }
7734: if (keys(%offloadstr) == 0) {
7735: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
7736: } else {
7737: my $showoffload;
7738: foreach my $sparetype (@sparestypes) {
7739: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
7740: if (defined($offloadstr{$sparetype})) {
7741: $showoffload .= $offloadstr{$sparetype};
7742: } else {
7743: $showoffload .= &mt('None');
7744: }
7745: $showoffload .= (' 'x3);
7746: }
7747: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
7748: }
7749: }
7750: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
7751: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7752: foreach my $type (@{$alltypes}) {
7753: if ($changes{'rules'}{$type}) {
7754: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
7755: my $balancetext;
7756: if ($rule eq '') {
7757: $balancetext = $ruletitles{'default'};
7758: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
7759: $balancetext = $ruletitles{$rule};
7760: } else {
7761: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
7762: }
7763: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
7764: }
7765: }
7766: }
7767: }
7768: if ($resulttext ne '') {
7769: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
7770: } else {
7771: $resulttext = $nochgmsg;
7772: }
7773: } else {
7774: $resulttext = $nochgmsg;
7775: if ($balancer ne '') {
7776: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7777: }
7778: }
7779: } else {
7780: $resulttext = '<span class="LC_error">'.
7781: &mt('An error occurred: [_1]',$putresult).'</span>';
7782: }
7783: } else {
7784: $resulttext = $nochgmsg;
7785: }
7786: } else {
7787: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
7788: }
7789: return $resulttext;
7790: }
7791:
1.48 raeburn 7792: sub recurse_check {
7793: my ($chkcats,$categories,$depth,$name) = @_;
7794: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7795: my $chg = 0;
7796: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7797: my $category = $chkcats->[$depth]{$name}[$j];
7798: my $item;
7799: if ($category eq '') {
7800: $chg ++;
7801: } else {
7802: my $deeper = $depth + 1;
7803: $item = &escape($category).':'.&escape($name).':'.$depth;
7804: if ($chg) {
7805: $categories->{$item} -= $chg;
7806: }
7807: &recurse_check($chkcats,$categories,$deeper,$category);
7808: $deeper --;
7809: }
7810: }
7811: }
7812: return;
7813: }
7814:
7815: sub recurse_cat_deletes {
7816: my ($item,$coursecategories,$deletions) = @_;
7817: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7818: my $subdepth = $depth + 1;
7819: if (ref($coursecategories) eq 'HASH') {
7820: foreach my $subitem (keys(%{$coursecategories})) {
7821: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7822: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7823: delete($coursecategories->{$subitem});
7824: $deletions->{$subitem} = 1;
7825: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7826: }
7827: }
7828: }
7829: return;
7830: }
7831:
1.125 raeburn 7832: sub get_active_dcs {
7833: my ($dom) = @_;
7834: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7835: my %domcoords;
7836: my $numdcs = 0;
7837: my $now = time;
7838: foreach my $server (keys(%dompersonnel)) {
7839: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7840: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7841: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7842: if (($end eq '') || ($end == 0) || ($end > $now)) {
7843: if ($start <= $now) {
7844: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7845: }
7846: }
7847: }
7848: }
7849: return %domcoords;
7850: }
7851:
7852: sub active_dc_picker {
7853: my ($dom,$curr_dc) = @_;
7854: my %domcoords = &get_active_dcs($dom);
7855: my @dcs = sort(keys(%domcoords));
7856: my $numdcs = scalar(@dcs);
7857: my $datatable;
7858: my $numinrow = 2;
7859: if ($numdcs > 1) {
7860: $datatable = '<table>';
7861: for (my $i=0; $i<@dcs; $i++) {
7862: my $rem = $i%($numinrow);
7863: if ($rem == 0) {
7864: if ($i > 0) {
7865: $datatable .= '</tr>';
7866: }
7867: $datatable .= '<tr>';
7868: }
7869: my $check = ' ';
7870: if ($curr_dc eq '') {
7871: if (!$i) {
7872: $check = ' checked="checked" ';
7873: }
7874: } elsif ($dcs[$i] eq $curr_dc) {
7875: $check = ' checked="checked" ';
7876: }
7877: if ($i == @dcs - 1) {
7878: my $colsleft = $numinrow - $rem;
7879: if ($colsleft > 1) {
7880: $datatable .= '<td colspan="'.$colsleft.'">';
7881: } else {
7882: $datatable .= '<td>';
7883: }
7884: } else {
7885: $datatable .= '<td>';
7886: }
7887: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7888: $datatable .= '<span class="LC_nobreak"><label>'.
7889: '<input type="radio" name="autocreate_xmldc"'.
7890: ' value="'.$dcs[$i].'"'.$check.'/>'.
7891: &Apache::loncommon::plainname($dcname,$dcdom).
7892: '</label></span></td>';
7893: }
7894: $datatable .= '</tr></table>';
7895: } elsif (@dcs) {
7896: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7897: $dcs[0].'" />';
7898: }
7899: return ($numdcs,$datatable);
7900: }
7901:
1.137 raeburn 7902: sub usersession_titles {
7903: return &Apache::lonlocal::texthash(
7904: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7905: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 7906: spares => 'Servers offloaded to, when busy',
1.137 raeburn 7907: version => 'LON-CAPA version requirement',
1.138 raeburn 7908: excludedomain => 'Allow all, but exclude specific domains',
7909: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 7910: primary => 'Primary (checked first)',
1.154 raeburn 7911: default => 'Default',
1.137 raeburn 7912: );
7913: }
7914:
1.152 raeburn 7915: sub id_for_thisdom {
7916: my (%servers) = @_;
7917: my %altids;
7918: foreach my $server (keys(%servers)) {
7919: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7920: if ($serverhome ne $server) {
7921: $altids{$serverhome} = $server;
7922: }
7923: }
7924: return %altids;
7925: }
7926:
1.150 raeburn 7927: sub count_servers {
7928: my ($currbalancer,%servers) = @_;
7929: my (@spares,$numspares);
7930: foreach my $lonhost (sort(keys(%servers))) {
7931: next if ($currbalancer eq $lonhost);
7932: push(@spares,$lonhost);
7933: }
7934: if ($currbalancer) {
7935: $numspares = scalar(@spares);
7936: } else {
7937: $numspares = scalar(@spares) - 1;
7938: }
7939: return ($numspares,@spares);
7940: }
7941:
7942: sub lonbalance_targets_js {
7943: my ($dom,$types,$servers) = @_;
7944: my $select = &mt('Select');
7945: my ($alltargets,$allishome,$allinsttypes,@alltypes);
7946: if (ref($servers) eq 'HASH') {
7947: $alltargets = join("','",sort(keys(%{$servers})));
7948: my @homedoms;
7949: foreach my $server (sort(keys(%{$servers}))) {
7950: if (&Apache::lonnet::host_domain($server) eq $dom) {
7951: push(@homedoms,'1');
7952: } else {
7953: push(@homedoms,'0');
7954: }
7955: }
7956: $allishome = join("','",@homedoms);
7957: }
7958: if (ref($types) eq 'ARRAY') {
7959: if (@{$types} > 0) {
7960: @alltypes = @{$types};
7961: }
7962: }
7963: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
7964: $allinsttypes = join("','",@alltypes);
7965: return <<"END";
7966:
7967: <script type="text/javascript">
7968: // <![CDATA[
7969:
7970: function toggleTargets() {
7971: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
7972: if (balancer == '') {
7973: hideSpares();
7974: } else {
7975: var homedoms = new Array('$allishome');
7976: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
7977: showSpares(balancer,ishomedom);
7978: }
7979: return;
7980: }
7981:
7982: function showSpares(balancer,ishomedom) {
7983: var alltargets = new Array('$alltargets');
7984: var insttypes = new Array('$allinsttypes');
1.151 raeburn 7985: var offloadtypes = new Array('primary','default');
7986:
1.150 raeburn 7987: document.getElementById('loadbalancing_targets').style.display='block';
7988: document.getElementById('loadbalancing_disabled').style.display='none';
1.152 raeburn 7989:
1.151 raeburn 7990: for (var i=0; i<offloadtypes.length; i++) {
7991: var count = 0;
7992: for (var j=0; j<alltargets.length; j++) {
7993: if (alltargets[j] != balancer) {
7994: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
7995: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
7996: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
7997: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
7998: count ++;
7999: }
1.150 raeburn 8000: }
8001: }
1.151 raeburn 8002: for (var k=0; k<insttypes.length; k++) {
8003: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8004: if (ishomedom == 1) {
1.151 raeburn 8005: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8006: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8007: } else {
1.151 raeburn 8008: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8009: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150 raeburn 8010:
8011: }
8012: } else {
1.151 raeburn 8013: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8014: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8015: }
1.151 raeburn 8016: if ((insttypes[k] != '_LC_external') &&
8017: ((insttypes[k] != '_LC_internetdom') ||
8018: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8019: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8020: for (var m=0; m<alltargets.length; m++) {
8021: var idx = m+1;
8022: if (alltargets[m] != balancer) {
8023: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 8024: }
8025: }
8026: }
8027: }
8028: return;
8029: }
8030:
8031: function hideSpares() {
8032: var alltargets = new Array('$alltargets');
8033: var insttypes = new Array('$allinsttypes');
8034: var offloadtypes = new Array('primary','default');
8035:
8036: document.getElementById('loadbalancing_targets').style.display='none';
8037: document.getElementById('loadbalancing_disabled').style.display='block';
8038:
8039: var total = alltargets.length - 1;
8040: for (var i=0; i<offloadtypes; i++) {
8041: for (var j=0; j<total; j++) {
8042: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8043: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8044: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8045: }
1.150 raeburn 8046: }
8047: for (var k=0; k<insttypes.length; k++) {
1.151 raeburn 8048: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8049: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8050: if (insttypes[k] != '_LC_external') {
8051: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8052: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8053: }
8054: }
8055: return;
8056: }
8057:
8058: function checkOffloads(item,type) {
8059: var alltargets = new Array('$alltargets');
8060: var offloadtypes = new Array('primary','default');
8061: if (item.checked) {
8062: var total = alltargets.length - 1;
8063: var other;
8064: if (type == offloadtypes[0]) {
1.151 raeburn 8065: other = offloadtypes[1];
1.150 raeburn 8066: } else {
1.151 raeburn 8067: other = offloadtypes[0];
1.150 raeburn 8068: }
8069: for (var i=0; i<total; i++) {
8070: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8071: if (server == item.value) {
8072: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8073: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8074: }
8075: }
8076: }
8077: }
8078: return;
8079: }
8080:
8081: function singleServerToggle(type) {
8082: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8083: if (offloadtoSelIdx == 0) {
8084: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8085: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8086:
8087: } else {
8088: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8089: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8090: }
8091: return;
8092: }
8093:
8094: function balanceruleChange(formname,type) {
8095: if (type == '_LC_external') {
8096: return;
8097: }
8098: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8099: for (var i=0; i<typesRules.length; i++) {
8100: if (formname.elements[typesRules[i]].checked) {
8101: if (formname.elements[typesRules[i]].value != 'specific') {
8102: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8103: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8104: } else {
8105: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8106: }
8107: }
8108: }
8109: return;
8110: }
8111:
1.152 raeburn 8112: // ]]>
8113: </script>
8114:
8115: END
8116: }
8117:
8118: sub new_spares_js {
8119: my @sparestypes = ('primary','default');
8120: my $types = join("','",@sparestypes);
8121: my $select = &mt('Select');
8122: return <<"END";
8123:
8124: <script type="text/javascript">
8125: // <![CDATA[
8126:
8127: function updateNewSpares(formname,lonhost) {
8128: var types = new Array('$types');
8129: var include = new Array();
8130: var exclude = new Array();
8131: for (var i=0; i<types.length; i++) {
8132: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8133: for (var j=0; j<spareboxes.length; j++) {
8134: if (formname.elements[spareboxes[j]].checked) {
8135: exclude.push(formname.elements[spareboxes[j]].value);
8136: } else {
8137: include.push(formname.elements[spareboxes[j]].value);
8138: }
8139: }
8140: }
8141: for (var i=0; i<types.length; i++) {
8142: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8143: var selIdx = newSpare.selectedIndex;
8144: var currnew = newSpare.options[selIdx].value;
8145: var okSpares = new Array();
8146: for (var j=0; j<newSpare.options.length; j++) {
8147: var possible = newSpare.options[j].value;
8148: if (possible != '') {
8149: if (exclude.indexOf(possible) == -1) {
8150: okSpares.push(possible);
8151: } else {
8152: if (currnew == possible) {
8153: selIdx = 0;
8154: }
8155: }
8156: }
8157: }
8158: for (var k=0; k<include.length; k++) {
8159: if (okSpares.indexOf(include[k]) == -1) {
8160: okSpares.push(include[k]);
8161: }
8162: }
8163: okSpares.sort();
8164: newSpare.options.length = 0;
8165: if (selIdx == 0) {
8166: newSpare.options[0] = new Option("$select","",true,true);
8167: } else {
8168: newSpare.options[0] = new Option("$select","",false,false);
8169: }
8170: for (var m=0; m<okSpares.length; m++) {
8171: var idx = m+1;
8172: var selThis = 0;
8173: if (selIdx != 0) {
8174: if (okSpares[m] == currnew) {
8175: selThis = 1;
8176: }
8177: }
8178: if (selThis == 1) {
8179: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8180: } else {
8181: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8182: }
8183: }
8184: }
8185: return;
8186: }
8187:
8188: function checkNewSpares(lonhost,type) {
8189: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8190: var chosen = newSpare.options[newSpare.selectedIndex].value;
8191: if (chosen != '') {
8192: var othertype;
8193: var othernewSpare;
8194: if (type == 'primary') {
8195: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8196: }
8197: if (type == 'default') {
8198: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8199: }
8200: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8201: othernewSpare.selectedIndex = 0;
8202: }
8203: }
8204: return;
8205: }
8206:
8207: // ]]>
8208: </script>
8209:
8210: END
8211:
8212: }
8213:
8214: sub common_domprefs_js {
8215: return <<"END";
8216:
8217: <script type="text/javascript">
8218: // <![CDATA[
8219:
1.150 raeburn 8220: function getIndicesByName(formname,item) {
1.152 raeburn 8221: var group = new Array();
1.150 raeburn 8222: for (var i=0;i<formname.elements.length;i++) {
8223: if (formname.elements[i].name == item) {
1.152 raeburn 8224: group.push(formname.elements[i].id);
1.150 raeburn 8225: }
8226: }
1.152 raeburn 8227: return group;
1.150 raeburn 8228: }
8229:
8230: // ]]>
8231: </script>
8232:
8233: END
1.152 raeburn 8234:
1.150 raeburn 8235: }
8236:
1.3 raeburn 8237: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>