Annotation of loncom/interface/domainprefs.pm, revision 1.162
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.162 ! raeburn 4: # $Id: domainprefs.pm,v 1.161 2012/05/30 16:29:20 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.162 ! raeburn 250: { text => 'Blogs, personal web pages, webDAV, 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 {
1.162 ! raeburn 1380: @usertools = ('aboutme','blog','webdav','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.162 ! raeburn 3006: aboutme => 'Personal web page',
1.86 raeburn 3007: blog => 'Blog',
1.162 ! raeburn 3008: webdav => 'WebDAV',
1.86 raeburn 3009: portfolio => 'Portfolio',
1.88 bisitz 3010: official => 'Official courses (with institutional codes)',
3011: unofficial => 'Unofficial courses',
1.98 raeburn 3012: community => 'Communities',
1.86 raeburn 3013: );
1.72 raeburn 3014: return %titles;
3015: }
3016:
1.101 raeburn 3017: sub courserequest_titles {
3018: my %titles = &Apache::lonlocal::texthash (
3019: official => 'Official',
3020: unofficial => 'Unofficial',
3021: community => 'Communities',
3022: norequest => 'Not allowed',
1.104 raeburn 3023: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3024: validate => 'With validation',
3025: autolimit => 'Numerical limit',
1.103 raeburn 3026: unlimited => '(blank for unlimited)',
1.101 raeburn 3027: );
3028: return %titles;
3029: }
3030:
3031: sub courserequest_conditions {
3032: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3033: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3034: validate => '(Processing of request subject to instittutional validation).',
3035: );
3036: return %conditions;
3037: }
3038:
3039:
1.27 raeburn 3040: sub print_usercreation {
1.30 raeburn 3041: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3042: my $numinrow = 4;
1.28 raeburn 3043: my $datatable;
3044: if ($position eq 'top') {
1.30 raeburn 3045: $$rowtotal ++;
1.34 raeburn 3046: my $rowcount = 0;
1.32 raeburn 3047: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3048: if (ref($rules) eq 'HASH') {
3049: if (keys(%{$rules}) > 0) {
1.32 raeburn 3050: $datatable .= &user_formats_row('username',$settings,$rules,
3051: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3052: $$rowtotal ++;
1.32 raeburn 3053: $rowcount ++;
3054: }
3055: }
3056: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3057: if (ref($idrules) eq 'HASH') {
3058: if (keys(%{$idrules}) > 0) {
3059: $datatable .= &user_formats_row('id',$settings,$idrules,
3060: $idruleorder,$numinrow,$rowcount);
3061: $$rowtotal ++;
3062: $rowcount ++;
1.28 raeburn 3063: }
3064: }
1.43 raeburn 3065: my ($emailrules,$emailruleorder) =
3066: &Apache::lonnet::inst_userrules($dom,'email');
3067: if (ref($emailrules) eq 'HASH') {
3068: if (keys(%{$emailrules}) > 0) {
3069: $datatable .= &user_formats_row('email',$settings,$emailrules,
3070: $emailruleorder,$numinrow,$rowcount);
3071: $$rowtotal ++;
3072: $rowcount ++;
3073: }
3074: }
1.39 raeburn 3075: if ($rowcount == 0) {
3076: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3077: $$rowtotal ++;
3078: $rowcount ++;
3079: }
1.34 raeburn 3080: } elsif ($position eq 'middle') {
1.100 raeburn 3081: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3082: my ($rules,$ruleorder) =
3083: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3084: my %lt = &usercreation_types();
3085: my %checked;
1.50 raeburn 3086: my @selfcreate;
1.34 raeburn 3087: if (ref($settings) eq 'HASH') {
3088: if (ref($settings->{'cancreate'}) eq 'HASH') {
3089: foreach my $item (@creators) {
3090: $checked{$item} = $settings->{'cancreate'}{$item};
3091: }
1.50 raeburn 3092: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3093: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3094: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3095: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3096: @selfcreate = ('email','login','sso');
3097: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3098: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3099: }
3100: }
1.34 raeburn 3101: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3102: foreach my $item (@creators) {
3103: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3104: $checked{$item} = 'none';
3105: }
3106: }
3107: }
3108: }
3109: my $rownum = 0;
3110: foreach my $item (@creators) {
3111: $rownum ++;
1.50 raeburn 3112: if ($item ne 'selfcreate') {
3113: if ($checked{$item} eq '') {
1.43 raeburn 3114: $checked{$item} = 'any';
3115: }
1.34 raeburn 3116: }
3117: my $css_class;
3118: if ($rownum%2) {
3119: $css_class = '';
3120: } else {
3121: $css_class = ' class="LC_odd_row" ';
3122: }
3123: $datatable .= '<tr'.$css_class.'>'.
3124: '<td><span class="LC_nobreak">'.$lt{$item}.
3125: '</span></td><td align="right">';
1.50 raeburn 3126: my @options;
1.45 raeburn 3127: if ($item eq 'selfcreate') {
1.43 raeburn 3128: push(@options,('email','login','sso'));
3129: } else {
1.50 raeburn 3130: @options = ('any');
1.43 raeburn 3131: if (ref($rules) eq 'HASH') {
3132: if (keys(%{$rules}) > 0) {
3133: push(@options,('official','unofficial'));
3134: }
1.37 raeburn 3135: }
1.50 raeburn 3136: push(@options,'none');
1.37 raeburn 3137: }
3138: foreach my $option (@options) {
1.50 raeburn 3139: my $type = 'radio';
1.34 raeburn 3140: my $check = ' ';
1.50 raeburn 3141: if ($item eq 'selfcreate') {
3142: $type = 'checkbox';
3143: if (grep(/^\Q$option\E$/,@selfcreate)) {
3144: $check = ' checked="checked" ';
3145: }
3146: } else {
3147: if ($checked{$item} eq $option) {
3148: $check = ' checked="checked" ';
3149: }
1.34 raeburn 3150: }
3151: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3152: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3153: $item.'" value="'.$option.'"'.$check.'/> '.
3154: $lt{$option}.'</label> </span>';
3155: }
3156: $datatable .= '</td></tr>';
3157: }
1.93 raeburn 3158: my ($othertitle,$usertypes,$types) =
3159: &Apache::loncommon::sorted_inst_types($dom);
3160: if (ref($usertypes) eq 'HASH') {
3161: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3162: my $createsettings;
3163: if (ref($settings) eq 'HASH') {
3164: $createsettings = $settings->{cancreate};
3165: }
3166: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3167: $dom,$numinrow,$othertitle,
3168: 'statustocreate');
3169: $$rowtotal ++;
3170: }
3171: }
1.28 raeburn 3172: } else {
3173: my @contexts = ('author','course','domain');
3174: my @authtypes = ('int','krb4','krb5','loc');
3175: my %checked;
3176: if (ref($settings) eq 'HASH') {
3177: if (ref($settings->{'authtypes'}) eq 'HASH') {
3178: foreach my $item (@contexts) {
3179: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3180: foreach my $auth (@authtypes) {
3181: if ($settings->{'authtypes'}{$item}{$auth}) {
3182: $checked{$item}{$auth} = ' checked="checked" ';
3183: }
3184: }
3185: }
3186: }
1.27 raeburn 3187: }
1.35 raeburn 3188: } else {
3189: foreach my $item (@contexts) {
1.36 raeburn 3190: foreach my $auth (@authtypes) {
1.35 raeburn 3191: $checked{$item}{$auth} = ' checked="checked" ';
3192: }
3193: }
1.27 raeburn 3194: }
1.28 raeburn 3195: my %title = &context_names();
3196: my %authname = &authtype_names();
3197: my $rownum = 0;
3198: my $css_class;
3199: foreach my $item (@contexts) {
3200: if ($rownum%2) {
3201: $css_class = '';
3202: } else {
3203: $css_class = ' class="LC_odd_row" ';
3204: }
1.30 raeburn 3205: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3206: '<td>'.$title{$item}.
3207: '</td><td class="LC_left_item">'.
3208: '<span class="LC_nobreak">';
3209: foreach my $auth (@authtypes) {
3210: $datatable .= '<label>'.
3211: '<input type="checkbox" name="'.$item.'_auth" '.
3212: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3213: $authname{$auth}.'</label> ';
3214: }
3215: $datatable .= '</span></td></tr>';
3216: $rownum ++;
1.27 raeburn 3217: }
1.30 raeburn 3218: $$rowtotal += $rownum;
1.27 raeburn 3219: }
3220: return $datatable;
3221: }
3222:
1.32 raeburn 3223: sub user_formats_row {
3224: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3225: my $output;
3226: my %text = (
3227: 'username' => 'new usernames',
3228: 'id' => 'IDs',
1.45 raeburn 3229: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3230: );
3231: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3232: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3233: '<td><span class="LC_nobreak">';
3234: if ($type eq 'email') {
3235: $output .= &mt("Formats disallowed for $text{$type}: ");
3236: } else {
3237: $output .= &mt("Format rules to check for $text{$type}: ");
3238: }
3239: $output .= '</span></td>'.
3240: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3241: my $rem;
3242: if (ref($ruleorder) eq 'ARRAY') {
3243: for (my $i=0; $i<@{$ruleorder}; $i++) {
3244: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3245: my $rem = $i%($numinrow);
3246: if ($rem == 0) {
3247: if ($i > 0) {
3248: $output .= '</tr>';
3249: }
3250: $output .= '<tr>';
3251: }
3252: my $check = ' ';
1.39 raeburn 3253: if (ref($settings) eq 'HASH') {
3254: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3255: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3256: $check = ' checked="checked" ';
3257: }
1.27 raeburn 3258: }
3259: }
3260: $output .= '<td class="LC_left_item">'.
3261: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3262: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3263: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3264: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3265: }
3266: }
3267: $rem = @{$ruleorder}%($numinrow);
3268: }
3269: my $colsleft = $numinrow - $rem;
3270: if ($colsleft > 1 ) {
3271: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3272: ' </td>';
3273: } elsif ($colsleft == 1) {
3274: $output .= '<td class="LC_left_item"> </td>';
3275: }
3276: $output .= '</tr></table></td></tr>';
3277: return $output;
3278: }
3279:
1.34 raeburn 3280: sub usercreation_types {
3281: my %lt = &Apache::lonlocal::texthash (
3282: author => 'When adding a co-author',
3283: course => 'When adding a user to a course',
1.100 raeburn 3284: requestcrs => 'When requesting a course',
1.45 raeburn 3285: selfcreate => 'User creates own account',
1.34 raeburn 3286: any => 'Any',
3287: official => 'Institutional only ',
3288: unofficial => 'Non-institutional only',
1.85 schafran 3289: email => 'E-mail address',
1.43 raeburn 3290: login => 'Institutional Login',
3291: sso => 'SSO',
1.34 raeburn 3292: none => 'None',
3293: );
3294: return %lt;
1.48 raeburn 3295: }
1.34 raeburn 3296:
1.28 raeburn 3297: sub authtype_names {
3298: my %lt = &Apache::lonlocal::texthash(
3299: int => 'Internal',
3300: krb4 => 'Kerberos 4',
3301: krb5 => 'Kerberos 5',
3302: loc => 'Local',
3303: );
3304: return %lt;
3305: }
3306:
3307: sub context_names {
3308: my %context_title = &Apache::lonlocal::texthash(
3309: author => 'Creating users when an Author',
3310: course => 'Creating users when in a course',
3311: domain => 'Creating users when a Domain Coordinator',
3312: );
3313: return %context_title;
3314: }
3315:
1.33 raeburn 3316: sub print_usermodification {
3317: my ($position,$dom,$settings,$rowtotal) = @_;
3318: my $numinrow = 4;
3319: my ($context,$datatable,$rowcount);
3320: if ($position eq 'top') {
3321: $rowcount = 0;
3322: $context = 'author';
3323: foreach my $role ('ca','aa') {
3324: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3325: $numinrow,$rowcount);
3326: $$rowtotal ++;
3327: $rowcount ++;
3328: }
1.63 raeburn 3329: } elsif ($position eq 'middle') {
1.33 raeburn 3330: $context = 'course';
3331: $rowcount = 0;
3332: foreach my $role ('st','ep','ta','in','cr') {
3333: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3334: $numinrow,$rowcount);
3335: $$rowtotal ++;
3336: $rowcount ++;
3337: }
1.63 raeburn 3338: } elsif ($position eq 'bottom') {
3339: $context = 'selfcreate';
3340: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3341: $usertypes->{'default'} = $othertitle;
3342: if (ref($types) eq 'ARRAY') {
3343: push(@{$types},'default');
3344: $usertypes->{'default'} = $othertitle;
3345: foreach my $status (@{$types}) {
3346: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3347: $numinrow,$rowcount,$usertypes);
3348: $$rowtotal ++;
3349: $rowcount ++;
3350: }
3351: }
1.33 raeburn 3352: }
3353: return $datatable;
3354: }
3355:
1.43 raeburn 3356: sub print_defaults {
3357: my ($dom,$rowtotal) = @_;
1.68 raeburn 3358: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3359: 'datelocale_def','portal_def');
1.43 raeburn 3360: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3361: my $titles = &defaults_titles($dom);
1.43 raeburn 3362: my $rownum = 0;
3363: my ($datatable,$css_class);
3364: foreach my $item (@items) {
3365: if ($rownum%2) {
3366: $css_class = '';
3367: } else {
3368: $css_class = ' class="LC_odd_row" ';
3369: }
3370: $datatable .= '<tr'.$css_class.'>'.
3371: '<td><span class="LC_nobreak">'.$titles->{$item}.
3372: '</span></td><td class="LC_right_item">';
3373: if ($item eq 'auth_def') {
3374: my @authtypes = ('internal','krb4','krb5','localauth');
3375: my %shortauth = (
3376: internal => 'int',
3377: krb4 => 'krb4',
3378: krb5 => 'krb5',
3379: localauth => 'loc'
3380: );
3381: my %authnames = &authtype_names();
3382: foreach my $auth (@authtypes) {
3383: my $checked = ' ';
3384: if ($domdefaults{$item} eq $auth) {
3385: $checked = ' checked="checked" ';
3386: }
3387: $datatable .= '<label><input type="radio" name="'.$item.
3388: '" value="'.$auth.'"'.$checked.'/>'.
3389: $authnames{$shortauth{$auth}}.'</label> ';
3390: }
1.54 raeburn 3391: } elsif ($item eq 'timezone_def') {
3392: my $includeempty = 1;
3393: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3394: } elsif ($item eq 'datelocale_def') {
3395: my $includeempty = 1;
3396: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 3397: } else {
1.141 raeburn 3398: my $size;
3399: if ($item eq 'portal_def') {
3400: $size = ' size="25"';
3401: }
1.43 raeburn 3402: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3403: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3404: }
3405: $datatable .= '</td></tr>';
3406: $rownum ++;
3407: }
3408: $$rowtotal += $rownum;
3409: return $datatable;
3410: }
3411:
3412: sub defaults_titles {
1.141 raeburn 3413: my ($dom) = @_;
1.43 raeburn 3414: my %titles = &Apache::lonlocal::texthash (
3415: 'auth_def' => 'Default authentication type',
3416: 'auth_arg_def' => 'Default authentication argument',
3417: 'lang_def' => 'Default language',
1.54 raeburn 3418: 'timezone_def' => 'Default timezone',
1.68 raeburn 3419: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3420: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3421: );
1.141 raeburn 3422: if ($dom) {
3423: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3424: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3425: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3426: $protocol = 'http' if ($protocol ne 'https');
3427: if ($uint_dom) {
3428: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3429: $uint_dom);
3430: }
3431: }
1.43 raeburn 3432: return (\%titles);
3433: }
3434:
1.46 raeburn 3435: sub print_scantronformat {
3436: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3437: my $itemcount = 1;
1.60 raeburn 3438: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3439: %confhash);
1.46 raeburn 3440: my $switchserver = &check_switchserver($dom,$confname);
3441: my %lt = &Apache::lonlocal::texthash (
1.95 www 3442: default => 'Default bubblesheet format file error',
3443: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3444: );
3445: my %scantronfiles = (
3446: default => 'default.tab',
3447: custom => 'custom.tab',
3448: );
3449: foreach my $key (keys(%scantronfiles)) {
3450: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3451: .$scantronfiles{$key};
3452: }
3453: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3454: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3455: if (!$switchserver) {
3456: my $servadm = $r->dir_config('lonAdmEMail');
3457: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3458: if ($configuserok eq 'ok') {
3459: if ($author_ok eq 'ok') {
3460: my %legacyfile = (
3461: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3462: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3463: );
3464: my %md5chk;
3465: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3466: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3467: chomp($md5chk{$type});
1.46 raeburn 3468: }
3469: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3470: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3471: ($scantronurls{$type},my $error) =
1.46 raeburn 3472: &legacy_scantronformat($r,$dom,$confname,
3473: $type,$legacyfile{$type},
3474: $scantronurls{$type},
3475: $scantronfiles{$type});
1.60 raeburn 3476: if ($error ne '') {
3477: $error{$type} = $error;
3478: }
3479: }
3480: if (keys(%error) == 0) {
3481: $is_custom = 1;
3482: $confhash{'scantron'}{'scantronformat'} =
3483: $scantronurls{'custom'};
3484: my $putresult =
3485: &Apache::lonnet::put_dom('configuration',
3486: \%confhash,$dom);
3487: if ($putresult ne 'ok') {
3488: $error{'custom'} =
3489: '<span class="LC_error">'.
3490: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3491: }
1.46 raeburn 3492: }
3493: } else {
1.60 raeburn 3494: ($scantronurls{'default'},my $error) =
1.46 raeburn 3495: &legacy_scantronformat($r,$dom,$confname,
3496: 'default',$legacyfile{'default'},
3497: $scantronurls{'default'},
3498: $scantronfiles{'default'});
1.60 raeburn 3499: if ($error eq '') {
3500: $confhash{'scantron'}{'scantronformat'} = '';
3501: my $putresult =
3502: &Apache::lonnet::put_dom('configuration',
3503: \%confhash,$dom);
3504: if ($putresult ne 'ok') {
3505: $error{'default'} =
3506: '<span class="LC_error">'.
3507: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3508: }
3509: } else {
3510: $error{'default'} = $error;
3511: }
1.46 raeburn 3512: }
3513: }
3514: }
3515: } else {
1.95 www 3516: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3517: }
3518: }
3519: if (ref($settings) eq 'HASH') {
3520: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3521: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3522: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3523: $scantronurl = '';
3524: } else {
3525: $scantronurl = $settings->{'scantronformat'};
3526: }
3527: $is_custom = 1;
3528: } else {
3529: $scantronurl = $scantronurls{'default'};
3530: }
3531: } else {
1.60 raeburn 3532: if ($is_custom) {
3533: $scantronurl = $scantronurls{'custom'};
3534: } else {
3535: $scantronurl = $scantronurls{'default'};
3536: }
1.46 raeburn 3537: }
3538: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3539: $datatable .= '<tr'.$css_class.'>';
3540: if (!$is_custom) {
1.65 raeburn 3541: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3542: '<span class="LC_nobreak">';
1.46 raeburn 3543: if ($scantronurl) {
3544: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3545: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3546: } else {
3547: $datatable = &mt('File unavailable for display');
3548: }
1.65 raeburn 3549: $datatable .= '</span></td>';
1.60 raeburn 3550: if (keys(%error) == 0) {
3551: $datatable .= '<td valign="bottom">';
3552: if (!$switchserver) {
3553: $datatable .= &mt('Upload:').'<br />';
3554: }
3555: } else {
3556: my $errorstr;
3557: foreach my $key (sort(keys(%error))) {
3558: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3559: }
3560: $datatable .= '<td>'.$errorstr;
3561: }
1.46 raeburn 3562: } else {
3563: if (keys(%error) > 0) {
3564: my $errorstr;
3565: foreach my $key (sort(keys(%error))) {
3566: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3567: }
1.60 raeburn 3568: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3569: } elsif ($scantronurl) {
1.65 raeburn 3570: $datatable .= '<td><span class="LC_nobreak">'.
3571: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3572: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3573: '<input type="checkbox" name="scantronformat_del"'.
3574: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3575: '<td><span class="LC_nobreak"> '.
3576: &mt('Replace:').'</span><br />';
1.46 raeburn 3577: }
3578: }
3579: if (keys(%error) == 0) {
3580: if ($switchserver) {
3581: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3582: } else {
1.65 raeburn 3583: $datatable .='<span class="LC_nobreak"> '.
3584: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3585: }
3586: }
3587: $datatable .= '</td></tr>';
3588: $$rowtotal ++;
3589: return $datatable;
3590: }
3591:
3592: sub legacy_scantronformat {
3593: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3594: my ($url,$error);
3595: my @statinfo = &Apache::lonnet::stat_file($newurl);
3596: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3597: (my $result,$url) =
3598: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3599: '','',$newfile);
3600: if ($result ne 'ok') {
1.130 raeburn 3601: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3602: }
3603: }
3604: return ($url,$error);
3605: }
1.43 raeburn 3606:
1.49 raeburn 3607: sub print_coursecategories {
1.57 raeburn 3608: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3609: my $datatable;
3610: if ($position eq 'top') {
3611: my $toggle_cats_crs = ' ';
3612: my $toggle_cats_dom = ' checked="checked" ';
3613: my $can_cat_crs = ' ';
3614: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3615: my $toggle_catscomm_comm = ' ';
3616: my $toggle_catscomm_dom = ' checked="checked" ';
3617: my $can_catcomm_comm = ' ';
3618: my $can_catcomm_dom = ' checked="checked" ';
3619:
1.57 raeburn 3620: if (ref($settings) eq 'HASH') {
3621: if ($settings->{'togglecats'} eq 'crs') {
3622: $toggle_cats_crs = $toggle_cats_dom;
3623: $toggle_cats_dom = ' ';
3624: }
3625: if ($settings->{'categorize'} eq 'crs') {
3626: $can_cat_crs = $can_cat_dom;
3627: $can_cat_dom = ' ';
3628: }
1.120 raeburn 3629: if ($settings->{'togglecatscomm'} eq 'comm') {
3630: $toggle_catscomm_comm = $toggle_catscomm_dom;
3631: $toggle_catscomm_dom = ' ';
3632: }
3633: if ($settings->{'categorizecomm'} eq 'comm') {
3634: $can_catcomm_comm = $can_catcomm_dom;
3635: $can_catcomm_dom = ' ';
3636: }
1.57 raeburn 3637: }
3638: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3639: togglecats => 'Show/Hide a course in catalog',
3640: togglecatscomm => 'Show/Hide a community in catalog',
3641: categorize => 'Assign a category to a course',
3642: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3643: );
3644: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3645: dom => 'Set in Domain',
3646: crs => 'Set in Course',
3647: comm => 'Set in Community',
1.57 raeburn 3648: );
3649: $datatable = '<tr class="LC_odd_row">'.
3650: '<td>'.$title{'togglecats'}.'</td>'.
3651: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3652: '<input type="radio" name="togglecats"'.
3653: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3654: '<label><input type="radio" name="togglecats"'.
3655: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3656: '</tr><tr>'.
3657: '<td>'.$title{'categorize'}.'</td>'.
3658: '<td class="LC_right_item"><span class="LC_nobreak">'.
3659: '<label><input type="radio" name="categorize"'.
3660: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3661: '<label><input type="radio" name="categorize"'.
3662: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3663: '</tr><tr class="LC_odd_row">'.
3664: '<td>'.$title{'togglecatscomm'}.'</td>'.
3665: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3666: '<input type="radio" name="togglecatscomm"'.
3667: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3668: '<label><input type="radio" name="togglecatscomm"'.
3669: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3670: '</tr><tr>'.
3671: '<td>'.$title{'categorizecomm'}.'</td>'.
3672: '<td class="LC_right_item"><span class="LC_nobreak">'.
3673: '<label><input type="radio" name="categorizecomm"'.
3674: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3675: '<label><input type="radio" name="categorizecomm"'.
3676: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3677: '</tr>';
1.120 raeburn 3678: $$rowtotal += 4;
1.57 raeburn 3679: } else {
3680: my $css_class;
3681: my $itemcount = 1;
3682: my $cathash;
3683: if (ref($settings) eq 'HASH') {
3684: $cathash = $settings->{'cats'};
3685: }
3686: if (ref($cathash) eq 'HASH') {
3687: my (@cats,@trails,%allitems,%idx,@jsarray);
3688: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3689: \%allitems,\%idx,\@jsarray);
3690: my $maxdepth = scalar(@cats);
3691: my $colattrib = '';
3692: if ($maxdepth > 2) {
3693: $colattrib = ' colspan="2" ';
3694: }
3695: my @path;
3696: if (@cats > 0) {
3697: if (ref($cats[0]) eq 'ARRAY') {
3698: my $numtop = @{$cats[0]};
3699: my $maxnum = $numtop;
1.120 raeburn 3700: my %default_names = (
3701: instcode => &mt('Official courses'),
3702: communities => &mt('Communities'),
3703: );
3704:
3705: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3706: ($cathash->{'instcode::0'} eq '') ||
3707: (!grep(/^communities$/,@{$cats[0]})) ||
3708: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3709: $maxnum ++;
3710: }
3711: my $lastidx;
3712: for (my $i=0; $i<$numtop; $i++) {
3713: my $parent = $cats[0][$i];
3714: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3715: my $item = &escape($parent).'::0';
3716: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3717: $lastidx = $idx{$item};
3718: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3719: .'<select name="'.$item.'"'.$chgstr.'>';
3720: for (my $k=0; $k<=$maxnum; $k++) {
3721: my $vpos = $k+1;
3722: my $selstr;
3723: if ($k == $i) {
3724: $selstr = ' selected="selected" ';
3725: }
3726: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3727: }
3728: $datatable .= '</select></td><td>';
1.120 raeburn 3729: if ($parent eq 'instcode' || $parent eq 'communities') {
3730: $datatable .= '<span class="LC_nobreak">'
3731: .$default_names{$parent}.'</span>';
3732: if ($parent eq 'instcode') {
3733: $datatable .= '<br /><span class="LC_nobreak">('
3734: .&mt('with institutional codes')
3735: .')</span></td><td'.$colattrib.'>';
3736: } else {
3737: $datatable .= '<table><tr><td>';
3738: }
3739: $datatable .= '<span class="LC_nobreak">'
3740: .'<label><input type="radio" name="'
3741: .$parent.'" value="1" checked="checked" />'
3742: .&mt('Display').'</label>';
3743: if ($parent eq 'instcode') {
3744: $datatable .= ' ';
3745: } else {
3746: $datatable .= '</span></td></tr><tr><td>'
3747: .'<span class="LC_nobreak">';
3748: }
3749: $datatable .= '<label><input type="radio" name="'
3750: .$parent.'" value="0" />'
3751: .&mt('Do not display').'</label></span>';
3752: if ($parent eq 'communities') {
3753: $datatable .= '</td></tr></table>';
3754: }
3755: $datatable .= '</td>';
1.57 raeburn 3756: } else {
3757: $datatable .= $parent
3758: .' <label><input type="checkbox" name="deletecategory" '
3759: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3760: }
3761: my $depth = 1;
3762: push(@path,$parent);
3763: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3764: pop(@path);
3765: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3766: $itemcount ++;
3767: }
1.48 raeburn 3768: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3769: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3770: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3771: for (my $k=0; $k<=$maxnum; $k++) {
3772: my $vpos = $k+1;
3773: my $selstr;
1.57 raeburn 3774: if ($k == $numtop) {
1.48 raeburn 3775: $selstr = ' selected="selected" ';
3776: }
3777: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3778: }
1.59 bisitz 3779: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3780: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3781: .'</tr>'."\n";
1.48 raeburn 3782: $itemcount ++;
1.120 raeburn 3783: foreach my $default ('instcode','communities') {
3784: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3785: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3786: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3787: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3788: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3789: for (my $k=0; $k<=$maxnum; $k++) {
3790: my $vpos = $k+1;
3791: my $selstr;
3792: if ($k == $maxnum) {
3793: $selstr = ' selected="selected" ';
3794: }
3795: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3796: }
1.120 raeburn 3797: $datatable .= '</select></span></td>'.
3798: '<td><span class="LC_nobreak">'.
3799: $default_names{$default}.'</span>';
3800: if ($default eq 'instcode') {
3801: $datatable .= '<br /><span class="LC_nobreak">('
3802: .&mt('with institutional codes').')</span>';
3803: }
3804: $datatable .= '</td>'
3805: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3806: .&mt('Display').'</label> '
3807: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3808: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3809: }
3810: }
3811: }
1.57 raeburn 3812: } else {
3813: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3814: }
3815: } else {
1.57 raeburn 3816: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3817: .&initialize_categories($itemcount);
1.48 raeburn 3818: }
1.57 raeburn 3819: $$rowtotal += $itemcount;
1.48 raeburn 3820: }
3821: return $datatable;
3822: }
3823:
1.69 raeburn 3824: sub print_serverstatuses {
3825: my ($dom,$settings,$rowtotal) = @_;
3826: my $datatable;
3827: my @pages = &serverstatus_pages();
3828: my (%namedaccess,%machineaccess);
3829: foreach my $type (@pages) {
3830: $namedaccess{$type} = '';
3831: $machineaccess{$type}= '';
3832: }
3833: if (ref($settings) eq 'HASH') {
3834: foreach my $type (@pages) {
3835: if (exists($settings->{$type})) {
3836: if (ref($settings->{$type}) eq 'HASH') {
3837: foreach my $key (keys(%{$settings->{$type}})) {
3838: if ($key eq 'namedusers') {
3839: $namedaccess{$type} = $settings->{$type}->{$key};
3840: } elsif ($key eq 'machines') {
3841: $machineaccess{$type} = $settings->{$type}->{$key};
3842: }
3843: }
3844: }
3845: }
3846: }
3847: }
1.81 raeburn 3848: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3849: my $rownum = 0;
3850: my $css_class;
3851: foreach my $type (@pages) {
3852: $rownum ++;
3853: $css_class = $rownum%2?' class="LC_odd_row"':'';
3854: $datatable .= '<tr'.$css_class.'>'.
3855: '<td><span class="LC_nobreak">'.
3856: $titles->{$type}.'</span></td>'.
3857: '<td class="LC_left_item">'.
3858: '<input type="text" name="'.$type.'_namedusers" '.
3859: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3860: '<td class="LC_right_item">'.
3861: '<span class="LC_nobreak">'.
3862: '<input type="text" name="'.$type.'_machines" '.
3863: 'value="'.$machineaccess{$type}.'" size="10" />'.
3864: '</td></tr>'."\n";
3865: }
3866: $$rowtotal += $rownum;
3867: return $datatable;
3868: }
3869:
3870: sub serverstatus_pages {
3871: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3872: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 3873: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 3874: }
3875:
1.49 raeburn 3876: sub coursecategories_javascript {
3877: my ($settings) = @_;
1.57 raeburn 3878: my ($output,$jstext,$cathash);
1.49 raeburn 3879: if (ref($settings) eq 'HASH') {
1.57 raeburn 3880: $cathash = $settings->{'cats'};
3881: }
3882: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3883: my (@cats,@jsarray,%idx);
1.57 raeburn 3884: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3885: if (@jsarray > 0) {
3886: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3887: for (my $i=0; $i<@jsarray; $i++) {
3888: if (ref($jsarray[$i]) eq 'ARRAY') {
3889: my $catstr = join('","',@{$jsarray[$i]});
3890: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3891: }
3892: }
3893: }
3894: } else {
3895: $jstext = ' var categories = Array(1);'."\n".
3896: ' categories[0] = Array("instcode_pos");'."\n";
3897: }
1.120 raeburn 3898: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3899: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3900: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3901: $output = <<"ENDSCRIPT";
3902: <script type="text/javascript">
1.109 raeburn 3903: // <![CDATA[
1.49 raeburn 3904: function reorderCats(form,parent,item,idx) {
3905: var changedVal;
3906: $jstext
3907: var newpos = 'addcategory_pos';
3908: var current = new Array;
3909: if (parent == '') {
3910: var has_instcode = 0;
3911: var maxtop = categories[idx].length;
3912: for (var j=0; j<maxtop; j++) {
3913: if (categories[idx][j] == 'instcode::0') {
3914: has_instcode == 1;
3915: }
3916: }
3917: if (has_instcode == 0) {
3918: categories[idx][maxtop] = 'instcode_pos';
3919: }
3920: } else {
3921: newpos += '_'+parent;
3922: }
3923: var maxh = 1 + categories[idx].length;
3924: var current = new Array;
3925: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3926: if (item == newpos) {
3927: changedVal = newitemVal;
3928: } else {
3929: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3930: current[newitemVal] = newpos;
3931: }
3932: for (var i=0; i<categories[idx].length; i++) {
3933: var elementName = categories[idx][i];
3934: if (elementName != item) {
3935: if (form.elements[elementName]) {
3936: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3937: current[currVal] = elementName;
3938: }
3939: }
3940: }
3941: var oldVal;
3942: for (var j=0; j<maxh; j++) {
3943: if (current[j] == undefined) {
3944: oldVal = j;
3945: }
3946: }
3947: if (oldVal < changedVal) {
3948: for (var k=oldVal+1; k<=changedVal ; k++) {
3949: var elementName = current[k];
3950: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3951: }
3952: } else {
3953: for (var k=changedVal; k<oldVal; k++) {
3954: var elementName = current[k];
3955: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3956: }
3957: }
3958: return;
3959: }
1.120 raeburn 3960:
3961: function categoryCheck(form) {
3962: if (form.elements['addcategory_name'].value == 'instcode') {
3963: alert('$instcode_reserved\\n$choose_again');
3964: return false;
3965: }
3966: if (form.elements['addcategory_name'].value == 'communities') {
3967: alert('$communities_reserved\\n$choose_again');
3968: return false;
3969: }
3970: return true;
3971: }
3972:
1.109 raeburn 3973: // ]]>
1.49 raeburn 3974: </script>
3975:
3976: ENDSCRIPT
3977: return $output;
3978: }
3979:
1.48 raeburn 3980: sub initialize_categories {
3981: my ($itemcount) = @_;
1.120 raeburn 3982: my ($datatable,$css_class,$chgstr);
3983: my %default_names = (
3984: instcode => 'Official courses (with institutional codes)',
3985: communities => 'Communities',
3986: );
3987: my $select0 = ' selected="selected"';
3988: my $select1 = '';
3989: foreach my $default ('instcode','communities') {
3990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3991: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3992: if ($default eq 'communities') {
3993: $select1 = $select0;
3994: $select0 = '';
3995: }
3996: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3997: .'<select name="'.$default.'_pos">'
3998: .'<option value="0"'.$select0.'>1</option>'
3999: .'<option value="1"'.$select1.'>2</option>'
4000: .'<option value="2">3</option></select> '
4001: .$default_names{$default}
4002: .'</span></td><td><span class="LC_nobreak">'
4003: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4004: .&mt('Display').'</label> <label>'
4005: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4006: .'</label></span></td></tr>';
1.120 raeburn 4007: $itemcount ++;
4008: }
1.48 raeburn 4009: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4010: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4011: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4012: .'<select name="addcategory_pos"'.$chgstr.'>'
4013: .'<option value="0">1</option>'
4014: .'<option value="1">2</option>'
4015: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4016: .&mt('Add category').'</td><td>'.&mt('Name:')
4017: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4018: return $datatable;
4019: }
4020:
4021: sub build_category_rows {
1.49 raeburn 4022: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4023: my ($text,$name,$item,$chgstr);
1.48 raeburn 4024: if (ref($cats) eq 'ARRAY') {
4025: my $maxdepth = scalar(@{$cats});
4026: if (ref($cats->[$depth]) eq 'HASH') {
4027: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4028: my $numchildren = @{$cats->[$depth]{$parent}};
4029: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4030: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4031: my ($idxnum,$parent_name,$parent_item);
4032: my $higher = $depth - 1;
4033: if ($higher == 0) {
4034: $parent_name = &escape($parent).'::'.$higher;
4035: } else {
4036: if (ref($path) eq 'ARRAY') {
4037: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4038: }
4039: }
4040: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4041: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4042: if ($j < $numchildren) {
1.48 raeburn 4043: $name = $cats->[$depth]{$parent}[$j];
4044: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4045: $idxnum = $idx->{$item};
4046: } else {
4047: $name = $parent_name;
4048: $item = $parent_item;
1.48 raeburn 4049: }
1.49 raeburn 4050: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4051: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4052: for (my $i=0; $i<=$numchildren; $i++) {
4053: my $vpos = $i+1;
4054: my $selstr;
4055: if ($j == $i) {
4056: $selstr = ' selected="selected" ';
4057: }
4058: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4059: }
4060: $text .= '</select> ';
4061: if ($j < $numchildren) {
4062: my $deeper = $depth+1;
4063: $text .= $name.' '
4064: .'<label><input type="checkbox" name="deletecategory" value="'
4065: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4066: if(ref($path) eq 'ARRAY') {
4067: push(@{$path},$name);
1.49 raeburn 4068: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4069: pop(@{$path});
4070: }
4071: } else {
1.59 bisitz 4072: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4073: if ($j == $numchildren) {
4074: $text .= $name;
4075: } else {
4076: $text .= $item;
4077: }
4078: $text .= '" value="" />';
4079: }
4080: $text .= '</td></tr>';
4081: }
4082: $text .= '</table></td>';
4083: } else {
4084: my $higher = $depth-1;
4085: if ($higher == 0) {
4086: $name = &escape($parent).'::'.$higher;
4087: } else {
4088: if (ref($path) eq 'ARRAY') {
4089: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4090: }
4091: }
4092: my $colspan;
4093: if ($parent ne 'instcode') {
4094: $colspan = $maxdepth - $depth - 1;
4095: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4096: }
4097: }
4098: }
4099: }
4100: return $text;
4101: }
4102:
1.33 raeburn 4103: sub modifiable_userdata_row {
1.63 raeburn 4104: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4105: my $rolename;
1.63 raeburn 4106: if ($context eq 'selfcreate') {
4107: if (ref($usertypes) eq 'HASH') {
4108: $rolename = $usertypes->{$role};
4109: } else {
4110: $rolename = $role;
4111: }
1.33 raeburn 4112: } else {
1.63 raeburn 4113: if ($role eq 'cr') {
4114: $rolename = &mt('Custom role');
4115: } else {
4116: $rolename = &Apache::lonnet::plaintext($role);
4117: }
1.33 raeburn 4118: }
4119: my @fields = ('lastname','firstname','middlename','generation',
4120: 'permanentemail','id');
4121: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4122: my $output;
4123: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4124: $output = '<tr '.$css_class.'>'.
4125: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4126: '<td class="LC_left_item" colspan="2"><table>';
4127: my $rem;
4128: my %checks;
4129: if (ref($settings) eq 'HASH') {
4130: if (ref($settings->{$context}) eq 'HASH') {
4131: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4132: foreach my $field (@fields) {
4133: if ($settings->{$context}->{$role}->{$field}) {
4134: $checks{$field} = ' checked="checked" ';
4135: }
4136: }
4137: }
4138: }
4139: }
4140: for (my $i=0; $i<@fields; $i++) {
4141: my $rem = $i%($numinrow);
4142: if ($rem == 0) {
4143: if ($i > 0) {
4144: $output .= '</tr>';
4145: }
4146: $output .= '<tr>';
4147: }
4148: my $check = ' ';
4149: if (exists($checks{$fields[$i]})) {
4150: $check = $checks{$fields[$i]}
4151: } else {
4152: if ($role eq 'st') {
4153: if (ref($settings) ne 'HASH') {
4154: $check = ' checked="checked" ';
4155: }
4156: }
4157: }
4158: $output .= '<td class="LC_left_item">'.
4159: '<span class="LC_nobreak"><label>'.
4160: '<input type="checkbox" name="canmodify_'.$role.'" '.
4161: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4162: '</label></span></td>';
4163: $rem = @fields%($numinrow);
4164: }
4165: my $colsleft = $numinrow - $rem;
4166: if ($colsleft > 1 ) {
4167: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4168: ' </td>';
4169: } elsif ($colsleft == 1) {
4170: $output .= '<td class="LC_left_item"> </td>';
4171: }
4172: $output .= '</tr></table></td></tr>';
4173: return $output;
4174: }
1.28 raeburn 4175:
1.93 raeburn 4176: sub insttypes_row {
4177: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4178: my %lt = &Apache::lonlocal::texthash (
4179: cansearch => 'Users allowed to search',
4180: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4181: lockablenames => 'User preference to lock name',
1.93 raeburn 4182: );
4183: my $showdom;
4184: if ($context eq 'cansearch') {
4185: $showdom = ' ('.$dom.')';
4186: }
1.25 raeburn 4187: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4188: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 4189: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 4190: my $rem;
4191: if (ref($types) eq 'ARRAY') {
4192: for (my $i=0; $i<@{$types}; $i++) {
4193: if (defined($usertypes->{$types->[$i]})) {
4194: my $rem = $i%($numinrow);
4195: if ($rem == 0) {
4196: if ($i > 0) {
4197: $output .= '</tr>';
4198: }
4199: $output .= '<tr>';
1.23 raeburn 4200: }
1.26 raeburn 4201: my $check = ' ';
1.99 raeburn 4202: if (ref($settings) eq 'HASH') {
4203: if (ref($settings->{$context}) eq 'ARRAY') {
4204: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4205: $check = ' checked="checked" ';
4206: }
4207: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4208: $check = ' checked="checked" ';
4209: }
1.23 raeburn 4210: }
1.26 raeburn 4211: $output .= '<td class="LC_left_item">'.
4212: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4213: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4214: 'value="'.$types->[$i].'"'.$check.'/>'.
4215: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4216: }
4217: }
1.26 raeburn 4218: $rem = @{$types}%($numinrow);
1.23 raeburn 4219: }
4220: my $colsleft = $numinrow - $rem;
1.131 raeburn 4221: if (($rem == 0) && (@{$types} > 0)) {
4222: $output .= '<tr>';
4223: }
1.23 raeburn 4224: if ($colsleft > 1) {
1.25 raeburn 4225: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4226: } else {
1.25 raeburn 4227: $output .= '<td class="LC_left_item">';
1.23 raeburn 4228: }
4229: my $defcheck = ' ';
1.99 raeburn 4230: if (ref($settings) eq 'HASH') {
4231: if (ref($settings->{$context}) eq 'ARRAY') {
4232: if (grep(/^default$/,@{$settings->{$context}})) {
4233: $defcheck = ' checked="checked" ';
4234: }
4235: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4236: $defcheck = ' checked="checked" ';
4237: }
1.23 raeburn 4238: }
1.25 raeburn 4239: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4240: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4241: 'value="default"'.$defcheck.'/>'.
4242: $othertitle.'</label></span></td>'.
4243: '</tr></table></td></tr>';
4244: return $output;
1.23 raeburn 4245: }
4246:
4247: sub sorted_searchtitles {
4248: my %searchtitles = &Apache::lonlocal::texthash(
4249: 'uname' => 'username',
4250: 'lastname' => 'last name',
4251: 'lastfirst' => 'last name, first name',
4252: );
4253: my @titleorder = ('uname','lastname','lastfirst');
4254: return (\%searchtitles,\@titleorder);
4255: }
4256:
1.25 raeburn 4257: sub sorted_searchtypes {
4258: my %srchtypes_desc = (
4259: exact => 'is exact match',
4260: contains => 'contains ..',
4261: begins => 'begins with ..',
4262: );
4263: my @srchtypeorder = ('exact','begins','contains');
4264: return (\%srchtypes_desc,\@srchtypeorder);
4265: }
4266:
1.3 raeburn 4267: sub usertype_update_row {
4268: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4269: my $datatable;
4270: my $numinrow = 4;
4271: foreach my $type (@{$types}) {
4272: if (defined($usertypes->{$type})) {
4273: $$rownums ++;
4274: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4275: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4276: '</td><td class="LC_left_item"><table>';
4277: for (my $i=0; $i<@{$fields}; $i++) {
4278: my $rem = $i%($numinrow);
4279: if ($rem == 0) {
4280: if ($i > 0) {
4281: $datatable .= '</tr>';
4282: }
4283: $datatable .= '<tr>';
4284: }
4285: my $check = ' ';
1.39 raeburn 4286: if (ref($settings) eq 'HASH') {
4287: if (ref($settings->{'fields'}) eq 'HASH') {
4288: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4289: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4290: $check = ' checked="checked" ';
4291: }
1.3 raeburn 4292: }
4293: }
4294: }
4295:
4296: if ($i == @{$fields}-1) {
4297: my $colsleft = $numinrow - $rem;
4298: if ($colsleft > 1) {
4299: $datatable .= '<td colspan="'.$colsleft.'">';
4300: } else {
4301: $datatable .= '<td>';
4302: }
4303: } else {
4304: $datatable .= '<td>';
4305: }
1.8 raeburn 4306: $datatable .= '<span class="LC_nobreak"><label>'.
4307: '<input type="checkbox" name="updateable_'.$type.
4308: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4309: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4310: }
4311: $datatable .= '</tr></table></td></tr>';
4312: }
4313: }
4314: return $datatable;
1.1 raeburn 4315: }
4316:
4317: sub modify_login {
1.9 raeburn 4318: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 4319: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 4320: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 4321: adminmail => 'Display administrator E-mail address',
1.43 raeburn 4322: newuser => 'Link for visitors to create a user account',
1.41 raeburn 4323: loginheader => 'Log-in box header');
1.3 raeburn 4324: my @offon = ('off','on');
1.112 raeburn 4325: my %curr_loginvia;
4326: if (ref($domconfig{login}) eq 'HASH') {
4327: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4328: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4329: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4330: }
4331: }
4332: }
1.6 raeburn 4333: my %loginhash;
1.9 raeburn 4334: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4335: \%domconfig,\%loginhash);
1.118 jms 4336: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4337: foreach my $item (@toggles) {
4338: $loginhash{login}{$item} = $env{'form.'.$item};
4339: }
1.41 raeburn 4340: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4341: if (ref($colchanges{'login'}) eq 'HASH') {
4342: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4343: \%loginhash);
4344: }
1.110 raeburn 4345:
1.149 raeburn 4346: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4347: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4348: if (keys(%servers) > 1) {
4349: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4350: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4351: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4352: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4353: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4354: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4355: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4356: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4357: $changes{'loginvia'}{$lonhost} = 1;
4358: } else {
4359: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4360: $changes{'loginvia'}{$lonhost} = 1;
4361: }
4362: } else {
4363: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4364: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4365: $changes{'loginvia'}{$lonhost} = 1;
4366: }
4367: }
4368: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4369: foreach my $item (@loginvia_attribs) {
4370: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4371: }
4372: } else {
4373: foreach my $item (@loginvia_attribs) {
4374: my $new = $env{'form.'.$lonhost.'_'.$item};
4375: if (($item eq 'serverpath') && ($new eq 'custom')) {
4376: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4377: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4378: $new = '/';
4379: }
4380: }
4381: if (($item eq 'custompath') &&
4382: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4383: $new = '';
4384: }
4385: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4386: $changes{'loginvia'}{$lonhost} = 1;
4387: }
4388: if ($item eq 'exempt') {
4389: $new =~ s/^\s+//;
4390: $new =~ s/\s+$//;
4391: my @poss_ips = split(/\s*[,:]\s*/,$new);
4392: my @okips;
4393: foreach my $ip (@poss_ips) {
4394: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4395: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4396: push(@okips,$ip);
4397: }
4398: }
4399: }
4400: if (@okips > 0) {
4401: $new = join(',',@okips);
4402: } else {
4403: $new = '';
4404: }
4405: }
4406:
4407: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4408: }
4409: }
1.112 raeburn 4410: } else {
1.128 raeburn 4411: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4412: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4413: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4414: foreach my $item (@loginvia_attribs) {
4415: my $new = $env{'form.'.$lonhost.'_'.$item};
4416: if (($item eq 'serverpath') && ($new eq 'custom')) {
4417: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4418: $new = '/';
4419: }
4420: }
4421: if (($item eq 'custompath') &&
4422: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4423: $new = '';
4424: }
4425: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4426: }
1.110 raeburn 4427: }
4428: }
4429: }
4430: }
1.119 raeburn 4431:
1.1 raeburn 4432: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4433: $dom);
4434: if ($putresult eq 'ok') {
1.118 jms 4435: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4436: my %defaultchecked = (
4437: 'coursecatalog' => 'on',
4438: 'adminmail' => 'off',
1.43 raeburn 4439: 'newuser' => 'off',
1.42 raeburn 4440: );
1.55 raeburn 4441: if (ref($domconfig{'login'}) eq 'HASH') {
4442: foreach my $item (@toggles) {
4443: if ($defaultchecked{$item} eq 'on') {
4444: if (($domconfig{'login'}{$item} eq '0') &&
4445: ($env{'form.'.$item} eq '1')) {
4446: $changes{$item} = 1;
4447: } elsif (($domconfig{'login'}{$item} eq '' ||
4448: $domconfig{'login'}{$item} eq '1') &&
4449: ($env{'form.'.$item} eq '0')) {
4450: $changes{$item} = 1;
4451: }
4452: } elsif ($defaultchecked{$item} eq 'off') {
4453: if (($domconfig{'login'}{$item} eq '1') &&
4454: ($env{'form.'.$item} eq '0')) {
4455: $changes{$item} = 1;
4456: } elsif (($domconfig{'login'}{$item} eq '' ||
4457: $domconfig{'login'}{$item} eq '0') &&
4458: ($env{'form.'.$item} eq '1')) {
4459: $changes{$item} = 1;
4460: }
1.42 raeburn 4461: }
4462: }
1.41 raeburn 4463: }
1.6 raeburn 4464: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4465: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4466: $resulttext = &mt('Changes made:').'<ul>';
4467: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4468: if ($item eq 'loginvia') {
1.112 raeburn 4469: if (ref($changes{$item}) eq 'HASH') {
4470: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4471: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4472: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4473: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4474: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4475: $protocol = 'http' if ($protocol ne 'https');
4476: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4477:
4478: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4479: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4480: } else {
4481: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4482: }
4483: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4484: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4485: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4486: }
4487: $resulttext .= '</li>';
4488: } else {
4489: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4490: }
1.112 raeburn 4491: } else {
1.128 raeburn 4492: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4493: }
4494: }
1.128 raeburn 4495: $resulttext .= '</ul></li>';
1.112 raeburn 4496: }
1.41 raeburn 4497: } else {
4498: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4499: }
1.1 raeburn 4500: }
1.6 raeburn 4501: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4502: } else {
4503: $resulttext = &mt('No changes made to log-in page settings');
4504: }
4505: } else {
1.11 albertel 4506: $resulttext = '<span class="LC_error">'.
4507: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4508: }
1.6 raeburn 4509: if ($errors) {
1.9 raeburn 4510: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4511: $errors.'</ul>';
4512: }
4513: return $resulttext;
4514: }
4515:
4516: sub color_font_choices {
4517: my %choices =
4518: &Apache::lonlocal::texthash (
4519: img => "Header",
4520: bgs => "Background colors",
4521: links => "Link colors",
1.55 raeburn 4522: images => "Images",
1.6 raeburn 4523: font => "Font color",
1.97 tempelho 4524: fontmenu => "Font Menu",
1.76 raeburn 4525: pgbg => "Page",
1.6 raeburn 4526: tabbg => "Header",
4527: sidebg => "Border",
4528: link => "Link",
4529: alink => "Active link",
4530: vlink => "Visited link",
4531: );
4532: return %choices;
4533: }
4534:
4535: sub modify_rolecolors {
1.9 raeburn 4536: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4537: my ($resulttext,%rolehash);
4538: $rolehash{'rolecolors'} = {};
1.55 raeburn 4539: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4540: if ($domconfig{'rolecolors'} eq '') {
4541: $domconfig{'rolecolors'} = {};
4542: }
4543: }
1.9 raeburn 4544: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4545: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4546: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4547: $dom);
4548: if ($putresult eq 'ok') {
4549: if (keys(%changes) > 0) {
1.41 raeburn 4550: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4551: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4552: $rolehash{'rolecolors'});
4553: } else {
4554: $resulttext = &mt('No changes made to default color schemes');
4555: }
4556: } else {
1.11 albertel 4557: $resulttext = '<span class="LC_error">'.
4558: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4559: }
4560: if ($errors) {
4561: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4562: $errors.'</ul>';
4563: }
4564: return $resulttext;
4565: }
4566:
4567: sub modify_colors {
1.9 raeburn 4568: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4569: my (%changes,%choices);
1.51 raeburn 4570: my @bgs;
1.6 raeburn 4571: my @links = ('link','alink','vlink');
1.41 raeburn 4572: my @logintext;
1.6 raeburn 4573: my @images;
4574: my $servadm = $r->dir_config('lonAdmEMail');
4575: my $errors;
4576: foreach my $role (@{$roles}) {
4577: if ($role eq 'login') {
1.12 raeburn 4578: %choices = &login_choices();
1.41 raeburn 4579: @logintext = ('textcol','bgcol');
1.12 raeburn 4580: } else {
4581: %choices = &color_font_choices();
1.107 raeburn 4582: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4583: }
4584: if ($role eq 'login') {
1.41 raeburn 4585: @images = ('img','logo','domlogo','login');
1.51 raeburn 4586: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4587: } else {
4588: @images = ('img');
1.51 raeburn 4589: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4590: }
4591: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4592: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4593: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4594: }
1.46 raeburn 4595: my ($configuserok,$author_ok,$switchserver) =
4596: &config_check($dom,$confname,$servadm);
1.9 raeburn 4597: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4598: if (ref($domconfig->{$role}) ne 'HASH') {
4599: $domconfig->{$role} = {};
4600: }
1.8 raeburn 4601: foreach my $img (@images) {
1.70 raeburn 4602: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4603: if (defined($env{'form.login_showlogo_'.$img})) {
4604: $confhash->{$role}{'showlogo'}{$img} = 1;
4605: } else {
4606: $confhash->{$role}{'showlogo'}{$img} = 0;
4607: }
4608: }
1.18 albertel 4609: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4610: && !defined($domconfig->{$role}{$img})
4611: && !$env{'form.'.$role.'_del_'.$img}
4612: && $env{'form.'.$role.'_import_'.$img}) {
4613: # import the old configured image from the .tab setting
4614: # if they haven't provided a new one
4615: $domconfig->{$role}{$img} =
4616: $env{'form.'.$role.'_import_'.$img};
4617: }
1.6 raeburn 4618: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4619: my $error;
1.6 raeburn 4620: if ($configuserok eq 'ok') {
1.9 raeburn 4621: if ($switchserver) {
1.12 raeburn 4622: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4623: } else {
4624: if ($author_ok eq 'ok') {
4625: my ($result,$logourl) =
4626: &publishlogo($r,'upload',$role.'_'.$img,
4627: $dom,$confname,$img,$width,$height);
4628: if ($result eq 'ok') {
4629: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4630: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4631: } else {
1.12 raeburn 4632: $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 4633: }
4634: } else {
1.46 raeburn 4635: $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 4636: }
4637: }
4638: } else {
1.46 raeburn 4639: $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 4640: }
4641: if ($error) {
1.8 raeburn 4642: &Apache::lonnet::logthis($error);
1.11 albertel 4643: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4644: }
4645: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4646: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4647: my $error;
4648: if ($configuserok eq 'ok') {
4649: # is confname an author?
4650: if ($switchserver eq '') {
4651: if ($author_ok eq 'ok') {
4652: my ($result,$logourl) =
4653: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4654: $dom,$confname,$img,$width,$height);
4655: if ($result eq 'ok') {
4656: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4657: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4658: }
4659: }
4660: }
4661: }
1.6 raeburn 4662: }
4663: }
4664: }
4665: if (ref($domconfig) eq 'HASH') {
4666: if (ref($domconfig->{$role}) eq 'HASH') {
4667: foreach my $img (@images) {
4668: if ($domconfig->{$role}{$img} ne '') {
4669: if ($env{'form.'.$role.'_del_'.$img}) {
4670: $confhash->{$role}{$img} = '';
1.12 raeburn 4671: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4672: } else {
1.9 raeburn 4673: if ($confhash->{$role}{$img} eq '') {
4674: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4675: }
1.6 raeburn 4676: }
4677: } else {
4678: if ($env{'form.'.$role.'_del_'.$img}) {
4679: $confhash->{$role}{$img} = '';
1.12 raeburn 4680: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4681: }
4682: }
1.70 raeburn 4683: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4684: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4685: if ($confhash->{$role}{'showlogo'}{$img} ne
4686: $domconfig->{$role}{'showlogo'}{$img}) {
4687: $changes{$role}{'showlogo'}{$img} = 1;
4688: }
4689: } else {
4690: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4691: $changes{$role}{'showlogo'}{$img} = 1;
4692: }
4693: }
4694: }
4695: }
1.6 raeburn 4696: if ($domconfig->{$role}{'font'} ne '') {
4697: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4698: $changes{$role}{'font'} = 1;
4699: }
4700: } else {
4701: if ($confhash->{$role}{'font'}) {
4702: $changes{$role}{'font'} = 1;
4703: }
4704: }
1.107 raeburn 4705: if ($role ne 'login') {
4706: if ($domconfig->{$role}{'fontmenu'} ne '') {
4707: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4708: $changes{$role}{'fontmenu'} = 1;
4709: }
4710: } else {
4711: if ($confhash->{$role}{'fontmenu'}) {
4712: $changes{$role}{'fontmenu'} = 1;
4713: }
1.97 tempelho 4714: }
4715: }
1.6 raeburn 4716: foreach my $item (@bgs) {
4717: if ($domconfig->{$role}{$item} ne '') {
4718: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4719: $changes{$role}{'bgs'}{$item} = 1;
4720: }
4721: } else {
4722: if ($confhash->{$role}{$item}) {
4723: $changes{$role}{'bgs'}{$item} = 1;
4724: }
4725: }
4726: }
4727: foreach my $item (@links) {
4728: if ($domconfig->{$role}{$item} ne '') {
4729: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4730: $changes{$role}{'links'}{$item} = 1;
4731: }
4732: } else {
4733: if ($confhash->{$role}{$item}) {
4734: $changes{$role}{'links'}{$item} = 1;
4735: }
4736: }
4737: }
1.41 raeburn 4738: foreach my $item (@logintext) {
4739: if ($domconfig->{$role}{$item} ne '') {
4740: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4741: $changes{$role}{'logintext'}{$item} = 1;
4742: }
4743: } else {
4744: if ($confhash->{$role}{$item}) {
4745: $changes{$role}{'logintext'}{$item} = 1;
4746: }
4747: }
4748: }
1.6 raeburn 4749: } else {
4750: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4751: \@logintext,$confhash,\%changes);
1.6 raeburn 4752: }
4753: } else {
4754: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4755: \@logintext,$confhash,\%changes);
1.6 raeburn 4756: }
4757: }
4758: return ($errors,%changes);
4759: }
4760:
1.46 raeburn 4761: sub config_check {
4762: my ($dom,$confname,$servadm) = @_;
4763: my ($configuserok,$author_ok,$switchserver,%currroles);
4764: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4765: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4766: $confname,$servadm);
4767: if ($configuserok eq 'ok') {
4768: $switchserver = &check_switchserver($dom,$confname);
4769: if ($switchserver eq '') {
4770: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4771: }
4772: }
4773: return ($configuserok,$author_ok,$switchserver);
4774: }
4775:
1.6 raeburn 4776: sub default_change_checker {
1.41 raeburn 4777: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4778: foreach my $item (@{$links}) {
4779: if ($confhash->{$role}{$item}) {
4780: $changes->{$role}{'links'}{$item} = 1;
4781: }
4782: }
4783: foreach my $item (@{$bgs}) {
4784: if ($confhash->{$role}{$item}) {
4785: $changes->{$role}{'bgs'}{$item} = 1;
4786: }
4787: }
1.41 raeburn 4788: foreach my $item (@{$logintext}) {
4789: if ($confhash->{$role}{$item}) {
4790: $changes->{$role}{'logintext'}{$item} = 1;
4791: }
4792: }
1.6 raeburn 4793: foreach my $img (@{$images}) {
4794: if ($env{'form.'.$role.'_del_'.$img}) {
4795: $confhash->{$role}{$img} = '';
1.12 raeburn 4796: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4797: }
1.70 raeburn 4798: if ($role eq 'login') {
4799: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4800: $changes->{$role}{'showlogo'}{$img} = 1;
4801: }
4802: }
1.6 raeburn 4803: }
4804: if ($confhash->{$role}{'font'}) {
4805: $changes->{$role}{'font'} = 1;
4806: }
1.48 raeburn 4807: }
1.6 raeburn 4808:
4809: sub display_colorchgs {
4810: my ($dom,$changes,$roles,$confhash) = @_;
4811: my (%choices,$resulttext);
4812: if (!grep(/^login$/,@{$roles})) {
4813: $resulttext = &mt('Changes made:').'<br />';
4814: }
4815: foreach my $role (@{$roles}) {
4816: if ($role eq 'login') {
4817: %choices = &login_choices();
4818: } else {
4819: %choices = &color_font_choices();
4820: }
4821: if (ref($changes->{$role}) eq 'HASH') {
4822: if ($role ne 'login') {
4823: $resulttext .= '<h4>'.&mt($role).'</h4>';
4824: }
4825: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4826: if ($role ne 'login') {
4827: $resulttext .= '<ul>';
4828: }
4829: if (ref($changes->{$role}{$key}) eq 'HASH') {
4830: if ($role ne 'login') {
4831: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4832: }
4833: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4834: if (($role eq 'login') && ($key eq 'showlogo')) {
4835: if ($confhash->{$role}{$key}{$item}) {
4836: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4837: } else {
4838: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4839: }
4840: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4841: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4842: } else {
1.12 raeburn 4843: my $newitem = $confhash->{$role}{$item};
4844: if ($key eq 'images') {
4845: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4846: }
4847: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4848: }
4849: }
4850: if ($role ne 'login') {
4851: $resulttext .= '</ul></li>';
4852: }
4853: } else {
4854: if ($confhash->{$role}{$key} eq '') {
4855: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4856: } else {
4857: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4858: }
4859: }
4860: if ($role ne 'login') {
4861: $resulttext .= '</ul>';
4862: }
4863: }
4864: }
4865: }
1.3 raeburn 4866: return $resulttext;
1.1 raeburn 4867: }
4868:
1.9 raeburn 4869: sub thumb_dimensions {
4870: return ('200','50');
4871: }
4872:
1.16 raeburn 4873: sub check_dimensions {
4874: my ($inputfile) = @_;
4875: my ($fullwidth,$fullheight);
4876: if ($inputfile =~ m|^[/\w.\-]+$|) {
4877: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4878: my $imageinfo = <PIPE>;
4879: if (!close(PIPE)) {
4880: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4881: }
4882: chomp($imageinfo);
4883: my ($fullsize) =
1.21 raeburn 4884: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4885: if ($fullsize) {
4886: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4887: }
4888: }
4889: }
4890: return ($fullwidth,$fullheight);
4891: }
4892:
1.9 raeburn 4893: sub check_configuser {
4894: my ($uhome,$dom,$confname,$servadm) = @_;
4895: my ($configuserok,%currroles);
4896: if ($uhome eq 'no_host') {
4897: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4898: my $configpass = &LONCAPA::Enrollment::create_password();
4899: $configuserok =
4900: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4901: $configpass,'','','','','',undef,$servadm);
4902: } else {
4903: $configuserok = 'ok';
4904: %currroles =
4905: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4906: }
4907: return ($configuserok,%currroles);
4908: }
4909:
4910: sub check_authorstatus {
4911: my ($dom,$confname,%currroles) = @_;
4912: my $author_ok;
1.40 raeburn 4913: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4914: my $start = time;
4915: my $end = 0;
4916: $author_ok =
4917: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4918: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4919: } else {
4920: $author_ok = 'ok';
4921: }
4922: return $author_ok;
4923: }
4924:
4925: sub publishlogo {
1.46 raeburn 4926: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4927: my ($output,$fname,$logourl);
4928: if ($action eq 'upload') {
4929: $fname=$env{'form.'.$formname.'.filename'};
4930: chop($env{'form.'.$formname});
4931: } else {
4932: ($fname) = ($formname =~ /([^\/]+)$/);
4933: }
1.46 raeburn 4934: if ($savefileas ne '') {
4935: $fname = $savefileas;
4936: }
1.9 raeburn 4937: $fname=&Apache::lonnet::clean_filename($fname);
4938: # See if there is anything left
4939: unless ($fname) { return ('error: no uploaded file'); }
4940: $fname="$subdir/$fname";
1.158 raeburn 4941: my $filepath=$r->dir_config('lonDocRoot')."/priv/$dom/$confname";
1.9 raeburn 4942: my ($fnamepath,$file,$fetchthumb);
4943: $file=$fname;
4944: if ($fname=~m|/|) {
4945: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4946: }
4947: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4948: my $count;
4949: for ($count=4;$count<=$#parts;$count++) {
4950: $filepath.="/$parts[$count]";
4951: if ((-e $filepath)!=1) {
4952: mkdir($filepath,02770);
4953: }
4954: }
4955: # Check for bad extension and disallow upload
4956: if ($file=~/\.(\w+)$/ &&
4957: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4958: $output =
4959: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4960: } elsif ($file=~/\.(\w+)$/ &&
4961: !defined(&Apache::loncommon::fileembstyle($1))) {
4962: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4963: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4964: $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 4965: } elsif (-d "$filepath/$file") {
4966: $output = &mt('File name is a directory name - rename the file and re-upload');
4967: } else {
4968: my $source = $filepath.'/'.$file;
4969: my $logfile;
4970: if (!open($logfile,">>$source".'.log')) {
4971: return (&mt('No write permission to Construction Space'));
4972: }
4973: print $logfile
4974: "\n================= Publish ".localtime()." ================\n".
4975: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4976: # Save the file
4977: if (!open(FH,'>'.$source)) {
4978: &Apache::lonnet::logthis('Failed to create '.$source);
4979: return (&mt('Failed to create file'));
4980: }
4981: if ($action eq 'upload') {
4982: if (!print FH ($env{'form.'.$formname})) {
4983: &Apache::lonnet::logthis('Failed to write to '.$source);
4984: return (&mt('Failed to write file'));
4985: }
4986: } else {
4987: my $original = &Apache::lonnet::filelocation('',$formname);
4988: if(!copy($original,$source)) {
4989: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4990: return (&mt('Failed to write file'));
4991: }
4992: }
4993: close(FH);
4994: chmod(0660, $source); # Permissions to rw-rw---.
4995:
4996: my $docroot=$r->dir_config('lonDocRoot');
4997: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4998: my $copyfile=$targetdir.'/'.$file;
4999:
5000: my @parts=split(/\//,$targetdir);
5001: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5002: for (my $count=5;$count<=$#parts;$count++) {
5003: $path.="/$parts[$count]";
5004: if (!-e $path) {
5005: print $logfile "\nCreating directory ".$path;
5006: mkdir($path,02770);
5007: }
5008: }
5009: my $versionresult;
5010: if (-e $copyfile) {
5011: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5012: } else {
5013: $versionresult = 'ok';
5014: }
5015: if ($versionresult eq 'ok') {
5016: if (copy($source,$copyfile)) {
5017: print $logfile "\nCopied original source to ".$copyfile."\n";
5018: $output = 'ok';
5019: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5020: push(@{$modified_urls},[$copyfile,$source]);
5021: my $metaoutput =
5022: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5023: unless ($registered_cleanup) {
5024: my $handlers = $r->get_handlers('PerlCleanupHandler');
5025: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5026: $registered_cleanup=1;
5027: }
1.9 raeburn 5028: } else {
5029: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5030: $output = &mt('Failed to copy file to RES space').", $!";
5031: }
5032: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5033: my $inputfile = $filepath.'/'.$file;
5034: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5035: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5036: if ($fullwidth ne '' && $fullheight ne '') {
5037: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5038: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5039: system("convert -sample $thumbsize $inputfile $outfile");
5040: chmod(0660, $filepath.'/tn-'.$file);
5041: if (-e $outfile) {
5042: my $copyfile=$targetdir.'/tn-'.$file;
5043: if (copy($outfile,$copyfile)) {
5044: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5045: my $thumb_metaoutput =
5046: &write_metadata($dom,$confname,$formname,
5047: $targetdir,'tn-'.$file,$logfile);
5048: push(@{$modified_urls},[$copyfile,$outfile]);
5049: unless ($registered_cleanup) {
5050: my $handlers = $r->get_handlers('PerlCleanupHandler');
5051: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5052: $registered_cleanup=1;
5053: }
1.16 raeburn 5054: } else {
5055: print $logfile "\nUnable to write ".$copyfile.
5056: ':'.$!."\n";
5057: }
5058: }
1.9 raeburn 5059: }
5060: }
5061: }
5062: } else {
5063: $output = $versionresult;
5064: }
5065: }
5066: return ($output,$logourl);
5067: }
5068:
5069: sub logo_versioning {
5070: my ($targetdir,$file,$logfile) = @_;
5071: my $target = $targetdir.'/'.$file;
5072: my ($maxversion,$fn,$extn,$output);
5073: $maxversion = 0;
5074: if ($file =~ /^(.+)\.(\w+)$/) {
5075: $fn=$1;
5076: $extn=$2;
5077: }
5078: opendir(DIR,$targetdir);
5079: while (my $filename=readdir(DIR)) {
5080: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5081: $maxversion=($1>$maxversion)?$1:$maxversion;
5082: }
5083: }
5084: $maxversion++;
5085: print $logfile "\nCreating old version ".$maxversion."\n";
5086: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5087: if (copy($target,$copyfile)) {
5088: print $logfile "Copied old target to ".$copyfile."\n";
5089: $copyfile=$copyfile.'.meta';
5090: if (copy($target.'.meta',$copyfile)) {
5091: print $logfile "Copied old target metadata to ".$copyfile."\n";
5092: $output = 'ok';
5093: } else {
5094: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5095: $output = &mt('Failed to copy old meta').", $!, ";
5096: }
5097: } else {
5098: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5099: $output = &mt('Failed to copy old target').", $!, ";
5100: }
5101: return $output;
5102: }
5103:
5104: sub write_metadata {
5105: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5106: my (%metadatafields,%metadatakeys,$output);
5107: $metadatafields{'title'}=$formname;
5108: $metadatafields{'creationdate'}=time;
5109: $metadatafields{'lastrevisiondate'}=time;
5110: $metadatafields{'copyright'}='public';
5111: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5112: $env{'user.domain'};
5113: $metadatafields{'authorspace'}=$confname.':'.$dom;
5114: $metadatafields{'domain'}=$dom;
5115: {
5116: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5117: my $mfh;
1.155 raeburn 5118: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5119: foreach (sort keys %metadatafields) {
5120: unless ($_=~/\./) {
5121: my $unikey=$_;
5122: $unikey=~/^([A-Za-z]+)/;
5123: my $tag=$1;
5124: $tag=~tr/A-Z/a-z/;
5125: print $mfh "\n\<$tag";
5126: foreach (split(/\,/,$metadatakeys{$unikey})) {
5127: my $value=$metadatafields{$unikey.'.'.$_};
5128: $value=~s/\"/\'\'/g;
5129: print $mfh ' '.$_.'="'.$value.'"';
5130: }
5131: print $mfh '>'.
5132: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5133: .'</'.$tag.'>';
5134: }
5135: }
5136: $output = 'ok';
5137: print $logfile "\nWrote metadata";
5138: close($mfh);
5139: } else {
5140: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5141: $output = &mt('Could not write metadata');
5142: }
5143: }
1.155 raeburn 5144: return $output;
5145: }
5146:
5147: sub notifysubscribed {
5148: foreach my $targetsource (@{$modified_urls}){
5149: next unless (ref($targetsource) eq 'ARRAY');
5150: my ($target,$source)=@{$targetsource};
5151: if ($source ne '') {
5152: if (open(my $logfh,'>>'.$source.'.log')) {
5153: print $logfh "\nCleanup phase: Notifications\n";
5154: my @subscribed=&subscribed_hosts($target);
5155: foreach my $subhost (@subscribed) {
5156: print $logfh "\nNotifying host ".$subhost.':';
5157: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5158: print $logfh $reply;
5159: }
5160: my @subscribedmeta=&subscribed_hosts("$target.meta");
5161: foreach my $subhost (@subscribedmeta) {
5162: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5163: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5164: $subhost);
5165: print $logfh $reply;
5166: }
5167: print $logfh "\n============ Done ============\n";
1.160 raeburn 5168: close($logfh);
1.155 raeburn 5169: }
5170: }
5171: }
5172: return OK;
5173: }
5174:
5175: sub subscribed_hosts {
5176: my ($target) = @_;
5177: my @subscribed;
5178: if (open(my $fh,"<$target.subscription")) {
5179: while (my $subline=<$fh>) {
5180: if ($subline =~ /^($match_lonid):/) {
5181: my $host = $1;
5182: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5183: unless (grep(/^\Q$host\E$/,@subscribed)) {
5184: push(@subscribed,$host);
5185: }
5186: }
5187: }
5188: }
5189: }
5190: return @subscribed;
1.9 raeburn 5191: }
5192:
5193: sub check_switchserver {
5194: my ($dom,$confname) = @_;
5195: my ($allowed,$switchserver);
5196: my $home = &Apache::lonnet::homeserver($confname,$dom);
5197: if ($home eq 'no_host') {
5198: $home = &Apache::lonnet::domain($dom,'primary');
5199: }
5200: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5201: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5202: if (!$allowed) {
5203: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5204: }
5205: return $switchserver;
5206: }
5207:
1.1 raeburn 5208: sub modify_quotas {
1.86 raeburn 5209: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5210: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5211: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5212: if ($action eq 'quotas') {
5213: $context = 'tools';
5214: } else {
5215: $context = $action;
5216: }
5217: if ($context eq 'requestcourses') {
1.98 raeburn 5218: @usertools = ('official','unofficial','community');
1.106 raeburn 5219: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5220: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5221: %titles = &courserequest_titles();
5222: $toolregexp = join('|',@usertools);
5223: %conditions = &courserequest_conditions();
1.86 raeburn 5224: } else {
1.162 ! raeburn 5225: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5226: %titles = &tool_titles();
1.86 raeburn 5227: }
1.72 raeburn 5228: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5229: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5230: foreach my $key (keys(%env)) {
1.101 raeburn 5231: if ($context eq 'requestcourses') {
5232: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5233: my $item = $1;
5234: my $type = $2;
5235: if ($type =~ /^limit_(.+)/) {
5236: $limithash{$item}{$1} = $env{$key};
5237: } else {
5238: $confhash{$item}{$type} = $env{$key};
5239: }
5240: }
5241: } else {
1.86 raeburn 5242: if ($key =~ /^form\.quota_(.+)$/) {
5243: $confhash{'defaultquota'}{$1} = $env{$key};
5244: }
1.101 raeburn 5245: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5246: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5247: }
1.72 raeburn 5248: }
5249: }
1.102 raeburn 5250: if ($context eq 'requestcourses') {
5251: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5252: @approvalnotify = sort(@approvalnotify);
5253: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5254: if (ref($domconfig{$action}) eq 'HASH') {
5255: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5256: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5257: $changes{'notify'}{'approval'} = 1;
5258: }
5259: } else {
1.144 raeburn 5260: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5261: $changes{'notify'}{'approval'} = 1;
5262: }
5263: }
5264: } else {
1.144 raeburn 5265: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5266: $changes{'notify'}{'approval'} = 1;
5267: }
5268: }
5269: } else {
1.86 raeburn 5270: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5271: }
1.72 raeburn 5272: foreach my $item (@usertools) {
5273: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5274: my $unset;
1.101 raeburn 5275: if ($context eq 'requestcourses') {
1.104 raeburn 5276: $unset = '0';
5277: if ($type eq '_LC_adv') {
5278: $unset = '';
5279: }
1.101 raeburn 5280: if ($confhash{$item}{$type} eq 'autolimit') {
5281: $confhash{$item}{$type} .= '=';
5282: unless ($limithash{$item}{$type} =~ /\D/) {
5283: $confhash{$item}{$type} .= $limithash{$item}{$type};
5284: }
5285: }
1.72 raeburn 5286: } else {
1.101 raeburn 5287: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5288: $confhash{$item}{$type} = 1;
5289: } else {
5290: $confhash{$item}{$type} = 0;
5291: }
1.72 raeburn 5292: }
1.86 raeburn 5293: if (ref($domconfig{$action}) eq 'HASH') {
5294: if (ref($domconfig{$action}{$item}) eq 'HASH') {
5295: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5296: $changes{$item}{$type} = 1;
5297: }
5298: } else {
5299: if ($context eq 'requestcourses') {
1.104 raeburn 5300: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5301: $changes{$item}{$type} = 1;
5302: }
5303: } else {
5304: if (!$confhash{$item}{$type}) {
5305: $changes{$item}{$type} = 1;
5306: }
5307: }
5308: }
5309: } else {
5310: if ($context eq 'requestcourses') {
1.104 raeburn 5311: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5312: $changes{$item}{$type} = 1;
5313: }
5314: } else {
5315: if (!$confhash{$item}{$type}) {
5316: $changes{$item}{$type} = 1;
5317: }
5318: }
5319: }
1.1 raeburn 5320: }
5321: }
1.86 raeburn 5322: unless ($context eq 'requestcourses') {
5323: if (ref($domconfig{'quotas'}) eq 'HASH') {
5324: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5325: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5326: if (exists($confhash{'defaultquota'}{$key})) {
5327: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5328: $changes{'defaultquota'}{$key} = 1;
5329: }
5330: } else {
5331: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5332: }
5333: }
1.86 raeburn 5334: } else {
5335: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5336: if (exists($confhash{'defaultquota'}{$key})) {
5337: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5338: $changes{'defaultquota'}{$key} = 1;
5339: }
5340: } else {
5341: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5342: }
1.1 raeburn 5343: }
5344: }
5345: }
1.86 raeburn 5346: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5347: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5348: if (ref($domconfig{'quotas'}) eq 'HASH') {
5349: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5350: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5351: $changes{'defaultquota'}{$key} = 1;
5352: }
5353: } else {
5354: if (!exists($domconfig{'quotas'}{$key})) {
5355: $changes{'defaultquota'}{$key} = 1;
5356: }
1.72 raeburn 5357: }
5358: } else {
1.86 raeburn 5359: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5360: }
1.1 raeburn 5361: }
5362: }
5363: }
1.72 raeburn 5364:
5365: foreach my $key (keys(%confhash)) {
5366: $domdefaults{$key} = $confhash{$key};
5367: }
5368:
1.1 raeburn 5369: my %quotahash = (
1.86 raeburn 5370: $action => { %confhash }
1.1 raeburn 5371: );
5372: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5373: $dom);
5374: if ($putresult eq 'ok') {
5375: if (keys(%changes) > 0) {
1.72 raeburn 5376: my $cachetime = 24*60*60;
5377: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5378:
1.1 raeburn 5379: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 5380: unless ($context eq 'requestcourses') {
5381: if (ref($changes{'defaultquota'}) eq 'HASH') {
5382: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5383: foreach my $type (@{$types},'default') {
5384: if (defined($changes{'defaultquota'}{$type})) {
5385: my $typetitle = $usertypes->{$type};
5386: if ($type eq 'default') {
5387: $typetitle = $othertitle;
5388: }
5389: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5390: }
5391: }
1.86 raeburn 5392: $resulttext .= '</ul></li>';
1.72 raeburn 5393: }
5394: }
1.80 raeburn 5395: my %newenv;
1.72 raeburn 5396: foreach my $item (@usertools) {
5397: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 5398: my $newacc =
5399: &Apache::lonnet::usertools_access($env{'user.name'},
5400: $env{'user.domain'},
1.86 raeburn 5401: $item,'reload',$context);
5402: if ($context eq 'requestcourses') {
1.108 raeburn 5403: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5404: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5405: }
5406: } else {
5407: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5408: $newenv{'environment.availabletools.'.$item} = $newacc;
5409: }
1.80 raeburn 5410: }
1.72 raeburn 5411: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5412: foreach my $type (@{$types},'default','_LC_adv') {
5413: if ($changes{$item}{$type}) {
5414: my $typetitle = $usertypes->{$type};
5415: if ($type eq 'default') {
5416: $typetitle = $othertitle;
5417: } elsif ($type eq '_LC_adv') {
5418: $typetitle = 'LON-CAPA Advanced Users';
5419: }
5420: if ($confhash{$item}{$type}) {
1.101 raeburn 5421: if ($context eq 'requestcourses') {
5422: my $cond;
5423: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
5424: if ($1 eq '') {
5425: $cond = &mt('(Automatic processing of any request).');
5426: } else {
5427: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5428: }
5429: } else {
5430: $cond = $conditions{$confhash{$item}{$type}};
5431: }
5432: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5433: } else {
5434: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5435: }
1.72 raeburn 5436: } else {
1.104 raeburn 5437: if ($type eq '_LC_adv') {
5438: if ($confhash{$item}{$type} eq '0') {
5439: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5440: } else {
5441: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5442: }
5443: } else {
5444: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5445: }
1.72 raeburn 5446: }
5447: }
1.26 raeburn 5448: }
1.72 raeburn 5449: $resulttext .= '</ul></li>';
1.26 raeburn 5450: }
1.1 raeburn 5451: }
1.102 raeburn 5452: if ($action eq 'requestcourses') {
5453: if (ref($changes{'notify'}) eq 'HASH') {
5454: if ($changes{'notify'}{'approval'}) {
5455: if (ref($confhash{'notify'}) eq 'HASH') {
5456: if ($confhash{'notify'}{'approval'}) {
5457: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5458: } else {
5459: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
5460: }
5461: }
5462: }
5463: }
5464: }
1.1 raeburn 5465: $resulttext .= '</ul>';
1.80 raeburn 5466: if (keys(%newenv)) {
5467: &Apache::lonnet::appenv(\%newenv);
5468: }
1.1 raeburn 5469: } else {
1.86 raeburn 5470: if ($context eq 'requestcourses') {
5471: $resulttext = &mt('No changes made to rights to request creation of courses.');
5472: } else {
1.90 weissno 5473: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5474: }
1.1 raeburn 5475: }
5476: } else {
1.11 albertel 5477: $resulttext = '<span class="LC_error">'.
5478: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5479: }
1.3 raeburn 5480: return $resulttext;
1.1 raeburn 5481: }
5482:
1.3 raeburn 5483: sub modify_autoenroll {
5484: my ($dom,%domconfig) = @_;
1.1 raeburn 5485: my ($resulttext,%changes);
5486: my %currautoenroll;
5487: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5488: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5489: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5490: }
5491: }
5492: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5493: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5494: sender => 'Sender for notification messages',
5495: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5496: my @offon = ('off','on');
1.17 raeburn 5497: my $sender_uname = $env{'form.sender_uname'};
5498: my $sender_domain = $env{'form.sender_domain'};
5499: if ($sender_domain eq '') {
5500: $sender_uname = '';
5501: } elsif ($sender_uname eq '') {
5502: $sender_domain = '';
5503: }
1.129 raeburn 5504: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5505: my %autoenrollhash = (
1.129 raeburn 5506: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5507: 'sender_uname' => $sender_uname,
5508: 'sender_domain' => $sender_domain,
5509: 'co-owners' => $coowners,
1.1 raeburn 5510: }
5511: );
1.4 raeburn 5512: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5513: $dom);
1.1 raeburn 5514: if ($putresult eq 'ok') {
5515: if (exists($currautoenroll{'run'})) {
5516: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5517: $changes{'run'} = 1;
5518: }
5519: } elsif ($autorun) {
5520: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 5521: $changes{'run'} = 1;
1.1 raeburn 5522: }
5523: }
1.17 raeburn 5524: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 5525: $changes{'sender'} = 1;
5526: }
1.17 raeburn 5527: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 5528: $changes{'sender'} = 1;
5529: }
1.129 raeburn 5530: if ($currautoenroll{'co-owners'} ne '') {
5531: if ($currautoenroll{'co-owners'} ne $coowners) {
5532: $changes{'coowners'} = 1;
5533: }
5534: } elsif ($coowners) {
5535: $changes{'coowners'} = 1;
5536: }
1.1 raeburn 5537: if (keys(%changes) > 0) {
5538: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5539: if ($changes{'run'}) {
1.1 raeburn 5540: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5541: }
5542: if ($changes{'sender'}) {
1.17 raeburn 5543: if ($sender_uname eq '' || $sender_domain eq '') {
5544: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5545: } else {
5546: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5547: }
1.1 raeburn 5548: }
1.129 raeburn 5549: if ($changes{'coowners'}) {
5550: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5551: &Apache::loncommon::devalidate_domconfig_cache($dom);
5552: }
1.1 raeburn 5553: $resulttext .= '</ul>';
5554: } else {
5555: $resulttext = &mt('No changes made to auto-enrollment settings');
5556: }
5557: } else {
1.11 albertel 5558: $resulttext = '<span class="LC_error">'.
5559: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5560: }
1.3 raeburn 5561: return $resulttext;
1.1 raeburn 5562: }
5563:
5564: sub modify_autoupdate {
1.3 raeburn 5565: my ($dom,%domconfig) = @_;
1.1 raeburn 5566: my ($resulttext,%currautoupdate,%fields,%changes);
5567: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5568: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5569: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5570: }
5571: }
5572: my @offon = ('off','on');
5573: my %title = &Apache::lonlocal::texthash (
5574: run => 'Auto-update:',
5575: classlists => 'Updates to user information in classlists?'
5576: );
1.44 raeburn 5577: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5578: my %fieldtitles = &Apache::lonlocal::texthash (
5579: id => 'Student/Employee ID',
1.20 raeburn 5580: permanentemail => 'E-mail address',
1.1 raeburn 5581: lastname => 'Last Name',
5582: firstname => 'First Name',
5583: middlename => 'Middle Name',
1.132 raeburn 5584: generation => 'Generation',
1.1 raeburn 5585: );
1.142 raeburn 5586: $othertitle = &mt('All users');
1.1 raeburn 5587: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5588: $othertitle = &mt('Other users');
1.1 raeburn 5589: }
5590: foreach my $key (keys(%env)) {
5591: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5592: my ($usertype,$item) = ($1,$2);
5593: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5594: if ($usertype eq 'default') {
5595: push(@{$fields{$1}},$2);
5596: } elsif (ref($types) eq 'ARRAY') {
5597: if (grep(/^\Q$usertype\E$/,@{$types})) {
5598: push(@{$fields{$1}},$2);
5599: }
5600: }
5601: }
1.1 raeburn 5602: }
5603: }
1.131 raeburn 5604: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5605: @lockablenames = sort(@lockablenames);
5606: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5607: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5608: if (@changed) {
5609: $changes{'lockablenames'} = 1;
5610: }
5611: } else {
5612: if (@lockablenames) {
5613: $changes{'lockablenames'} = 1;
5614: }
5615: }
1.1 raeburn 5616: my %updatehash = (
5617: autoupdate => { run => $env{'form.autoupdate_run'},
5618: classlists => $env{'form.classlists'},
5619: fields => {%fields},
1.131 raeburn 5620: lockablenames => \@lockablenames,
1.1 raeburn 5621: }
5622: );
5623: foreach my $key (keys(%currautoupdate)) {
5624: if (($key eq 'run') || ($key eq 'classlists')) {
5625: if (exists($updatehash{autoupdate}{$key})) {
5626: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5627: $changes{$key} = 1;
5628: }
5629: }
5630: } elsif ($key eq 'fields') {
5631: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5632: foreach my $item (@{$types},'default') {
1.1 raeburn 5633: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5634: my $change = 0;
5635: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5636: if (!exists($fields{$item})) {
5637: $change = 1;
1.132 raeburn 5638: last;
1.1 raeburn 5639: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5640: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5641: $change = 1;
1.132 raeburn 5642: last;
1.1 raeburn 5643: }
5644: }
5645: }
5646: if ($change) {
5647: push(@{$changes{$key}},$item);
5648: }
1.26 raeburn 5649: }
1.1 raeburn 5650: }
5651: }
1.131 raeburn 5652: } elsif ($key eq 'lockablenames') {
5653: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5654: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5655: if (@changed) {
5656: $changes{'lockablenames'} = 1;
5657: }
5658: } else {
5659: if (@lockablenames) {
5660: $changes{'lockablenames'} = 1;
5661: }
5662: }
5663: }
5664: }
5665: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5666: if (@lockablenames) {
5667: $changes{'lockablenames'} = 1;
1.1 raeburn 5668: }
5669: }
1.26 raeburn 5670: foreach my $item (@{$types},'default') {
5671: if (defined($fields{$item})) {
5672: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5673: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5674: my $change = 0;
5675: if (ref($fields{$item}) eq 'ARRAY') {
5676: foreach my $type (@{$fields{$item}}) {
5677: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5678: $change = 1;
5679: last;
5680: }
5681: }
5682: }
5683: if ($change) {
5684: push(@{$changes{'fields'}},$item);
5685: }
5686: } else {
1.26 raeburn 5687: push(@{$changes{'fields'}},$item);
5688: }
5689: } else {
5690: push(@{$changes{'fields'}},$item);
1.1 raeburn 5691: }
5692: }
5693: }
5694: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5695: $dom);
5696: if ($putresult eq 'ok') {
5697: if (keys(%changes) > 0) {
5698: $resulttext = &mt('Changes made:').'<ul>';
5699: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5700: if ($key eq 'lockablenames') {
5701: $resulttext .= '<li>';
5702: if (@lockablenames) {
5703: $usertypes->{'default'} = $othertitle;
5704: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5705: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5706: } else {
5707: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5708: }
5709: $resulttext .= '</li>';
5710: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5711: foreach my $item (@{$changes{$key}}) {
5712: my @newvalues;
5713: foreach my $type (@{$fields{$item}}) {
5714: push(@newvalues,$fieldtitles{$type});
5715: }
1.3 raeburn 5716: my $newvaluestr;
5717: if (@newvalues > 0) {
5718: $newvaluestr = join(', ',@newvalues);
5719: } else {
5720: $newvaluestr = &mt('none');
1.6 raeburn 5721: }
1.1 raeburn 5722: if ($item eq 'default') {
1.26 raeburn 5723: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5724: } else {
1.26 raeburn 5725: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5726: }
5727: }
5728: } else {
5729: my $newvalue;
5730: if ($key eq 'run') {
5731: $newvalue = $offon[$env{'form.autoupdate_run'}];
5732: } else {
5733: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5734: }
1.1 raeburn 5735: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5736: }
5737: }
5738: $resulttext .= '</ul>';
5739: } else {
1.3 raeburn 5740: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5741: }
5742: } else {
1.11 albertel 5743: $resulttext = '<span class="LC_error">'.
5744: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5745: }
1.3 raeburn 5746: return $resulttext;
1.1 raeburn 5747: }
5748:
1.125 raeburn 5749: sub modify_autocreate {
5750: my ($dom,%domconfig) = @_;
5751: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5752: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5753: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5754: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5755: }
5756: }
5757: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5758: req => 'Auto-creation of validated requests for official courses',
5759: xmldc => 'Identity of course creator of courses from XML files',
5760: );
5761: my @types = ('xml','req');
5762: foreach my $item (@types) {
5763: $newvals{$item} = $env{'form.autocreate_'.$item};
5764: $newvals{$item} =~ s/\D//g;
5765: $newvals{$item} = 0 if ($newvals{$item} eq '');
5766: }
5767: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5768: my %domcoords = &get_active_dcs($dom);
5769: unless (exists($domcoords{$newvals{'xmldc'}})) {
5770: $newvals{'xmldc'} = '';
5771: }
5772: %autocreatehash = (
5773: autocreate => { xml => $newvals{'xml'},
5774: req => $newvals{'req'},
5775: }
5776: );
5777: if ($newvals{'xmldc'} ne '') {
5778: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5779: }
5780: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5781: $dom);
5782: if ($putresult eq 'ok') {
5783: my @items = @types;
5784: if ($newvals{'xml'}) {
5785: push(@items,'xmldc');
5786: }
5787: foreach my $item (@items) {
5788: if (exists($currautocreate{$item})) {
5789: if ($currautocreate{$item} ne $newvals{$item}) {
5790: $changes{$item} = 1;
5791: }
5792: } elsif ($newvals{$item}) {
5793: $changes{$item} = 1;
5794: }
5795: }
5796: if (keys(%changes) > 0) {
5797: my @offon = ('off','on');
5798: $resulttext = &mt('Changes made:').'<ul>';
5799: foreach my $item (@types) {
5800: if ($changes{$item}) {
5801: my $newtxt = $offon[$newvals{$item}];
5802: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5803: }
5804: }
5805: if ($changes{'xmldc'}) {
5806: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5807: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5808: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5809: }
5810: $resulttext .= '</ul>';
5811: } else {
5812: $resulttext = &mt('No changes made to auto-creation settings');
5813: }
5814: } else {
5815: $resulttext = '<span class="LC_error">'.
5816: &mt('An error occurred: [_1]',$putresult).'</span>';
5817: }
5818: return $resulttext;
5819: }
5820:
1.23 raeburn 5821: sub modify_directorysrch {
5822: my ($dom,%domconfig) = @_;
5823: my ($resulttext,%changes);
5824: my %currdirsrch;
5825: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5826: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5827: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5828: }
5829: }
5830: my %title = ( available => 'Directory search available',
1.24 raeburn 5831: localonly => 'Other domains can search',
1.23 raeburn 5832: searchby => 'Search types',
5833: searchtypes => 'Search latitude');
5834: my @offon = ('off','on');
1.24 raeburn 5835: my @otherdoms = ('Yes','No');
1.23 raeburn 5836:
1.25 raeburn 5837: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5838: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5839: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5840:
1.44 raeburn 5841: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5842: if (keys(%{$usertypes}) == 0) {
5843: @cansearch = ('default');
5844: } else {
5845: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5846: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5847: if (!grep(/^\Q$type\E$/,@cansearch)) {
5848: push(@{$changes{'cansearch'}},$type);
5849: }
1.23 raeburn 5850: }
1.26 raeburn 5851: foreach my $type (@cansearch) {
5852: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5853: push(@{$changes{'cansearch'}},$type);
5854: }
1.23 raeburn 5855: }
1.26 raeburn 5856: } else {
5857: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5858: }
5859: }
5860:
5861: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5862: foreach my $by (@{$currdirsrch{'searchby'}}) {
5863: if (!grep(/^\Q$by\E$/,@searchby)) {
5864: push(@{$changes{'searchby'}},$by);
5865: }
5866: }
5867: foreach my $by (@searchby) {
5868: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5869: push(@{$changes{'searchby'}},$by);
5870: }
5871: }
5872: } else {
5873: push(@{$changes{'searchby'}},@searchby);
5874: }
1.25 raeburn 5875:
5876: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5877: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5878: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5879: push(@{$changes{'searchtypes'}},$type);
5880: }
5881: }
5882: foreach my $type (@searchtypes) {
5883: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5884: push(@{$changes{'searchtypes'}},$type);
5885: }
5886: }
5887: } else {
5888: if (exists($currdirsrch{'searchtypes'})) {
5889: foreach my $type (@searchtypes) {
5890: if ($type ne $currdirsrch{'searchtypes'}) {
5891: push(@{$changes{'searchtypes'}},$type);
5892: }
5893: }
5894: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5895: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5896: }
5897: } else {
5898: push(@{$changes{'searchtypes'}},@searchtypes);
5899: }
5900: }
5901:
1.23 raeburn 5902: my %dirsrch_hash = (
5903: directorysrch => { available => $env{'form.dirsrch_available'},
5904: cansearch => \@cansearch,
1.24 raeburn 5905: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5906: searchby => \@searchby,
1.25 raeburn 5907: searchtypes => \@searchtypes,
1.23 raeburn 5908: }
5909: );
5910: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5911: $dom);
5912: if ($putresult eq 'ok') {
5913: if (exists($currdirsrch{'available'})) {
5914: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5915: $changes{'available'} = 1;
5916: }
5917: } else {
5918: if ($env{'form.dirsrch_available'} eq '1') {
5919: $changes{'available'} = 1;
5920: }
5921: }
1.24 raeburn 5922: if (exists($currdirsrch{'localonly'})) {
5923: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5924: $changes{'localonly'} = 1;
5925: }
5926: } else {
5927: if ($env{'form.dirsrch_localonly'} eq '1') {
5928: $changes{'localonly'} = 1;
5929: }
5930: }
1.23 raeburn 5931: if (keys(%changes) > 0) {
5932: $resulttext = &mt('Changes made:').'<ul>';
5933: if ($changes{'available'}) {
5934: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5935: }
1.24 raeburn 5936: if ($changes{'localonly'}) {
5937: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5938: }
5939:
1.23 raeburn 5940: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5941: my $chgtext;
1.26 raeburn 5942: if (ref($usertypes) eq 'HASH') {
5943: if (keys(%{$usertypes}) > 0) {
5944: foreach my $type (@{$types}) {
5945: if (grep(/^\Q$type\E$/,@cansearch)) {
5946: $chgtext .= $usertypes->{$type}.'; ';
5947: }
5948: }
5949: if (grep(/^default$/,@cansearch)) {
5950: $chgtext .= $othertitle;
5951: } else {
5952: $chgtext =~ s/\; $//;
5953: }
5954: $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 5955: }
5956: }
5957: }
5958: if (ref($changes{'searchby'}) eq 'ARRAY') {
5959: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5960: my $chgtext;
5961: foreach my $type (@{$titleorder}) {
5962: if (grep(/^\Q$type\E$/,@searchby)) {
5963: if (defined($searchtitles->{$type})) {
5964: $chgtext .= $searchtitles->{$type}.'; ';
5965: }
5966: }
5967: }
5968: $chgtext =~ s/\; $//;
5969: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5970: }
1.25 raeburn 5971: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5972: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5973: my $chgtext;
5974: foreach my $type (@{$srchtypeorder}) {
5975: if (grep(/^\Q$type\E$/,@searchtypes)) {
5976: if (defined($srchtypes_desc->{$type})) {
5977: $chgtext .= $srchtypes_desc->{$type}.'; ';
5978: }
5979: }
5980: }
5981: $chgtext =~ s/\; $//;
5982: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5983: }
5984: $resulttext .= '</ul>';
5985: } else {
5986: $resulttext = &mt('No changes made to institution directory search settings');
5987: }
5988: } else {
5989: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5990: &mt('An error occurred: [_1]',$putresult).'</span>';
5991: }
5992: return $resulttext;
5993: }
5994:
1.28 raeburn 5995: sub modify_contacts {
5996: my ($dom,%domconfig) = @_;
5997: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5998: if (ref($domconfig{'contacts'}) eq 'HASH') {
5999: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6000: $currsetting{$key} = $domconfig{'contacts'}{$key};
6001: }
6002: }
1.134 raeburn 6003: my (%others,%to,%bcc);
1.28 raeburn 6004: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6005: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6006: 'requestsmail');
1.28 raeburn 6007: foreach my $type (@mailings) {
6008: @{$newsetting{$type}} =
6009: &Apache::loncommon::get_env_multiple('form.'.$type);
6010: foreach my $item (@contacts) {
6011: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6012: $contacts_hash{contacts}{$type}{$item} = 1;
6013: } else {
6014: $contacts_hash{contacts}{$type}{$item} = 0;
6015: }
6016: }
6017: $others{$type} = $env{'form.'.$type.'_others'};
6018: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6019: if ($type eq 'helpdeskmail') {
6020: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6021: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6022: }
1.28 raeburn 6023: }
6024: foreach my $item (@contacts) {
6025: $to{$item} = $env{'form.'.$item};
6026: $contacts_hash{'contacts'}{$item} = $to{$item};
6027: }
6028: if (keys(%currsetting) > 0) {
6029: foreach my $item (@contacts) {
6030: if ($to{$item} ne $currsetting{$item}) {
6031: $changes{$item} = 1;
6032: }
6033: }
6034: foreach my $type (@mailings) {
6035: foreach my $item (@contacts) {
6036: if (ref($currsetting{$type}) eq 'HASH') {
6037: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6038: push(@{$changes{$type}},$item);
6039: }
6040: } else {
6041: push(@{$changes{$type}},@{$newsetting{$type}});
6042: }
6043: }
6044: if ($others{$type} ne $currsetting{$type}{'others'}) {
6045: push(@{$changes{$type}},'others');
6046: }
1.134 raeburn 6047: if ($type eq 'helpdeskmail') {
6048: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6049: push(@{$changes{$type}},'bcc');
6050: }
6051: }
1.28 raeburn 6052: }
6053: } else {
6054: my %default;
6055: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6056: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6057: $default{'errormail'} = 'adminemail';
6058: $default{'packagesmail'} = 'adminemail';
6059: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6060: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6061: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6062: foreach my $item (@contacts) {
6063: if ($to{$item} ne $default{$item}) {
6064: $changes{$item} = 1;
6065: }
6066: }
6067: foreach my $type (@mailings) {
6068: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6069:
6070: push(@{$changes{$type}},@{$newsetting{$type}});
6071: }
6072: if ($others{$type} ne '') {
6073: push(@{$changes{$type}},'others');
1.134 raeburn 6074: }
6075: if ($type eq 'helpdeskmail') {
6076: if ($bcc{$type} ne '') {
6077: push(@{$changes{$type}},'bcc');
6078: }
6079: }
1.28 raeburn 6080: }
6081: }
6082: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6083: $dom);
6084: if ($putresult eq 'ok') {
6085: if (keys(%changes) > 0) {
6086: my ($titles,$short_titles) = &contact_titles();
6087: $resulttext = &mt('Changes made:').'<ul>';
6088: foreach my $item (@contacts) {
6089: if ($changes{$item}) {
6090: $resulttext .= '<li>'.$titles->{$item}.
6091: &mt(' set to: ').
6092: '<span class="LC_cusr_emph">'.
6093: $to{$item}.'</span></li>';
6094: }
6095: }
6096: foreach my $type (@mailings) {
6097: if (ref($changes{$type}) eq 'ARRAY') {
6098: $resulttext .= '<li>'.$titles->{$type}.': ';
6099: my @text;
6100: foreach my $item (@{$newsetting{$type}}) {
6101: push(@text,$short_titles->{$item});
6102: }
6103: if ($others{$type} ne '') {
6104: push(@text,$others{$type});
6105: }
6106: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6107: join(', ',@text).'</span>';
6108: if ($type eq 'helpdeskmail') {
6109: if ($bcc{$type} ne '') {
6110: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6111: }
6112: }
6113: $resulttext .= '</li>';
1.28 raeburn 6114: }
6115: }
6116: $resulttext .= '</ul>';
6117: } else {
1.34 raeburn 6118: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6119: }
6120: } else {
6121: $resulttext = '<span class="LC_error">'.
6122: &mt('An error occurred: [_1].',$putresult).'</span>';
6123: }
6124: return $resulttext;
6125: }
6126:
6127: sub modify_usercreation {
1.27 raeburn 6128: my ($dom,%domconfig) = @_;
1.34 raeburn 6129: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6130: my $warningmsg;
1.27 raeburn 6131: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6132: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6133: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6134: }
6135: }
6136: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6137: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6138: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6139: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6140: foreach my $item(@contexts) {
1.45 raeburn 6141: if ($item eq 'selfcreate') {
1.50 raeburn 6142: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6144: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6145: if (ref($cancreate{$item}) eq 'ARRAY') {
6146: if (grep(/^login$/,@{$cancreate{$item}})) {
6147: $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.');
6148: }
1.43 raeburn 6149: }
6150: }
1.50 raeburn 6151: } else {
6152: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6153: }
1.34 raeburn 6154: }
1.93 raeburn 6155: my ($othertitle,$usertypes,$types) =
6156: &Apache::loncommon::sorted_inst_types($dom);
6157: if (ref($types) eq 'ARRAY') {
6158: if (@{$types} > 0) {
6159: @{$cancreate{'statustocreate'}} =
6160: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6161: } else {
6162: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6163: }
6164: push(@contexts,'statustocreate');
6165: }
1.34 raeburn 6166: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6167: foreach my $item (@contexts) {
1.93 raeburn 6168: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6169: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6170: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6171: if (ref($cancreate{$item}) eq 'ARRAY') {
6172: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6173: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6174: push(@{$changes{'cancreate'}},$item);
6175: }
1.50 raeburn 6176: }
6177: }
6178: }
6179: } else {
6180: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6181: if (@{$cancreate{$item}} > 0) {
6182: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6183: push(@{$changes{'cancreate'}},$item);
6184: }
6185: }
6186: } else {
6187: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6188: if (@{$cancreate{$item}} < 3) {
6189: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6190: push(@{$changes{'cancreate'}},$item);
6191: }
6192: }
6193: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6194: if (@{$cancreate{$item}} > 0) {
6195: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6196: push(@{$changes{'cancreate'}},$item);
6197: }
6198: }
6199: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6200: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6201: push(@{$changes{'cancreate'}},$item);
6202: }
6203: }
6204: }
6205: }
6206: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6207: foreach my $type (@{$cancreate{$item}}) {
6208: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6209: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6210: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6211: push(@{$changes{'cancreate'}},$item);
6212: }
6213: }
6214: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6215: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6216: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6217: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6218: push(@{$changes{'cancreate'}},$item);
6219: }
6220: }
6221: }
6222: }
6223: }
6224: } else {
6225: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6226: push(@{$changes{'cancreate'}},$item);
6227: }
6228: }
1.27 raeburn 6229: }
1.34 raeburn 6230: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6231: foreach my $item (@contexts) {
1.43 raeburn 6232: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6233: if ($cancreate{$item} ne 'any') {
6234: push(@{$changes{'cancreate'}},$item);
6235: }
6236: } else {
6237: if ($cancreate{$item} ne 'none') {
6238: push(@{$changes{'cancreate'}},$item);
6239: }
1.27 raeburn 6240: }
6241: }
6242: } else {
1.43 raeburn 6243: foreach my $item (@contexts) {
1.34 raeburn 6244: push(@{$changes{'cancreate'}},$item);
6245: }
1.27 raeburn 6246: }
1.34 raeburn 6247:
1.27 raeburn 6248: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6249: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6250: if (!grep(/^\Q$type\E$/,@username_rule)) {
6251: push(@{$changes{'username_rule'}},$type);
6252: }
6253: }
6254: foreach my $type (@username_rule) {
6255: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6256: push(@{$changes{'username_rule'}},$type);
6257: }
6258: }
6259: } else {
6260: push(@{$changes{'username_rule'}},@username_rule);
6261: }
6262:
1.32 raeburn 6263: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6264: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6265: if (!grep(/^\Q$type\E$/,@id_rule)) {
6266: push(@{$changes{'id_rule'}},$type);
6267: }
6268: }
6269: foreach my $type (@id_rule) {
6270: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6271: push(@{$changes{'id_rule'}},$type);
6272: }
6273: }
6274: } else {
6275: push(@{$changes{'id_rule'}},@id_rule);
6276: }
6277:
1.43 raeburn 6278: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6279: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6280: if (!grep(/^\Q$type\E$/,@email_rule)) {
6281: push(@{$changes{'email_rule'}},$type);
6282: }
6283: }
6284: foreach my $type (@email_rule) {
6285: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6286: push(@{$changes{'email_rule'}},$type);
6287: }
6288: }
6289: } else {
6290: push(@{$changes{'email_rule'}},@email_rule);
6291: }
6292:
6293: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6294: my @authtypes = ('int','krb4','krb5','loc');
6295: my %authhash;
1.43 raeburn 6296: foreach my $item (@authen_contexts) {
1.28 raeburn 6297: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6298: foreach my $auth (@authtypes) {
6299: if (grep(/^\Q$auth\E$/,@authallowed)) {
6300: $authhash{$item}{$auth} = 1;
6301: } else {
6302: $authhash{$item}{$auth} = 0;
6303: }
6304: }
6305: }
6306: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6307: foreach my $item (@authen_contexts) {
1.28 raeburn 6308: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6309: foreach my $auth (@authtypes) {
6310: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6311: push(@{$changes{'authtypes'}},$item);
6312: last;
6313: }
6314: }
6315: }
6316: }
6317: } else {
1.43 raeburn 6318: foreach my $item (@authen_contexts) {
1.28 raeburn 6319: push(@{$changes{'authtypes'}},$item);
6320: }
6321: }
6322:
1.27 raeburn 6323: my %usercreation_hash = (
1.28 raeburn 6324: usercreation => {
1.34 raeburn 6325: cancreate => \%cancreate,
1.27 raeburn 6326: username_rule => \@username_rule,
1.32 raeburn 6327: id_rule => \@id_rule,
1.43 raeburn 6328: email_rule => \@email_rule,
1.32 raeburn 6329: authtypes => \%authhash,
1.27 raeburn 6330: }
6331: );
6332:
6333: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6334: $dom);
1.50 raeburn 6335:
6336: my %selfcreatetypes = (
6337: sso => 'users authenticated by institutional single sign on',
6338: login => 'users authenticated by institutional log-in',
6339: email => 'users who provide a valid e-mail address for use as the username',
6340: );
1.27 raeburn 6341: if ($putresult eq 'ok') {
6342: if (keys(%changes) > 0) {
6343: $resulttext = &mt('Changes made:').'<ul>';
6344: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6345: my %lt = &usercreation_types();
6346: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6347: my $chgtext;
6348: unless ($type eq 'statustocreate') {
6349: $chgtext = $lt{$type}.', ';
6350: }
1.45 raeburn 6351: if ($type eq 'selfcreate') {
1.50 raeburn 6352: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6353: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6354: } else {
1.100 raeburn 6355: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6356: foreach my $case (@{$cancreate{$type}}) {
6357: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6358: }
6359: $chgtext .= '</ul>';
1.100 raeburn 6360: if (ref($cancreate{$type}) eq 'ARRAY') {
6361: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6362: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6363: if (@{$cancreate{'statustocreate'}} == 0) {
6364: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6365: }
6366: }
6367: }
6368: }
1.43 raeburn 6369: }
1.93 raeburn 6370: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6371: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6372: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6373: if (@{$cancreate{'selfcreate'}} > 0) {
6374: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6375:
6376: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6377: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6378: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6379: }
1.96 raeburn 6380: } elsif (ref($usertypes) eq 'HASH') {
6381: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6382: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6383: } else {
6384: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6385: }
6386: $chgtext .= '<ul>';
6387: foreach my $case (@{$cancreate{$type}}) {
6388: if ($case eq 'default') {
6389: $chgtext .= '<li>'.$othertitle.'</li>';
6390: } else {
6391: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6392: }
6393: }
1.100 raeburn 6394: $chgtext .= '</ul>';
6395: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6396: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6397: }
6398: }
6399: } else {
6400: if (@{$cancreate{$type}} == 0) {
6401: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6402: } else {
6403: $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 6404: }
6405: }
6406: }
1.43 raeburn 6407: } else {
6408: if ($cancreate{$type} eq 'none') {
6409: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6410: } elsif ($cancreate{$type} eq 'any') {
6411: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6412: } elsif ($cancreate{$type} eq 'official') {
6413: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6414: } elsif ($cancreate{$type} eq 'unofficial') {
6415: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6416: }
1.34 raeburn 6417: }
6418: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6419: }
6420: }
6421: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6422: my ($rules,$ruleorder) =
6423: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6424: my $chgtext = '<ul>';
6425: foreach my $type (@username_rule) {
6426: if (ref($rules->{$type}) eq 'HASH') {
6427: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6428: }
6429: }
6430: $chgtext .= '</ul>';
6431: if (@username_rule > 0) {
6432: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6433: } else {
1.28 raeburn 6434: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6435: }
6436: }
1.32 raeburn 6437: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6438: my ($idrules,$idruleorder) =
6439: &Apache::lonnet::inst_userrules($dom,'id');
6440: my $chgtext = '<ul>';
6441: foreach my $type (@id_rule) {
6442: if (ref($idrules->{$type}) eq 'HASH') {
6443: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6444: }
6445: }
6446: $chgtext .= '</ul>';
6447: if (@id_rule > 0) {
6448: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6449: } else {
6450: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6451: }
6452: }
1.43 raeburn 6453: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6454: my ($emailrules,$emailruleorder) =
6455: &Apache::lonnet::inst_userrules($dom,'email');
6456: my $chgtext = '<ul>';
6457: foreach my $type (@email_rule) {
6458: if (ref($emailrules->{$type}) eq 'HASH') {
6459: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6460: }
6461: }
6462: $chgtext .= '</ul>';
6463: if (@email_rule > 0) {
6464: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6465: } else {
6466: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6467: }
6468: }
6469:
1.28 raeburn 6470: my %authname = &authtype_names();
6471: my %context_title = &context_names();
6472: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6473: my $chgtext = '<ul>';
6474: foreach my $type (@{$changes{'authtypes'}}) {
6475: my @allowed;
6476: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6477: foreach my $auth (@authtypes) {
6478: if ($authhash{$type}{$auth}) {
6479: push(@allowed,$authname{$auth});
6480: }
6481: }
1.43 raeburn 6482: if (@allowed > 0) {
6483: $chgtext .= join(', ',@allowed).'</li>';
6484: } else {
6485: $chgtext .= &mt('none').'</li>';
6486: }
1.28 raeburn 6487: }
6488: $chgtext .= '</ul>';
6489: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6490: $resulttext .= '</li>';
6491: }
1.27 raeburn 6492: $resulttext .= '</ul>';
6493: } else {
1.28 raeburn 6494: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 6495: }
6496: } else {
6497: $resulttext = '<span class="LC_error">'.
1.23 raeburn 6498: &mt('An error occurred: [_1]',$putresult).'</span>';
6499: }
1.43 raeburn 6500: if ($warningmsg ne '') {
6501: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6502: }
1.23 raeburn 6503: return $resulttext;
6504: }
6505:
1.33 raeburn 6506: sub modify_usermodification {
6507: my ($dom,%domconfig) = @_;
6508: my ($resulttext,%curr_usermodification,%changes);
6509: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6510: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6511: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6512: }
6513: }
1.63 raeburn 6514: my @contexts = ('author','course','selfcreate');
1.33 raeburn 6515: my %context_title = (
6516: author => 'In author context',
6517: course => 'In course context',
1.63 raeburn 6518: selfcreate => 'When self creating account',
1.33 raeburn 6519: );
6520: my @fields = ('lastname','firstname','middlename','generation',
6521: 'permanentemail','id');
6522: my %roles = (
6523: author => ['ca','aa'],
6524: course => ['st','ep','ta','in','cr'],
6525: );
1.63 raeburn 6526: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6527: if (ref($types) eq 'ARRAY') {
6528: push(@{$types},'default');
6529: $usertypes->{'default'} = $othertitle;
6530: }
6531: $roles{'selfcreate'} = $types;
1.33 raeburn 6532: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6533: my %modifyhash;
6534: foreach my $context (@contexts) {
6535: foreach my $role (@{$roles{$context}}) {
6536: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6537: foreach my $item (@fields) {
6538: if (grep(/^\Q$item\E$/,@modifiable)) {
6539: $modifyhash{$context}{$role}{$item} = 1;
6540: } else {
6541: $modifyhash{$context}{$role}{$item} = 0;
6542: }
6543: }
6544: }
6545: if (ref($curr_usermodification{$context}) eq 'HASH') {
6546: foreach my $role (@{$roles{$context}}) {
6547: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6548: foreach my $field (@fields) {
6549: if ($modifyhash{$context}{$role}{$field} ne
6550: $curr_usermodification{$context}{$role}{$field}) {
6551: push(@{$changes{$context}},$role);
6552: last;
6553: }
6554: }
6555: }
6556: }
6557: } else {
6558: foreach my $context (@contexts) {
6559: foreach my $role (@{$roles{$context}}) {
6560: push(@{$changes{$context}},$role);
6561: }
6562: }
6563: }
6564: }
6565: my %usermodification_hash = (
6566: usermodification => \%modifyhash,
6567: );
6568: my $putresult = &Apache::lonnet::put_dom('configuration',
6569: \%usermodification_hash,$dom);
6570: if ($putresult eq 'ok') {
6571: if (keys(%changes) > 0) {
6572: $resulttext = &mt('Changes made: ').'<ul>';
6573: foreach my $context (@contexts) {
6574: if (ref($changes{$context}) eq 'ARRAY') {
6575: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6576: if (ref($changes{$context}) eq 'ARRAY') {
6577: foreach my $role (@{$changes{$context}}) {
6578: my $rolename;
1.63 raeburn 6579: if ($context eq 'selfcreate') {
6580: $rolename = $role;
6581: if (ref($usertypes) eq 'HASH') {
6582: if ($usertypes->{$role} ne '') {
6583: $rolename = $usertypes->{$role};
6584: }
6585: }
1.33 raeburn 6586: } else {
1.63 raeburn 6587: if ($role eq 'cr') {
6588: $rolename = &mt('Custom');
6589: } else {
6590: $rolename = &Apache::lonnet::plaintext($role);
6591: }
1.33 raeburn 6592: }
6593: my @modifiable;
1.63 raeburn 6594: if ($context eq 'selfcreate') {
1.126 bisitz 6595: $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 6596: } else {
6597: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6598: }
1.33 raeburn 6599: foreach my $field (@fields) {
6600: if ($modifyhash{$context}{$role}{$field}) {
6601: push(@modifiable,$fieldtitles{$field});
6602: }
6603: }
6604: if (@modifiable > 0) {
6605: $resulttext .= join(', ',@modifiable);
6606: } else {
6607: $resulttext .= &mt('none');
6608: }
6609: $resulttext .= '</li>';
6610: }
6611: $resulttext .= '</ul></li>';
6612: }
6613: }
6614: }
6615: $resulttext .= '</ul>';
6616: } else {
6617: $resulttext = &mt('No changes made to user modification settings');
6618: }
6619: } else {
6620: $resulttext = '<span class="LC_error">'.
6621: &mt('An error occurred: [_1]',$putresult).'</span>';
6622: }
6623: return $resulttext;
6624: }
6625:
1.43 raeburn 6626: sub modify_defaults {
6627: my ($dom,$r) = @_;
6628: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6629: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6630: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6631: my @authtypes = ('internal','krb4','krb5','localauth');
6632: foreach my $item (@items) {
6633: $newvalues{$item} = $env{'form.'.$item};
6634: if ($item eq 'auth_def') {
6635: if ($newvalues{$item} ne '') {
6636: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6637: push(@errors,$item);
6638: }
6639: }
6640: } elsif ($item eq 'lang_def') {
6641: if ($newvalues{$item} ne '') {
6642: if ($newvalues{$item} =~ /^(\w+)/) {
6643: my $langcode = $1;
1.103 raeburn 6644: if ($langcode ne 'x_chef') {
6645: if (code2language($langcode) eq '') {
6646: push(@errors,$item);
6647: }
1.43 raeburn 6648: }
6649: } else {
6650: push(@errors,$item);
6651: }
6652: }
1.54 raeburn 6653: } elsif ($item eq 'timezone_def') {
6654: if ($newvalues{$item} ne '') {
1.62 raeburn 6655: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6656: push(@errors,$item);
6657: }
6658: }
1.68 raeburn 6659: } elsif ($item eq 'datelocale_def') {
6660: if ($newvalues{$item} ne '') {
6661: my @datelocale_ids = DateTime::Locale->ids();
6662: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6663: push(@errors,$item);
6664: }
6665: }
1.141 raeburn 6666: } elsif ($item eq 'portal_def') {
6667: if ($newvalues{$item} ne '') {
6668: 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])\/?$/) {
6669: push(@errors,$item);
6670: }
6671: }
1.43 raeburn 6672: }
6673: if (grep(/^\Q$item\E$/,@errors)) {
6674: $newvalues{$item} = $domdefaults{$item};
6675: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6676: $changes{$item} = 1;
6677: }
1.72 raeburn 6678: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6679: }
6680: my %defaults_hash = (
1.72 raeburn 6681: defaults => \%newvalues,
6682: );
1.43 raeburn 6683: my $title = &defaults_titles();
6684: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6685: $dom);
6686: if ($putresult eq 'ok') {
6687: if (keys(%changes) > 0) {
6688: $resulttext = &mt('Changes made:').'<ul>';
6689: my $version = $r->dir_config('lonVersion');
6690: 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";
6691: foreach my $item (sort(keys(%changes))) {
6692: my $value = $env{'form.'.$item};
6693: if ($value eq '') {
6694: $value = &mt('none');
6695: } elsif ($item eq 'auth_def') {
6696: my %authnames = &authtype_names();
6697: my %shortauth = (
6698: internal => 'int',
6699: krb4 => 'krb4',
6700: krb5 => 'krb5',
6701: localauth => 'loc',
6702: );
6703: $value = $authnames{$shortauth{$value}};
6704: }
6705: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6706: $mailmsgtext .= "$title->{$item} set to $value\n";
6707: }
6708: $resulttext .= '</ul>';
6709: $mailmsgtext .= "\n";
6710: my $cachetime = 24*60*60;
1.72 raeburn 6711: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6712: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6713: my $sysmail = $r->dir_config('lonSysEMail');
6714: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6715: }
1.43 raeburn 6716: } else {
1.54 raeburn 6717: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6718: }
6719: } else {
6720: $resulttext = '<span class="LC_error">'.
6721: &mt('An error occurred: [_1]',$putresult).'</span>';
6722: }
6723: if (@errors > 0) {
6724: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6725: foreach my $item (@errors) {
6726: $resulttext .= ' "'.$title->{$item}.'",';
6727: }
6728: $resulttext =~ s/,$//;
6729: }
6730: return $resulttext;
6731: }
6732:
1.46 raeburn 6733: sub modify_scantron {
1.48 raeburn 6734: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6735: my ($resulttext,%confhash,%changes,$errors);
6736: my $custom = 'custom.tab';
6737: my $default = 'default.tab';
6738: my $servadm = $r->dir_config('lonAdmEMail');
6739: my ($configuserok,$author_ok,$switchserver) =
6740: &config_check($dom,$confname,$servadm);
6741: if ($env{'form.scantronformat.filename'} ne '') {
6742: my $error;
6743: if ($configuserok eq 'ok') {
6744: if ($switchserver) {
1.130 raeburn 6745: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6746: } else {
6747: if ($author_ok eq 'ok') {
6748: my ($result,$scantronurl) =
6749: &publishlogo($r,'upload','scantronformat',$dom,
6750: $confname,'scantron','','',$custom);
6751: if ($result eq 'ok') {
6752: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6753: $changes{'scantronformat'} = 1;
1.46 raeburn 6754: } else {
6755: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6756: }
6757: } else {
6758: $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);
6759: }
6760: }
6761: } else {
6762: $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);
6763: }
6764: if ($error) {
6765: &Apache::lonnet::logthis($error);
6766: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6767: }
6768: }
1.48 raeburn 6769: if (ref($domconfig{'scantron'}) eq 'HASH') {
6770: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6771: if ($env{'form.scantronformat_del'}) {
6772: $confhash{'scantron'}{'scantronformat'} = '';
6773: $changes{'scantronformat'} = 1;
1.46 raeburn 6774: }
6775: }
6776: }
6777: if (keys(%confhash) > 0) {
6778: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6779: $dom);
6780: if ($putresult eq 'ok') {
6781: if (keys(%changes) > 0) {
1.48 raeburn 6782: if (ref($confhash{'scantron'}) eq 'HASH') {
6783: $resulttext = &mt('Changes made:').'<ul>';
6784: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6785: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6786: } else {
1.130 raeburn 6787: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6788: }
1.48 raeburn 6789: $resulttext .= '</ul>';
6790: } else {
1.130 raeburn 6791: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6792: }
6793: $resulttext .= '</ul>';
6794: &Apache::loncommon::devalidate_domconfig_cache($dom);
6795: } else {
1.130 raeburn 6796: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6797: }
6798: } else {
6799: $resulttext = '<span class="LC_error">'.
6800: &mt('An error occurred: [_1]',$putresult).'</span>';
6801: }
6802: } else {
1.130 raeburn 6803: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6804: }
6805: if ($errors) {
6806: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6807: $errors.'</ul>';
6808: }
6809: return $resulttext;
6810: }
6811:
1.48 raeburn 6812: sub modify_coursecategories {
6813: my ($dom,%domconfig) = @_;
1.57 raeburn 6814: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6815: $cathash);
1.48 raeburn 6816: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6817: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6818: $cathash = $domconfig{'coursecategories'}{'cats'};
6819: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6820: $changes{'togglecats'} = 1;
6821: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6822: }
6823: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6824: $changes{'categorize'} = 1;
6825: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6826: }
1.120 raeburn 6827: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6828: $changes{'togglecatscomm'} = 1;
6829: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6830: }
6831: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6832: $changes{'categorizecomm'} = 1;
6833: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6834: }
1.57 raeburn 6835: } else {
6836: $changes{'togglecats'} = 1;
6837: $changes{'categorize'} = 1;
1.124 raeburn 6838: $changes{'togglecatscomm'} = 1;
6839: $changes{'categorizecomm'} = 1;
1.87 raeburn 6840: $domconfig{'coursecategories'} = {
6841: togglecats => $env{'form.togglecats'},
6842: categorize => $env{'form.categorize'},
1.124 raeburn 6843: togglecatscomm => $env{'form.togglecatscomm'},
6844: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6845: };
1.57 raeburn 6846: }
6847: if (ref($cathash) eq 'HASH') {
6848: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6849: push (@deletecategory,'instcode::0');
6850: }
1.120 raeburn 6851: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6852: push(@deletecategory,'communities::0');
6853: }
1.48 raeburn 6854: }
1.57 raeburn 6855: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6856: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6857: if (@deletecategory > 0) {
6858: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6859: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6860: foreach my $item (@deletecategory) {
1.57 raeburn 6861: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6862: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6863: $deletions{$item} = 1;
1.57 raeburn 6864: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6865: }
6866: }
6867: }
1.57 raeburn 6868: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6869: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6870: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6871: $reorderings{$item} = 1;
1.57 raeburn 6872: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6873: }
6874: if ($env{'form.addcategory_name_'.$item} ne '') {
6875: my $newcat = $env{'form.addcategory_name_'.$item};
6876: my $newdepth = $depth+1;
6877: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6878: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6879: $adds{$newitem} = 1;
6880: }
6881: if ($env{'form.subcat_'.$item} ne '') {
6882: my $newcat = $env{'form.subcat_'.$item};
6883: my $newdepth = $depth+1;
6884: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6885: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6886: $adds{$newitem} = 1;
6887: }
6888: }
6889: }
6890: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6891: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6892: my $newitem = 'instcode::0';
1.57 raeburn 6893: if ($cathash->{$newitem} eq '') {
6894: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6895: $adds{$newitem} = 1;
6896: }
6897: } else {
6898: my $newitem = 'instcode::0';
1.57 raeburn 6899: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6900: $adds{$newitem} = 1;
6901: }
6902: }
1.120 raeburn 6903: if ($env{'form.communities'} eq '1') {
6904: if (ref($cathash) eq 'HASH') {
6905: my $newitem = 'communities::0';
6906: if ($cathash->{$newitem} eq '') {
6907: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6908: $adds{$newitem} = 1;
6909: }
6910: } else {
6911: my $newitem = 'communities::0';
6912: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6913: $adds{$newitem} = 1;
6914: }
6915: }
1.48 raeburn 6916: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6917: if (($env{'form.addcategory_name'} ne 'instcode') &&
6918: ($env{'form.addcategory_name'} ne 'communities')) {
6919: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6920: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6921: $adds{$newitem} = 1;
6922: }
1.48 raeburn 6923: }
1.57 raeburn 6924: my $putresult;
1.48 raeburn 6925: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6926: if (keys(%deletions) > 0) {
6927: foreach my $key (keys(%deletions)) {
6928: if ($predelallitems{$key} ne '') {
6929: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6930: }
6931: }
6932: }
6933: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6934: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6935: if (ref($chkcats[0]) eq 'ARRAY') {
6936: my $depth = 0;
6937: my $chg = 0;
6938: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6939: my $name = $chkcats[0][$i];
6940: my $item;
6941: if ($name eq '') {
6942: $chg ++;
6943: } else {
6944: $item = &escape($name).'::0';
6945: if ($chg) {
1.57 raeburn 6946: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6947: }
6948: $depth ++;
1.57 raeburn 6949: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6950: $depth --;
6951: }
6952: }
6953: }
1.57 raeburn 6954: }
6955: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6956: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6957: if ($putresult eq 'ok') {
1.57 raeburn 6958: my %title = (
1.120 raeburn 6959: togglecats => 'Show/Hide a course in catalog',
6960: categorize => 'Assign a category to a course',
6961: togglecatscomm => 'Show/Hide a community in catalog',
6962: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6963: );
6964: my %level = (
1.120 raeburn 6965: dom => 'set in Domain ("Modify Course/Community")',
6966: crs => 'set in Course ("Course Configuration")',
6967: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6968: );
1.48 raeburn 6969: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6970: if ($changes{'togglecats'}) {
6971: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6972: }
6973: if ($changes{'categorize'}) {
6974: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6975: }
1.120 raeburn 6976: if ($changes{'togglecatscomm'}) {
6977: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6978: }
6979: if ($changes{'categorizecomm'}) {
6980: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6981: }
1.57 raeburn 6982: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6983: my $cathash;
6984: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6985: $cathash = $domconfig{'coursecategories'}{'cats'};
6986: } else {
6987: $cathash = {};
6988: }
6989: my (@cats,@trails,%allitems);
6990: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6991: if (keys(%deletions) > 0) {
6992: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6993: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6994: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6995: }
6996: $resulttext .= '</ul></li>';
6997: }
6998: if (keys(%reorderings) > 0) {
6999: my %sort_by_trail;
7000: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7001: foreach my $key (keys(%reorderings)) {
7002: if ($allitems{$key} ne '') {
7003: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7004: }
1.48 raeburn 7005: }
1.57 raeburn 7006: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7007: $resulttext .= '<li>'.$trails[$trail].'</li>';
7008: }
7009: $resulttext .= '</ul></li>';
1.48 raeburn 7010: }
1.57 raeburn 7011: if (keys(%adds) > 0) {
7012: my %sort_by_trail;
7013: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7014: foreach my $key (keys(%adds)) {
7015: if ($allitems{$key} ne '') {
7016: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7017: }
7018: }
7019: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7020: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7021: }
1.57 raeburn 7022: $resulttext .= '</ul></li>';
1.48 raeburn 7023: }
7024: }
7025: $resulttext .= '</ul>';
7026: } else {
7027: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7028: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7029: }
7030: } else {
1.120 raeburn 7031: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7032: }
7033: return $resulttext;
7034: }
7035:
1.69 raeburn 7036: sub modify_serverstatuses {
7037: my ($dom,%domconfig) = @_;
7038: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7039: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7040: %currserverstatus = %{$domconfig{'serverstatuses'}};
7041: }
7042: my @pages = &serverstatus_pages();
7043: foreach my $type (@pages) {
7044: $newserverstatus{$type}{'namedusers'} = '';
7045: $newserverstatus{$type}{'machines'} = '';
7046: if (defined($env{'form.'.$type.'_namedusers'})) {
7047: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7048: my @okusers;
7049: foreach my $user (@users) {
7050: my ($uname,$udom) = split(/:/,$user);
7051: if (($udom =~ /^$match_domain$/) &&
7052: (&Apache::lonnet::domain($udom)) &&
7053: ($uname =~ /^$match_username$/)) {
7054: if (!grep(/^\Q$user\E/,@okusers)) {
7055: push(@okusers,$user);
7056: }
7057: }
7058: }
7059: if (@okusers > 0) {
7060: @okusers = sort(@okusers);
7061: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7062: }
7063: }
7064: if (defined($env{'form.'.$type.'_machines'})) {
7065: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7066: my @okmachines;
7067: foreach my $ip (@machines) {
7068: my @parts = split(/\./,$ip);
7069: next if (@parts < 4);
7070: my $badip = 0;
7071: for (my $i=0; $i<4; $i++) {
7072: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7073: $badip = 1;
7074: last;
7075: }
7076: }
7077: if (!$badip) {
7078: push(@okmachines,$ip);
7079: }
7080: }
7081: @okmachines = sort(@okmachines);
7082: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7083: }
7084: }
7085: my %serverstatushash = (
7086: serverstatuses => \%newserverstatus,
7087: );
7088: foreach my $type (@pages) {
1.83 raeburn 7089: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7090: my (@current,@new);
1.83 raeburn 7091: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7092: if ($currserverstatus{$type}{$setting} ne '') {
7093: @current = split(/,/,$currserverstatus{$type}{$setting});
7094: }
7095: }
7096: if ($newserverstatus{$type}{$setting} ne '') {
7097: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7098: }
7099: if (@current > 0) {
7100: if (@new > 0) {
7101: foreach my $item (@current) {
7102: if (!grep(/^\Q$item\E$/,@new)) {
7103: $changes{$type}{$setting} = 1;
1.82 raeburn 7104: last;
7105: }
7106: }
1.84 raeburn 7107: foreach my $item (@new) {
7108: if (!grep(/^\Q$item\E$/,@current)) {
7109: $changes{$type}{$setting} = 1;
7110: last;
1.82 raeburn 7111: }
7112: }
7113: } else {
1.83 raeburn 7114: $changes{$type}{$setting} = 1;
1.69 raeburn 7115: }
1.83 raeburn 7116: } elsif (@new > 0) {
7117: $changes{$type}{$setting} = 1;
1.69 raeburn 7118: }
7119: }
7120: }
7121: if (keys(%changes) > 0) {
1.81 raeburn 7122: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7123: my $putresult = &Apache::lonnet::put_dom('configuration',
7124: \%serverstatushash,$dom);
7125: if ($putresult eq 'ok') {
7126: $resulttext .= &mt('Changes made:').'<ul>';
7127: foreach my $type (@pages) {
1.84 raeburn 7128: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7129: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7130: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7131: if ($newserverstatus{$type}{'namedusers'} eq '') {
7132: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7133: } else {
7134: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7135: }
1.84 raeburn 7136: }
7137: if ($changes{$type}{'machines'}) {
1.69 raeburn 7138: if ($newserverstatus{$type}{'machines'} eq '') {
7139: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7140: } else {
7141: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7142: }
7143:
7144: }
7145: $resulttext .= '</ul></li>';
7146: }
7147: }
7148: $resulttext .= '</ul>';
7149: } else {
7150: $resulttext = '<span class="LC_error">'.
7151: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7152:
7153: }
7154: } else {
7155: $resulttext = &mt('No changes made to access to server status pages');
7156: }
7157: return $resulttext;
7158: }
7159:
1.118 jms 7160: sub modify_helpsettings {
1.122 jms 7161: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 7162: my ($resulttext,$errors,%changes,%helphash);
7163:
1.122 jms 7164: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7165: my $defaulthelpfile = 'defaulthelp.html';
7166: my $servadm = $r->dir_config('lonAdmEMail');
7167: my ($configuserok,$author_ok,$switchserver) =
7168: &config_check($dom,$confname,$servadm);
7169:
1.118 jms 7170: my %defaultchecked = ('submitbugs' => 'on');
7171: my @offon = ('off','on');
1.122 jms 7172: my %title = ( submitbugs => 'Display link for users to submit a bug',
7173: loginhelpurl => 'Unauthenticated login help page set to custom file');
7174:
1.118 jms 7175: my @toggles = ('submitbugs');
7176:
7177: $helphash{'helpsettings'} = {};
7178:
7179: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7180: if ($domconfig{'helpsettings'} eq '') {
7181: $domconfig{'helpsettings'} = {};
7182: }
7183: }
7184:
7185: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7186:
7187: foreach my $item (@toggles) {
7188:
7189: if ($defaultchecked{$item} eq 'on') {
7190: if (($domconfig{'helpsettings'}{$item} eq '') &&
7191: ($env{'form.'.$item} eq '0')) {
7192: $changes{$item} = 1;
7193: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7194: $changes{$item} = 1;
7195: }
7196: } elsif ($defaultchecked{$item} eq 'off') {
7197: if (($domconfig{'helpsettings'}{$item} eq '') &&
7198: ($env{'form.'.$item} eq '1')) {
7199: $changes{$item} = 1;
7200: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7201: $changes{$item} = 1;
7202: }
7203: }
7204: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7205: }
7206:
7207: if ($customhelpfile ne '') {
7208: my $error;
7209: if ($configuserok eq 'ok') {
7210: if ($switchserver) {
7211: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7212: } else {
7213: if ($author_ok eq 'ok') {
7214: my ($result,$loginhelpurl) =
7215: &publishlogo($r,'upload','loginhelpurl',$dom,
7216: $confname,'help','','',$customhelpfile);
7217: if ($result eq 'ok') {
7218: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7219: $changes{'loginhelpurl'} = 1;
7220: } else {
7221: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7222: }
7223: } else {
7224: $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);
7225: }
7226: }
7227: } else {
7228: $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);
7229: }
7230: if ($error) {
7231: &Apache::lonnet::logthis($error);
7232: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7233: }
7234: }
7235:
7236: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7237: if ($env{'form.loginhelpurl_del'}) {
7238: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7239: $changes{'loginhelpurl'} = 1;
7240: }
7241: }
1.118 jms 7242: }
7243:
1.123 jms 7244:
7245: my $putresult;
7246:
7247: if (keys(%changes) > 0) {
7248: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7249: } else {
7250: $putresult = 'ok';
7251: }
1.118 jms 7252:
7253: if ($putresult eq 'ok') {
7254: if (keys(%changes) > 0) {
7255: $resulttext = &mt('Changes made:').'<ul>';
7256: foreach my $item (sort(keys(%changes))) {
7257: if ($item eq 'submitbugs') {
7258: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7259: }
1.122 jms 7260: if ($item eq 'loginhelpurl') {
7261: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7262: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7263: } else {
7264: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7265: }
7266: }
1.118 jms 7267: }
7268: $resulttext .= '</ul>';
7269: } else {
7270: $resulttext = &mt('No changes made to help settings');
7271: }
7272: } else {
7273: $resulttext = '<span class="LC_error">'.
7274: &mt('An error occurred: [_1]',$putresult).'</span>';
7275: }
7276: if ($errors) {
7277: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7278: $errors.'</ul>';
7279: }
7280: return $resulttext;
7281: }
7282:
1.121 raeburn 7283: sub modify_coursedefaults {
7284: my ($dom,%domconfig) = @_;
7285: my ($resulttext,$errors,%changes,%defaultshash);
7286: my %defaultchecked = ('canuse_pdfforms' => 'off');
7287: my @offon = ('off','on');
7288: my @toggles = ('canuse_pdfforms');
7289:
7290: $defaultshash{'coursedefaults'} = {};
7291:
7292: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7293: if ($domconfig{'coursedefaults'} eq '') {
7294: $domconfig{'coursedefaults'} = {};
7295: }
7296: }
7297:
7298: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7299: foreach my $item (@toggles) {
7300: if ($defaultchecked{$item} eq 'on') {
7301: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7302: ($env{'form.'.$item} eq '0')) {
7303: $changes{$item} = 1;
7304: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7305: $changes{$item} = 1;
7306: }
7307: } elsif ($defaultchecked{$item} eq 'off') {
7308: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7309: ($env{'form.'.$item} eq '1')) {
7310: $changes{$item} = 1;
7311: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7312: $changes{$item} = 1;
7313: }
7314: }
7315: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7316: }
1.139 raeburn 7317: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7318: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7319: $newdefresponder =~ s/\D//g;
7320: if ($newdefresponder eq '' || $newdefresponder < 1) {
7321: $newdefresponder = 1;
7322: }
7323: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7324: if ($currdefresponder ne $newdefresponder) {
7325: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7326: $changes{'anonsurvey_threshold'} = 1;
7327: }
7328: }
1.121 raeburn 7329: }
7330: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7331: $dom);
7332: if ($putresult eq 'ok') {
7333: if (keys(%changes) > 0) {
7334: if ($changes{'canuse_pdfforms'}) {
7335: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7336: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7337: my $cachetime = 24*60*60;
7338: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7339: }
7340: $resulttext = &mt('Changes made:').'<ul>';
7341: foreach my $item (sort(keys(%changes))) {
7342: if ($item eq 'canuse_pdfforms') {
7343: if ($env{'form.'.$item} eq '1') {
7344: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7345: } else {
7346: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7347: }
1.139 raeburn 7348: } elsif ($item eq 'anonsurvey_threshold') {
7349: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7350: }
1.121 raeburn 7351: }
7352: $resulttext .= '</ul>';
7353: } else {
7354: $resulttext = &mt('No changes made to course defaults');
7355: }
7356: } else {
7357: $resulttext = '<span class="LC_error">'.
7358: &mt('An error occurred: [_1]',$putresult).'</span>';
7359: }
7360: return $resulttext;
7361: }
7362:
1.137 raeburn 7363: sub modify_usersessions {
7364: my ($dom,%domconfig) = @_;
1.145 raeburn 7365: my @hostingtypes = ('version','excludedomain','includedomain');
7366: my @offloadtypes = ('primary','default');
7367: my %types = (
7368: remote => \@hostingtypes,
7369: hosted => \@hostingtypes,
7370: spares => \@offloadtypes,
7371: );
7372: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7373: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7374: my (%by_ip,%by_location,@intdoms);
7375: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7376: my @locations = sort(keys(%by_location));
1.137 raeburn 7377: my (%defaultshash,%changes);
7378: foreach my $prefix (@prefixes) {
7379: $defaultshash{'usersessions'}{$prefix} = {};
7380: }
7381: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7382: my $resulttext;
1.138 raeburn 7383: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7384: foreach my $prefix (@prefixes) {
1.145 raeburn 7385: next if ($prefix eq 'spares');
7386: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7387: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7388: if ($type eq 'version') {
7389: my $value = $env{'form.'.$prefix.'_'.$type};
7390: my $okvalue;
7391: if ($value ne '') {
7392: if (grep(/^\Q$value\E$/,@lcversions)) {
7393: $okvalue = $value;
7394: }
7395: }
7396: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7397: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7398: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7399: if ($inuse == 0) {
7400: $changes{$prefix}{$type} = 1;
7401: } else {
7402: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7403: $changes{$prefix}{$type} = 1;
7404: }
7405: if ($okvalue ne '') {
7406: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7407: }
7408: }
7409: } else {
7410: if (($inuse == 1) && ($okvalue ne '')) {
7411: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7412: $changes{$prefix}{$type} = 1;
7413: }
7414: }
7415: } else {
7416: if (($inuse == 1) && ($okvalue ne '')) {
7417: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7418: $changes{$prefix}{$type} = 1;
7419: }
7420: }
7421: } else {
7422: if (($inuse == 1) && ($okvalue ne '')) {
7423: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7424: $changes{$prefix}{$type} = 1;
7425: }
7426: }
7427: } else {
7428: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7429: my @okvals;
7430: foreach my $val (@vals) {
1.138 raeburn 7431: if ($val =~ /:/) {
7432: my @items = split(/:/,$val);
7433: foreach my $item (@items) {
7434: if (ref($by_location{$item}) eq 'ARRAY') {
7435: push(@okvals,$item);
7436: }
7437: }
7438: } else {
7439: if (ref($by_location{$val}) eq 'ARRAY') {
7440: push(@okvals,$val);
7441: }
1.137 raeburn 7442: }
7443: }
7444: @okvals = sort(@okvals);
7445: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7446: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7447: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7448: if ($inuse == 0) {
7449: $changes{$prefix}{$type} = 1;
7450: } else {
7451: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7452: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7453: if (@changed > 0) {
7454: $changes{$prefix}{$type} = 1;
7455: }
7456: }
7457: } else {
7458: if ($inuse == 1) {
7459: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7460: $changes{$prefix}{$type} = 1;
7461: }
7462: }
7463: } else {
7464: if ($inuse == 1) {
7465: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7466: $changes{$prefix}{$type} = 1;
7467: }
7468: }
7469: } else {
7470: if ($inuse == 1) {
7471: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7472: $changes{$prefix}{$type} = 1;
7473: }
7474: }
7475: }
7476: }
7477: }
1.145 raeburn 7478:
7479: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7480: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7481: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7482: my $savespares;
7483:
7484: foreach my $lonhost (sort(keys(%servers))) {
7485: my $serverhomeID =
7486: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 7487: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7488: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7489: my %spareschg;
7490: foreach my $type (@{$types{'spares'}}) {
7491: my @okspares;
7492: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7493: foreach my $server (@checked) {
1.152 raeburn 7494: if (&Apache::lonnet::hostname($server) ne '') {
7495: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
7496: unless (grep(/^\Q$server\E$/,@okspares)) {
7497: push(@okspares,$server);
7498: }
1.145 raeburn 7499: }
7500: }
7501: }
7502: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7503: my $newspare;
1.152 raeburn 7504: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
7505: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 7506: $newspare = $new;
7507: }
7508: }
1.152 raeburn 7509: my @spares;
7510: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
7511: @spares = sort(@okspares,$newspare);
7512: } else {
7513: @spares = sort(@okspares);
7514: }
7515: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 7516: if (ref($spareid{$lonhost}) eq 'HASH') {
7517: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 7518: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 7519: if (@diffs > 0) {
7520: $spareschg{$type} = 1;
7521: }
7522: }
7523: }
7524: }
7525: if (keys(%spareschg) > 0) {
7526: $changes{'spares'}{$lonhost} = \%spareschg;
7527: }
7528: }
7529:
7530: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7531: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7532: if (ref($changes{'spares'}) eq 'HASH') {
7533: if (keys(%{$changes{'spares'}}) > 0) {
7534: $savespares = 1;
7535: }
7536: }
7537: } else {
7538: $savespares = 1;
7539: }
7540: }
7541:
1.147 raeburn 7542: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7543: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 7544: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7545: $dom);
7546: if ($putresult eq 'ok') {
7547: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7548: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7549: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7550: }
7551: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7552: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7553: }
7554: }
7555: my $cachetime = 24*60*60;
7556: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 7557: if (keys(%changes) > 0) {
7558: my %lt = &usersession_titles();
7559: $resulttext = &mt('Changes made:').'<ul>';
7560: foreach my $prefix (@prefixes) {
7561: if (ref($changes{$prefix}) eq 'HASH') {
7562: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7563: if ($prefix eq 'spares') {
7564: if (ref($changes{$prefix}) eq 'HASH') {
7565: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7566: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 7567: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7568: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 7569: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7570: foreach my $type (@{$types{$prefix}}) {
7571: if ($changes{$prefix}{$lonhost}{$type}) {
7572: my $offloadto = &mt('None');
7573: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7574: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7575: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7576: }
1.145 raeburn 7577: }
1.147 raeburn 7578: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 7579: }
1.137 raeburn 7580: }
7581: }
1.147 raeburn 7582: $resulttext .= '</li>';
1.137 raeburn 7583: }
7584: }
1.147 raeburn 7585: } else {
7586: foreach my $type (@{$types{$prefix}}) {
7587: if (defined($changes{$prefix}{$type})) {
7588: my $newvalue;
7589: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7590: if (ref($defaultshash{'usersessions'}{$prefix})) {
7591: if ($type eq 'version') {
7592: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7593: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7594: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7595: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7596: }
1.145 raeburn 7597: }
7598: }
7599: }
1.147 raeburn 7600: if ($newvalue eq '') {
7601: if ($type eq 'version') {
7602: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7603: } else {
7604: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7605: }
1.145 raeburn 7606: } else {
1.147 raeburn 7607: if ($type eq 'version') {
7608: $newvalue .= ' '.&mt('(or later)');
7609: }
7610: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 7611: }
1.137 raeburn 7612: }
7613: }
7614: }
1.147 raeburn 7615: $resulttext .= '</ul>';
1.137 raeburn 7616: }
7617: }
1.147 raeburn 7618: $resulttext .= '</ul>';
7619: } else {
7620: $resulttext = $nochgmsg;
1.137 raeburn 7621: }
7622: } else {
7623: $resulttext = '<span class="LC_error">'.
7624: &mt('An error occurred: [_1]',$putresult).'</span>';
7625: }
7626: } else {
1.147 raeburn 7627: $resulttext = $nochgmsg;
1.137 raeburn 7628: }
7629: return $resulttext;
7630: }
7631:
1.150 raeburn 7632: sub modify_loadbalancing {
7633: my ($dom,%domconfig) = @_;
7634: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7635: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7636: my ($othertitle,$usertypes,$types) =
7637: &Apache::loncommon::sorted_inst_types($dom);
7638: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7639: my @sparestypes = ('primary','default');
7640: my %typetitles = &sparestype_titles();
7641: my $resulttext;
7642: if (keys(%servers) > 1) {
7643: my ($currbalancer,$currtargets,$currrules);
7644: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7645: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7646: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7647: $currrules = $domconfig{'loadbalancing'}{'rules'};
7648: } else {
7649: ($currbalancer,$currtargets) =
7650: &Apache::lonnet::get_lonbalancer_config(\%servers);
7651: }
7652: my ($saveloadbalancing,%defaultshash,%changes);
7653: my ($alltypes,$othertypes,$titles) =
7654: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7655: my %ruletitles = &offloadtype_text();
7656: my $balancer = $env{'form.loadbalancing_lonhost'};
7657: if (!$servers{$balancer}) {
7658: undef($balancer);
7659: }
7660: if ($currbalancer ne $balancer) {
7661: $changes{'lonhost'} = 1;
7662: }
7663: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7664: if ($balancer ne '') {
7665: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7666: $saveloadbalancing = 1;
7667: }
7668: foreach my $sparetype (@sparestypes) {
7669: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151 raeburn 7670: my @offloadto;
1.150 raeburn 7671: foreach my $target (@targets) {
7672: if (($servers{$target}) && ($target ne $balancer)) {
7673: if ($sparetype eq 'default') {
7674: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7675: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7676: }
7677: }
7678: unless(grep(/^\Q$target\E$/,@offloadto)) {
7679: push(@offloadto,$target);
7680: }
7681: }
7682: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7683: }
7684: }
7685: } else {
7686: foreach my $sparetype (@sparestypes) {
7687: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7688: }
7689: }
7690: if (ref($currtargets) eq 'HASH') {
7691: foreach my $sparetype (@sparestypes) {
7692: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7693: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7694: if (@targetdiffs > 0) {
7695: $changes{'targets'} = 1;
7696: }
7697: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7698: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7699: $changes{'targets'} = 1;
7700: }
7701: }
7702: }
7703: } else {
7704: foreach my $sparetype (@sparestypes) {
7705: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7706: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7707: $changes{'targets'} = 1;
7708: }
7709: }
7710: }
7711: }
7712: my $ishomedom;
7713: if ($balancer ne '') {
7714: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7715: $ishomedom = 1;
7716: }
7717: }
7718: if (ref($alltypes) eq 'ARRAY') {
7719: foreach my $type (@{$alltypes}) {
7720: my $rule;
7721: if ($balancer ne '') {
7722: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7723: (!$ishomedom)) {
7724: $rule = $env{'form.loadbalancing_rules_'.$type};
7725: }
7726: if ($rule eq 'specific') {
7727: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7728: }
7729: }
7730: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7731: if (ref($currrules) eq 'HASH') {
7732: if ($rule ne $currrules->{$type}) {
7733: $changes{'rules'}{$type} = 1;
7734: }
7735: } elsif ($rule ne '') {
7736: $changes{'rules'}{$type} = 1;
7737: }
7738: }
7739: }
7740: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7741: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
7742: my $putresult = &Apache::lonnet::put_dom('configuration',
7743: \%defaultshash,$dom);
7744: if ($putresult eq 'ok') {
7745: if (keys(%changes) > 0) {
7746: if ($changes{'lonhost'}) {
7747: if ($currbalancer ne '') {
7748: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
7749: }
7750: if ($balancer eq '') {
7751: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
7752: } else {
7753: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7754: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
7755: }
7756: } else {
7757: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7758: }
7759: if (($changes{'targets'}) && ($balancer ne '')) {
7760: my %offloadstr;
7761: foreach my $sparetype (@sparestypes) {
7762: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7763: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7764: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
7765: }
7766: }
7767: }
7768: if (keys(%offloadstr) == 0) {
7769: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
7770: } else {
7771: my $showoffload;
7772: foreach my $sparetype (@sparestypes) {
7773: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
7774: if (defined($offloadstr{$sparetype})) {
7775: $showoffload .= $offloadstr{$sparetype};
7776: } else {
7777: $showoffload .= &mt('None');
7778: }
7779: $showoffload .= (' 'x3);
7780: }
7781: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
7782: }
7783: }
7784: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
7785: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7786: foreach my $type (@{$alltypes}) {
7787: if ($changes{'rules'}{$type}) {
7788: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
7789: my $balancetext;
7790: if ($rule eq '') {
7791: $balancetext = $ruletitles{'default'};
7792: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
7793: $balancetext = $ruletitles{$rule};
7794: } else {
7795: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
7796: }
7797: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
7798: }
7799: }
7800: }
7801: }
7802: if ($resulttext ne '') {
7803: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
7804: } else {
7805: $resulttext = $nochgmsg;
7806: }
7807: } else {
7808: $resulttext = $nochgmsg;
7809: if ($balancer ne '') {
7810: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7811: }
7812: }
7813: } else {
7814: $resulttext = '<span class="LC_error">'.
7815: &mt('An error occurred: [_1]',$putresult).'</span>';
7816: }
7817: } else {
7818: $resulttext = $nochgmsg;
7819: }
7820: } else {
7821: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
7822: }
7823: return $resulttext;
7824: }
7825:
1.48 raeburn 7826: sub recurse_check {
7827: my ($chkcats,$categories,$depth,$name) = @_;
7828: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7829: my $chg = 0;
7830: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7831: my $category = $chkcats->[$depth]{$name}[$j];
7832: my $item;
7833: if ($category eq '') {
7834: $chg ++;
7835: } else {
7836: my $deeper = $depth + 1;
7837: $item = &escape($category).':'.&escape($name).':'.$depth;
7838: if ($chg) {
7839: $categories->{$item} -= $chg;
7840: }
7841: &recurse_check($chkcats,$categories,$deeper,$category);
7842: $deeper --;
7843: }
7844: }
7845: }
7846: return;
7847: }
7848:
7849: sub recurse_cat_deletes {
7850: my ($item,$coursecategories,$deletions) = @_;
7851: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7852: my $subdepth = $depth + 1;
7853: if (ref($coursecategories) eq 'HASH') {
7854: foreach my $subitem (keys(%{$coursecategories})) {
7855: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7856: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7857: delete($coursecategories->{$subitem});
7858: $deletions->{$subitem} = 1;
7859: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7860: }
7861: }
7862: }
7863: return;
7864: }
7865:
1.125 raeburn 7866: sub get_active_dcs {
7867: my ($dom) = @_;
7868: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7869: my %domcoords;
7870: my $numdcs = 0;
7871: my $now = time;
7872: foreach my $server (keys(%dompersonnel)) {
7873: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7874: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7875: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7876: if (($end eq '') || ($end == 0) || ($end > $now)) {
7877: if ($start <= $now) {
7878: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7879: }
7880: }
7881: }
7882: }
7883: return %domcoords;
7884: }
7885:
7886: sub active_dc_picker {
7887: my ($dom,$curr_dc) = @_;
7888: my %domcoords = &get_active_dcs($dom);
7889: my @dcs = sort(keys(%domcoords));
7890: my $numdcs = scalar(@dcs);
7891: my $datatable;
7892: my $numinrow = 2;
7893: if ($numdcs > 1) {
7894: $datatable = '<table>';
7895: for (my $i=0; $i<@dcs; $i++) {
7896: my $rem = $i%($numinrow);
7897: if ($rem == 0) {
7898: if ($i > 0) {
7899: $datatable .= '</tr>';
7900: }
7901: $datatable .= '<tr>';
7902: }
7903: my $check = ' ';
7904: if ($curr_dc eq '') {
7905: if (!$i) {
7906: $check = ' checked="checked" ';
7907: }
7908: } elsif ($dcs[$i] eq $curr_dc) {
7909: $check = ' checked="checked" ';
7910: }
7911: if ($i == @dcs - 1) {
7912: my $colsleft = $numinrow - $rem;
7913: if ($colsleft > 1) {
7914: $datatable .= '<td colspan="'.$colsleft.'">';
7915: } else {
7916: $datatable .= '<td>';
7917: }
7918: } else {
7919: $datatable .= '<td>';
7920: }
7921: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7922: $datatable .= '<span class="LC_nobreak"><label>'.
7923: '<input type="radio" name="autocreate_xmldc"'.
7924: ' value="'.$dcs[$i].'"'.$check.'/>'.
7925: &Apache::loncommon::plainname($dcname,$dcdom).
7926: '</label></span></td>';
7927: }
7928: $datatable .= '</tr></table>';
7929: } elsif (@dcs) {
7930: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7931: $dcs[0].'" />';
7932: }
7933: return ($numdcs,$datatable);
7934: }
7935:
1.137 raeburn 7936: sub usersession_titles {
7937: return &Apache::lonlocal::texthash(
7938: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7939: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 7940: spares => 'Servers offloaded to, when busy',
1.137 raeburn 7941: version => 'LON-CAPA version requirement',
1.138 raeburn 7942: excludedomain => 'Allow all, but exclude specific domains',
7943: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 7944: primary => 'Primary (checked first)',
1.154 raeburn 7945: default => 'Default',
1.137 raeburn 7946: );
7947: }
7948:
1.152 raeburn 7949: sub id_for_thisdom {
7950: my (%servers) = @_;
7951: my %altids;
7952: foreach my $server (keys(%servers)) {
7953: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7954: if ($serverhome ne $server) {
7955: $altids{$serverhome} = $server;
7956: }
7957: }
7958: return %altids;
7959: }
7960:
1.150 raeburn 7961: sub count_servers {
7962: my ($currbalancer,%servers) = @_;
7963: my (@spares,$numspares);
7964: foreach my $lonhost (sort(keys(%servers))) {
7965: next if ($currbalancer eq $lonhost);
7966: push(@spares,$lonhost);
7967: }
7968: if ($currbalancer) {
7969: $numspares = scalar(@spares);
7970: } else {
7971: $numspares = scalar(@spares) - 1;
7972: }
7973: return ($numspares,@spares);
7974: }
7975:
7976: sub lonbalance_targets_js {
7977: my ($dom,$types,$servers) = @_;
7978: my $select = &mt('Select');
7979: my ($alltargets,$allishome,$allinsttypes,@alltypes);
7980: if (ref($servers) eq 'HASH') {
7981: $alltargets = join("','",sort(keys(%{$servers})));
7982: my @homedoms;
7983: foreach my $server (sort(keys(%{$servers}))) {
7984: if (&Apache::lonnet::host_domain($server) eq $dom) {
7985: push(@homedoms,'1');
7986: } else {
7987: push(@homedoms,'0');
7988: }
7989: }
7990: $allishome = join("','",@homedoms);
7991: }
7992: if (ref($types) eq 'ARRAY') {
7993: if (@{$types} > 0) {
7994: @alltypes = @{$types};
7995: }
7996: }
7997: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
7998: $allinsttypes = join("','",@alltypes);
7999: return <<"END";
8000:
8001: <script type="text/javascript">
8002: // <![CDATA[
8003:
8004: function toggleTargets() {
8005: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
8006: if (balancer == '') {
8007: hideSpares();
8008: } else {
8009: var homedoms = new Array('$allishome');
8010: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
8011: showSpares(balancer,ishomedom);
8012: }
8013: return;
8014: }
8015:
8016: function showSpares(balancer,ishomedom) {
8017: var alltargets = new Array('$alltargets');
8018: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8019: var offloadtypes = new Array('primary','default');
8020:
1.150 raeburn 8021: document.getElementById('loadbalancing_targets').style.display='block';
8022: document.getElementById('loadbalancing_disabled').style.display='none';
1.152 raeburn 8023:
1.151 raeburn 8024: for (var i=0; i<offloadtypes.length; i++) {
8025: var count = 0;
8026: for (var j=0; j<alltargets.length; j++) {
8027: if (alltargets[j] != balancer) {
8028: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
8029: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
8030: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
8031: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8032: count ++;
8033: }
1.150 raeburn 8034: }
8035: }
1.151 raeburn 8036: for (var k=0; k<insttypes.length; k++) {
8037: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8038: if (ishomedom == 1) {
1.151 raeburn 8039: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8040: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8041: } else {
1.151 raeburn 8042: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8043: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150 raeburn 8044:
8045: }
8046: } else {
1.151 raeburn 8047: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
8048: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 8049: }
1.151 raeburn 8050: if ((insttypes[k] != '_LC_external') &&
8051: ((insttypes[k] != '_LC_internetdom') ||
8052: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
8053: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
8054: for (var m=0; m<alltargets.length; m++) {
8055: var idx = m+1;
8056: if (alltargets[m] != balancer) {
8057: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 8058: }
8059: }
8060: }
8061: }
8062: return;
8063: }
8064:
8065: function hideSpares() {
8066: var alltargets = new Array('$alltargets');
8067: var insttypes = new Array('$allinsttypes');
8068: var offloadtypes = new Array('primary','default');
8069:
8070: document.getElementById('loadbalancing_targets').style.display='none';
8071: document.getElementById('loadbalancing_disabled').style.display='block';
8072:
8073: var total = alltargets.length - 1;
8074: for (var i=0; i<offloadtypes; i++) {
8075: for (var j=0; j<total; j++) {
8076: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8077: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8078: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8079: }
1.150 raeburn 8080: }
8081: for (var k=0; k<insttypes.length; k++) {
1.151 raeburn 8082: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8083: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8084: if (insttypes[k] != '_LC_external') {
8085: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8086: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8087: }
8088: }
8089: return;
8090: }
8091:
8092: function checkOffloads(item,type) {
8093: var alltargets = new Array('$alltargets');
8094: var offloadtypes = new Array('primary','default');
8095: if (item.checked) {
8096: var total = alltargets.length - 1;
8097: var other;
8098: if (type == offloadtypes[0]) {
1.151 raeburn 8099: other = offloadtypes[1];
1.150 raeburn 8100: } else {
1.151 raeburn 8101: other = offloadtypes[0];
1.150 raeburn 8102: }
8103: for (var i=0; i<total; i++) {
8104: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8105: if (server == item.value) {
8106: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8107: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8108: }
8109: }
8110: }
8111: }
8112: return;
8113: }
8114:
8115: function singleServerToggle(type) {
8116: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8117: if (offloadtoSelIdx == 0) {
8118: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8119: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8120:
8121: } else {
8122: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8123: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8124: }
8125: return;
8126: }
8127:
8128: function balanceruleChange(formname,type) {
8129: if (type == '_LC_external') {
8130: return;
8131: }
8132: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8133: for (var i=0; i<typesRules.length; i++) {
8134: if (formname.elements[typesRules[i]].checked) {
8135: if (formname.elements[typesRules[i]].value != 'specific') {
8136: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8137: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8138: } else {
8139: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8140: }
8141: }
8142: }
8143: return;
8144: }
8145:
1.152 raeburn 8146: // ]]>
8147: </script>
8148:
8149: END
8150: }
8151:
8152: sub new_spares_js {
8153: my @sparestypes = ('primary','default');
8154: my $types = join("','",@sparestypes);
8155: my $select = &mt('Select');
8156: return <<"END";
8157:
8158: <script type="text/javascript">
8159: // <![CDATA[
8160:
8161: function updateNewSpares(formname,lonhost) {
8162: var types = new Array('$types');
8163: var include = new Array();
8164: var exclude = new Array();
8165: for (var i=0; i<types.length; i++) {
8166: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8167: for (var j=0; j<spareboxes.length; j++) {
8168: if (formname.elements[spareboxes[j]].checked) {
8169: exclude.push(formname.elements[spareboxes[j]].value);
8170: } else {
8171: include.push(formname.elements[spareboxes[j]].value);
8172: }
8173: }
8174: }
8175: for (var i=0; i<types.length; i++) {
8176: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8177: var selIdx = newSpare.selectedIndex;
8178: var currnew = newSpare.options[selIdx].value;
8179: var okSpares = new Array();
8180: for (var j=0; j<newSpare.options.length; j++) {
8181: var possible = newSpare.options[j].value;
8182: if (possible != '') {
8183: if (exclude.indexOf(possible) == -1) {
8184: okSpares.push(possible);
8185: } else {
8186: if (currnew == possible) {
8187: selIdx = 0;
8188: }
8189: }
8190: }
8191: }
8192: for (var k=0; k<include.length; k++) {
8193: if (okSpares.indexOf(include[k]) == -1) {
8194: okSpares.push(include[k]);
8195: }
8196: }
8197: okSpares.sort();
8198: newSpare.options.length = 0;
8199: if (selIdx == 0) {
8200: newSpare.options[0] = new Option("$select","",true,true);
8201: } else {
8202: newSpare.options[0] = new Option("$select","",false,false);
8203: }
8204: for (var m=0; m<okSpares.length; m++) {
8205: var idx = m+1;
8206: var selThis = 0;
8207: if (selIdx != 0) {
8208: if (okSpares[m] == currnew) {
8209: selThis = 1;
8210: }
8211: }
8212: if (selThis == 1) {
8213: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8214: } else {
8215: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8216: }
8217: }
8218: }
8219: return;
8220: }
8221:
8222: function checkNewSpares(lonhost,type) {
8223: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8224: var chosen = newSpare.options[newSpare.selectedIndex].value;
8225: if (chosen != '') {
8226: var othertype;
8227: var othernewSpare;
8228: if (type == 'primary') {
8229: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8230: }
8231: if (type == 'default') {
8232: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8233: }
8234: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8235: othernewSpare.selectedIndex = 0;
8236: }
8237: }
8238: return;
8239: }
8240:
8241: // ]]>
8242: </script>
8243:
8244: END
8245:
8246: }
8247:
8248: sub common_domprefs_js {
8249: return <<"END";
8250:
8251: <script type="text/javascript">
8252: // <![CDATA[
8253:
1.150 raeburn 8254: function getIndicesByName(formname,item) {
1.152 raeburn 8255: var group = new Array();
1.150 raeburn 8256: for (var i=0;i<formname.elements.length;i++) {
8257: if (formname.elements[i].name == item) {
1.152 raeburn 8258: group.push(formname.elements[i].id);
1.150 raeburn 8259: }
8260: }
1.152 raeburn 8261: return group;
1.150 raeburn 8262: }
8263:
8264: // ]]>
8265: </script>
8266:
8267: END
1.152 raeburn 8268:
1.150 raeburn 8269: }
8270:
1.3 raeburn 8271: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>