Annotation of loncom/interface/domainprefs.pm, revision 1.161
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.161 ! 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',
213: 'serverstatuses','requestcourses','helpsettings',
1.150 raeburn 214: 'coursedefaults','usersessions','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.121 raeburn 218: 'requestcourses','coursecategories','serverstatuses','helpsettings',
1.137 raeburn 219: 'coursedefaults','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.118 jms 343: 'helpsettings' =>
344: {text => 'Help page settings',
345: help => 'Domain_Configuration_Help_Settings',
1.122 jms 346: header => [{col1 => 'Authenticated Help Settings',
347: col2 => ''},
348: {col1 => 'Unauthenticated Help Settings',
349: col2 => ''}],
1.118 jms 350: },
1.121 raeburn 351: 'coursedefaults' =>
352: {text => 'Course/Community defaults',
353: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 354: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
355: col2 => 'Value',},
356: {col1 => 'Defaults which can be overridden for each course by a DC',
357: col2 => 'Value',},],
1.121 raeburn 358: },
1.120 raeburn 359: 'privacy' =>
360: {text => 'User Privacy',
361: help => 'Domain_Configuration_User_Privacy',
362: header => [{col1 => 'Setting',
363: col2 => 'Value',}],
364: },
1.141 raeburn 365: 'usersessions' =>
1.145 raeburn 366: {text => 'User session hosting/offloading',
1.137 raeburn 367: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 368: header => [{col1 => 'Domain server',
369: col2 => 'Servers to offload sessions to when busy'},
370: {col1 => 'Hosting of users from other domains',
1.137 raeburn 371: col2 => 'Rules'},
372: {col1 => "Hosting domain's own users elsewhere",
373: col2 => 'Rules'}],
374: },
1.150 raeburn 375: 'loadbalancing' =>
376: {text => 'Dedicated Load Balancer',
377: help => 'Domain_Configuration_Load_Balancing',
378: header => [{col1 => 'Server',
379: col2 => 'Default destinations',
380: col3 => 'User affliation',
381: col4 => 'Overrides'},
382: ],
383: },
1.3 raeburn 384: );
1.110 raeburn 385: if (keys(%servers) > 1) {
386: $prefs{'login'} = { text => 'Log-in page options',
387: help => 'Domain_Configuration_Login_Page',
388: header => [{col1 => 'Log-in Service',
389: col2 => 'Server Setting',},
390: {col1 => 'Log-in Page Items',
391: col2 => ''}],
392: };
393: }
1.6 raeburn 394: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 395: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 396: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 397: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 398: text=>"Settings to display/modify"});
1.9 raeburn 399: my $confname = $dom.'-domainconfig';
1.3 raeburn 400: if ($phase eq 'process') {
1.91 raeburn 401: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 402: } elsif ($phase eq 'display') {
1.152 raeburn 403: my $js;
404: if (keys(%servers) > 1) {
405: my ($othertitle,$usertypes,$types) =
406: &Apache::loncommon::sorted_inst_types($dom);
407: $js = &lonbalance_targets_js($dom,$types,\%servers).
408: &new_spares_js().
1.153 raeburn 409: &common_domprefs_js().
410: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 411: }
1.150 raeburn 412: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 413: } else {
1.21 raeburn 414: if (keys(%domconfig) == 0) {
415: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 416: my @ids=&Apache::lonnet::current_machine_ids();
417: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 418: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 419: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 420: my $custom_img_count = 0;
421: foreach my $img (@loginimages) {
422: if ($designhash{$dom.'.login.'.$img} ne '') {
423: $custom_img_count ++;
424: }
425: }
426: foreach my $role (@roles) {
427: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
428: $custom_img_count ++;
429: }
430: }
431: if ($custom_img_count > 0) {
1.94 raeburn 432: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 433: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 434: $r->print(
435: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
436: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
437: &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 />'.
438: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
439: if ($switch_server) {
1.30 raeburn 440: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 441: }
1.91 raeburn 442: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 443: return OK;
444: }
445: }
446: }
1.91 raeburn 447: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 448: }
449: return OK;
450: }
451:
452: sub process_changes {
1.92 raeburn 453: my ($r,$dom,$confname,$action,$roles,$values) = @_;
454: my %domconfig;
455: if (ref($values) eq 'HASH') {
456: %domconfig = %{$values};
457: }
1.3 raeburn 458: my $output;
459: if ($action eq 'login') {
1.9 raeburn 460: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 461: } elsif ($action eq 'rolecolors') {
1.9 raeburn 462: $output = &modify_rolecolors($r,$dom,$confname,$roles,
463: %domconfig);
1.3 raeburn 464: } elsif ($action eq 'quotas') {
1.86 raeburn 465: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 466: } elsif ($action eq 'autoenroll') {
467: $output = &modify_autoenroll($dom,%domconfig);
468: } elsif ($action eq 'autoupdate') {
469: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 470: } elsif ($action eq 'autocreate') {
471: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 472: } elsif ($action eq 'directorysrch') {
473: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 474: } elsif ($action eq 'usercreation') {
1.28 raeburn 475: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 476: } elsif ($action eq 'usermodification') {
477: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 478: } elsif ($action eq 'contacts') {
479: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 480: } elsif ($action eq 'defaults') {
481: $output = &modify_defaults($dom,$r);
1.46 raeburn 482: } elsif ($action eq 'scantron') {
1.48 raeburn 483: $output = &modify_scantron($r,$dom,$confname,%domconfig);
484: } elsif ($action eq 'coursecategories') {
485: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 486: } elsif ($action eq 'serverstatuses') {
487: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 488: } elsif ($action eq 'requestcourses') {
489: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 490: } elsif ($action eq 'helpsettings') {
1.122 jms 491: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 492: } elsif ($action eq 'coursedefaults') {
493: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 494: } elsif ($action eq 'usersessions') {
495: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 496: } elsif ($action eq 'loadbalancing') {
497: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 498: }
499: return $output;
500: }
501:
502: sub print_config_box {
1.9 raeburn 503: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 504: my $rowtotal = 0;
1.49 raeburn 505: my $output;
506: if ($action eq 'coursecategories') {
507: $output = &coursecategories_javascript($settings);
1.91 raeburn 508: }
1.49 raeburn 509: $output .=
1.30 raeburn 510: '<table class="LC_nested_outer">
1.3 raeburn 511: <tr>
1.66 raeburn 512: <th align="left" valign="middle"><span class="LC_nobreak">'.
513: &mt($item->{text}).' '.
514: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
515: '</tr>';
1.30 raeburn 516: $rowtotal ++;
1.110 raeburn 517: my $numheaders = 1;
518: if (ref($item->{'header'}) eq 'ARRAY') {
519: $numheaders = scalar(@{$item->{'header'}});
520: }
521: if ($numheaders > 1) {
1.64 raeburn 522: my $colspan = '';
1.145 raeburn 523: my $rightcolspan = '';
1.122 jms 524: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64 raeburn 525: $colspan = ' colspan="2"';
526: }
1.145 raeburn 527: if ($action eq 'usersessions') {
528: $rightcolspan = ' colspan="3"';
529: }
1.30 raeburn 530: $output .= '
1.3 raeburn 531: <tr>
532: <td>
533: <table class="LC_nested">
534: <tr class="LC_info_row">
1.59 bisitz 535: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 536: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 537: </tr>';
1.69 raeburn 538: $rowtotal ++;
1.6 raeburn 539: if ($action eq 'autoupdate') {
1.30 raeburn 540: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 541: } elsif ($action eq 'usercreation') {
1.33 raeburn 542: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
543: } elsif ($action eq 'usermodification') {
544: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 545: } elsif ($action eq 'coursecategories') {
546: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 547: } elsif ($action eq 'login') {
548: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
549: $colspan = ' colspan="2"';
1.102 raeburn 550: } elsif ($action eq 'requestcourses') {
551: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118 jms 552: } elsif ($action eq 'helpsettings') {
1.122 jms 553: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 554: } elsif ($action eq 'usersessions') {
555: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 556: } elsif ($action eq 'rolecolors') {
1.30 raeburn 557: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 558: } elsif ($action eq 'coursedefaults') {
559: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 560: }
1.30 raeburn 561: $output .= '
1.6 raeburn 562: </table>
563: </td>
564: </tr>
565: <tr>
566: <td>
567: <table class="LC_nested">
568: <tr class="LC_info_row">
1.59 bisitz 569: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 570: $output .= '
1.59 bisitz 571: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 572: </tr>';
573: $rowtotal ++;
1.6 raeburn 574: if ($action eq 'autoupdate') {
1.131 raeburn 575: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
576: </table>
577: </td>
578: </tr>
579: <tr>
580: <td>
581: <table class="LC_nested">
582: <tr class="LC_info_row">
583: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
584: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
585: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
586: $rowtotal ++;
1.28 raeburn 587: } elsif ($action eq 'usercreation') {
1.34 raeburn 588: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
589: </table>
590: </td>
591: </tr>
592: <tr>
593: <td>
594: <table class="LC_nested">
595: <tr class="LC_info_row">
1.59 bisitz 596: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
597: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 598: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
599: $rowtotal ++;
1.33 raeburn 600: } elsif ($action eq 'usermodification') {
1.63 raeburn 601: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
602: </table>
603: </td>
604: </tr>
605: <tr>
606: <td>
607: <table class="LC_nested">
608: <tr class="LC_info_row">
609: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
610: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
611: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
612: $rowtotal ++;
1.57 raeburn 613: } elsif ($action eq 'coursecategories') {
614: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 615: } elsif ($action eq 'login') {
616: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 617: } elsif ($action eq 'requestcourses') {
618: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122 jms 619: } elsif ($action eq 'helpsettings') {
620: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 621: } elsif ($action eq 'usersessions') {
1.145 raeburn 622: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
623: </table>
624: </td>
625: </tr>
626: <tr>
627: <td>
628: <table class="LC_nested">
629: <tr class="LC_info_row">
630: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
631: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
632: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
633: $rowtotal ++;
1.139 raeburn 634: } elsif ($action eq 'coursedefaults') {
635: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 636: } elsif ($action eq 'rolecolors') {
1.30 raeburn 637: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 638: </table>
639: </td>
640: </tr>
641: <tr>
642: <td>
643: <table class="LC_nested">
644: <tr class="LC_info_row">
1.69 raeburn 645: <td class="LC_left_item"'.$colspan.' valign="top">'.
646: &mt($item->{'header'}->[2]->{'col1'}).'</td>
647: <td class="LC_right_item" valign="top">'.
648: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 649: </tr>'.
1.30 raeburn 650: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 651: </table>
652: </td>
653: </tr>
654: <tr>
655: <td>
656: <table class="LC_nested">
657: <tr class="LC_info_row">
1.59 bisitz 658: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
659: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 660: </tr>'.
1.30 raeburn 661: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
662: $rowtotal += 2;
1.6 raeburn 663: }
1.3 raeburn 664: } else {
1.30 raeburn 665: $output .= '
1.3 raeburn 666: <tr>
667: <td>
668: <table class="LC_nested">
1.30 raeburn 669: <tr class="LC_info_row">';
1.24 raeburn 670: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 671: $output .= '
1.59 bisitz 672: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 673: } elsif ($action eq 'serverstatuses') {
674: $output .= '
675: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
676: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
677:
1.6 raeburn 678: } else {
1.30 raeburn 679: $output .= '
1.69 raeburn 680: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
681: }
1.72 raeburn 682: if (defined($item->{'header'}->[0]->{'col3'})) {
683: $output .= '<td class="LC_left_item" valign="top">'.
684: &mt($item->{'header'}->[0]->{'col2'});
685: if ($action eq 'serverstatuses') {
686: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
687: }
1.69 raeburn 688: } else {
689: $output .= '<td class="LC_right_item" valign="top">'.
690: &mt($item->{'header'}->[0]->{'col2'});
691: }
692: $output .= '</td>';
693: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 694: if (defined($item->{'header'}->[0]->{'col4'})) {
695: $output .= '<td class="LC_left_item" valign="top">'.
696: &mt($item->{'header'}->[0]->{'col3'});
697: } else {
698: $output .= '<td class="LC_right_item" valign="top">'.
699: &mt($item->{'header'}->[0]->{'col3'});
700: }
1.69 raeburn 701: if ($action eq 'serverstatuses') {
702: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
703: }
704: $output .= '</td>';
1.6 raeburn 705: }
1.150 raeburn 706: if ($item->{'header'}->[0]->{'col4'}) {
707: $output .= '<td class="LC_right_item" valign="top">'.
708: &mt($item->{'header'}->[0]->{'col4'});
709: }
1.69 raeburn 710: $output .= '</tr>';
1.48 raeburn 711: $rowtotal ++;
1.3 raeburn 712: if ($action eq 'login') {
1.110 raeburn 713: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
714: \$rowtotal);
1.3 raeburn 715: } elsif ($action eq 'quotas') {
1.86 raeburn 716: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 717: } elsif ($action eq 'autoenroll') {
1.30 raeburn 718: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 719: } elsif ($action eq 'autocreate') {
720: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 721: } elsif ($action eq 'directorysrch') {
1.30 raeburn 722: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 723: } elsif ($action eq 'contacts') {
1.30 raeburn 724: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 725: } elsif ($action eq 'defaults') {
726: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 727: } elsif ($action eq 'scantron') {
728: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 729: } elsif ($action eq 'serverstatuses') {
730: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 731: } elsif ($action eq 'helpsettings') {
1.122 jms 732: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150 raeburn 733: } elsif ($action eq 'loadbalancing') {
734: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 735: }
1.3 raeburn 736: }
1.30 raeburn 737: $output .= '
1.3 raeburn 738: </table>
739: </td>
740: </tr>
1.30 raeburn 741: </table><br />';
742: return ($output,$rowtotal);
1.1 raeburn 743: }
744:
1.3 raeburn 745: sub print_login {
1.110 raeburn 746: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
747: my ($css_class,$datatable);
1.6 raeburn 748: my %choices = &login_choices();
1.110 raeburn 749:
750: if ($position eq 'top') {
1.149 raeburn 751: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 752: my $choice = $choices{'disallowlogin'};
753: $css_class = ' class="LC_odd_row"';
1.128 raeburn 754: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 755: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 756: '<th>'.$choices{'server'}.'</th>'.
757: '<th>'.$choices{'serverpath'}.'</th>'.
758: '<th>'.$choices{'custompath'}.'</th>'.
759: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 760: my %disallowed;
761: if (ref($settings) eq 'HASH') {
762: if (ref($settings->{'loginvia'}) eq 'HASH') {
763: %disallowed = %{$settings->{'loginvia'}};
764: }
765: }
766: foreach my $lonhost (sort(keys(%servers))) {
767: my $direct = 'selected="selected"';
1.128 raeburn 768: if (ref($disallowed{$lonhost}) eq 'HASH') {
769: if ($disallowed{$lonhost}{'server'} ne '') {
770: $direct = '';
771: }
1.110 raeburn 772: }
1.115 raeburn 773: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 774: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 775: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
776: '</option>';
777: foreach my $hostid (keys(%servers)) {
1.115 raeburn 778: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 779: my $selected = '';
1.128 raeburn 780: if (ref($disallowed{$lonhost}) eq 'HASH') {
781: if ($hostid eq $disallowed{$lonhost}{'server'}) {
782: $selected = 'selected="selected"';
783: }
1.110 raeburn 784: }
785: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
786: $servers{$hostid}.'</option>';
787: }
1.128 raeburn 788: $datatable .= '</select></td>'.
789: '<td><select name="'.$lonhost.'_serverpath">';
790: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
791: my $pathname = $path;
792: if ($path eq 'custom') {
793: $pathname = &mt('Custom Path').' ->';
794: }
795: my $selected = '';
796: if (ref($disallowed{$lonhost}) eq 'HASH') {
797: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
798: $selected = 'selected="selected"';
799: }
800: } elsif ($path eq '') {
801: $selected = 'selected="selected"';
802: }
803: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
804: }
805: $datatable .= '</select></td>';
806: my ($custom,$exempt);
807: if (ref($disallowed{$lonhost}) eq 'HASH') {
808: $custom = $disallowed{$lonhost}{'custompath'};
809: $exempt = $disallowed{$lonhost}{'exempt'};
810: }
811: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
812: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
813: '</tr>';
1.110 raeburn 814: }
815: $datatable .= '</table></td></tr>';
816: return $datatable;
817: }
818:
1.42 raeburn 819: my %defaultchecked = (
1.43 raeburn 820: 'coursecatalog' => 'on',
821: 'adminmail' => 'off',
822: 'newuser' => 'off',
823: );
1.118 jms 824: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 825: my (%checkedon,%checkedoff);
826: foreach my $item (@toggles) {
827: if ($defaultchecked{$item} eq 'on') {
828: $checkedon{$item} = ' checked="checked" ';
829: $checkedoff{$item} = ' ';
830: } elsif ($defaultchecked{$item} eq 'off') {
831: $checkedoff{$item} = ' checked="checked" ';
832: $checkedon{$item} = ' ';
833: }
834: }
1.41 raeburn 835: my @images = ('img','logo','domlogo','login');
836: my @logintext = ('textcol','bgcol');
1.6 raeburn 837: my @bgs = ('pgbg','mainbg','sidebg');
838: my @links = ('link','alink','vlink');
1.7 albertel 839: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 840: my %defaultdesign = %Apache::loncommon::defaultdesign;
841: my (%is_custom,%designs);
842: my %defaults = (
843: font => $defaultdesign{'login.font'},
844: );
845: foreach my $item (@images) {
846: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 847: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 848: }
849: foreach my $item (@bgs) {
850: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
851: }
1.41 raeburn 852: foreach my $item (@logintext) {
853: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
854: }
1.6 raeburn 855: foreach my $item (@links) {
856: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
857: }
1.3 raeburn 858: if (ref($settings) eq 'HASH') {
1.42 raeburn 859: foreach my $item (@toggles) {
860: if ($settings->{$item} eq '1') {
861: $checkedon{$item} = ' checked="checked" ';
862: $checkedoff{$item} = ' ';
863: } elsif ($settings->{$item} eq '0') {
864: $checkedoff{$item} = ' checked="checked" ';
865: $checkedon{$item} = ' ';
866: }
1.1 raeburn 867: }
1.6 raeburn 868: foreach my $item (@images) {
1.70 raeburn 869: if (defined($settings->{$item})) {
1.6 raeburn 870: $designs{$item} = $settings->{$item};
871: $is_custom{$item} = 1;
872: }
1.70 raeburn 873: if (defined($settings->{'showlogo'}{$item})) {
874: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
875: }
1.6 raeburn 876: }
1.41 raeburn 877: foreach my $item (@logintext) {
878: if ($settings->{$item} ne '') {
879: $designs{'logintext'}{$item} = $settings->{$item};
880: $is_custom{$item} = 1;
881: }
882: }
1.6 raeburn 883: if ($settings->{'font'} ne '') {
884: $designs{'font'} = $settings->{'font'};
885: $is_custom{'font'} = 1;
886: }
887: foreach my $item (@bgs) {
888: if ($settings->{$item} ne '') {
889: $designs{'bgs'}{$item} = $settings->{$item};
890: $is_custom{$item} = 1;
891: }
892: }
893: foreach my $item (@links) {
894: if ($settings->{$item} ne '') {
895: $designs{'links'}{$item} = $settings->{$item};
896: $is_custom{$item} = 1;
897: }
898: }
899: } else {
900: if ($designhash{$dom.'.login.font'} ne '') {
901: $designs{'font'} = $designhash{$dom.'.login.font'};
902: $is_custom{'font'} = 1;
903: }
1.8 raeburn 904: foreach my $item (@images) {
905: if ($designhash{$dom.'.login.'.$item} ne '') {
906: $designs{$item} = $designhash{$dom.'.login.'.$item};
907: $is_custom{$item} = 1;
908: }
909: }
1.6 raeburn 910: foreach my $item (@bgs) {
911: if ($designhash{$dom.'.login.'.$item} ne '') {
912: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
913: $is_custom{$item} = 1;
914: }
915: }
916: foreach my $item (@links) {
917: if ($designhash{$dom.'.login.'.$item} ne '') {
918: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
919: $is_custom{$item} = 1;
920: }
921: }
1.1 raeburn 922: }
1.6 raeburn 923: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
924: logo => 'Institution Logo',
1.41 raeburn 925: domlogo => 'Domain Logo',
926: login => 'Login box');
1.6 raeburn 927: my $itemcount = 1;
1.42 raeburn 928: foreach my $item (@toggles) {
929: $css_class = $itemcount%2?' class="LC_odd_row"':'';
930: $datatable .=
931: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
932: '</td><td>'.
933: '<span class="LC_nobreak"><label><input type="radio" name="'.
934: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
935: '</label> <label><input type="radio" name="'.$item.'"'.
936: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
937: '</tr>';
938: $itemcount ++;
939: }
1.135 bisitz 940: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 941: $datatable .= '</tr></table></td></tr>';
942: return $datatable;
943: }
944:
945: sub login_choices {
946: my %choices =
947: &Apache::lonlocal::texthash (
1.116 bisitz 948: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 949: adminmail => "Display Administrator's E-mail Address?",
950: disallowlogin => "Login page requests redirected",
951: hostid => "Server",
1.128 raeburn 952: server => "Redirect to:",
953: serverpath => "Path",
954: custompath => "Custom",
955: exempt => "Exempt IP(s)",
1.110 raeburn 956: directlogin => "No redirect",
957: newuser => "Link to create a user account",
958: img => "Header",
959: logo => "Main Logo",
960: domlogo => "Domain Logo",
961: login => "Log-in Header",
962: textcol => "Text color",
963: bgcol => "Box color",
964: bgs => "Background colors",
965: links => "Link colors",
966: font => "Font color",
967: pgbg => "Header",
968: mainbg => "Page",
969: sidebg => "Login box",
970: link => "Link",
971: alink => "Active link",
972: vlink => "Visited link",
1.6 raeburn 973: );
974: return %choices;
975: }
976:
977: sub print_rolecolors {
1.30 raeburn 978: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 979: my %choices = &color_font_choices();
980: my @bgs = ('pgbg','tabbg','sidebg');
981: my @links = ('link','alink','vlink');
982: my @images = ('img');
983: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 984: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 985: my %defaultdesign = %Apache::loncommon::defaultdesign;
986: my (%is_custom,%designs);
987: my %defaults = (
988: img => $defaultdesign{$role.'.img'},
989: font => $defaultdesign{$role.'.font'},
1.97 tempelho 990: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 991: );
992: foreach my $item (@bgs) {
993: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
994: }
995: foreach my $item (@links) {
996: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
997: }
998: if (ref($settings) eq 'HASH') {
999: if (ref($settings->{$role}) eq 'HASH') {
1000: if ($settings->{$role}->{'img'} ne '') {
1001: $designs{'img'} = $settings->{$role}->{'img'};
1002: $is_custom{'img'} = 1;
1003: }
1004: if ($settings->{$role}->{'font'} ne '') {
1005: $designs{'font'} = $settings->{$role}->{'font'};
1006: $is_custom{'font'} = 1;
1007: }
1.97 tempelho 1008: if ($settings->{$role}->{'fontmenu'} ne '') {
1009: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1010: $is_custom{'fontmenu'} = 1;
1011: }
1.6 raeburn 1012: foreach my $item (@bgs) {
1013: if ($settings->{$role}->{$item} ne '') {
1014: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1015: $is_custom{$item} = 1;
1016: }
1017: }
1018: foreach my $item (@links) {
1019: if ($settings->{$role}->{$item} ne '') {
1020: $designs{'links'}{$item} = $settings->{$role}->{$item};
1021: $is_custom{$item} = 1;
1022: }
1023: }
1024: }
1025: } else {
1026: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1027: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1028: $is_custom{'img'} = 1;
1029: }
1.97 tempelho 1030: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1031: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1032: $is_custom{'fontmenu'} = 1;
1033: }
1.6 raeburn 1034: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1035: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1036: $is_custom{'font'} = 1;
1037: }
1038: foreach my $item (@bgs) {
1039: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1040: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1041: $is_custom{$item} = 1;
1042:
1043: }
1044: }
1045: foreach my $item (@links) {
1046: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1047: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1048: $is_custom{$item} = 1;
1049: }
1050: }
1051: }
1052: my $itemcount = 1;
1.30 raeburn 1053: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1054: $datatable .= '</tr></table></td></tr>';
1055: return $datatable;
1056: }
1057:
1058: sub display_color_options {
1.9 raeburn 1059: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1060: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1061: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1062: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1063: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1064: '<td>'.$choices->{'font'}.'</td>';
1065: if (!$is_custom->{'font'}) {
1.30 raeburn 1066: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1067: } else {
1068: $datatable .= '<td> </td>';
1069: }
1070: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1071: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1072: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1073: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1074: ' <span id="css_'.$role.'_font" style="background-color: '.
1075: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1076: '</span></td></tr>';
1.107 raeburn 1077: unless ($role eq 'login') {
1078: $datatable .= '<tr'.$css_class.'>'.
1079: '<td>'.$choices->{'fontmenu'}.'</td>';
1080: if (!$is_custom->{'fontmenu'}) {
1081: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1082: } else {
1083: $datatable .= '<td> </td>';
1084: }
1085: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1086: $datatable .= '<td><span class="LC_nobreak">'.
1087: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1088: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1089: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1090: $designs->{'fontmenu'}.';"> </span>'.
1091: '</span></td></tr>';
1.97 tempelho 1092: }
1.9 raeburn 1093: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1094: foreach my $img (@{$images}) {
1.18 albertel 1095: $itemcount ++;
1.6 raeburn 1096: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1097: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1098: '<td>'.$choices->{$img};
1.41 raeburn 1099: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1100: if ($role eq 'login') {
1101: if ($img eq 'login') {
1102: $login_hdr_pick =
1.135 bisitz 1103: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1104: $logincolors =
1105: &login_text_colors($img,$role,$logintext,$phase,$choices,
1106: $designs);
1107: } elsif ($img ne 'domlogo') {
1108: $datatable.= &logo_display_options($img,$defaults,$designs);
1109: }
1110: }
1111: $datatable .= '</td>';
1.6 raeburn 1112: if ($designs->{$img} ne '') {
1113: $imgfile = $designs->{$img};
1.18 albertel 1114: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1115: } else {
1116: $imgfile = $defaults->{$img};
1117: }
1118: if ($imgfile) {
1.9 raeburn 1119: my ($showfile,$fullsize);
1120: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1121: my $urldir = $1;
1122: my $filename = $2;
1123: my @info = &Apache::lonnet::stat_file($designs->{$img});
1124: if (@info) {
1125: my $thumbfile = 'tn-'.$filename;
1126: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1127: if (@thumb) {
1128: $showfile = $urldir.'/'.$thumbfile;
1129: } else {
1130: $showfile = $imgfile;
1131: }
1132: } else {
1133: $showfile = '';
1134: }
1135: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1136: $showfile = $imgfile;
1.6 raeburn 1137: my $imgdir = $1;
1138: my $filename = $2;
1.159 raeburn 1139: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1140: $showfile = "/$imgdir/tn-".$filename;
1141: } else {
1.159 raeburn 1142: my $input = $londocroot.$imgfile;
1143: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1144: if (!-e $output) {
1.9 raeburn 1145: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1146: my ($fullwidth,$fullheight) = &check_dimensions($input);
1147: if ($fullwidth ne '' && $fullheight ne '') {
1148: if ($fullwidth > $width && $fullheight > $height) {
1149: my $size = $width.'x'.$height;
1150: system("convert -sample $size $input $output");
1.159 raeburn 1151: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1152: }
1153: }
1.6 raeburn 1154: }
1155: }
1.16 raeburn 1156: }
1.6 raeburn 1157: if ($showfile) {
1.40 raeburn 1158: if ($showfile =~ m{^/(adm|res)/}) {
1159: if ($showfile =~ m{^/res/}) {
1160: my $local_showfile =
1161: &Apache::lonnet::filelocation('',$showfile);
1162: &Apache::lonnet::repcopy($local_showfile);
1163: }
1164: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1165: }
1166: if ($imgfile) {
1167: if ($imgfile =~ m{^/(adm|res)/}) {
1168: if ($imgfile =~ m{^/res/}) {
1169: my $local_imgfile =
1170: &Apache::lonnet::filelocation('',$imgfile);
1171: &Apache::lonnet::repcopy($local_imgfile);
1172: }
1173: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1174: } else {
1175: $fullsize = $imgfile;
1176: }
1177: }
1.41 raeburn 1178: $datatable .= '<td>';
1179: if ($img eq 'login') {
1.135 bisitz 1180: $datatable .= $login_hdr_pick;
1181: }
1.41 raeburn 1182: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1183: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1184: } else {
1185: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1186: &mt('Upload:');
1187: }
1188: } else {
1189: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1190: &mt('Upload:');
1191: }
1.9 raeburn 1192: if ($switchserver) {
1193: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1194: } else {
1.135 bisitz 1195: if ($img ne 'login') { # suppress file selection for Log-in header
1196: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1197: }
1.9 raeburn 1198: }
1199: $datatable .= '</td></tr>';
1.6 raeburn 1200: }
1201: $itemcount ++;
1202: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1203: $datatable .= '<tr'.$css_class.'>'.
1204: '<td>'.$choices->{'bgs'}.'</td>';
1205: my $bgs_def;
1206: foreach my $item (@{$bgs}) {
1207: if (!$is_custom->{$item}) {
1.70 raeburn 1208: $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 1209: }
1210: }
1211: if ($bgs_def) {
1.8 raeburn 1212: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1213: } else {
1214: $datatable .= '<td> </td>';
1215: }
1216: $datatable .= '<td class="LC_right_item">'.
1217: '<table border="0"><tr>';
1218: foreach my $item (@{$bgs}) {
1219: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1220: $datatable .= '<td align="center">'.$link;
1221: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1222: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1223: }
1224: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1225: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1226: }
1227: $datatable .= '</tr></table></td></tr>';
1228: $itemcount ++;
1229: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1230: $datatable .= '<tr'.$css_class.'>'.
1231: '<td>'.$choices->{'links'}.'</td>';
1232: my $links_def;
1233: foreach my $item (@{$links}) {
1234: if (!$is_custom->{$item}) {
1.30 raeburn 1235: $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 1236: }
1237: }
1238: if ($links_def) {
1.8 raeburn 1239: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1240: } else {
1241: $datatable .= '<td> </td>';
1242: }
1243: $datatable .= '<td class="LC_right_item">'.
1244: '<table border="0"><tr>';
1245: foreach my $item (@{$links}) {
1.30 raeburn 1246: $datatable .= '<td align="center">'."\n".
1247: &color_pick($phase,$role,$item,$choices->{$item},
1248: $designs->{'links'}{$item});
1.6 raeburn 1249: if ($designs->{'links'}{$item}) {
1.30 raeburn 1250: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1251: }
1252: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1253: '" /></td>';
1254: }
1.30 raeburn 1255: $$rowtotal += $itemcount;
1.3 raeburn 1256: return $datatable;
1257: }
1258:
1.70 raeburn 1259: sub logo_display_options {
1260: my ($img,$defaults,$designs) = @_;
1261: my $checkedon;
1262: if (ref($defaults) eq 'HASH') {
1263: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1264: if ($defaults->{'showlogo'}{$img}) {
1265: $checkedon = 'checked="checked" ';
1266: }
1267: }
1268: }
1269: if (ref($designs) eq 'HASH') {
1270: if (ref($designs->{'showlogo'}) eq 'HASH') {
1271: if (defined($designs->{'showlogo'}{$img})) {
1272: if ($designs->{'showlogo'}{$img} == 0) {
1273: $checkedon = '';
1274: } elsif ($designs->{'showlogo'}{$img} == 1) {
1275: $checkedon = 'checked="checked" ';
1276: }
1277: }
1278: }
1279: }
1280: return '<br /><label> <input type="checkbox" name="'.
1281: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1282: &mt('show').'</label>'."\n";
1283: }
1284:
1.41 raeburn 1285: sub login_header_options {
1.135 bisitz 1286: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1287: my $output = '';
1.41 raeburn 1288: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1289: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1290: if (!$is_custom->{'textcol'}) {
1291: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1292: ' ';
1293: }
1294: if (!$is_custom->{'bgcol'}) {
1295: $output .= $choices->{'bgcol'}.': '.
1296: '<span id="css_'.$role.'_font" style="background-color: '.
1297: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1298: }
1299: $output .= '<br />';
1300: }
1301: $output .='<br />';
1302: return $output;
1303: }
1304:
1305: sub login_text_colors {
1306: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1307: my $color_menu = '<table border="0"><tr>';
1308: foreach my $item (@{$logintext}) {
1309: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1310: $color_menu .= '<td align="center">'.$link;
1311: if ($designs->{'logintext'}{$item}) {
1312: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1313: }
1314: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1315: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1316: '<td> </td>';
1317: }
1318: $color_menu .= '</tr></table><br />';
1319: return $color_menu;
1320: }
1321:
1322: sub image_changes {
1323: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1324: my $output;
1.135 bisitz 1325: if ($img eq 'login') {
1326: # suppress image for Log-in header
1327: } elsif (!$is_custom) {
1.70 raeburn 1328: if ($img ne 'domlogo') {
1.41 raeburn 1329: $output .= &mt('Default image:').'<br />';
1330: } else {
1331: $output .= &mt('Default in use:').'<br />';
1332: }
1333: }
1.135 bisitz 1334: if ($img eq 'login') { # suppress image for Log-in header
1335: $output .= '<td>'.$logincolors;
1.41 raeburn 1336: } else {
1.135 bisitz 1337: if ($img_import) {
1338: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1339: }
1340: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1341: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1342: if ($is_custom) {
1343: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1344: '<input type="checkbox" name="'.
1345: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1346: '</label> '.&mt('Replace:').'</span><br />';
1347: } else {
1348: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1349: }
1.41 raeburn 1350: }
1351: return $output;
1352: }
1353:
1.6 raeburn 1354: sub color_pick {
1355: my ($phase,$role,$item,$desc,$curcol) = @_;
1356: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1357: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1358: ');">'.$desc.'</a>';
1359: return $link;
1360: }
1361:
1.3 raeburn 1362: sub print_quotas {
1.86 raeburn 1363: my ($dom,$settings,$rowtotal,$action) = @_;
1364: my $context;
1365: if ($action eq 'quotas') {
1366: $context = 'tools';
1367: } else {
1368: $context = $action;
1369: }
1.101 raeburn 1370: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1371: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1372: my $typecount = 0;
1.101 raeburn 1373: my ($css_class,%titles);
1.86 raeburn 1374: if ($context eq 'requestcourses') {
1.98 raeburn 1375: @usertools = ('official','unofficial','community');
1.106 raeburn 1376: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1377: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1378: %titles = &courserequest_titles();
1.86 raeburn 1379: } else {
1380: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1381: %titles = &tool_titles();
1.86 raeburn 1382: }
1.26 raeburn 1383: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1384: foreach my $type (@{$types}) {
1.72 raeburn 1385: my $currdefquota;
1.86 raeburn 1386: unless ($context eq 'requestcourses') {
1387: if (ref($settings) eq 'HASH') {
1388: if (ref($settings->{defaultquota}) eq 'HASH') {
1389: $currdefquota = $settings->{defaultquota}->{$type};
1390: } else {
1391: $currdefquota = $settings->{$type};
1392: }
1.78 raeburn 1393: }
1.72 raeburn 1394: }
1.3 raeburn 1395: if (defined($usertypes->{$type})) {
1396: $typecount ++;
1397: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1398: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1399: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1400: '<td class="LC_left_item">';
1.101 raeburn 1401: if ($context eq 'requestcourses') {
1402: $datatable .= '<table><tr>';
1403: }
1404: my %cell;
1.72 raeburn 1405: foreach my $item (@usertools) {
1.101 raeburn 1406: if ($context eq 'requestcourses') {
1407: my ($curroption,$currlimit);
1408: if (ref($settings) eq 'HASH') {
1409: if (ref($settings->{$item}) eq 'HASH') {
1410: $curroption = $settings->{$item}->{$type};
1411: if ($curroption =~ /^autolimit=(\d*)$/) {
1412: $currlimit = $1;
1413: }
1414: }
1415: }
1416: if (!$curroption) {
1417: $curroption = 'norequest';
1418: }
1419: $datatable .= '<th>'.$titles{$item}.'</th>';
1420: foreach my $option (@options) {
1421: my $val = $option;
1422: if ($option eq 'norequest') {
1423: $val = 0;
1424: }
1425: if ($option eq 'validate') {
1426: my $canvalidate = 0;
1427: if (ref($validations{$item}) eq 'HASH') {
1428: if ($validations{$item}{$type}) {
1429: $canvalidate = 1;
1430: }
1431: }
1432: next if (!$canvalidate);
1433: }
1434: my $checked = '';
1435: if ($option eq $curroption) {
1436: $checked = ' checked="checked"';
1437: } elsif ($option eq 'autolimit') {
1438: if ($curroption =~ /^autolimit/) {
1439: $checked = ' checked="checked"';
1440: }
1441: }
1442: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1443: '<input type="radio" name="crsreq_'.$item.
1444: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1445: $titles{$option}.'</label>';
1.101 raeburn 1446: if ($option eq 'autolimit') {
1.127 raeburn 1447: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1448: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1449: 'value="'.$currlimit.'" />';
1.101 raeburn 1450: }
1.127 raeburn 1451: $cell{$item} .= '</span> ';
1.103 raeburn 1452: if ($option eq 'autolimit') {
1.127 raeburn 1453: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1454: }
1.101 raeburn 1455: }
1456: } else {
1457: my $checked = 'checked="checked" ';
1458: if (ref($settings) eq 'HASH') {
1459: if (ref($settings->{$item}) eq 'HASH') {
1460: if ($settings->{$item}->{$type} == 0) {
1461: $checked = '';
1462: } elsif ($settings->{$item}->{$type} == 1) {
1463: $checked = 'checked="checked" ';
1464: }
1.78 raeburn 1465: }
1.72 raeburn 1466: }
1.101 raeburn 1467: $datatable .= '<span class="LC_nobreak"><label>'.
1468: '<input type="checkbox" name="'.$context.'_'.$item.
1469: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1470: '</label></span> ';
1.72 raeburn 1471: }
1.101 raeburn 1472: }
1473: if ($context eq 'requestcourses') {
1474: $datatable .= '</tr><tr>';
1475: foreach my $item (@usertools) {
1.106 raeburn 1476: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1477: }
1478: $datatable .= '</tr></table>';
1.72 raeburn 1479: }
1.86 raeburn 1480: $datatable .= '</td>';
1481: unless ($context eq 'requestcourses') {
1482: $datatable .=
1483: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1484: '<input type="text" name="quota_'.$type.
1.72 raeburn 1485: '" value="'.$currdefquota.
1.86 raeburn 1486: '" size="5" /> Mb</span></td>';
1487: }
1488: $datatable .= '</tr>';
1.3 raeburn 1489: }
1490: }
1491: }
1.86 raeburn 1492: unless ($context eq 'requestcourses') {
1493: $defaultquota = '20';
1494: if (ref($settings) eq 'HASH') {
1495: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1496: $defaultquota = $settings->{'defaultquota'}->{'default'};
1497: } elsif (defined($settings->{'default'})) {
1498: $defaultquota = $settings->{'default'};
1499: }
1.3 raeburn 1500: }
1501: }
1502: $typecount ++;
1503: $css_class = $typecount%2?' class="LC_odd_row"':'';
1504: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1505: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1506: '<td class="LC_left_item">';
1.101 raeburn 1507: if ($context eq 'requestcourses') {
1508: $datatable .= '<table><tr>';
1509: }
1510: my %defcell;
1.72 raeburn 1511: foreach my $item (@usertools) {
1.101 raeburn 1512: if ($context eq 'requestcourses') {
1513: my ($curroption,$currlimit);
1514: if (ref($settings) eq 'HASH') {
1515: if (ref($settings->{$item}) eq 'HASH') {
1516: $curroption = $settings->{$item}->{'default'};
1517: if ($curroption =~ /^autolimit=(\d*)$/) {
1518: $currlimit = $1;
1519: }
1520: }
1521: }
1522: if (!$curroption) {
1523: $curroption = 'norequest';
1524: }
1525: $datatable .= '<th>'.$titles{$item}.'</th>';
1526: foreach my $option (@options) {
1527: my $val = $option;
1528: if ($option eq 'norequest') {
1529: $val = 0;
1530: }
1531: if ($option eq 'validate') {
1532: my $canvalidate = 0;
1533: if (ref($validations{$item}) eq 'HASH') {
1534: if ($validations{$item}{'default'}) {
1535: $canvalidate = 1;
1536: }
1537: }
1538: next if (!$canvalidate);
1539: }
1540: my $checked = '';
1541: if ($option eq $curroption) {
1542: $checked = ' checked="checked"';
1543: } elsif ($option eq 'autolimit') {
1544: if ($curroption =~ /^autolimit/) {
1545: $checked = ' checked="checked"';
1546: }
1547: }
1548: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1549: '<input type="radio" name="crsreq_'.$item.
1550: '_default" value="'.$val.'"'.$checked.' />'.
1551: $titles{$option}.'</label>';
1552: if ($option eq 'autolimit') {
1.127 raeburn 1553: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1554: $item.'_limit_default" size="1" '.
1555: 'value="'.$currlimit.'" />';
1556: }
1.127 raeburn 1557: $defcell{$item} .= '</span> ';
1.104 raeburn 1558: if ($option eq 'autolimit') {
1.127 raeburn 1559: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1560: }
1.101 raeburn 1561: }
1562: } else {
1563: my $checked = 'checked="checked" ';
1564: if (ref($settings) eq 'HASH') {
1565: if (ref($settings->{$item}) eq 'HASH') {
1566: if ($settings->{$item}->{'default'} == 0) {
1567: $checked = '';
1568: } elsif ($settings->{$item}->{'default'} == 1) {
1569: $checked = 'checked="checked" ';
1570: }
1.78 raeburn 1571: }
1.72 raeburn 1572: }
1.101 raeburn 1573: $datatable .= '<span class="LC_nobreak"><label>'.
1574: '<input type="checkbox" name="'.$context.'_'.$item.
1575: '" value="default" '.$checked.'/>'.$titles{$item}.
1576: '</label></span> ';
1577: }
1578: }
1579: if ($context eq 'requestcourses') {
1580: $datatable .= '</tr><tr>';
1581: foreach my $item (@usertools) {
1.106 raeburn 1582: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1583: }
1.101 raeburn 1584: $datatable .= '</tr></table>';
1.72 raeburn 1585: }
1.86 raeburn 1586: $datatable .= '</td>';
1587: unless ($context eq 'requestcourses') {
1588: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1589: '<input type="text" name="defaultquota" value="'.
1590: $defaultquota.'" size="5" /> Mb</span></td>';
1591: }
1592: $datatable .= '</tr>';
1.72 raeburn 1593: $typecount ++;
1594: $css_class = $typecount%2?' class="LC_odd_row"':'';
1595: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1596: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1597: if ($context eq 'requestcourses') {
1.109 raeburn 1598: $datatable .= &mt('(overrides affiliation, if set)').
1599: '</td>'.
1600: '<td class="LC_left_item">'.
1601: '<table><tr>';
1.101 raeburn 1602: } else {
1.109 raeburn 1603: $datatable .= &mt('(overrides affiliation, if checked)').
1604: '</td>'.
1605: '<td class="LC_left_item" colspan="2">'.
1606: '<br />';
1.101 raeburn 1607: }
1608: my %advcell;
1.72 raeburn 1609: foreach my $item (@usertools) {
1.101 raeburn 1610: if ($context eq 'requestcourses') {
1611: my ($curroption,$currlimit);
1612: if (ref($settings) eq 'HASH') {
1613: if (ref($settings->{$item}) eq 'HASH') {
1614: $curroption = $settings->{$item}->{'_LC_adv'};
1615: if ($curroption =~ /^autolimit=(\d*)$/) {
1616: $currlimit = $1;
1617: }
1618: }
1619: }
1620: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1621: my $checked = '';
1622: if ($curroption eq '') {
1623: $checked = ' checked="checked"';
1624: }
1625: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1626: '<input type="radio" name="crsreq_'.$item.
1627: '__LC_adv" value=""'.$checked.' />'.
1628: &mt('No override set').'</label></span> ';
1.101 raeburn 1629: foreach my $option (@options) {
1630: my $val = $option;
1631: if ($option eq 'norequest') {
1632: $val = 0;
1633: }
1634: if ($option eq 'validate') {
1635: my $canvalidate = 0;
1636: if (ref($validations{$item}) eq 'HASH') {
1637: if ($validations{$item}{'_LC_adv'}) {
1638: $canvalidate = 1;
1639: }
1640: }
1641: next if (!$canvalidate);
1642: }
1643: my $checked = '';
1.104 raeburn 1644: if ($val eq $curroption) {
1.101 raeburn 1645: $checked = ' checked="checked"';
1646: } elsif ($option eq 'autolimit') {
1647: if ($curroption =~ /^autolimit/) {
1648: $checked = ' checked="checked"';
1649: }
1650: }
1651: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1652: '<input type="radio" name="crsreq_'.$item.
1653: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1654: $titles{$option}.'</label>';
1655: if ($option eq 'autolimit') {
1.127 raeburn 1656: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1657: $item.'_limit__LC_adv" size="1" '.
1658: 'value="'.$currlimit.'" />';
1659: }
1.127 raeburn 1660: $advcell{$item} .= '</span> ';
1.104 raeburn 1661: if ($option eq 'autolimit') {
1.127 raeburn 1662: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1663: }
1.101 raeburn 1664: }
1665: } else {
1666: my $checked = 'checked="checked" ';
1667: if (ref($settings) eq 'HASH') {
1668: if (ref($settings->{$item}) eq 'HASH') {
1669: if ($settings->{$item}->{'_LC_adv'} == 0) {
1670: $checked = '';
1671: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1672: $checked = 'checked="checked" ';
1673: }
1.79 raeburn 1674: }
1.72 raeburn 1675: }
1.101 raeburn 1676: $datatable .= '<span class="LC_nobreak"><label>'.
1677: '<input type="checkbox" name="'.$context.'_'.$item.
1678: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1679: '</label></span> ';
1680: }
1681: }
1682: if ($context eq 'requestcourses') {
1683: $datatable .= '</tr><tr>';
1684: foreach my $item (@usertools) {
1.106 raeburn 1685: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1686: }
1.101 raeburn 1687: $datatable .= '</tr></table>';
1.72 raeburn 1688: }
1.98 raeburn 1689: $datatable .= '</td></tr>';
1.30 raeburn 1690: $$rowtotal += $typecount;
1.3 raeburn 1691: return $datatable;
1692: }
1693:
1.102 raeburn 1694: sub print_courserequestmail {
1695: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1696: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1697: $now = time;
1698: $rows = 0;
1699: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1700: foreach my $server (keys(%dompersonnel)) {
1701: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1702: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1703: if (!grep(/^$uname:$udom$/,@domcoord)) {
1704: push(@domcoord,$uname.':'.$udom);
1705: }
1706: }
1707: }
1708: if (ref($settings) eq 'HASH') {
1709: if (ref($settings->{'notify'}) eq 'HASH') {
1710: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1711: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1712: }
1713: }
1714: }
1.104 raeburn 1715: if (@currapproval) {
1716: foreach my $dc (@currapproval) {
1.102 raeburn 1717: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1718: push(@domcoord,$dc);
1719: }
1720: }
1721: }
1722: @domcoord = sort(@domcoord);
1723: my $numinrow = 4;
1724: my $numdc = @domcoord;
1725: my $css_class = 'class="LC_odd_row"';
1726: $datatable = '<tr'.$css_class.'>'.
1727: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1728: ' </td>'.
1729: ' <td class="LC_left_item">';
1730: if (@domcoord > 0) {
1731: $datatable .= '<table>';
1732: for (my $i=0; $i<$numdc; $i++) {
1733: my $rem = $i%($numinrow);
1734: if ($rem == 0) {
1735: if ($i > 0) {
1736: $datatable .= '</tr>';
1737: }
1738: $datatable .= '<tr>';
1739: $rows ++;
1740: }
1741: my $check = ' ';
1.104 raeburn 1742: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1743: $check = ' checked="checked" ';
1744: }
1745: my ($uname,$udom) = split(':',$domcoord[$i]);
1746: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1747: if ($i == $numdc-1) {
1748: my $colsleft = $numinrow-$rem;
1749: if ($colsleft > 1) {
1750: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1751: } else {
1752: $datatable .= '<td class="LC_left_item">';
1753: }
1754: } else {
1755: $datatable .= '<td class="LC_left_item">';
1756: }
1757: $datatable .= '<span class="LC_nobreak"><label>'.
1758: '<input type="checkbox" name="reqapprovalnotify" '.
1759: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1760: $fullname.'</label></span></td>';
1761: }
1762: $datatable .= '</tr></table>';
1763: } else {
1764: $datatable .= &mt('There are no active Domain Coordinators');
1765: $rows ++;
1766: }
1767: $datatable .='</td></tr>';
1768: $$rowtotal += $rows;
1769: return $datatable;
1770: }
1771:
1.3 raeburn 1772: sub print_autoenroll {
1.30 raeburn 1773: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1774: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1775: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1776: if (ref($settings) eq 'HASH') {
1777: if (exists($settings->{'run'})) {
1778: if ($settings->{'run'} eq '0') {
1779: $runoff = ' checked="checked" ';
1780: $runon = ' ';
1781: } else {
1782: $runon = ' checked="checked" ';
1783: $runoff = ' ';
1784: }
1785: } else {
1786: if ($autorun) {
1787: $runon = ' checked="checked" ';
1788: $runoff = ' ';
1789: } else {
1790: $runoff = ' checked="checked" ';
1791: $runon = ' ';
1792: }
1793: }
1.129 raeburn 1794: if (exists($settings->{'co-owners'})) {
1795: if ($settings->{'co-owners'} eq '0') {
1796: $coownersoff = ' checked="checked" ';
1797: $coownerson = ' ';
1798: } else {
1799: $coownerson = ' checked="checked" ';
1800: $coownersoff = ' ';
1801: }
1802: } else {
1803: $coownersoff = ' checked="checked" ';
1804: $coownerson = ' ';
1805: }
1.3 raeburn 1806: if (exists($settings->{'sender_domain'})) {
1807: $defdom = $settings->{'sender_domain'};
1808: }
1.14 raeburn 1809: } else {
1810: if ($autorun) {
1811: $runon = ' checked="checked" ';
1812: $runoff = ' ';
1813: } else {
1814: $runoff = ' checked="checked" ';
1815: $runon = ' ';
1816: }
1.3 raeburn 1817: }
1818: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1819: my $notif_sender;
1820: if (ref($settings) eq 'HASH') {
1821: $notif_sender = $settings->{'sender_uname'};
1822: }
1.3 raeburn 1823: my $datatable='<tr class="LC_odd_row">'.
1824: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1825: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1826: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1827: $runon.' value="1" />'.&mt('Yes').'</label> '.
1828: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1829: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1830: '</tr><tr>'.
1831: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1832: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1833: &mt('username').': '.
1834: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1835: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1836: ': '.$domform.'</span></td></tr>'.
1837: '<tr class="LC_odd_row">'.
1838: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1839: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1840: '<input type="radio" name="autoassign_coowners"'.
1841: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1842: '<label><input type="radio" name="autoassign_coowners"'.
1843: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1844: '</tr>';
1845: $$rowtotal += 3;
1.3 raeburn 1846: return $datatable;
1847: }
1848:
1849: sub print_autoupdate {
1.30 raeburn 1850: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1851: my $datatable;
1852: if ($position eq 'top') {
1853: my $updateon = ' ';
1854: my $updateoff = ' checked="checked" ';
1855: my $classlistson = ' ';
1856: my $classlistsoff = ' checked="checked" ';
1857: if (ref($settings) eq 'HASH') {
1858: if ($settings->{'run'} eq '1') {
1859: $updateon = $updateoff;
1860: $updateoff = ' ';
1861: }
1862: if ($settings->{'classlists'} eq '1') {
1863: $classlistson = $classlistsoff;
1864: $classlistsoff = ' ';
1865: }
1866: }
1867: my %title = (
1868: run => 'Auto-update active?',
1869: classlists => 'Update information in classlists?',
1870: );
1871: $datatable = '<tr class="LC_odd_row">'.
1872: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1873: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1874: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1875: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1876: '<label><input type="radio" name="autoupdate_run"'.
1877: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1878: '</tr><tr>'.
1879: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1880: '<td class="LC_right_item"><span class="LC_nobreak">'.
1881: '<label><input type="radio" name="classlists"'.
1882: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1883: '<label><input type="radio" name="classlists"'.
1884: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1885: '</tr>';
1.30 raeburn 1886: $$rowtotal += 2;
1.131 raeburn 1887: } elsif ($position eq 'middle') {
1888: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1889: my $numinrow = 3;
1890: my $locknamesettings;
1891: $datatable .= &insttypes_row($settings,$types,$usertypes,
1892: $dom,$numinrow,$othertitle,
1893: 'lockablenames');
1894: $$rowtotal ++;
1.3 raeburn 1895: } else {
1.44 raeburn 1896: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1897: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1898: 'permanentemail','id');
1.33 raeburn 1899: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1900: my $numrows = 0;
1.26 raeburn 1901: if (ref($types) eq 'ARRAY') {
1902: if (@{$types} > 0) {
1903: $datatable =
1904: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1905: \@fields,$types,\$numrows);
1.30 raeburn 1906: $$rowtotal += @{$types};
1.26 raeburn 1907: }
1.3 raeburn 1908: }
1909: $datatable .=
1910: &usertype_update_row($settings,{'default' => $othertitle},
1911: \%fieldtitles,\@fields,['default'],
1912: \$numrows);
1.30 raeburn 1913: $$rowtotal ++;
1.3 raeburn 1914: }
1915: return $datatable;
1916: }
1917:
1.125 raeburn 1918: sub print_autocreate {
1919: my ($dom,$settings,$rowtotal) = @_;
1920: my (%createon,%createoff);
1921: my $curr_dc;
1922: my @types = ('xml','req');
1923: if (ref($settings) eq 'HASH') {
1924: foreach my $item (@types) {
1925: $createoff{$item} = ' checked="checked" ';
1926: $createon{$item} = ' ';
1927: if (exists($settings->{$item})) {
1928: if ($settings->{$item}) {
1929: $createon{$item} = ' checked="checked" ';
1930: $createoff{$item} = ' ';
1931: }
1932: }
1933: }
1934: $curr_dc = $settings->{'xmldc'};
1935: } else {
1936: foreach my $item (@types) {
1937: $createoff{$item} = ' checked="checked" ';
1938: $createon{$item} = ' ';
1939: }
1940: }
1941: $$rowtotal += 2;
1942: my $datatable='<tr class="LC_odd_row">'.
1943: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1944: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1945: '<input type="radio" name="autocreate_xml"'.
1946: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1947: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 1948: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
1949: '</td></tr><tr>'.
1950: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1951: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1952: '<input type="radio" name="autocreate_req"'.
1953: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1954: '<label><input type="radio" name="autocreate_req"'.
1955: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 1956: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1957: if ($numdc > 1) {
1.143 raeburn 1958: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
1959: &mt('Course creation processed as: (choose Dom. Coord.)').
1960: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 1961: $$rowtotal ++ ;
1962: } else {
1.143 raeburn 1963: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 1964: }
1965: return $datatable;
1966: }
1967:
1.23 raeburn 1968: sub print_directorysrch {
1.30 raeburn 1969: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1970: my $srchon = ' ';
1971: my $srchoff = ' checked="checked" ';
1.25 raeburn 1972: my ($exacton,$containson,$beginson);
1.24 raeburn 1973: my $localon = ' ';
1974: my $localoff = ' checked="checked" ';
1.23 raeburn 1975: if (ref($settings) eq 'HASH') {
1976: if ($settings->{'available'} eq '1') {
1977: $srchon = $srchoff;
1978: $srchoff = ' ';
1979: }
1.24 raeburn 1980: if ($settings->{'localonly'} eq '1') {
1981: $localon = $localoff;
1982: $localoff = ' ';
1983: }
1.25 raeburn 1984: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1985: foreach my $type (@{$settings->{'searchtypes'}}) {
1986: if ($type eq 'exact') {
1987: $exacton = ' checked="checked" ';
1988: } elsif ($type eq 'contains') {
1989: $containson = ' checked="checked" ';
1990: } elsif ($type eq 'begins') {
1991: $beginson = ' checked="checked" ';
1992: }
1993: }
1994: } else {
1995: if ($settings->{'searchtypes'} eq 'exact') {
1996: $exacton = ' checked="checked" ';
1997: } elsif ($settings->{'searchtypes'} eq 'contains') {
1998: $containson = ' checked="checked" ';
1999: } elsif ($settings->{'searchtypes'} eq 'specify') {
2000: $exacton = ' checked="checked" ';
2001: $containson = ' checked="checked" ';
2002: }
1.23 raeburn 2003: }
2004: }
2005: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2006: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2007:
2008: my $numinrow = 4;
1.26 raeburn 2009: my $cansrchrow = 0;
1.23 raeburn 2010: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2011: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2012: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2013: '<input type="radio" name="dirsrch_available"'.
2014: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2015: '<label><input type="radio" name="dirsrch_available"'.
2016: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2017: '</tr><tr>'.
1.30 raeburn 2018: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2019: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2020: '<input type="radio" name="dirsrch_localonly"'.
2021: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2022: '<label><input type="radio" name="dirsrch_localonly"'.
2023: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2024: '</tr>';
1.30 raeburn 2025: $$rowtotal += 2;
1.26 raeburn 2026: if (ref($usertypes) eq 'HASH') {
2027: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2028: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2029: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2030: $cansrchrow = 1;
2031: }
2032: }
2033: if ($cansrchrow) {
1.30 raeburn 2034: $$rowtotal ++;
1.26 raeburn 2035: $datatable .= '<tr>';
2036: } else {
2037: $datatable .= '<tr class="LC_odd_row">';
2038: }
1.30 raeburn 2039: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2040: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2041: foreach my $title (@{$titleorder}) {
2042: if (defined($searchtitles->{$title})) {
2043: my $check = ' ';
1.93 raeburn 2044: if (ref($settings) eq 'HASH') {
1.39 raeburn 2045: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2046: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2047: $check = ' checked="checked" ';
2048: }
1.25 raeburn 2049: }
2050: }
2051: $datatable .= '<td class="LC_left_item">'.
2052: '<span class="LC_nobreak"><label>'.
2053: '<input type="checkbox" name="searchby" '.
2054: 'value="'.$title.'"'.$check.'/>'.
2055: $searchtitles->{$title}.'</label></span></td>';
2056: }
2057: }
1.26 raeburn 2058: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2059: $$rowtotal ++;
1.26 raeburn 2060: if ($cansrchrow) {
2061: $datatable .= '<tr class="LC_odd_row">';
2062: } else {
2063: $datatable .= '<tr>';
2064: }
1.30 raeburn 2065: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2066: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2067: '<span class="LC_nobreak"><label>'.
2068: '<input type="checkbox" name="searchtypes" '.
2069: $exacton.' value="exact" />'.&mt('Exact match').
2070: '</label> '.
2071: '<label><input type="checkbox" name="searchtypes" '.
2072: $beginson.' value="begins" />'.&mt('Begins with').
2073: '</label> '.
2074: '<label><input type="checkbox" name="searchtypes" '.
2075: $containson.' value="contains" />'.&mt('Contains').
2076: '</label></span></td></tr>';
1.30 raeburn 2077: $$rowtotal ++;
1.25 raeburn 2078: return $datatable;
2079: }
2080:
1.28 raeburn 2081: sub print_contacts {
1.30 raeburn 2082: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2083: my $datatable;
2084: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2085: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2086: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2087: 'requestsmail');
1.28 raeburn 2088: foreach my $type (@mailings) {
2089: $otheremails{$type} = '';
2090: }
1.134 raeburn 2091: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2092: if (ref($settings) eq 'HASH') {
2093: foreach my $item (@contacts) {
2094: if (exists($settings->{$item})) {
2095: $to{$item} = $settings->{$item};
2096: }
2097: }
2098: foreach my $type (@mailings) {
2099: if (exists($settings->{$type})) {
2100: if (ref($settings->{$type}) eq 'HASH') {
2101: foreach my $item (@contacts) {
2102: if ($settings->{$type}{$item}) {
2103: $checked{$type}{$item} = ' checked="checked" ';
2104: }
2105: }
2106: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2107: if ($type eq 'helpdeskmail') {
2108: $bccemails{$type} = $settings->{$type}{'bcc'};
2109: }
1.28 raeburn 2110: }
1.89 raeburn 2111: } elsif ($type eq 'lonstatusmail') {
2112: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2113: }
2114: }
2115: } else {
2116: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2117: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2118: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2119: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2120: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2121: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2122: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2123: }
2124: my ($titles,$short_titles) = &contact_titles();
2125: my $rownum = 0;
2126: my $css_class;
2127: foreach my $item (@contacts) {
1.69 raeburn 2128: $rownum ++;
2129: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2130: $datatable .= '<tr'.$css_class.'>'.
2131: '<td><span class="LC_nobreak">'.$titles->{$item}.
2132: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2133: '<input type="text" name="'.$item.'" value="'.
2134: $to{$item}.'" /></td></tr>';
2135: }
2136: foreach my $type (@mailings) {
1.69 raeburn 2137: $rownum ++;
2138: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2139: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2140: '<td><span class="LC_nobreak">'.
2141: $titles->{$type}.': </span></td>'.
1.28 raeburn 2142: '<td class="LC_left_item">'.
2143: '<span class="LC_nobreak">';
2144: foreach my $item (@contacts) {
2145: $datatable .= '<label>'.
2146: '<input type="checkbox" name="'.$type.'"'.
2147: $checked{$type}{$item}.
2148: ' value="'.$item.'" />'.$short_titles->{$item}.
2149: '</label> ';
2150: }
2151: $datatable .= '</span><br />'.&mt('Others').': '.
2152: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2153: 'value="'.$otheremails{$type}.'" />';
2154: if ($type eq 'helpdeskmail') {
1.136 raeburn 2155: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2156: '<input type="text" name="'.$type.'_bcc" '.
2157: 'value="'.$bccemails{$type}.'" />';
2158: }
2159: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2160: }
1.30 raeburn 2161: $$rowtotal += $rownum;
1.28 raeburn 2162: return $datatable;
2163: }
2164:
1.118 jms 2165: sub print_helpsettings {
1.122 jms 2166:
2167: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2168: my ($css_class,$datatable);
2169:
2170: my $switchserver = &check_switchserver($dom,$confname);
2171:
2172: my $itemcount = 1;
2173:
2174: if ($position eq 'top') {
2175:
2176: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2177:
2178: %choices =
2179: &Apache::lonlocal::texthash (
2180: submitbugs => 'Display "Submit a bug" link?',
2181: );
2182:
2183: %defaultchecked = ('submitbugs' => 'on');
2184:
2185: @toggles = ('submitbugs',);
2186:
2187: foreach my $item (@toggles) {
2188: if ($defaultchecked{$item} eq 'on') {
2189: $checkedon{$item} = ' checked="checked" ';
2190: $checkedoff{$item} = ' ';
2191: } elsif ($defaultchecked{$item} eq 'off') {
2192: $checkedoff{$item} = ' checked="checked" ';
2193: $checkedon{$item} = ' ';
2194: }
2195: }
2196:
2197: if (ref($settings) eq 'HASH') {
2198: foreach my $item (@toggles) {
2199: if ($settings->{$item} eq '1') {
2200: $checkedon{$item} = ' checked="checked" ';
2201: $checkedoff{$item} = ' ';
2202: } elsif ($settings->{$item} eq '0') {
2203: $checkedoff{$item} = ' checked="checked" ';
2204: $checkedon{$item} = ' ';
2205: }
2206: }
2207: }
2208:
2209: foreach my $item (@toggles) {
2210: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2211: $datatable .=
2212: '<tr'.$css_class.'>
2213: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2214: <td><span class="LC_nobreak"> </span></td>
2215: <td class="LC_right_item"><span class="LC_nobreak">
2216: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2217: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2218: '</span></td>'.
2219: '</tr>';
2220: $itemcount ++;
2221: }
2222:
2223: } else {
2224:
2225: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2226:
2227: $datatable .= '<tr'.$css_class.'>';
2228:
2229: if (ref($settings) eq 'HASH') {
2230: if ($settings->{'loginhelpurl'} ne '') {
2231: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2232: $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>';
2233: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2234: } else {
2235: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2236: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2237: }
2238: } else {
2239: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2240: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2241: }
2242:
2243: $datatable .= '<td width="33%"><span class="LC_right_item">';
2244: if ($switchserver) {
2245: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2246: } else {
2247: $datatable .= &mt('Upload Custom Login Page Help File:');
2248: $datatable .='<input type="file" name="loginhelpurl" />';
2249: }
2250: $datatable .= '</span></td></tr>';
2251:
2252: }
2253:
2254: return $datatable;
2255:
1.121 raeburn 2256: }
2257:
1.122 jms 2258:
1.121 raeburn 2259: sub radiobutton_prefs {
2260: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2261: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2262: (ref($choices) eq 'HASH'));
2263:
2264: my (%checkedon,%checkedoff,$datatable,$css_class);
2265:
2266: foreach my $item (@{$toggles}) {
2267: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2268: $checkedon{$item} = ' checked="checked" ';
2269: $checkedoff{$item} = ' ';
1.121 raeburn 2270: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2271: $checkedoff{$item} = ' checked="checked" ';
2272: $checkedon{$item} = ' ';
2273: }
2274: }
2275: if (ref($settings) eq 'HASH') {
1.121 raeburn 2276: foreach my $item (@{$toggles}) {
1.118 jms 2277: if ($settings->{$item} eq '1') {
2278: $checkedon{$item} = ' checked="checked" ';
2279: $checkedoff{$item} = ' ';
2280: } elsif ($settings->{$item} eq '0') {
2281: $checkedoff{$item} = ' checked="checked" ';
2282: $checkedon{$item} = ' ';
2283: }
2284: }
1.121 raeburn 2285: }
2286: foreach my $item (@{$toggles}) {
1.118 jms 2287: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2288: $datatable .=
2289: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2290: '</span></td>'.
2291: '<td class="LC_right_item"><span class="LC_nobreak">'.
2292: '<label><input type="radio" name="'.
2293: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2294: '</label> <label><input type="radio" name="'.$item.'" '.
2295: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2296: '</span></td>'.
2297: '</tr>';
2298: $itemcount ++;
1.121 raeburn 2299: }
2300: return ($datatable,$itemcount);
2301: }
2302:
2303: sub print_coursedefaults {
1.139 raeburn 2304: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2305: my ($css_class,$datatable);
2306: my $itemcount = 1;
1.139 raeburn 2307: if ($position eq 'top') {
2308: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2309: %choices =
2310: &Apache::lonlocal::texthash (
2311: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2312: );
2313: %defaultchecked = ('canuse_pdfforms' => 'off');
2314: @toggles = ('canuse_pdfforms',);
2315: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2316: \%choices,$itemcount);
1.139 raeburn 2317: $$rowtotal += $itemcount;
2318: } else {
2319: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2320: my %choices =
2321: &Apache::lonlocal::texthash (
2322: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2323: );
2324: my $currdefresponder;
2325: if (ref($settings) eq 'HASH') {
2326: $currdefresponder = $settings->{'anonsurvey_threshold'};
2327: }
2328: if (!$currdefresponder) {
2329: $currdefresponder = 10;
2330: } elsif ($currdefresponder < 1) {
2331: $currdefresponder = 1;
2332: }
2333: $datatable .=
2334: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2335: '</span></td>'.
2336: '<td class="LC_right_item"><span class="LC_nobreak">'.
2337: '<input type="text" name="anonsurvey_threshold"'.
2338: ' value="'.$currdefresponder.'" size="5" /></span>'.
2339: '</td></tr>';
2340: }
1.121 raeburn 2341: return $datatable;
1.118 jms 2342: }
2343:
1.137 raeburn 2344: sub print_usersessions {
2345: my ($position,$dom,$settings,$rowtotal) = @_;
2346: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2347: my (%by_ip,%by_location,@intdoms);
2348: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2349:
2350: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2351: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2352: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2353: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2354: my $itemcount = 1;
2355: if ($position eq 'top') {
1.152 raeburn 2356: if (keys(%serverhomes) > 1) {
1.145 raeburn 2357: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2358: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2359: } else {
1.140 raeburn 2360: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2361: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2362: }
1.137 raeburn 2363: } else {
1.145 raeburn 2364: if (keys(%by_location) == 0) {
2365: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2366: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2367: } else {
2368: my %lt = &usersession_titles();
2369: my $numinrow = 5;
2370: my $prefix;
2371: my @types;
2372: if ($position eq 'bottom') {
2373: $prefix = 'remote';
2374: @types = ('version','excludedomain','includedomain');
2375: } else {
2376: $prefix = 'hosted';
2377: @types = ('excludedomain','includedomain');
2378: }
2379: my (%current,%checkedon,%checkedoff);
2380: my @lcversions = &Apache::lonnet::all_loncaparevs();
2381: my @locations = sort(keys(%by_location));
2382: foreach my $type (@types) {
2383: $checkedon{$type} = '';
2384: $checkedoff{$type} = ' checked="checked"';
2385: }
2386: if (ref($settings) eq 'HASH') {
2387: if (ref($settings->{$prefix}) eq 'HASH') {
2388: foreach my $key (keys(%{$settings->{$prefix}})) {
2389: $current{$key} = $settings->{$prefix}{$key};
2390: if ($key eq 'version') {
2391: if ($current{$key} ne '') {
2392: $checkedon{$key} = ' checked="checked"';
2393: $checkedoff{$key} = '';
2394: }
2395: } elsif (ref($current{$key}) eq 'ARRAY') {
2396: $checkedon{$key} = ' checked="checked"';
2397: $checkedoff{$key} = '';
2398: }
1.137 raeburn 2399: }
2400: }
2401: }
1.145 raeburn 2402: foreach my $type (@types) {
2403: next if ($type ne 'version' && !@locations);
2404: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2405: $datatable .= '<tr'.$css_class.'>
2406: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2407: <span class="LC_nobreak">
2408: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2409: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2410: if ($type eq 'version') {
2411: my $selector = '<select name="'.$prefix.'_version">';
2412: foreach my $version (@lcversions) {
2413: my $selected = '';
2414: if ($current{'version'} eq $version) {
2415: $selected = ' selected="selected"';
2416: }
2417: $selector .= ' <option value="'.$version.'"'.
2418: $selected.'>'.$version.'</option>';
2419: }
2420: $selector .= '</select> ';
2421: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2422: } else {
2423: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2424: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2425: ' />'.(' 'x2).
2426: '<input type="button" value="'.&mt('uncheck all').'" '.
2427: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2428: "\n".
2429: '</div><div><table>';
2430: my $rem;
2431: for (my $i=0; $i<@locations; $i++) {
2432: my ($showloc,$value,$checkedtype);
2433: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2434: my $ip = $by_location{$locations[$i]}->[0];
2435: if (ref($by_ip{$ip}) eq 'ARRAY') {
2436: $value = join(':',@{$by_ip{$ip}});
2437: $showloc = join(', ',@{$by_ip{$ip}});
2438: if (ref($current{$type}) eq 'ARRAY') {
2439: foreach my $loc (@{$by_ip{$ip}}) {
2440: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2441: $checkedtype = ' checked="checked"';
2442: last;
2443: }
2444: }
1.138 raeburn 2445: }
2446: }
2447: }
1.145 raeburn 2448: $rem = $i%($numinrow);
2449: if ($rem == 0) {
2450: if ($i > 0) {
2451: $datatable .= '</tr>';
2452: }
2453: $datatable .= '<tr>';
2454: }
2455: $datatable .= '<td class="LC_left_item">'.
2456: '<span class="LC_nobreak"><label>'.
2457: '<input type="checkbox" name="'.$prefix.'_'.$type.
2458: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2459: '</label></span></td>';
1.137 raeburn 2460: }
1.145 raeburn 2461: $rem = @locations%($numinrow);
2462: my $colsleft = $numinrow - $rem;
2463: if ($colsleft > 1 ) {
2464: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2465: ' </td>';
2466: } elsif ($colsleft == 1) {
2467: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2468: }
1.145 raeburn 2469: $datatable .= '</tr></table>';
1.137 raeburn 2470: }
1.145 raeburn 2471: $datatable .= '</td></tr>';
2472: $itemcount ++;
1.137 raeburn 2473: }
2474: }
2475: }
2476: $$rowtotal += $itemcount;
2477: return $datatable;
2478: }
2479:
1.138 raeburn 2480: sub build_location_hashes {
2481: my ($intdoms,$by_ip,$by_location) = @_;
2482: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2483: (ref($by_location) eq 'HASH'));
2484: my %iphost = &Apache::lonnet::get_iphost();
2485: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2486: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2487: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2488: foreach my $id (@{$iphost{$primary_ip}}) {
2489: my $intdom = &Apache::lonnet::internet_dom($id);
2490: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2491: push(@{$intdoms},$intdom);
2492: }
2493: }
2494: }
2495: foreach my $ip (keys(%iphost)) {
2496: if (ref($iphost{$ip}) eq 'ARRAY') {
2497: foreach my $id (@{$iphost{$ip}}) {
2498: my $location = &Apache::lonnet::internet_dom($id);
2499: if ($location) {
2500: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2501: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2502: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2503: push(@{$by_ip->{$ip}},$location);
2504: }
2505: } else {
2506: $by_ip->{$ip} = [$location];
2507: }
2508: }
2509: }
2510: }
2511: }
2512: foreach my $ip (sort(keys(%{$by_ip}))) {
2513: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2514: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2515: my $first = $by_ip->{$ip}->[0];
2516: if (ref($by_location->{$first}) eq 'ARRAY') {
2517: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2518: push(@{$by_location->{$first}},$ip);
2519: }
2520: } else {
2521: $by_location->{$first} = [$ip];
2522: }
2523: }
2524: }
2525: return;
2526: }
2527:
1.145 raeburn 2528: sub current_offloads_to {
2529: my ($dom,$settings,$servers) = @_;
2530: my (%spareid,%otherdomconfigs);
1.152 raeburn 2531: if (ref($servers) eq 'HASH') {
1.145 raeburn 2532: foreach my $lonhost (sort(keys(%{$servers}))) {
2533: my $gotspares;
1.152 raeburn 2534: if (ref($settings) eq 'HASH') {
2535: if (ref($settings->{'spares'}) eq 'HASH') {
2536: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2537: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2538: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2539: $gotspares = 1;
2540: }
1.145 raeburn 2541: }
2542: }
2543: unless ($gotspares) {
2544: my $gotspares;
2545: my $serverhomeID =
2546: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2547: my $serverhomedom =
2548: &Apache::lonnet::host_domain($serverhomeID);
2549: if ($serverhomedom ne $dom) {
2550: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2551: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2552: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2553: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2554: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2555: $gotspares = 1;
2556: }
2557: }
2558: } else {
2559: $otherdomconfigs{$serverhomedom} =
2560: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2561: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2562: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2563: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2564: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2565: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2566: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2567: $gotspares = 1;
2568: }
2569: }
2570: }
2571: }
2572: }
2573: }
2574: }
2575: unless ($gotspares) {
2576: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2577: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2578: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2579: } else {
2580: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2581: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2582: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2583: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2584: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2585: } else {
1.150 raeburn 2586: my %what = (
2587: spareid => 1,
2588: );
2589: my ($result,$returnhash) =
2590: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2591: if ($result eq 'ok') {
2592: if (ref($returnhash) eq 'HASH') {
2593: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2594: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2595: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2596: }
2597: }
1.145 raeburn 2598: }
2599: }
2600: }
2601: }
2602: }
2603: }
2604: return %spareid;
2605: }
2606:
2607: sub spares_row {
1.152 raeburn 2608: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2609: my $css_class;
2610: my $numinrow = 4;
2611: my $itemcount = 1;
2612: my $datatable;
1.152 raeburn 2613: my %typetitles = &sparestype_titles();
2614: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2615: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2616: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2617: my ($othercontrol,$serverdom);
2618: if ($serverhome ne $server) {
2619: $serverdom = &Apache::lonnet::host_domain($serverhome);
2620: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2621: } else {
2622: $serverdom = &Apache::lonnet::host_domain($server);
2623: if ($serverdom ne $dom) {
2624: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2625: }
2626: }
2627: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2628: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2629: $datatable .= '<tr'.$css_class.'>
2630: <td rowspan="2">
1.152 raeburn 2631: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2632: my (%current,%canselect);
1.152 raeburn 2633: my @choices =
2634: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2635: foreach my $type ('primary','default') {
2636: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2637: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2638: my @spares = @{$spareid->{$server}{$type}};
2639: if (@spares > 0) {
1.152 raeburn 2640: if ($othercontrol) {
2641: $current{$type} = join(', ',@spares);
2642: } else {
2643: $current{$type} .= '<table>';
2644: my $numspares = scalar(@spares);
2645: for (my $i=0; $i<@spares; $i++) {
2646: my $rem = $i%($numinrow);
2647: if ($rem == 0) {
2648: if ($i > 0) {
2649: $current{$type} .= '</tr>';
2650: }
2651: $current{$type} .= '<tr>';
1.145 raeburn 2652: }
1.152 raeburn 2653: $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'".');" /> '.
2654: $spareid->{$server}{$type}[$i].
2655: '</label></td>'."\n";
2656: }
2657: my $rem = @spares%($numinrow);
2658: my $colsleft = $numinrow - $rem;
2659: if ($colsleft > 1 ) {
2660: $current{$type} .= '<td colspan="'.$colsleft.
2661: '" class="LC_left_item">'.
2662: ' </td>';
2663: } elsif ($colsleft == 1) {
2664: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2665: }
1.152 raeburn 2666: $current{$type} .= '</tr></table>';
1.150 raeburn 2667: }
1.145 raeburn 2668: }
2669: }
2670: if ($current{$type} eq '') {
2671: $current{$type} = &mt('None specified');
2672: }
1.152 raeburn 2673: if ($othercontrol) {
2674: if ($type eq 'primary') {
2675: $canselect{$type} = $othercontrol;
2676: }
2677: } else {
2678: $canselect{$type} =
2679: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2680: '<select name="newspare_'.$type.'_'.$server.'" '.
2681: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2682: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2683: if (@choices > 0) {
2684: foreach my $lonhost (@choices) {
2685: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2686: }
2687: }
2688: $canselect{$type} .= '</select>'."\n";
2689: }
2690: } else {
2691: $current{$type} = &mt('Could not be determined');
2692: if ($type eq 'primary') {
2693: $canselect{$type} = $othercontrol;
2694: }
1.145 raeburn 2695: }
1.152 raeburn 2696: if ($type eq 'default') {
2697: $datatable .= '<tr'.$css_class.'>';
2698: }
2699: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2700: '<td>'.$current{$type}.'</td>'."\n".
2701: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2702: }
2703: $itemcount ++;
2704: }
2705: }
2706: $$rowtotal += $itemcount;
2707: return $datatable;
2708: }
2709:
1.152 raeburn 2710: sub possible_newspares {
2711: my ($server,$currspares,$serverhomes,$altids) = @_;
2712: my $serverhostname = &Apache::lonnet::hostname($server);
2713: my %excluded;
2714: if ($serverhostname ne '') {
2715: %excluded = (
2716: $serverhostname => 1,
2717: );
2718: }
2719: if (ref($currspares) eq 'HASH') {
2720: foreach my $type (keys(%{$currspares})) {
2721: if (ref($currspares->{$type}) eq 'ARRAY') {
2722: if (@{$currspares->{$type}} > 0) {
2723: foreach my $curr (@{$currspares->{$type}}) {
2724: my $hostname = &Apache::lonnet::hostname($curr);
2725: $excluded{$hostname} = 1;
2726: }
2727: }
2728: }
2729: }
2730: }
2731: my @choices;
2732: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2733: if (keys(%{$serverhomes}) > 1) {
2734: foreach my $name (sort(keys(%{$serverhomes}))) {
2735: unless ($excluded{$name}) {
2736: if (exists($altids->{$serverhomes->{$name}})) {
2737: push(@choices,$altids->{$serverhomes->{$name}});
2738: } else {
2739: push(@choices,$serverhomes->{$name});
1.145 raeburn 2740: }
2741: }
2742: }
2743: }
2744: }
1.152 raeburn 2745: return sort(@choices);
1.145 raeburn 2746: }
2747:
1.150 raeburn 2748: sub print_loadbalancing {
2749: my ($dom,$settings,$rowtotal) = @_;
2750: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2751: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2752: my $numinrow = 1;
2753: my $datatable;
2754: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2755: my ($currbalancer,$currtargets,$currrules);
2756: if (keys(%servers) > 1) {
2757: if (ref($settings) eq 'HASH') {
2758: $currbalancer = $settings->{'lonhost'};
2759: $currtargets = $settings->{'targets'};
2760: $currrules = $settings->{'rules'};
2761: } else {
2762: ($currbalancer,$currtargets) =
2763: &Apache::lonnet::get_lonbalancer_config(\%servers);
2764: }
2765: } else {
2766: return;
2767: }
2768: my ($othertitle,$usertypes,$types) =
2769: &Apache::loncommon::sorted_inst_types($dom);
2770: my $rownum = 6;
2771: if (ref($types) eq 'ARRAY') {
2772: $rownum += scalar(@{$types});
2773: }
1.153 raeburn 2774: my $css_class = ' class="LC_odd_row"';
1.150 raeburn 2775: my $targets_div_style = 'display: none';
2776: my $disabled_div_style = 'display: block';
2777: my $homedom_div_style = 'display: none';
2778: $datatable = '<tr'.$css_class.'>'.
2779: '<td rowspan="'.$rownum.'" valign="top">'.
2780: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
2781: '<option value=""';
2782: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
2783: $datatable .= ' selected="selected"';
2784: } else {
2785: $targets_div_style = 'display: block';
2786: $disabled_div_style = 'display: none';
2787: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
2788: $homedom_div_style = 'display: block';
2789: }
2790: }
2791: $datatable .= '>'.&mt('None').'</option>'."\n";
2792: foreach my $lonhost (sort(keys(%servers))) {
2793: my $selected;
2794: if ($lonhost eq $currbalancer) {
2795: $selected .= ' selected="selected"';
2796: }
2797: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
2798: }
2799: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
2800: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
2801: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2802: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
2803: my @sparestypes = ('primary','default');
2804: my %typetitles = &sparestype_titles();
2805: foreach my $sparetype (@sparestypes) {
2806: my $targettable;
2807: for (my $i=0; $i<$numspares; $i++) {
2808: my $checked;
2809: if (ref($currtargets) eq 'HASH') {
2810: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
2811: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
2812: $checked = ' checked="checked"';
2813: }
2814: }
2815: }
2816: my $chkboxval;
2817: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
2818: $chkboxval = $spares[$i];
2819: }
2820: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
2821: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2822: '</span></label></td>';
2823: my $rem = $i%($numinrow);
2824: if ($rem == 0) {
2825: if ($i > 0) {
2826: $targettable .= '</tr>';
2827: }
2828: $targettable .= '<tr>';
2829: }
2830: }
2831: if ($targettable ne '') {
2832: my $rem = $numspares%($numinrow);
2833: my $colsleft = $numinrow - $rem;
2834: if ($colsleft > 1 ) {
2835: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2836: ' </td>';
2837: } elsif ($colsleft == 1) {
2838: $targettable .= '<td class="LC_left_item"> </td>';
2839: }
2840: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2841: '<table><tr>'.$targettable.'</table><br />';
2842: }
2843: }
2844: $datatable .= '</div></td></tr>'.
2845: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
2846: $usertypes,$types,\%servers,$currbalancer,
1.153 raeburn 2847: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2848: $$rowtotal += $rownum;
2849: return $datatable;
2850: }
2851:
2852: sub loadbalancing_rules {
2853: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153 raeburn 2854: $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150 raeburn 2855: my $output;
2856: my ($alltypes,$othertypes,$titles) =
2857: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
2858: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
2859: foreach my $type (@{$alltypes}) {
2860: my $current;
2861: if (ref($currrules) eq 'HASH') {
2862: $current = $currrules->{$type};
2863: }
2864: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2865: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
2866: $current = '';
2867: }
2868: }
2869: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
2870: $servers,$currbalancer,$dom,
1.153 raeburn 2871: $targets_div_style,$homedom_div_style,$css_class);
1.150 raeburn 2872: }
2873: }
2874: return $output;
2875: }
2876:
2877: sub loadbalancing_titles {
2878: my ($dom,$intdom,$usertypes,$types) = @_;
2879: my %othertypes = (
2880: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
2881: '_LC_author' => &mt('Users from [_1] with author role',$dom),
2882: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
2883: '_LC_external' => &mt('Users not from [_1]',$intdom),
2884: );
2885: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
2886: if (ref($types) eq 'ARRAY') {
2887: unshift(@alltypes,@{$types},'default');
2888: }
2889: my %titles;
2890: foreach my $type (@alltypes) {
2891: if ($type =~ /^_LC_/) {
2892: $titles{$type} = $othertypes{$type};
2893: } elsif ($type eq 'default') {
2894: $titles{$type} = &mt('All users from [_1]',$dom);
2895: if (ref($types) eq 'ARRAY') {
2896: if (@{$types} > 0) {
2897: $titles{$type} = &mt('Other users from [_1]',$dom);
2898: }
2899: }
2900: } elsif (ref($usertypes) eq 'HASH') {
2901: $titles{$type} = $usertypes->{$type};
2902: }
2903: }
2904: return (\@alltypes,\%othertypes,\%titles);
2905: }
2906:
2907: sub loadbalance_rule_row {
2908: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153 raeburn 2909: $homedom_div_style,$css_class) = @_;
1.150 raeburn 2910: my @rulenames = ('default','homeserver');
2911: my %ruletitles = &offloadtype_text();
2912: if ($type eq '_LC_external') {
2913: push(@rulenames,'externalbalancer');
2914: } else {
2915: push(@rulenames,'specific');
2916: }
1.161 ! raeburn 2917: push(@rulenames,'none');
1.150 raeburn 2918: my $style = $targets_div_style;
2919: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2920: $style = $homedom_div_style;
2921: }
2922: my $output =
1.153 raeburn 2923: '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150 raeburn 2924: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
2925: for (my $i=0; $i<@rulenames; $i++) {
2926: my $rule = $rulenames[$i];
2927: my ($checked,$extra);
2928: if ($rulenames[$i] eq 'default') {
2929: $rule = '';
2930: }
2931: if ($rulenames[$i] eq 'specific') {
2932: if (ref($servers) eq 'HASH') {
2933: my $default;
2934: if (($current ne '') && (exists($servers->{$current}))) {
2935: $checked = ' checked="checked"';
2936: }
2937: unless ($checked) {
2938: $default = ' selected="selected"';
2939: }
2940: $extra = ': <select name="loadbalancing_singleserver_'.$type.
2941: '" id="loadbalancing_singleserver_'.$type.
2942: '" onchange="singleServerToggle('."'$type'".')">'."\n".
2943: '<option value=""'.$default.'></option>'."\n";
2944: foreach my $lonhost (sort(keys(%{$servers}))) {
2945: next if ($lonhost eq $currbalancer);
2946: my $selected;
2947: if ($lonhost eq $current) {
2948: $selected = ' selected="selected"';
2949: }
2950: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
2951: }
2952: $extra .= '</select>';
2953: }
2954: } elsif ($rule eq $current) {
2955: $checked = ' checked="checked"';
2956: }
2957: $output .= '<span class="LC_nobreak"><label>'.
2958: '<input type="radio" name="loadbalancing_rules_'.$type.
2959: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
2960: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
2961: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
2962: '</label>'.$extra.'</span><br />'."\n";
2963: }
2964: $output .= '</div></td></tr>'."\n";
2965: return $output;
2966: }
2967:
2968: sub offloadtype_text {
2969: my %ruletitles = &Apache::lonlocal::texthash (
2970: 'default' => 'Offloads to default destinations',
2971: 'homeserver' => "Offloads to user's home server",
2972: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
2973: 'specific' => 'Offloads to specific server',
1.161 ! raeburn 2974: 'none' => 'No offload',
1.150 raeburn 2975: );
2976: return %ruletitles;
2977: }
2978:
2979: sub sparestype_titles {
2980: my %typestitles = &Apache::lonlocal::texthash (
2981: 'primary' => 'primary',
2982: 'default' => 'default',
2983: );
2984: return %typestitles;
2985: }
2986:
1.28 raeburn 2987: sub contact_titles {
2988: my %titles = &Apache::lonlocal::texthash (
2989: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2990: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2991: 'errormail' => 'Error reports to be e-mailed to',
2992: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2993: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2994: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2995: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2996: );
2997: my %short_titles = &Apache::lonlocal::texthash (
2998: adminemail => 'Admin E-mail address',
2999: supportemail => 'Support E-mail',
3000: );
3001: return (\%titles,\%short_titles);
3002: }
3003:
1.72 raeburn 3004: sub tool_titles {
3005: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 3006: aboutme => 'Personal Information Page',
1.86 raeburn 3007: blog => 'Blog',
3008: portfolio => 'Portfolio',
1.88 bisitz 3009: official => 'Official courses (with institutional codes)',
3010: unofficial => 'Unofficial courses',
1.98 raeburn 3011: community => 'Communities',
1.86 raeburn 3012: );
1.72 raeburn 3013: return %titles;
3014: }
3015:
1.101 raeburn 3016: sub courserequest_titles {
3017: my %titles = &Apache::lonlocal::texthash (
3018: official => 'Official',
3019: unofficial => 'Unofficial',
3020: community => 'Communities',
3021: norequest => 'Not allowed',
1.104 raeburn 3022: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3023: validate => 'With validation',
3024: autolimit => 'Numerical limit',
1.103 raeburn 3025: unlimited => '(blank for unlimited)',
1.101 raeburn 3026: );
3027: return %titles;
3028: }
3029:
3030: sub courserequest_conditions {
3031: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3032: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3033: validate => '(Processing of request subject to instittutional validation).',
3034: );
3035: return %conditions;
3036: }
3037:
3038:
1.27 raeburn 3039: sub print_usercreation {
1.30 raeburn 3040: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3041: my $numinrow = 4;
1.28 raeburn 3042: my $datatable;
3043: if ($position eq 'top') {
1.30 raeburn 3044: $$rowtotal ++;
1.34 raeburn 3045: my $rowcount = 0;
1.32 raeburn 3046: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3047: if (ref($rules) eq 'HASH') {
3048: if (keys(%{$rules}) > 0) {
1.32 raeburn 3049: $datatable .= &user_formats_row('username',$settings,$rules,
3050: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3051: $$rowtotal ++;
1.32 raeburn 3052: $rowcount ++;
3053: }
3054: }
3055: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3056: if (ref($idrules) eq 'HASH') {
3057: if (keys(%{$idrules}) > 0) {
3058: $datatable .= &user_formats_row('id',$settings,$idrules,
3059: $idruleorder,$numinrow,$rowcount);
3060: $$rowtotal ++;
3061: $rowcount ++;
1.28 raeburn 3062: }
3063: }
1.43 raeburn 3064: my ($emailrules,$emailruleorder) =
3065: &Apache::lonnet::inst_userrules($dom,'email');
3066: if (ref($emailrules) eq 'HASH') {
3067: if (keys(%{$emailrules}) > 0) {
3068: $datatable .= &user_formats_row('email',$settings,$emailrules,
3069: $emailruleorder,$numinrow,$rowcount);
3070: $$rowtotal ++;
3071: $rowcount ++;
3072: }
3073: }
1.39 raeburn 3074: if ($rowcount == 0) {
3075: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3076: $$rowtotal ++;
3077: $rowcount ++;
3078: }
1.34 raeburn 3079: } elsif ($position eq 'middle') {
1.100 raeburn 3080: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3081: my ($rules,$ruleorder) =
3082: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3083: my %lt = &usercreation_types();
3084: my %checked;
1.50 raeburn 3085: my @selfcreate;
1.34 raeburn 3086: if (ref($settings) eq 'HASH') {
3087: if (ref($settings->{'cancreate'}) eq 'HASH') {
3088: foreach my $item (@creators) {
3089: $checked{$item} = $settings->{'cancreate'}{$item};
3090: }
1.50 raeburn 3091: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3092: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3093: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3094: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3095: @selfcreate = ('email','login','sso');
3096: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3097: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3098: }
3099: }
1.34 raeburn 3100: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3101: foreach my $item (@creators) {
3102: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3103: $checked{$item} = 'none';
3104: }
3105: }
3106: }
3107: }
3108: my $rownum = 0;
3109: foreach my $item (@creators) {
3110: $rownum ++;
1.50 raeburn 3111: if ($item ne 'selfcreate') {
3112: if ($checked{$item} eq '') {
1.43 raeburn 3113: $checked{$item} = 'any';
3114: }
1.34 raeburn 3115: }
3116: my $css_class;
3117: if ($rownum%2) {
3118: $css_class = '';
3119: } else {
3120: $css_class = ' class="LC_odd_row" ';
3121: }
3122: $datatable .= '<tr'.$css_class.'>'.
3123: '<td><span class="LC_nobreak">'.$lt{$item}.
3124: '</span></td><td align="right">';
1.50 raeburn 3125: my @options;
1.45 raeburn 3126: if ($item eq 'selfcreate') {
1.43 raeburn 3127: push(@options,('email','login','sso'));
3128: } else {
1.50 raeburn 3129: @options = ('any');
1.43 raeburn 3130: if (ref($rules) eq 'HASH') {
3131: if (keys(%{$rules}) > 0) {
3132: push(@options,('official','unofficial'));
3133: }
1.37 raeburn 3134: }
1.50 raeburn 3135: push(@options,'none');
1.37 raeburn 3136: }
3137: foreach my $option (@options) {
1.50 raeburn 3138: my $type = 'radio';
1.34 raeburn 3139: my $check = ' ';
1.50 raeburn 3140: if ($item eq 'selfcreate') {
3141: $type = 'checkbox';
3142: if (grep(/^\Q$option\E$/,@selfcreate)) {
3143: $check = ' checked="checked" ';
3144: }
3145: } else {
3146: if ($checked{$item} eq $option) {
3147: $check = ' checked="checked" ';
3148: }
1.34 raeburn 3149: }
3150: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3151: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3152: $item.'" value="'.$option.'"'.$check.'/> '.
3153: $lt{$option}.'</label> </span>';
3154: }
3155: $datatable .= '</td></tr>';
3156: }
1.93 raeburn 3157: my ($othertitle,$usertypes,$types) =
3158: &Apache::loncommon::sorted_inst_types($dom);
3159: if (ref($usertypes) eq 'HASH') {
3160: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3161: my $createsettings;
3162: if (ref($settings) eq 'HASH') {
3163: $createsettings = $settings->{cancreate};
3164: }
3165: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3166: $dom,$numinrow,$othertitle,
3167: 'statustocreate');
3168: $$rowtotal ++;
3169: }
3170: }
1.28 raeburn 3171: } else {
3172: my @contexts = ('author','course','domain');
3173: my @authtypes = ('int','krb4','krb5','loc');
3174: my %checked;
3175: if (ref($settings) eq 'HASH') {
3176: if (ref($settings->{'authtypes'}) eq 'HASH') {
3177: foreach my $item (@contexts) {
3178: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3179: foreach my $auth (@authtypes) {
3180: if ($settings->{'authtypes'}{$item}{$auth}) {
3181: $checked{$item}{$auth} = ' checked="checked" ';
3182: }
3183: }
3184: }
3185: }
1.27 raeburn 3186: }
1.35 raeburn 3187: } else {
3188: foreach my $item (@contexts) {
1.36 raeburn 3189: foreach my $auth (@authtypes) {
1.35 raeburn 3190: $checked{$item}{$auth} = ' checked="checked" ';
3191: }
3192: }
1.27 raeburn 3193: }
1.28 raeburn 3194: my %title = &context_names();
3195: my %authname = &authtype_names();
3196: my $rownum = 0;
3197: my $css_class;
3198: foreach my $item (@contexts) {
3199: if ($rownum%2) {
3200: $css_class = '';
3201: } else {
3202: $css_class = ' class="LC_odd_row" ';
3203: }
1.30 raeburn 3204: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3205: '<td>'.$title{$item}.
3206: '</td><td class="LC_left_item">'.
3207: '<span class="LC_nobreak">';
3208: foreach my $auth (@authtypes) {
3209: $datatable .= '<label>'.
3210: '<input type="checkbox" name="'.$item.'_auth" '.
3211: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3212: $authname{$auth}.'</label> ';
3213: }
3214: $datatable .= '</span></td></tr>';
3215: $rownum ++;
1.27 raeburn 3216: }
1.30 raeburn 3217: $$rowtotal += $rownum;
1.27 raeburn 3218: }
3219: return $datatable;
3220: }
3221:
1.32 raeburn 3222: sub user_formats_row {
3223: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3224: my $output;
3225: my %text = (
3226: 'username' => 'new usernames',
3227: 'id' => 'IDs',
1.45 raeburn 3228: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3229: );
3230: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3231: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3232: '<td><span class="LC_nobreak">';
3233: if ($type eq 'email') {
3234: $output .= &mt("Formats disallowed for $text{$type}: ");
3235: } else {
3236: $output .= &mt("Format rules to check for $text{$type}: ");
3237: }
3238: $output .= '</span></td>'.
3239: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3240: my $rem;
3241: if (ref($ruleorder) eq 'ARRAY') {
3242: for (my $i=0; $i<@{$ruleorder}; $i++) {
3243: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3244: my $rem = $i%($numinrow);
3245: if ($rem == 0) {
3246: if ($i > 0) {
3247: $output .= '</tr>';
3248: }
3249: $output .= '<tr>';
3250: }
3251: my $check = ' ';
1.39 raeburn 3252: if (ref($settings) eq 'HASH') {
3253: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3254: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3255: $check = ' checked="checked" ';
3256: }
1.27 raeburn 3257: }
3258: }
3259: $output .= '<td class="LC_left_item">'.
3260: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3261: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3262: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3263: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3264: }
3265: }
3266: $rem = @{$ruleorder}%($numinrow);
3267: }
3268: my $colsleft = $numinrow - $rem;
3269: if ($colsleft > 1 ) {
3270: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3271: ' </td>';
3272: } elsif ($colsleft == 1) {
3273: $output .= '<td class="LC_left_item"> </td>';
3274: }
3275: $output .= '</tr></table></td></tr>';
3276: return $output;
3277: }
3278:
1.34 raeburn 3279: sub usercreation_types {
3280: my %lt = &Apache::lonlocal::texthash (
3281: author => 'When adding a co-author',
3282: course => 'When adding a user to a course',
1.100 raeburn 3283: requestcrs => 'When requesting a course',
1.45 raeburn 3284: selfcreate => 'User creates own account',
1.34 raeburn 3285: any => 'Any',
3286: official => 'Institutional only ',
3287: unofficial => 'Non-institutional only',
1.85 schafran 3288: email => 'E-mail address',
1.43 raeburn 3289: login => 'Institutional Login',
3290: sso => 'SSO',
1.34 raeburn 3291: none => 'None',
3292: );
3293: return %lt;
1.48 raeburn 3294: }
1.34 raeburn 3295:
1.28 raeburn 3296: sub authtype_names {
3297: my %lt = &Apache::lonlocal::texthash(
3298: int => 'Internal',
3299: krb4 => 'Kerberos 4',
3300: krb5 => 'Kerberos 5',
3301: loc => 'Local',
3302: );
3303: return %lt;
3304: }
3305:
3306: sub context_names {
3307: my %context_title = &Apache::lonlocal::texthash(
3308: author => 'Creating users when an Author',
3309: course => 'Creating users when in a course',
3310: domain => 'Creating users when a Domain Coordinator',
3311: );
3312: return %context_title;
3313: }
3314:
1.33 raeburn 3315: sub print_usermodification {
3316: my ($position,$dom,$settings,$rowtotal) = @_;
3317: my $numinrow = 4;
3318: my ($context,$datatable,$rowcount);
3319: if ($position eq 'top') {
3320: $rowcount = 0;
3321: $context = 'author';
3322: foreach my $role ('ca','aa') {
3323: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3324: $numinrow,$rowcount);
3325: $$rowtotal ++;
3326: $rowcount ++;
3327: }
1.63 raeburn 3328: } elsif ($position eq 'middle') {
1.33 raeburn 3329: $context = 'course';
3330: $rowcount = 0;
3331: foreach my $role ('st','ep','ta','in','cr') {
3332: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3333: $numinrow,$rowcount);
3334: $$rowtotal ++;
3335: $rowcount ++;
3336: }
1.63 raeburn 3337: } elsif ($position eq 'bottom') {
3338: $context = 'selfcreate';
3339: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3340: $usertypes->{'default'} = $othertitle;
3341: if (ref($types) eq 'ARRAY') {
3342: push(@{$types},'default');
3343: $usertypes->{'default'} = $othertitle;
3344: foreach my $status (@{$types}) {
3345: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3346: $numinrow,$rowcount,$usertypes);
3347: $$rowtotal ++;
3348: $rowcount ++;
3349: }
3350: }
1.33 raeburn 3351: }
3352: return $datatable;
3353: }
3354:
1.43 raeburn 3355: sub print_defaults {
3356: my ($dom,$rowtotal) = @_;
1.68 raeburn 3357: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3358: 'datelocale_def','portal_def');
1.43 raeburn 3359: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3360: my $titles = &defaults_titles($dom);
1.43 raeburn 3361: my $rownum = 0;
3362: my ($datatable,$css_class);
3363: foreach my $item (@items) {
3364: if ($rownum%2) {
3365: $css_class = '';
3366: } else {
3367: $css_class = ' class="LC_odd_row" ';
3368: }
3369: $datatable .= '<tr'.$css_class.'>'.
3370: '<td><span class="LC_nobreak">'.$titles->{$item}.
3371: '</span></td><td class="LC_right_item">';
3372: if ($item eq 'auth_def') {
3373: my @authtypes = ('internal','krb4','krb5','localauth');
3374: my %shortauth = (
3375: internal => 'int',
3376: krb4 => 'krb4',
3377: krb5 => 'krb5',
3378: localauth => 'loc'
3379: );
3380: my %authnames = &authtype_names();
3381: foreach my $auth (@authtypes) {
3382: my $checked = ' ';
3383: if ($domdefaults{$item} eq $auth) {
3384: $checked = ' checked="checked" ';
3385: }
3386: $datatable .= '<label><input type="radio" name="'.$item.
3387: '" value="'.$auth.'"'.$checked.'/>'.
3388: $authnames{$shortauth{$auth}}.'</label> ';
3389: }
1.54 raeburn 3390: } elsif ($item eq 'timezone_def') {
3391: my $includeempty = 1;
3392: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3393: } elsif ($item eq 'datelocale_def') {
3394: my $includeempty = 1;
3395: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 3396: } else {
1.141 raeburn 3397: my $size;
3398: if ($item eq 'portal_def') {
3399: $size = ' size="25"';
3400: }
1.43 raeburn 3401: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3402: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3403: }
3404: $datatable .= '</td></tr>';
3405: $rownum ++;
3406: }
3407: $$rowtotal += $rownum;
3408: return $datatable;
3409: }
3410:
3411: sub defaults_titles {
1.141 raeburn 3412: my ($dom) = @_;
1.43 raeburn 3413: my %titles = &Apache::lonlocal::texthash (
3414: 'auth_def' => 'Default authentication type',
3415: 'auth_arg_def' => 'Default authentication argument',
3416: 'lang_def' => 'Default language',
1.54 raeburn 3417: 'timezone_def' => 'Default timezone',
1.68 raeburn 3418: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3419: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3420: );
1.141 raeburn 3421: if ($dom) {
3422: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3423: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3424: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3425: $protocol = 'http' if ($protocol ne 'https');
3426: if ($uint_dom) {
3427: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3428: $uint_dom);
3429: }
3430: }
1.43 raeburn 3431: return (\%titles);
3432: }
3433:
1.46 raeburn 3434: sub print_scantronformat {
3435: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3436: my $itemcount = 1;
1.60 raeburn 3437: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3438: %confhash);
1.46 raeburn 3439: my $switchserver = &check_switchserver($dom,$confname);
3440: my %lt = &Apache::lonlocal::texthash (
1.95 www 3441: default => 'Default bubblesheet format file error',
3442: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3443: );
3444: my %scantronfiles = (
3445: default => 'default.tab',
3446: custom => 'custom.tab',
3447: );
3448: foreach my $key (keys(%scantronfiles)) {
3449: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3450: .$scantronfiles{$key};
3451: }
3452: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3453: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3454: if (!$switchserver) {
3455: my $servadm = $r->dir_config('lonAdmEMail');
3456: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3457: if ($configuserok eq 'ok') {
3458: if ($author_ok eq 'ok') {
3459: my %legacyfile = (
3460: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3461: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3462: );
3463: my %md5chk;
3464: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3465: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3466: chomp($md5chk{$type});
1.46 raeburn 3467: }
3468: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3469: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3470: ($scantronurls{$type},my $error) =
1.46 raeburn 3471: &legacy_scantronformat($r,$dom,$confname,
3472: $type,$legacyfile{$type},
3473: $scantronurls{$type},
3474: $scantronfiles{$type});
1.60 raeburn 3475: if ($error ne '') {
3476: $error{$type} = $error;
3477: }
3478: }
3479: if (keys(%error) == 0) {
3480: $is_custom = 1;
3481: $confhash{'scantron'}{'scantronformat'} =
3482: $scantronurls{'custom'};
3483: my $putresult =
3484: &Apache::lonnet::put_dom('configuration',
3485: \%confhash,$dom);
3486: if ($putresult ne 'ok') {
3487: $error{'custom'} =
3488: '<span class="LC_error">'.
3489: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3490: }
1.46 raeburn 3491: }
3492: } else {
1.60 raeburn 3493: ($scantronurls{'default'},my $error) =
1.46 raeburn 3494: &legacy_scantronformat($r,$dom,$confname,
3495: 'default',$legacyfile{'default'},
3496: $scantronurls{'default'},
3497: $scantronfiles{'default'});
1.60 raeburn 3498: if ($error eq '') {
3499: $confhash{'scantron'}{'scantronformat'} = '';
3500: my $putresult =
3501: &Apache::lonnet::put_dom('configuration',
3502: \%confhash,$dom);
3503: if ($putresult ne 'ok') {
3504: $error{'default'} =
3505: '<span class="LC_error">'.
3506: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3507: }
3508: } else {
3509: $error{'default'} = $error;
3510: }
1.46 raeburn 3511: }
3512: }
3513: }
3514: } else {
1.95 www 3515: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3516: }
3517: }
3518: if (ref($settings) eq 'HASH') {
3519: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3520: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3521: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3522: $scantronurl = '';
3523: } else {
3524: $scantronurl = $settings->{'scantronformat'};
3525: }
3526: $is_custom = 1;
3527: } else {
3528: $scantronurl = $scantronurls{'default'};
3529: }
3530: } else {
1.60 raeburn 3531: if ($is_custom) {
3532: $scantronurl = $scantronurls{'custom'};
3533: } else {
3534: $scantronurl = $scantronurls{'default'};
3535: }
1.46 raeburn 3536: }
3537: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3538: $datatable .= '<tr'.$css_class.'>';
3539: if (!$is_custom) {
1.65 raeburn 3540: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3541: '<span class="LC_nobreak">';
1.46 raeburn 3542: if ($scantronurl) {
3543: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3544: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3545: } else {
3546: $datatable = &mt('File unavailable for display');
3547: }
1.65 raeburn 3548: $datatable .= '</span></td>';
1.60 raeburn 3549: if (keys(%error) == 0) {
3550: $datatable .= '<td valign="bottom">';
3551: if (!$switchserver) {
3552: $datatable .= &mt('Upload:').'<br />';
3553: }
3554: } else {
3555: my $errorstr;
3556: foreach my $key (sort(keys(%error))) {
3557: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3558: }
3559: $datatable .= '<td>'.$errorstr;
3560: }
1.46 raeburn 3561: } else {
3562: if (keys(%error) > 0) {
3563: my $errorstr;
3564: foreach my $key (sort(keys(%error))) {
3565: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3566: }
1.60 raeburn 3567: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3568: } elsif ($scantronurl) {
1.65 raeburn 3569: $datatable .= '<td><span class="LC_nobreak">'.
3570: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3571: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3572: '<input type="checkbox" name="scantronformat_del"'.
3573: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3574: '<td><span class="LC_nobreak"> '.
3575: &mt('Replace:').'</span><br />';
1.46 raeburn 3576: }
3577: }
3578: if (keys(%error) == 0) {
3579: if ($switchserver) {
3580: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3581: } else {
1.65 raeburn 3582: $datatable .='<span class="LC_nobreak"> '.
3583: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3584: }
3585: }
3586: $datatable .= '</td></tr>';
3587: $$rowtotal ++;
3588: return $datatable;
3589: }
3590:
3591: sub legacy_scantronformat {
3592: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3593: my ($url,$error);
3594: my @statinfo = &Apache::lonnet::stat_file($newurl);
3595: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3596: (my $result,$url) =
3597: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3598: '','',$newfile);
3599: if ($result ne 'ok') {
1.130 raeburn 3600: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3601: }
3602: }
3603: return ($url,$error);
3604: }
1.43 raeburn 3605:
1.49 raeburn 3606: sub print_coursecategories {
1.57 raeburn 3607: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3608: my $datatable;
3609: if ($position eq 'top') {
3610: my $toggle_cats_crs = ' ';
3611: my $toggle_cats_dom = ' checked="checked" ';
3612: my $can_cat_crs = ' ';
3613: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3614: my $toggle_catscomm_comm = ' ';
3615: my $toggle_catscomm_dom = ' checked="checked" ';
3616: my $can_catcomm_comm = ' ';
3617: my $can_catcomm_dom = ' checked="checked" ';
3618:
1.57 raeburn 3619: if (ref($settings) eq 'HASH') {
3620: if ($settings->{'togglecats'} eq 'crs') {
3621: $toggle_cats_crs = $toggle_cats_dom;
3622: $toggle_cats_dom = ' ';
3623: }
3624: if ($settings->{'categorize'} eq 'crs') {
3625: $can_cat_crs = $can_cat_dom;
3626: $can_cat_dom = ' ';
3627: }
1.120 raeburn 3628: if ($settings->{'togglecatscomm'} eq 'comm') {
3629: $toggle_catscomm_comm = $toggle_catscomm_dom;
3630: $toggle_catscomm_dom = ' ';
3631: }
3632: if ($settings->{'categorizecomm'} eq 'comm') {
3633: $can_catcomm_comm = $can_catcomm_dom;
3634: $can_catcomm_dom = ' ';
3635: }
1.57 raeburn 3636: }
3637: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3638: togglecats => 'Show/Hide a course in catalog',
3639: togglecatscomm => 'Show/Hide a community in catalog',
3640: categorize => 'Assign a category to a course',
3641: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3642: );
3643: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3644: dom => 'Set in Domain',
3645: crs => 'Set in Course',
3646: comm => 'Set in Community',
1.57 raeburn 3647: );
3648: $datatable = '<tr class="LC_odd_row">'.
3649: '<td>'.$title{'togglecats'}.'</td>'.
3650: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3651: '<input type="radio" name="togglecats"'.
3652: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3653: '<label><input type="radio" name="togglecats"'.
3654: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3655: '</tr><tr>'.
3656: '<td>'.$title{'categorize'}.'</td>'.
3657: '<td class="LC_right_item"><span class="LC_nobreak">'.
3658: '<label><input type="radio" name="categorize"'.
3659: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3660: '<label><input type="radio" name="categorize"'.
3661: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3662: '</tr><tr class="LC_odd_row">'.
3663: '<td>'.$title{'togglecatscomm'}.'</td>'.
3664: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3665: '<input type="radio" name="togglecatscomm"'.
3666: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3667: '<label><input type="radio" name="togglecatscomm"'.
3668: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3669: '</tr><tr>'.
3670: '<td>'.$title{'categorizecomm'}.'</td>'.
3671: '<td class="LC_right_item"><span class="LC_nobreak">'.
3672: '<label><input type="radio" name="categorizecomm"'.
3673: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3674: '<label><input type="radio" name="categorizecomm"'.
3675: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3676: '</tr>';
1.120 raeburn 3677: $$rowtotal += 4;
1.57 raeburn 3678: } else {
3679: my $css_class;
3680: my $itemcount = 1;
3681: my $cathash;
3682: if (ref($settings) eq 'HASH') {
3683: $cathash = $settings->{'cats'};
3684: }
3685: if (ref($cathash) eq 'HASH') {
3686: my (@cats,@trails,%allitems,%idx,@jsarray);
3687: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3688: \%allitems,\%idx,\@jsarray);
3689: my $maxdepth = scalar(@cats);
3690: my $colattrib = '';
3691: if ($maxdepth > 2) {
3692: $colattrib = ' colspan="2" ';
3693: }
3694: my @path;
3695: if (@cats > 0) {
3696: if (ref($cats[0]) eq 'ARRAY') {
3697: my $numtop = @{$cats[0]};
3698: my $maxnum = $numtop;
1.120 raeburn 3699: my %default_names = (
3700: instcode => &mt('Official courses'),
3701: communities => &mt('Communities'),
3702: );
3703:
3704: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3705: ($cathash->{'instcode::0'} eq '') ||
3706: (!grep(/^communities$/,@{$cats[0]})) ||
3707: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3708: $maxnum ++;
3709: }
3710: my $lastidx;
3711: for (my $i=0; $i<$numtop; $i++) {
3712: my $parent = $cats[0][$i];
3713: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3714: my $item = &escape($parent).'::0';
3715: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3716: $lastidx = $idx{$item};
3717: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3718: .'<select name="'.$item.'"'.$chgstr.'>';
3719: for (my $k=0; $k<=$maxnum; $k++) {
3720: my $vpos = $k+1;
3721: my $selstr;
3722: if ($k == $i) {
3723: $selstr = ' selected="selected" ';
3724: }
3725: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3726: }
3727: $datatable .= '</select></td><td>';
1.120 raeburn 3728: if ($parent eq 'instcode' || $parent eq 'communities') {
3729: $datatable .= '<span class="LC_nobreak">'
3730: .$default_names{$parent}.'</span>';
3731: if ($parent eq 'instcode') {
3732: $datatable .= '<br /><span class="LC_nobreak">('
3733: .&mt('with institutional codes')
3734: .')</span></td><td'.$colattrib.'>';
3735: } else {
3736: $datatable .= '<table><tr><td>';
3737: }
3738: $datatable .= '<span class="LC_nobreak">'
3739: .'<label><input type="radio" name="'
3740: .$parent.'" value="1" checked="checked" />'
3741: .&mt('Display').'</label>';
3742: if ($parent eq 'instcode') {
3743: $datatable .= ' ';
3744: } else {
3745: $datatable .= '</span></td></tr><tr><td>'
3746: .'<span class="LC_nobreak">';
3747: }
3748: $datatable .= '<label><input type="radio" name="'
3749: .$parent.'" value="0" />'
3750: .&mt('Do not display').'</label></span>';
3751: if ($parent eq 'communities') {
3752: $datatable .= '</td></tr></table>';
3753: }
3754: $datatable .= '</td>';
1.57 raeburn 3755: } else {
3756: $datatable .= $parent
3757: .' <label><input type="checkbox" name="deletecategory" '
3758: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3759: }
3760: my $depth = 1;
3761: push(@path,$parent);
3762: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3763: pop(@path);
3764: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3765: $itemcount ++;
3766: }
1.48 raeburn 3767: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3768: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3769: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3770: for (my $k=0; $k<=$maxnum; $k++) {
3771: my $vpos = $k+1;
3772: my $selstr;
1.57 raeburn 3773: if ($k == $numtop) {
1.48 raeburn 3774: $selstr = ' selected="selected" ';
3775: }
3776: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3777: }
1.59 bisitz 3778: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3779: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3780: .'</tr>'."\n";
1.48 raeburn 3781: $itemcount ++;
1.120 raeburn 3782: foreach my $default ('instcode','communities') {
3783: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3784: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3785: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3786: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3787: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3788: for (my $k=0; $k<=$maxnum; $k++) {
3789: my $vpos = $k+1;
3790: my $selstr;
3791: if ($k == $maxnum) {
3792: $selstr = ' selected="selected" ';
3793: }
3794: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3795: }
1.120 raeburn 3796: $datatable .= '</select></span></td>'.
3797: '<td><span class="LC_nobreak">'.
3798: $default_names{$default}.'</span>';
3799: if ($default eq 'instcode') {
3800: $datatable .= '<br /><span class="LC_nobreak">('
3801: .&mt('with institutional codes').')</span>';
3802: }
3803: $datatable .= '</td>'
3804: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3805: .&mt('Display').'</label> '
3806: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3807: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3808: }
3809: }
3810: }
1.57 raeburn 3811: } else {
3812: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3813: }
3814: } else {
1.57 raeburn 3815: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3816: .&initialize_categories($itemcount);
1.48 raeburn 3817: }
1.57 raeburn 3818: $$rowtotal += $itemcount;
1.48 raeburn 3819: }
3820: return $datatable;
3821: }
3822:
1.69 raeburn 3823: sub print_serverstatuses {
3824: my ($dom,$settings,$rowtotal) = @_;
3825: my $datatable;
3826: my @pages = &serverstatus_pages();
3827: my (%namedaccess,%machineaccess);
3828: foreach my $type (@pages) {
3829: $namedaccess{$type} = '';
3830: $machineaccess{$type}= '';
3831: }
3832: if (ref($settings) eq 'HASH') {
3833: foreach my $type (@pages) {
3834: if (exists($settings->{$type})) {
3835: if (ref($settings->{$type}) eq 'HASH') {
3836: foreach my $key (keys(%{$settings->{$type}})) {
3837: if ($key eq 'namedusers') {
3838: $namedaccess{$type} = $settings->{$type}->{$key};
3839: } elsif ($key eq 'machines') {
3840: $machineaccess{$type} = $settings->{$type}->{$key};
3841: }
3842: }
3843: }
3844: }
3845: }
3846: }
1.81 raeburn 3847: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3848: my $rownum = 0;
3849: my $css_class;
3850: foreach my $type (@pages) {
3851: $rownum ++;
3852: $css_class = $rownum%2?' class="LC_odd_row"':'';
3853: $datatable .= '<tr'.$css_class.'>'.
3854: '<td><span class="LC_nobreak">'.
3855: $titles->{$type}.'</span></td>'.
3856: '<td class="LC_left_item">'.
3857: '<input type="text" name="'.$type.'_namedusers" '.
3858: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3859: '<td class="LC_right_item">'.
3860: '<span class="LC_nobreak">'.
3861: '<input type="text" name="'.$type.'_machines" '.
3862: 'value="'.$machineaccess{$type}.'" size="10" />'.
3863: '</td></tr>'."\n";
3864: }
3865: $$rowtotal += $rownum;
3866: return $datatable;
3867: }
3868:
3869: sub serverstatus_pages {
3870: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3871: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 3872: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 3873: }
3874:
1.49 raeburn 3875: sub coursecategories_javascript {
3876: my ($settings) = @_;
1.57 raeburn 3877: my ($output,$jstext,$cathash);
1.49 raeburn 3878: if (ref($settings) eq 'HASH') {
1.57 raeburn 3879: $cathash = $settings->{'cats'};
3880: }
3881: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3882: my (@cats,@jsarray,%idx);
1.57 raeburn 3883: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3884: if (@jsarray > 0) {
3885: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3886: for (my $i=0; $i<@jsarray; $i++) {
3887: if (ref($jsarray[$i]) eq 'ARRAY') {
3888: my $catstr = join('","',@{$jsarray[$i]});
3889: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3890: }
3891: }
3892: }
3893: } else {
3894: $jstext = ' var categories = Array(1);'."\n".
3895: ' categories[0] = Array("instcode_pos");'."\n";
3896: }
1.120 raeburn 3897: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3898: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3899: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3900: $output = <<"ENDSCRIPT";
3901: <script type="text/javascript">
1.109 raeburn 3902: // <![CDATA[
1.49 raeburn 3903: function reorderCats(form,parent,item,idx) {
3904: var changedVal;
3905: $jstext
3906: var newpos = 'addcategory_pos';
3907: var current = new Array;
3908: if (parent == '') {
3909: var has_instcode = 0;
3910: var maxtop = categories[idx].length;
3911: for (var j=0; j<maxtop; j++) {
3912: if (categories[idx][j] == 'instcode::0') {
3913: has_instcode == 1;
3914: }
3915: }
3916: if (has_instcode == 0) {
3917: categories[idx][maxtop] = 'instcode_pos';
3918: }
3919: } else {
3920: newpos += '_'+parent;
3921: }
3922: var maxh = 1 + categories[idx].length;
3923: var current = new Array;
3924: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3925: if (item == newpos) {
3926: changedVal = newitemVal;
3927: } else {
3928: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3929: current[newitemVal] = newpos;
3930: }
3931: for (var i=0; i<categories[idx].length; i++) {
3932: var elementName = categories[idx][i];
3933: if (elementName != item) {
3934: if (form.elements[elementName]) {
3935: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3936: current[currVal] = elementName;
3937: }
3938: }
3939: }
3940: var oldVal;
3941: for (var j=0; j<maxh; j++) {
3942: if (current[j] == undefined) {
3943: oldVal = j;
3944: }
3945: }
3946: if (oldVal < changedVal) {
3947: for (var k=oldVal+1; k<=changedVal ; k++) {
3948: var elementName = current[k];
3949: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3950: }
3951: } else {
3952: for (var k=changedVal; k<oldVal; k++) {
3953: var elementName = current[k];
3954: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3955: }
3956: }
3957: return;
3958: }
1.120 raeburn 3959:
3960: function categoryCheck(form) {
3961: if (form.elements['addcategory_name'].value == 'instcode') {
3962: alert('$instcode_reserved\\n$choose_again');
3963: return false;
3964: }
3965: if (form.elements['addcategory_name'].value == 'communities') {
3966: alert('$communities_reserved\\n$choose_again');
3967: return false;
3968: }
3969: return true;
3970: }
3971:
1.109 raeburn 3972: // ]]>
1.49 raeburn 3973: </script>
3974:
3975: ENDSCRIPT
3976: return $output;
3977: }
3978:
1.48 raeburn 3979: sub initialize_categories {
3980: my ($itemcount) = @_;
1.120 raeburn 3981: my ($datatable,$css_class,$chgstr);
3982: my %default_names = (
3983: instcode => 'Official courses (with institutional codes)',
3984: communities => 'Communities',
3985: );
3986: my $select0 = ' selected="selected"';
3987: my $select1 = '';
3988: foreach my $default ('instcode','communities') {
3989: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3990: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3991: if ($default eq 'communities') {
3992: $select1 = $select0;
3993: $select0 = '';
3994: }
3995: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3996: .'<select name="'.$default.'_pos">'
3997: .'<option value="0"'.$select0.'>1</option>'
3998: .'<option value="1"'.$select1.'>2</option>'
3999: .'<option value="2">3</option></select> '
4000: .$default_names{$default}
4001: .'</span></td><td><span class="LC_nobreak">'
4002: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4003: .&mt('Display').'</label> <label>'
4004: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4005: .'</label></span></td></tr>';
1.120 raeburn 4006: $itemcount ++;
4007: }
1.48 raeburn 4008: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4009: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4010: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4011: .'<select name="addcategory_pos"'.$chgstr.'>'
4012: .'<option value="0">1</option>'
4013: .'<option value="1">2</option>'
4014: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4015: .&mt('Add category').'</td><td>'.&mt('Name:')
4016: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4017: return $datatable;
4018: }
4019:
4020: sub build_category_rows {
1.49 raeburn 4021: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4022: my ($text,$name,$item,$chgstr);
1.48 raeburn 4023: if (ref($cats) eq 'ARRAY') {
4024: my $maxdepth = scalar(@{$cats});
4025: if (ref($cats->[$depth]) eq 'HASH') {
4026: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4027: my $numchildren = @{$cats->[$depth]{$parent}};
4028: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4029: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4030: my ($idxnum,$parent_name,$parent_item);
4031: my $higher = $depth - 1;
4032: if ($higher == 0) {
4033: $parent_name = &escape($parent).'::'.$higher;
4034: } else {
4035: if (ref($path) eq 'ARRAY') {
4036: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4037: }
4038: }
4039: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4040: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4041: if ($j < $numchildren) {
1.48 raeburn 4042: $name = $cats->[$depth]{$parent}[$j];
4043: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4044: $idxnum = $idx->{$item};
4045: } else {
4046: $name = $parent_name;
4047: $item = $parent_item;
1.48 raeburn 4048: }
1.49 raeburn 4049: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4050: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4051: for (my $i=0; $i<=$numchildren; $i++) {
4052: my $vpos = $i+1;
4053: my $selstr;
4054: if ($j == $i) {
4055: $selstr = ' selected="selected" ';
4056: }
4057: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4058: }
4059: $text .= '</select> ';
4060: if ($j < $numchildren) {
4061: my $deeper = $depth+1;
4062: $text .= $name.' '
4063: .'<label><input type="checkbox" name="deletecategory" value="'
4064: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4065: if(ref($path) eq 'ARRAY') {
4066: push(@{$path},$name);
1.49 raeburn 4067: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4068: pop(@{$path});
4069: }
4070: } else {
1.59 bisitz 4071: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4072: if ($j == $numchildren) {
4073: $text .= $name;
4074: } else {
4075: $text .= $item;
4076: }
4077: $text .= '" value="" />';
4078: }
4079: $text .= '</td></tr>';
4080: }
4081: $text .= '</table></td>';
4082: } else {
4083: my $higher = $depth-1;
4084: if ($higher == 0) {
4085: $name = &escape($parent).'::'.$higher;
4086: } else {
4087: if (ref($path) eq 'ARRAY') {
4088: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4089: }
4090: }
4091: my $colspan;
4092: if ($parent ne 'instcode') {
4093: $colspan = $maxdepth - $depth - 1;
4094: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4095: }
4096: }
4097: }
4098: }
4099: return $text;
4100: }
4101:
1.33 raeburn 4102: sub modifiable_userdata_row {
1.63 raeburn 4103: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4104: my $rolename;
1.63 raeburn 4105: if ($context eq 'selfcreate') {
4106: if (ref($usertypes) eq 'HASH') {
4107: $rolename = $usertypes->{$role};
4108: } else {
4109: $rolename = $role;
4110: }
1.33 raeburn 4111: } else {
1.63 raeburn 4112: if ($role eq 'cr') {
4113: $rolename = &mt('Custom role');
4114: } else {
4115: $rolename = &Apache::lonnet::plaintext($role);
4116: }
1.33 raeburn 4117: }
4118: my @fields = ('lastname','firstname','middlename','generation',
4119: 'permanentemail','id');
4120: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4121: my $output;
4122: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4123: $output = '<tr '.$css_class.'>'.
4124: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4125: '<td class="LC_left_item" colspan="2"><table>';
4126: my $rem;
4127: my %checks;
4128: if (ref($settings) eq 'HASH') {
4129: if (ref($settings->{$context}) eq 'HASH') {
4130: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4131: foreach my $field (@fields) {
4132: if ($settings->{$context}->{$role}->{$field}) {
4133: $checks{$field} = ' checked="checked" ';
4134: }
4135: }
4136: }
4137: }
4138: }
4139: for (my $i=0; $i<@fields; $i++) {
4140: my $rem = $i%($numinrow);
4141: if ($rem == 0) {
4142: if ($i > 0) {
4143: $output .= '</tr>';
4144: }
4145: $output .= '<tr>';
4146: }
4147: my $check = ' ';
4148: if (exists($checks{$fields[$i]})) {
4149: $check = $checks{$fields[$i]}
4150: } else {
4151: if ($role eq 'st') {
4152: if (ref($settings) ne 'HASH') {
4153: $check = ' checked="checked" ';
4154: }
4155: }
4156: }
4157: $output .= '<td class="LC_left_item">'.
4158: '<span class="LC_nobreak"><label>'.
4159: '<input type="checkbox" name="canmodify_'.$role.'" '.
4160: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4161: '</label></span></td>';
4162: $rem = @fields%($numinrow);
4163: }
4164: my $colsleft = $numinrow - $rem;
4165: if ($colsleft > 1 ) {
4166: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4167: ' </td>';
4168: } elsif ($colsleft == 1) {
4169: $output .= '<td class="LC_left_item"> </td>';
4170: }
4171: $output .= '</tr></table></td></tr>';
4172: return $output;
4173: }
1.28 raeburn 4174:
1.93 raeburn 4175: sub insttypes_row {
4176: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4177: my %lt = &Apache::lonlocal::texthash (
4178: cansearch => 'Users allowed to search',
4179: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4180: lockablenames => 'User preference to lock name',
1.93 raeburn 4181: );
4182: my $showdom;
4183: if ($context eq 'cansearch') {
4184: $showdom = ' ('.$dom.')';
4185: }
1.25 raeburn 4186: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4187: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 4188: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 4189: my $rem;
4190: if (ref($types) eq 'ARRAY') {
4191: for (my $i=0; $i<@{$types}; $i++) {
4192: if (defined($usertypes->{$types->[$i]})) {
4193: my $rem = $i%($numinrow);
4194: if ($rem == 0) {
4195: if ($i > 0) {
4196: $output .= '</tr>';
4197: }
4198: $output .= '<tr>';
1.23 raeburn 4199: }
1.26 raeburn 4200: my $check = ' ';
1.99 raeburn 4201: if (ref($settings) eq 'HASH') {
4202: if (ref($settings->{$context}) eq 'ARRAY') {
4203: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4204: $check = ' checked="checked" ';
4205: }
4206: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4207: $check = ' checked="checked" ';
4208: }
1.23 raeburn 4209: }
1.26 raeburn 4210: $output .= '<td class="LC_left_item">'.
4211: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4212: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4213: 'value="'.$types->[$i].'"'.$check.'/>'.
4214: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4215: }
4216: }
1.26 raeburn 4217: $rem = @{$types}%($numinrow);
1.23 raeburn 4218: }
4219: my $colsleft = $numinrow - $rem;
1.131 raeburn 4220: if (($rem == 0) && (@{$types} > 0)) {
4221: $output .= '<tr>';
4222: }
1.23 raeburn 4223: if ($colsleft > 1) {
1.25 raeburn 4224: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4225: } else {
1.25 raeburn 4226: $output .= '<td class="LC_left_item">';
1.23 raeburn 4227: }
4228: my $defcheck = ' ';
1.99 raeburn 4229: if (ref($settings) eq 'HASH') {
4230: if (ref($settings->{$context}) eq 'ARRAY') {
4231: if (grep(/^default$/,@{$settings->{$context}})) {
4232: $defcheck = ' checked="checked" ';
4233: }
4234: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4235: $defcheck = ' checked="checked" ';
4236: }
1.23 raeburn 4237: }
1.25 raeburn 4238: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4239: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4240: 'value="default"'.$defcheck.'/>'.
4241: $othertitle.'</label></span></td>'.
4242: '</tr></table></td></tr>';
4243: return $output;
1.23 raeburn 4244: }
4245:
4246: sub sorted_searchtitles {
4247: my %searchtitles = &Apache::lonlocal::texthash(
4248: 'uname' => 'username',
4249: 'lastname' => 'last name',
4250: 'lastfirst' => 'last name, first name',
4251: );
4252: my @titleorder = ('uname','lastname','lastfirst');
4253: return (\%searchtitles,\@titleorder);
4254: }
4255:
1.25 raeburn 4256: sub sorted_searchtypes {
4257: my %srchtypes_desc = (
4258: exact => 'is exact match',
4259: contains => 'contains ..',
4260: begins => 'begins with ..',
4261: );
4262: my @srchtypeorder = ('exact','begins','contains');
4263: return (\%srchtypes_desc,\@srchtypeorder);
4264: }
4265:
1.3 raeburn 4266: sub usertype_update_row {
4267: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4268: my $datatable;
4269: my $numinrow = 4;
4270: foreach my $type (@{$types}) {
4271: if (defined($usertypes->{$type})) {
4272: $$rownums ++;
4273: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4274: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4275: '</td><td class="LC_left_item"><table>';
4276: for (my $i=0; $i<@{$fields}; $i++) {
4277: my $rem = $i%($numinrow);
4278: if ($rem == 0) {
4279: if ($i > 0) {
4280: $datatable .= '</tr>';
4281: }
4282: $datatable .= '<tr>';
4283: }
4284: my $check = ' ';
1.39 raeburn 4285: if (ref($settings) eq 'HASH') {
4286: if (ref($settings->{'fields'}) eq 'HASH') {
4287: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4288: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4289: $check = ' checked="checked" ';
4290: }
1.3 raeburn 4291: }
4292: }
4293: }
4294:
4295: if ($i == @{$fields}-1) {
4296: my $colsleft = $numinrow - $rem;
4297: if ($colsleft > 1) {
4298: $datatable .= '<td colspan="'.$colsleft.'">';
4299: } else {
4300: $datatable .= '<td>';
4301: }
4302: } else {
4303: $datatable .= '<td>';
4304: }
1.8 raeburn 4305: $datatable .= '<span class="LC_nobreak"><label>'.
4306: '<input type="checkbox" name="updateable_'.$type.
4307: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4308: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4309: }
4310: $datatable .= '</tr></table></td></tr>';
4311: }
4312: }
4313: return $datatable;
1.1 raeburn 4314: }
4315:
4316: sub modify_login {
1.9 raeburn 4317: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 4318: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 4319: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 4320: adminmail => 'Display administrator E-mail address',
1.43 raeburn 4321: newuser => 'Link for visitors to create a user account',
1.41 raeburn 4322: loginheader => 'Log-in box header');
1.3 raeburn 4323: my @offon = ('off','on');
1.112 raeburn 4324: my %curr_loginvia;
4325: if (ref($domconfig{login}) eq 'HASH') {
4326: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4327: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4328: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4329: }
4330: }
4331: }
1.6 raeburn 4332: my %loginhash;
1.9 raeburn 4333: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4334: \%domconfig,\%loginhash);
1.118 jms 4335: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4336: foreach my $item (@toggles) {
4337: $loginhash{login}{$item} = $env{'form.'.$item};
4338: }
1.41 raeburn 4339: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4340: if (ref($colchanges{'login'}) eq 'HASH') {
4341: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4342: \%loginhash);
4343: }
1.110 raeburn 4344:
1.149 raeburn 4345: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4346: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4347: if (keys(%servers) > 1) {
4348: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4349: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4350: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4351: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4352: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4353: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4354: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4355: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4356: $changes{'loginvia'}{$lonhost} = 1;
4357: } else {
4358: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4359: $changes{'loginvia'}{$lonhost} = 1;
4360: }
4361: } else {
4362: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4363: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4364: $changes{'loginvia'}{$lonhost} = 1;
4365: }
4366: }
4367: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4368: foreach my $item (@loginvia_attribs) {
4369: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4370: }
4371: } else {
4372: foreach my $item (@loginvia_attribs) {
4373: my $new = $env{'form.'.$lonhost.'_'.$item};
4374: if (($item eq 'serverpath') && ($new eq 'custom')) {
4375: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4376: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4377: $new = '/';
4378: }
4379: }
4380: if (($item eq 'custompath') &&
4381: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4382: $new = '';
4383: }
4384: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4385: $changes{'loginvia'}{$lonhost} = 1;
4386: }
4387: if ($item eq 'exempt') {
4388: $new =~ s/^\s+//;
4389: $new =~ s/\s+$//;
4390: my @poss_ips = split(/\s*[,:]\s*/,$new);
4391: my @okips;
4392: foreach my $ip (@poss_ips) {
4393: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4394: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4395: push(@okips,$ip);
4396: }
4397: }
4398: }
4399: if (@okips > 0) {
4400: $new = join(',',@okips);
4401: } else {
4402: $new = '';
4403: }
4404: }
4405:
4406: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4407: }
4408: }
1.112 raeburn 4409: } else {
1.128 raeburn 4410: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4411: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4412: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4413: foreach my $item (@loginvia_attribs) {
4414: my $new = $env{'form.'.$lonhost.'_'.$item};
4415: if (($item eq 'serverpath') && ($new eq 'custom')) {
4416: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4417: $new = '/';
4418: }
4419: }
4420: if (($item eq 'custompath') &&
4421: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4422: $new = '';
4423: }
4424: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4425: }
1.110 raeburn 4426: }
4427: }
4428: }
4429: }
1.119 raeburn 4430:
1.1 raeburn 4431: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4432: $dom);
4433: if ($putresult eq 'ok') {
1.118 jms 4434: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4435: my %defaultchecked = (
4436: 'coursecatalog' => 'on',
4437: 'adminmail' => 'off',
1.43 raeburn 4438: 'newuser' => 'off',
1.42 raeburn 4439: );
1.55 raeburn 4440: if (ref($domconfig{'login'}) eq 'HASH') {
4441: foreach my $item (@toggles) {
4442: if ($defaultchecked{$item} eq 'on') {
4443: if (($domconfig{'login'}{$item} eq '0') &&
4444: ($env{'form.'.$item} eq '1')) {
4445: $changes{$item} = 1;
4446: } elsif (($domconfig{'login'}{$item} eq '' ||
4447: $domconfig{'login'}{$item} eq '1') &&
4448: ($env{'form.'.$item} eq '0')) {
4449: $changes{$item} = 1;
4450: }
4451: } elsif ($defaultchecked{$item} eq 'off') {
4452: if (($domconfig{'login'}{$item} eq '1') &&
4453: ($env{'form.'.$item} eq '0')) {
4454: $changes{$item} = 1;
4455: } elsif (($domconfig{'login'}{$item} eq '' ||
4456: $domconfig{'login'}{$item} eq '0') &&
4457: ($env{'form.'.$item} eq '1')) {
4458: $changes{$item} = 1;
4459: }
1.42 raeburn 4460: }
4461: }
1.41 raeburn 4462: }
1.6 raeburn 4463: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4464: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4465: $resulttext = &mt('Changes made:').'<ul>';
4466: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4467: if ($item eq 'loginvia') {
1.112 raeburn 4468: if (ref($changes{$item}) eq 'HASH') {
4469: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4470: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4471: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4472: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4473: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4474: $protocol = 'http' if ($protocol ne 'https');
4475: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4476:
4477: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4478: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4479: } else {
4480: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4481: }
4482: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4483: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4484: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4485: }
4486: $resulttext .= '</li>';
4487: } else {
4488: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4489: }
1.112 raeburn 4490: } else {
1.128 raeburn 4491: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4492: }
4493: }
1.128 raeburn 4494: $resulttext .= '</ul></li>';
1.112 raeburn 4495: }
1.41 raeburn 4496: } else {
4497: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4498: }
1.1 raeburn 4499: }
1.6 raeburn 4500: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4501: } else {
4502: $resulttext = &mt('No changes made to log-in page settings');
4503: }
4504: } else {
1.11 albertel 4505: $resulttext = '<span class="LC_error">'.
4506: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4507: }
1.6 raeburn 4508: if ($errors) {
1.9 raeburn 4509: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4510: $errors.'</ul>';
4511: }
4512: return $resulttext;
4513: }
4514:
4515: sub color_font_choices {
4516: my %choices =
4517: &Apache::lonlocal::texthash (
4518: img => "Header",
4519: bgs => "Background colors",
4520: links => "Link colors",
1.55 raeburn 4521: images => "Images",
1.6 raeburn 4522: font => "Font color",
1.97 tempelho 4523: fontmenu => "Font Menu",
1.76 raeburn 4524: pgbg => "Page",
1.6 raeburn 4525: tabbg => "Header",
4526: sidebg => "Border",
4527: link => "Link",
4528: alink => "Active link",
4529: vlink => "Visited link",
4530: );
4531: return %choices;
4532: }
4533:
4534: sub modify_rolecolors {
1.9 raeburn 4535: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4536: my ($resulttext,%rolehash);
4537: $rolehash{'rolecolors'} = {};
1.55 raeburn 4538: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4539: if ($domconfig{'rolecolors'} eq '') {
4540: $domconfig{'rolecolors'} = {};
4541: }
4542: }
1.9 raeburn 4543: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4544: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4545: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4546: $dom);
4547: if ($putresult eq 'ok') {
4548: if (keys(%changes) > 0) {
1.41 raeburn 4549: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4550: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4551: $rolehash{'rolecolors'});
4552: } else {
4553: $resulttext = &mt('No changes made to default color schemes');
4554: }
4555: } else {
1.11 albertel 4556: $resulttext = '<span class="LC_error">'.
4557: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4558: }
4559: if ($errors) {
4560: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4561: $errors.'</ul>';
4562: }
4563: return $resulttext;
4564: }
4565:
4566: sub modify_colors {
1.9 raeburn 4567: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4568: my (%changes,%choices);
1.51 raeburn 4569: my @bgs;
1.6 raeburn 4570: my @links = ('link','alink','vlink');
1.41 raeburn 4571: my @logintext;
1.6 raeburn 4572: my @images;
4573: my $servadm = $r->dir_config('lonAdmEMail');
4574: my $errors;
4575: foreach my $role (@{$roles}) {
4576: if ($role eq 'login') {
1.12 raeburn 4577: %choices = &login_choices();
1.41 raeburn 4578: @logintext = ('textcol','bgcol');
1.12 raeburn 4579: } else {
4580: %choices = &color_font_choices();
1.107 raeburn 4581: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4582: }
4583: if ($role eq 'login') {
1.41 raeburn 4584: @images = ('img','logo','domlogo','login');
1.51 raeburn 4585: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4586: } else {
4587: @images = ('img');
1.51 raeburn 4588: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4589: }
4590: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4591: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4592: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4593: }
1.46 raeburn 4594: my ($configuserok,$author_ok,$switchserver) =
4595: &config_check($dom,$confname,$servadm);
1.9 raeburn 4596: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4597: if (ref($domconfig->{$role}) ne 'HASH') {
4598: $domconfig->{$role} = {};
4599: }
1.8 raeburn 4600: foreach my $img (@images) {
1.70 raeburn 4601: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4602: if (defined($env{'form.login_showlogo_'.$img})) {
4603: $confhash->{$role}{'showlogo'}{$img} = 1;
4604: } else {
4605: $confhash->{$role}{'showlogo'}{$img} = 0;
4606: }
4607: }
1.18 albertel 4608: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4609: && !defined($domconfig->{$role}{$img})
4610: && !$env{'form.'.$role.'_del_'.$img}
4611: && $env{'form.'.$role.'_import_'.$img}) {
4612: # import the old configured image from the .tab setting
4613: # if they haven't provided a new one
4614: $domconfig->{$role}{$img} =
4615: $env{'form.'.$role.'_import_'.$img};
4616: }
1.6 raeburn 4617: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4618: my $error;
1.6 raeburn 4619: if ($configuserok eq 'ok') {
1.9 raeburn 4620: if ($switchserver) {
1.12 raeburn 4621: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4622: } else {
4623: if ($author_ok eq 'ok') {
4624: my ($result,$logourl) =
4625: &publishlogo($r,'upload',$role.'_'.$img,
4626: $dom,$confname,$img,$width,$height);
4627: if ($result eq 'ok') {
4628: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4629: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4630: } else {
1.12 raeburn 4631: $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 4632: }
4633: } else {
1.46 raeburn 4634: $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 4635: }
4636: }
4637: } else {
1.46 raeburn 4638: $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 4639: }
4640: if ($error) {
1.8 raeburn 4641: &Apache::lonnet::logthis($error);
1.11 albertel 4642: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4643: }
4644: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4645: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4646: my $error;
4647: if ($configuserok eq 'ok') {
4648: # is confname an author?
4649: if ($switchserver eq '') {
4650: if ($author_ok eq 'ok') {
4651: my ($result,$logourl) =
4652: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4653: $dom,$confname,$img,$width,$height);
4654: if ($result eq 'ok') {
4655: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4656: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4657: }
4658: }
4659: }
4660: }
1.6 raeburn 4661: }
4662: }
4663: }
4664: if (ref($domconfig) eq 'HASH') {
4665: if (ref($domconfig->{$role}) eq 'HASH') {
4666: foreach my $img (@images) {
4667: if ($domconfig->{$role}{$img} ne '') {
4668: if ($env{'form.'.$role.'_del_'.$img}) {
4669: $confhash->{$role}{$img} = '';
1.12 raeburn 4670: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4671: } else {
1.9 raeburn 4672: if ($confhash->{$role}{$img} eq '') {
4673: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4674: }
1.6 raeburn 4675: }
4676: } else {
4677: if ($env{'form.'.$role.'_del_'.$img}) {
4678: $confhash->{$role}{$img} = '';
1.12 raeburn 4679: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4680: }
4681: }
1.70 raeburn 4682: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4683: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4684: if ($confhash->{$role}{'showlogo'}{$img} ne
4685: $domconfig->{$role}{'showlogo'}{$img}) {
4686: $changes{$role}{'showlogo'}{$img} = 1;
4687: }
4688: } else {
4689: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4690: $changes{$role}{'showlogo'}{$img} = 1;
4691: }
4692: }
4693: }
4694: }
1.6 raeburn 4695: if ($domconfig->{$role}{'font'} ne '') {
4696: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4697: $changes{$role}{'font'} = 1;
4698: }
4699: } else {
4700: if ($confhash->{$role}{'font'}) {
4701: $changes{$role}{'font'} = 1;
4702: }
4703: }
1.107 raeburn 4704: if ($role ne 'login') {
4705: if ($domconfig->{$role}{'fontmenu'} ne '') {
4706: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4707: $changes{$role}{'fontmenu'} = 1;
4708: }
4709: } else {
4710: if ($confhash->{$role}{'fontmenu'}) {
4711: $changes{$role}{'fontmenu'} = 1;
4712: }
1.97 tempelho 4713: }
4714: }
1.6 raeburn 4715: foreach my $item (@bgs) {
4716: if ($domconfig->{$role}{$item} ne '') {
4717: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4718: $changes{$role}{'bgs'}{$item} = 1;
4719: }
4720: } else {
4721: if ($confhash->{$role}{$item}) {
4722: $changes{$role}{'bgs'}{$item} = 1;
4723: }
4724: }
4725: }
4726: foreach my $item (@links) {
4727: if ($domconfig->{$role}{$item} ne '') {
4728: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4729: $changes{$role}{'links'}{$item} = 1;
4730: }
4731: } else {
4732: if ($confhash->{$role}{$item}) {
4733: $changes{$role}{'links'}{$item} = 1;
4734: }
4735: }
4736: }
1.41 raeburn 4737: foreach my $item (@logintext) {
4738: if ($domconfig->{$role}{$item} ne '') {
4739: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4740: $changes{$role}{'logintext'}{$item} = 1;
4741: }
4742: } else {
4743: if ($confhash->{$role}{$item}) {
4744: $changes{$role}{'logintext'}{$item} = 1;
4745: }
4746: }
4747: }
1.6 raeburn 4748: } else {
4749: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4750: \@logintext,$confhash,\%changes);
1.6 raeburn 4751: }
4752: } else {
4753: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4754: \@logintext,$confhash,\%changes);
1.6 raeburn 4755: }
4756: }
4757: return ($errors,%changes);
4758: }
4759:
1.46 raeburn 4760: sub config_check {
4761: my ($dom,$confname,$servadm) = @_;
4762: my ($configuserok,$author_ok,$switchserver,%currroles);
4763: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4764: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4765: $confname,$servadm);
4766: if ($configuserok eq 'ok') {
4767: $switchserver = &check_switchserver($dom,$confname);
4768: if ($switchserver eq '') {
4769: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4770: }
4771: }
4772: return ($configuserok,$author_ok,$switchserver);
4773: }
4774:
1.6 raeburn 4775: sub default_change_checker {
1.41 raeburn 4776: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4777: foreach my $item (@{$links}) {
4778: if ($confhash->{$role}{$item}) {
4779: $changes->{$role}{'links'}{$item} = 1;
4780: }
4781: }
4782: foreach my $item (@{$bgs}) {
4783: if ($confhash->{$role}{$item}) {
4784: $changes->{$role}{'bgs'}{$item} = 1;
4785: }
4786: }
1.41 raeburn 4787: foreach my $item (@{$logintext}) {
4788: if ($confhash->{$role}{$item}) {
4789: $changes->{$role}{'logintext'}{$item} = 1;
4790: }
4791: }
1.6 raeburn 4792: foreach my $img (@{$images}) {
4793: if ($env{'form.'.$role.'_del_'.$img}) {
4794: $confhash->{$role}{$img} = '';
1.12 raeburn 4795: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4796: }
1.70 raeburn 4797: if ($role eq 'login') {
4798: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4799: $changes->{$role}{'showlogo'}{$img} = 1;
4800: }
4801: }
1.6 raeburn 4802: }
4803: if ($confhash->{$role}{'font'}) {
4804: $changes->{$role}{'font'} = 1;
4805: }
1.48 raeburn 4806: }
1.6 raeburn 4807:
4808: sub display_colorchgs {
4809: my ($dom,$changes,$roles,$confhash) = @_;
4810: my (%choices,$resulttext);
4811: if (!grep(/^login$/,@{$roles})) {
4812: $resulttext = &mt('Changes made:').'<br />';
4813: }
4814: foreach my $role (@{$roles}) {
4815: if ($role eq 'login') {
4816: %choices = &login_choices();
4817: } else {
4818: %choices = &color_font_choices();
4819: }
4820: if (ref($changes->{$role}) eq 'HASH') {
4821: if ($role ne 'login') {
4822: $resulttext .= '<h4>'.&mt($role).'</h4>';
4823: }
4824: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4825: if ($role ne 'login') {
4826: $resulttext .= '<ul>';
4827: }
4828: if (ref($changes->{$role}{$key}) eq 'HASH') {
4829: if ($role ne 'login') {
4830: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4831: }
4832: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4833: if (($role eq 'login') && ($key eq 'showlogo')) {
4834: if ($confhash->{$role}{$key}{$item}) {
4835: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4836: } else {
4837: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4838: }
4839: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4840: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4841: } else {
1.12 raeburn 4842: my $newitem = $confhash->{$role}{$item};
4843: if ($key eq 'images') {
4844: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4845: }
4846: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4847: }
4848: }
4849: if ($role ne 'login') {
4850: $resulttext .= '</ul></li>';
4851: }
4852: } else {
4853: if ($confhash->{$role}{$key} eq '') {
4854: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4855: } else {
4856: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4857: }
4858: }
4859: if ($role ne 'login') {
4860: $resulttext .= '</ul>';
4861: }
4862: }
4863: }
4864: }
1.3 raeburn 4865: return $resulttext;
1.1 raeburn 4866: }
4867:
1.9 raeburn 4868: sub thumb_dimensions {
4869: return ('200','50');
4870: }
4871:
1.16 raeburn 4872: sub check_dimensions {
4873: my ($inputfile) = @_;
4874: my ($fullwidth,$fullheight);
4875: if ($inputfile =~ m|^[/\w.\-]+$|) {
4876: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4877: my $imageinfo = <PIPE>;
4878: if (!close(PIPE)) {
4879: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4880: }
4881: chomp($imageinfo);
4882: my ($fullsize) =
1.21 raeburn 4883: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4884: if ($fullsize) {
4885: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4886: }
4887: }
4888: }
4889: return ($fullwidth,$fullheight);
4890: }
4891:
1.9 raeburn 4892: sub check_configuser {
4893: my ($uhome,$dom,$confname,$servadm) = @_;
4894: my ($configuserok,%currroles);
4895: if ($uhome eq 'no_host') {
4896: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4897: my $configpass = &LONCAPA::Enrollment::create_password();
4898: $configuserok =
4899: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4900: $configpass,'','','','','',undef,$servadm);
4901: } else {
4902: $configuserok = 'ok';
4903: %currroles =
4904: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4905: }
4906: return ($configuserok,%currroles);
4907: }
4908:
4909: sub check_authorstatus {
4910: my ($dom,$confname,%currroles) = @_;
4911: my $author_ok;
1.40 raeburn 4912: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4913: my $start = time;
4914: my $end = 0;
4915: $author_ok =
4916: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4917: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4918: } else {
4919: $author_ok = 'ok';
4920: }
4921: return $author_ok;
4922: }
4923:
4924: sub publishlogo {
1.46 raeburn 4925: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4926: my ($output,$fname,$logourl);
4927: if ($action eq 'upload') {
4928: $fname=$env{'form.'.$formname.'.filename'};
4929: chop($env{'form.'.$formname});
4930: } else {
4931: ($fname) = ($formname =~ /([^\/]+)$/);
4932: }
1.46 raeburn 4933: if ($savefileas ne '') {
4934: $fname = $savefileas;
4935: }
1.9 raeburn 4936: $fname=&Apache::lonnet::clean_filename($fname);
4937: # See if there is anything left
4938: unless ($fname) { return ('error: no uploaded file'); }
4939: $fname="$subdir/$fname";
1.158 raeburn 4940: my $filepath=$r->dir_config('lonDocRoot')."/priv/$dom/$confname";
1.9 raeburn 4941: my ($fnamepath,$file,$fetchthumb);
4942: $file=$fname;
4943: if ($fname=~m|/|) {
4944: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4945: }
4946: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4947: my $count;
4948: for ($count=4;$count<=$#parts;$count++) {
4949: $filepath.="/$parts[$count]";
4950: if ((-e $filepath)!=1) {
4951: mkdir($filepath,02770);
4952: }
4953: }
4954: # Check for bad extension and disallow upload
4955: if ($file=~/\.(\w+)$/ &&
4956: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4957: $output =
4958: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4959: } elsif ($file=~/\.(\w+)$/ &&
4960: !defined(&Apache::loncommon::fileembstyle($1))) {
4961: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4962: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4963: $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 4964: } elsif (-d "$filepath/$file") {
4965: $output = &mt('File name is a directory name - rename the file and re-upload');
4966: } else {
4967: my $source = $filepath.'/'.$file;
4968: my $logfile;
4969: if (!open($logfile,">>$source".'.log')) {
4970: return (&mt('No write permission to Construction Space'));
4971: }
4972: print $logfile
4973: "\n================= Publish ".localtime()." ================\n".
4974: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4975: # Save the file
4976: if (!open(FH,'>'.$source)) {
4977: &Apache::lonnet::logthis('Failed to create '.$source);
4978: return (&mt('Failed to create file'));
4979: }
4980: if ($action eq 'upload') {
4981: if (!print FH ($env{'form.'.$formname})) {
4982: &Apache::lonnet::logthis('Failed to write to '.$source);
4983: return (&mt('Failed to write file'));
4984: }
4985: } else {
4986: my $original = &Apache::lonnet::filelocation('',$formname);
4987: if(!copy($original,$source)) {
4988: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4989: return (&mt('Failed to write file'));
4990: }
4991: }
4992: close(FH);
4993: chmod(0660, $source); # Permissions to rw-rw---.
4994:
4995: my $docroot=$r->dir_config('lonDocRoot');
4996: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4997: my $copyfile=$targetdir.'/'.$file;
4998:
4999: my @parts=split(/\//,$targetdir);
5000: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5001: for (my $count=5;$count<=$#parts;$count++) {
5002: $path.="/$parts[$count]";
5003: if (!-e $path) {
5004: print $logfile "\nCreating directory ".$path;
5005: mkdir($path,02770);
5006: }
5007: }
5008: my $versionresult;
5009: if (-e $copyfile) {
5010: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5011: } else {
5012: $versionresult = 'ok';
5013: }
5014: if ($versionresult eq 'ok') {
5015: if (copy($source,$copyfile)) {
5016: print $logfile "\nCopied original source to ".$copyfile."\n";
5017: $output = 'ok';
5018: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5019: push(@{$modified_urls},[$copyfile,$source]);
5020: my $metaoutput =
5021: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5022: unless ($registered_cleanup) {
5023: my $handlers = $r->get_handlers('PerlCleanupHandler');
5024: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5025: $registered_cleanup=1;
5026: }
1.9 raeburn 5027: } else {
5028: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5029: $output = &mt('Failed to copy file to RES space').", $!";
5030: }
5031: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5032: my $inputfile = $filepath.'/'.$file;
5033: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5034: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5035: if ($fullwidth ne '' && $fullheight ne '') {
5036: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5037: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5038: system("convert -sample $thumbsize $inputfile $outfile");
5039: chmod(0660, $filepath.'/tn-'.$file);
5040: if (-e $outfile) {
5041: my $copyfile=$targetdir.'/tn-'.$file;
5042: if (copy($outfile,$copyfile)) {
5043: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5044: my $thumb_metaoutput =
5045: &write_metadata($dom,$confname,$formname,
5046: $targetdir,'tn-'.$file,$logfile);
5047: push(@{$modified_urls},[$copyfile,$outfile]);
5048: unless ($registered_cleanup) {
5049: my $handlers = $r->get_handlers('PerlCleanupHandler');
5050: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5051: $registered_cleanup=1;
5052: }
1.16 raeburn 5053: } else {
5054: print $logfile "\nUnable to write ".$copyfile.
5055: ':'.$!."\n";
5056: }
5057: }
1.9 raeburn 5058: }
5059: }
5060: }
5061: } else {
5062: $output = $versionresult;
5063: }
5064: }
5065: return ($output,$logourl);
5066: }
5067:
5068: sub logo_versioning {
5069: my ($targetdir,$file,$logfile) = @_;
5070: my $target = $targetdir.'/'.$file;
5071: my ($maxversion,$fn,$extn,$output);
5072: $maxversion = 0;
5073: if ($file =~ /^(.+)\.(\w+)$/) {
5074: $fn=$1;
5075: $extn=$2;
5076: }
5077: opendir(DIR,$targetdir);
5078: while (my $filename=readdir(DIR)) {
5079: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5080: $maxversion=($1>$maxversion)?$1:$maxversion;
5081: }
5082: }
5083: $maxversion++;
5084: print $logfile "\nCreating old version ".$maxversion."\n";
5085: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5086: if (copy($target,$copyfile)) {
5087: print $logfile "Copied old target to ".$copyfile."\n";
5088: $copyfile=$copyfile.'.meta';
5089: if (copy($target.'.meta',$copyfile)) {
5090: print $logfile "Copied old target metadata to ".$copyfile."\n";
5091: $output = 'ok';
5092: } else {
5093: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5094: $output = &mt('Failed to copy old meta').", $!, ";
5095: }
5096: } else {
5097: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5098: $output = &mt('Failed to copy old target').", $!, ";
5099: }
5100: return $output;
5101: }
5102:
5103: sub write_metadata {
5104: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5105: my (%metadatafields,%metadatakeys,$output);
5106: $metadatafields{'title'}=$formname;
5107: $metadatafields{'creationdate'}=time;
5108: $metadatafields{'lastrevisiondate'}=time;
5109: $metadatafields{'copyright'}='public';
5110: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5111: $env{'user.domain'};
5112: $metadatafields{'authorspace'}=$confname.':'.$dom;
5113: $metadatafields{'domain'}=$dom;
5114: {
5115: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5116: my $mfh;
1.155 raeburn 5117: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5118: foreach (sort keys %metadatafields) {
5119: unless ($_=~/\./) {
5120: my $unikey=$_;
5121: $unikey=~/^([A-Za-z]+)/;
5122: my $tag=$1;
5123: $tag=~tr/A-Z/a-z/;
5124: print $mfh "\n\<$tag";
5125: foreach (split(/\,/,$metadatakeys{$unikey})) {
5126: my $value=$metadatafields{$unikey.'.'.$_};
5127: $value=~s/\"/\'\'/g;
5128: print $mfh ' '.$_.'="'.$value.'"';
5129: }
5130: print $mfh '>'.
5131: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5132: .'</'.$tag.'>';
5133: }
5134: }
5135: $output = 'ok';
5136: print $logfile "\nWrote metadata";
5137: close($mfh);
5138: } else {
5139: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5140: $output = &mt('Could not write metadata');
5141: }
5142: }
1.155 raeburn 5143: return $output;
5144: }
5145:
5146: sub notifysubscribed {
5147: foreach my $targetsource (@{$modified_urls}){
5148: next unless (ref($targetsource) eq 'ARRAY');
5149: my ($target,$source)=@{$targetsource};
5150: if ($source ne '') {
5151: if (open(my $logfh,'>>'.$source.'.log')) {
5152: print $logfh "\nCleanup phase: Notifications\n";
5153: my @subscribed=&subscribed_hosts($target);
5154: foreach my $subhost (@subscribed) {
5155: print $logfh "\nNotifying host ".$subhost.':';
5156: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5157: print $logfh $reply;
5158: }
5159: my @subscribedmeta=&subscribed_hosts("$target.meta");
5160: foreach my $subhost (@subscribedmeta) {
5161: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5162: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5163: $subhost);
5164: print $logfh $reply;
5165: }
5166: print $logfh "\n============ Done ============\n";
1.160 raeburn 5167: close($logfh);
1.155 raeburn 5168: }
5169: }
5170: }
5171: return OK;
5172: }
5173:
5174: sub subscribed_hosts {
5175: my ($target) = @_;
5176: my @subscribed;
5177: if (open(my $fh,"<$target.subscription")) {
5178: while (my $subline=<$fh>) {
5179: if ($subline =~ /^($match_lonid):/) {
5180: my $host = $1;
5181: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5182: unless (grep(/^\Q$host\E$/,@subscribed)) {
5183: push(@subscribed,$host);
5184: }
5185: }
5186: }
5187: }
5188: }
5189: return @subscribed;
1.9 raeburn 5190: }
5191:
5192: sub check_switchserver {
5193: my ($dom,$confname) = @_;
5194: my ($allowed,$switchserver);
5195: my $home = &Apache::lonnet::homeserver($confname,$dom);
5196: if ($home eq 'no_host') {
5197: $home = &Apache::lonnet::domain($dom,'primary');
5198: }
5199: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5200: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5201: if (!$allowed) {
5202: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5203: }
5204: return $switchserver;
5205: }
5206:
1.1 raeburn 5207: sub modify_quotas {
1.86 raeburn 5208: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5209: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5210: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5211: if ($action eq 'quotas') {
5212: $context = 'tools';
5213: } else {
5214: $context = $action;
5215: }
5216: if ($context eq 'requestcourses') {
1.98 raeburn 5217: @usertools = ('official','unofficial','community');
1.106 raeburn 5218: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5219: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5220: %titles = &courserequest_titles();
5221: $toolregexp = join('|',@usertools);
5222: %conditions = &courserequest_conditions();
1.86 raeburn 5223: } else {
5224: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 5225: %titles = &tool_titles();
1.86 raeburn 5226: }
1.72 raeburn 5227: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5228: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5229: foreach my $key (keys(%env)) {
1.101 raeburn 5230: if ($context eq 'requestcourses') {
5231: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5232: my $item = $1;
5233: my $type = $2;
5234: if ($type =~ /^limit_(.+)/) {
5235: $limithash{$item}{$1} = $env{$key};
5236: } else {
5237: $confhash{$item}{$type} = $env{$key};
5238: }
5239: }
5240: } else {
1.86 raeburn 5241: if ($key =~ /^form\.quota_(.+)$/) {
5242: $confhash{'defaultquota'}{$1} = $env{$key};
5243: }
1.101 raeburn 5244: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5245: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5246: }
1.72 raeburn 5247: }
5248: }
1.102 raeburn 5249: if ($context eq 'requestcourses') {
5250: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5251: @approvalnotify = sort(@approvalnotify);
5252: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5253: if (ref($domconfig{$action}) eq 'HASH') {
5254: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5255: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5256: $changes{'notify'}{'approval'} = 1;
5257: }
5258: } else {
1.144 raeburn 5259: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5260: $changes{'notify'}{'approval'} = 1;
5261: }
5262: }
5263: } else {
1.144 raeburn 5264: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5265: $changes{'notify'}{'approval'} = 1;
5266: }
5267: }
5268: } else {
1.86 raeburn 5269: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5270: }
1.72 raeburn 5271: foreach my $item (@usertools) {
5272: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5273: my $unset;
1.101 raeburn 5274: if ($context eq 'requestcourses') {
1.104 raeburn 5275: $unset = '0';
5276: if ($type eq '_LC_adv') {
5277: $unset = '';
5278: }
1.101 raeburn 5279: if ($confhash{$item}{$type} eq 'autolimit') {
5280: $confhash{$item}{$type} .= '=';
5281: unless ($limithash{$item}{$type} =~ /\D/) {
5282: $confhash{$item}{$type} .= $limithash{$item}{$type};
5283: }
5284: }
1.72 raeburn 5285: } else {
1.101 raeburn 5286: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5287: $confhash{$item}{$type} = 1;
5288: } else {
5289: $confhash{$item}{$type} = 0;
5290: }
1.72 raeburn 5291: }
1.86 raeburn 5292: if (ref($domconfig{$action}) eq 'HASH') {
5293: if (ref($domconfig{$action}{$item}) eq 'HASH') {
5294: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5295: $changes{$item}{$type} = 1;
5296: }
5297: } else {
5298: if ($context eq 'requestcourses') {
1.104 raeburn 5299: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5300: $changes{$item}{$type} = 1;
5301: }
5302: } else {
5303: if (!$confhash{$item}{$type}) {
5304: $changes{$item}{$type} = 1;
5305: }
5306: }
5307: }
5308: } else {
5309: if ($context eq 'requestcourses') {
1.104 raeburn 5310: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5311: $changes{$item}{$type} = 1;
5312: }
5313: } else {
5314: if (!$confhash{$item}{$type}) {
5315: $changes{$item}{$type} = 1;
5316: }
5317: }
5318: }
1.1 raeburn 5319: }
5320: }
1.86 raeburn 5321: unless ($context eq 'requestcourses') {
5322: if (ref($domconfig{'quotas'}) eq 'HASH') {
5323: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5324: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5325: if (exists($confhash{'defaultquota'}{$key})) {
5326: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5327: $changes{'defaultquota'}{$key} = 1;
5328: }
5329: } else {
5330: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5331: }
5332: }
1.86 raeburn 5333: } else {
5334: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5335: if (exists($confhash{'defaultquota'}{$key})) {
5336: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5337: $changes{'defaultquota'}{$key} = 1;
5338: }
5339: } else {
5340: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5341: }
1.1 raeburn 5342: }
5343: }
5344: }
1.86 raeburn 5345: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5346: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5347: if (ref($domconfig{'quotas'}) eq 'HASH') {
5348: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5349: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5350: $changes{'defaultquota'}{$key} = 1;
5351: }
5352: } else {
5353: if (!exists($domconfig{'quotas'}{$key})) {
5354: $changes{'defaultquota'}{$key} = 1;
5355: }
1.72 raeburn 5356: }
5357: } else {
1.86 raeburn 5358: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5359: }
1.1 raeburn 5360: }
5361: }
5362: }
1.72 raeburn 5363:
5364: foreach my $key (keys(%confhash)) {
5365: $domdefaults{$key} = $confhash{$key};
5366: }
5367:
1.1 raeburn 5368: my %quotahash = (
1.86 raeburn 5369: $action => { %confhash }
1.1 raeburn 5370: );
5371: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5372: $dom);
5373: if ($putresult eq 'ok') {
5374: if (keys(%changes) > 0) {
1.72 raeburn 5375: my $cachetime = 24*60*60;
5376: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5377:
1.1 raeburn 5378: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 5379: unless ($context eq 'requestcourses') {
5380: if (ref($changes{'defaultquota'}) eq 'HASH') {
5381: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5382: foreach my $type (@{$types},'default') {
5383: if (defined($changes{'defaultquota'}{$type})) {
5384: my $typetitle = $usertypes->{$type};
5385: if ($type eq 'default') {
5386: $typetitle = $othertitle;
5387: }
5388: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5389: }
5390: }
1.86 raeburn 5391: $resulttext .= '</ul></li>';
1.72 raeburn 5392: }
5393: }
1.80 raeburn 5394: my %newenv;
1.72 raeburn 5395: foreach my $item (@usertools) {
5396: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 5397: my $newacc =
5398: &Apache::lonnet::usertools_access($env{'user.name'},
5399: $env{'user.domain'},
1.86 raeburn 5400: $item,'reload',$context);
5401: if ($context eq 'requestcourses') {
1.108 raeburn 5402: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5403: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5404: }
5405: } else {
5406: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5407: $newenv{'environment.availabletools.'.$item} = $newacc;
5408: }
1.80 raeburn 5409: }
1.72 raeburn 5410: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5411: foreach my $type (@{$types},'default','_LC_adv') {
5412: if ($changes{$item}{$type}) {
5413: my $typetitle = $usertypes->{$type};
5414: if ($type eq 'default') {
5415: $typetitle = $othertitle;
5416: } elsif ($type eq '_LC_adv') {
5417: $typetitle = 'LON-CAPA Advanced Users';
5418: }
5419: if ($confhash{$item}{$type}) {
1.101 raeburn 5420: if ($context eq 'requestcourses') {
5421: my $cond;
5422: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
5423: if ($1 eq '') {
5424: $cond = &mt('(Automatic processing of any request).');
5425: } else {
5426: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5427: }
5428: } else {
5429: $cond = $conditions{$confhash{$item}{$type}};
5430: }
5431: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5432: } else {
5433: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5434: }
1.72 raeburn 5435: } else {
1.104 raeburn 5436: if ($type eq '_LC_adv') {
5437: if ($confhash{$item}{$type} eq '0') {
5438: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5439: } else {
5440: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5441: }
5442: } else {
5443: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5444: }
1.72 raeburn 5445: }
5446: }
1.26 raeburn 5447: }
1.72 raeburn 5448: $resulttext .= '</ul></li>';
1.26 raeburn 5449: }
1.1 raeburn 5450: }
1.102 raeburn 5451: if ($action eq 'requestcourses') {
5452: if (ref($changes{'notify'}) eq 'HASH') {
5453: if ($changes{'notify'}{'approval'}) {
5454: if (ref($confhash{'notify'}) eq 'HASH') {
5455: if ($confhash{'notify'}{'approval'}) {
5456: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5457: } else {
5458: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
5459: }
5460: }
5461: }
5462: }
5463: }
1.1 raeburn 5464: $resulttext .= '</ul>';
1.80 raeburn 5465: if (keys(%newenv)) {
5466: &Apache::lonnet::appenv(\%newenv);
5467: }
1.1 raeburn 5468: } else {
1.86 raeburn 5469: if ($context eq 'requestcourses') {
5470: $resulttext = &mt('No changes made to rights to request creation of courses.');
5471: } else {
1.90 weissno 5472: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5473: }
1.1 raeburn 5474: }
5475: } else {
1.11 albertel 5476: $resulttext = '<span class="LC_error">'.
5477: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5478: }
1.3 raeburn 5479: return $resulttext;
1.1 raeburn 5480: }
5481:
1.3 raeburn 5482: sub modify_autoenroll {
5483: my ($dom,%domconfig) = @_;
1.1 raeburn 5484: my ($resulttext,%changes);
5485: my %currautoenroll;
5486: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5487: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5488: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5489: }
5490: }
5491: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5492: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5493: sender => 'Sender for notification messages',
5494: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5495: my @offon = ('off','on');
1.17 raeburn 5496: my $sender_uname = $env{'form.sender_uname'};
5497: my $sender_domain = $env{'form.sender_domain'};
5498: if ($sender_domain eq '') {
5499: $sender_uname = '';
5500: } elsif ($sender_uname eq '') {
5501: $sender_domain = '';
5502: }
1.129 raeburn 5503: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5504: my %autoenrollhash = (
1.129 raeburn 5505: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5506: 'sender_uname' => $sender_uname,
5507: 'sender_domain' => $sender_domain,
5508: 'co-owners' => $coowners,
1.1 raeburn 5509: }
5510: );
1.4 raeburn 5511: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5512: $dom);
1.1 raeburn 5513: if ($putresult eq 'ok') {
5514: if (exists($currautoenroll{'run'})) {
5515: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5516: $changes{'run'} = 1;
5517: }
5518: } elsif ($autorun) {
5519: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 5520: $changes{'run'} = 1;
1.1 raeburn 5521: }
5522: }
1.17 raeburn 5523: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 5524: $changes{'sender'} = 1;
5525: }
1.17 raeburn 5526: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 5527: $changes{'sender'} = 1;
5528: }
1.129 raeburn 5529: if ($currautoenroll{'co-owners'} ne '') {
5530: if ($currautoenroll{'co-owners'} ne $coowners) {
5531: $changes{'coowners'} = 1;
5532: }
5533: } elsif ($coowners) {
5534: $changes{'coowners'} = 1;
5535: }
1.1 raeburn 5536: if (keys(%changes) > 0) {
5537: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5538: if ($changes{'run'}) {
1.1 raeburn 5539: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5540: }
5541: if ($changes{'sender'}) {
1.17 raeburn 5542: if ($sender_uname eq '' || $sender_domain eq '') {
5543: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5544: } else {
5545: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5546: }
1.1 raeburn 5547: }
1.129 raeburn 5548: if ($changes{'coowners'}) {
5549: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5550: &Apache::loncommon::devalidate_domconfig_cache($dom);
5551: }
1.1 raeburn 5552: $resulttext .= '</ul>';
5553: } else {
5554: $resulttext = &mt('No changes made to auto-enrollment settings');
5555: }
5556: } else {
1.11 albertel 5557: $resulttext = '<span class="LC_error">'.
5558: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5559: }
1.3 raeburn 5560: return $resulttext;
1.1 raeburn 5561: }
5562:
5563: sub modify_autoupdate {
1.3 raeburn 5564: my ($dom,%domconfig) = @_;
1.1 raeburn 5565: my ($resulttext,%currautoupdate,%fields,%changes);
5566: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5567: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5568: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5569: }
5570: }
5571: my @offon = ('off','on');
5572: my %title = &Apache::lonlocal::texthash (
5573: run => 'Auto-update:',
5574: classlists => 'Updates to user information in classlists?'
5575: );
1.44 raeburn 5576: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5577: my %fieldtitles = &Apache::lonlocal::texthash (
5578: id => 'Student/Employee ID',
1.20 raeburn 5579: permanentemail => 'E-mail address',
1.1 raeburn 5580: lastname => 'Last Name',
5581: firstname => 'First Name',
5582: middlename => 'Middle Name',
1.132 raeburn 5583: generation => 'Generation',
1.1 raeburn 5584: );
1.142 raeburn 5585: $othertitle = &mt('All users');
1.1 raeburn 5586: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5587: $othertitle = &mt('Other users');
1.1 raeburn 5588: }
5589: foreach my $key (keys(%env)) {
5590: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5591: my ($usertype,$item) = ($1,$2);
5592: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5593: if ($usertype eq 'default') {
5594: push(@{$fields{$1}},$2);
5595: } elsif (ref($types) eq 'ARRAY') {
5596: if (grep(/^\Q$usertype\E$/,@{$types})) {
5597: push(@{$fields{$1}},$2);
5598: }
5599: }
5600: }
1.1 raeburn 5601: }
5602: }
1.131 raeburn 5603: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5604: @lockablenames = sort(@lockablenames);
5605: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5606: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5607: if (@changed) {
5608: $changes{'lockablenames'} = 1;
5609: }
5610: } else {
5611: if (@lockablenames) {
5612: $changes{'lockablenames'} = 1;
5613: }
5614: }
1.1 raeburn 5615: my %updatehash = (
5616: autoupdate => { run => $env{'form.autoupdate_run'},
5617: classlists => $env{'form.classlists'},
5618: fields => {%fields},
1.131 raeburn 5619: lockablenames => \@lockablenames,
1.1 raeburn 5620: }
5621: );
5622: foreach my $key (keys(%currautoupdate)) {
5623: if (($key eq 'run') || ($key eq 'classlists')) {
5624: if (exists($updatehash{autoupdate}{$key})) {
5625: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5626: $changes{$key} = 1;
5627: }
5628: }
5629: } elsif ($key eq 'fields') {
5630: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5631: foreach my $item (@{$types},'default') {
1.1 raeburn 5632: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5633: my $change = 0;
5634: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5635: if (!exists($fields{$item})) {
5636: $change = 1;
1.132 raeburn 5637: last;
1.1 raeburn 5638: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5639: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5640: $change = 1;
1.132 raeburn 5641: last;
1.1 raeburn 5642: }
5643: }
5644: }
5645: if ($change) {
5646: push(@{$changes{$key}},$item);
5647: }
1.26 raeburn 5648: }
1.1 raeburn 5649: }
5650: }
1.131 raeburn 5651: } elsif ($key eq 'lockablenames') {
5652: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5653: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5654: if (@changed) {
5655: $changes{'lockablenames'} = 1;
5656: }
5657: } else {
5658: if (@lockablenames) {
5659: $changes{'lockablenames'} = 1;
5660: }
5661: }
5662: }
5663: }
5664: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5665: if (@lockablenames) {
5666: $changes{'lockablenames'} = 1;
1.1 raeburn 5667: }
5668: }
1.26 raeburn 5669: foreach my $item (@{$types},'default') {
5670: if (defined($fields{$item})) {
5671: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5672: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5673: my $change = 0;
5674: if (ref($fields{$item}) eq 'ARRAY') {
5675: foreach my $type (@{$fields{$item}}) {
5676: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5677: $change = 1;
5678: last;
5679: }
5680: }
5681: }
5682: if ($change) {
5683: push(@{$changes{'fields'}},$item);
5684: }
5685: } else {
1.26 raeburn 5686: push(@{$changes{'fields'}},$item);
5687: }
5688: } else {
5689: push(@{$changes{'fields'}},$item);
1.1 raeburn 5690: }
5691: }
5692: }
5693: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5694: $dom);
5695: if ($putresult eq 'ok') {
5696: if (keys(%changes) > 0) {
5697: $resulttext = &mt('Changes made:').'<ul>';
5698: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5699: if ($key eq 'lockablenames') {
5700: $resulttext .= '<li>';
5701: if (@lockablenames) {
5702: $usertypes->{'default'} = $othertitle;
5703: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5704: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5705: } else {
5706: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5707: }
5708: $resulttext .= '</li>';
5709: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5710: foreach my $item (@{$changes{$key}}) {
5711: my @newvalues;
5712: foreach my $type (@{$fields{$item}}) {
5713: push(@newvalues,$fieldtitles{$type});
5714: }
1.3 raeburn 5715: my $newvaluestr;
5716: if (@newvalues > 0) {
5717: $newvaluestr = join(', ',@newvalues);
5718: } else {
5719: $newvaluestr = &mt('none');
1.6 raeburn 5720: }
1.1 raeburn 5721: if ($item eq 'default') {
1.26 raeburn 5722: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5723: } else {
1.26 raeburn 5724: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5725: }
5726: }
5727: } else {
5728: my $newvalue;
5729: if ($key eq 'run') {
5730: $newvalue = $offon[$env{'form.autoupdate_run'}];
5731: } else {
5732: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5733: }
1.1 raeburn 5734: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5735: }
5736: }
5737: $resulttext .= '</ul>';
5738: } else {
1.3 raeburn 5739: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5740: }
5741: } else {
1.11 albertel 5742: $resulttext = '<span class="LC_error">'.
5743: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5744: }
1.3 raeburn 5745: return $resulttext;
1.1 raeburn 5746: }
5747:
1.125 raeburn 5748: sub modify_autocreate {
5749: my ($dom,%domconfig) = @_;
5750: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5751: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5752: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5753: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5754: }
5755: }
5756: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5757: req => 'Auto-creation of validated requests for official courses',
5758: xmldc => 'Identity of course creator of courses from XML files',
5759: );
5760: my @types = ('xml','req');
5761: foreach my $item (@types) {
5762: $newvals{$item} = $env{'form.autocreate_'.$item};
5763: $newvals{$item} =~ s/\D//g;
5764: $newvals{$item} = 0 if ($newvals{$item} eq '');
5765: }
5766: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5767: my %domcoords = &get_active_dcs($dom);
5768: unless (exists($domcoords{$newvals{'xmldc'}})) {
5769: $newvals{'xmldc'} = '';
5770: }
5771: %autocreatehash = (
5772: autocreate => { xml => $newvals{'xml'},
5773: req => $newvals{'req'},
5774: }
5775: );
5776: if ($newvals{'xmldc'} ne '') {
5777: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5778: }
5779: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5780: $dom);
5781: if ($putresult eq 'ok') {
5782: my @items = @types;
5783: if ($newvals{'xml'}) {
5784: push(@items,'xmldc');
5785: }
5786: foreach my $item (@items) {
5787: if (exists($currautocreate{$item})) {
5788: if ($currautocreate{$item} ne $newvals{$item}) {
5789: $changes{$item} = 1;
5790: }
5791: } elsif ($newvals{$item}) {
5792: $changes{$item} = 1;
5793: }
5794: }
5795: if (keys(%changes) > 0) {
5796: my @offon = ('off','on');
5797: $resulttext = &mt('Changes made:').'<ul>';
5798: foreach my $item (@types) {
5799: if ($changes{$item}) {
5800: my $newtxt = $offon[$newvals{$item}];
5801: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5802: }
5803: }
5804: if ($changes{'xmldc'}) {
5805: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5806: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5807: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5808: }
5809: $resulttext .= '</ul>';
5810: } else {
5811: $resulttext = &mt('No changes made to auto-creation settings');
5812: }
5813: } else {
5814: $resulttext = '<span class="LC_error">'.
5815: &mt('An error occurred: [_1]',$putresult).'</span>';
5816: }
5817: return $resulttext;
5818: }
5819:
1.23 raeburn 5820: sub modify_directorysrch {
5821: my ($dom,%domconfig) = @_;
5822: my ($resulttext,%changes);
5823: my %currdirsrch;
5824: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5825: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5826: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5827: }
5828: }
5829: my %title = ( available => 'Directory search available',
1.24 raeburn 5830: localonly => 'Other domains can search',
1.23 raeburn 5831: searchby => 'Search types',
5832: searchtypes => 'Search latitude');
5833: my @offon = ('off','on');
1.24 raeburn 5834: my @otherdoms = ('Yes','No');
1.23 raeburn 5835:
1.25 raeburn 5836: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5837: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5838: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5839:
1.44 raeburn 5840: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5841: if (keys(%{$usertypes}) == 0) {
5842: @cansearch = ('default');
5843: } else {
5844: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5845: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5846: if (!grep(/^\Q$type\E$/,@cansearch)) {
5847: push(@{$changes{'cansearch'}},$type);
5848: }
1.23 raeburn 5849: }
1.26 raeburn 5850: foreach my $type (@cansearch) {
5851: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5852: push(@{$changes{'cansearch'}},$type);
5853: }
1.23 raeburn 5854: }
1.26 raeburn 5855: } else {
5856: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5857: }
5858: }
5859:
5860: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5861: foreach my $by (@{$currdirsrch{'searchby'}}) {
5862: if (!grep(/^\Q$by\E$/,@searchby)) {
5863: push(@{$changes{'searchby'}},$by);
5864: }
5865: }
5866: foreach my $by (@searchby) {
5867: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5868: push(@{$changes{'searchby'}},$by);
5869: }
5870: }
5871: } else {
5872: push(@{$changes{'searchby'}},@searchby);
5873: }
1.25 raeburn 5874:
5875: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5876: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5877: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5878: push(@{$changes{'searchtypes'}},$type);
5879: }
5880: }
5881: foreach my $type (@searchtypes) {
5882: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5883: push(@{$changes{'searchtypes'}},$type);
5884: }
5885: }
5886: } else {
5887: if (exists($currdirsrch{'searchtypes'})) {
5888: foreach my $type (@searchtypes) {
5889: if ($type ne $currdirsrch{'searchtypes'}) {
5890: push(@{$changes{'searchtypes'}},$type);
5891: }
5892: }
5893: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5894: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5895: }
5896: } else {
5897: push(@{$changes{'searchtypes'}},@searchtypes);
5898: }
5899: }
5900:
1.23 raeburn 5901: my %dirsrch_hash = (
5902: directorysrch => { available => $env{'form.dirsrch_available'},
5903: cansearch => \@cansearch,
1.24 raeburn 5904: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5905: searchby => \@searchby,
1.25 raeburn 5906: searchtypes => \@searchtypes,
1.23 raeburn 5907: }
5908: );
5909: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5910: $dom);
5911: if ($putresult eq 'ok') {
5912: if (exists($currdirsrch{'available'})) {
5913: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5914: $changes{'available'} = 1;
5915: }
5916: } else {
5917: if ($env{'form.dirsrch_available'} eq '1') {
5918: $changes{'available'} = 1;
5919: }
5920: }
1.24 raeburn 5921: if (exists($currdirsrch{'localonly'})) {
5922: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5923: $changes{'localonly'} = 1;
5924: }
5925: } else {
5926: if ($env{'form.dirsrch_localonly'} eq '1') {
5927: $changes{'localonly'} = 1;
5928: }
5929: }
1.23 raeburn 5930: if (keys(%changes) > 0) {
5931: $resulttext = &mt('Changes made:').'<ul>';
5932: if ($changes{'available'}) {
5933: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5934: }
1.24 raeburn 5935: if ($changes{'localonly'}) {
5936: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5937: }
5938:
1.23 raeburn 5939: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5940: my $chgtext;
1.26 raeburn 5941: if (ref($usertypes) eq 'HASH') {
5942: if (keys(%{$usertypes}) > 0) {
5943: foreach my $type (@{$types}) {
5944: if (grep(/^\Q$type\E$/,@cansearch)) {
5945: $chgtext .= $usertypes->{$type}.'; ';
5946: }
5947: }
5948: if (grep(/^default$/,@cansearch)) {
5949: $chgtext .= $othertitle;
5950: } else {
5951: $chgtext =~ s/\; $//;
5952: }
5953: $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 5954: }
5955: }
5956: }
5957: if (ref($changes{'searchby'}) eq 'ARRAY') {
5958: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5959: my $chgtext;
5960: foreach my $type (@{$titleorder}) {
5961: if (grep(/^\Q$type\E$/,@searchby)) {
5962: if (defined($searchtitles->{$type})) {
5963: $chgtext .= $searchtitles->{$type}.'; ';
5964: }
5965: }
5966: }
5967: $chgtext =~ s/\; $//;
5968: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5969: }
1.25 raeburn 5970: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5971: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5972: my $chgtext;
5973: foreach my $type (@{$srchtypeorder}) {
5974: if (grep(/^\Q$type\E$/,@searchtypes)) {
5975: if (defined($srchtypes_desc->{$type})) {
5976: $chgtext .= $srchtypes_desc->{$type}.'; ';
5977: }
5978: }
5979: }
5980: $chgtext =~ s/\; $//;
5981: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5982: }
5983: $resulttext .= '</ul>';
5984: } else {
5985: $resulttext = &mt('No changes made to institution directory search settings');
5986: }
5987: } else {
5988: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5989: &mt('An error occurred: [_1]',$putresult).'</span>';
5990: }
5991: return $resulttext;
5992: }
5993:
1.28 raeburn 5994: sub modify_contacts {
5995: my ($dom,%domconfig) = @_;
5996: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5997: if (ref($domconfig{'contacts'}) eq 'HASH') {
5998: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5999: $currsetting{$key} = $domconfig{'contacts'}{$key};
6000: }
6001: }
1.134 raeburn 6002: my (%others,%to,%bcc);
1.28 raeburn 6003: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6004: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6005: 'requestsmail');
1.28 raeburn 6006: foreach my $type (@mailings) {
6007: @{$newsetting{$type}} =
6008: &Apache::loncommon::get_env_multiple('form.'.$type);
6009: foreach my $item (@contacts) {
6010: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6011: $contacts_hash{contacts}{$type}{$item} = 1;
6012: } else {
6013: $contacts_hash{contacts}{$type}{$item} = 0;
6014: }
6015: }
6016: $others{$type} = $env{'form.'.$type.'_others'};
6017: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6018: if ($type eq 'helpdeskmail') {
6019: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6020: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6021: }
1.28 raeburn 6022: }
6023: foreach my $item (@contacts) {
6024: $to{$item} = $env{'form.'.$item};
6025: $contacts_hash{'contacts'}{$item} = $to{$item};
6026: }
6027: if (keys(%currsetting) > 0) {
6028: foreach my $item (@contacts) {
6029: if ($to{$item} ne $currsetting{$item}) {
6030: $changes{$item} = 1;
6031: }
6032: }
6033: foreach my $type (@mailings) {
6034: foreach my $item (@contacts) {
6035: if (ref($currsetting{$type}) eq 'HASH') {
6036: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6037: push(@{$changes{$type}},$item);
6038: }
6039: } else {
6040: push(@{$changes{$type}},@{$newsetting{$type}});
6041: }
6042: }
6043: if ($others{$type} ne $currsetting{$type}{'others'}) {
6044: push(@{$changes{$type}},'others');
6045: }
1.134 raeburn 6046: if ($type eq 'helpdeskmail') {
6047: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6048: push(@{$changes{$type}},'bcc');
6049: }
6050: }
1.28 raeburn 6051: }
6052: } else {
6053: my %default;
6054: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6055: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6056: $default{'errormail'} = 'adminemail';
6057: $default{'packagesmail'} = 'adminemail';
6058: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6059: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6060: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6061: foreach my $item (@contacts) {
6062: if ($to{$item} ne $default{$item}) {
6063: $changes{$item} = 1;
6064: }
6065: }
6066: foreach my $type (@mailings) {
6067: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6068:
6069: push(@{$changes{$type}},@{$newsetting{$type}});
6070: }
6071: if ($others{$type} ne '') {
6072: push(@{$changes{$type}},'others');
1.134 raeburn 6073: }
6074: if ($type eq 'helpdeskmail') {
6075: if ($bcc{$type} ne '') {
6076: push(@{$changes{$type}},'bcc');
6077: }
6078: }
1.28 raeburn 6079: }
6080: }
6081: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6082: $dom);
6083: if ($putresult eq 'ok') {
6084: if (keys(%changes) > 0) {
6085: my ($titles,$short_titles) = &contact_titles();
6086: $resulttext = &mt('Changes made:').'<ul>';
6087: foreach my $item (@contacts) {
6088: if ($changes{$item}) {
6089: $resulttext .= '<li>'.$titles->{$item}.
6090: &mt(' set to: ').
6091: '<span class="LC_cusr_emph">'.
6092: $to{$item}.'</span></li>';
6093: }
6094: }
6095: foreach my $type (@mailings) {
6096: if (ref($changes{$type}) eq 'ARRAY') {
6097: $resulttext .= '<li>'.$titles->{$type}.': ';
6098: my @text;
6099: foreach my $item (@{$newsetting{$type}}) {
6100: push(@text,$short_titles->{$item});
6101: }
6102: if ($others{$type} ne '') {
6103: push(@text,$others{$type});
6104: }
6105: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6106: join(', ',@text).'</span>';
6107: if ($type eq 'helpdeskmail') {
6108: if ($bcc{$type} ne '') {
6109: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6110: }
6111: }
6112: $resulttext .= '</li>';
1.28 raeburn 6113: }
6114: }
6115: $resulttext .= '</ul>';
6116: } else {
1.34 raeburn 6117: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6118: }
6119: } else {
6120: $resulttext = '<span class="LC_error">'.
6121: &mt('An error occurred: [_1].',$putresult).'</span>';
6122: }
6123: return $resulttext;
6124: }
6125:
6126: sub modify_usercreation {
1.27 raeburn 6127: my ($dom,%domconfig) = @_;
1.34 raeburn 6128: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6129: my $warningmsg;
1.27 raeburn 6130: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6131: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6132: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6133: }
6134: }
6135: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6136: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6137: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6138: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6139: foreach my $item(@contexts) {
1.45 raeburn 6140: if ($item eq 'selfcreate') {
1.50 raeburn 6141: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6142: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6143: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6144: if (ref($cancreate{$item}) eq 'ARRAY') {
6145: if (grep(/^login$/,@{$cancreate{$item}})) {
6146: $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.');
6147: }
1.43 raeburn 6148: }
6149: }
1.50 raeburn 6150: } else {
6151: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6152: }
1.34 raeburn 6153: }
1.93 raeburn 6154: my ($othertitle,$usertypes,$types) =
6155: &Apache::loncommon::sorted_inst_types($dom);
6156: if (ref($types) eq 'ARRAY') {
6157: if (@{$types} > 0) {
6158: @{$cancreate{'statustocreate'}} =
6159: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6160: } else {
6161: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6162: }
6163: push(@contexts,'statustocreate');
6164: }
1.34 raeburn 6165: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6166: foreach my $item (@contexts) {
1.93 raeburn 6167: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6168: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6169: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6170: if (ref($cancreate{$item}) eq 'ARRAY') {
6171: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6172: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6173: push(@{$changes{'cancreate'}},$item);
6174: }
1.50 raeburn 6175: }
6176: }
6177: }
6178: } else {
6179: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6180: if (@{$cancreate{$item}} > 0) {
6181: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6182: push(@{$changes{'cancreate'}},$item);
6183: }
6184: }
6185: } else {
6186: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6187: if (@{$cancreate{$item}} < 3) {
6188: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6189: push(@{$changes{'cancreate'}},$item);
6190: }
6191: }
6192: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6193: if (@{$cancreate{$item}} > 0) {
6194: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6195: push(@{$changes{'cancreate'}},$item);
6196: }
6197: }
6198: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6199: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6200: push(@{$changes{'cancreate'}},$item);
6201: }
6202: }
6203: }
6204: }
6205: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6206: foreach my $type (@{$cancreate{$item}}) {
6207: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6208: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6209: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6210: push(@{$changes{'cancreate'}},$item);
6211: }
6212: }
6213: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6214: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6215: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6216: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6217: push(@{$changes{'cancreate'}},$item);
6218: }
6219: }
6220: }
6221: }
6222: }
6223: } else {
6224: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6225: push(@{$changes{'cancreate'}},$item);
6226: }
6227: }
1.27 raeburn 6228: }
1.34 raeburn 6229: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6230: foreach my $item (@contexts) {
1.43 raeburn 6231: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6232: if ($cancreate{$item} ne 'any') {
6233: push(@{$changes{'cancreate'}},$item);
6234: }
6235: } else {
6236: if ($cancreate{$item} ne 'none') {
6237: push(@{$changes{'cancreate'}},$item);
6238: }
1.27 raeburn 6239: }
6240: }
6241: } else {
1.43 raeburn 6242: foreach my $item (@contexts) {
1.34 raeburn 6243: push(@{$changes{'cancreate'}},$item);
6244: }
1.27 raeburn 6245: }
1.34 raeburn 6246:
1.27 raeburn 6247: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6248: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6249: if (!grep(/^\Q$type\E$/,@username_rule)) {
6250: push(@{$changes{'username_rule'}},$type);
6251: }
6252: }
6253: foreach my $type (@username_rule) {
6254: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6255: push(@{$changes{'username_rule'}},$type);
6256: }
6257: }
6258: } else {
6259: push(@{$changes{'username_rule'}},@username_rule);
6260: }
6261:
1.32 raeburn 6262: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6263: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6264: if (!grep(/^\Q$type\E$/,@id_rule)) {
6265: push(@{$changes{'id_rule'}},$type);
6266: }
6267: }
6268: foreach my $type (@id_rule) {
6269: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6270: push(@{$changes{'id_rule'}},$type);
6271: }
6272: }
6273: } else {
6274: push(@{$changes{'id_rule'}},@id_rule);
6275: }
6276:
1.43 raeburn 6277: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6278: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6279: if (!grep(/^\Q$type\E$/,@email_rule)) {
6280: push(@{$changes{'email_rule'}},$type);
6281: }
6282: }
6283: foreach my $type (@email_rule) {
6284: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6285: push(@{$changes{'email_rule'}},$type);
6286: }
6287: }
6288: } else {
6289: push(@{$changes{'email_rule'}},@email_rule);
6290: }
6291:
6292: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6293: my @authtypes = ('int','krb4','krb5','loc');
6294: my %authhash;
1.43 raeburn 6295: foreach my $item (@authen_contexts) {
1.28 raeburn 6296: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6297: foreach my $auth (@authtypes) {
6298: if (grep(/^\Q$auth\E$/,@authallowed)) {
6299: $authhash{$item}{$auth} = 1;
6300: } else {
6301: $authhash{$item}{$auth} = 0;
6302: }
6303: }
6304: }
6305: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6306: foreach my $item (@authen_contexts) {
1.28 raeburn 6307: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6308: foreach my $auth (@authtypes) {
6309: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6310: push(@{$changes{'authtypes'}},$item);
6311: last;
6312: }
6313: }
6314: }
6315: }
6316: } else {
1.43 raeburn 6317: foreach my $item (@authen_contexts) {
1.28 raeburn 6318: push(@{$changes{'authtypes'}},$item);
6319: }
6320: }
6321:
1.27 raeburn 6322: my %usercreation_hash = (
1.28 raeburn 6323: usercreation => {
1.34 raeburn 6324: cancreate => \%cancreate,
1.27 raeburn 6325: username_rule => \@username_rule,
1.32 raeburn 6326: id_rule => \@id_rule,
1.43 raeburn 6327: email_rule => \@email_rule,
1.32 raeburn 6328: authtypes => \%authhash,
1.27 raeburn 6329: }
6330: );
6331:
6332: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6333: $dom);
1.50 raeburn 6334:
6335: my %selfcreatetypes = (
6336: sso => 'users authenticated by institutional single sign on',
6337: login => 'users authenticated by institutional log-in',
6338: email => 'users who provide a valid e-mail address for use as the username',
6339: );
1.27 raeburn 6340: if ($putresult eq 'ok') {
6341: if (keys(%changes) > 0) {
6342: $resulttext = &mt('Changes made:').'<ul>';
6343: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6344: my %lt = &usercreation_types();
6345: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6346: my $chgtext;
6347: unless ($type eq 'statustocreate') {
6348: $chgtext = $lt{$type}.', ';
6349: }
1.45 raeburn 6350: if ($type eq 'selfcreate') {
1.50 raeburn 6351: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6352: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6353: } else {
1.100 raeburn 6354: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6355: foreach my $case (@{$cancreate{$type}}) {
6356: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6357: }
6358: $chgtext .= '</ul>';
1.100 raeburn 6359: if (ref($cancreate{$type}) eq 'ARRAY') {
6360: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6361: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6362: if (@{$cancreate{'statustocreate'}} == 0) {
6363: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6364: }
6365: }
6366: }
6367: }
1.43 raeburn 6368: }
1.93 raeburn 6369: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6370: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6371: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6372: if (@{$cancreate{'selfcreate'}} > 0) {
6373: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6374:
6375: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6376: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6377: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6378: }
1.96 raeburn 6379: } elsif (ref($usertypes) eq 'HASH') {
6380: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6381: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6382: } else {
6383: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6384: }
6385: $chgtext .= '<ul>';
6386: foreach my $case (@{$cancreate{$type}}) {
6387: if ($case eq 'default') {
6388: $chgtext .= '<li>'.$othertitle.'</li>';
6389: } else {
6390: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6391: }
6392: }
1.100 raeburn 6393: $chgtext .= '</ul>';
6394: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6395: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6396: }
6397: }
6398: } else {
6399: if (@{$cancreate{$type}} == 0) {
6400: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6401: } else {
6402: $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 6403: }
6404: }
6405: }
1.43 raeburn 6406: } else {
6407: if ($cancreate{$type} eq 'none') {
6408: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6409: } elsif ($cancreate{$type} eq 'any') {
6410: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6411: } elsif ($cancreate{$type} eq 'official') {
6412: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6413: } elsif ($cancreate{$type} eq 'unofficial') {
6414: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6415: }
1.34 raeburn 6416: }
6417: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6418: }
6419: }
6420: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6421: my ($rules,$ruleorder) =
6422: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6423: my $chgtext = '<ul>';
6424: foreach my $type (@username_rule) {
6425: if (ref($rules->{$type}) eq 'HASH') {
6426: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6427: }
6428: }
6429: $chgtext .= '</ul>';
6430: if (@username_rule > 0) {
6431: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6432: } else {
1.28 raeburn 6433: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6434: }
6435: }
1.32 raeburn 6436: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6437: my ($idrules,$idruleorder) =
6438: &Apache::lonnet::inst_userrules($dom,'id');
6439: my $chgtext = '<ul>';
6440: foreach my $type (@id_rule) {
6441: if (ref($idrules->{$type}) eq 'HASH') {
6442: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6443: }
6444: }
6445: $chgtext .= '</ul>';
6446: if (@id_rule > 0) {
6447: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6448: } else {
6449: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6450: }
6451: }
1.43 raeburn 6452: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6453: my ($emailrules,$emailruleorder) =
6454: &Apache::lonnet::inst_userrules($dom,'email');
6455: my $chgtext = '<ul>';
6456: foreach my $type (@email_rule) {
6457: if (ref($emailrules->{$type}) eq 'HASH') {
6458: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6459: }
6460: }
6461: $chgtext .= '</ul>';
6462: if (@email_rule > 0) {
6463: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6464: } else {
6465: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6466: }
6467: }
6468:
1.28 raeburn 6469: my %authname = &authtype_names();
6470: my %context_title = &context_names();
6471: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6472: my $chgtext = '<ul>';
6473: foreach my $type (@{$changes{'authtypes'}}) {
6474: my @allowed;
6475: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6476: foreach my $auth (@authtypes) {
6477: if ($authhash{$type}{$auth}) {
6478: push(@allowed,$authname{$auth});
6479: }
6480: }
1.43 raeburn 6481: if (@allowed > 0) {
6482: $chgtext .= join(', ',@allowed).'</li>';
6483: } else {
6484: $chgtext .= &mt('none').'</li>';
6485: }
1.28 raeburn 6486: }
6487: $chgtext .= '</ul>';
6488: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6489: $resulttext .= '</li>';
6490: }
1.27 raeburn 6491: $resulttext .= '</ul>';
6492: } else {
1.28 raeburn 6493: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 6494: }
6495: } else {
6496: $resulttext = '<span class="LC_error">'.
1.23 raeburn 6497: &mt('An error occurred: [_1]',$putresult).'</span>';
6498: }
1.43 raeburn 6499: if ($warningmsg ne '') {
6500: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6501: }
1.23 raeburn 6502: return $resulttext;
6503: }
6504:
1.33 raeburn 6505: sub modify_usermodification {
6506: my ($dom,%domconfig) = @_;
6507: my ($resulttext,%curr_usermodification,%changes);
6508: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6509: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6510: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6511: }
6512: }
1.63 raeburn 6513: my @contexts = ('author','course','selfcreate');
1.33 raeburn 6514: my %context_title = (
6515: author => 'In author context',
6516: course => 'In course context',
1.63 raeburn 6517: selfcreate => 'When self creating account',
1.33 raeburn 6518: );
6519: my @fields = ('lastname','firstname','middlename','generation',
6520: 'permanentemail','id');
6521: my %roles = (
6522: author => ['ca','aa'],
6523: course => ['st','ep','ta','in','cr'],
6524: );
1.63 raeburn 6525: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6526: if (ref($types) eq 'ARRAY') {
6527: push(@{$types},'default');
6528: $usertypes->{'default'} = $othertitle;
6529: }
6530: $roles{'selfcreate'} = $types;
1.33 raeburn 6531: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6532: my %modifyhash;
6533: foreach my $context (@contexts) {
6534: foreach my $role (@{$roles{$context}}) {
6535: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6536: foreach my $item (@fields) {
6537: if (grep(/^\Q$item\E$/,@modifiable)) {
6538: $modifyhash{$context}{$role}{$item} = 1;
6539: } else {
6540: $modifyhash{$context}{$role}{$item} = 0;
6541: }
6542: }
6543: }
6544: if (ref($curr_usermodification{$context}) eq 'HASH') {
6545: foreach my $role (@{$roles{$context}}) {
6546: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6547: foreach my $field (@fields) {
6548: if ($modifyhash{$context}{$role}{$field} ne
6549: $curr_usermodification{$context}{$role}{$field}) {
6550: push(@{$changes{$context}},$role);
6551: last;
6552: }
6553: }
6554: }
6555: }
6556: } else {
6557: foreach my $context (@contexts) {
6558: foreach my $role (@{$roles{$context}}) {
6559: push(@{$changes{$context}},$role);
6560: }
6561: }
6562: }
6563: }
6564: my %usermodification_hash = (
6565: usermodification => \%modifyhash,
6566: );
6567: my $putresult = &Apache::lonnet::put_dom('configuration',
6568: \%usermodification_hash,$dom);
6569: if ($putresult eq 'ok') {
6570: if (keys(%changes) > 0) {
6571: $resulttext = &mt('Changes made: ').'<ul>';
6572: foreach my $context (@contexts) {
6573: if (ref($changes{$context}) eq 'ARRAY') {
6574: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6575: if (ref($changes{$context}) eq 'ARRAY') {
6576: foreach my $role (@{$changes{$context}}) {
6577: my $rolename;
1.63 raeburn 6578: if ($context eq 'selfcreate') {
6579: $rolename = $role;
6580: if (ref($usertypes) eq 'HASH') {
6581: if ($usertypes->{$role} ne '') {
6582: $rolename = $usertypes->{$role};
6583: }
6584: }
1.33 raeburn 6585: } else {
1.63 raeburn 6586: if ($role eq 'cr') {
6587: $rolename = &mt('Custom');
6588: } else {
6589: $rolename = &Apache::lonnet::plaintext($role);
6590: }
1.33 raeburn 6591: }
6592: my @modifiable;
1.63 raeburn 6593: if ($context eq 'selfcreate') {
1.126 bisitz 6594: $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 6595: } else {
6596: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6597: }
1.33 raeburn 6598: foreach my $field (@fields) {
6599: if ($modifyhash{$context}{$role}{$field}) {
6600: push(@modifiable,$fieldtitles{$field});
6601: }
6602: }
6603: if (@modifiable > 0) {
6604: $resulttext .= join(', ',@modifiable);
6605: } else {
6606: $resulttext .= &mt('none');
6607: }
6608: $resulttext .= '</li>';
6609: }
6610: $resulttext .= '</ul></li>';
6611: }
6612: }
6613: }
6614: $resulttext .= '</ul>';
6615: } else {
6616: $resulttext = &mt('No changes made to user modification settings');
6617: }
6618: } else {
6619: $resulttext = '<span class="LC_error">'.
6620: &mt('An error occurred: [_1]',$putresult).'</span>';
6621: }
6622: return $resulttext;
6623: }
6624:
1.43 raeburn 6625: sub modify_defaults {
6626: my ($dom,$r) = @_;
6627: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6628: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6629: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6630: my @authtypes = ('internal','krb4','krb5','localauth');
6631: foreach my $item (@items) {
6632: $newvalues{$item} = $env{'form.'.$item};
6633: if ($item eq 'auth_def') {
6634: if ($newvalues{$item} ne '') {
6635: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6636: push(@errors,$item);
6637: }
6638: }
6639: } elsif ($item eq 'lang_def') {
6640: if ($newvalues{$item} ne '') {
6641: if ($newvalues{$item} =~ /^(\w+)/) {
6642: my $langcode = $1;
1.103 raeburn 6643: if ($langcode ne 'x_chef') {
6644: if (code2language($langcode) eq '') {
6645: push(@errors,$item);
6646: }
1.43 raeburn 6647: }
6648: } else {
6649: push(@errors,$item);
6650: }
6651: }
1.54 raeburn 6652: } elsif ($item eq 'timezone_def') {
6653: if ($newvalues{$item} ne '') {
1.62 raeburn 6654: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6655: push(@errors,$item);
6656: }
6657: }
1.68 raeburn 6658: } elsif ($item eq 'datelocale_def') {
6659: if ($newvalues{$item} ne '') {
6660: my @datelocale_ids = DateTime::Locale->ids();
6661: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6662: push(@errors,$item);
6663: }
6664: }
1.141 raeburn 6665: } elsif ($item eq 'portal_def') {
6666: if ($newvalues{$item} ne '') {
6667: 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])\/?$/) {
6668: push(@errors,$item);
6669: }
6670: }
1.43 raeburn 6671: }
6672: if (grep(/^\Q$item\E$/,@errors)) {
6673: $newvalues{$item} = $domdefaults{$item};
6674: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6675: $changes{$item} = 1;
6676: }
1.72 raeburn 6677: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6678: }
6679: my %defaults_hash = (
1.72 raeburn 6680: defaults => \%newvalues,
6681: );
1.43 raeburn 6682: my $title = &defaults_titles();
6683: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6684: $dom);
6685: if ($putresult eq 'ok') {
6686: if (keys(%changes) > 0) {
6687: $resulttext = &mt('Changes made:').'<ul>';
6688: my $version = $r->dir_config('lonVersion');
6689: 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";
6690: foreach my $item (sort(keys(%changes))) {
6691: my $value = $env{'form.'.$item};
6692: if ($value eq '') {
6693: $value = &mt('none');
6694: } elsif ($item eq 'auth_def') {
6695: my %authnames = &authtype_names();
6696: my %shortauth = (
6697: internal => 'int',
6698: krb4 => 'krb4',
6699: krb5 => 'krb5',
6700: localauth => 'loc',
6701: );
6702: $value = $authnames{$shortauth{$value}};
6703: }
6704: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6705: $mailmsgtext .= "$title->{$item} set to $value\n";
6706: }
6707: $resulttext .= '</ul>';
6708: $mailmsgtext .= "\n";
6709: my $cachetime = 24*60*60;
1.72 raeburn 6710: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6711: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6712: my $sysmail = $r->dir_config('lonSysEMail');
6713: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6714: }
1.43 raeburn 6715: } else {
1.54 raeburn 6716: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6717: }
6718: } else {
6719: $resulttext = '<span class="LC_error">'.
6720: &mt('An error occurred: [_1]',$putresult).'</span>';
6721: }
6722: if (@errors > 0) {
6723: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6724: foreach my $item (@errors) {
6725: $resulttext .= ' "'.$title->{$item}.'",';
6726: }
6727: $resulttext =~ s/,$//;
6728: }
6729: return $resulttext;
6730: }
6731:
1.46 raeburn 6732: sub modify_scantron {
1.48 raeburn 6733: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6734: my ($resulttext,%confhash,%changes,$errors);
6735: my $custom = 'custom.tab';
6736: my $default = 'default.tab';
6737: my $servadm = $r->dir_config('lonAdmEMail');
6738: my ($configuserok,$author_ok,$switchserver) =
6739: &config_check($dom,$confname,$servadm);
6740: if ($env{'form.scantronformat.filename'} ne '') {
6741: my $error;
6742: if ($configuserok eq 'ok') {
6743: if ($switchserver) {
1.130 raeburn 6744: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6745: } else {
6746: if ($author_ok eq 'ok') {
6747: my ($result,$scantronurl) =
6748: &publishlogo($r,'upload','scantronformat',$dom,
6749: $confname,'scantron','','',$custom);
6750: if ($result eq 'ok') {
6751: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6752: $changes{'scantronformat'} = 1;
1.46 raeburn 6753: } else {
6754: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6755: }
6756: } else {
6757: $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);
6758: }
6759: }
6760: } else {
6761: $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);
6762: }
6763: if ($error) {
6764: &Apache::lonnet::logthis($error);
6765: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6766: }
6767: }
1.48 raeburn 6768: if (ref($domconfig{'scantron'}) eq 'HASH') {
6769: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6770: if ($env{'form.scantronformat_del'}) {
6771: $confhash{'scantron'}{'scantronformat'} = '';
6772: $changes{'scantronformat'} = 1;
1.46 raeburn 6773: }
6774: }
6775: }
6776: if (keys(%confhash) > 0) {
6777: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6778: $dom);
6779: if ($putresult eq 'ok') {
6780: if (keys(%changes) > 0) {
1.48 raeburn 6781: if (ref($confhash{'scantron'}) eq 'HASH') {
6782: $resulttext = &mt('Changes made:').'<ul>';
6783: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6784: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6785: } else {
1.130 raeburn 6786: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6787: }
1.48 raeburn 6788: $resulttext .= '</ul>';
6789: } else {
1.130 raeburn 6790: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6791: }
6792: $resulttext .= '</ul>';
6793: &Apache::loncommon::devalidate_domconfig_cache($dom);
6794: } else {
1.130 raeburn 6795: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6796: }
6797: } else {
6798: $resulttext = '<span class="LC_error">'.
6799: &mt('An error occurred: [_1]',$putresult).'</span>';
6800: }
6801: } else {
1.130 raeburn 6802: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6803: }
6804: if ($errors) {
6805: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6806: $errors.'</ul>';
6807: }
6808: return $resulttext;
6809: }
6810:
1.48 raeburn 6811: sub modify_coursecategories {
6812: my ($dom,%domconfig) = @_;
1.57 raeburn 6813: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6814: $cathash);
1.48 raeburn 6815: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6816: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6817: $cathash = $domconfig{'coursecategories'}{'cats'};
6818: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6819: $changes{'togglecats'} = 1;
6820: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6821: }
6822: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6823: $changes{'categorize'} = 1;
6824: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6825: }
1.120 raeburn 6826: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6827: $changes{'togglecatscomm'} = 1;
6828: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6829: }
6830: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6831: $changes{'categorizecomm'} = 1;
6832: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6833: }
1.57 raeburn 6834: } else {
6835: $changes{'togglecats'} = 1;
6836: $changes{'categorize'} = 1;
1.124 raeburn 6837: $changes{'togglecatscomm'} = 1;
6838: $changes{'categorizecomm'} = 1;
1.87 raeburn 6839: $domconfig{'coursecategories'} = {
6840: togglecats => $env{'form.togglecats'},
6841: categorize => $env{'form.categorize'},
1.124 raeburn 6842: togglecatscomm => $env{'form.togglecatscomm'},
6843: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6844: };
1.57 raeburn 6845: }
6846: if (ref($cathash) eq 'HASH') {
6847: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6848: push (@deletecategory,'instcode::0');
6849: }
1.120 raeburn 6850: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6851: push(@deletecategory,'communities::0');
6852: }
1.48 raeburn 6853: }
1.57 raeburn 6854: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6855: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6856: if (@deletecategory > 0) {
6857: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6858: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6859: foreach my $item (@deletecategory) {
1.57 raeburn 6860: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6861: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6862: $deletions{$item} = 1;
1.57 raeburn 6863: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6864: }
6865: }
6866: }
1.57 raeburn 6867: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6868: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6869: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6870: $reorderings{$item} = 1;
1.57 raeburn 6871: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6872: }
6873: if ($env{'form.addcategory_name_'.$item} ne '') {
6874: my $newcat = $env{'form.addcategory_name_'.$item};
6875: my $newdepth = $depth+1;
6876: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6877: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6878: $adds{$newitem} = 1;
6879: }
6880: if ($env{'form.subcat_'.$item} ne '') {
6881: my $newcat = $env{'form.subcat_'.$item};
6882: my $newdepth = $depth+1;
6883: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6884: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6885: $adds{$newitem} = 1;
6886: }
6887: }
6888: }
6889: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6890: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6891: my $newitem = 'instcode::0';
1.57 raeburn 6892: if ($cathash->{$newitem} eq '') {
6893: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6894: $adds{$newitem} = 1;
6895: }
6896: } else {
6897: my $newitem = 'instcode::0';
1.57 raeburn 6898: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6899: $adds{$newitem} = 1;
6900: }
6901: }
1.120 raeburn 6902: if ($env{'form.communities'} eq '1') {
6903: if (ref($cathash) eq 'HASH') {
6904: my $newitem = 'communities::0';
6905: if ($cathash->{$newitem} eq '') {
6906: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6907: $adds{$newitem} = 1;
6908: }
6909: } else {
6910: my $newitem = 'communities::0';
6911: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6912: $adds{$newitem} = 1;
6913: }
6914: }
1.48 raeburn 6915: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6916: if (($env{'form.addcategory_name'} ne 'instcode') &&
6917: ($env{'form.addcategory_name'} ne 'communities')) {
6918: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6919: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6920: $adds{$newitem} = 1;
6921: }
1.48 raeburn 6922: }
1.57 raeburn 6923: my $putresult;
1.48 raeburn 6924: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6925: if (keys(%deletions) > 0) {
6926: foreach my $key (keys(%deletions)) {
6927: if ($predelallitems{$key} ne '') {
6928: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6929: }
6930: }
6931: }
6932: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6933: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6934: if (ref($chkcats[0]) eq 'ARRAY') {
6935: my $depth = 0;
6936: my $chg = 0;
6937: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6938: my $name = $chkcats[0][$i];
6939: my $item;
6940: if ($name eq '') {
6941: $chg ++;
6942: } else {
6943: $item = &escape($name).'::0';
6944: if ($chg) {
1.57 raeburn 6945: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6946: }
6947: $depth ++;
1.57 raeburn 6948: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6949: $depth --;
6950: }
6951: }
6952: }
1.57 raeburn 6953: }
6954: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6955: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6956: if ($putresult eq 'ok') {
1.57 raeburn 6957: my %title = (
1.120 raeburn 6958: togglecats => 'Show/Hide a course in catalog',
6959: categorize => 'Assign a category to a course',
6960: togglecatscomm => 'Show/Hide a community in catalog',
6961: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6962: );
6963: my %level = (
1.120 raeburn 6964: dom => 'set in Domain ("Modify Course/Community")',
6965: crs => 'set in Course ("Course Configuration")',
6966: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6967: );
1.48 raeburn 6968: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6969: if ($changes{'togglecats'}) {
6970: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6971: }
6972: if ($changes{'categorize'}) {
6973: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6974: }
1.120 raeburn 6975: if ($changes{'togglecatscomm'}) {
6976: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6977: }
6978: if ($changes{'categorizecomm'}) {
6979: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6980: }
1.57 raeburn 6981: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6982: my $cathash;
6983: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6984: $cathash = $domconfig{'coursecategories'}{'cats'};
6985: } else {
6986: $cathash = {};
6987: }
6988: my (@cats,@trails,%allitems);
6989: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6990: if (keys(%deletions) > 0) {
6991: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6992: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6993: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6994: }
6995: $resulttext .= '</ul></li>';
6996: }
6997: if (keys(%reorderings) > 0) {
6998: my %sort_by_trail;
6999: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7000: foreach my $key (keys(%reorderings)) {
7001: if ($allitems{$key} ne '') {
7002: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7003: }
1.48 raeburn 7004: }
1.57 raeburn 7005: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7006: $resulttext .= '<li>'.$trails[$trail].'</li>';
7007: }
7008: $resulttext .= '</ul></li>';
1.48 raeburn 7009: }
1.57 raeburn 7010: if (keys(%adds) > 0) {
7011: my %sort_by_trail;
7012: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7013: foreach my $key (keys(%adds)) {
7014: if ($allitems{$key} ne '') {
7015: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7016: }
7017: }
7018: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7019: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7020: }
1.57 raeburn 7021: $resulttext .= '</ul></li>';
1.48 raeburn 7022: }
7023: }
7024: $resulttext .= '</ul>';
7025: } else {
7026: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7027: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7028: }
7029: } else {
1.120 raeburn 7030: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7031: }
7032: return $resulttext;
7033: }
7034:
1.69 raeburn 7035: sub modify_serverstatuses {
7036: my ($dom,%domconfig) = @_;
7037: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7038: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7039: %currserverstatus = %{$domconfig{'serverstatuses'}};
7040: }
7041: my @pages = &serverstatus_pages();
7042: foreach my $type (@pages) {
7043: $newserverstatus{$type}{'namedusers'} = '';
7044: $newserverstatus{$type}{'machines'} = '';
7045: if (defined($env{'form.'.$type.'_namedusers'})) {
7046: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7047: my @okusers;
7048: foreach my $user (@users) {
7049: my ($uname,$udom) = split(/:/,$user);
7050: if (($udom =~ /^$match_domain$/) &&
7051: (&Apache::lonnet::domain($udom)) &&
7052: ($uname =~ /^$match_username$/)) {
7053: if (!grep(/^\Q$user\E/,@okusers)) {
7054: push(@okusers,$user);
7055: }
7056: }
7057: }
7058: if (@okusers > 0) {
7059: @okusers = sort(@okusers);
7060: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7061: }
7062: }
7063: if (defined($env{'form.'.$type.'_machines'})) {
7064: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7065: my @okmachines;
7066: foreach my $ip (@machines) {
7067: my @parts = split(/\./,$ip);
7068: next if (@parts < 4);
7069: my $badip = 0;
7070: for (my $i=0; $i<4; $i++) {
7071: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7072: $badip = 1;
7073: last;
7074: }
7075: }
7076: if (!$badip) {
7077: push(@okmachines,$ip);
7078: }
7079: }
7080: @okmachines = sort(@okmachines);
7081: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7082: }
7083: }
7084: my %serverstatushash = (
7085: serverstatuses => \%newserverstatus,
7086: );
7087: foreach my $type (@pages) {
1.83 raeburn 7088: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7089: my (@current,@new);
1.83 raeburn 7090: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7091: if ($currserverstatus{$type}{$setting} ne '') {
7092: @current = split(/,/,$currserverstatus{$type}{$setting});
7093: }
7094: }
7095: if ($newserverstatus{$type}{$setting} ne '') {
7096: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7097: }
7098: if (@current > 0) {
7099: if (@new > 0) {
7100: foreach my $item (@current) {
7101: if (!grep(/^\Q$item\E$/,@new)) {
7102: $changes{$type}{$setting} = 1;
1.82 raeburn 7103: last;
7104: }
7105: }
1.84 raeburn 7106: foreach my $item (@new) {
7107: if (!grep(/^\Q$item\E$/,@current)) {
7108: $changes{$type}{$setting} = 1;
7109: last;
1.82 raeburn 7110: }
7111: }
7112: } else {
1.83 raeburn 7113: $changes{$type}{$setting} = 1;
1.69 raeburn 7114: }
1.83 raeburn 7115: } elsif (@new > 0) {
7116: $changes{$type}{$setting} = 1;
1.69 raeburn 7117: }
7118: }
7119: }
7120: if (keys(%changes) > 0) {
1.81 raeburn 7121: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7122: my $putresult = &Apache::lonnet::put_dom('configuration',
7123: \%serverstatushash,$dom);
7124: if ($putresult eq 'ok') {
7125: $resulttext .= &mt('Changes made:').'<ul>';
7126: foreach my $type (@pages) {
1.84 raeburn 7127: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7128: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7129: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7130: if ($newserverstatus{$type}{'namedusers'} eq '') {
7131: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7132: } else {
7133: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7134: }
1.84 raeburn 7135: }
7136: if ($changes{$type}{'machines'}) {
1.69 raeburn 7137: if ($newserverstatus{$type}{'machines'} eq '') {
7138: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7139: } else {
7140: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7141: }
7142:
7143: }
7144: $resulttext .= '</ul></li>';
7145: }
7146: }
7147: $resulttext .= '</ul>';
7148: } else {
7149: $resulttext = '<span class="LC_error">'.
7150: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7151:
7152: }
7153: } else {
7154: $resulttext = &mt('No changes made to access to server status pages');
7155: }
7156: return $resulttext;
7157: }
7158:
1.118 jms 7159: sub modify_helpsettings {
1.122 jms 7160: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 7161: my ($resulttext,$errors,%changes,%helphash);
7162:
1.122 jms 7163: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7164: my $defaulthelpfile = 'defaulthelp.html';
7165: my $servadm = $r->dir_config('lonAdmEMail');
7166: my ($configuserok,$author_ok,$switchserver) =
7167: &config_check($dom,$confname,$servadm);
7168:
1.118 jms 7169: my %defaultchecked = ('submitbugs' => 'on');
7170: my @offon = ('off','on');
1.122 jms 7171: my %title = ( submitbugs => 'Display link for users to submit a bug',
7172: loginhelpurl => 'Unauthenticated login help page set to custom file');
7173:
1.118 jms 7174: my @toggles = ('submitbugs');
7175:
7176: $helphash{'helpsettings'} = {};
7177:
7178: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7179: if ($domconfig{'helpsettings'} eq '') {
7180: $domconfig{'helpsettings'} = {};
7181: }
7182: }
7183:
7184: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7185:
7186: foreach my $item (@toggles) {
7187:
7188: if ($defaultchecked{$item} eq 'on') {
7189: if (($domconfig{'helpsettings'}{$item} eq '') &&
7190: ($env{'form.'.$item} eq '0')) {
7191: $changes{$item} = 1;
7192: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7193: $changes{$item} = 1;
7194: }
7195: } elsif ($defaultchecked{$item} eq 'off') {
7196: if (($domconfig{'helpsettings'}{$item} eq '') &&
7197: ($env{'form.'.$item} eq '1')) {
7198: $changes{$item} = 1;
7199: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7200: $changes{$item} = 1;
7201: }
7202: }
7203: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7204: }
7205:
7206: if ($customhelpfile ne '') {
7207: my $error;
7208: if ($configuserok eq 'ok') {
7209: if ($switchserver) {
7210: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7211: } else {
7212: if ($author_ok eq 'ok') {
7213: my ($result,$loginhelpurl) =
7214: &publishlogo($r,'upload','loginhelpurl',$dom,
7215: $confname,'help','','',$customhelpfile);
7216: if ($result eq 'ok') {
7217: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7218: $changes{'loginhelpurl'} = 1;
7219: } else {
7220: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7221: }
7222: } else {
7223: $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);
7224: }
7225: }
7226: } else {
7227: $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);
7228: }
7229: if ($error) {
7230: &Apache::lonnet::logthis($error);
7231: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7232: }
7233: }
7234:
7235: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7236: if ($env{'form.loginhelpurl_del'}) {
7237: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7238: $changes{'loginhelpurl'} = 1;
7239: }
7240: }
1.118 jms 7241: }
7242:
1.123 jms 7243:
7244: my $putresult;
7245:
7246: if (keys(%changes) > 0) {
7247: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7248: } else {
7249: $putresult = 'ok';
7250: }
1.118 jms 7251:
7252: if ($putresult eq 'ok') {
7253: if (keys(%changes) > 0) {
7254: $resulttext = &mt('Changes made:').'<ul>';
7255: foreach my $item (sort(keys(%changes))) {
7256: if ($item eq 'submitbugs') {
7257: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7258: }
1.122 jms 7259: if ($item eq 'loginhelpurl') {
7260: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7261: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7262: } else {
7263: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7264: }
7265: }
1.118 jms 7266: }
7267: $resulttext .= '</ul>';
7268: } else {
7269: $resulttext = &mt('No changes made to help settings');
7270: }
7271: } else {
7272: $resulttext = '<span class="LC_error">'.
7273: &mt('An error occurred: [_1]',$putresult).'</span>';
7274: }
7275: if ($errors) {
7276: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7277: $errors.'</ul>';
7278: }
7279: return $resulttext;
7280: }
7281:
1.121 raeburn 7282: sub modify_coursedefaults {
7283: my ($dom,%domconfig) = @_;
7284: my ($resulttext,$errors,%changes,%defaultshash);
7285: my %defaultchecked = ('canuse_pdfforms' => 'off');
7286: my @offon = ('off','on');
7287: my @toggles = ('canuse_pdfforms');
7288:
7289: $defaultshash{'coursedefaults'} = {};
7290:
7291: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7292: if ($domconfig{'coursedefaults'} eq '') {
7293: $domconfig{'coursedefaults'} = {};
7294: }
7295: }
7296:
7297: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7298: foreach my $item (@toggles) {
7299: if ($defaultchecked{$item} eq 'on') {
7300: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7301: ($env{'form.'.$item} eq '0')) {
7302: $changes{$item} = 1;
7303: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7304: $changes{$item} = 1;
7305: }
7306: } elsif ($defaultchecked{$item} eq 'off') {
7307: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7308: ($env{'form.'.$item} eq '1')) {
7309: $changes{$item} = 1;
7310: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7311: $changes{$item} = 1;
7312: }
7313: }
7314: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7315: }
1.139 raeburn 7316: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7317: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7318: $newdefresponder =~ s/\D//g;
7319: if ($newdefresponder eq '' || $newdefresponder < 1) {
7320: $newdefresponder = 1;
7321: }
7322: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7323: if ($currdefresponder ne $newdefresponder) {
7324: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7325: $changes{'anonsurvey_threshold'} = 1;
7326: }
7327: }
1.121 raeburn 7328: }
7329: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7330: $dom);
7331: if ($putresult eq 'ok') {
7332: if (keys(%changes) > 0) {
7333: if ($changes{'canuse_pdfforms'}) {
7334: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7335: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7336: my $cachetime = 24*60*60;
7337: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7338: }
7339: $resulttext = &mt('Changes made:').'<ul>';
7340: foreach my $item (sort(keys(%changes))) {
7341: if ($item eq 'canuse_pdfforms') {
7342: if ($env{'form.'.$item} eq '1') {
7343: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7344: } else {
7345: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7346: }
1.139 raeburn 7347: } elsif ($item eq 'anonsurvey_threshold') {
7348: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7349: }
1.121 raeburn 7350: }
7351: $resulttext .= '</ul>';
7352: } else {
7353: $resulttext = &mt('No changes made to course defaults');
7354: }
7355: } else {
7356: $resulttext = '<span class="LC_error">'.
7357: &mt('An error occurred: [_1]',$putresult).'</span>';
7358: }
7359: return $resulttext;
7360: }
7361:
1.137 raeburn 7362: sub modify_usersessions {
7363: my ($dom,%domconfig) = @_;
1.145 raeburn 7364: my @hostingtypes = ('version','excludedomain','includedomain');
7365: my @offloadtypes = ('primary','default');
7366: my %types = (
7367: remote => \@hostingtypes,
7368: hosted => \@hostingtypes,
7369: spares => \@offloadtypes,
7370: );
7371: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7372: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7373: my (%by_ip,%by_location,@intdoms);
7374: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7375: my @locations = sort(keys(%by_location));
1.137 raeburn 7376: my (%defaultshash,%changes);
7377: foreach my $prefix (@prefixes) {
7378: $defaultshash{'usersessions'}{$prefix} = {};
7379: }
7380: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7381: my $resulttext;
1.138 raeburn 7382: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7383: foreach my $prefix (@prefixes) {
1.145 raeburn 7384: next if ($prefix eq 'spares');
7385: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7386: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7387: if ($type eq 'version') {
7388: my $value = $env{'form.'.$prefix.'_'.$type};
7389: my $okvalue;
7390: if ($value ne '') {
7391: if (grep(/^\Q$value\E$/,@lcversions)) {
7392: $okvalue = $value;
7393: }
7394: }
7395: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7396: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7397: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7398: if ($inuse == 0) {
7399: $changes{$prefix}{$type} = 1;
7400: } else {
7401: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7402: $changes{$prefix}{$type} = 1;
7403: }
7404: if ($okvalue ne '') {
7405: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7406: }
7407: }
7408: } else {
7409: if (($inuse == 1) && ($okvalue ne '')) {
7410: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7411: $changes{$prefix}{$type} = 1;
7412: }
7413: }
7414: } else {
7415: if (($inuse == 1) && ($okvalue ne '')) {
7416: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7417: $changes{$prefix}{$type} = 1;
7418: }
7419: }
7420: } else {
7421: if (($inuse == 1) && ($okvalue ne '')) {
7422: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7423: $changes{$prefix}{$type} = 1;
7424: }
7425: }
7426: } else {
7427: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7428: my @okvals;
7429: foreach my $val (@vals) {
1.138 raeburn 7430: if ($val =~ /:/) {
7431: my @items = split(/:/,$val);
7432: foreach my $item (@items) {
7433: if (ref($by_location{$item}) eq 'ARRAY') {
7434: push(@okvals,$item);
7435: }
7436: }
7437: } else {
7438: if (ref($by_location{$val}) eq 'ARRAY') {
7439: push(@okvals,$val);
7440: }
1.137 raeburn 7441: }
7442: }
7443: @okvals = sort(@okvals);
7444: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7445: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7446: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7447: if ($inuse == 0) {
7448: $changes{$prefix}{$type} = 1;
7449: } else {
7450: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7451: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7452: if (@changed > 0) {
7453: $changes{$prefix}{$type} = 1;
7454: }
7455: }
7456: } else {
7457: if ($inuse == 1) {
7458: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7459: $changes{$prefix}{$type} = 1;
7460: }
7461: }
7462: } else {
7463: if ($inuse == 1) {
7464: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7465: $changes{$prefix}{$type} = 1;
7466: }
7467: }
7468: } else {
7469: if ($inuse == 1) {
7470: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7471: $changes{$prefix}{$type} = 1;
7472: }
7473: }
7474: }
7475: }
7476: }
1.145 raeburn 7477:
7478: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7479: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7480: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7481: my $savespares;
7482:
7483: foreach my $lonhost (sort(keys(%servers))) {
7484: my $serverhomeID =
7485: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 7486: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7487: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7488: my %spareschg;
7489: foreach my $type (@{$types{'spares'}}) {
7490: my @okspares;
7491: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7492: foreach my $server (@checked) {
1.152 raeburn 7493: if (&Apache::lonnet::hostname($server) ne '') {
7494: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7495: unless (grep(/^\Q$server\E$/,@okspares)) {
7496: push(@okspares,$server);
7497: }
1.145 raeburn 7498: }
7499: }
7500: }
7501: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7502: my $newspare;
1.152 raeburn 7503: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
7504: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 7505: $newspare = $new;
7506: }
7507: }
1.152 raeburn 7508: my @spares;
7509: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7510: @spares = sort(@okspares,$newspare);
7511: } else {
7512: @spares = sort(@okspares);
7513: }
7514: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 7515: if (ref($spareid{$lonhost}) eq 'HASH') {
7516: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 7517: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 7518: if (@diffs > 0) {
7519: $spareschg{$type} = 1;
7520: }
7521: }
7522: }
7523: }
7524: if (keys(%spareschg) > 0) {
7525: $changes{'spares'}{$lonhost} = \%spareschg;
7526: }
7527: }
7528:
7529: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7530: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7531: if (ref($changes{'spares'}) eq 'HASH') {
7532: if (keys(%{$changes{'spares'}}) > 0) {
7533: $savespares = 1;
7534: }
7535: }
7536: } else {
7537: $savespares = 1;
7538: }
7539: }
7540:
1.147 raeburn 7541: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7542: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 7543: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7544: $dom);
7545: if ($putresult eq 'ok') {
7546: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7547: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7548: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7549: }
7550: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7551: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7552: }
7553: }
7554: my $cachetime = 24*60*60;
7555: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 7556: if (keys(%changes) > 0) {
7557: my %lt = &usersession_titles();
7558: $resulttext = &mt('Changes made:').'<ul>';
7559: foreach my $prefix (@prefixes) {
7560: if (ref($changes{$prefix}) eq 'HASH') {
7561: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7562: if ($prefix eq 'spares') {
7563: if (ref($changes{$prefix}) eq 'HASH') {
7564: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7565: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 7566: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7567: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 7568: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7569: foreach my $type (@{$types{$prefix}}) {
7570: if ($changes{$prefix}{$lonhost}{$type}) {
7571: my $offloadto = &mt('None');
7572: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7573: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7574: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7575: }
1.145 raeburn 7576: }
1.147 raeburn 7577: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 7578: }
1.137 raeburn 7579: }
7580: }
1.147 raeburn 7581: $resulttext .= '</li>';
1.137 raeburn 7582: }
7583: }
1.147 raeburn 7584: } else {
7585: foreach my $type (@{$types{$prefix}}) {
7586: if (defined($changes{$prefix}{$type})) {
7587: my $newvalue;
7588: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7589: if (ref($defaultshash{'usersessions'}{$prefix})) {
7590: if ($type eq 'version') {
7591: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7592: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7593: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7594: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7595: }
1.145 raeburn 7596: }
7597: }
7598: }
1.147 raeburn 7599: if ($newvalue eq '') {
7600: if ($type eq 'version') {
7601: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7602: } else {
7603: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7604: }
1.145 raeburn 7605: } else {
1.147 raeburn 7606: if ($type eq 'version') {
7607: $newvalue .= ' '.&mt('(or later)');
7608: }
7609: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 7610: }
1.137 raeburn 7611: }
7612: }
7613: }
1.147 raeburn 7614: $resulttext .= '</ul>';
1.137 raeburn 7615: }
7616: }
1.147 raeburn 7617: $resulttext .= '</ul>';
7618: } else {
7619: $resulttext = $nochgmsg;
1.137 raeburn 7620: }
7621: } else {
7622: $resulttext = '<span class="LC_error">'.
7623: &mt('An error occurred: [_1]',$putresult).'</span>';
7624: }
7625: } else {
1.147 raeburn 7626: $resulttext = $nochgmsg;
1.137 raeburn 7627: }
7628: return $resulttext;
7629: }
7630:
1.150 raeburn 7631: sub modify_loadbalancing {
7632: my ($dom,%domconfig) = @_;
7633: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7634: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7635: my ($othertitle,$usertypes,$types) =
7636: &Apache::loncommon::sorted_inst_types($dom);
7637: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7638: my @sparestypes = ('primary','default');
7639: my %typetitles = &sparestype_titles();
7640: my $resulttext;
7641: if (keys(%servers) > 1) {
7642: my ($currbalancer,$currtargets,$currrules);
7643: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7644: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7645: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7646: $currrules = $domconfig{'loadbalancing'}{'rules'};
7647: } else {
7648: ($currbalancer,$currtargets) =
7649: &Apache::lonnet::get_lonbalancer_config(\%servers);
7650: }
7651: my ($saveloadbalancing,%defaultshash,%changes);
7652: my ($alltypes,$othertypes,$titles) =
7653: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7654: my %ruletitles = &offloadtype_text();
7655: my $balancer = $env{'form.loadbalancing_lonhost'};
7656: if (!$servers{$balancer}) {
7657: undef($balancer);
7658: }
7659: if ($currbalancer ne $balancer) {
7660: $changes{'lonhost'} = 1;
7661: }
7662: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7663: if ($balancer ne '') {
7664: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7665: $saveloadbalancing = 1;
7666: }
7667: foreach my $sparetype (@sparestypes) {
7668: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151 raeburn 7669: my @offloadto;
1.150 raeburn 7670: foreach my $target (@targets) {
7671: if (($servers{$target}) && ($target ne $balancer)) {
7672: if ($sparetype eq 'default') {
7673: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7674: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7675: }
7676: }
7677: unless(grep(/^\Q$target\E$/,@offloadto)) {
7678: push(@offloadto,$target);
7679: }
7680: }
7681: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7682: }
7683: }
7684: } else {
7685: foreach my $sparetype (@sparestypes) {
7686: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7687: }
7688: }
7689: if (ref($currtargets) eq 'HASH') {
7690: foreach my $sparetype (@sparestypes) {
7691: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7692: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7693: if (@targetdiffs > 0) {
7694: $changes{'targets'} = 1;
7695: }
7696: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7697: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7698: $changes{'targets'} = 1;
7699: }
7700: }
7701: }
7702: } else {
7703: foreach my $sparetype (@sparestypes) {
7704: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7705: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7706: $changes{'targets'} = 1;
7707: }
7708: }
7709: }
7710: }
7711: my $ishomedom;
7712: if ($balancer ne '') {
7713: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7714: $ishomedom = 1;
7715: }
7716: }
7717: if (ref($alltypes) eq 'ARRAY') {
7718: foreach my $type (@{$alltypes}) {
7719: my $rule;
7720: if ($balancer ne '') {
7721: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7722: (!$ishomedom)) {
7723: $rule = $env{'form.loadbalancing_rules_'.$type};
7724: }
7725: if ($rule eq 'specific') {
7726: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7727: }
7728: }
7729: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7730: if (ref($currrules) eq 'HASH') {
7731: if ($rule ne $currrules->{$type}) {
7732: $changes{'rules'}{$type} = 1;
7733: }
7734: } elsif ($rule ne '') {
7735: $changes{'rules'}{$type} = 1;
7736: }
7737: }
7738: }
7739: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7740: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
7741: my $putresult = &Apache::lonnet::put_dom('configuration',
7742: \%defaultshash,$dom);
7743: if ($putresult eq 'ok') {
7744: if (keys(%changes) > 0) {
7745: if ($changes{'lonhost'}) {
7746: if ($currbalancer ne '') {
7747: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
7748: }
7749: if ($balancer eq '') {
7750: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
7751: } else {
7752: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7753: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
7754: }
7755: } else {
7756: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7757: }
7758: if (($changes{'targets'}) && ($balancer ne '')) {
7759: my %offloadstr;
7760: foreach my $sparetype (@sparestypes) {
7761: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7762: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7763: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
7764: }
7765: }
7766: }
7767: if (keys(%offloadstr) == 0) {
7768: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
7769: } else {
7770: my $showoffload;
7771: foreach my $sparetype (@sparestypes) {
7772: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
7773: if (defined($offloadstr{$sparetype})) {
7774: $showoffload .= $offloadstr{$sparetype};
7775: } else {
7776: $showoffload .= &mt('None');
7777: }
7778: $showoffload .= (' 'x3);
7779: }
7780: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
7781: }
7782: }
7783: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
7784: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7785: foreach my $type (@{$alltypes}) {
7786: if ($changes{'rules'}{$type}) {
7787: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
7788: my $balancetext;
7789: if ($rule eq '') {
7790: $balancetext = $ruletitles{'default'};
7791: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
7792: $balancetext = $ruletitles{$rule};
7793: } else {
7794: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
7795: }
7796: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
7797: }
7798: }
7799: }
7800: }
7801: if ($resulttext ne '') {
7802: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
7803: } else {
7804: $resulttext = $nochgmsg;
7805: }
7806: } else {
7807: $resulttext = $nochgmsg;
7808: if ($balancer ne '') {
7809: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7810: }
7811: }
7812: } else {
7813: $resulttext = '<span class="LC_error">'.
7814: &mt('An error occurred: [_1]',$putresult).'</span>';
7815: }
7816: } else {
7817: $resulttext = $nochgmsg;
7818: }
7819: } else {
7820: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
7821: }
7822: return $resulttext;
7823: }
7824:
1.48 raeburn 7825: sub recurse_check {
7826: my ($chkcats,$categories,$depth,$name) = @_;
7827: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7828: my $chg = 0;
7829: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7830: my $category = $chkcats->[$depth]{$name}[$j];
7831: my $item;
7832: if ($category eq '') {
7833: $chg ++;
7834: } else {
7835: my $deeper = $depth + 1;
7836: $item = &escape($category).':'.&escape($name).':'.$depth;
7837: if ($chg) {
7838: $categories->{$item} -= $chg;
7839: }
7840: &recurse_check($chkcats,$categories,$deeper,$category);
7841: $deeper --;
7842: }
7843: }
7844: }
7845: return;
7846: }
7847:
7848: sub recurse_cat_deletes {
7849: my ($item,$coursecategories,$deletions) = @_;
7850: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7851: my $subdepth = $depth + 1;
7852: if (ref($coursecategories) eq 'HASH') {
7853: foreach my $subitem (keys(%{$coursecategories})) {
7854: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7855: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7856: delete($coursecategories->{$subitem});
7857: $deletions->{$subitem} = 1;
7858: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7859: }
7860: }
7861: }
7862: return;
7863: }
7864:
1.125 raeburn 7865: sub get_active_dcs {
7866: my ($dom) = @_;
7867: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7868: my %domcoords;
7869: my $numdcs = 0;
7870: my $now = time;
7871: foreach my $server (keys(%dompersonnel)) {
7872: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7873: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7874: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7875: if (($end eq '') || ($end == 0) || ($end > $now)) {
7876: if ($start <= $now) {
7877: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7878: }
7879: }
7880: }
7881: }
7882: return %domcoords;
7883: }
7884:
7885: sub active_dc_picker {
7886: my ($dom,$curr_dc) = @_;
7887: my %domcoords = &get_active_dcs($dom);
7888: my @dcs = sort(keys(%domcoords));
7889: my $numdcs = scalar(@dcs);
7890: my $datatable;
7891: my $numinrow = 2;
7892: if ($numdcs > 1) {
7893: $datatable = '<table>';
7894: for (my $i=0; $i<@dcs; $i++) {
7895: my $rem = $i%($numinrow);
7896: if ($rem == 0) {
7897: if ($i > 0) {
7898: $datatable .= '</tr>';
7899: }
7900: $datatable .= '<tr>';
7901: }
7902: my $check = ' ';
7903: if ($curr_dc eq '') {
7904: if (!$i) {
7905: $check = ' checked="checked" ';
7906: }
7907: } elsif ($dcs[$i] eq $curr_dc) {
7908: $check = ' checked="checked" ';
7909: }
7910: if ($i == @dcs - 1) {
7911: my $colsleft = $numinrow - $rem;
7912: if ($colsleft > 1) {
7913: $datatable .= '<td colspan="'.$colsleft.'">';
7914: } else {
7915: $datatable .= '<td>';
7916: }
7917: } else {
7918: $datatable .= '<td>';
7919: }
7920: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7921: $datatable .= '<span class="LC_nobreak"><label>'.
7922: '<input type="radio" name="autocreate_xmldc"'.
7923: ' value="'.$dcs[$i].'"'.$check.'/>'.
7924: &Apache::loncommon::plainname($dcname,$dcdom).
7925: '</label></span></td>';
7926: }
7927: $datatable .= '</tr></table>';
7928: } elsif (@dcs) {
7929: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7930: $dcs[0].'" />';
7931: }
7932: return ($numdcs,$datatable);
7933: }
7934:
1.137 raeburn 7935: sub usersession_titles {
7936: return &Apache::lonlocal::texthash(
7937: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7938: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 7939: spares => 'Servers offloaded to, when busy',
1.137 raeburn 7940: version => 'LON-CAPA version requirement',
1.138 raeburn 7941: excludedomain => 'Allow all, but exclude specific domains',
7942: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 7943: primary => 'Primary (checked first)',
1.154 raeburn 7944: default => 'Default',
1.137 raeburn 7945: );
7946: }
7947:
1.152 raeburn 7948: sub id_for_thisdom {
7949: my (%servers) = @_;
7950: my %altids;
7951: foreach my $server (keys(%servers)) {
7952: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7953: if ($serverhome ne $server) {
7954: $altids{$serverhome} = $server;
7955: }
7956: }
7957: return %altids;
7958: }
7959:
1.150 raeburn 7960: sub count_servers {
7961: my ($currbalancer,%servers) = @_;
7962: my (@spares,$numspares);
7963: foreach my $lonhost (sort(keys(%servers))) {
7964: next if ($currbalancer eq $lonhost);
7965: push(@spares,$lonhost);
7966: }
7967: if ($currbalancer) {
7968: $numspares = scalar(@spares);
7969: } else {
7970: $numspares = scalar(@spares) - 1;
7971: }
7972: return ($numspares,@spares);
7973: }
7974:
7975: sub lonbalance_targets_js {
7976: my ($dom,$types,$servers) = @_;
7977: my $select = &mt('Select');
7978: my ($alltargets,$allishome,$allinsttypes,@alltypes);
7979: if (ref($servers) eq 'HASH') {
7980: $alltargets = join("','",sort(keys(%{$servers})));
7981: my @homedoms;
7982: foreach my $server (sort(keys(%{$servers}))) {
7983: if (&Apache::lonnet::host_domain($server) eq $dom) {
7984: push(@homedoms,'1');
7985: } else {
7986: push(@homedoms,'0');
7987: }
7988: }
7989: $allishome = join("','",@homedoms);
7990: }
7991: if (ref($types) eq 'ARRAY') {
7992: if (@{$types} > 0) {
7993: @alltypes = @{$types};
7994: }
7995: }
7996: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
7997: $allinsttypes = join("','",@alltypes);
7998: return <<"END";
7999:
8000: <script type="text/javascript">
8001: // <![CDATA[
8002:
8003: function toggleTargets() {
8004: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
8005: if (balancer == '') {
8006: hideSpares();
8007: } else {
8008: var homedoms = new Array('$allishome');
8009: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
8010: showSpares(balancer,ishomedom);
8011: }
8012: return;
8013: }
8014:
8015: function showSpares(balancer,ishomedom) {
8016: var alltargets = new Array('$alltargets');
8017: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8018: var offloadtypes = new Array('primary','default');
8019:
1.150 raeburn 8020: document.getElementById('loadbalancing_targets').style.display='block';
8021: document.getElementById('loadbalancing_disabled').style.display='none';
1.152 raeburn 8022:
1.151 raeburn 8023: for (var i=0; i<offloadtypes.length; i++) {
8024: var count = 0;
8025: for (var j=0; j<alltargets.length; j++) {
8026: if (alltargets[j] != balancer) {
8027: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
8028: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
8029: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
8030: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8031: count ++;
8032: }
1.150 raeburn 8033: }
8034: }
1.151 raeburn 8035: for (var k=0; k<insttypes.length; k++) {
8036: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8037: if (ishomedom == 1) {
1.151 raeburn 8038: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8039: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8040: } else {
1.151 raeburn 8041: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8042: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150 raeburn 8043:
8044: }
8045: } else {
1.151 raeburn 8046: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8047: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8048: }
1.151 raeburn 8049: if ((insttypes[k] != '_LC_external') &&
8050: ((insttypes[k] != '_LC_internetdom') ||
8051: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8052: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8053: for (var m=0; m<alltargets.length; m++) {
8054: var idx = m+1;
8055: if (alltargets[m] != balancer) {
8056: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 8057: }
8058: }
8059: }
8060: }
8061: return;
8062: }
8063:
8064: function hideSpares() {
8065: var alltargets = new Array('$alltargets');
8066: var insttypes = new Array('$allinsttypes');
8067: var offloadtypes = new Array('primary','default');
8068:
8069: document.getElementById('loadbalancing_targets').style.display='none';
8070: document.getElementById('loadbalancing_disabled').style.display='block';
8071:
8072: var total = alltargets.length - 1;
8073: for (var i=0; i<offloadtypes; i++) {
8074: for (var j=0; j<total; j++) {
8075: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8076: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8077: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8078: }
1.150 raeburn 8079: }
8080: for (var k=0; k<insttypes.length; k++) {
1.151 raeburn 8081: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8082: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8083: if (insttypes[k] != '_LC_external') {
8084: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8085: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8086: }
8087: }
8088: return;
8089: }
8090:
8091: function checkOffloads(item,type) {
8092: var alltargets = new Array('$alltargets');
8093: var offloadtypes = new Array('primary','default');
8094: if (item.checked) {
8095: var total = alltargets.length - 1;
8096: var other;
8097: if (type == offloadtypes[0]) {
1.151 raeburn 8098: other = offloadtypes[1];
1.150 raeburn 8099: } else {
1.151 raeburn 8100: other = offloadtypes[0];
1.150 raeburn 8101: }
8102: for (var i=0; i<total; i++) {
8103: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8104: if (server == item.value) {
8105: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8106: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8107: }
8108: }
8109: }
8110: }
8111: return;
8112: }
8113:
8114: function singleServerToggle(type) {
8115: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8116: if (offloadtoSelIdx == 0) {
8117: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8118: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8119:
8120: } else {
8121: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8122: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8123: }
8124: return;
8125: }
8126:
8127: function balanceruleChange(formname,type) {
8128: if (type == '_LC_external') {
8129: return;
8130: }
8131: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8132: for (var i=0; i<typesRules.length; i++) {
8133: if (formname.elements[typesRules[i]].checked) {
8134: if (formname.elements[typesRules[i]].value != 'specific') {
8135: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8136: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8137: } else {
8138: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8139: }
8140: }
8141: }
8142: return;
8143: }
8144:
1.152 raeburn 8145: // ]]>
8146: </script>
8147:
8148: END
8149: }
8150:
8151: sub new_spares_js {
8152: my @sparestypes = ('primary','default');
8153: my $types = join("','",@sparestypes);
8154: my $select = &mt('Select');
8155: return <<"END";
8156:
8157: <script type="text/javascript">
8158: // <![CDATA[
8159:
8160: function updateNewSpares(formname,lonhost) {
8161: var types = new Array('$types');
8162: var include = new Array();
8163: var exclude = new Array();
8164: for (var i=0; i<types.length; i++) {
8165: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8166: for (var j=0; j<spareboxes.length; j++) {
8167: if (formname.elements[spareboxes[j]].checked) {
8168: exclude.push(formname.elements[spareboxes[j]].value);
8169: } else {
8170: include.push(formname.elements[spareboxes[j]].value);
8171: }
8172: }
8173: }
8174: for (var i=0; i<types.length; i++) {
8175: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8176: var selIdx = newSpare.selectedIndex;
8177: var currnew = newSpare.options[selIdx].value;
8178: var okSpares = new Array();
8179: for (var j=0; j<newSpare.options.length; j++) {
8180: var possible = newSpare.options[j].value;
8181: if (possible != '') {
8182: if (exclude.indexOf(possible) == -1) {
8183: okSpares.push(possible);
8184: } else {
8185: if (currnew == possible) {
8186: selIdx = 0;
8187: }
8188: }
8189: }
8190: }
8191: for (var k=0; k<include.length; k++) {
8192: if (okSpares.indexOf(include[k]) == -1) {
8193: okSpares.push(include[k]);
8194: }
8195: }
8196: okSpares.sort();
8197: newSpare.options.length = 0;
8198: if (selIdx == 0) {
8199: newSpare.options[0] = new Option("$select","",true,true);
8200: } else {
8201: newSpare.options[0] = new Option("$select","",false,false);
8202: }
8203: for (var m=0; m<okSpares.length; m++) {
8204: var idx = m+1;
8205: var selThis = 0;
8206: if (selIdx != 0) {
8207: if (okSpares[m] == currnew) {
8208: selThis = 1;
8209: }
8210: }
8211: if (selThis == 1) {
8212: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8213: } else {
8214: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8215: }
8216: }
8217: }
8218: return;
8219: }
8220:
8221: function checkNewSpares(lonhost,type) {
8222: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8223: var chosen = newSpare.options[newSpare.selectedIndex].value;
8224: if (chosen != '') {
8225: var othertype;
8226: var othernewSpare;
8227: if (type == 'primary') {
8228: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8229: }
8230: if (type == 'default') {
8231: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8232: }
8233: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8234: othernewSpare.selectedIndex = 0;
8235: }
8236: }
8237: return;
8238: }
8239:
8240: // ]]>
8241: </script>
8242:
8243: END
8244:
8245: }
8246:
8247: sub common_domprefs_js {
8248: return <<"END";
8249:
8250: <script type="text/javascript">
8251: // <![CDATA[
8252:
1.150 raeburn 8253: function getIndicesByName(formname,item) {
1.152 raeburn 8254: var group = new Array();
1.150 raeburn 8255: for (var i=0;i<formname.elements.length;i++) {
8256: if (formname.elements[i].name == item) {
1.152 raeburn 8257: group.push(formname.elements[i].id);
1.150 raeburn 8258: }
8259: }
1.152 raeburn 8260: return group;
1.150 raeburn 8261: }
8262:
8263: // ]]>
8264: </script>
8265:
8266: END
1.152 raeburn 8267:
1.150 raeburn 8268: }
8269:
1.3 raeburn 8270: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>