Annotation of loncom/interface/domainprefs.pm, revision 1.152
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.152 ! raeburn 4: # $Id: domainprefs.pm,v 1.151 2011/08/09 12:16:41 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:
174: sub handler {
175: my $r=shift;
176: if ($r->header_only) {
177: &Apache::loncommon::content_type($r,'text/html');
178: $r->send_http_header;
179: return OK;
180: }
181:
1.91 raeburn 182: my $context = 'domain';
1.1 raeburn 183: my $dom = $env{'request.role.domain'};
1.5 albertel 184: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 185: if (&Apache::lonnet::allowed('mau',$dom)) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: } else {
189: $env{'user.error.msg'}=
190: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
191: return HTTP_NOT_ACCEPTABLE;
192: }
193: &Apache::lonhtmlcommon::clear_breadcrumbs();
194: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 195: ['phase','actions']);
1.30 raeburn 196: my $phase = 'pickactions';
1.3 raeburn 197: if ( exists($env{'form.phase'}) ) {
198: $phase = $env{'form.phase'};
199: }
1.150 raeburn 200: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 201: my %domconfig =
1.6 raeburn 202: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 203: 'quotas','autoenroll','autoupdate','autocreate',
204: 'directorysrch','usercreation','usermodification',
205: 'contacts','defaults','scantron','coursecategories',
206: 'serverstatuses','requestcourses','helpsettings',
1.150 raeburn 207: 'coursedefaults','usersessions','loadbalancing'],$dom);
1.43 raeburn 208: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 209: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 210: 'usercreation','usermodification','scantron',
1.121 raeburn 211: 'requestcourses','coursecategories','serverstatuses','helpsettings',
1.137 raeburn 212: 'coursedefaults','usersessions');
1.150 raeburn 213: if (keys(%servers) > 1) {
214: push(@prefs_order,'loadbalancing');
215: }
1.30 raeburn 216: my %prefs = (
217: 'rolecolors' =>
218: { text => 'Default color schemes',
1.67 raeburn 219: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 220: header => [{col1 => 'Student Settings',
221: col2 => '',},
222: {col1 => 'Coordinator Settings',
223: col2 => '',},
224: {col1 => 'Author Settings',
225: col2 => '',},
226: {col1 => 'Administrator Settings',
227: col2 => '',}],
228: },
1.110 raeburn 229: 'login' =>
1.30 raeburn 230: { text => 'Log-in page options',
1.67 raeburn 231: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 232: header => [{col1 => 'Item',
233: col2 => '',}],
234: },
1.110 raeburn 235:
1.43 raeburn 236: 'defaults' =>
1.141 raeburn 237: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 238: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 239: header => [{col1 => 'Setting',
240: col2 => 'Value'}],
241: },
1.30 raeburn 242: 'quotas' =>
1.133 raeburn 243: { text => 'User blogs, personal information pages, portfolios',
1.67 raeburn 244: help => 'Domain_Configuration_Quotas',
1.77 raeburn 245: header => [{col1 => 'User affiliation',
1.72 raeburn 246: col2 => 'Available tools',
247: col3 => 'Portfolio quota',}],
1.30 raeburn 248: },
249: 'autoenroll' =>
250: { text => 'Auto-enrollment settings',
1.67 raeburn 251: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 252: header => [{col1 => 'Configuration setting',
253: col2 => 'Value(s)'}],
254: },
255: 'autoupdate' =>
256: { text => 'Auto-update settings',
1.67 raeburn 257: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 258: header => [{col1 => 'Setting',
259: col2 => 'Value',},
1.131 raeburn 260: {col1 => 'Setting',
261: col2 => 'Affiliation'},
1.43 raeburn 262: {col1 => 'User population',
1.131 raeburn 263: col2 => 'Updateable user data'}],
1.30 raeburn 264: },
1.125 raeburn 265: 'autocreate' =>
266: { text => 'Auto-course creation settings',
267: help => 'Domain_Configuration_Auto_Creation',
268: header => [{col1 => 'Configuration Setting',
269: col2 => 'Value',}],
270: },
1.30 raeburn 271: 'directorysrch' =>
272: { text => 'Institutional directory searches',
1.67 raeburn 273: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 274: header => [{col1 => 'Setting',
275: col2 => 'Value',}],
276: },
277: 'contacts' =>
278: { text => 'Contact Information',
1.67 raeburn 279: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 280: header => [{col1 => 'Setting',
281: col2 => 'Value',}],
282: },
283:
284: 'usercreation' =>
285: { text => 'User creation',
1.67 raeburn 286: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 287: header => [{col1 => 'Format rule type',
288: col2 => 'Format rules in force'},
1.34 raeburn 289: {col1 => 'User account creation',
290: col2 => 'Usernames which may be created',},
1.30 raeburn 291: {col1 => 'Context',
1.43 raeburn 292: col2 => 'Assignable authentication types'}],
1.30 raeburn 293: },
1.69 raeburn 294: 'usermodification' =>
1.33 raeburn 295: { text => 'User modification',
1.67 raeburn 296: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 297: header => [{col1 => 'Target user has role',
298: col2 => 'User information updateable in author context'},
299: {col1 => 'Target user has role',
1.63 raeburn 300: col2 => 'User information updateable in course context'},
301: {col1 => "Status of user",
302: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 303: },
1.69 raeburn 304: 'scantron' =>
1.95 www 305: { text => 'Bubblesheet format file',
1.67 raeburn 306: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 307: header => [ {col1 => 'Item',
308: col2 => '',
309: }],
310: },
1.86 raeburn 311: 'requestcourses' =>
312: {text => 'Request creation of courses',
313: help => 'Domain_Configuration_Request_Courses',
314: header => [{col1 => 'User affiliation',
1.102 raeburn 315: col2 => 'Availability/Processing of requests',},
316: {col1 => 'Setting',
317: col2 => 'Value'}],
1.86 raeburn 318: },
1.69 raeburn 319: 'coursecategories' =>
1.120 raeburn 320: { text => 'Cataloging of courses/communities',
1.67 raeburn 321: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 322: header => [{col1 => 'Category settings',
1.57 raeburn 323: col2 => '',},
324: {col1 => 'Categories',
325: col2 => '',
326: }],
1.69 raeburn 327: },
328: 'serverstatuses' =>
1.77 raeburn 329: {text => 'Access to server status pages',
1.69 raeburn 330: help => 'Domain_Configuration_Server_Status',
331: header => [{col1 => 'Status Page',
332: col2 => 'Other named users',
333: col3 => 'Specific IPs',
334: }],
335: },
1.118 jms 336: 'helpsettings' =>
337: {text => 'Help page settings',
338: help => 'Domain_Configuration_Help_Settings',
1.122 jms 339: header => [{col1 => 'Authenticated Help Settings',
340: col2 => ''},
341: {col1 => 'Unauthenticated Help Settings',
342: col2 => ''}],
1.118 jms 343: },
1.121 raeburn 344: 'coursedefaults' =>
345: {text => 'Course/Community defaults',
346: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 347: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
348: col2 => 'Value',},
349: {col1 => 'Defaults which can be overridden for each course by a DC',
350: col2 => 'Value',},],
1.121 raeburn 351: },
1.120 raeburn 352: 'privacy' =>
353: {text => 'User Privacy',
354: help => 'Domain_Configuration_User_Privacy',
355: header => [{col1 => 'Setting',
356: col2 => 'Value',}],
357: },
1.141 raeburn 358: 'usersessions' =>
1.145 raeburn 359: {text => 'User session hosting/offloading',
1.137 raeburn 360: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 361: header => [{col1 => 'Domain server',
362: col2 => 'Servers to offload sessions to when busy'},
363: {col1 => 'Hosting of users from other domains',
1.137 raeburn 364: col2 => 'Rules'},
365: {col1 => "Hosting domain's own users elsewhere",
366: col2 => 'Rules'}],
367: },
1.150 raeburn 368: 'loadbalancing' =>
369: {text => 'Dedicated Load Balancer',
370: help => 'Domain_Configuration_Load_Balancing',
371: header => [{col1 => 'Server',
372: col2 => 'Default destinations',
373: col3 => 'User affliation',
374: col4 => 'Overrides'},
375: ],
376: },
1.3 raeburn 377: );
1.110 raeburn 378: if (keys(%servers) > 1) {
379: $prefs{'login'} = { text => 'Log-in page options',
380: help => 'Domain_Configuration_Login_Page',
381: header => [{col1 => 'Log-in Service',
382: col2 => 'Server Setting',},
383: {col1 => 'Log-in Page Items',
384: col2 => ''}],
385: };
386: }
1.6 raeburn 387: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 388: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 389: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 390: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 391: text=>"Settings to display/modify"});
1.9 raeburn 392: my $confname = $dom.'-domainconfig';
1.3 raeburn 393: if ($phase eq 'process') {
1.91 raeburn 394: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 395: } elsif ($phase eq 'display') {
1.152 ! raeburn 396: my $js;
! 397: if (keys(%servers) > 1) {
! 398: my ($othertitle,$usertypes,$types) =
! 399: &Apache::loncommon::sorted_inst_types($dom);
! 400: $js = &lonbalance_targets_js($dom,$types,\%servers).
! 401: &new_spares_js().
! 402: &common_domprefs_js();
! 403: }
1.150 raeburn 404: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 405: } else {
1.21 raeburn 406: if (keys(%domconfig) == 0) {
407: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 408: my @ids=&Apache::lonnet::current_machine_ids();
409: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 410: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 411: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 412: my $custom_img_count = 0;
413: foreach my $img (@loginimages) {
414: if ($designhash{$dom.'.login.'.$img} ne '') {
415: $custom_img_count ++;
416: }
417: }
418: foreach my $role (@roles) {
419: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
420: $custom_img_count ++;
421: }
422: }
423: if ($custom_img_count > 0) {
1.94 raeburn 424: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 425: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 426: $r->print(
427: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
428: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
429: &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 />'.
430: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
431: if ($switch_server) {
1.30 raeburn 432: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 433: }
1.91 raeburn 434: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 435: return OK;
436: }
437: }
438: }
1.91 raeburn 439: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 440: }
441: return OK;
442: }
443:
444: sub process_changes {
1.92 raeburn 445: my ($r,$dom,$confname,$action,$roles,$values) = @_;
446: my %domconfig;
447: if (ref($values) eq 'HASH') {
448: %domconfig = %{$values};
449: }
1.3 raeburn 450: my $output;
451: if ($action eq 'login') {
1.9 raeburn 452: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 453: } elsif ($action eq 'rolecolors') {
1.9 raeburn 454: $output = &modify_rolecolors($r,$dom,$confname,$roles,
455: %domconfig);
1.3 raeburn 456: } elsif ($action eq 'quotas') {
1.86 raeburn 457: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 458: } elsif ($action eq 'autoenroll') {
459: $output = &modify_autoenroll($dom,%domconfig);
460: } elsif ($action eq 'autoupdate') {
461: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 462: } elsif ($action eq 'autocreate') {
463: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 464: } elsif ($action eq 'directorysrch') {
465: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 466: } elsif ($action eq 'usercreation') {
1.28 raeburn 467: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 468: } elsif ($action eq 'usermodification') {
469: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 470: } elsif ($action eq 'contacts') {
471: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 472: } elsif ($action eq 'defaults') {
473: $output = &modify_defaults($dom,$r);
1.46 raeburn 474: } elsif ($action eq 'scantron') {
1.48 raeburn 475: $output = &modify_scantron($r,$dom,$confname,%domconfig);
476: } elsif ($action eq 'coursecategories') {
477: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 478: } elsif ($action eq 'serverstatuses') {
479: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 480: } elsif ($action eq 'requestcourses') {
481: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 482: } elsif ($action eq 'helpsettings') {
1.122 jms 483: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 484: } elsif ($action eq 'coursedefaults') {
485: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 486: } elsif ($action eq 'usersessions') {
487: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 488: } elsif ($action eq 'loadbalancing') {
489: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 490: }
491: return $output;
492: }
493:
494: sub print_config_box {
1.9 raeburn 495: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 496: my $rowtotal = 0;
1.49 raeburn 497: my $output;
498: if ($action eq 'coursecategories') {
499: $output = &coursecategories_javascript($settings);
1.91 raeburn 500: }
1.49 raeburn 501: $output .=
1.30 raeburn 502: '<table class="LC_nested_outer">
1.3 raeburn 503: <tr>
1.66 raeburn 504: <th align="left" valign="middle"><span class="LC_nobreak">'.
505: &mt($item->{text}).' '.
506: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
507: '</tr>';
1.30 raeburn 508: $rowtotal ++;
1.110 raeburn 509: my $numheaders = 1;
510: if (ref($item->{'header'}) eq 'ARRAY') {
511: $numheaders = scalar(@{$item->{'header'}});
512: }
513: if ($numheaders > 1) {
1.64 raeburn 514: my $colspan = '';
1.145 raeburn 515: my $rightcolspan = '';
1.122 jms 516: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64 raeburn 517: $colspan = ' colspan="2"';
518: }
1.145 raeburn 519: if ($action eq 'usersessions') {
520: $rightcolspan = ' colspan="3"';
521: }
1.30 raeburn 522: $output .= '
1.3 raeburn 523: <tr>
524: <td>
525: <table class="LC_nested">
526: <tr class="LC_info_row">
1.59 bisitz 527: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 528: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 529: </tr>';
1.69 raeburn 530: $rowtotal ++;
1.6 raeburn 531: if ($action eq 'autoupdate') {
1.30 raeburn 532: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 533: } elsif ($action eq 'usercreation') {
1.33 raeburn 534: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
535: } elsif ($action eq 'usermodification') {
536: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 537: } elsif ($action eq 'coursecategories') {
538: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 539: } elsif ($action eq 'login') {
540: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
541: $colspan = ' colspan="2"';
1.102 raeburn 542: } elsif ($action eq 'requestcourses') {
543: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118 jms 544: } elsif ($action eq 'helpsettings') {
1.122 jms 545: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 546: } elsif ($action eq 'usersessions') {
547: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 548: } elsif ($action eq 'rolecolors') {
1.30 raeburn 549: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 550: } elsif ($action eq 'coursedefaults') {
551: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 552: }
1.30 raeburn 553: $output .= '
1.6 raeburn 554: </table>
555: </td>
556: </tr>
557: <tr>
558: <td>
559: <table class="LC_nested">
560: <tr class="LC_info_row">
1.59 bisitz 561: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 562: $output .= '
1.59 bisitz 563: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 564: </tr>';
565: $rowtotal ++;
1.6 raeburn 566: if ($action eq 'autoupdate') {
1.131 raeburn 567: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
568: </table>
569: </td>
570: </tr>
571: <tr>
572: <td>
573: <table class="LC_nested">
574: <tr class="LC_info_row">
575: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
576: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
577: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
578: $rowtotal ++;
1.28 raeburn 579: } elsif ($action eq 'usercreation') {
1.34 raeburn 580: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
581: </table>
582: </td>
583: </tr>
584: <tr>
585: <td>
586: <table class="LC_nested">
587: <tr class="LC_info_row">
1.59 bisitz 588: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
589: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 590: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
591: $rowtotal ++;
1.33 raeburn 592: } elsif ($action eq 'usermodification') {
1.63 raeburn 593: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
594: </table>
595: </td>
596: </tr>
597: <tr>
598: <td>
599: <table class="LC_nested">
600: <tr class="LC_info_row">
601: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
602: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
603: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
604: $rowtotal ++;
1.57 raeburn 605: } elsif ($action eq 'coursecategories') {
606: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 607: } elsif ($action eq 'login') {
608: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 609: } elsif ($action eq 'requestcourses') {
610: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122 jms 611: } elsif ($action eq 'helpsettings') {
612: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 613: } elsif ($action eq 'usersessions') {
1.145 raeburn 614: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
615: </table>
616: </td>
617: </tr>
618: <tr>
619: <td>
620: <table class="LC_nested">
621: <tr class="LC_info_row">
622: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
623: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
624: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
625: $rowtotal ++;
1.139 raeburn 626: } elsif ($action eq 'coursedefaults') {
627: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 628: } elsif ($action eq 'rolecolors') {
1.30 raeburn 629: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 630: </table>
631: </td>
632: </tr>
633: <tr>
634: <td>
635: <table class="LC_nested">
636: <tr class="LC_info_row">
1.69 raeburn 637: <td class="LC_left_item"'.$colspan.' valign="top">'.
638: &mt($item->{'header'}->[2]->{'col1'}).'</td>
639: <td class="LC_right_item" valign="top">'.
640: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 641: </tr>'.
1.30 raeburn 642: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 643: </table>
644: </td>
645: </tr>
646: <tr>
647: <td>
648: <table class="LC_nested">
649: <tr class="LC_info_row">
1.59 bisitz 650: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
651: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 652: </tr>'.
1.30 raeburn 653: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
654: $rowtotal += 2;
1.6 raeburn 655: }
1.3 raeburn 656: } else {
1.30 raeburn 657: $output .= '
1.3 raeburn 658: <tr>
659: <td>
660: <table class="LC_nested">
1.30 raeburn 661: <tr class="LC_info_row">';
1.24 raeburn 662: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 663: $output .= '
1.59 bisitz 664: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 665: } elsif ($action eq 'serverstatuses') {
666: $output .= '
667: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
668: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
669:
1.6 raeburn 670: } else {
1.30 raeburn 671: $output .= '
1.69 raeburn 672: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
673: }
1.72 raeburn 674: if (defined($item->{'header'}->[0]->{'col3'})) {
675: $output .= '<td class="LC_left_item" valign="top">'.
676: &mt($item->{'header'}->[0]->{'col2'});
677: if ($action eq 'serverstatuses') {
678: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
679: }
1.69 raeburn 680: } else {
681: $output .= '<td class="LC_right_item" valign="top">'.
682: &mt($item->{'header'}->[0]->{'col2'});
683: }
684: $output .= '</td>';
685: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 686: if (defined($item->{'header'}->[0]->{'col4'})) {
687: $output .= '<td class="LC_left_item" valign="top">'.
688: &mt($item->{'header'}->[0]->{'col3'});
689: } else {
690: $output .= '<td class="LC_right_item" valign="top">'.
691: &mt($item->{'header'}->[0]->{'col3'});
692: }
1.69 raeburn 693: if ($action eq 'serverstatuses') {
694: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
695: }
696: $output .= '</td>';
1.6 raeburn 697: }
1.150 raeburn 698: if ($item->{'header'}->[0]->{'col4'}) {
699: $output .= '<td class="LC_right_item" valign="top">'.
700: &mt($item->{'header'}->[0]->{'col4'});
701: }
1.69 raeburn 702: $output .= '</tr>';
1.48 raeburn 703: $rowtotal ++;
1.3 raeburn 704: if ($action eq 'login') {
1.110 raeburn 705: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
706: \$rowtotal);
1.3 raeburn 707: } elsif ($action eq 'quotas') {
1.86 raeburn 708: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 709: } elsif ($action eq 'autoenroll') {
1.30 raeburn 710: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 711: } elsif ($action eq 'autocreate') {
712: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 713: } elsif ($action eq 'directorysrch') {
1.30 raeburn 714: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 715: } elsif ($action eq 'contacts') {
1.30 raeburn 716: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 717: } elsif ($action eq 'defaults') {
718: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 719: } elsif ($action eq 'scantron') {
720: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 721: } elsif ($action eq 'serverstatuses') {
722: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 723: } elsif ($action eq 'helpsettings') {
1.122 jms 724: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150 raeburn 725: } elsif ($action eq 'loadbalancing') {
726: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 727: }
1.3 raeburn 728: }
1.30 raeburn 729: $output .= '
1.3 raeburn 730: </table>
731: </td>
732: </tr>
1.30 raeburn 733: </table><br />';
734: return ($output,$rowtotal);
1.1 raeburn 735: }
736:
1.3 raeburn 737: sub print_login {
1.110 raeburn 738: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
739: my ($css_class,$datatable);
1.6 raeburn 740: my %choices = &login_choices();
1.110 raeburn 741:
742: if ($position eq 'top') {
1.149 raeburn 743: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 744: my $choice = $choices{'disallowlogin'};
745: $css_class = ' class="LC_odd_row"';
1.128 raeburn 746: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 747: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 748: '<th>'.$choices{'server'}.'</th>'.
749: '<th>'.$choices{'serverpath'}.'</th>'.
750: '<th>'.$choices{'custompath'}.'</th>'.
751: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 752: my %disallowed;
753: if (ref($settings) eq 'HASH') {
754: if (ref($settings->{'loginvia'}) eq 'HASH') {
755: %disallowed = %{$settings->{'loginvia'}};
756: }
757: }
758: foreach my $lonhost (sort(keys(%servers))) {
759: my $direct = 'selected="selected"';
1.128 raeburn 760: if (ref($disallowed{$lonhost}) eq 'HASH') {
761: if ($disallowed{$lonhost}{'server'} ne '') {
762: $direct = '';
763: }
1.110 raeburn 764: }
1.115 raeburn 765: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 766: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 767: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
768: '</option>';
769: foreach my $hostid (keys(%servers)) {
1.115 raeburn 770: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 771: my $selected = '';
1.128 raeburn 772: if (ref($disallowed{$lonhost}) eq 'HASH') {
773: if ($hostid eq $disallowed{$lonhost}{'server'}) {
774: $selected = 'selected="selected"';
775: }
1.110 raeburn 776: }
777: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
778: $servers{$hostid}.'</option>';
779: }
1.128 raeburn 780: $datatable .= '</select></td>'.
781: '<td><select name="'.$lonhost.'_serverpath">';
782: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
783: my $pathname = $path;
784: if ($path eq 'custom') {
785: $pathname = &mt('Custom Path').' ->';
786: }
787: my $selected = '';
788: if (ref($disallowed{$lonhost}) eq 'HASH') {
789: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
790: $selected = 'selected="selected"';
791: }
792: } elsif ($path eq '') {
793: $selected = 'selected="selected"';
794: }
795: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
796: }
797: $datatable .= '</select></td>';
798: my ($custom,$exempt);
799: if (ref($disallowed{$lonhost}) eq 'HASH') {
800: $custom = $disallowed{$lonhost}{'custompath'};
801: $exempt = $disallowed{$lonhost}{'exempt'};
802: }
803: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
804: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
805: '</tr>';
1.110 raeburn 806: }
807: $datatable .= '</table></td></tr>';
808: return $datatable;
809: }
810:
1.42 raeburn 811: my %defaultchecked = (
1.43 raeburn 812: 'coursecatalog' => 'on',
813: 'adminmail' => 'off',
814: 'newuser' => 'off',
815: );
1.118 jms 816: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 817: my (%checkedon,%checkedoff);
818: foreach my $item (@toggles) {
819: if ($defaultchecked{$item} eq 'on') {
820: $checkedon{$item} = ' checked="checked" ';
821: $checkedoff{$item} = ' ';
822: } elsif ($defaultchecked{$item} eq 'off') {
823: $checkedoff{$item} = ' checked="checked" ';
824: $checkedon{$item} = ' ';
825: }
826: }
1.41 raeburn 827: my @images = ('img','logo','domlogo','login');
828: my @logintext = ('textcol','bgcol');
1.6 raeburn 829: my @bgs = ('pgbg','mainbg','sidebg');
830: my @links = ('link','alink','vlink');
1.7 albertel 831: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 832: my %defaultdesign = %Apache::loncommon::defaultdesign;
833: my (%is_custom,%designs);
834: my %defaults = (
835: font => $defaultdesign{'login.font'},
836: );
837: foreach my $item (@images) {
838: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 839: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 840: }
841: foreach my $item (@bgs) {
842: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
843: }
1.41 raeburn 844: foreach my $item (@logintext) {
845: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
846: }
1.6 raeburn 847: foreach my $item (@links) {
848: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
849: }
1.3 raeburn 850: if (ref($settings) eq 'HASH') {
1.42 raeburn 851: foreach my $item (@toggles) {
852: if ($settings->{$item} eq '1') {
853: $checkedon{$item} = ' checked="checked" ';
854: $checkedoff{$item} = ' ';
855: } elsif ($settings->{$item} eq '0') {
856: $checkedoff{$item} = ' checked="checked" ';
857: $checkedon{$item} = ' ';
858: }
1.1 raeburn 859: }
1.6 raeburn 860: foreach my $item (@images) {
1.70 raeburn 861: if (defined($settings->{$item})) {
1.6 raeburn 862: $designs{$item} = $settings->{$item};
863: $is_custom{$item} = 1;
864: }
1.70 raeburn 865: if (defined($settings->{'showlogo'}{$item})) {
866: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
867: }
1.6 raeburn 868: }
1.41 raeburn 869: foreach my $item (@logintext) {
870: if ($settings->{$item} ne '') {
871: $designs{'logintext'}{$item} = $settings->{$item};
872: $is_custom{$item} = 1;
873: }
874: }
1.6 raeburn 875: if ($settings->{'font'} ne '') {
876: $designs{'font'} = $settings->{'font'};
877: $is_custom{'font'} = 1;
878: }
879: foreach my $item (@bgs) {
880: if ($settings->{$item} ne '') {
881: $designs{'bgs'}{$item} = $settings->{$item};
882: $is_custom{$item} = 1;
883: }
884: }
885: foreach my $item (@links) {
886: if ($settings->{$item} ne '') {
887: $designs{'links'}{$item} = $settings->{$item};
888: $is_custom{$item} = 1;
889: }
890: }
891: } else {
892: if ($designhash{$dom.'.login.font'} ne '') {
893: $designs{'font'} = $designhash{$dom.'.login.font'};
894: $is_custom{'font'} = 1;
895: }
1.8 raeburn 896: foreach my $item (@images) {
897: if ($designhash{$dom.'.login.'.$item} ne '') {
898: $designs{$item} = $designhash{$dom.'.login.'.$item};
899: $is_custom{$item} = 1;
900: }
901: }
1.6 raeburn 902: foreach my $item (@bgs) {
903: if ($designhash{$dom.'.login.'.$item} ne '') {
904: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
905: $is_custom{$item} = 1;
906: }
907: }
908: foreach my $item (@links) {
909: if ($designhash{$dom.'.login.'.$item} ne '') {
910: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
911: $is_custom{$item} = 1;
912: }
913: }
1.1 raeburn 914: }
1.6 raeburn 915: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
916: logo => 'Institution Logo',
1.41 raeburn 917: domlogo => 'Domain Logo',
918: login => 'Login box');
1.6 raeburn 919: my $itemcount = 1;
1.42 raeburn 920: foreach my $item (@toggles) {
921: $css_class = $itemcount%2?' class="LC_odd_row"':'';
922: $datatable .=
923: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
924: '</td><td>'.
925: '<span class="LC_nobreak"><label><input type="radio" name="'.
926: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
927: '</label> <label><input type="radio" name="'.$item.'"'.
928: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
929: '</tr>';
930: $itemcount ++;
931: }
1.135 bisitz 932: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 933: $datatable .= '</tr></table></td></tr>';
934: return $datatable;
935: }
936:
937: sub login_choices {
938: my %choices =
939: &Apache::lonlocal::texthash (
1.116 bisitz 940: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 941: adminmail => "Display Administrator's E-mail Address?",
942: disallowlogin => "Login page requests redirected",
943: hostid => "Server",
1.128 raeburn 944: server => "Redirect to:",
945: serverpath => "Path",
946: custompath => "Custom",
947: exempt => "Exempt IP(s)",
1.110 raeburn 948: directlogin => "No redirect",
949: newuser => "Link to create a user account",
950: img => "Header",
951: logo => "Main Logo",
952: domlogo => "Domain Logo",
953: login => "Log-in Header",
954: textcol => "Text color",
955: bgcol => "Box color",
956: bgs => "Background colors",
957: links => "Link colors",
958: font => "Font color",
959: pgbg => "Header",
960: mainbg => "Page",
961: sidebg => "Login box",
962: link => "Link",
963: alink => "Active link",
964: vlink => "Visited link",
1.6 raeburn 965: );
966: return %choices;
967: }
968:
969: sub print_rolecolors {
1.30 raeburn 970: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 971: my %choices = &color_font_choices();
972: my @bgs = ('pgbg','tabbg','sidebg');
973: my @links = ('link','alink','vlink');
974: my @images = ('img');
975: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 976: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 977: my %defaultdesign = %Apache::loncommon::defaultdesign;
978: my (%is_custom,%designs);
979: my %defaults = (
980: img => $defaultdesign{$role.'.img'},
981: font => $defaultdesign{$role.'.font'},
1.97 tempelho 982: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 983: );
984: foreach my $item (@bgs) {
985: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
986: }
987: foreach my $item (@links) {
988: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
989: }
990: if (ref($settings) eq 'HASH') {
991: if (ref($settings->{$role}) eq 'HASH') {
992: if ($settings->{$role}->{'img'} ne '') {
993: $designs{'img'} = $settings->{$role}->{'img'};
994: $is_custom{'img'} = 1;
995: }
996: if ($settings->{$role}->{'font'} ne '') {
997: $designs{'font'} = $settings->{$role}->{'font'};
998: $is_custom{'font'} = 1;
999: }
1.97 tempelho 1000: if ($settings->{$role}->{'fontmenu'} ne '') {
1001: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1002: $is_custom{'fontmenu'} = 1;
1003: }
1.6 raeburn 1004: foreach my $item (@bgs) {
1005: if ($settings->{$role}->{$item} ne '') {
1006: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1007: $is_custom{$item} = 1;
1008: }
1009: }
1010: foreach my $item (@links) {
1011: if ($settings->{$role}->{$item} ne '') {
1012: $designs{'links'}{$item} = $settings->{$role}->{$item};
1013: $is_custom{$item} = 1;
1014: }
1015: }
1016: }
1017: } else {
1018: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1019: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1020: $is_custom{'img'} = 1;
1021: }
1.97 tempelho 1022: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1023: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1024: $is_custom{'fontmenu'} = 1;
1025: }
1.6 raeburn 1026: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1027: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1028: $is_custom{'font'} = 1;
1029: }
1030: foreach my $item (@bgs) {
1031: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1032: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1033: $is_custom{$item} = 1;
1034:
1035: }
1036: }
1037: foreach my $item (@links) {
1038: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1039: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1040: $is_custom{$item} = 1;
1041: }
1042: }
1043: }
1044: my $itemcount = 1;
1.30 raeburn 1045: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1046: $datatable .= '</tr></table></td></tr>';
1047: return $datatable;
1048: }
1049:
1050: sub display_color_options {
1.9 raeburn 1051: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1052: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.6 raeburn 1053: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1054: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1055: '<td>'.$choices->{'font'}.'</td>';
1056: if (!$is_custom->{'font'}) {
1.30 raeburn 1057: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1058: } else {
1059: $datatable .= '<td> </td>';
1060: }
1061: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1062: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1063: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1064: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1065: ' <span id="css_'.$role.'_font" style="background-color: '.
1066: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1067: '</span></td></tr>';
1.107 raeburn 1068: unless ($role eq 'login') {
1069: $datatable .= '<tr'.$css_class.'>'.
1070: '<td>'.$choices->{'fontmenu'}.'</td>';
1071: if (!$is_custom->{'fontmenu'}) {
1072: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1073: } else {
1074: $datatable .= '<td> </td>';
1075: }
1076: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1077: $datatable .= '<td><span class="LC_nobreak">'.
1078: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1079: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1080: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1081: $designs->{'fontmenu'}.';"> </span>'.
1082: '</span></td></tr>';
1.97 tempelho 1083: }
1.9 raeburn 1084: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1085: foreach my $img (@{$images}) {
1.18 albertel 1086: $itemcount ++;
1.6 raeburn 1087: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1088: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1089: '<td>'.$choices->{$img};
1.41 raeburn 1090: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1091: if ($role eq 'login') {
1092: if ($img eq 'login') {
1093: $login_hdr_pick =
1.135 bisitz 1094: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1095: $logincolors =
1096: &login_text_colors($img,$role,$logintext,$phase,$choices,
1097: $designs);
1098: } elsif ($img ne 'domlogo') {
1099: $datatable.= &logo_display_options($img,$defaults,$designs);
1100: }
1101: }
1102: $datatable .= '</td>';
1.6 raeburn 1103: if ($designs->{$img} ne '') {
1104: $imgfile = $designs->{$img};
1.18 albertel 1105: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1106: } else {
1107: $imgfile = $defaults->{$img};
1108: }
1109: if ($imgfile) {
1.9 raeburn 1110: my ($showfile,$fullsize);
1111: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1112: my $urldir = $1;
1113: my $filename = $2;
1114: my @info = &Apache::lonnet::stat_file($designs->{$img});
1115: if (@info) {
1116: my $thumbfile = 'tn-'.$filename;
1117: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1118: if (@thumb) {
1119: $showfile = $urldir.'/'.$thumbfile;
1120: } else {
1121: $showfile = $imgfile;
1122: }
1123: } else {
1124: $showfile = '';
1125: }
1126: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1127: $showfile = $imgfile;
1.6 raeburn 1128: my $imgdir = $1;
1129: my $filename = $2;
1130: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
1131: $showfile = "/$imgdir/tn-".$filename;
1132: } else {
1133: my $input = "/home/httpd/html".$imgfile;
1134: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
1135: if (!-e $output) {
1.9 raeburn 1136: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1137: my ($fullwidth,$fullheight) = &check_dimensions($input);
1138: if ($fullwidth ne '' && $fullheight ne '') {
1139: if ($fullwidth > $width && $fullheight > $height) {
1140: my $size = $width.'x'.$height;
1141: system("convert -sample $size $input $output");
1142: $showfile = '/'.$imgdir.'/tn-'.$filename;
1143: }
1144: }
1.6 raeburn 1145: }
1146: }
1.16 raeburn 1147: }
1.6 raeburn 1148: if ($showfile) {
1.40 raeburn 1149: if ($showfile =~ m{^/(adm|res)/}) {
1150: if ($showfile =~ m{^/res/}) {
1151: my $local_showfile =
1152: &Apache::lonnet::filelocation('',$showfile);
1153: &Apache::lonnet::repcopy($local_showfile);
1154: }
1155: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1156: }
1157: if ($imgfile) {
1158: if ($imgfile =~ m{^/(adm|res)/}) {
1159: if ($imgfile =~ m{^/res/}) {
1160: my $local_imgfile =
1161: &Apache::lonnet::filelocation('',$imgfile);
1162: &Apache::lonnet::repcopy($local_imgfile);
1163: }
1164: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1165: } else {
1166: $fullsize = $imgfile;
1167: }
1168: }
1.41 raeburn 1169: $datatable .= '<td>';
1170: if ($img eq 'login') {
1.135 bisitz 1171: $datatable .= $login_hdr_pick;
1172: }
1.41 raeburn 1173: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1174: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1175: } else {
1176: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1177: &mt('Upload:');
1178: }
1179: } else {
1180: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1181: &mt('Upload:');
1182: }
1.9 raeburn 1183: if ($switchserver) {
1184: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1185: } else {
1.135 bisitz 1186: if ($img ne 'login') { # suppress file selection for Log-in header
1187: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1188: }
1.9 raeburn 1189: }
1190: $datatable .= '</td></tr>';
1.6 raeburn 1191: }
1192: $itemcount ++;
1193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1194: $datatable .= '<tr'.$css_class.'>'.
1195: '<td>'.$choices->{'bgs'}.'</td>';
1196: my $bgs_def;
1197: foreach my $item (@{$bgs}) {
1198: if (!$is_custom->{$item}) {
1.70 raeburn 1199: $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 1200: }
1201: }
1202: if ($bgs_def) {
1.8 raeburn 1203: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1204: } else {
1205: $datatable .= '<td> </td>';
1206: }
1207: $datatable .= '<td class="LC_right_item">'.
1208: '<table border="0"><tr>';
1209: foreach my $item (@{$bgs}) {
1210: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1211: $datatable .= '<td align="center">'.$link;
1212: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1213: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1214: }
1215: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1216: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1217: }
1218: $datatable .= '</tr></table></td></tr>';
1219: $itemcount ++;
1220: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1221: $datatable .= '<tr'.$css_class.'>'.
1222: '<td>'.$choices->{'links'}.'</td>';
1223: my $links_def;
1224: foreach my $item (@{$links}) {
1225: if (!$is_custom->{$item}) {
1.30 raeburn 1226: $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 1227: }
1228: }
1229: if ($links_def) {
1.8 raeburn 1230: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1231: } else {
1232: $datatable .= '<td> </td>';
1233: }
1234: $datatable .= '<td class="LC_right_item">'.
1235: '<table border="0"><tr>';
1236: foreach my $item (@{$links}) {
1.30 raeburn 1237: $datatable .= '<td align="center">'."\n".
1238: &color_pick($phase,$role,$item,$choices->{$item},
1239: $designs->{'links'}{$item});
1.6 raeburn 1240: if ($designs->{'links'}{$item}) {
1.30 raeburn 1241: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1242: }
1243: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1244: '" /></td>';
1245: }
1.30 raeburn 1246: $$rowtotal += $itemcount;
1.3 raeburn 1247: return $datatable;
1248: }
1249:
1.70 raeburn 1250: sub logo_display_options {
1251: my ($img,$defaults,$designs) = @_;
1252: my $checkedon;
1253: if (ref($defaults) eq 'HASH') {
1254: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1255: if ($defaults->{'showlogo'}{$img}) {
1256: $checkedon = 'checked="checked" ';
1257: }
1258: }
1259: }
1260: if (ref($designs) eq 'HASH') {
1261: if (ref($designs->{'showlogo'}) eq 'HASH') {
1262: if (defined($designs->{'showlogo'}{$img})) {
1263: if ($designs->{'showlogo'}{$img} == 0) {
1264: $checkedon = '';
1265: } elsif ($designs->{'showlogo'}{$img} == 1) {
1266: $checkedon = 'checked="checked" ';
1267: }
1268: }
1269: }
1270: }
1271: return '<br /><label> <input type="checkbox" name="'.
1272: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1273: &mt('show').'</label>'."\n";
1274: }
1275:
1.41 raeburn 1276: sub login_header_options {
1.135 bisitz 1277: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1278: my $output = '';
1.41 raeburn 1279: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1280: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1281: if (!$is_custom->{'textcol'}) {
1282: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1283: ' ';
1284: }
1285: if (!$is_custom->{'bgcol'}) {
1286: $output .= $choices->{'bgcol'}.': '.
1287: '<span id="css_'.$role.'_font" style="background-color: '.
1288: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1289: }
1290: $output .= '<br />';
1291: }
1292: $output .='<br />';
1293: return $output;
1294: }
1295:
1296: sub login_text_colors {
1297: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1298: my $color_menu = '<table border="0"><tr>';
1299: foreach my $item (@{$logintext}) {
1300: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1301: $color_menu .= '<td align="center">'.$link;
1302: if ($designs->{'logintext'}{$item}) {
1303: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1304: }
1305: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1306: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1307: '<td> </td>';
1308: }
1309: $color_menu .= '</tr></table><br />';
1310: return $color_menu;
1311: }
1312:
1313: sub image_changes {
1314: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1315: my $output;
1.135 bisitz 1316: if ($img eq 'login') {
1317: # suppress image for Log-in header
1318: } elsif (!$is_custom) {
1.70 raeburn 1319: if ($img ne 'domlogo') {
1.41 raeburn 1320: $output .= &mt('Default image:').'<br />';
1321: } else {
1322: $output .= &mt('Default in use:').'<br />';
1323: }
1324: }
1.135 bisitz 1325: if ($img eq 'login') { # suppress image for Log-in header
1326: $output .= '<td>'.$logincolors;
1.41 raeburn 1327: } else {
1.135 bisitz 1328: if ($img_import) {
1329: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1330: }
1331: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1332: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1333: if ($is_custom) {
1334: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1335: '<input type="checkbox" name="'.
1336: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1337: '</label> '.&mt('Replace:').'</span><br />';
1338: } else {
1339: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1340: }
1.41 raeburn 1341: }
1342: return $output;
1343: }
1344:
1.6 raeburn 1345: sub color_pick {
1346: my ($phase,$role,$item,$desc,$curcol) = @_;
1347: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1348: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1349: ');">'.$desc.'</a>';
1350: return $link;
1351: }
1352:
1.3 raeburn 1353: sub print_quotas {
1.86 raeburn 1354: my ($dom,$settings,$rowtotal,$action) = @_;
1355: my $context;
1356: if ($action eq 'quotas') {
1357: $context = 'tools';
1358: } else {
1359: $context = $action;
1360: }
1.101 raeburn 1361: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1362: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1363: my $typecount = 0;
1.101 raeburn 1364: my ($css_class,%titles);
1.86 raeburn 1365: if ($context eq 'requestcourses') {
1.98 raeburn 1366: @usertools = ('official','unofficial','community');
1.106 raeburn 1367: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1368: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1369: %titles = &courserequest_titles();
1.86 raeburn 1370: } else {
1371: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1372: %titles = &tool_titles();
1.86 raeburn 1373: }
1.26 raeburn 1374: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1375: foreach my $type (@{$types}) {
1.72 raeburn 1376: my $currdefquota;
1.86 raeburn 1377: unless ($context eq 'requestcourses') {
1378: if (ref($settings) eq 'HASH') {
1379: if (ref($settings->{defaultquota}) eq 'HASH') {
1380: $currdefquota = $settings->{defaultquota}->{$type};
1381: } else {
1382: $currdefquota = $settings->{$type};
1383: }
1.78 raeburn 1384: }
1.72 raeburn 1385: }
1.3 raeburn 1386: if (defined($usertypes->{$type})) {
1387: $typecount ++;
1388: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1389: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1390: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1391: '<td class="LC_left_item">';
1.101 raeburn 1392: if ($context eq 'requestcourses') {
1393: $datatable .= '<table><tr>';
1394: }
1395: my %cell;
1.72 raeburn 1396: foreach my $item (@usertools) {
1.101 raeburn 1397: if ($context eq 'requestcourses') {
1398: my ($curroption,$currlimit);
1399: if (ref($settings) eq 'HASH') {
1400: if (ref($settings->{$item}) eq 'HASH') {
1401: $curroption = $settings->{$item}->{$type};
1402: if ($curroption =~ /^autolimit=(\d*)$/) {
1403: $currlimit = $1;
1404: }
1405: }
1406: }
1407: if (!$curroption) {
1408: $curroption = 'norequest';
1409: }
1410: $datatable .= '<th>'.$titles{$item}.'</th>';
1411: foreach my $option (@options) {
1412: my $val = $option;
1413: if ($option eq 'norequest') {
1414: $val = 0;
1415: }
1416: if ($option eq 'validate') {
1417: my $canvalidate = 0;
1418: if (ref($validations{$item}) eq 'HASH') {
1419: if ($validations{$item}{$type}) {
1420: $canvalidate = 1;
1421: }
1422: }
1423: next if (!$canvalidate);
1424: }
1425: my $checked = '';
1426: if ($option eq $curroption) {
1427: $checked = ' checked="checked"';
1428: } elsif ($option eq 'autolimit') {
1429: if ($curroption =~ /^autolimit/) {
1430: $checked = ' checked="checked"';
1431: }
1432: }
1433: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1434: '<input type="radio" name="crsreq_'.$item.
1435: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1436: $titles{$option}.'</label>';
1.101 raeburn 1437: if ($option eq 'autolimit') {
1.127 raeburn 1438: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1439: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1440: 'value="'.$currlimit.'" />';
1.101 raeburn 1441: }
1.127 raeburn 1442: $cell{$item} .= '</span> ';
1.103 raeburn 1443: if ($option eq 'autolimit') {
1.127 raeburn 1444: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1445: }
1.101 raeburn 1446: }
1447: } else {
1448: my $checked = 'checked="checked" ';
1449: if (ref($settings) eq 'HASH') {
1450: if (ref($settings->{$item}) eq 'HASH') {
1451: if ($settings->{$item}->{$type} == 0) {
1452: $checked = '';
1453: } elsif ($settings->{$item}->{$type} == 1) {
1454: $checked = 'checked="checked" ';
1455: }
1.78 raeburn 1456: }
1.72 raeburn 1457: }
1.101 raeburn 1458: $datatable .= '<span class="LC_nobreak"><label>'.
1459: '<input type="checkbox" name="'.$context.'_'.$item.
1460: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1461: '</label></span> ';
1.72 raeburn 1462: }
1.101 raeburn 1463: }
1464: if ($context eq 'requestcourses') {
1465: $datatable .= '</tr><tr>';
1466: foreach my $item (@usertools) {
1.106 raeburn 1467: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1468: }
1469: $datatable .= '</tr></table>';
1.72 raeburn 1470: }
1.86 raeburn 1471: $datatable .= '</td>';
1472: unless ($context eq 'requestcourses') {
1473: $datatable .=
1474: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1475: '<input type="text" name="quota_'.$type.
1.72 raeburn 1476: '" value="'.$currdefquota.
1.86 raeburn 1477: '" size="5" /> Mb</span></td>';
1478: }
1479: $datatable .= '</tr>';
1.3 raeburn 1480: }
1481: }
1482: }
1.86 raeburn 1483: unless ($context eq 'requestcourses') {
1484: $defaultquota = '20';
1485: if (ref($settings) eq 'HASH') {
1486: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1487: $defaultquota = $settings->{'defaultquota'}->{'default'};
1488: } elsif (defined($settings->{'default'})) {
1489: $defaultquota = $settings->{'default'};
1490: }
1.3 raeburn 1491: }
1492: }
1493: $typecount ++;
1494: $css_class = $typecount%2?' class="LC_odd_row"':'';
1495: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1496: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1497: '<td class="LC_left_item">';
1.101 raeburn 1498: if ($context eq 'requestcourses') {
1499: $datatable .= '<table><tr>';
1500: }
1501: my %defcell;
1.72 raeburn 1502: foreach my $item (@usertools) {
1.101 raeburn 1503: if ($context eq 'requestcourses') {
1504: my ($curroption,$currlimit);
1505: if (ref($settings) eq 'HASH') {
1506: if (ref($settings->{$item}) eq 'HASH') {
1507: $curroption = $settings->{$item}->{'default'};
1508: if ($curroption =~ /^autolimit=(\d*)$/) {
1509: $currlimit = $1;
1510: }
1511: }
1512: }
1513: if (!$curroption) {
1514: $curroption = 'norequest';
1515: }
1516: $datatable .= '<th>'.$titles{$item}.'</th>';
1517: foreach my $option (@options) {
1518: my $val = $option;
1519: if ($option eq 'norequest') {
1520: $val = 0;
1521: }
1522: if ($option eq 'validate') {
1523: my $canvalidate = 0;
1524: if (ref($validations{$item}) eq 'HASH') {
1525: if ($validations{$item}{'default'}) {
1526: $canvalidate = 1;
1527: }
1528: }
1529: next if (!$canvalidate);
1530: }
1531: my $checked = '';
1532: if ($option eq $curroption) {
1533: $checked = ' checked="checked"';
1534: } elsif ($option eq 'autolimit') {
1535: if ($curroption =~ /^autolimit/) {
1536: $checked = ' checked="checked"';
1537: }
1538: }
1539: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1540: '<input type="radio" name="crsreq_'.$item.
1541: '_default" value="'.$val.'"'.$checked.' />'.
1542: $titles{$option}.'</label>';
1543: if ($option eq 'autolimit') {
1.127 raeburn 1544: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1545: $item.'_limit_default" size="1" '.
1546: 'value="'.$currlimit.'" />';
1547: }
1.127 raeburn 1548: $defcell{$item} .= '</span> ';
1.104 raeburn 1549: if ($option eq 'autolimit') {
1.127 raeburn 1550: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1551: }
1.101 raeburn 1552: }
1553: } else {
1554: my $checked = 'checked="checked" ';
1555: if (ref($settings) eq 'HASH') {
1556: if (ref($settings->{$item}) eq 'HASH') {
1557: if ($settings->{$item}->{'default'} == 0) {
1558: $checked = '';
1559: } elsif ($settings->{$item}->{'default'} == 1) {
1560: $checked = 'checked="checked" ';
1561: }
1.78 raeburn 1562: }
1.72 raeburn 1563: }
1.101 raeburn 1564: $datatable .= '<span class="LC_nobreak"><label>'.
1565: '<input type="checkbox" name="'.$context.'_'.$item.
1566: '" value="default" '.$checked.'/>'.$titles{$item}.
1567: '</label></span> ';
1568: }
1569: }
1570: if ($context eq 'requestcourses') {
1571: $datatable .= '</tr><tr>';
1572: foreach my $item (@usertools) {
1.106 raeburn 1573: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1574: }
1.101 raeburn 1575: $datatable .= '</tr></table>';
1.72 raeburn 1576: }
1.86 raeburn 1577: $datatable .= '</td>';
1578: unless ($context eq 'requestcourses') {
1579: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1580: '<input type="text" name="defaultquota" value="'.
1581: $defaultquota.'" size="5" /> Mb</span></td>';
1582: }
1583: $datatable .= '</tr>';
1.72 raeburn 1584: $typecount ++;
1585: $css_class = $typecount%2?' class="LC_odd_row"':'';
1586: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1587: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1588: if ($context eq 'requestcourses') {
1.109 raeburn 1589: $datatable .= &mt('(overrides affiliation, if set)').
1590: '</td>'.
1591: '<td class="LC_left_item">'.
1592: '<table><tr>';
1.101 raeburn 1593: } else {
1.109 raeburn 1594: $datatable .= &mt('(overrides affiliation, if checked)').
1595: '</td>'.
1596: '<td class="LC_left_item" colspan="2">'.
1597: '<br />';
1.101 raeburn 1598: }
1599: my %advcell;
1.72 raeburn 1600: foreach my $item (@usertools) {
1.101 raeburn 1601: if ($context eq 'requestcourses') {
1602: my ($curroption,$currlimit);
1603: if (ref($settings) eq 'HASH') {
1604: if (ref($settings->{$item}) eq 'HASH') {
1605: $curroption = $settings->{$item}->{'_LC_adv'};
1606: if ($curroption =~ /^autolimit=(\d*)$/) {
1607: $currlimit = $1;
1608: }
1609: }
1610: }
1611: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1612: my $checked = '';
1613: if ($curroption eq '') {
1614: $checked = ' checked="checked"';
1615: }
1616: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1617: '<input type="radio" name="crsreq_'.$item.
1618: '__LC_adv" value=""'.$checked.' />'.
1619: &mt('No override set').'</label></span> ';
1.101 raeburn 1620: foreach my $option (@options) {
1621: my $val = $option;
1622: if ($option eq 'norequest') {
1623: $val = 0;
1624: }
1625: if ($option eq 'validate') {
1626: my $canvalidate = 0;
1627: if (ref($validations{$item}) eq 'HASH') {
1628: if ($validations{$item}{'_LC_adv'}) {
1629: $canvalidate = 1;
1630: }
1631: }
1632: next if (!$canvalidate);
1633: }
1634: my $checked = '';
1.104 raeburn 1635: if ($val eq $curroption) {
1.101 raeburn 1636: $checked = ' checked="checked"';
1637: } elsif ($option eq 'autolimit') {
1638: if ($curroption =~ /^autolimit/) {
1639: $checked = ' checked="checked"';
1640: }
1641: }
1642: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1643: '<input type="radio" name="crsreq_'.$item.
1644: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1645: $titles{$option}.'</label>';
1646: if ($option eq 'autolimit') {
1.127 raeburn 1647: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1648: $item.'_limit__LC_adv" size="1" '.
1649: 'value="'.$currlimit.'" />';
1650: }
1.127 raeburn 1651: $advcell{$item} .= '</span> ';
1.104 raeburn 1652: if ($option eq 'autolimit') {
1.127 raeburn 1653: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1654: }
1.101 raeburn 1655: }
1656: } else {
1657: my $checked = 'checked="checked" ';
1658: if (ref($settings) eq 'HASH') {
1659: if (ref($settings->{$item}) eq 'HASH') {
1660: if ($settings->{$item}->{'_LC_adv'} == 0) {
1661: $checked = '';
1662: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1663: $checked = 'checked="checked" ';
1664: }
1.79 raeburn 1665: }
1.72 raeburn 1666: }
1.101 raeburn 1667: $datatable .= '<span class="LC_nobreak"><label>'.
1668: '<input type="checkbox" name="'.$context.'_'.$item.
1669: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1670: '</label></span> ';
1671: }
1672: }
1673: if ($context eq 'requestcourses') {
1674: $datatable .= '</tr><tr>';
1675: foreach my $item (@usertools) {
1.106 raeburn 1676: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1677: }
1.101 raeburn 1678: $datatable .= '</tr></table>';
1.72 raeburn 1679: }
1.98 raeburn 1680: $datatable .= '</td></tr>';
1.30 raeburn 1681: $$rowtotal += $typecount;
1.3 raeburn 1682: return $datatable;
1683: }
1684:
1.102 raeburn 1685: sub print_courserequestmail {
1686: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1687: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1688: $now = time;
1689: $rows = 0;
1690: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1691: foreach my $server (keys(%dompersonnel)) {
1692: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1693: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1694: if (!grep(/^$uname:$udom$/,@domcoord)) {
1695: push(@domcoord,$uname.':'.$udom);
1696: }
1697: }
1698: }
1699: if (ref($settings) eq 'HASH') {
1700: if (ref($settings->{'notify'}) eq 'HASH') {
1701: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1702: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1703: }
1704: }
1705: }
1.104 raeburn 1706: if (@currapproval) {
1707: foreach my $dc (@currapproval) {
1.102 raeburn 1708: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1709: push(@domcoord,$dc);
1710: }
1711: }
1712: }
1713: @domcoord = sort(@domcoord);
1714: my $numinrow = 4;
1715: my $numdc = @domcoord;
1716: my $css_class = 'class="LC_odd_row"';
1717: $datatable = '<tr'.$css_class.'>'.
1718: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1719: ' </td>'.
1720: ' <td class="LC_left_item">';
1721: if (@domcoord > 0) {
1722: $datatable .= '<table>';
1723: for (my $i=0; $i<$numdc; $i++) {
1724: my $rem = $i%($numinrow);
1725: if ($rem == 0) {
1726: if ($i > 0) {
1727: $datatable .= '</tr>';
1728: }
1729: $datatable .= '<tr>';
1730: $rows ++;
1731: }
1732: my $check = ' ';
1.104 raeburn 1733: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1734: $check = ' checked="checked" ';
1735: }
1736: my ($uname,$udom) = split(':',$domcoord[$i]);
1737: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1738: if ($i == $numdc-1) {
1739: my $colsleft = $numinrow-$rem;
1740: if ($colsleft > 1) {
1741: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1742: } else {
1743: $datatable .= '<td class="LC_left_item">';
1744: }
1745: } else {
1746: $datatable .= '<td class="LC_left_item">';
1747: }
1748: $datatable .= '<span class="LC_nobreak"><label>'.
1749: '<input type="checkbox" name="reqapprovalnotify" '.
1750: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1751: $fullname.'</label></span></td>';
1752: }
1753: $datatable .= '</tr></table>';
1754: } else {
1755: $datatable .= &mt('There are no active Domain Coordinators');
1756: $rows ++;
1757: }
1758: $datatable .='</td></tr>';
1759: $$rowtotal += $rows;
1760: return $datatable;
1761: }
1762:
1.3 raeburn 1763: sub print_autoenroll {
1.30 raeburn 1764: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1765: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1766: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1767: if (ref($settings) eq 'HASH') {
1768: if (exists($settings->{'run'})) {
1769: if ($settings->{'run'} eq '0') {
1770: $runoff = ' checked="checked" ';
1771: $runon = ' ';
1772: } else {
1773: $runon = ' checked="checked" ';
1774: $runoff = ' ';
1775: }
1776: } else {
1777: if ($autorun) {
1778: $runon = ' checked="checked" ';
1779: $runoff = ' ';
1780: } else {
1781: $runoff = ' checked="checked" ';
1782: $runon = ' ';
1783: }
1784: }
1.129 raeburn 1785: if (exists($settings->{'co-owners'})) {
1786: if ($settings->{'co-owners'} eq '0') {
1787: $coownersoff = ' checked="checked" ';
1788: $coownerson = ' ';
1789: } else {
1790: $coownerson = ' checked="checked" ';
1791: $coownersoff = ' ';
1792: }
1793: } else {
1794: $coownersoff = ' checked="checked" ';
1795: $coownerson = ' ';
1796: }
1.3 raeburn 1797: if (exists($settings->{'sender_domain'})) {
1798: $defdom = $settings->{'sender_domain'};
1799: }
1.14 raeburn 1800: } else {
1801: if ($autorun) {
1802: $runon = ' checked="checked" ';
1803: $runoff = ' ';
1804: } else {
1805: $runoff = ' checked="checked" ';
1806: $runon = ' ';
1807: }
1.3 raeburn 1808: }
1809: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1810: my $notif_sender;
1811: if (ref($settings) eq 'HASH') {
1812: $notif_sender = $settings->{'sender_uname'};
1813: }
1.3 raeburn 1814: my $datatable='<tr class="LC_odd_row">'.
1815: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1816: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1817: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1818: $runon.' value="1" />'.&mt('Yes').'</label> '.
1819: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1820: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1821: '</tr><tr>'.
1822: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1823: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1824: &mt('username').': '.
1825: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1826: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1827: ': '.$domform.'</span></td></tr>'.
1828: '<tr class="LC_odd_row">'.
1829: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1830: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1831: '<input type="radio" name="autoassign_coowners"'.
1832: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1833: '<label><input type="radio" name="autoassign_coowners"'.
1834: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1835: '</tr>';
1836: $$rowtotal += 3;
1.3 raeburn 1837: return $datatable;
1838: }
1839:
1840: sub print_autoupdate {
1.30 raeburn 1841: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1842: my $datatable;
1843: if ($position eq 'top') {
1844: my $updateon = ' ';
1845: my $updateoff = ' checked="checked" ';
1846: my $classlistson = ' ';
1847: my $classlistsoff = ' checked="checked" ';
1848: if (ref($settings) eq 'HASH') {
1849: if ($settings->{'run'} eq '1') {
1850: $updateon = $updateoff;
1851: $updateoff = ' ';
1852: }
1853: if ($settings->{'classlists'} eq '1') {
1854: $classlistson = $classlistsoff;
1855: $classlistsoff = ' ';
1856: }
1857: }
1858: my %title = (
1859: run => 'Auto-update active?',
1860: classlists => 'Update information in classlists?',
1861: );
1862: $datatable = '<tr class="LC_odd_row">'.
1863: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1864: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1865: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1866: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1867: '<label><input type="radio" name="autoupdate_run"'.
1868: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1869: '</tr><tr>'.
1870: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1871: '<td class="LC_right_item"><span class="LC_nobreak">'.
1872: '<label><input type="radio" name="classlists"'.
1873: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1874: '<label><input type="radio" name="classlists"'.
1875: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1876: '</tr>';
1.30 raeburn 1877: $$rowtotal += 2;
1.131 raeburn 1878: } elsif ($position eq 'middle') {
1879: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1880: my $numinrow = 3;
1881: my $locknamesettings;
1882: $datatable .= &insttypes_row($settings,$types,$usertypes,
1883: $dom,$numinrow,$othertitle,
1884: 'lockablenames');
1885: $$rowtotal ++;
1.3 raeburn 1886: } else {
1.44 raeburn 1887: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1888: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1889: 'permanentemail','id');
1.33 raeburn 1890: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1891: my $numrows = 0;
1.26 raeburn 1892: if (ref($types) eq 'ARRAY') {
1893: if (@{$types} > 0) {
1894: $datatable =
1895: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1896: \@fields,$types,\$numrows);
1.30 raeburn 1897: $$rowtotal += @{$types};
1.26 raeburn 1898: }
1.3 raeburn 1899: }
1900: $datatable .=
1901: &usertype_update_row($settings,{'default' => $othertitle},
1902: \%fieldtitles,\@fields,['default'],
1903: \$numrows);
1.30 raeburn 1904: $$rowtotal ++;
1.3 raeburn 1905: }
1906: return $datatable;
1907: }
1908:
1.125 raeburn 1909: sub print_autocreate {
1910: my ($dom,$settings,$rowtotal) = @_;
1911: my (%createon,%createoff);
1912: my $curr_dc;
1913: my @types = ('xml','req');
1914: if (ref($settings) eq 'HASH') {
1915: foreach my $item (@types) {
1916: $createoff{$item} = ' checked="checked" ';
1917: $createon{$item} = ' ';
1918: if (exists($settings->{$item})) {
1919: if ($settings->{$item}) {
1920: $createon{$item} = ' checked="checked" ';
1921: $createoff{$item} = ' ';
1922: }
1923: }
1924: }
1925: $curr_dc = $settings->{'xmldc'};
1926: } else {
1927: foreach my $item (@types) {
1928: $createoff{$item} = ' checked="checked" ';
1929: $createon{$item} = ' ';
1930: }
1931: }
1932: $$rowtotal += 2;
1933: my $datatable='<tr class="LC_odd_row">'.
1934: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1935: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1936: '<input type="radio" name="autocreate_xml"'.
1937: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1938: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 1939: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
1940: '</td></tr><tr>'.
1941: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1942: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1943: '<input type="radio" name="autocreate_req"'.
1944: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1945: '<label><input type="radio" name="autocreate_req"'.
1946: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 1947: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1948: if ($numdc > 1) {
1.143 raeburn 1949: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
1950: &mt('Course creation processed as: (choose Dom. Coord.)').
1951: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 1952: $$rowtotal ++ ;
1953: } else {
1.143 raeburn 1954: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 1955: }
1956: return $datatable;
1957: }
1958:
1.23 raeburn 1959: sub print_directorysrch {
1.30 raeburn 1960: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1961: my $srchon = ' ';
1962: my $srchoff = ' checked="checked" ';
1.25 raeburn 1963: my ($exacton,$containson,$beginson);
1.24 raeburn 1964: my $localon = ' ';
1965: my $localoff = ' checked="checked" ';
1.23 raeburn 1966: if (ref($settings) eq 'HASH') {
1967: if ($settings->{'available'} eq '1') {
1968: $srchon = $srchoff;
1969: $srchoff = ' ';
1970: }
1.24 raeburn 1971: if ($settings->{'localonly'} eq '1') {
1972: $localon = $localoff;
1973: $localoff = ' ';
1974: }
1.25 raeburn 1975: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1976: foreach my $type (@{$settings->{'searchtypes'}}) {
1977: if ($type eq 'exact') {
1978: $exacton = ' checked="checked" ';
1979: } elsif ($type eq 'contains') {
1980: $containson = ' checked="checked" ';
1981: } elsif ($type eq 'begins') {
1982: $beginson = ' checked="checked" ';
1983: }
1984: }
1985: } else {
1986: if ($settings->{'searchtypes'} eq 'exact') {
1987: $exacton = ' checked="checked" ';
1988: } elsif ($settings->{'searchtypes'} eq 'contains') {
1989: $containson = ' checked="checked" ';
1990: } elsif ($settings->{'searchtypes'} eq 'specify') {
1991: $exacton = ' checked="checked" ';
1992: $containson = ' checked="checked" ';
1993: }
1.23 raeburn 1994: }
1995: }
1996: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1997: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1998:
1999: my $numinrow = 4;
1.26 raeburn 2000: my $cansrchrow = 0;
1.23 raeburn 2001: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2002: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2003: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2004: '<input type="radio" name="dirsrch_available"'.
2005: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2006: '<label><input type="radio" name="dirsrch_available"'.
2007: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2008: '</tr><tr>'.
1.30 raeburn 2009: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2010: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2011: '<input type="radio" name="dirsrch_localonly"'.
2012: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2013: '<label><input type="radio" name="dirsrch_localonly"'.
2014: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2015: '</tr>';
1.30 raeburn 2016: $$rowtotal += 2;
1.26 raeburn 2017: if (ref($usertypes) eq 'HASH') {
2018: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2019: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2020: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2021: $cansrchrow = 1;
2022: }
2023: }
2024: if ($cansrchrow) {
1.30 raeburn 2025: $$rowtotal ++;
1.26 raeburn 2026: $datatable .= '<tr>';
2027: } else {
2028: $datatable .= '<tr class="LC_odd_row">';
2029: }
1.30 raeburn 2030: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2031: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2032: foreach my $title (@{$titleorder}) {
2033: if (defined($searchtitles->{$title})) {
2034: my $check = ' ';
1.93 raeburn 2035: if (ref($settings) eq 'HASH') {
1.39 raeburn 2036: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2037: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2038: $check = ' checked="checked" ';
2039: }
1.25 raeburn 2040: }
2041: }
2042: $datatable .= '<td class="LC_left_item">'.
2043: '<span class="LC_nobreak"><label>'.
2044: '<input type="checkbox" name="searchby" '.
2045: 'value="'.$title.'"'.$check.'/>'.
2046: $searchtitles->{$title}.'</label></span></td>';
2047: }
2048: }
1.26 raeburn 2049: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2050: $$rowtotal ++;
1.26 raeburn 2051: if ($cansrchrow) {
2052: $datatable .= '<tr class="LC_odd_row">';
2053: } else {
2054: $datatable .= '<tr>';
2055: }
1.30 raeburn 2056: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2057: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2058: '<span class="LC_nobreak"><label>'.
2059: '<input type="checkbox" name="searchtypes" '.
2060: $exacton.' value="exact" />'.&mt('Exact match').
2061: '</label> '.
2062: '<label><input type="checkbox" name="searchtypes" '.
2063: $beginson.' value="begins" />'.&mt('Begins with').
2064: '</label> '.
2065: '<label><input type="checkbox" name="searchtypes" '.
2066: $containson.' value="contains" />'.&mt('Contains').
2067: '</label></span></td></tr>';
1.30 raeburn 2068: $$rowtotal ++;
1.25 raeburn 2069: return $datatable;
2070: }
2071:
1.28 raeburn 2072: sub print_contacts {
1.30 raeburn 2073: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2074: my $datatable;
2075: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2076: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2077: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2078: 'requestsmail');
1.28 raeburn 2079: foreach my $type (@mailings) {
2080: $otheremails{$type} = '';
2081: }
1.134 raeburn 2082: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2083: if (ref($settings) eq 'HASH') {
2084: foreach my $item (@contacts) {
2085: if (exists($settings->{$item})) {
2086: $to{$item} = $settings->{$item};
2087: }
2088: }
2089: foreach my $type (@mailings) {
2090: if (exists($settings->{$type})) {
2091: if (ref($settings->{$type}) eq 'HASH') {
2092: foreach my $item (@contacts) {
2093: if ($settings->{$type}{$item}) {
2094: $checked{$type}{$item} = ' checked="checked" ';
2095: }
2096: }
2097: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2098: if ($type eq 'helpdeskmail') {
2099: $bccemails{$type} = $settings->{$type}{'bcc'};
2100: }
1.28 raeburn 2101: }
1.89 raeburn 2102: } elsif ($type eq 'lonstatusmail') {
2103: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2104: }
2105: }
2106: } else {
2107: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2108: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2109: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2110: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2111: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2112: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2113: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2114: }
2115: my ($titles,$short_titles) = &contact_titles();
2116: my $rownum = 0;
2117: my $css_class;
2118: foreach my $item (@contacts) {
1.69 raeburn 2119: $rownum ++;
2120: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2121: $datatable .= '<tr'.$css_class.'>'.
2122: '<td><span class="LC_nobreak">'.$titles->{$item}.
2123: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2124: '<input type="text" name="'.$item.'" value="'.
2125: $to{$item}.'" /></td></tr>';
2126: }
2127: foreach my $type (@mailings) {
1.69 raeburn 2128: $rownum ++;
2129: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2130: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2131: '<td><span class="LC_nobreak">'.
2132: $titles->{$type}.': </span></td>'.
1.28 raeburn 2133: '<td class="LC_left_item">'.
2134: '<span class="LC_nobreak">';
2135: foreach my $item (@contacts) {
2136: $datatable .= '<label>'.
2137: '<input type="checkbox" name="'.$type.'"'.
2138: $checked{$type}{$item}.
2139: ' value="'.$item.'" />'.$short_titles->{$item}.
2140: '</label> ';
2141: }
2142: $datatable .= '</span><br />'.&mt('Others').': '.
2143: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2144: 'value="'.$otheremails{$type}.'" />';
2145: if ($type eq 'helpdeskmail') {
1.136 raeburn 2146: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2147: '<input type="text" name="'.$type.'_bcc" '.
2148: 'value="'.$bccemails{$type}.'" />';
2149: }
2150: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2151: }
1.30 raeburn 2152: $$rowtotal += $rownum;
1.28 raeburn 2153: return $datatable;
2154: }
2155:
1.118 jms 2156: sub print_helpsettings {
1.122 jms 2157:
2158: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2159: my ($css_class,$datatable);
2160:
2161: my $switchserver = &check_switchserver($dom,$confname);
2162:
2163: my $itemcount = 1;
2164:
2165: if ($position eq 'top') {
2166:
2167: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2168:
2169: %choices =
2170: &Apache::lonlocal::texthash (
2171: submitbugs => 'Display "Submit a bug" link?',
2172: );
2173:
2174: %defaultchecked = ('submitbugs' => 'on');
2175:
2176: @toggles = ('submitbugs',);
2177:
2178: foreach my $item (@toggles) {
2179: if ($defaultchecked{$item} eq 'on') {
2180: $checkedon{$item} = ' checked="checked" ';
2181: $checkedoff{$item} = ' ';
2182: } elsif ($defaultchecked{$item} eq 'off') {
2183: $checkedoff{$item} = ' checked="checked" ';
2184: $checkedon{$item} = ' ';
2185: }
2186: }
2187:
2188: if (ref($settings) eq 'HASH') {
2189: foreach my $item (@toggles) {
2190: if ($settings->{$item} eq '1') {
2191: $checkedon{$item} = ' checked="checked" ';
2192: $checkedoff{$item} = ' ';
2193: } elsif ($settings->{$item} eq '0') {
2194: $checkedoff{$item} = ' checked="checked" ';
2195: $checkedon{$item} = ' ';
2196: }
2197: }
2198: }
2199:
2200: foreach my $item (@toggles) {
2201: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2202: $datatable .=
2203: '<tr'.$css_class.'>
2204: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2205: <td><span class="LC_nobreak"> </span></td>
2206: <td class="LC_right_item"><span class="LC_nobreak">
2207: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2208: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2209: '</span></td>'.
2210: '</tr>';
2211: $itemcount ++;
2212: }
2213:
2214: } else {
2215:
2216: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2217:
2218: $datatable .= '<tr'.$css_class.'>';
2219:
2220: if (ref($settings) eq 'HASH') {
2221: if ($settings->{'loginhelpurl'} ne '') {
2222: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2223: $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>';
2224: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2225: } else {
2226: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2227: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2228: }
2229: } else {
2230: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2231: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2232: }
2233:
2234: $datatable .= '<td width="33%"><span class="LC_right_item">';
2235: if ($switchserver) {
2236: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2237: } else {
2238: $datatable .= &mt('Upload Custom Login Page Help File:');
2239: $datatable .='<input type="file" name="loginhelpurl" />';
2240: }
2241: $datatable .= '</span></td></tr>';
2242:
2243: }
2244:
2245: return $datatable;
2246:
1.121 raeburn 2247: }
2248:
1.122 jms 2249:
1.121 raeburn 2250: sub radiobutton_prefs {
2251: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2252: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2253: (ref($choices) eq 'HASH'));
2254:
2255: my (%checkedon,%checkedoff,$datatable,$css_class);
2256:
2257: foreach my $item (@{$toggles}) {
2258: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2259: $checkedon{$item} = ' checked="checked" ';
2260: $checkedoff{$item} = ' ';
1.121 raeburn 2261: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2262: $checkedoff{$item} = ' checked="checked" ';
2263: $checkedon{$item} = ' ';
2264: }
2265: }
2266: if (ref($settings) eq 'HASH') {
1.121 raeburn 2267: foreach my $item (@{$toggles}) {
1.118 jms 2268: if ($settings->{$item} eq '1') {
2269: $checkedon{$item} = ' checked="checked" ';
2270: $checkedoff{$item} = ' ';
2271: } elsif ($settings->{$item} eq '0') {
2272: $checkedoff{$item} = ' checked="checked" ';
2273: $checkedon{$item} = ' ';
2274: }
2275: }
1.121 raeburn 2276: }
2277: foreach my $item (@{$toggles}) {
1.118 jms 2278: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2279: $datatable .=
2280: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2281: '</span></td>'.
2282: '<td class="LC_right_item"><span class="LC_nobreak">'.
2283: '<label><input type="radio" name="'.
2284: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2285: '</label> <label><input type="radio" name="'.$item.'" '.
2286: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2287: '</span></td>'.
2288: '</tr>';
2289: $itemcount ++;
1.121 raeburn 2290: }
2291: return ($datatable,$itemcount);
2292: }
2293:
2294: sub print_coursedefaults {
1.139 raeburn 2295: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2296: my ($css_class,$datatable);
2297: my $itemcount = 1;
1.139 raeburn 2298: if ($position eq 'top') {
2299: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2300: %choices =
2301: &Apache::lonlocal::texthash (
2302: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2303: );
2304: %defaultchecked = ('canuse_pdfforms' => 'off');
2305: @toggles = ('canuse_pdfforms',);
2306: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2307: \%choices,$itemcount);
1.139 raeburn 2308: $$rowtotal += $itemcount;
2309: } else {
2310: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2311: my %choices =
2312: &Apache::lonlocal::texthash (
2313: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2314: );
2315: my $currdefresponder;
2316: if (ref($settings) eq 'HASH') {
2317: $currdefresponder = $settings->{'anonsurvey_threshold'};
2318: }
2319: if (!$currdefresponder) {
2320: $currdefresponder = 10;
2321: } elsif ($currdefresponder < 1) {
2322: $currdefresponder = 1;
2323: }
2324: $datatable .=
2325: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2326: '</span></td>'.
2327: '<td class="LC_right_item"><span class="LC_nobreak">'.
2328: '<input type="text" name="anonsurvey_threshold"'.
2329: ' value="'.$currdefresponder.'" size="5" /></span>'.
2330: '</td></tr>';
2331: }
1.121 raeburn 2332: return $datatable;
1.118 jms 2333: }
2334:
1.137 raeburn 2335: sub print_usersessions {
2336: my ($position,$dom,$settings,$rowtotal) = @_;
2337: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2338: my (%by_ip,%by_location,@intdoms);
2339: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2340:
2341: my @alldoms = &Apache::lonnet::all_domains();
1.152 ! raeburn 2342: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2343: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 ! raeburn 2344: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2345: my $itemcount = 1;
2346: if ($position eq 'top') {
1.152 ! raeburn 2347: if (keys(%serverhomes) > 1) {
1.145 raeburn 2348: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 ! raeburn 2349: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2350: } else {
1.140 raeburn 2351: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2352: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2353: }
1.137 raeburn 2354: } else {
1.145 raeburn 2355: if (keys(%by_location) == 0) {
2356: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2357: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2358: } else {
2359: my %lt = &usersession_titles();
2360: my $numinrow = 5;
2361: my $prefix;
2362: my @types;
2363: if ($position eq 'bottom') {
2364: $prefix = 'remote';
2365: @types = ('version','excludedomain','includedomain');
2366: } else {
2367: $prefix = 'hosted';
2368: @types = ('excludedomain','includedomain');
2369: }
2370: my (%current,%checkedon,%checkedoff);
2371: my @lcversions = &Apache::lonnet::all_loncaparevs();
2372: my @locations = sort(keys(%by_location));
2373: foreach my $type (@types) {
2374: $checkedon{$type} = '';
2375: $checkedoff{$type} = ' checked="checked"';
2376: }
2377: if (ref($settings) eq 'HASH') {
2378: if (ref($settings->{$prefix}) eq 'HASH') {
2379: foreach my $key (keys(%{$settings->{$prefix}})) {
2380: $current{$key} = $settings->{$prefix}{$key};
2381: if ($key eq 'version') {
2382: if ($current{$key} ne '') {
2383: $checkedon{$key} = ' checked="checked"';
2384: $checkedoff{$key} = '';
2385: }
2386: } elsif (ref($current{$key}) eq 'ARRAY') {
2387: $checkedon{$key} = ' checked="checked"';
2388: $checkedoff{$key} = '';
2389: }
1.137 raeburn 2390: }
2391: }
2392: }
1.145 raeburn 2393: foreach my $type (@types) {
2394: next if ($type ne 'version' && !@locations);
2395: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2396: $datatable .= '<tr'.$css_class.'>
2397: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2398: <span class="LC_nobreak">
2399: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2400: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2401: if ($type eq 'version') {
2402: my $selector = '<select name="'.$prefix.'_version">';
2403: foreach my $version (@lcversions) {
2404: my $selected = '';
2405: if ($current{'version'} eq $version) {
2406: $selected = ' selected="selected"';
2407: }
2408: $selector .= ' <option value="'.$version.'"'.
2409: $selected.'>'.$version.'</option>';
2410: }
2411: $selector .= '</select> ';
2412: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2413: } else {
2414: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2415: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2416: ' />'.(' 'x2).
2417: '<input type="button" value="'.&mt('uncheck all').'" '.
2418: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2419: "\n".
2420: '</div><div><table>';
2421: my $rem;
2422: for (my $i=0; $i<@locations; $i++) {
2423: my ($showloc,$value,$checkedtype);
2424: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2425: my $ip = $by_location{$locations[$i]}->[0];
2426: if (ref($by_ip{$ip}) eq 'ARRAY') {
2427: $value = join(':',@{$by_ip{$ip}});
2428: $showloc = join(', ',@{$by_ip{$ip}});
2429: if (ref($current{$type}) eq 'ARRAY') {
2430: foreach my $loc (@{$by_ip{$ip}}) {
2431: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2432: $checkedtype = ' checked="checked"';
2433: last;
2434: }
2435: }
1.138 raeburn 2436: }
2437: }
2438: }
1.145 raeburn 2439: $rem = $i%($numinrow);
2440: if ($rem == 0) {
2441: if ($i > 0) {
2442: $datatable .= '</tr>';
2443: }
2444: $datatable .= '<tr>';
2445: }
2446: $datatable .= '<td class="LC_left_item">'.
2447: '<span class="LC_nobreak"><label>'.
2448: '<input type="checkbox" name="'.$prefix.'_'.$type.
2449: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2450: '</label></span></td>';
1.137 raeburn 2451: }
1.145 raeburn 2452: $rem = @locations%($numinrow);
2453: my $colsleft = $numinrow - $rem;
2454: if ($colsleft > 1 ) {
2455: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2456: ' </td>';
2457: } elsif ($colsleft == 1) {
2458: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2459: }
1.145 raeburn 2460: $datatable .= '</tr></table>';
1.137 raeburn 2461: }
1.145 raeburn 2462: $datatable .= '</td></tr>';
2463: $itemcount ++;
1.137 raeburn 2464: }
2465: }
2466: }
2467: $$rowtotal += $itemcount;
2468: return $datatable;
2469: }
2470:
1.138 raeburn 2471: sub build_location_hashes {
2472: my ($intdoms,$by_ip,$by_location) = @_;
2473: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2474: (ref($by_location) eq 'HASH'));
2475: my %iphost = &Apache::lonnet::get_iphost();
2476: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2477: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2478: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2479: foreach my $id (@{$iphost{$primary_ip}}) {
2480: my $intdom = &Apache::lonnet::internet_dom($id);
2481: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2482: push(@{$intdoms},$intdom);
2483: }
2484: }
2485: }
2486: foreach my $ip (keys(%iphost)) {
2487: if (ref($iphost{$ip}) eq 'ARRAY') {
2488: foreach my $id (@{$iphost{$ip}}) {
2489: my $location = &Apache::lonnet::internet_dom($id);
2490: if ($location) {
2491: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2492: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2493: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2494: push(@{$by_ip->{$ip}},$location);
2495: }
2496: } else {
2497: $by_ip->{$ip} = [$location];
2498: }
2499: }
2500: }
2501: }
2502: }
2503: foreach my $ip (sort(keys(%{$by_ip}))) {
2504: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2505: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2506: my $first = $by_ip->{$ip}->[0];
2507: if (ref($by_location->{$first}) eq 'ARRAY') {
2508: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2509: push(@{$by_location->{$first}},$ip);
2510: }
2511: } else {
2512: $by_location->{$first} = [$ip];
2513: }
2514: }
2515: }
2516: return;
2517: }
2518:
1.145 raeburn 2519: sub current_offloads_to {
2520: my ($dom,$settings,$servers) = @_;
2521: my (%spareid,%otherdomconfigs);
1.152 ! raeburn 2522: if (ref($servers) eq 'HASH') {
1.145 raeburn 2523: foreach my $lonhost (sort(keys(%{$servers}))) {
2524: my $gotspares;
1.152 ! raeburn 2525: if (ref($settings) eq 'HASH') {
! 2526: if (ref($settings->{'spares'}) eq 'HASH') {
! 2527: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
! 2528: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
! 2529: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
! 2530: $gotspares = 1;
! 2531: }
1.145 raeburn 2532: }
2533: }
2534: unless ($gotspares) {
2535: my $gotspares;
2536: my $serverhomeID =
2537: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2538: my $serverhomedom =
2539: &Apache::lonnet::host_domain($serverhomeID);
2540: if ($serverhomedom ne $dom) {
2541: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2542: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2543: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2544: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2545: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2546: $gotspares = 1;
2547: }
2548: }
2549: } else {
2550: $otherdomconfigs{$serverhomedom} =
2551: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2552: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2553: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2554: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2555: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2556: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2557: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2558: $gotspares = 1;
2559: }
2560: }
2561: }
2562: }
2563: }
2564: }
2565: }
2566: unless ($gotspares) {
2567: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2568: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2569: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2570: } else {
2571: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2572: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2573: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2574: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2575: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2576: } else {
1.150 raeburn 2577: my %what = (
2578: spareid => 1,
2579: );
2580: my ($result,$returnhash) =
2581: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2582: if ($result eq 'ok') {
2583: if (ref($returnhash) eq 'HASH') {
2584: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2585: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2586: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2587: }
2588: }
1.145 raeburn 2589: }
2590: }
2591: }
2592: }
2593: }
2594: }
2595: return %spareid;
2596: }
2597:
2598: sub spares_row {
1.152 ! raeburn 2599: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2600: my $css_class;
2601: my $numinrow = 4;
2602: my $itemcount = 1;
2603: my $datatable;
1.152 ! raeburn 2604: my %typetitles = &sparestype_titles();
! 2605: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2606: foreach my $server (sort(keys(%{$servers}))) {
1.152 ! raeburn 2607: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
! 2608: my ($othercontrol,$serverdom);
! 2609: if ($serverhome ne $server) {
! 2610: $serverdom = &Apache::lonnet::host_domain($serverhome);
! 2611: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
! 2612: } else {
! 2613: $serverdom = &Apache::lonnet::host_domain($server);
! 2614: if ($serverdom ne $dom) {
! 2615: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
! 2616: }
! 2617: }
! 2618: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2619: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2620: $datatable .= '<tr'.$css_class.'>
2621: <td rowspan="2">
1.152 ! raeburn 2622: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2623: my (%current,%canselect);
1.152 ! raeburn 2624: my @choices =
! 2625: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
! 2626: foreach my $type ('primary','default') {
! 2627: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2628: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2629: my @spares = @{$spareid->{$server}{$type}};
2630: if (@spares > 0) {
1.152 ! raeburn 2631: if ($othercontrol) {
! 2632: $current{$type} = join(', ',@spares);
! 2633: } else {
! 2634: $current{$type} .= '<table>';
! 2635: my $numspares = scalar(@spares);
! 2636: for (my $i=0; $i<@spares; $i++) {
! 2637: my $rem = $i%($numinrow);
! 2638: if ($rem == 0) {
! 2639: if ($i > 0) {
! 2640: $current{$type} .= '</tr>';
! 2641: }
! 2642: $current{$type} .= '<tr>';
1.145 raeburn 2643: }
1.152 ! raeburn 2644: $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'".');" /> '.
! 2645: $spareid->{$server}{$type}[$i].
! 2646: '</label></td>'."\n";
! 2647: }
! 2648: my $rem = @spares%($numinrow);
! 2649: my $colsleft = $numinrow - $rem;
! 2650: if ($colsleft > 1 ) {
! 2651: $current{$type} .= '<td colspan="'.$colsleft.
! 2652: '" class="LC_left_item">'.
! 2653: ' </td>';
! 2654: } elsif ($colsleft == 1) {
! 2655: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2656: }
1.152 ! raeburn 2657: $current{$type} .= '</tr></table>';
1.150 raeburn 2658: }
1.145 raeburn 2659: }
2660: }
2661: if ($current{$type} eq '') {
2662: $current{$type} = &mt('None specified');
2663: }
1.152 ! raeburn 2664: if ($othercontrol) {
! 2665: if ($type eq 'primary') {
! 2666: $canselect{$type} = $othercontrol;
! 2667: }
! 2668: } else {
! 2669: $canselect{$type} =
! 2670: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
! 2671: '<select name="newspare_'.$type.'_'.$server.'" '.
! 2672: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
! 2673: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
! 2674: if (@choices > 0) {
! 2675: foreach my $lonhost (@choices) {
! 2676: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
! 2677: }
! 2678: }
! 2679: $canselect{$type} .= '</select>'."\n";
! 2680: }
! 2681: } else {
! 2682: $current{$type} = &mt('Could not be determined');
! 2683: if ($type eq 'primary') {
! 2684: $canselect{$type} = $othercontrol;
! 2685: }
1.145 raeburn 2686: }
1.152 ! raeburn 2687: if ($type eq 'default') {
! 2688: $datatable .= '<tr'.$css_class.'>';
! 2689: }
! 2690: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
! 2691: '<td>'.$current{$type}.'</td>'."\n".
! 2692: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2693: }
2694: $itemcount ++;
2695: }
2696: }
2697: $$rowtotal += $itemcount;
2698: return $datatable;
2699: }
2700:
1.152 ! raeburn 2701: sub possible_newspares {
! 2702: my ($server,$currspares,$serverhomes,$altids) = @_;
! 2703: my $serverhostname = &Apache::lonnet::hostname($server);
! 2704: my %excluded;
! 2705: if ($serverhostname ne '') {
! 2706: %excluded = (
! 2707: $serverhostname => 1,
! 2708: );
! 2709: }
! 2710: if (ref($currspares) eq 'HASH') {
! 2711: foreach my $type (keys(%{$currspares})) {
! 2712: if (ref($currspares->{$type}) eq 'ARRAY') {
! 2713: if (@{$currspares->{$type}} > 0) {
! 2714: foreach my $curr (@{$currspares->{$type}}) {
! 2715: my $hostname = &Apache::lonnet::hostname($curr);
! 2716: $excluded{$hostname} = 1;
! 2717: }
! 2718: }
! 2719: }
! 2720: }
! 2721: }
! 2722: my @choices;
! 2723: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
! 2724: if (keys(%{$serverhomes}) > 1) {
! 2725: foreach my $name (sort(keys(%{$serverhomes}))) {
! 2726: unless ($excluded{$name}) {
! 2727: if (exists($altids->{$serverhomes->{$name}})) {
! 2728: push(@choices,$altids->{$serverhomes->{$name}});
! 2729: } else {
! 2730: push(@choices,$serverhomes->{$name});
1.145 raeburn 2731: }
2732: }
2733: }
2734: }
2735: }
1.152 ! raeburn 2736: return sort(@choices);
1.145 raeburn 2737: }
2738:
1.150 raeburn 2739: sub print_loadbalancing {
2740: my ($dom,$settings,$rowtotal) = @_;
2741: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2742: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2743: my $numinrow = 1;
2744: my $datatable;
2745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
2746: my ($currbalancer,$currtargets,$currrules);
2747: if (keys(%servers) > 1) {
2748: if (ref($settings) eq 'HASH') {
2749: $currbalancer = $settings->{'lonhost'};
2750: $currtargets = $settings->{'targets'};
2751: $currrules = $settings->{'rules'};
2752: } else {
2753: ($currbalancer,$currtargets) =
2754: &Apache::lonnet::get_lonbalancer_config(\%servers);
2755: }
2756: } else {
2757: return;
2758: }
2759: my ($othertitle,$usertypes,$types) =
2760: &Apache::loncommon::sorted_inst_types($dom);
2761: my $rownum = 6;
2762: if (ref($types) eq 'ARRAY') {
2763: $rownum += scalar(@{$types});
2764: }
2765: my $css_class = 'class="LC_odd_row"';
2766: my $targets_div_style = 'display: none';
2767: my $disabled_div_style = 'display: block';
2768: my $homedom_div_style = 'display: none';
2769: $datatable = '<tr'.$css_class.'>'.
2770: '<td rowspan="'.$rownum.'" valign="top">'.
2771: '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
2772: '<option value=""';
2773: if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
2774: $datatable .= ' selected="selected"';
2775: } else {
2776: $targets_div_style = 'display: block';
2777: $disabled_div_style = 'display: none';
2778: if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
2779: $homedom_div_style = 'display: block';
2780: }
2781: }
2782: $datatable .= '>'.&mt('None').'</option>'."\n";
2783: foreach my $lonhost (sort(keys(%servers))) {
2784: my $selected;
2785: if ($lonhost eq $currbalancer) {
2786: $selected .= ' selected="selected"';
2787: }
2788: $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
2789: }
2790: $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
2791: '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
2792: '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2793: my ($numspares,@spares) = &count_servers($currbalancer,%servers);
2794: my @sparestypes = ('primary','default');
2795: my %typetitles = &sparestype_titles();
2796: foreach my $sparetype (@sparestypes) {
2797: my $targettable;
2798: for (my $i=0; $i<$numspares; $i++) {
2799: my $checked;
2800: if (ref($currtargets) eq 'HASH') {
2801: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
2802: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
2803: $checked = ' checked="checked"';
2804: }
2805: }
2806: }
2807: my $chkboxval;
2808: if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
2809: $chkboxval = $spares[$i];
2810: }
2811: $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
2812: $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2813: '</span></label></td>';
2814: my $rem = $i%($numinrow);
2815: if ($rem == 0) {
2816: if ($i > 0) {
2817: $targettable .= '</tr>';
2818: }
2819: $targettable .= '<tr>';
2820: }
2821: }
2822: if ($targettable ne '') {
2823: my $rem = $numspares%($numinrow);
2824: my $colsleft = $numinrow - $rem;
2825: if ($colsleft > 1 ) {
2826: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2827: ' </td>';
2828: } elsif ($colsleft == 1) {
2829: $targettable .= '<td class="LC_left_item"> </td>';
2830: }
2831: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
2832: '<table><tr>'.$targettable.'</table><br />';
2833: }
2834: }
2835: $datatable .= '</div></td></tr>'.
2836: &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
2837: $usertypes,$types,\%servers,$currbalancer,
2838: $targets_div_style,$homedom_div_style);
2839: $$rowtotal += $rownum;
2840: return $datatable;
2841: }
2842:
2843: sub loadbalancing_rules {
2844: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
2845: $currbalancer,$targets_div_style,$homedom_div_style) = @_;
2846: my $output;
2847: my ($alltypes,$othertypes,$titles) =
2848: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
2849: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
2850: foreach my $type (@{$alltypes}) {
2851: my $current;
2852: if (ref($currrules) eq 'HASH') {
2853: $current = $currrules->{$type};
2854: }
2855: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2856: if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
2857: $current = '';
2858: }
2859: }
2860: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
2861: $servers,$currbalancer,$dom,
2862: $targets_div_style,$homedom_div_style);
2863: }
2864: }
2865: return $output;
2866: }
2867:
2868: sub loadbalancing_titles {
2869: my ($dom,$intdom,$usertypes,$types) = @_;
2870: my %othertypes = (
2871: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
2872: '_LC_author' => &mt('Users from [_1] with author role',$dom),
2873: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
2874: '_LC_external' => &mt('Users not from [_1]',$intdom),
2875: );
2876: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
2877: if (ref($types) eq 'ARRAY') {
2878: unshift(@alltypes,@{$types},'default');
2879: }
2880: my %titles;
2881: foreach my $type (@alltypes) {
2882: if ($type =~ /^_LC_/) {
2883: $titles{$type} = $othertypes{$type};
2884: } elsif ($type eq 'default') {
2885: $titles{$type} = &mt('All users from [_1]',$dom);
2886: if (ref($types) eq 'ARRAY') {
2887: if (@{$types} > 0) {
2888: $titles{$type} = &mt('Other users from [_1]',$dom);
2889: }
2890: }
2891: } elsif (ref($usertypes) eq 'HASH') {
2892: $titles{$type} = $usertypes->{$type};
2893: }
2894: }
2895: return (\@alltypes,\%othertypes,\%titles);
2896: }
2897:
2898: sub loadbalance_rule_row {
2899: my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
2900: $homedom_div_style) = @_;
2901: my @rulenames = ('default','homeserver');
2902: my %ruletitles = &offloadtype_text();
2903: if ($type eq '_LC_external') {
2904: push(@rulenames,'externalbalancer');
2905: } else {
2906: push(@rulenames,'specific');
2907: }
2908: my $style = $targets_div_style;
2909: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
2910: $style = $homedom_div_style;
2911: }
2912: my $output =
2913: '<tr><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
2914: '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
2915: for (my $i=0; $i<@rulenames; $i++) {
2916: my $rule = $rulenames[$i];
2917: my ($checked,$extra);
2918: if ($rulenames[$i] eq 'default') {
2919: $rule = '';
2920: }
2921: if ($rulenames[$i] eq 'specific') {
2922: if (ref($servers) eq 'HASH') {
2923: my $default;
2924: if (($current ne '') && (exists($servers->{$current}))) {
2925: $checked = ' checked="checked"';
2926: }
2927: unless ($checked) {
2928: $default = ' selected="selected"';
2929: }
2930: $extra = ': <select name="loadbalancing_singleserver_'.$type.
2931: '" id="loadbalancing_singleserver_'.$type.
2932: '" onchange="singleServerToggle('."'$type'".')">'."\n".
2933: '<option value=""'.$default.'></option>'."\n";
2934: foreach my $lonhost (sort(keys(%{$servers}))) {
2935: next if ($lonhost eq $currbalancer);
2936: my $selected;
2937: if ($lonhost eq $current) {
2938: $selected = ' selected="selected"';
2939: }
2940: $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
2941: }
2942: $extra .= '</select>';
2943: }
2944: } elsif ($rule eq $current) {
2945: $checked = ' checked="checked"';
2946: }
2947: $output .= '<span class="LC_nobreak"><label>'.
2948: '<input type="radio" name="loadbalancing_rules_'.$type.
2949: '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
2950: $rule.'" onclick="balanceruleChange('."this.form,'$type'".
2951: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
2952: '</label>'.$extra.'</span><br />'."\n";
2953: }
2954: $output .= '</div></td></tr>'."\n";
2955: return $output;
2956: }
2957:
2958: sub offloadtype_text {
2959: my %ruletitles = &Apache::lonlocal::texthash (
2960: 'default' => 'Offloads to default destinations',
2961: 'homeserver' => "Offloads to user's home server",
2962: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
2963: 'specific' => 'Offloads to specific server',
2964: );
2965: return %ruletitles;
2966: }
2967:
2968: sub sparestype_titles {
2969: my %typestitles = &Apache::lonlocal::texthash (
2970: 'primary' => 'primary',
2971: 'default' => 'default',
2972: );
2973: return %typestitles;
2974: }
2975:
1.28 raeburn 2976: sub contact_titles {
2977: my %titles = &Apache::lonlocal::texthash (
2978: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2979: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2980: 'errormail' => 'Error reports to be e-mailed to',
2981: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2982: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2983: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2984: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2985: );
2986: my %short_titles = &Apache::lonlocal::texthash (
2987: adminemail => 'Admin E-mail address',
2988: supportemail => 'Support E-mail',
2989: );
2990: return (\%titles,\%short_titles);
2991: }
2992:
1.72 raeburn 2993: sub tool_titles {
2994: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 2995: aboutme => 'Personal Information Page',
1.86 raeburn 2996: blog => 'Blog',
2997: portfolio => 'Portfolio',
1.88 bisitz 2998: official => 'Official courses (with institutional codes)',
2999: unofficial => 'Unofficial courses',
1.98 raeburn 3000: community => 'Communities',
1.86 raeburn 3001: );
1.72 raeburn 3002: return %titles;
3003: }
3004:
1.101 raeburn 3005: sub courserequest_titles {
3006: my %titles = &Apache::lonlocal::texthash (
3007: official => 'Official',
3008: unofficial => 'Unofficial',
3009: community => 'Communities',
3010: norequest => 'Not allowed',
1.104 raeburn 3011: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3012: validate => 'With validation',
3013: autolimit => 'Numerical limit',
1.103 raeburn 3014: unlimited => '(blank for unlimited)',
1.101 raeburn 3015: );
3016: return %titles;
3017: }
3018:
3019: sub courserequest_conditions {
3020: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3021: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3022: validate => '(Processing of request subject to instittutional validation).',
3023: );
3024: return %conditions;
3025: }
3026:
3027:
1.27 raeburn 3028: sub print_usercreation {
1.30 raeburn 3029: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3030: my $numinrow = 4;
1.28 raeburn 3031: my $datatable;
3032: if ($position eq 'top') {
1.30 raeburn 3033: $$rowtotal ++;
1.34 raeburn 3034: my $rowcount = 0;
1.32 raeburn 3035: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3036: if (ref($rules) eq 'HASH') {
3037: if (keys(%{$rules}) > 0) {
1.32 raeburn 3038: $datatable .= &user_formats_row('username',$settings,$rules,
3039: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3040: $$rowtotal ++;
1.32 raeburn 3041: $rowcount ++;
3042: }
3043: }
3044: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3045: if (ref($idrules) eq 'HASH') {
3046: if (keys(%{$idrules}) > 0) {
3047: $datatable .= &user_formats_row('id',$settings,$idrules,
3048: $idruleorder,$numinrow,$rowcount);
3049: $$rowtotal ++;
3050: $rowcount ++;
1.28 raeburn 3051: }
3052: }
1.43 raeburn 3053: my ($emailrules,$emailruleorder) =
3054: &Apache::lonnet::inst_userrules($dom,'email');
3055: if (ref($emailrules) eq 'HASH') {
3056: if (keys(%{$emailrules}) > 0) {
3057: $datatable .= &user_formats_row('email',$settings,$emailrules,
3058: $emailruleorder,$numinrow,$rowcount);
3059: $$rowtotal ++;
3060: $rowcount ++;
3061: }
3062: }
1.39 raeburn 3063: if ($rowcount == 0) {
3064: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3065: $$rowtotal ++;
3066: $rowcount ++;
3067: }
1.34 raeburn 3068: } elsif ($position eq 'middle') {
1.100 raeburn 3069: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3070: my ($rules,$ruleorder) =
3071: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3072: my %lt = &usercreation_types();
3073: my %checked;
1.50 raeburn 3074: my @selfcreate;
1.34 raeburn 3075: if (ref($settings) eq 'HASH') {
3076: if (ref($settings->{'cancreate'}) eq 'HASH') {
3077: foreach my $item (@creators) {
3078: $checked{$item} = $settings->{'cancreate'}{$item};
3079: }
1.50 raeburn 3080: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3081: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3082: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3083: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3084: @selfcreate = ('email','login','sso');
3085: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3086: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3087: }
3088: }
1.34 raeburn 3089: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3090: foreach my $item (@creators) {
3091: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3092: $checked{$item} = 'none';
3093: }
3094: }
3095: }
3096: }
3097: my $rownum = 0;
3098: foreach my $item (@creators) {
3099: $rownum ++;
1.50 raeburn 3100: if ($item ne 'selfcreate') {
3101: if ($checked{$item} eq '') {
1.43 raeburn 3102: $checked{$item} = 'any';
3103: }
1.34 raeburn 3104: }
3105: my $css_class;
3106: if ($rownum%2) {
3107: $css_class = '';
3108: } else {
3109: $css_class = ' class="LC_odd_row" ';
3110: }
3111: $datatable .= '<tr'.$css_class.'>'.
3112: '<td><span class="LC_nobreak">'.$lt{$item}.
3113: '</span></td><td align="right">';
1.50 raeburn 3114: my @options;
1.45 raeburn 3115: if ($item eq 'selfcreate') {
1.43 raeburn 3116: push(@options,('email','login','sso'));
3117: } else {
1.50 raeburn 3118: @options = ('any');
1.43 raeburn 3119: if (ref($rules) eq 'HASH') {
3120: if (keys(%{$rules}) > 0) {
3121: push(@options,('official','unofficial'));
3122: }
1.37 raeburn 3123: }
1.50 raeburn 3124: push(@options,'none');
1.37 raeburn 3125: }
3126: foreach my $option (@options) {
1.50 raeburn 3127: my $type = 'radio';
1.34 raeburn 3128: my $check = ' ';
1.50 raeburn 3129: if ($item eq 'selfcreate') {
3130: $type = 'checkbox';
3131: if (grep(/^\Q$option\E$/,@selfcreate)) {
3132: $check = ' checked="checked" ';
3133: }
3134: } else {
3135: if ($checked{$item} eq $option) {
3136: $check = ' checked="checked" ';
3137: }
1.34 raeburn 3138: }
3139: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3140: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3141: $item.'" value="'.$option.'"'.$check.'/> '.
3142: $lt{$option}.'</label> </span>';
3143: }
3144: $datatable .= '</td></tr>';
3145: }
1.93 raeburn 3146: my ($othertitle,$usertypes,$types) =
3147: &Apache::loncommon::sorted_inst_types($dom);
3148: if (ref($usertypes) eq 'HASH') {
3149: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3150: my $createsettings;
3151: if (ref($settings) eq 'HASH') {
3152: $createsettings = $settings->{cancreate};
3153: }
3154: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3155: $dom,$numinrow,$othertitle,
3156: 'statustocreate');
3157: $$rowtotal ++;
3158: }
3159: }
1.28 raeburn 3160: } else {
3161: my @contexts = ('author','course','domain');
3162: my @authtypes = ('int','krb4','krb5','loc');
3163: my %checked;
3164: if (ref($settings) eq 'HASH') {
3165: if (ref($settings->{'authtypes'}) eq 'HASH') {
3166: foreach my $item (@contexts) {
3167: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3168: foreach my $auth (@authtypes) {
3169: if ($settings->{'authtypes'}{$item}{$auth}) {
3170: $checked{$item}{$auth} = ' checked="checked" ';
3171: }
3172: }
3173: }
3174: }
1.27 raeburn 3175: }
1.35 raeburn 3176: } else {
3177: foreach my $item (@contexts) {
1.36 raeburn 3178: foreach my $auth (@authtypes) {
1.35 raeburn 3179: $checked{$item}{$auth} = ' checked="checked" ';
3180: }
3181: }
1.27 raeburn 3182: }
1.28 raeburn 3183: my %title = &context_names();
3184: my %authname = &authtype_names();
3185: my $rownum = 0;
3186: my $css_class;
3187: foreach my $item (@contexts) {
3188: if ($rownum%2) {
3189: $css_class = '';
3190: } else {
3191: $css_class = ' class="LC_odd_row" ';
3192: }
1.30 raeburn 3193: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3194: '<td>'.$title{$item}.
3195: '</td><td class="LC_left_item">'.
3196: '<span class="LC_nobreak">';
3197: foreach my $auth (@authtypes) {
3198: $datatable .= '<label>'.
3199: '<input type="checkbox" name="'.$item.'_auth" '.
3200: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3201: $authname{$auth}.'</label> ';
3202: }
3203: $datatable .= '</span></td></tr>';
3204: $rownum ++;
1.27 raeburn 3205: }
1.30 raeburn 3206: $$rowtotal += $rownum;
1.27 raeburn 3207: }
3208: return $datatable;
3209: }
3210:
1.32 raeburn 3211: sub user_formats_row {
3212: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3213: my $output;
3214: my %text = (
3215: 'username' => 'new usernames',
3216: 'id' => 'IDs',
1.45 raeburn 3217: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3218: );
3219: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3220: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3221: '<td><span class="LC_nobreak">';
3222: if ($type eq 'email') {
3223: $output .= &mt("Formats disallowed for $text{$type}: ");
3224: } else {
3225: $output .= &mt("Format rules to check for $text{$type}: ");
3226: }
3227: $output .= '</span></td>'.
3228: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3229: my $rem;
3230: if (ref($ruleorder) eq 'ARRAY') {
3231: for (my $i=0; $i<@{$ruleorder}; $i++) {
3232: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3233: my $rem = $i%($numinrow);
3234: if ($rem == 0) {
3235: if ($i > 0) {
3236: $output .= '</tr>';
3237: }
3238: $output .= '<tr>';
3239: }
3240: my $check = ' ';
1.39 raeburn 3241: if (ref($settings) eq 'HASH') {
3242: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3243: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3244: $check = ' checked="checked" ';
3245: }
1.27 raeburn 3246: }
3247: }
3248: $output .= '<td class="LC_left_item">'.
3249: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3250: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3251: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3252: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3253: }
3254: }
3255: $rem = @{$ruleorder}%($numinrow);
3256: }
3257: my $colsleft = $numinrow - $rem;
3258: if ($colsleft > 1 ) {
3259: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3260: ' </td>';
3261: } elsif ($colsleft == 1) {
3262: $output .= '<td class="LC_left_item"> </td>';
3263: }
3264: $output .= '</tr></table></td></tr>';
3265: return $output;
3266: }
3267:
1.34 raeburn 3268: sub usercreation_types {
3269: my %lt = &Apache::lonlocal::texthash (
3270: author => 'When adding a co-author',
3271: course => 'When adding a user to a course',
1.100 raeburn 3272: requestcrs => 'When requesting a course',
1.45 raeburn 3273: selfcreate => 'User creates own account',
1.34 raeburn 3274: any => 'Any',
3275: official => 'Institutional only ',
3276: unofficial => 'Non-institutional only',
1.85 schafran 3277: email => 'E-mail address',
1.43 raeburn 3278: login => 'Institutional Login',
3279: sso => 'SSO',
1.34 raeburn 3280: none => 'None',
3281: );
3282: return %lt;
1.48 raeburn 3283: }
1.34 raeburn 3284:
1.28 raeburn 3285: sub authtype_names {
3286: my %lt = &Apache::lonlocal::texthash(
3287: int => 'Internal',
3288: krb4 => 'Kerberos 4',
3289: krb5 => 'Kerberos 5',
3290: loc => 'Local',
3291: );
3292: return %lt;
3293: }
3294:
3295: sub context_names {
3296: my %context_title = &Apache::lonlocal::texthash(
3297: author => 'Creating users when an Author',
3298: course => 'Creating users when in a course',
3299: domain => 'Creating users when a Domain Coordinator',
3300: );
3301: return %context_title;
3302: }
3303:
1.33 raeburn 3304: sub print_usermodification {
3305: my ($position,$dom,$settings,$rowtotal) = @_;
3306: my $numinrow = 4;
3307: my ($context,$datatable,$rowcount);
3308: if ($position eq 'top') {
3309: $rowcount = 0;
3310: $context = 'author';
3311: foreach my $role ('ca','aa') {
3312: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3313: $numinrow,$rowcount);
3314: $$rowtotal ++;
3315: $rowcount ++;
3316: }
1.63 raeburn 3317: } elsif ($position eq 'middle') {
1.33 raeburn 3318: $context = 'course';
3319: $rowcount = 0;
3320: foreach my $role ('st','ep','ta','in','cr') {
3321: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3322: $numinrow,$rowcount);
3323: $$rowtotal ++;
3324: $rowcount ++;
3325: }
1.63 raeburn 3326: } elsif ($position eq 'bottom') {
3327: $context = 'selfcreate';
3328: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3329: $usertypes->{'default'} = $othertitle;
3330: if (ref($types) eq 'ARRAY') {
3331: push(@{$types},'default');
3332: $usertypes->{'default'} = $othertitle;
3333: foreach my $status (@{$types}) {
3334: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3335: $numinrow,$rowcount,$usertypes);
3336: $$rowtotal ++;
3337: $rowcount ++;
3338: }
3339: }
1.33 raeburn 3340: }
3341: return $datatable;
3342: }
3343:
1.43 raeburn 3344: sub print_defaults {
3345: my ($dom,$rowtotal) = @_;
1.68 raeburn 3346: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3347: 'datelocale_def','portal_def');
1.43 raeburn 3348: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3349: my $titles = &defaults_titles($dom);
1.43 raeburn 3350: my $rownum = 0;
3351: my ($datatable,$css_class);
3352: foreach my $item (@items) {
3353: if ($rownum%2) {
3354: $css_class = '';
3355: } else {
3356: $css_class = ' class="LC_odd_row" ';
3357: }
3358: $datatable .= '<tr'.$css_class.'>'.
3359: '<td><span class="LC_nobreak">'.$titles->{$item}.
3360: '</span></td><td class="LC_right_item">';
3361: if ($item eq 'auth_def') {
3362: my @authtypes = ('internal','krb4','krb5','localauth');
3363: my %shortauth = (
3364: internal => 'int',
3365: krb4 => 'krb4',
3366: krb5 => 'krb5',
3367: localauth => 'loc'
3368: );
3369: my %authnames = &authtype_names();
3370: foreach my $auth (@authtypes) {
3371: my $checked = ' ';
3372: if ($domdefaults{$item} eq $auth) {
3373: $checked = ' checked="checked" ';
3374: }
3375: $datatable .= '<label><input type="radio" name="'.$item.
3376: '" value="'.$auth.'"'.$checked.'/>'.
3377: $authnames{$shortauth{$auth}}.'</label> ';
3378: }
1.54 raeburn 3379: } elsif ($item eq 'timezone_def') {
3380: my $includeempty = 1;
3381: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3382: } elsif ($item eq 'datelocale_def') {
3383: my $includeempty = 1;
3384: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 3385: } else {
1.141 raeburn 3386: my $size;
3387: if ($item eq 'portal_def') {
3388: $size = ' size="25"';
3389: }
1.43 raeburn 3390: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3391: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3392: }
3393: $datatable .= '</td></tr>';
3394: $rownum ++;
3395: }
3396: $$rowtotal += $rownum;
3397: return $datatable;
3398: }
3399:
3400: sub defaults_titles {
1.141 raeburn 3401: my ($dom) = @_;
1.43 raeburn 3402: my %titles = &Apache::lonlocal::texthash (
3403: 'auth_def' => 'Default authentication type',
3404: 'auth_arg_def' => 'Default authentication argument',
3405: 'lang_def' => 'Default language',
1.54 raeburn 3406: 'timezone_def' => 'Default timezone',
1.68 raeburn 3407: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3408: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3409: );
1.141 raeburn 3410: if ($dom) {
3411: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3412: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3413: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3414: $protocol = 'http' if ($protocol ne 'https');
3415: if ($uint_dom) {
3416: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3417: $uint_dom);
3418: }
3419: }
1.43 raeburn 3420: return (\%titles);
3421: }
3422:
1.46 raeburn 3423: sub print_scantronformat {
3424: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3425: my $itemcount = 1;
1.60 raeburn 3426: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3427: %confhash);
1.46 raeburn 3428: my $switchserver = &check_switchserver($dom,$confname);
3429: my %lt = &Apache::lonlocal::texthash (
1.95 www 3430: default => 'Default bubblesheet format file error',
3431: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3432: );
3433: my %scantronfiles = (
3434: default => 'default.tab',
3435: custom => 'custom.tab',
3436: );
3437: foreach my $key (keys(%scantronfiles)) {
3438: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3439: .$scantronfiles{$key};
3440: }
3441: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3442: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3443: if (!$switchserver) {
3444: my $servadm = $r->dir_config('lonAdmEMail');
3445: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3446: if ($configuserok eq 'ok') {
3447: if ($author_ok eq 'ok') {
3448: my %legacyfile = (
3449: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3450: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3451: );
3452: my %md5chk;
3453: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3454: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3455: chomp($md5chk{$type});
1.46 raeburn 3456: }
3457: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3458: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3459: ($scantronurls{$type},my $error) =
1.46 raeburn 3460: &legacy_scantronformat($r,$dom,$confname,
3461: $type,$legacyfile{$type},
3462: $scantronurls{$type},
3463: $scantronfiles{$type});
1.60 raeburn 3464: if ($error ne '') {
3465: $error{$type} = $error;
3466: }
3467: }
3468: if (keys(%error) == 0) {
3469: $is_custom = 1;
3470: $confhash{'scantron'}{'scantronformat'} =
3471: $scantronurls{'custom'};
3472: my $putresult =
3473: &Apache::lonnet::put_dom('configuration',
3474: \%confhash,$dom);
3475: if ($putresult ne 'ok') {
3476: $error{'custom'} =
3477: '<span class="LC_error">'.
3478: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3479: }
1.46 raeburn 3480: }
3481: } else {
1.60 raeburn 3482: ($scantronurls{'default'},my $error) =
1.46 raeburn 3483: &legacy_scantronformat($r,$dom,$confname,
3484: 'default',$legacyfile{'default'},
3485: $scantronurls{'default'},
3486: $scantronfiles{'default'});
1.60 raeburn 3487: if ($error eq '') {
3488: $confhash{'scantron'}{'scantronformat'} = '';
3489: my $putresult =
3490: &Apache::lonnet::put_dom('configuration',
3491: \%confhash,$dom);
3492: if ($putresult ne 'ok') {
3493: $error{'default'} =
3494: '<span class="LC_error">'.
3495: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3496: }
3497: } else {
3498: $error{'default'} = $error;
3499: }
1.46 raeburn 3500: }
3501: }
3502: }
3503: } else {
1.95 www 3504: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3505: }
3506: }
3507: if (ref($settings) eq 'HASH') {
3508: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3509: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3510: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3511: $scantronurl = '';
3512: } else {
3513: $scantronurl = $settings->{'scantronformat'};
3514: }
3515: $is_custom = 1;
3516: } else {
3517: $scantronurl = $scantronurls{'default'};
3518: }
3519: } else {
1.60 raeburn 3520: if ($is_custom) {
3521: $scantronurl = $scantronurls{'custom'};
3522: } else {
3523: $scantronurl = $scantronurls{'default'};
3524: }
1.46 raeburn 3525: }
3526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3527: $datatable .= '<tr'.$css_class.'>';
3528: if (!$is_custom) {
1.65 raeburn 3529: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3530: '<span class="LC_nobreak">';
1.46 raeburn 3531: if ($scantronurl) {
3532: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3533: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3534: } else {
3535: $datatable = &mt('File unavailable for display');
3536: }
1.65 raeburn 3537: $datatable .= '</span></td>';
1.60 raeburn 3538: if (keys(%error) == 0) {
3539: $datatable .= '<td valign="bottom">';
3540: if (!$switchserver) {
3541: $datatable .= &mt('Upload:').'<br />';
3542: }
3543: } else {
3544: my $errorstr;
3545: foreach my $key (sort(keys(%error))) {
3546: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3547: }
3548: $datatable .= '<td>'.$errorstr;
3549: }
1.46 raeburn 3550: } else {
3551: if (keys(%error) > 0) {
3552: my $errorstr;
3553: foreach my $key (sort(keys(%error))) {
3554: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3555: }
1.60 raeburn 3556: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3557: } elsif ($scantronurl) {
1.65 raeburn 3558: $datatable .= '<td><span class="LC_nobreak">'.
3559: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3560: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3561: '<input type="checkbox" name="scantronformat_del"'.
3562: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3563: '<td><span class="LC_nobreak"> '.
3564: &mt('Replace:').'</span><br />';
1.46 raeburn 3565: }
3566: }
3567: if (keys(%error) == 0) {
3568: if ($switchserver) {
3569: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3570: } else {
1.65 raeburn 3571: $datatable .='<span class="LC_nobreak"> '.
3572: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3573: }
3574: }
3575: $datatable .= '</td></tr>';
3576: $$rowtotal ++;
3577: return $datatable;
3578: }
3579:
3580: sub legacy_scantronformat {
3581: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3582: my ($url,$error);
3583: my @statinfo = &Apache::lonnet::stat_file($newurl);
3584: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3585: (my $result,$url) =
3586: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3587: '','',$newfile);
3588: if ($result ne 'ok') {
1.130 raeburn 3589: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3590: }
3591: }
3592: return ($url,$error);
3593: }
1.43 raeburn 3594:
1.49 raeburn 3595: sub print_coursecategories {
1.57 raeburn 3596: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3597: my $datatable;
3598: if ($position eq 'top') {
3599: my $toggle_cats_crs = ' ';
3600: my $toggle_cats_dom = ' checked="checked" ';
3601: my $can_cat_crs = ' ';
3602: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3603: my $toggle_catscomm_comm = ' ';
3604: my $toggle_catscomm_dom = ' checked="checked" ';
3605: my $can_catcomm_comm = ' ';
3606: my $can_catcomm_dom = ' checked="checked" ';
3607:
1.57 raeburn 3608: if (ref($settings) eq 'HASH') {
3609: if ($settings->{'togglecats'} eq 'crs') {
3610: $toggle_cats_crs = $toggle_cats_dom;
3611: $toggle_cats_dom = ' ';
3612: }
3613: if ($settings->{'categorize'} eq 'crs') {
3614: $can_cat_crs = $can_cat_dom;
3615: $can_cat_dom = ' ';
3616: }
1.120 raeburn 3617: if ($settings->{'togglecatscomm'} eq 'comm') {
3618: $toggle_catscomm_comm = $toggle_catscomm_dom;
3619: $toggle_catscomm_dom = ' ';
3620: }
3621: if ($settings->{'categorizecomm'} eq 'comm') {
3622: $can_catcomm_comm = $can_catcomm_dom;
3623: $can_catcomm_dom = ' ';
3624: }
1.57 raeburn 3625: }
3626: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3627: togglecats => 'Show/Hide a course in catalog',
3628: togglecatscomm => 'Show/Hide a community in catalog',
3629: categorize => 'Assign a category to a course',
3630: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3631: );
3632: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3633: dom => 'Set in Domain',
3634: crs => 'Set in Course',
3635: comm => 'Set in Community',
1.57 raeburn 3636: );
3637: $datatable = '<tr class="LC_odd_row">'.
3638: '<td>'.$title{'togglecats'}.'</td>'.
3639: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3640: '<input type="radio" name="togglecats"'.
3641: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3642: '<label><input type="radio" name="togglecats"'.
3643: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3644: '</tr><tr>'.
3645: '<td>'.$title{'categorize'}.'</td>'.
3646: '<td class="LC_right_item"><span class="LC_nobreak">'.
3647: '<label><input type="radio" name="categorize"'.
3648: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3649: '<label><input type="radio" name="categorize"'.
3650: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3651: '</tr><tr class="LC_odd_row">'.
3652: '<td>'.$title{'togglecatscomm'}.'</td>'.
3653: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3654: '<input type="radio" name="togglecatscomm"'.
3655: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3656: '<label><input type="radio" name="togglecatscomm"'.
3657: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3658: '</tr><tr>'.
3659: '<td>'.$title{'categorizecomm'}.'</td>'.
3660: '<td class="LC_right_item"><span class="LC_nobreak">'.
3661: '<label><input type="radio" name="categorizecomm"'.
3662: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3663: '<label><input type="radio" name="categorizecomm"'.
3664: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3665: '</tr>';
1.120 raeburn 3666: $$rowtotal += 4;
1.57 raeburn 3667: } else {
3668: my $css_class;
3669: my $itemcount = 1;
3670: my $cathash;
3671: if (ref($settings) eq 'HASH') {
3672: $cathash = $settings->{'cats'};
3673: }
3674: if (ref($cathash) eq 'HASH') {
3675: my (@cats,@trails,%allitems,%idx,@jsarray);
3676: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3677: \%allitems,\%idx,\@jsarray);
3678: my $maxdepth = scalar(@cats);
3679: my $colattrib = '';
3680: if ($maxdepth > 2) {
3681: $colattrib = ' colspan="2" ';
3682: }
3683: my @path;
3684: if (@cats > 0) {
3685: if (ref($cats[0]) eq 'ARRAY') {
3686: my $numtop = @{$cats[0]};
3687: my $maxnum = $numtop;
1.120 raeburn 3688: my %default_names = (
3689: instcode => &mt('Official courses'),
3690: communities => &mt('Communities'),
3691: );
3692:
3693: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3694: ($cathash->{'instcode::0'} eq '') ||
3695: (!grep(/^communities$/,@{$cats[0]})) ||
3696: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3697: $maxnum ++;
3698: }
3699: my $lastidx;
3700: for (my $i=0; $i<$numtop; $i++) {
3701: my $parent = $cats[0][$i];
3702: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3703: my $item = &escape($parent).'::0';
3704: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3705: $lastidx = $idx{$item};
3706: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3707: .'<select name="'.$item.'"'.$chgstr.'>';
3708: for (my $k=0; $k<=$maxnum; $k++) {
3709: my $vpos = $k+1;
3710: my $selstr;
3711: if ($k == $i) {
3712: $selstr = ' selected="selected" ';
3713: }
3714: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3715: }
3716: $datatable .= '</select></td><td>';
1.120 raeburn 3717: if ($parent eq 'instcode' || $parent eq 'communities') {
3718: $datatable .= '<span class="LC_nobreak">'
3719: .$default_names{$parent}.'</span>';
3720: if ($parent eq 'instcode') {
3721: $datatable .= '<br /><span class="LC_nobreak">('
3722: .&mt('with institutional codes')
3723: .')</span></td><td'.$colattrib.'>';
3724: } else {
3725: $datatable .= '<table><tr><td>';
3726: }
3727: $datatable .= '<span class="LC_nobreak">'
3728: .'<label><input type="radio" name="'
3729: .$parent.'" value="1" checked="checked" />'
3730: .&mt('Display').'</label>';
3731: if ($parent eq 'instcode') {
3732: $datatable .= ' ';
3733: } else {
3734: $datatable .= '</span></td></tr><tr><td>'
3735: .'<span class="LC_nobreak">';
3736: }
3737: $datatable .= '<label><input type="radio" name="'
3738: .$parent.'" value="0" />'
3739: .&mt('Do not display').'</label></span>';
3740: if ($parent eq 'communities') {
3741: $datatable .= '</td></tr></table>';
3742: }
3743: $datatable .= '</td>';
1.57 raeburn 3744: } else {
3745: $datatable .= $parent
3746: .' <label><input type="checkbox" name="deletecategory" '
3747: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3748: }
3749: my $depth = 1;
3750: push(@path,$parent);
3751: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3752: pop(@path);
3753: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3754: $itemcount ++;
3755: }
1.48 raeburn 3756: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3757: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3758: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3759: for (my $k=0; $k<=$maxnum; $k++) {
3760: my $vpos = $k+1;
3761: my $selstr;
1.57 raeburn 3762: if ($k == $numtop) {
1.48 raeburn 3763: $selstr = ' selected="selected" ';
3764: }
3765: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3766: }
1.59 bisitz 3767: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3768: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3769: .'</tr>'."\n";
1.48 raeburn 3770: $itemcount ++;
1.120 raeburn 3771: foreach my $default ('instcode','communities') {
3772: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3773: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3774: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3775: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3776: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3777: for (my $k=0; $k<=$maxnum; $k++) {
3778: my $vpos = $k+1;
3779: my $selstr;
3780: if ($k == $maxnum) {
3781: $selstr = ' selected="selected" ';
3782: }
3783: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3784: }
1.120 raeburn 3785: $datatable .= '</select></span></td>'.
3786: '<td><span class="LC_nobreak">'.
3787: $default_names{$default}.'</span>';
3788: if ($default eq 'instcode') {
3789: $datatable .= '<br /><span class="LC_nobreak">('
3790: .&mt('with institutional codes').')</span>';
3791: }
3792: $datatable .= '</td>'
3793: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3794: .&mt('Display').'</label> '
3795: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3796: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3797: }
3798: }
3799: }
1.57 raeburn 3800: } else {
3801: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3802: }
3803: } else {
1.57 raeburn 3804: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3805: .&initialize_categories($itemcount);
1.48 raeburn 3806: }
1.57 raeburn 3807: $$rowtotal += $itemcount;
1.48 raeburn 3808: }
3809: return $datatable;
3810: }
3811:
1.69 raeburn 3812: sub print_serverstatuses {
3813: my ($dom,$settings,$rowtotal) = @_;
3814: my $datatable;
3815: my @pages = &serverstatus_pages();
3816: my (%namedaccess,%machineaccess);
3817: foreach my $type (@pages) {
3818: $namedaccess{$type} = '';
3819: $machineaccess{$type}= '';
3820: }
3821: if (ref($settings) eq 'HASH') {
3822: foreach my $type (@pages) {
3823: if (exists($settings->{$type})) {
3824: if (ref($settings->{$type}) eq 'HASH') {
3825: foreach my $key (keys(%{$settings->{$type}})) {
3826: if ($key eq 'namedusers') {
3827: $namedaccess{$type} = $settings->{$type}->{$key};
3828: } elsif ($key eq 'machines') {
3829: $machineaccess{$type} = $settings->{$type}->{$key};
3830: }
3831: }
3832: }
3833: }
3834: }
3835: }
1.81 raeburn 3836: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3837: my $rownum = 0;
3838: my $css_class;
3839: foreach my $type (@pages) {
3840: $rownum ++;
3841: $css_class = $rownum%2?' class="LC_odd_row"':'';
3842: $datatable .= '<tr'.$css_class.'>'.
3843: '<td><span class="LC_nobreak">'.
3844: $titles->{$type}.'</span></td>'.
3845: '<td class="LC_left_item">'.
3846: '<input type="text" name="'.$type.'_namedusers" '.
3847: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3848: '<td class="LC_right_item">'.
3849: '<span class="LC_nobreak">'.
3850: '<input type="text" name="'.$type.'_machines" '.
3851: 'value="'.$machineaccess{$type}.'" size="10" />'.
3852: '</td></tr>'."\n";
3853: }
3854: $$rowtotal += $rownum;
3855: return $datatable;
3856: }
3857:
3858: sub serverstatus_pages {
3859: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3860: 'clusterstatus','metadata_keywords','metadata_harvest',
1.113 raeburn 3861: 'takeoffline','takeonline','showenv','toggledebug');
1.69 raeburn 3862: }
3863:
1.49 raeburn 3864: sub coursecategories_javascript {
3865: my ($settings) = @_;
1.57 raeburn 3866: my ($output,$jstext,$cathash);
1.49 raeburn 3867: if (ref($settings) eq 'HASH') {
1.57 raeburn 3868: $cathash = $settings->{'cats'};
3869: }
3870: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3871: my (@cats,@jsarray,%idx);
1.57 raeburn 3872: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3873: if (@jsarray > 0) {
3874: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3875: for (my $i=0; $i<@jsarray; $i++) {
3876: if (ref($jsarray[$i]) eq 'ARRAY') {
3877: my $catstr = join('","',@{$jsarray[$i]});
3878: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3879: }
3880: }
3881: }
3882: } else {
3883: $jstext = ' var categories = Array(1);'."\n".
3884: ' categories[0] = Array("instcode_pos");'."\n";
3885: }
1.120 raeburn 3886: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3887: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3888: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3889: $output = <<"ENDSCRIPT";
3890: <script type="text/javascript">
1.109 raeburn 3891: // <![CDATA[
1.49 raeburn 3892: function reorderCats(form,parent,item,idx) {
3893: var changedVal;
3894: $jstext
3895: var newpos = 'addcategory_pos';
3896: var current = new Array;
3897: if (parent == '') {
3898: var has_instcode = 0;
3899: var maxtop = categories[idx].length;
3900: for (var j=0; j<maxtop; j++) {
3901: if (categories[idx][j] == 'instcode::0') {
3902: has_instcode == 1;
3903: }
3904: }
3905: if (has_instcode == 0) {
3906: categories[idx][maxtop] = 'instcode_pos';
3907: }
3908: } else {
3909: newpos += '_'+parent;
3910: }
3911: var maxh = 1 + categories[idx].length;
3912: var current = new Array;
3913: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3914: if (item == newpos) {
3915: changedVal = newitemVal;
3916: } else {
3917: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3918: current[newitemVal] = newpos;
3919: }
3920: for (var i=0; i<categories[idx].length; i++) {
3921: var elementName = categories[idx][i];
3922: if (elementName != item) {
3923: if (form.elements[elementName]) {
3924: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3925: current[currVal] = elementName;
3926: }
3927: }
3928: }
3929: var oldVal;
3930: for (var j=0; j<maxh; j++) {
3931: if (current[j] == undefined) {
3932: oldVal = j;
3933: }
3934: }
3935: if (oldVal < changedVal) {
3936: for (var k=oldVal+1; k<=changedVal ; k++) {
3937: var elementName = current[k];
3938: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3939: }
3940: } else {
3941: for (var k=changedVal; k<oldVal; k++) {
3942: var elementName = current[k];
3943: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3944: }
3945: }
3946: return;
3947: }
1.120 raeburn 3948:
3949: function categoryCheck(form) {
3950: if (form.elements['addcategory_name'].value == 'instcode') {
3951: alert('$instcode_reserved\\n$choose_again');
3952: return false;
3953: }
3954: if (form.elements['addcategory_name'].value == 'communities') {
3955: alert('$communities_reserved\\n$choose_again');
3956: return false;
3957: }
3958: return true;
3959: }
3960:
1.109 raeburn 3961: // ]]>
1.49 raeburn 3962: </script>
3963:
3964: ENDSCRIPT
3965: return $output;
3966: }
3967:
1.48 raeburn 3968: sub initialize_categories {
3969: my ($itemcount) = @_;
1.120 raeburn 3970: my ($datatable,$css_class,$chgstr);
3971: my %default_names = (
3972: instcode => 'Official courses (with institutional codes)',
3973: communities => 'Communities',
3974: );
3975: my $select0 = ' selected="selected"';
3976: my $select1 = '';
3977: foreach my $default ('instcode','communities') {
3978: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3979: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3980: if ($default eq 'communities') {
3981: $select1 = $select0;
3982: $select0 = '';
3983: }
3984: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3985: .'<select name="'.$default.'_pos">'
3986: .'<option value="0"'.$select0.'>1</option>'
3987: .'<option value="1"'.$select1.'>2</option>'
3988: .'<option value="2">3</option></select> '
3989: .$default_names{$default}
3990: .'</span></td><td><span class="LC_nobreak">'
3991: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3992: .&mt('Display').'</label> <label>'
3993: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 3994: .'</label></span></td></tr>';
1.120 raeburn 3995: $itemcount ++;
3996: }
1.48 raeburn 3997: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 3998: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 3999: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4000: .'<select name="addcategory_pos"'.$chgstr.'>'
4001: .'<option value="0">1</option>'
4002: .'<option value="1">2</option>'
4003: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4004: .&mt('Add category').'</td><td>'.&mt('Name:')
4005: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4006: return $datatable;
4007: }
4008:
4009: sub build_category_rows {
1.49 raeburn 4010: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4011: my ($text,$name,$item,$chgstr);
1.48 raeburn 4012: if (ref($cats) eq 'ARRAY') {
4013: my $maxdepth = scalar(@{$cats});
4014: if (ref($cats->[$depth]) eq 'HASH') {
4015: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4016: my $numchildren = @{$cats->[$depth]{$parent}};
4017: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4018: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4019: my ($idxnum,$parent_name,$parent_item);
4020: my $higher = $depth - 1;
4021: if ($higher == 0) {
4022: $parent_name = &escape($parent).'::'.$higher;
4023: } else {
4024: if (ref($path) eq 'ARRAY') {
4025: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4026: }
4027: }
4028: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4029: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4030: if ($j < $numchildren) {
1.48 raeburn 4031: $name = $cats->[$depth]{$parent}[$j];
4032: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4033: $idxnum = $idx->{$item};
4034: } else {
4035: $name = $parent_name;
4036: $item = $parent_item;
1.48 raeburn 4037: }
1.49 raeburn 4038: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4039: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4040: for (my $i=0; $i<=$numchildren; $i++) {
4041: my $vpos = $i+1;
4042: my $selstr;
4043: if ($j == $i) {
4044: $selstr = ' selected="selected" ';
4045: }
4046: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4047: }
4048: $text .= '</select> ';
4049: if ($j < $numchildren) {
4050: my $deeper = $depth+1;
4051: $text .= $name.' '
4052: .'<label><input type="checkbox" name="deletecategory" value="'
4053: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4054: if(ref($path) eq 'ARRAY') {
4055: push(@{$path},$name);
1.49 raeburn 4056: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4057: pop(@{$path});
4058: }
4059: } else {
1.59 bisitz 4060: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4061: if ($j == $numchildren) {
4062: $text .= $name;
4063: } else {
4064: $text .= $item;
4065: }
4066: $text .= '" value="" />';
4067: }
4068: $text .= '</td></tr>';
4069: }
4070: $text .= '</table></td>';
4071: } else {
4072: my $higher = $depth-1;
4073: if ($higher == 0) {
4074: $name = &escape($parent).'::'.$higher;
4075: } else {
4076: if (ref($path) eq 'ARRAY') {
4077: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4078: }
4079: }
4080: my $colspan;
4081: if ($parent ne 'instcode') {
4082: $colspan = $maxdepth - $depth - 1;
4083: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4084: }
4085: }
4086: }
4087: }
4088: return $text;
4089: }
4090:
1.33 raeburn 4091: sub modifiable_userdata_row {
1.63 raeburn 4092: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4093: my $rolename;
1.63 raeburn 4094: if ($context eq 'selfcreate') {
4095: if (ref($usertypes) eq 'HASH') {
4096: $rolename = $usertypes->{$role};
4097: } else {
4098: $rolename = $role;
4099: }
1.33 raeburn 4100: } else {
1.63 raeburn 4101: if ($role eq 'cr') {
4102: $rolename = &mt('Custom role');
4103: } else {
4104: $rolename = &Apache::lonnet::plaintext($role);
4105: }
1.33 raeburn 4106: }
4107: my @fields = ('lastname','firstname','middlename','generation',
4108: 'permanentemail','id');
4109: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4110: my $output;
4111: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4112: $output = '<tr '.$css_class.'>'.
4113: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4114: '<td class="LC_left_item" colspan="2"><table>';
4115: my $rem;
4116: my %checks;
4117: if (ref($settings) eq 'HASH') {
4118: if (ref($settings->{$context}) eq 'HASH') {
4119: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4120: foreach my $field (@fields) {
4121: if ($settings->{$context}->{$role}->{$field}) {
4122: $checks{$field} = ' checked="checked" ';
4123: }
4124: }
4125: }
4126: }
4127: }
4128: for (my $i=0; $i<@fields; $i++) {
4129: my $rem = $i%($numinrow);
4130: if ($rem == 0) {
4131: if ($i > 0) {
4132: $output .= '</tr>';
4133: }
4134: $output .= '<tr>';
4135: }
4136: my $check = ' ';
4137: if (exists($checks{$fields[$i]})) {
4138: $check = $checks{$fields[$i]}
4139: } else {
4140: if ($role eq 'st') {
4141: if (ref($settings) ne 'HASH') {
4142: $check = ' checked="checked" ';
4143: }
4144: }
4145: }
4146: $output .= '<td class="LC_left_item">'.
4147: '<span class="LC_nobreak"><label>'.
4148: '<input type="checkbox" name="canmodify_'.$role.'" '.
4149: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4150: '</label></span></td>';
4151: $rem = @fields%($numinrow);
4152: }
4153: my $colsleft = $numinrow - $rem;
4154: if ($colsleft > 1 ) {
4155: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4156: ' </td>';
4157: } elsif ($colsleft == 1) {
4158: $output .= '<td class="LC_left_item"> </td>';
4159: }
4160: $output .= '</tr></table></td></tr>';
4161: return $output;
4162: }
1.28 raeburn 4163:
1.93 raeburn 4164: sub insttypes_row {
4165: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4166: my %lt = &Apache::lonlocal::texthash (
4167: cansearch => 'Users allowed to search',
4168: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4169: lockablenames => 'User preference to lock name',
1.93 raeburn 4170: );
4171: my $showdom;
4172: if ($context eq 'cansearch') {
4173: $showdom = ' ('.$dom.')';
4174: }
1.25 raeburn 4175: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4176: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 4177: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 4178: my $rem;
4179: if (ref($types) eq 'ARRAY') {
4180: for (my $i=0; $i<@{$types}; $i++) {
4181: if (defined($usertypes->{$types->[$i]})) {
4182: my $rem = $i%($numinrow);
4183: if ($rem == 0) {
4184: if ($i > 0) {
4185: $output .= '</tr>';
4186: }
4187: $output .= '<tr>';
1.23 raeburn 4188: }
1.26 raeburn 4189: my $check = ' ';
1.99 raeburn 4190: if (ref($settings) eq 'HASH') {
4191: if (ref($settings->{$context}) eq 'ARRAY') {
4192: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4193: $check = ' checked="checked" ';
4194: }
4195: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4196: $check = ' checked="checked" ';
4197: }
1.23 raeburn 4198: }
1.26 raeburn 4199: $output .= '<td class="LC_left_item">'.
4200: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4201: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4202: 'value="'.$types->[$i].'"'.$check.'/>'.
4203: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4204: }
4205: }
1.26 raeburn 4206: $rem = @{$types}%($numinrow);
1.23 raeburn 4207: }
4208: my $colsleft = $numinrow - $rem;
1.131 raeburn 4209: if (($rem == 0) && (@{$types} > 0)) {
4210: $output .= '<tr>';
4211: }
1.23 raeburn 4212: if ($colsleft > 1) {
1.25 raeburn 4213: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4214: } else {
1.25 raeburn 4215: $output .= '<td class="LC_left_item">';
1.23 raeburn 4216: }
4217: my $defcheck = ' ';
1.99 raeburn 4218: if (ref($settings) eq 'HASH') {
4219: if (ref($settings->{$context}) eq 'ARRAY') {
4220: if (grep(/^default$/,@{$settings->{$context}})) {
4221: $defcheck = ' checked="checked" ';
4222: }
4223: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4224: $defcheck = ' checked="checked" ';
4225: }
1.23 raeburn 4226: }
1.25 raeburn 4227: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4228: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4229: 'value="default"'.$defcheck.'/>'.
4230: $othertitle.'</label></span></td>'.
4231: '</tr></table></td></tr>';
4232: return $output;
1.23 raeburn 4233: }
4234:
4235: sub sorted_searchtitles {
4236: my %searchtitles = &Apache::lonlocal::texthash(
4237: 'uname' => 'username',
4238: 'lastname' => 'last name',
4239: 'lastfirst' => 'last name, first name',
4240: );
4241: my @titleorder = ('uname','lastname','lastfirst');
4242: return (\%searchtitles,\@titleorder);
4243: }
4244:
1.25 raeburn 4245: sub sorted_searchtypes {
4246: my %srchtypes_desc = (
4247: exact => 'is exact match',
4248: contains => 'contains ..',
4249: begins => 'begins with ..',
4250: );
4251: my @srchtypeorder = ('exact','begins','contains');
4252: return (\%srchtypes_desc,\@srchtypeorder);
4253: }
4254:
1.3 raeburn 4255: sub usertype_update_row {
4256: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4257: my $datatable;
4258: my $numinrow = 4;
4259: foreach my $type (@{$types}) {
4260: if (defined($usertypes->{$type})) {
4261: $$rownums ++;
4262: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4263: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4264: '</td><td class="LC_left_item"><table>';
4265: for (my $i=0; $i<@{$fields}; $i++) {
4266: my $rem = $i%($numinrow);
4267: if ($rem == 0) {
4268: if ($i > 0) {
4269: $datatable .= '</tr>';
4270: }
4271: $datatable .= '<tr>';
4272: }
4273: my $check = ' ';
1.39 raeburn 4274: if (ref($settings) eq 'HASH') {
4275: if (ref($settings->{'fields'}) eq 'HASH') {
4276: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4277: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4278: $check = ' checked="checked" ';
4279: }
1.3 raeburn 4280: }
4281: }
4282: }
4283:
4284: if ($i == @{$fields}-1) {
4285: my $colsleft = $numinrow - $rem;
4286: if ($colsleft > 1) {
4287: $datatable .= '<td colspan="'.$colsleft.'">';
4288: } else {
4289: $datatable .= '<td>';
4290: }
4291: } else {
4292: $datatable .= '<td>';
4293: }
1.8 raeburn 4294: $datatable .= '<span class="LC_nobreak"><label>'.
4295: '<input type="checkbox" name="updateable_'.$type.
4296: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4297: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4298: }
4299: $datatable .= '</tr></table></td></tr>';
4300: }
4301: }
4302: return $datatable;
1.1 raeburn 4303: }
4304:
4305: sub modify_login {
1.9 raeburn 4306: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 4307: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 4308: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 4309: adminmail => 'Display administrator E-mail address',
1.43 raeburn 4310: newuser => 'Link for visitors to create a user account',
1.41 raeburn 4311: loginheader => 'Log-in box header');
1.3 raeburn 4312: my @offon = ('off','on');
1.112 raeburn 4313: my %curr_loginvia;
4314: if (ref($domconfig{login}) eq 'HASH') {
4315: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4316: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4317: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4318: }
4319: }
4320: }
1.6 raeburn 4321: my %loginhash;
1.9 raeburn 4322: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4323: \%domconfig,\%loginhash);
1.118 jms 4324: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4325: foreach my $item (@toggles) {
4326: $loginhash{login}{$item} = $env{'form.'.$item};
4327: }
1.41 raeburn 4328: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4329: if (ref($colchanges{'login'}) eq 'HASH') {
4330: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4331: \%loginhash);
4332: }
1.110 raeburn 4333:
1.149 raeburn 4334: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4335: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4336: if (keys(%servers) > 1) {
4337: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4338: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4339: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4340: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4341: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4342: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4343: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4344: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4345: $changes{'loginvia'}{$lonhost} = 1;
4346: } else {
4347: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4348: $changes{'loginvia'}{$lonhost} = 1;
4349: }
4350: } else {
4351: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4352: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4353: $changes{'loginvia'}{$lonhost} = 1;
4354: }
4355: }
4356: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4357: foreach my $item (@loginvia_attribs) {
4358: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4359: }
4360: } else {
4361: foreach my $item (@loginvia_attribs) {
4362: my $new = $env{'form.'.$lonhost.'_'.$item};
4363: if (($item eq 'serverpath') && ($new eq 'custom')) {
4364: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4365: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4366: $new = '/';
4367: }
4368: }
4369: if (($item eq 'custompath') &&
4370: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4371: $new = '';
4372: }
4373: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4374: $changes{'loginvia'}{$lonhost} = 1;
4375: }
4376: if ($item eq 'exempt') {
4377: $new =~ s/^\s+//;
4378: $new =~ s/\s+$//;
4379: my @poss_ips = split(/\s*[,:]\s*/,$new);
4380: my @okips;
4381: foreach my $ip (@poss_ips) {
4382: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4383: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4384: push(@okips,$ip);
4385: }
4386: }
4387: }
4388: if (@okips > 0) {
4389: $new = join(',',@okips);
4390: } else {
4391: $new = '';
4392: }
4393: }
4394:
4395: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4396: }
4397: }
1.112 raeburn 4398: } else {
1.128 raeburn 4399: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4400: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4401: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4402: foreach my $item (@loginvia_attribs) {
4403: my $new = $env{'form.'.$lonhost.'_'.$item};
4404: if (($item eq 'serverpath') && ($new eq 'custom')) {
4405: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4406: $new = '/';
4407: }
4408: }
4409: if (($item eq 'custompath') &&
4410: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4411: $new = '';
4412: }
4413: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4414: }
1.110 raeburn 4415: }
4416: }
4417: }
4418: }
1.119 raeburn 4419:
1.1 raeburn 4420: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4421: $dom);
4422: if ($putresult eq 'ok') {
1.118 jms 4423: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4424: my %defaultchecked = (
4425: 'coursecatalog' => 'on',
4426: 'adminmail' => 'off',
1.43 raeburn 4427: 'newuser' => 'off',
1.42 raeburn 4428: );
1.55 raeburn 4429: if (ref($domconfig{'login'}) eq 'HASH') {
4430: foreach my $item (@toggles) {
4431: if ($defaultchecked{$item} eq 'on') {
4432: if (($domconfig{'login'}{$item} eq '0') &&
4433: ($env{'form.'.$item} eq '1')) {
4434: $changes{$item} = 1;
4435: } elsif (($domconfig{'login'}{$item} eq '' ||
4436: $domconfig{'login'}{$item} eq '1') &&
4437: ($env{'form.'.$item} eq '0')) {
4438: $changes{$item} = 1;
4439: }
4440: } elsif ($defaultchecked{$item} eq 'off') {
4441: if (($domconfig{'login'}{$item} eq '1') &&
4442: ($env{'form.'.$item} eq '0')) {
4443: $changes{$item} = 1;
4444: } elsif (($domconfig{'login'}{$item} eq '' ||
4445: $domconfig{'login'}{$item} eq '0') &&
4446: ($env{'form.'.$item} eq '1')) {
4447: $changes{$item} = 1;
4448: }
1.42 raeburn 4449: }
4450: }
1.41 raeburn 4451: }
1.6 raeburn 4452: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4453: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4454: $resulttext = &mt('Changes made:').'<ul>';
4455: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4456: if ($item eq 'loginvia') {
1.112 raeburn 4457: if (ref($changes{$item}) eq 'HASH') {
4458: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4459: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4460: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4461: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4462: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4463: $protocol = 'http' if ($protocol ne 'https');
4464: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4465:
4466: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4467: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4468: } else {
4469: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4470: }
4471: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4472: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4473: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4474: }
4475: $resulttext .= '</li>';
4476: } else {
4477: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4478: }
1.112 raeburn 4479: } else {
1.128 raeburn 4480: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4481: }
4482: }
1.128 raeburn 4483: $resulttext .= '</ul></li>';
1.112 raeburn 4484: }
1.41 raeburn 4485: } else {
4486: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4487: }
1.1 raeburn 4488: }
1.6 raeburn 4489: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4490: } else {
4491: $resulttext = &mt('No changes made to log-in page settings');
4492: }
4493: } else {
1.11 albertel 4494: $resulttext = '<span class="LC_error">'.
4495: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4496: }
1.6 raeburn 4497: if ($errors) {
1.9 raeburn 4498: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4499: $errors.'</ul>';
4500: }
4501: return $resulttext;
4502: }
4503:
4504: sub color_font_choices {
4505: my %choices =
4506: &Apache::lonlocal::texthash (
4507: img => "Header",
4508: bgs => "Background colors",
4509: links => "Link colors",
1.55 raeburn 4510: images => "Images",
1.6 raeburn 4511: font => "Font color",
1.97 tempelho 4512: fontmenu => "Font Menu",
1.76 raeburn 4513: pgbg => "Page",
1.6 raeburn 4514: tabbg => "Header",
4515: sidebg => "Border",
4516: link => "Link",
4517: alink => "Active link",
4518: vlink => "Visited link",
4519: );
4520: return %choices;
4521: }
4522:
4523: sub modify_rolecolors {
1.9 raeburn 4524: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4525: my ($resulttext,%rolehash);
4526: $rolehash{'rolecolors'} = {};
1.55 raeburn 4527: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4528: if ($domconfig{'rolecolors'} eq '') {
4529: $domconfig{'rolecolors'} = {};
4530: }
4531: }
1.9 raeburn 4532: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4533: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4534: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4535: $dom);
4536: if ($putresult eq 'ok') {
4537: if (keys(%changes) > 0) {
1.41 raeburn 4538: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4539: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4540: $rolehash{'rolecolors'});
4541: } else {
4542: $resulttext = &mt('No changes made to default color schemes');
4543: }
4544: } else {
1.11 albertel 4545: $resulttext = '<span class="LC_error">'.
4546: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4547: }
4548: if ($errors) {
4549: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4550: $errors.'</ul>';
4551: }
4552: return $resulttext;
4553: }
4554:
4555: sub modify_colors {
1.9 raeburn 4556: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4557: my (%changes,%choices);
1.51 raeburn 4558: my @bgs;
1.6 raeburn 4559: my @links = ('link','alink','vlink');
1.41 raeburn 4560: my @logintext;
1.6 raeburn 4561: my @images;
4562: my $servadm = $r->dir_config('lonAdmEMail');
4563: my $errors;
4564: foreach my $role (@{$roles}) {
4565: if ($role eq 'login') {
1.12 raeburn 4566: %choices = &login_choices();
1.41 raeburn 4567: @logintext = ('textcol','bgcol');
1.12 raeburn 4568: } else {
4569: %choices = &color_font_choices();
1.107 raeburn 4570: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4571: }
4572: if ($role eq 'login') {
1.41 raeburn 4573: @images = ('img','logo','domlogo','login');
1.51 raeburn 4574: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4575: } else {
4576: @images = ('img');
1.51 raeburn 4577: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4578: }
4579: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4580: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4581: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4582: }
1.46 raeburn 4583: my ($configuserok,$author_ok,$switchserver) =
4584: &config_check($dom,$confname,$servadm);
1.9 raeburn 4585: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4586: if (ref($domconfig->{$role}) ne 'HASH') {
4587: $domconfig->{$role} = {};
4588: }
1.8 raeburn 4589: foreach my $img (@images) {
1.70 raeburn 4590: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4591: if (defined($env{'form.login_showlogo_'.$img})) {
4592: $confhash->{$role}{'showlogo'}{$img} = 1;
4593: } else {
4594: $confhash->{$role}{'showlogo'}{$img} = 0;
4595: }
4596: }
1.18 albertel 4597: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4598: && !defined($domconfig->{$role}{$img})
4599: && !$env{'form.'.$role.'_del_'.$img}
4600: && $env{'form.'.$role.'_import_'.$img}) {
4601: # import the old configured image from the .tab setting
4602: # if they haven't provided a new one
4603: $domconfig->{$role}{$img} =
4604: $env{'form.'.$role.'_import_'.$img};
4605: }
1.6 raeburn 4606: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4607: my $error;
1.6 raeburn 4608: if ($configuserok eq 'ok') {
1.9 raeburn 4609: if ($switchserver) {
1.12 raeburn 4610: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4611: } else {
4612: if ($author_ok eq 'ok') {
4613: my ($result,$logourl) =
4614: &publishlogo($r,'upload',$role.'_'.$img,
4615: $dom,$confname,$img,$width,$height);
4616: if ($result eq 'ok') {
4617: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4618: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4619: } else {
1.12 raeburn 4620: $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 4621: }
4622: } else {
1.46 raeburn 4623: $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 4624: }
4625: }
4626: } else {
1.46 raeburn 4627: $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 4628: }
4629: if ($error) {
1.8 raeburn 4630: &Apache::lonnet::logthis($error);
1.11 albertel 4631: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4632: }
4633: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4634: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4635: my $error;
4636: if ($configuserok eq 'ok') {
4637: # is confname an author?
4638: if ($switchserver eq '') {
4639: if ($author_ok eq 'ok') {
4640: my ($result,$logourl) =
4641: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4642: $dom,$confname,$img,$width,$height);
4643: if ($result eq 'ok') {
4644: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4645: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4646: }
4647: }
4648: }
4649: }
1.6 raeburn 4650: }
4651: }
4652: }
4653: if (ref($domconfig) eq 'HASH') {
4654: if (ref($domconfig->{$role}) eq 'HASH') {
4655: foreach my $img (@images) {
4656: if ($domconfig->{$role}{$img} ne '') {
4657: if ($env{'form.'.$role.'_del_'.$img}) {
4658: $confhash->{$role}{$img} = '';
1.12 raeburn 4659: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4660: } else {
1.9 raeburn 4661: if ($confhash->{$role}{$img} eq '') {
4662: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4663: }
1.6 raeburn 4664: }
4665: } else {
4666: if ($env{'form.'.$role.'_del_'.$img}) {
4667: $confhash->{$role}{$img} = '';
1.12 raeburn 4668: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4669: }
4670: }
1.70 raeburn 4671: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4672: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4673: if ($confhash->{$role}{'showlogo'}{$img} ne
4674: $domconfig->{$role}{'showlogo'}{$img}) {
4675: $changes{$role}{'showlogo'}{$img} = 1;
4676: }
4677: } else {
4678: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4679: $changes{$role}{'showlogo'}{$img} = 1;
4680: }
4681: }
4682: }
4683: }
1.6 raeburn 4684: if ($domconfig->{$role}{'font'} ne '') {
4685: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4686: $changes{$role}{'font'} = 1;
4687: }
4688: } else {
4689: if ($confhash->{$role}{'font'}) {
4690: $changes{$role}{'font'} = 1;
4691: }
4692: }
1.107 raeburn 4693: if ($role ne 'login') {
4694: if ($domconfig->{$role}{'fontmenu'} ne '') {
4695: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4696: $changes{$role}{'fontmenu'} = 1;
4697: }
4698: } else {
4699: if ($confhash->{$role}{'fontmenu'}) {
4700: $changes{$role}{'fontmenu'} = 1;
4701: }
1.97 tempelho 4702: }
4703: }
1.6 raeburn 4704: foreach my $item (@bgs) {
4705: if ($domconfig->{$role}{$item} ne '') {
4706: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4707: $changes{$role}{'bgs'}{$item} = 1;
4708: }
4709: } else {
4710: if ($confhash->{$role}{$item}) {
4711: $changes{$role}{'bgs'}{$item} = 1;
4712: }
4713: }
4714: }
4715: foreach my $item (@links) {
4716: if ($domconfig->{$role}{$item} ne '') {
4717: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4718: $changes{$role}{'links'}{$item} = 1;
4719: }
4720: } else {
4721: if ($confhash->{$role}{$item}) {
4722: $changes{$role}{'links'}{$item} = 1;
4723: }
4724: }
4725: }
1.41 raeburn 4726: foreach my $item (@logintext) {
4727: if ($domconfig->{$role}{$item} ne '') {
4728: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4729: $changes{$role}{'logintext'}{$item} = 1;
4730: }
4731: } else {
4732: if ($confhash->{$role}{$item}) {
4733: $changes{$role}{'logintext'}{$item} = 1;
4734: }
4735: }
4736: }
1.6 raeburn 4737: } else {
4738: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4739: \@logintext,$confhash,\%changes);
1.6 raeburn 4740: }
4741: } else {
4742: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4743: \@logintext,$confhash,\%changes);
1.6 raeburn 4744: }
4745: }
4746: return ($errors,%changes);
4747: }
4748:
1.46 raeburn 4749: sub config_check {
4750: my ($dom,$confname,$servadm) = @_;
4751: my ($configuserok,$author_ok,$switchserver,%currroles);
4752: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4753: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4754: $confname,$servadm);
4755: if ($configuserok eq 'ok') {
4756: $switchserver = &check_switchserver($dom,$confname);
4757: if ($switchserver eq '') {
4758: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4759: }
4760: }
4761: return ($configuserok,$author_ok,$switchserver);
4762: }
4763:
1.6 raeburn 4764: sub default_change_checker {
1.41 raeburn 4765: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4766: foreach my $item (@{$links}) {
4767: if ($confhash->{$role}{$item}) {
4768: $changes->{$role}{'links'}{$item} = 1;
4769: }
4770: }
4771: foreach my $item (@{$bgs}) {
4772: if ($confhash->{$role}{$item}) {
4773: $changes->{$role}{'bgs'}{$item} = 1;
4774: }
4775: }
1.41 raeburn 4776: foreach my $item (@{$logintext}) {
4777: if ($confhash->{$role}{$item}) {
4778: $changes->{$role}{'logintext'}{$item} = 1;
4779: }
4780: }
1.6 raeburn 4781: foreach my $img (@{$images}) {
4782: if ($env{'form.'.$role.'_del_'.$img}) {
4783: $confhash->{$role}{$img} = '';
1.12 raeburn 4784: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4785: }
1.70 raeburn 4786: if ($role eq 'login') {
4787: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4788: $changes->{$role}{'showlogo'}{$img} = 1;
4789: }
4790: }
1.6 raeburn 4791: }
4792: if ($confhash->{$role}{'font'}) {
4793: $changes->{$role}{'font'} = 1;
4794: }
1.48 raeburn 4795: }
1.6 raeburn 4796:
4797: sub display_colorchgs {
4798: my ($dom,$changes,$roles,$confhash) = @_;
4799: my (%choices,$resulttext);
4800: if (!grep(/^login$/,@{$roles})) {
4801: $resulttext = &mt('Changes made:').'<br />';
4802: }
4803: foreach my $role (@{$roles}) {
4804: if ($role eq 'login') {
4805: %choices = &login_choices();
4806: } else {
4807: %choices = &color_font_choices();
4808: }
4809: if (ref($changes->{$role}) eq 'HASH') {
4810: if ($role ne 'login') {
4811: $resulttext .= '<h4>'.&mt($role).'</h4>';
4812: }
4813: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4814: if ($role ne 'login') {
4815: $resulttext .= '<ul>';
4816: }
4817: if (ref($changes->{$role}{$key}) eq 'HASH') {
4818: if ($role ne 'login') {
4819: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4820: }
4821: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4822: if (($role eq 'login') && ($key eq 'showlogo')) {
4823: if ($confhash->{$role}{$key}{$item}) {
4824: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4825: } else {
4826: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4827: }
4828: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4829: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4830: } else {
1.12 raeburn 4831: my $newitem = $confhash->{$role}{$item};
4832: if ($key eq 'images') {
4833: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4834: }
4835: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4836: }
4837: }
4838: if ($role ne 'login') {
4839: $resulttext .= '</ul></li>';
4840: }
4841: } else {
4842: if ($confhash->{$role}{$key} eq '') {
4843: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4844: } else {
4845: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4846: }
4847: }
4848: if ($role ne 'login') {
4849: $resulttext .= '</ul>';
4850: }
4851: }
4852: }
4853: }
1.3 raeburn 4854: return $resulttext;
1.1 raeburn 4855: }
4856:
1.9 raeburn 4857: sub thumb_dimensions {
4858: return ('200','50');
4859: }
4860:
1.16 raeburn 4861: sub check_dimensions {
4862: my ($inputfile) = @_;
4863: my ($fullwidth,$fullheight);
4864: if ($inputfile =~ m|^[/\w.\-]+$|) {
4865: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4866: my $imageinfo = <PIPE>;
4867: if (!close(PIPE)) {
4868: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4869: }
4870: chomp($imageinfo);
4871: my ($fullsize) =
1.21 raeburn 4872: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4873: if ($fullsize) {
4874: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4875: }
4876: }
4877: }
4878: return ($fullwidth,$fullheight);
4879: }
4880:
1.9 raeburn 4881: sub check_configuser {
4882: my ($uhome,$dom,$confname,$servadm) = @_;
4883: my ($configuserok,%currroles);
4884: if ($uhome eq 'no_host') {
4885: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4886: my $configpass = &LONCAPA::Enrollment::create_password();
4887: $configuserok =
4888: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4889: $configpass,'','','','','',undef,$servadm);
4890: } else {
4891: $configuserok = 'ok';
4892: %currroles =
4893: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4894: }
4895: return ($configuserok,%currroles);
4896: }
4897:
4898: sub check_authorstatus {
4899: my ($dom,$confname,%currroles) = @_;
4900: my $author_ok;
1.40 raeburn 4901: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4902: my $start = time;
4903: my $end = 0;
4904: $author_ok =
4905: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4906: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4907: } else {
4908: $author_ok = 'ok';
4909: }
4910: return $author_ok;
4911: }
4912:
4913: sub publishlogo {
1.46 raeburn 4914: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4915: my ($output,$fname,$logourl);
4916: if ($action eq 'upload') {
4917: $fname=$env{'form.'.$formname.'.filename'};
4918: chop($env{'form.'.$formname});
4919: } else {
4920: ($fname) = ($formname =~ /([^\/]+)$/);
4921: }
1.46 raeburn 4922: if ($savefileas ne '') {
4923: $fname = $savefileas;
4924: }
1.9 raeburn 4925: $fname=&Apache::lonnet::clean_filename($fname);
4926: # See if there is anything left
4927: unless ($fname) { return ('error: no uploaded file'); }
4928: $fname="$subdir/$fname";
4929: my $filepath='/home/'.$confname.'/public_html';
4930: my ($fnamepath,$file,$fetchthumb);
4931: $file=$fname;
4932: if ($fname=~m|/|) {
4933: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4934: }
4935: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4936: my $count;
4937: for ($count=4;$count<=$#parts;$count++) {
4938: $filepath.="/$parts[$count]";
4939: if ((-e $filepath)!=1) {
4940: mkdir($filepath,02770);
4941: }
4942: }
4943: # Check for bad extension and disallow upload
4944: if ($file=~/\.(\w+)$/ &&
4945: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4946: $output =
4947: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4948: } elsif ($file=~/\.(\w+)$/ &&
4949: !defined(&Apache::loncommon::fileembstyle($1))) {
4950: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4951: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4952: $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 4953: } elsif (-d "$filepath/$file") {
4954: $output = &mt('File name is a directory name - rename the file and re-upload');
4955: } else {
4956: my $source = $filepath.'/'.$file;
4957: my $logfile;
4958: if (!open($logfile,">>$source".'.log')) {
4959: return (&mt('No write permission to Construction Space'));
4960: }
4961: print $logfile
4962: "\n================= Publish ".localtime()." ================\n".
4963: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4964: # Save the file
4965: if (!open(FH,'>'.$source)) {
4966: &Apache::lonnet::logthis('Failed to create '.$source);
4967: return (&mt('Failed to create file'));
4968: }
4969: if ($action eq 'upload') {
4970: if (!print FH ($env{'form.'.$formname})) {
4971: &Apache::lonnet::logthis('Failed to write to '.$source);
4972: return (&mt('Failed to write file'));
4973: }
4974: } else {
4975: my $original = &Apache::lonnet::filelocation('',$formname);
4976: if(!copy($original,$source)) {
4977: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4978: return (&mt('Failed to write file'));
4979: }
4980: }
4981: close(FH);
4982: chmod(0660, $source); # Permissions to rw-rw---.
4983:
4984: my $docroot=$r->dir_config('lonDocRoot');
4985: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4986: my $copyfile=$targetdir.'/'.$file;
4987:
4988: my @parts=split(/\//,$targetdir);
4989: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4990: for (my $count=5;$count<=$#parts;$count++) {
4991: $path.="/$parts[$count]";
4992: if (!-e $path) {
4993: print $logfile "\nCreating directory ".$path;
4994: mkdir($path,02770);
4995: }
4996: }
4997: my $versionresult;
4998: if (-e $copyfile) {
4999: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5000: } else {
5001: $versionresult = 'ok';
5002: }
5003: if ($versionresult eq 'ok') {
5004: if (copy($source,$copyfile)) {
5005: print $logfile "\nCopied original source to ".$copyfile."\n";
5006: $output = 'ok';
5007: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5008: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
5009: } else {
5010: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5011: $output = &mt('Failed to copy file to RES space').", $!";
5012: }
5013: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5014: my $inputfile = $filepath.'/'.$file;
5015: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5016: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5017: if ($fullwidth ne '' && $fullheight ne '') {
5018: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5019: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5020: system("convert -sample $thumbsize $inputfile $outfile");
5021: chmod(0660, $filepath.'/tn-'.$file);
5022: if (-e $outfile) {
5023: my $copyfile=$targetdir.'/tn-'.$file;
5024: if (copy($outfile,$copyfile)) {
5025: print $logfile "\nCopied source to ".$copyfile."\n";
5026: &write_metadata($dom,$confname,$formname,
5027: $targetdir,'tn-'.$file,$logfile);
5028: } else {
5029: print $logfile "\nUnable to write ".$copyfile.
5030: ':'.$!."\n";
5031: }
5032: }
1.9 raeburn 5033: }
5034: }
5035: }
5036: } else {
5037: $output = $versionresult;
5038: }
5039: }
5040: return ($output,$logourl);
5041: }
5042:
5043: sub logo_versioning {
5044: my ($targetdir,$file,$logfile) = @_;
5045: my $target = $targetdir.'/'.$file;
5046: my ($maxversion,$fn,$extn,$output);
5047: $maxversion = 0;
5048: if ($file =~ /^(.+)\.(\w+)$/) {
5049: $fn=$1;
5050: $extn=$2;
5051: }
5052: opendir(DIR,$targetdir);
5053: while (my $filename=readdir(DIR)) {
5054: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5055: $maxversion=($1>$maxversion)?$1:$maxversion;
5056: }
5057: }
5058: $maxversion++;
5059: print $logfile "\nCreating old version ".$maxversion."\n";
5060: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5061: if (copy($target,$copyfile)) {
5062: print $logfile "Copied old target to ".$copyfile."\n";
5063: $copyfile=$copyfile.'.meta';
5064: if (copy($target.'.meta',$copyfile)) {
5065: print $logfile "Copied old target metadata to ".$copyfile."\n";
5066: $output = 'ok';
5067: } else {
5068: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5069: $output = &mt('Failed to copy old meta').", $!, ";
5070: }
5071: } else {
5072: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5073: $output = &mt('Failed to copy old target').", $!, ";
5074: }
5075: return $output;
5076: }
5077:
5078: sub write_metadata {
5079: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5080: my (%metadatafields,%metadatakeys,$output);
5081: $metadatafields{'title'}=$formname;
5082: $metadatafields{'creationdate'}=time;
5083: $metadatafields{'lastrevisiondate'}=time;
5084: $metadatafields{'copyright'}='public';
5085: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5086: $env{'user.domain'};
5087: $metadatafields{'authorspace'}=$confname.':'.$dom;
5088: $metadatafields{'domain'}=$dom;
5089: {
5090: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5091: my $mfh;
5092: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5093: $output = &mt('Could not write metadata');
5094: }
5095: foreach (sort keys %metadatafields) {
5096: unless ($_=~/\./) {
5097: my $unikey=$_;
5098: $unikey=~/^([A-Za-z]+)/;
5099: my $tag=$1;
5100: $tag=~tr/A-Z/a-z/;
5101: print $mfh "\n\<$tag";
5102: foreach (split(/\,/,$metadatakeys{$unikey})) {
5103: my $value=$metadatafields{$unikey.'.'.$_};
5104: $value=~s/\"/\'\'/g;
5105: print $mfh ' '.$_.'="'.$value.'"';
5106: }
5107: print $mfh '>'.
5108: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5109: .'</'.$tag.'>';
5110: }
5111: }
5112: $output = 'ok';
5113: print $logfile "\nWrote metadata";
5114: close($mfh);
5115: }
5116: }
5117:
5118: sub check_switchserver {
5119: my ($dom,$confname) = @_;
5120: my ($allowed,$switchserver);
5121: my $home = &Apache::lonnet::homeserver($confname,$dom);
5122: if ($home eq 'no_host') {
5123: $home = &Apache::lonnet::domain($dom,'primary');
5124: }
5125: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5126: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5127: if (!$allowed) {
5128: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5129: }
5130: return $switchserver;
5131: }
5132:
1.1 raeburn 5133: sub modify_quotas {
1.86 raeburn 5134: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5135: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5136: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5137: if ($action eq 'quotas') {
5138: $context = 'tools';
5139: } else {
5140: $context = $action;
5141: }
5142: if ($context eq 'requestcourses') {
1.98 raeburn 5143: @usertools = ('official','unofficial','community');
1.106 raeburn 5144: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5145: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5146: %titles = &courserequest_titles();
5147: $toolregexp = join('|',@usertools);
5148: %conditions = &courserequest_conditions();
1.86 raeburn 5149: } else {
5150: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 5151: %titles = &tool_titles();
1.86 raeburn 5152: }
1.72 raeburn 5153: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5154: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5155: foreach my $key (keys(%env)) {
1.101 raeburn 5156: if ($context eq 'requestcourses') {
5157: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5158: my $item = $1;
5159: my $type = $2;
5160: if ($type =~ /^limit_(.+)/) {
5161: $limithash{$item}{$1} = $env{$key};
5162: } else {
5163: $confhash{$item}{$type} = $env{$key};
5164: }
5165: }
5166: } else {
1.86 raeburn 5167: if ($key =~ /^form\.quota_(.+)$/) {
5168: $confhash{'defaultquota'}{$1} = $env{$key};
5169: }
1.101 raeburn 5170: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5171: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5172: }
1.72 raeburn 5173: }
5174: }
1.102 raeburn 5175: if ($context eq 'requestcourses') {
5176: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5177: @approvalnotify = sort(@approvalnotify);
5178: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5179: if (ref($domconfig{$action}) eq 'HASH') {
5180: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5181: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5182: $changes{'notify'}{'approval'} = 1;
5183: }
5184: } else {
1.144 raeburn 5185: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5186: $changes{'notify'}{'approval'} = 1;
5187: }
5188: }
5189: } else {
1.144 raeburn 5190: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5191: $changes{'notify'}{'approval'} = 1;
5192: }
5193: }
5194: } else {
1.86 raeburn 5195: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5196: }
1.72 raeburn 5197: foreach my $item (@usertools) {
5198: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5199: my $unset;
1.101 raeburn 5200: if ($context eq 'requestcourses') {
1.104 raeburn 5201: $unset = '0';
5202: if ($type eq '_LC_adv') {
5203: $unset = '';
5204: }
1.101 raeburn 5205: if ($confhash{$item}{$type} eq 'autolimit') {
5206: $confhash{$item}{$type} .= '=';
5207: unless ($limithash{$item}{$type} =~ /\D/) {
5208: $confhash{$item}{$type} .= $limithash{$item}{$type};
5209: }
5210: }
1.72 raeburn 5211: } else {
1.101 raeburn 5212: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5213: $confhash{$item}{$type} = 1;
5214: } else {
5215: $confhash{$item}{$type} = 0;
5216: }
1.72 raeburn 5217: }
1.86 raeburn 5218: if (ref($domconfig{$action}) eq 'HASH') {
5219: if (ref($domconfig{$action}{$item}) eq 'HASH') {
5220: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5221: $changes{$item}{$type} = 1;
5222: }
5223: } else {
5224: if ($context eq 'requestcourses') {
1.104 raeburn 5225: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5226: $changes{$item}{$type} = 1;
5227: }
5228: } else {
5229: if (!$confhash{$item}{$type}) {
5230: $changes{$item}{$type} = 1;
5231: }
5232: }
5233: }
5234: } else {
5235: if ($context eq 'requestcourses') {
1.104 raeburn 5236: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5237: $changes{$item}{$type} = 1;
5238: }
5239: } else {
5240: if (!$confhash{$item}{$type}) {
5241: $changes{$item}{$type} = 1;
5242: }
5243: }
5244: }
1.1 raeburn 5245: }
5246: }
1.86 raeburn 5247: unless ($context eq 'requestcourses') {
5248: if (ref($domconfig{'quotas'}) eq 'HASH') {
5249: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5250: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5251: if (exists($confhash{'defaultquota'}{$key})) {
5252: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5253: $changes{'defaultquota'}{$key} = 1;
5254: }
5255: } else {
5256: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5257: }
5258: }
1.86 raeburn 5259: } else {
5260: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5261: if (exists($confhash{'defaultquota'}{$key})) {
5262: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5263: $changes{'defaultquota'}{$key} = 1;
5264: }
5265: } else {
5266: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5267: }
1.1 raeburn 5268: }
5269: }
5270: }
1.86 raeburn 5271: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5272: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5273: if (ref($domconfig{'quotas'}) eq 'HASH') {
5274: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5275: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5276: $changes{'defaultquota'}{$key} = 1;
5277: }
5278: } else {
5279: if (!exists($domconfig{'quotas'}{$key})) {
5280: $changes{'defaultquota'}{$key} = 1;
5281: }
1.72 raeburn 5282: }
5283: } else {
1.86 raeburn 5284: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5285: }
1.1 raeburn 5286: }
5287: }
5288: }
1.72 raeburn 5289:
5290: foreach my $key (keys(%confhash)) {
5291: $domdefaults{$key} = $confhash{$key};
5292: }
5293:
1.1 raeburn 5294: my %quotahash = (
1.86 raeburn 5295: $action => { %confhash }
1.1 raeburn 5296: );
5297: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5298: $dom);
5299: if ($putresult eq 'ok') {
5300: if (keys(%changes) > 0) {
1.72 raeburn 5301: my $cachetime = 24*60*60;
5302: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5303:
1.1 raeburn 5304: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 5305: unless ($context eq 'requestcourses') {
5306: if (ref($changes{'defaultquota'}) eq 'HASH') {
5307: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5308: foreach my $type (@{$types},'default') {
5309: if (defined($changes{'defaultquota'}{$type})) {
5310: my $typetitle = $usertypes->{$type};
5311: if ($type eq 'default') {
5312: $typetitle = $othertitle;
5313: }
5314: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5315: }
5316: }
1.86 raeburn 5317: $resulttext .= '</ul></li>';
1.72 raeburn 5318: }
5319: }
1.80 raeburn 5320: my %newenv;
1.72 raeburn 5321: foreach my $item (@usertools) {
5322: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 5323: my $newacc =
5324: &Apache::lonnet::usertools_access($env{'user.name'},
5325: $env{'user.domain'},
1.86 raeburn 5326: $item,'reload',$context);
5327: if ($context eq 'requestcourses') {
1.108 raeburn 5328: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5329: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5330: }
5331: } else {
5332: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5333: $newenv{'environment.availabletools.'.$item} = $newacc;
5334: }
1.80 raeburn 5335: }
1.72 raeburn 5336: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5337: foreach my $type (@{$types},'default','_LC_adv') {
5338: if ($changes{$item}{$type}) {
5339: my $typetitle = $usertypes->{$type};
5340: if ($type eq 'default') {
5341: $typetitle = $othertitle;
5342: } elsif ($type eq '_LC_adv') {
5343: $typetitle = 'LON-CAPA Advanced Users';
5344: }
5345: if ($confhash{$item}{$type}) {
1.101 raeburn 5346: if ($context eq 'requestcourses') {
5347: my $cond;
5348: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
5349: if ($1 eq '') {
5350: $cond = &mt('(Automatic processing of any request).');
5351: } else {
5352: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5353: }
5354: } else {
5355: $cond = $conditions{$confhash{$item}{$type}};
5356: }
5357: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
5358: } else {
5359: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5360: }
1.72 raeburn 5361: } else {
1.104 raeburn 5362: if ($type eq '_LC_adv') {
5363: if ($confhash{$item}{$type} eq '0') {
5364: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5365: } else {
5366: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5367: }
5368: } else {
5369: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5370: }
1.72 raeburn 5371: }
5372: }
1.26 raeburn 5373: }
1.72 raeburn 5374: $resulttext .= '</ul></li>';
1.26 raeburn 5375: }
1.1 raeburn 5376: }
1.102 raeburn 5377: if ($action eq 'requestcourses') {
5378: if (ref($changes{'notify'}) eq 'HASH') {
5379: if ($changes{'notify'}{'approval'}) {
5380: if (ref($confhash{'notify'}) eq 'HASH') {
5381: if ($confhash{'notify'}{'approval'}) {
5382: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5383: } else {
5384: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
5385: }
5386: }
5387: }
5388: }
5389: }
1.1 raeburn 5390: $resulttext .= '</ul>';
1.80 raeburn 5391: if (keys(%newenv)) {
5392: &Apache::lonnet::appenv(\%newenv);
5393: }
1.1 raeburn 5394: } else {
1.86 raeburn 5395: if ($context eq 'requestcourses') {
5396: $resulttext = &mt('No changes made to rights to request creation of courses.');
5397: } else {
1.90 weissno 5398: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5399: }
1.1 raeburn 5400: }
5401: } else {
1.11 albertel 5402: $resulttext = '<span class="LC_error">'.
5403: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5404: }
1.3 raeburn 5405: return $resulttext;
1.1 raeburn 5406: }
5407:
1.3 raeburn 5408: sub modify_autoenroll {
5409: my ($dom,%domconfig) = @_;
1.1 raeburn 5410: my ($resulttext,%changes);
5411: my %currautoenroll;
5412: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5413: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5414: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5415: }
5416: }
5417: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
5418: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 5419: sender => 'Sender for notification messages',
5420: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 5421: my @offon = ('off','on');
1.17 raeburn 5422: my $sender_uname = $env{'form.sender_uname'};
5423: my $sender_domain = $env{'form.sender_domain'};
5424: if ($sender_domain eq '') {
5425: $sender_uname = '';
5426: } elsif ($sender_uname eq '') {
5427: $sender_domain = '';
5428: }
1.129 raeburn 5429: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 5430: my %autoenrollhash = (
1.129 raeburn 5431: autoenroll => { 'run' => $env{'form.autoenroll_run'},
5432: 'sender_uname' => $sender_uname,
5433: 'sender_domain' => $sender_domain,
5434: 'co-owners' => $coowners,
1.1 raeburn 5435: }
5436: );
1.4 raeburn 5437: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
5438: $dom);
1.1 raeburn 5439: if ($putresult eq 'ok') {
5440: if (exists($currautoenroll{'run'})) {
5441: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
5442: $changes{'run'} = 1;
5443: }
5444: } elsif ($autorun) {
5445: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 5446: $changes{'run'} = 1;
1.1 raeburn 5447: }
5448: }
1.17 raeburn 5449: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 5450: $changes{'sender'} = 1;
5451: }
1.17 raeburn 5452: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 5453: $changes{'sender'} = 1;
5454: }
1.129 raeburn 5455: if ($currautoenroll{'co-owners'} ne '') {
5456: if ($currautoenroll{'co-owners'} ne $coowners) {
5457: $changes{'coowners'} = 1;
5458: }
5459: } elsif ($coowners) {
5460: $changes{'coowners'} = 1;
5461: }
1.1 raeburn 5462: if (keys(%changes) > 0) {
5463: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5464: if ($changes{'run'}) {
1.1 raeburn 5465: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5466: }
5467: if ($changes{'sender'}) {
1.17 raeburn 5468: if ($sender_uname eq '' || $sender_domain eq '') {
5469: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5470: } else {
5471: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5472: }
1.1 raeburn 5473: }
1.129 raeburn 5474: if ($changes{'coowners'}) {
5475: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5476: &Apache::loncommon::devalidate_domconfig_cache($dom);
5477: }
1.1 raeburn 5478: $resulttext .= '</ul>';
5479: } else {
5480: $resulttext = &mt('No changes made to auto-enrollment settings');
5481: }
5482: } else {
1.11 albertel 5483: $resulttext = '<span class="LC_error">'.
5484: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5485: }
1.3 raeburn 5486: return $resulttext;
1.1 raeburn 5487: }
5488:
5489: sub modify_autoupdate {
1.3 raeburn 5490: my ($dom,%domconfig) = @_;
1.1 raeburn 5491: my ($resulttext,%currautoupdate,%fields,%changes);
5492: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5493: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5494: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5495: }
5496: }
5497: my @offon = ('off','on');
5498: my %title = &Apache::lonlocal::texthash (
5499: run => 'Auto-update:',
5500: classlists => 'Updates to user information in classlists?'
5501: );
1.44 raeburn 5502: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5503: my %fieldtitles = &Apache::lonlocal::texthash (
5504: id => 'Student/Employee ID',
1.20 raeburn 5505: permanentemail => 'E-mail address',
1.1 raeburn 5506: lastname => 'Last Name',
5507: firstname => 'First Name',
5508: middlename => 'Middle Name',
1.132 raeburn 5509: generation => 'Generation',
1.1 raeburn 5510: );
1.142 raeburn 5511: $othertitle = &mt('All users');
1.1 raeburn 5512: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5513: $othertitle = &mt('Other users');
1.1 raeburn 5514: }
5515: foreach my $key (keys(%env)) {
5516: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5517: my ($usertype,$item) = ($1,$2);
5518: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5519: if ($usertype eq 'default') {
5520: push(@{$fields{$1}},$2);
5521: } elsif (ref($types) eq 'ARRAY') {
5522: if (grep(/^\Q$usertype\E$/,@{$types})) {
5523: push(@{$fields{$1}},$2);
5524: }
5525: }
5526: }
1.1 raeburn 5527: }
5528: }
1.131 raeburn 5529: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5530: @lockablenames = sort(@lockablenames);
5531: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5532: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5533: if (@changed) {
5534: $changes{'lockablenames'} = 1;
5535: }
5536: } else {
5537: if (@lockablenames) {
5538: $changes{'lockablenames'} = 1;
5539: }
5540: }
1.1 raeburn 5541: my %updatehash = (
5542: autoupdate => { run => $env{'form.autoupdate_run'},
5543: classlists => $env{'form.classlists'},
5544: fields => {%fields},
1.131 raeburn 5545: lockablenames => \@lockablenames,
1.1 raeburn 5546: }
5547: );
5548: foreach my $key (keys(%currautoupdate)) {
5549: if (($key eq 'run') || ($key eq 'classlists')) {
5550: if (exists($updatehash{autoupdate}{$key})) {
5551: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5552: $changes{$key} = 1;
5553: }
5554: }
5555: } elsif ($key eq 'fields') {
5556: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5557: foreach my $item (@{$types},'default') {
1.1 raeburn 5558: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5559: my $change = 0;
5560: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5561: if (!exists($fields{$item})) {
5562: $change = 1;
1.132 raeburn 5563: last;
1.1 raeburn 5564: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5565: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5566: $change = 1;
1.132 raeburn 5567: last;
1.1 raeburn 5568: }
5569: }
5570: }
5571: if ($change) {
5572: push(@{$changes{$key}},$item);
5573: }
1.26 raeburn 5574: }
1.1 raeburn 5575: }
5576: }
1.131 raeburn 5577: } elsif ($key eq 'lockablenames') {
5578: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5579: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5580: if (@changed) {
5581: $changes{'lockablenames'} = 1;
5582: }
5583: } else {
5584: if (@lockablenames) {
5585: $changes{'lockablenames'} = 1;
5586: }
5587: }
5588: }
5589: }
5590: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5591: if (@lockablenames) {
5592: $changes{'lockablenames'} = 1;
1.1 raeburn 5593: }
5594: }
1.26 raeburn 5595: foreach my $item (@{$types},'default') {
5596: if (defined($fields{$item})) {
5597: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5598: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5599: my $change = 0;
5600: if (ref($fields{$item}) eq 'ARRAY') {
5601: foreach my $type (@{$fields{$item}}) {
5602: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5603: $change = 1;
5604: last;
5605: }
5606: }
5607: }
5608: if ($change) {
5609: push(@{$changes{'fields'}},$item);
5610: }
5611: } else {
1.26 raeburn 5612: push(@{$changes{'fields'}},$item);
5613: }
5614: } else {
5615: push(@{$changes{'fields'}},$item);
1.1 raeburn 5616: }
5617: }
5618: }
5619: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5620: $dom);
5621: if ($putresult eq 'ok') {
5622: if (keys(%changes) > 0) {
5623: $resulttext = &mt('Changes made:').'<ul>';
5624: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5625: if ($key eq 'lockablenames') {
5626: $resulttext .= '<li>';
5627: if (@lockablenames) {
5628: $usertypes->{'default'} = $othertitle;
5629: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5630: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5631: } else {
5632: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5633: }
5634: $resulttext .= '</li>';
5635: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5636: foreach my $item (@{$changes{$key}}) {
5637: my @newvalues;
5638: foreach my $type (@{$fields{$item}}) {
5639: push(@newvalues,$fieldtitles{$type});
5640: }
1.3 raeburn 5641: my $newvaluestr;
5642: if (@newvalues > 0) {
5643: $newvaluestr = join(', ',@newvalues);
5644: } else {
5645: $newvaluestr = &mt('none');
1.6 raeburn 5646: }
1.1 raeburn 5647: if ($item eq 'default') {
1.26 raeburn 5648: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5649: } else {
1.26 raeburn 5650: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5651: }
5652: }
5653: } else {
5654: my $newvalue;
5655: if ($key eq 'run') {
5656: $newvalue = $offon[$env{'form.autoupdate_run'}];
5657: } else {
5658: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5659: }
1.1 raeburn 5660: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5661: }
5662: }
5663: $resulttext .= '</ul>';
5664: } else {
1.3 raeburn 5665: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5666: }
5667: } else {
1.11 albertel 5668: $resulttext = '<span class="LC_error">'.
5669: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5670: }
1.3 raeburn 5671: return $resulttext;
1.1 raeburn 5672: }
5673:
1.125 raeburn 5674: sub modify_autocreate {
5675: my ($dom,%domconfig) = @_;
5676: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5677: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5678: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5679: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5680: }
5681: }
5682: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5683: req => 'Auto-creation of validated requests for official courses',
5684: xmldc => 'Identity of course creator of courses from XML files',
5685: );
5686: my @types = ('xml','req');
5687: foreach my $item (@types) {
5688: $newvals{$item} = $env{'form.autocreate_'.$item};
5689: $newvals{$item} =~ s/\D//g;
5690: $newvals{$item} = 0 if ($newvals{$item} eq '');
5691: }
5692: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5693: my %domcoords = &get_active_dcs($dom);
5694: unless (exists($domcoords{$newvals{'xmldc'}})) {
5695: $newvals{'xmldc'} = '';
5696: }
5697: %autocreatehash = (
5698: autocreate => { xml => $newvals{'xml'},
5699: req => $newvals{'req'},
5700: }
5701: );
5702: if ($newvals{'xmldc'} ne '') {
5703: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5704: }
5705: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5706: $dom);
5707: if ($putresult eq 'ok') {
5708: my @items = @types;
5709: if ($newvals{'xml'}) {
5710: push(@items,'xmldc');
5711: }
5712: foreach my $item (@items) {
5713: if (exists($currautocreate{$item})) {
5714: if ($currautocreate{$item} ne $newvals{$item}) {
5715: $changes{$item} = 1;
5716: }
5717: } elsif ($newvals{$item}) {
5718: $changes{$item} = 1;
5719: }
5720: }
5721: if (keys(%changes) > 0) {
5722: my @offon = ('off','on');
5723: $resulttext = &mt('Changes made:').'<ul>';
5724: foreach my $item (@types) {
5725: if ($changes{$item}) {
5726: my $newtxt = $offon[$newvals{$item}];
5727: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5728: }
5729: }
5730: if ($changes{'xmldc'}) {
5731: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5732: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5733: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5734: }
5735: $resulttext .= '</ul>';
5736: } else {
5737: $resulttext = &mt('No changes made to auto-creation settings');
5738: }
5739: } else {
5740: $resulttext = '<span class="LC_error">'.
5741: &mt('An error occurred: [_1]',$putresult).'</span>';
5742: }
5743: return $resulttext;
5744: }
5745:
1.23 raeburn 5746: sub modify_directorysrch {
5747: my ($dom,%domconfig) = @_;
5748: my ($resulttext,%changes);
5749: my %currdirsrch;
5750: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5751: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5752: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5753: }
5754: }
5755: my %title = ( available => 'Directory search available',
1.24 raeburn 5756: localonly => 'Other domains can search',
1.23 raeburn 5757: searchby => 'Search types',
5758: searchtypes => 'Search latitude');
5759: my @offon = ('off','on');
1.24 raeburn 5760: my @otherdoms = ('Yes','No');
1.23 raeburn 5761:
1.25 raeburn 5762: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5763: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5764: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5765:
1.44 raeburn 5766: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5767: if (keys(%{$usertypes}) == 0) {
5768: @cansearch = ('default');
5769: } else {
5770: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5771: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5772: if (!grep(/^\Q$type\E$/,@cansearch)) {
5773: push(@{$changes{'cansearch'}},$type);
5774: }
1.23 raeburn 5775: }
1.26 raeburn 5776: foreach my $type (@cansearch) {
5777: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5778: push(@{$changes{'cansearch'}},$type);
5779: }
1.23 raeburn 5780: }
1.26 raeburn 5781: } else {
5782: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5783: }
5784: }
5785:
5786: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5787: foreach my $by (@{$currdirsrch{'searchby'}}) {
5788: if (!grep(/^\Q$by\E$/,@searchby)) {
5789: push(@{$changes{'searchby'}},$by);
5790: }
5791: }
5792: foreach my $by (@searchby) {
5793: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5794: push(@{$changes{'searchby'}},$by);
5795: }
5796: }
5797: } else {
5798: push(@{$changes{'searchby'}},@searchby);
5799: }
1.25 raeburn 5800:
5801: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5802: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5803: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5804: push(@{$changes{'searchtypes'}},$type);
5805: }
5806: }
5807: foreach my $type (@searchtypes) {
5808: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5809: push(@{$changes{'searchtypes'}},$type);
5810: }
5811: }
5812: } else {
5813: if (exists($currdirsrch{'searchtypes'})) {
5814: foreach my $type (@searchtypes) {
5815: if ($type ne $currdirsrch{'searchtypes'}) {
5816: push(@{$changes{'searchtypes'}},$type);
5817: }
5818: }
5819: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5820: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5821: }
5822: } else {
5823: push(@{$changes{'searchtypes'}},@searchtypes);
5824: }
5825: }
5826:
1.23 raeburn 5827: my %dirsrch_hash = (
5828: directorysrch => { available => $env{'form.dirsrch_available'},
5829: cansearch => \@cansearch,
1.24 raeburn 5830: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5831: searchby => \@searchby,
1.25 raeburn 5832: searchtypes => \@searchtypes,
1.23 raeburn 5833: }
5834: );
5835: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5836: $dom);
5837: if ($putresult eq 'ok') {
5838: if (exists($currdirsrch{'available'})) {
5839: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5840: $changes{'available'} = 1;
5841: }
5842: } else {
5843: if ($env{'form.dirsrch_available'} eq '1') {
5844: $changes{'available'} = 1;
5845: }
5846: }
1.24 raeburn 5847: if (exists($currdirsrch{'localonly'})) {
5848: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5849: $changes{'localonly'} = 1;
5850: }
5851: } else {
5852: if ($env{'form.dirsrch_localonly'} eq '1') {
5853: $changes{'localonly'} = 1;
5854: }
5855: }
1.23 raeburn 5856: if (keys(%changes) > 0) {
5857: $resulttext = &mt('Changes made:').'<ul>';
5858: if ($changes{'available'}) {
5859: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5860: }
1.24 raeburn 5861: if ($changes{'localonly'}) {
5862: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5863: }
5864:
1.23 raeburn 5865: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5866: my $chgtext;
1.26 raeburn 5867: if (ref($usertypes) eq 'HASH') {
5868: if (keys(%{$usertypes}) > 0) {
5869: foreach my $type (@{$types}) {
5870: if (grep(/^\Q$type\E$/,@cansearch)) {
5871: $chgtext .= $usertypes->{$type}.'; ';
5872: }
5873: }
5874: if (grep(/^default$/,@cansearch)) {
5875: $chgtext .= $othertitle;
5876: } else {
5877: $chgtext =~ s/\; $//;
5878: }
5879: $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 5880: }
5881: }
5882: }
5883: if (ref($changes{'searchby'}) eq 'ARRAY') {
5884: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5885: my $chgtext;
5886: foreach my $type (@{$titleorder}) {
5887: if (grep(/^\Q$type\E$/,@searchby)) {
5888: if (defined($searchtitles->{$type})) {
5889: $chgtext .= $searchtitles->{$type}.'; ';
5890: }
5891: }
5892: }
5893: $chgtext =~ s/\; $//;
5894: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5895: }
1.25 raeburn 5896: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5897: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5898: my $chgtext;
5899: foreach my $type (@{$srchtypeorder}) {
5900: if (grep(/^\Q$type\E$/,@searchtypes)) {
5901: if (defined($srchtypes_desc->{$type})) {
5902: $chgtext .= $srchtypes_desc->{$type}.'; ';
5903: }
5904: }
5905: }
5906: $chgtext =~ s/\; $//;
5907: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5908: }
5909: $resulttext .= '</ul>';
5910: } else {
5911: $resulttext = &mt('No changes made to institution directory search settings');
5912: }
5913: } else {
5914: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5915: &mt('An error occurred: [_1]',$putresult).'</span>';
5916: }
5917: return $resulttext;
5918: }
5919:
1.28 raeburn 5920: sub modify_contacts {
5921: my ($dom,%domconfig) = @_;
5922: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5923: if (ref($domconfig{'contacts'}) eq 'HASH') {
5924: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5925: $currsetting{$key} = $domconfig{'contacts'}{$key};
5926: }
5927: }
1.134 raeburn 5928: my (%others,%to,%bcc);
1.28 raeburn 5929: my @contacts = ('supportemail','adminemail');
1.102 raeburn 5930: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5931: 'requestsmail');
1.28 raeburn 5932: foreach my $type (@mailings) {
5933: @{$newsetting{$type}} =
5934: &Apache::loncommon::get_env_multiple('form.'.$type);
5935: foreach my $item (@contacts) {
5936: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5937: $contacts_hash{contacts}{$type}{$item} = 1;
5938: } else {
5939: $contacts_hash{contacts}{$type}{$item} = 0;
5940: }
5941: }
5942: $others{$type} = $env{'form.'.$type.'_others'};
5943: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 5944: if ($type eq 'helpdeskmail') {
5945: $bcc{$type} = $env{'form.'.$type.'_bcc'};
5946: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
5947: }
1.28 raeburn 5948: }
5949: foreach my $item (@contacts) {
5950: $to{$item} = $env{'form.'.$item};
5951: $contacts_hash{'contacts'}{$item} = $to{$item};
5952: }
5953: if (keys(%currsetting) > 0) {
5954: foreach my $item (@contacts) {
5955: if ($to{$item} ne $currsetting{$item}) {
5956: $changes{$item} = 1;
5957: }
5958: }
5959: foreach my $type (@mailings) {
5960: foreach my $item (@contacts) {
5961: if (ref($currsetting{$type}) eq 'HASH') {
5962: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
5963: push(@{$changes{$type}},$item);
5964: }
5965: } else {
5966: push(@{$changes{$type}},@{$newsetting{$type}});
5967: }
5968: }
5969: if ($others{$type} ne $currsetting{$type}{'others'}) {
5970: push(@{$changes{$type}},'others');
5971: }
1.134 raeburn 5972: if ($type eq 'helpdeskmail') {
5973: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
5974: push(@{$changes{$type}},'bcc');
5975: }
5976: }
1.28 raeburn 5977: }
5978: } else {
5979: my %default;
5980: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
5981: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
5982: $default{'errormail'} = 'adminemail';
5983: $default{'packagesmail'} = 'adminemail';
5984: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 5985: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 5986: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 5987: foreach my $item (@contacts) {
5988: if ($to{$item} ne $default{$item}) {
5989: $changes{$item} = 1;
5990: }
5991: }
5992: foreach my $type (@mailings) {
5993: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
5994:
5995: push(@{$changes{$type}},@{$newsetting{$type}});
5996: }
5997: if ($others{$type} ne '') {
5998: push(@{$changes{$type}},'others');
1.134 raeburn 5999: }
6000: if ($type eq 'helpdeskmail') {
6001: if ($bcc{$type} ne '') {
6002: push(@{$changes{$type}},'bcc');
6003: }
6004: }
1.28 raeburn 6005: }
6006: }
6007: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6008: $dom);
6009: if ($putresult eq 'ok') {
6010: if (keys(%changes) > 0) {
6011: my ($titles,$short_titles) = &contact_titles();
6012: $resulttext = &mt('Changes made:').'<ul>';
6013: foreach my $item (@contacts) {
6014: if ($changes{$item}) {
6015: $resulttext .= '<li>'.$titles->{$item}.
6016: &mt(' set to: ').
6017: '<span class="LC_cusr_emph">'.
6018: $to{$item}.'</span></li>';
6019: }
6020: }
6021: foreach my $type (@mailings) {
6022: if (ref($changes{$type}) eq 'ARRAY') {
6023: $resulttext .= '<li>'.$titles->{$type}.': ';
6024: my @text;
6025: foreach my $item (@{$newsetting{$type}}) {
6026: push(@text,$short_titles->{$item});
6027: }
6028: if ($others{$type} ne '') {
6029: push(@text,$others{$type});
6030: }
6031: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6032: join(', ',@text).'</span>';
6033: if ($type eq 'helpdeskmail') {
6034: if ($bcc{$type} ne '') {
6035: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6036: }
6037: }
6038: $resulttext .= '</li>';
1.28 raeburn 6039: }
6040: }
6041: $resulttext .= '</ul>';
6042: } else {
1.34 raeburn 6043: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6044: }
6045: } else {
6046: $resulttext = '<span class="LC_error">'.
6047: &mt('An error occurred: [_1].',$putresult).'</span>';
6048: }
6049: return $resulttext;
6050: }
6051:
6052: sub modify_usercreation {
1.27 raeburn 6053: my ($dom,%domconfig) = @_;
1.34 raeburn 6054: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6055: my $warningmsg;
1.27 raeburn 6056: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6057: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6058: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6059: }
6060: }
6061: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6062: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6063: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6064: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6065: foreach my $item(@contexts) {
1.45 raeburn 6066: if ($item eq 'selfcreate') {
1.50 raeburn 6067: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6068: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6069: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6070: if (ref($cancreate{$item}) eq 'ARRAY') {
6071: if (grep(/^login$/,@{$cancreate{$item}})) {
6072: $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.');
6073: }
1.43 raeburn 6074: }
6075: }
1.50 raeburn 6076: } else {
6077: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6078: }
1.34 raeburn 6079: }
1.93 raeburn 6080: my ($othertitle,$usertypes,$types) =
6081: &Apache::loncommon::sorted_inst_types($dom);
6082: if (ref($types) eq 'ARRAY') {
6083: if (@{$types} > 0) {
6084: @{$cancreate{'statustocreate'}} =
6085: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6086: } else {
6087: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6088: }
6089: push(@contexts,'statustocreate');
6090: }
1.34 raeburn 6091: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6092: foreach my $item (@contexts) {
1.93 raeburn 6093: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6094: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6095: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6096: if (ref($cancreate{$item}) eq 'ARRAY') {
6097: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6098: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6099: push(@{$changes{'cancreate'}},$item);
6100: }
1.50 raeburn 6101: }
6102: }
6103: }
6104: } else {
6105: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6106: if (@{$cancreate{$item}} > 0) {
6107: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6108: push(@{$changes{'cancreate'}},$item);
6109: }
6110: }
6111: } else {
6112: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6113: if (@{$cancreate{$item}} < 3) {
6114: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6115: push(@{$changes{'cancreate'}},$item);
6116: }
6117: }
6118: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6119: if (@{$cancreate{$item}} > 0) {
6120: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6121: push(@{$changes{'cancreate'}},$item);
6122: }
6123: }
6124: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6125: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6126: push(@{$changes{'cancreate'}},$item);
6127: }
6128: }
6129: }
6130: }
6131: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6132: foreach my $type (@{$cancreate{$item}}) {
6133: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6134: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6135: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6136: push(@{$changes{'cancreate'}},$item);
6137: }
6138: }
6139: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6140: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6141: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6142: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6143: push(@{$changes{'cancreate'}},$item);
6144: }
6145: }
6146: }
6147: }
6148: }
6149: } else {
6150: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6151: push(@{$changes{'cancreate'}},$item);
6152: }
6153: }
1.27 raeburn 6154: }
1.34 raeburn 6155: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6156: foreach my $item (@contexts) {
1.43 raeburn 6157: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6158: if ($cancreate{$item} ne 'any') {
6159: push(@{$changes{'cancreate'}},$item);
6160: }
6161: } else {
6162: if ($cancreate{$item} ne 'none') {
6163: push(@{$changes{'cancreate'}},$item);
6164: }
1.27 raeburn 6165: }
6166: }
6167: } else {
1.43 raeburn 6168: foreach my $item (@contexts) {
1.34 raeburn 6169: push(@{$changes{'cancreate'}},$item);
6170: }
1.27 raeburn 6171: }
1.34 raeburn 6172:
1.27 raeburn 6173: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6174: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6175: if (!grep(/^\Q$type\E$/,@username_rule)) {
6176: push(@{$changes{'username_rule'}},$type);
6177: }
6178: }
6179: foreach my $type (@username_rule) {
6180: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6181: push(@{$changes{'username_rule'}},$type);
6182: }
6183: }
6184: } else {
6185: push(@{$changes{'username_rule'}},@username_rule);
6186: }
6187:
1.32 raeburn 6188: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6189: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6190: if (!grep(/^\Q$type\E$/,@id_rule)) {
6191: push(@{$changes{'id_rule'}},$type);
6192: }
6193: }
6194: foreach my $type (@id_rule) {
6195: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6196: push(@{$changes{'id_rule'}},$type);
6197: }
6198: }
6199: } else {
6200: push(@{$changes{'id_rule'}},@id_rule);
6201: }
6202:
1.43 raeburn 6203: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6204: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6205: if (!grep(/^\Q$type\E$/,@email_rule)) {
6206: push(@{$changes{'email_rule'}},$type);
6207: }
6208: }
6209: foreach my $type (@email_rule) {
6210: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6211: push(@{$changes{'email_rule'}},$type);
6212: }
6213: }
6214: } else {
6215: push(@{$changes{'email_rule'}},@email_rule);
6216: }
6217:
6218: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6219: my @authtypes = ('int','krb4','krb5','loc');
6220: my %authhash;
1.43 raeburn 6221: foreach my $item (@authen_contexts) {
1.28 raeburn 6222: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6223: foreach my $auth (@authtypes) {
6224: if (grep(/^\Q$auth\E$/,@authallowed)) {
6225: $authhash{$item}{$auth} = 1;
6226: } else {
6227: $authhash{$item}{$auth} = 0;
6228: }
6229: }
6230: }
6231: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6232: foreach my $item (@authen_contexts) {
1.28 raeburn 6233: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6234: foreach my $auth (@authtypes) {
6235: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6236: push(@{$changes{'authtypes'}},$item);
6237: last;
6238: }
6239: }
6240: }
6241: }
6242: } else {
1.43 raeburn 6243: foreach my $item (@authen_contexts) {
1.28 raeburn 6244: push(@{$changes{'authtypes'}},$item);
6245: }
6246: }
6247:
1.27 raeburn 6248: my %usercreation_hash = (
1.28 raeburn 6249: usercreation => {
1.34 raeburn 6250: cancreate => \%cancreate,
1.27 raeburn 6251: username_rule => \@username_rule,
1.32 raeburn 6252: id_rule => \@id_rule,
1.43 raeburn 6253: email_rule => \@email_rule,
1.32 raeburn 6254: authtypes => \%authhash,
1.27 raeburn 6255: }
6256: );
6257:
6258: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6259: $dom);
1.50 raeburn 6260:
6261: my %selfcreatetypes = (
6262: sso => 'users authenticated by institutional single sign on',
6263: login => 'users authenticated by institutional log-in',
6264: email => 'users who provide a valid e-mail address for use as the username',
6265: );
1.27 raeburn 6266: if ($putresult eq 'ok') {
6267: if (keys(%changes) > 0) {
6268: $resulttext = &mt('Changes made:').'<ul>';
6269: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6270: my %lt = &usercreation_types();
6271: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6272: my $chgtext;
6273: unless ($type eq 'statustocreate') {
6274: $chgtext = $lt{$type}.', ';
6275: }
1.45 raeburn 6276: if ($type eq 'selfcreate') {
1.50 raeburn 6277: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6278: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6279: } else {
1.100 raeburn 6280: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6281: foreach my $case (@{$cancreate{$type}}) {
6282: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6283: }
6284: $chgtext .= '</ul>';
1.100 raeburn 6285: if (ref($cancreate{$type}) eq 'ARRAY') {
6286: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6287: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6288: if (@{$cancreate{'statustocreate'}} == 0) {
6289: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6290: }
6291: }
6292: }
6293: }
1.43 raeburn 6294: }
1.93 raeburn 6295: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6296: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6297: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6298: if (@{$cancreate{'selfcreate'}} > 0) {
6299: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6300:
6301: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6302: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6303: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6304: }
1.96 raeburn 6305: } elsif (ref($usertypes) eq 'HASH') {
6306: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6307: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6308: } else {
6309: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6310: }
6311: $chgtext .= '<ul>';
6312: foreach my $case (@{$cancreate{$type}}) {
6313: if ($case eq 'default') {
6314: $chgtext .= '<li>'.$othertitle.'</li>';
6315: } else {
6316: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6317: }
6318: }
1.100 raeburn 6319: $chgtext .= '</ul>';
6320: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6321: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6322: }
6323: }
6324: } else {
6325: if (@{$cancreate{$type}} == 0) {
6326: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6327: } else {
6328: $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 6329: }
6330: }
6331: }
1.43 raeburn 6332: } else {
6333: if ($cancreate{$type} eq 'none') {
6334: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6335: } elsif ($cancreate{$type} eq 'any') {
6336: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6337: } elsif ($cancreate{$type} eq 'official') {
6338: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6339: } elsif ($cancreate{$type} eq 'unofficial') {
6340: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6341: }
1.34 raeburn 6342: }
6343: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6344: }
6345: }
6346: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6347: my ($rules,$ruleorder) =
6348: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6349: my $chgtext = '<ul>';
6350: foreach my $type (@username_rule) {
6351: if (ref($rules->{$type}) eq 'HASH') {
6352: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6353: }
6354: }
6355: $chgtext .= '</ul>';
6356: if (@username_rule > 0) {
6357: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6358: } else {
1.28 raeburn 6359: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6360: }
6361: }
1.32 raeburn 6362: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6363: my ($idrules,$idruleorder) =
6364: &Apache::lonnet::inst_userrules($dom,'id');
6365: my $chgtext = '<ul>';
6366: foreach my $type (@id_rule) {
6367: if (ref($idrules->{$type}) eq 'HASH') {
6368: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6369: }
6370: }
6371: $chgtext .= '</ul>';
6372: if (@id_rule > 0) {
6373: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6374: } else {
6375: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6376: }
6377: }
1.43 raeburn 6378: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6379: my ($emailrules,$emailruleorder) =
6380: &Apache::lonnet::inst_userrules($dom,'email');
6381: my $chgtext = '<ul>';
6382: foreach my $type (@email_rule) {
6383: if (ref($emailrules->{$type}) eq 'HASH') {
6384: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6385: }
6386: }
6387: $chgtext .= '</ul>';
6388: if (@email_rule > 0) {
6389: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
6390: } else {
6391: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
6392: }
6393: }
6394:
1.28 raeburn 6395: my %authname = &authtype_names();
6396: my %context_title = &context_names();
6397: if (ref($changes{'authtypes'}) eq 'ARRAY') {
6398: my $chgtext = '<ul>';
6399: foreach my $type (@{$changes{'authtypes'}}) {
6400: my @allowed;
6401: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
6402: foreach my $auth (@authtypes) {
6403: if ($authhash{$type}{$auth}) {
6404: push(@allowed,$authname{$auth});
6405: }
6406: }
1.43 raeburn 6407: if (@allowed > 0) {
6408: $chgtext .= join(', ',@allowed).'</li>';
6409: } else {
6410: $chgtext .= &mt('none').'</li>';
6411: }
1.28 raeburn 6412: }
6413: $chgtext .= '</ul>';
6414: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
6415: $resulttext .= '</li>';
6416: }
1.27 raeburn 6417: $resulttext .= '</ul>';
6418: } else {
1.28 raeburn 6419: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 6420: }
6421: } else {
6422: $resulttext = '<span class="LC_error">'.
1.23 raeburn 6423: &mt('An error occurred: [_1]',$putresult).'</span>';
6424: }
1.43 raeburn 6425: if ($warningmsg ne '') {
6426: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
6427: }
1.23 raeburn 6428: return $resulttext;
6429: }
6430:
1.33 raeburn 6431: sub modify_usermodification {
6432: my ($dom,%domconfig) = @_;
6433: my ($resulttext,%curr_usermodification,%changes);
6434: if (ref($domconfig{'usermodification'}) eq 'HASH') {
6435: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
6436: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
6437: }
6438: }
1.63 raeburn 6439: my @contexts = ('author','course','selfcreate');
1.33 raeburn 6440: my %context_title = (
6441: author => 'In author context',
6442: course => 'In course context',
1.63 raeburn 6443: selfcreate => 'When self creating account',
1.33 raeburn 6444: );
6445: my @fields = ('lastname','firstname','middlename','generation',
6446: 'permanentemail','id');
6447: my %roles = (
6448: author => ['ca','aa'],
6449: course => ['st','ep','ta','in','cr'],
6450: );
1.63 raeburn 6451: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6452: if (ref($types) eq 'ARRAY') {
6453: push(@{$types},'default');
6454: $usertypes->{'default'} = $othertitle;
6455: }
6456: $roles{'selfcreate'} = $types;
1.33 raeburn 6457: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6458: my %modifyhash;
6459: foreach my $context (@contexts) {
6460: foreach my $role (@{$roles{$context}}) {
6461: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6462: foreach my $item (@fields) {
6463: if (grep(/^\Q$item\E$/,@modifiable)) {
6464: $modifyhash{$context}{$role}{$item} = 1;
6465: } else {
6466: $modifyhash{$context}{$role}{$item} = 0;
6467: }
6468: }
6469: }
6470: if (ref($curr_usermodification{$context}) eq 'HASH') {
6471: foreach my $role (@{$roles{$context}}) {
6472: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6473: foreach my $field (@fields) {
6474: if ($modifyhash{$context}{$role}{$field} ne
6475: $curr_usermodification{$context}{$role}{$field}) {
6476: push(@{$changes{$context}},$role);
6477: last;
6478: }
6479: }
6480: }
6481: }
6482: } else {
6483: foreach my $context (@contexts) {
6484: foreach my $role (@{$roles{$context}}) {
6485: push(@{$changes{$context}},$role);
6486: }
6487: }
6488: }
6489: }
6490: my %usermodification_hash = (
6491: usermodification => \%modifyhash,
6492: );
6493: my $putresult = &Apache::lonnet::put_dom('configuration',
6494: \%usermodification_hash,$dom);
6495: if ($putresult eq 'ok') {
6496: if (keys(%changes) > 0) {
6497: $resulttext = &mt('Changes made: ').'<ul>';
6498: foreach my $context (@contexts) {
6499: if (ref($changes{$context}) eq 'ARRAY') {
6500: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6501: if (ref($changes{$context}) eq 'ARRAY') {
6502: foreach my $role (@{$changes{$context}}) {
6503: my $rolename;
1.63 raeburn 6504: if ($context eq 'selfcreate') {
6505: $rolename = $role;
6506: if (ref($usertypes) eq 'HASH') {
6507: if ($usertypes->{$role} ne '') {
6508: $rolename = $usertypes->{$role};
6509: }
6510: }
1.33 raeburn 6511: } else {
1.63 raeburn 6512: if ($role eq 'cr') {
6513: $rolename = &mt('Custom');
6514: } else {
6515: $rolename = &Apache::lonnet::plaintext($role);
6516: }
1.33 raeburn 6517: }
6518: my @modifiable;
1.63 raeburn 6519: if ($context eq 'selfcreate') {
1.126 bisitz 6520: $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 6521: } else {
6522: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6523: }
1.33 raeburn 6524: foreach my $field (@fields) {
6525: if ($modifyhash{$context}{$role}{$field}) {
6526: push(@modifiable,$fieldtitles{$field});
6527: }
6528: }
6529: if (@modifiable > 0) {
6530: $resulttext .= join(', ',@modifiable);
6531: } else {
6532: $resulttext .= &mt('none');
6533: }
6534: $resulttext .= '</li>';
6535: }
6536: $resulttext .= '</ul></li>';
6537: }
6538: }
6539: }
6540: $resulttext .= '</ul>';
6541: } else {
6542: $resulttext = &mt('No changes made to user modification settings');
6543: }
6544: } else {
6545: $resulttext = '<span class="LC_error">'.
6546: &mt('An error occurred: [_1]',$putresult).'</span>';
6547: }
6548: return $resulttext;
6549: }
6550:
1.43 raeburn 6551: sub modify_defaults {
6552: my ($dom,$r) = @_;
6553: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6554: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 6555: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6556: my @authtypes = ('internal','krb4','krb5','localauth');
6557: foreach my $item (@items) {
6558: $newvalues{$item} = $env{'form.'.$item};
6559: if ($item eq 'auth_def') {
6560: if ($newvalues{$item} ne '') {
6561: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6562: push(@errors,$item);
6563: }
6564: }
6565: } elsif ($item eq 'lang_def') {
6566: if ($newvalues{$item} ne '') {
6567: if ($newvalues{$item} =~ /^(\w+)/) {
6568: my $langcode = $1;
1.103 raeburn 6569: if ($langcode ne 'x_chef') {
6570: if (code2language($langcode) eq '') {
6571: push(@errors,$item);
6572: }
1.43 raeburn 6573: }
6574: } else {
6575: push(@errors,$item);
6576: }
6577: }
1.54 raeburn 6578: } elsif ($item eq 'timezone_def') {
6579: if ($newvalues{$item} ne '') {
1.62 raeburn 6580: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6581: push(@errors,$item);
6582: }
6583: }
1.68 raeburn 6584: } elsif ($item eq 'datelocale_def') {
6585: if ($newvalues{$item} ne '') {
6586: my @datelocale_ids = DateTime::Locale->ids();
6587: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6588: push(@errors,$item);
6589: }
6590: }
1.141 raeburn 6591: } elsif ($item eq 'portal_def') {
6592: if ($newvalues{$item} ne '') {
6593: 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])\/?$/) {
6594: push(@errors,$item);
6595: }
6596: }
1.43 raeburn 6597: }
6598: if (grep(/^\Q$item\E$/,@errors)) {
6599: $newvalues{$item} = $domdefaults{$item};
6600: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6601: $changes{$item} = 1;
6602: }
1.72 raeburn 6603: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6604: }
6605: my %defaults_hash = (
1.72 raeburn 6606: defaults => \%newvalues,
6607: );
1.43 raeburn 6608: my $title = &defaults_titles();
6609: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6610: $dom);
6611: if ($putresult eq 'ok') {
6612: if (keys(%changes) > 0) {
6613: $resulttext = &mt('Changes made:').'<ul>';
6614: my $version = $r->dir_config('lonVersion');
6615: 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";
6616: foreach my $item (sort(keys(%changes))) {
6617: my $value = $env{'form.'.$item};
6618: if ($value eq '') {
6619: $value = &mt('none');
6620: } elsif ($item eq 'auth_def') {
6621: my %authnames = &authtype_names();
6622: my %shortauth = (
6623: internal => 'int',
6624: krb4 => 'krb4',
6625: krb5 => 'krb5',
6626: localauth => 'loc',
6627: );
6628: $value = $authnames{$shortauth{$value}};
6629: }
6630: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6631: $mailmsgtext .= "$title->{$item} set to $value\n";
6632: }
6633: $resulttext .= '</ul>';
6634: $mailmsgtext .= "\n";
6635: my $cachetime = 24*60*60;
1.72 raeburn 6636: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6637: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6638: my $sysmail = $r->dir_config('lonSysEMail');
6639: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6640: }
1.43 raeburn 6641: } else {
1.54 raeburn 6642: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6643: }
6644: } else {
6645: $resulttext = '<span class="LC_error">'.
6646: &mt('An error occurred: [_1]',$putresult).'</span>';
6647: }
6648: if (@errors > 0) {
6649: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6650: foreach my $item (@errors) {
6651: $resulttext .= ' "'.$title->{$item}.'",';
6652: }
6653: $resulttext =~ s/,$//;
6654: }
6655: return $resulttext;
6656: }
6657:
1.46 raeburn 6658: sub modify_scantron {
1.48 raeburn 6659: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6660: my ($resulttext,%confhash,%changes,$errors);
6661: my $custom = 'custom.tab';
6662: my $default = 'default.tab';
6663: my $servadm = $r->dir_config('lonAdmEMail');
6664: my ($configuserok,$author_ok,$switchserver) =
6665: &config_check($dom,$confname,$servadm);
6666: if ($env{'form.scantronformat.filename'} ne '') {
6667: my $error;
6668: if ($configuserok eq 'ok') {
6669: if ($switchserver) {
1.130 raeburn 6670: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6671: } else {
6672: if ($author_ok eq 'ok') {
6673: my ($result,$scantronurl) =
6674: &publishlogo($r,'upload','scantronformat',$dom,
6675: $confname,'scantron','','',$custom);
6676: if ($result eq 'ok') {
6677: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6678: $changes{'scantronformat'} = 1;
1.46 raeburn 6679: } else {
6680: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6681: }
6682: } else {
6683: $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);
6684: }
6685: }
6686: } else {
6687: $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);
6688: }
6689: if ($error) {
6690: &Apache::lonnet::logthis($error);
6691: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6692: }
6693: }
1.48 raeburn 6694: if (ref($domconfig{'scantron'}) eq 'HASH') {
6695: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6696: if ($env{'form.scantronformat_del'}) {
6697: $confhash{'scantron'}{'scantronformat'} = '';
6698: $changes{'scantronformat'} = 1;
1.46 raeburn 6699: }
6700: }
6701: }
6702: if (keys(%confhash) > 0) {
6703: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6704: $dom);
6705: if ($putresult eq 'ok') {
6706: if (keys(%changes) > 0) {
1.48 raeburn 6707: if (ref($confhash{'scantron'}) eq 'HASH') {
6708: $resulttext = &mt('Changes made:').'<ul>';
6709: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6710: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6711: } else {
1.130 raeburn 6712: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6713: }
1.48 raeburn 6714: $resulttext .= '</ul>';
6715: } else {
1.130 raeburn 6716: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6717: }
6718: $resulttext .= '</ul>';
6719: &Apache::loncommon::devalidate_domconfig_cache($dom);
6720: } else {
1.130 raeburn 6721: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6722: }
6723: } else {
6724: $resulttext = '<span class="LC_error">'.
6725: &mt('An error occurred: [_1]',$putresult).'</span>';
6726: }
6727: } else {
1.130 raeburn 6728: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6729: }
6730: if ($errors) {
6731: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6732: $errors.'</ul>';
6733: }
6734: return $resulttext;
6735: }
6736:
1.48 raeburn 6737: sub modify_coursecategories {
6738: my ($dom,%domconfig) = @_;
1.57 raeburn 6739: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6740: $cathash);
1.48 raeburn 6741: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6742: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6743: $cathash = $domconfig{'coursecategories'}{'cats'};
6744: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6745: $changes{'togglecats'} = 1;
6746: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6747: }
6748: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6749: $changes{'categorize'} = 1;
6750: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6751: }
1.120 raeburn 6752: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6753: $changes{'togglecatscomm'} = 1;
6754: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6755: }
6756: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6757: $changes{'categorizecomm'} = 1;
6758: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6759: }
1.57 raeburn 6760: } else {
6761: $changes{'togglecats'} = 1;
6762: $changes{'categorize'} = 1;
1.124 raeburn 6763: $changes{'togglecatscomm'} = 1;
6764: $changes{'categorizecomm'} = 1;
1.87 raeburn 6765: $domconfig{'coursecategories'} = {
6766: togglecats => $env{'form.togglecats'},
6767: categorize => $env{'form.categorize'},
1.124 raeburn 6768: togglecatscomm => $env{'form.togglecatscomm'},
6769: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6770: };
1.57 raeburn 6771: }
6772: if (ref($cathash) eq 'HASH') {
6773: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6774: push (@deletecategory,'instcode::0');
6775: }
1.120 raeburn 6776: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6777: push(@deletecategory,'communities::0');
6778: }
1.48 raeburn 6779: }
1.57 raeburn 6780: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6781: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6782: if (@deletecategory > 0) {
6783: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6784: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6785: foreach my $item (@deletecategory) {
1.57 raeburn 6786: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6787: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6788: $deletions{$item} = 1;
1.57 raeburn 6789: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6790: }
6791: }
6792: }
1.57 raeburn 6793: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6794: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6795: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6796: $reorderings{$item} = 1;
1.57 raeburn 6797: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6798: }
6799: if ($env{'form.addcategory_name_'.$item} ne '') {
6800: my $newcat = $env{'form.addcategory_name_'.$item};
6801: my $newdepth = $depth+1;
6802: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6803: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6804: $adds{$newitem} = 1;
6805: }
6806: if ($env{'form.subcat_'.$item} ne '') {
6807: my $newcat = $env{'form.subcat_'.$item};
6808: my $newdepth = $depth+1;
6809: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6810: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6811: $adds{$newitem} = 1;
6812: }
6813: }
6814: }
6815: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6816: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6817: my $newitem = 'instcode::0';
1.57 raeburn 6818: if ($cathash->{$newitem} eq '') {
6819: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6820: $adds{$newitem} = 1;
6821: }
6822: } else {
6823: my $newitem = 'instcode::0';
1.57 raeburn 6824: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6825: $adds{$newitem} = 1;
6826: }
6827: }
1.120 raeburn 6828: if ($env{'form.communities'} eq '1') {
6829: if (ref($cathash) eq 'HASH') {
6830: my $newitem = 'communities::0';
6831: if ($cathash->{$newitem} eq '') {
6832: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6833: $adds{$newitem} = 1;
6834: }
6835: } else {
6836: my $newitem = 'communities::0';
6837: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6838: $adds{$newitem} = 1;
6839: }
6840: }
1.48 raeburn 6841: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6842: if (($env{'form.addcategory_name'} ne 'instcode') &&
6843: ($env{'form.addcategory_name'} ne 'communities')) {
6844: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6845: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6846: $adds{$newitem} = 1;
6847: }
1.48 raeburn 6848: }
1.57 raeburn 6849: my $putresult;
1.48 raeburn 6850: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6851: if (keys(%deletions) > 0) {
6852: foreach my $key (keys(%deletions)) {
6853: if ($predelallitems{$key} ne '') {
6854: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6855: }
6856: }
6857: }
6858: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6859: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6860: if (ref($chkcats[0]) eq 'ARRAY') {
6861: my $depth = 0;
6862: my $chg = 0;
6863: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6864: my $name = $chkcats[0][$i];
6865: my $item;
6866: if ($name eq '') {
6867: $chg ++;
6868: } else {
6869: $item = &escape($name).'::0';
6870: if ($chg) {
1.57 raeburn 6871: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6872: }
6873: $depth ++;
1.57 raeburn 6874: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6875: $depth --;
6876: }
6877: }
6878: }
1.57 raeburn 6879: }
6880: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6881: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6882: if ($putresult eq 'ok') {
1.57 raeburn 6883: my %title = (
1.120 raeburn 6884: togglecats => 'Show/Hide a course in catalog',
6885: categorize => 'Assign a category to a course',
6886: togglecatscomm => 'Show/Hide a community in catalog',
6887: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6888: );
6889: my %level = (
1.120 raeburn 6890: dom => 'set in Domain ("Modify Course/Community")',
6891: crs => 'set in Course ("Course Configuration")',
6892: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6893: );
1.48 raeburn 6894: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6895: if ($changes{'togglecats'}) {
6896: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6897: }
6898: if ($changes{'categorize'}) {
6899: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6900: }
1.120 raeburn 6901: if ($changes{'togglecatscomm'}) {
6902: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6903: }
6904: if ($changes{'categorizecomm'}) {
6905: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6906: }
1.57 raeburn 6907: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6908: my $cathash;
6909: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6910: $cathash = $domconfig{'coursecategories'}{'cats'};
6911: } else {
6912: $cathash = {};
6913: }
6914: my (@cats,@trails,%allitems);
6915: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6916: if (keys(%deletions) > 0) {
6917: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6918: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6919: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6920: }
6921: $resulttext .= '</ul></li>';
6922: }
6923: if (keys(%reorderings) > 0) {
6924: my %sort_by_trail;
6925: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6926: foreach my $key (keys(%reorderings)) {
6927: if ($allitems{$key} ne '') {
6928: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6929: }
1.48 raeburn 6930: }
1.57 raeburn 6931: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6932: $resulttext .= '<li>'.$trails[$trail].'</li>';
6933: }
6934: $resulttext .= '</ul></li>';
1.48 raeburn 6935: }
1.57 raeburn 6936: if (keys(%adds) > 0) {
6937: my %sort_by_trail;
6938: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6939: foreach my $key (keys(%adds)) {
6940: if ($allitems{$key} ne '') {
6941: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6942: }
6943: }
6944: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6945: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 6946: }
1.57 raeburn 6947: $resulttext .= '</ul></li>';
1.48 raeburn 6948: }
6949: }
6950: $resulttext .= '</ul>';
6951: } else {
6952: $resulttext = '<span class="LC_error">'.
1.57 raeburn 6953: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 6954: }
6955: } else {
1.120 raeburn 6956: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 6957: }
6958: return $resulttext;
6959: }
6960:
1.69 raeburn 6961: sub modify_serverstatuses {
6962: my ($dom,%domconfig) = @_;
6963: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
6964: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
6965: %currserverstatus = %{$domconfig{'serverstatuses'}};
6966: }
6967: my @pages = &serverstatus_pages();
6968: foreach my $type (@pages) {
6969: $newserverstatus{$type}{'namedusers'} = '';
6970: $newserverstatus{$type}{'machines'} = '';
6971: if (defined($env{'form.'.$type.'_namedusers'})) {
6972: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
6973: my @okusers;
6974: foreach my $user (@users) {
6975: my ($uname,$udom) = split(/:/,$user);
6976: if (($udom =~ /^$match_domain$/) &&
6977: (&Apache::lonnet::domain($udom)) &&
6978: ($uname =~ /^$match_username$/)) {
6979: if (!grep(/^\Q$user\E/,@okusers)) {
6980: push(@okusers,$user);
6981: }
6982: }
6983: }
6984: if (@okusers > 0) {
6985: @okusers = sort(@okusers);
6986: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
6987: }
6988: }
6989: if (defined($env{'form.'.$type.'_machines'})) {
6990: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
6991: my @okmachines;
6992: foreach my $ip (@machines) {
6993: my @parts = split(/\./,$ip);
6994: next if (@parts < 4);
6995: my $badip = 0;
6996: for (my $i=0; $i<4; $i++) {
6997: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
6998: $badip = 1;
6999: last;
7000: }
7001: }
7002: if (!$badip) {
7003: push(@okmachines,$ip);
7004: }
7005: }
7006: @okmachines = sort(@okmachines);
7007: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7008: }
7009: }
7010: my %serverstatushash = (
7011: serverstatuses => \%newserverstatus,
7012: );
7013: foreach my $type (@pages) {
1.83 raeburn 7014: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7015: my (@current,@new);
1.83 raeburn 7016: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7017: if ($currserverstatus{$type}{$setting} ne '') {
7018: @current = split(/,/,$currserverstatus{$type}{$setting});
7019: }
7020: }
7021: if ($newserverstatus{$type}{$setting} ne '') {
7022: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7023: }
7024: if (@current > 0) {
7025: if (@new > 0) {
7026: foreach my $item (@current) {
7027: if (!grep(/^\Q$item\E$/,@new)) {
7028: $changes{$type}{$setting} = 1;
1.82 raeburn 7029: last;
7030: }
7031: }
1.84 raeburn 7032: foreach my $item (@new) {
7033: if (!grep(/^\Q$item\E$/,@current)) {
7034: $changes{$type}{$setting} = 1;
7035: last;
1.82 raeburn 7036: }
7037: }
7038: } else {
1.83 raeburn 7039: $changes{$type}{$setting} = 1;
1.69 raeburn 7040: }
1.83 raeburn 7041: } elsif (@new > 0) {
7042: $changes{$type}{$setting} = 1;
1.69 raeburn 7043: }
7044: }
7045: }
7046: if (keys(%changes) > 0) {
1.81 raeburn 7047: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7048: my $putresult = &Apache::lonnet::put_dom('configuration',
7049: \%serverstatushash,$dom);
7050: if ($putresult eq 'ok') {
7051: $resulttext .= &mt('Changes made:').'<ul>';
7052: foreach my $type (@pages) {
1.84 raeburn 7053: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7054: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7055: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7056: if ($newserverstatus{$type}{'namedusers'} eq '') {
7057: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7058: } else {
7059: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7060: }
1.84 raeburn 7061: }
7062: if ($changes{$type}{'machines'}) {
1.69 raeburn 7063: if ($newserverstatus{$type}{'machines'} eq '') {
7064: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7065: } else {
7066: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7067: }
7068:
7069: }
7070: $resulttext .= '</ul></li>';
7071: }
7072: }
7073: $resulttext .= '</ul>';
7074: } else {
7075: $resulttext = '<span class="LC_error">'.
7076: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7077:
7078: }
7079: } else {
7080: $resulttext = &mt('No changes made to access to server status pages');
7081: }
7082: return $resulttext;
7083: }
7084:
1.118 jms 7085: sub modify_helpsettings {
1.122 jms 7086: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 7087: my ($resulttext,$errors,%changes,%helphash);
7088:
1.122 jms 7089: my $customhelpfile = $env{'form.loginhelpurl.filename'};
7090: my $defaulthelpfile = 'defaulthelp.html';
7091: my $servadm = $r->dir_config('lonAdmEMail');
7092: my ($configuserok,$author_ok,$switchserver) =
7093: &config_check($dom,$confname,$servadm);
7094:
1.118 jms 7095: my %defaultchecked = ('submitbugs' => 'on');
7096: my @offon = ('off','on');
1.122 jms 7097: my %title = ( submitbugs => 'Display link for users to submit a bug',
7098: loginhelpurl => 'Unauthenticated login help page set to custom file');
7099:
1.118 jms 7100: my @toggles = ('submitbugs');
7101:
7102: $helphash{'helpsettings'} = {};
7103:
7104: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
7105: if ($domconfig{'helpsettings'} eq '') {
7106: $domconfig{'helpsettings'} = {};
7107: }
7108: }
7109:
7110: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7111:
7112: foreach my $item (@toggles) {
7113:
7114: if ($defaultchecked{$item} eq 'on') {
7115: if (($domconfig{'helpsettings'}{$item} eq '') &&
7116: ($env{'form.'.$item} eq '0')) {
7117: $changes{$item} = 1;
7118: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7119: $changes{$item} = 1;
7120: }
7121: } elsif ($defaultchecked{$item} eq 'off') {
7122: if (($domconfig{'helpsettings'}{$item} eq '') &&
7123: ($env{'form.'.$item} eq '1')) {
7124: $changes{$item} = 1;
7125: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7126: $changes{$item} = 1;
7127: }
7128: }
7129: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7130: }
7131:
7132: if ($customhelpfile ne '') {
7133: my $error;
7134: if ($configuserok eq 'ok') {
7135: if ($switchserver) {
7136: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7137: } else {
7138: if ($author_ok eq 'ok') {
7139: my ($result,$loginhelpurl) =
7140: &publishlogo($r,'upload','loginhelpurl',$dom,
7141: $confname,'help','','',$customhelpfile);
7142: if ($result eq 'ok') {
7143: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
7144: $changes{'loginhelpurl'} = 1;
7145: } else {
7146: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
7147: }
7148: } else {
7149: $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);
7150: }
7151: }
7152: } else {
7153: $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);
7154: }
7155: if ($error) {
7156: &Apache::lonnet::logthis($error);
7157: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7158: }
7159: }
7160:
7161: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
7162: if ($env{'form.loginhelpurl_del'}) {
7163: $helphash{'helpsettings'}{'loginhelpurl'} = '';
7164: $changes{'loginhelpurl'} = 1;
7165: }
7166: }
1.118 jms 7167: }
7168:
1.123 jms 7169:
7170: my $putresult;
7171:
7172: if (keys(%changes) > 0) {
7173: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7174: } else {
7175: $putresult = 'ok';
7176: }
1.118 jms 7177:
7178: if ($putresult eq 'ok') {
7179: if (keys(%changes) > 0) {
7180: $resulttext = &mt('Changes made:').'<ul>';
7181: foreach my $item (sort(keys(%changes))) {
7182: if ($item eq 'submitbugs') {
7183: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7184: }
1.122 jms 7185: if ($item eq 'loginhelpurl') {
7186: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
7187: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
7188: } else {
7189: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
7190: }
7191: }
1.118 jms 7192: }
7193: $resulttext .= '</ul>';
7194: } else {
7195: $resulttext = &mt('No changes made to help settings');
7196: }
7197: } else {
7198: $resulttext = '<span class="LC_error">'.
7199: &mt('An error occurred: [_1]',$putresult).'</span>';
7200: }
7201: if ($errors) {
7202: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7203: $errors.'</ul>';
7204: }
7205: return $resulttext;
7206: }
7207:
1.121 raeburn 7208: sub modify_coursedefaults {
7209: my ($dom,%domconfig) = @_;
7210: my ($resulttext,$errors,%changes,%defaultshash);
7211: my %defaultchecked = ('canuse_pdfforms' => 'off');
7212: my @offon = ('off','on');
7213: my @toggles = ('canuse_pdfforms');
7214:
7215: $defaultshash{'coursedefaults'} = {};
7216:
7217: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7218: if ($domconfig{'coursedefaults'} eq '') {
7219: $domconfig{'coursedefaults'} = {};
7220: }
7221: }
7222:
7223: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7224: foreach my $item (@toggles) {
7225: if ($defaultchecked{$item} eq 'on') {
7226: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7227: ($env{'form.'.$item} eq '0')) {
7228: $changes{$item} = 1;
7229: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7230: $changes{$item} = 1;
7231: }
7232: } elsif ($defaultchecked{$item} eq 'off') {
7233: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7234: ($env{'form.'.$item} eq '1')) {
7235: $changes{$item} = 1;
7236: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7237: $changes{$item} = 1;
7238: }
7239: }
7240: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7241: }
1.139 raeburn 7242: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7243: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7244: $newdefresponder =~ s/\D//g;
7245: if ($newdefresponder eq '' || $newdefresponder < 1) {
7246: $newdefresponder = 1;
7247: }
7248: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7249: if ($currdefresponder ne $newdefresponder) {
7250: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7251: $changes{'anonsurvey_threshold'} = 1;
7252: }
7253: }
1.121 raeburn 7254: }
7255: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7256: $dom);
7257: if ($putresult eq 'ok') {
7258: if (keys(%changes) > 0) {
7259: if ($changes{'canuse_pdfforms'}) {
7260: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7261: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7262: my $cachetime = 24*60*60;
7263: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7264: }
7265: $resulttext = &mt('Changes made:').'<ul>';
7266: foreach my $item (sort(keys(%changes))) {
7267: if ($item eq 'canuse_pdfforms') {
7268: if ($env{'form.'.$item} eq '1') {
7269: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7270: } else {
7271: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7272: }
1.139 raeburn 7273: } elsif ($item eq 'anonsurvey_threshold') {
7274: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7275: }
1.121 raeburn 7276: }
7277: $resulttext .= '</ul>';
7278: } else {
7279: $resulttext = &mt('No changes made to course defaults');
7280: }
7281: } else {
7282: $resulttext = '<span class="LC_error">'.
7283: &mt('An error occurred: [_1]',$putresult).'</span>';
7284: }
7285: return $resulttext;
7286: }
7287:
1.137 raeburn 7288: sub modify_usersessions {
7289: my ($dom,%domconfig) = @_;
1.145 raeburn 7290: my @hostingtypes = ('version','excludedomain','includedomain');
7291: my @offloadtypes = ('primary','default');
7292: my %types = (
7293: remote => \@hostingtypes,
7294: hosted => \@hostingtypes,
7295: spares => \@offloadtypes,
7296: );
7297: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7298: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7299: my (%by_ip,%by_location,@intdoms);
7300: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7301: my @locations = sort(keys(%by_location));
1.137 raeburn 7302: my (%defaultshash,%changes);
7303: foreach my $prefix (@prefixes) {
7304: $defaultshash{'usersessions'}{$prefix} = {};
7305: }
7306: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7307: my $resulttext;
1.138 raeburn 7308: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7309: foreach my $prefix (@prefixes) {
1.145 raeburn 7310: next if ($prefix eq 'spares');
7311: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7312: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7313: if ($type eq 'version') {
7314: my $value = $env{'form.'.$prefix.'_'.$type};
7315: my $okvalue;
7316: if ($value ne '') {
7317: if (grep(/^\Q$value\E$/,@lcversions)) {
7318: $okvalue = $value;
7319: }
7320: }
7321: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7322: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7323: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7324: if ($inuse == 0) {
7325: $changes{$prefix}{$type} = 1;
7326: } else {
7327: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7328: $changes{$prefix}{$type} = 1;
7329: }
7330: if ($okvalue ne '') {
7331: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7332: }
7333: }
7334: } else {
7335: if (($inuse == 1) && ($okvalue ne '')) {
7336: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7337: $changes{$prefix}{$type} = 1;
7338: }
7339: }
7340: } else {
7341: if (($inuse == 1) && ($okvalue ne '')) {
7342: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7343: $changes{$prefix}{$type} = 1;
7344: }
7345: }
7346: } else {
7347: if (($inuse == 1) && ($okvalue ne '')) {
7348: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7349: $changes{$prefix}{$type} = 1;
7350: }
7351: }
7352: } else {
7353: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7354: my @okvals;
7355: foreach my $val (@vals) {
1.138 raeburn 7356: if ($val =~ /:/) {
7357: my @items = split(/:/,$val);
7358: foreach my $item (@items) {
7359: if (ref($by_location{$item}) eq 'ARRAY') {
7360: push(@okvals,$item);
7361: }
7362: }
7363: } else {
7364: if (ref($by_location{$val}) eq 'ARRAY') {
7365: push(@okvals,$val);
7366: }
1.137 raeburn 7367: }
7368: }
7369: @okvals = sort(@okvals);
7370: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7371: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7372: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7373: if ($inuse == 0) {
7374: $changes{$prefix}{$type} = 1;
7375: } else {
7376: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7377: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7378: if (@changed > 0) {
7379: $changes{$prefix}{$type} = 1;
7380: }
7381: }
7382: } else {
7383: if ($inuse == 1) {
7384: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7385: $changes{$prefix}{$type} = 1;
7386: }
7387: }
7388: } else {
7389: if ($inuse == 1) {
7390: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7391: $changes{$prefix}{$type} = 1;
7392: }
7393: }
7394: } else {
7395: if ($inuse == 1) {
7396: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7397: $changes{$prefix}{$type} = 1;
7398: }
7399: }
7400: }
7401: }
7402: }
1.145 raeburn 7403:
7404: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 7405: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 7406: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
7407: my $savespares;
7408:
7409: foreach my $lonhost (sort(keys(%servers))) {
7410: my $serverhomeID =
7411: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 ! raeburn 7412: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 7413: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
7414: my %spareschg;
7415: foreach my $type (@{$types{'spares'}}) {
7416: my @okspares;
7417: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
7418: foreach my $server (@checked) {
1.152 ! raeburn 7419: if (&Apache::lonnet::hostname($server) ne '') {
! 7420: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
! 7421: unless (grep(/^\Q$server\E$/,@okspares)) {
! 7422: push(@okspares,$server);
! 7423: }
1.145 raeburn 7424: }
7425: }
7426: }
7427: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
7428: my $newspare;
1.152 ! raeburn 7429: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
! 7430: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 7431: $newspare = $new;
7432: }
7433: }
1.152 ! raeburn 7434: my @spares;
! 7435: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
! 7436: @spares = sort(@okspares,$newspare);
! 7437: } else {
! 7438: @spares = sort(@okspares);
! 7439: }
! 7440: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 7441: if (ref($spareid{$lonhost}) eq 'HASH') {
7442: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 ! raeburn 7443: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 7444: if (@diffs > 0) {
7445: $spareschg{$type} = 1;
7446: }
7447: }
7448: }
7449: }
7450: if (keys(%spareschg) > 0) {
7451: $changes{'spares'}{$lonhost} = \%spareschg;
7452: }
7453: }
7454:
7455: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7456: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
7457: if (ref($changes{'spares'}) eq 'HASH') {
7458: if (keys(%{$changes{'spares'}}) > 0) {
7459: $savespares = 1;
7460: }
7461: }
7462: } else {
7463: $savespares = 1;
7464: }
7465: }
7466:
1.147 raeburn 7467: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
7468: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 7469: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7470: $dom);
7471: if ($putresult eq 'ok') {
7472: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7473: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
7474: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
7475: }
7476: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
7477: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
7478: }
7479: }
7480: my $cachetime = 24*60*60;
7481: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 7482: if (keys(%changes) > 0) {
7483: my %lt = &usersession_titles();
7484: $resulttext = &mt('Changes made:').'<ul>';
7485: foreach my $prefix (@prefixes) {
7486: if (ref($changes{$prefix}) eq 'HASH') {
7487: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
7488: if ($prefix eq 'spares') {
7489: if (ref($changes{$prefix}) eq 'HASH') {
7490: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
7491: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 7492: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
7493: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 7494: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
7495: foreach my $type (@{$types{$prefix}}) {
7496: if ($changes{$prefix}{$lonhost}{$type}) {
7497: my $offloadto = &mt('None');
7498: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
7499: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
7500: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
7501: }
1.145 raeburn 7502: }
1.147 raeburn 7503: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 7504: }
1.137 raeburn 7505: }
7506: }
1.147 raeburn 7507: $resulttext .= '</li>';
1.137 raeburn 7508: }
7509: }
1.147 raeburn 7510: } else {
7511: foreach my $type (@{$types{$prefix}}) {
7512: if (defined($changes{$prefix}{$type})) {
7513: my $newvalue;
7514: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
7515: if (ref($defaultshash{'usersessions'}{$prefix})) {
7516: if ($type eq 'version') {
7517: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
7518: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7519: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
7520: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
7521: }
1.145 raeburn 7522: }
7523: }
7524: }
1.147 raeburn 7525: if ($newvalue eq '') {
7526: if ($type eq 'version') {
7527: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
7528: } else {
7529: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
7530: }
1.145 raeburn 7531: } else {
1.147 raeburn 7532: if ($type eq 'version') {
7533: $newvalue .= ' '.&mt('(or later)');
7534: }
7535: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 7536: }
1.137 raeburn 7537: }
7538: }
7539: }
1.147 raeburn 7540: $resulttext .= '</ul>';
1.137 raeburn 7541: }
7542: }
1.147 raeburn 7543: $resulttext .= '</ul>';
7544: } else {
7545: $resulttext = $nochgmsg;
1.137 raeburn 7546: }
7547: } else {
7548: $resulttext = '<span class="LC_error">'.
7549: &mt('An error occurred: [_1]',$putresult).'</span>';
7550: }
7551: } else {
1.147 raeburn 7552: $resulttext = $nochgmsg;
1.137 raeburn 7553: }
7554: return $resulttext;
7555: }
7556:
1.150 raeburn 7557: sub modify_loadbalancing {
7558: my ($dom,%domconfig) = @_;
7559: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7560: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7561: my ($othertitle,$usertypes,$types) =
7562: &Apache::loncommon::sorted_inst_types($dom);
7563: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7564: my @sparestypes = ('primary','default');
7565: my %typetitles = &sparestype_titles();
7566: my $resulttext;
7567: if (keys(%servers) > 1) {
7568: my ($currbalancer,$currtargets,$currrules);
7569: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7570: $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
7571: $currtargets = $domconfig{'loadbalancing'}{'targets'};
7572: $currrules = $domconfig{'loadbalancing'}{'rules'};
7573: } else {
7574: ($currbalancer,$currtargets) =
7575: &Apache::lonnet::get_lonbalancer_config(\%servers);
7576: }
7577: my ($saveloadbalancing,%defaultshash,%changes);
7578: my ($alltypes,$othertypes,$titles) =
7579: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7580: my %ruletitles = &offloadtype_text();
7581: my $balancer = $env{'form.loadbalancing_lonhost'};
7582: if (!$servers{$balancer}) {
7583: undef($balancer);
7584: }
7585: if ($currbalancer ne $balancer) {
7586: $changes{'lonhost'} = 1;
7587: }
7588: $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
7589: if ($balancer ne '') {
7590: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
7591: $saveloadbalancing = 1;
7592: }
7593: foreach my $sparetype (@sparestypes) {
7594: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151 raeburn 7595: my @offloadto;
1.150 raeburn 7596: foreach my $target (@targets) {
7597: if (($servers{$target}) && ($target ne $balancer)) {
7598: if ($sparetype eq 'default') {
7599: if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
7600: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
7601: }
7602: }
7603: unless(grep(/^\Q$target\E$/,@offloadto)) {
7604: push(@offloadto,$target);
7605: }
7606: }
7607: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
7608: }
7609: }
7610: } else {
7611: foreach my $sparetype (@sparestypes) {
7612: $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
7613: }
7614: }
7615: if (ref($currtargets) eq 'HASH') {
7616: foreach my $sparetype (@sparestypes) {
7617: if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
7618: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
7619: if (@targetdiffs > 0) {
7620: $changes{'targets'} = 1;
7621: }
7622: } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7623: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7624: $changes{'targets'} = 1;
7625: }
7626: }
7627: }
7628: } else {
7629: foreach my $sparetype (@sparestypes) {
7630: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7631: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7632: $changes{'targets'} = 1;
7633: }
7634: }
7635: }
7636: }
7637: my $ishomedom;
7638: if ($balancer ne '') {
7639: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
7640: $ishomedom = 1;
7641: }
7642: }
7643: if (ref($alltypes) eq 'ARRAY') {
7644: foreach my $type (@{$alltypes}) {
7645: my $rule;
7646: if ($balancer ne '') {
7647: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
7648: (!$ishomedom)) {
7649: $rule = $env{'form.loadbalancing_rules_'.$type};
7650: }
7651: if ($rule eq 'specific') {
7652: $rule = $env{'form.loadbalancing_singleserver_'.$type};
7653: }
7654: }
7655: $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
7656: if (ref($currrules) eq 'HASH') {
7657: if ($rule ne $currrules->{$type}) {
7658: $changes{'rules'}{$type} = 1;
7659: }
7660: } elsif ($rule ne '') {
7661: $changes{'rules'}{$type} = 1;
7662: }
7663: }
7664: }
7665: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
7666: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
7667: my $putresult = &Apache::lonnet::put_dom('configuration',
7668: \%defaultshash,$dom);
7669: if ($putresult eq 'ok') {
7670: if (keys(%changes) > 0) {
7671: if ($changes{'lonhost'}) {
7672: if ($currbalancer ne '') {
7673: &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
7674: }
7675: if ($balancer eq '') {
7676: $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>';
7677: } else {
7678: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7679: $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
7680: }
7681: } else {
7682: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7683: }
7684: if (($changes{'targets'}) && ($balancer ne '')) {
7685: my %offloadstr;
7686: foreach my $sparetype (@sparestypes) {
7687: if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
7688: if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
7689: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
7690: }
7691: }
7692: }
7693: if (keys(%offloadstr) == 0) {
7694: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
7695: } else {
7696: my $showoffload;
7697: foreach my $sparetype (@sparestypes) {
7698: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
7699: if (defined($offloadstr{$sparetype})) {
7700: $showoffload .= $offloadstr{$sparetype};
7701: } else {
7702: $showoffload .= &mt('None');
7703: }
7704: $showoffload .= (' 'x3);
7705: }
7706: $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
7707: }
7708: }
7709: if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
7710: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7711: foreach my $type (@{$alltypes}) {
7712: if ($changes{'rules'}{$type}) {
7713: my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
7714: my $balancetext;
7715: if ($rule eq '') {
7716: $balancetext = $ruletitles{'default'};
7717: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
7718: $balancetext = $ruletitles{$rule};
7719: } else {
7720: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
7721: }
7722: $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';
7723: }
7724: }
7725: }
7726: }
7727: if ($resulttext ne '') {
7728: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
7729: } else {
7730: $resulttext = $nochgmsg;
7731: }
7732: } else {
7733: $resulttext = $nochgmsg;
7734: if ($balancer ne '') {
7735: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
7736: }
7737: }
7738: } else {
7739: $resulttext = '<span class="LC_error">'.
7740: &mt('An error occurred: [_1]',$putresult).'</span>';
7741: }
7742: } else {
7743: $resulttext = $nochgmsg;
7744: }
7745: } else {
7746: $resulttext = &mt('Load Balancing unavailable as this domain only has one server.');
7747: }
7748: return $resulttext;
7749: }
7750:
1.48 raeburn 7751: sub recurse_check {
7752: my ($chkcats,$categories,$depth,$name) = @_;
7753: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7754: my $chg = 0;
7755: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7756: my $category = $chkcats->[$depth]{$name}[$j];
7757: my $item;
7758: if ($category eq '') {
7759: $chg ++;
7760: } else {
7761: my $deeper = $depth + 1;
7762: $item = &escape($category).':'.&escape($name).':'.$depth;
7763: if ($chg) {
7764: $categories->{$item} -= $chg;
7765: }
7766: &recurse_check($chkcats,$categories,$deeper,$category);
7767: $deeper --;
7768: }
7769: }
7770: }
7771: return;
7772: }
7773:
7774: sub recurse_cat_deletes {
7775: my ($item,$coursecategories,$deletions) = @_;
7776: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7777: my $subdepth = $depth + 1;
7778: if (ref($coursecategories) eq 'HASH') {
7779: foreach my $subitem (keys(%{$coursecategories})) {
7780: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7781: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7782: delete($coursecategories->{$subitem});
7783: $deletions->{$subitem} = 1;
7784: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7785: }
7786: }
7787: }
7788: return;
7789: }
7790:
1.125 raeburn 7791: sub get_active_dcs {
7792: my ($dom) = @_;
7793: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7794: my %domcoords;
7795: my $numdcs = 0;
7796: my $now = time;
7797: foreach my $server (keys(%dompersonnel)) {
7798: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7799: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7800: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7801: if (($end eq '') || ($end == 0) || ($end > $now)) {
7802: if ($start <= $now) {
7803: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7804: }
7805: }
7806: }
7807: }
7808: return %domcoords;
7809: }
7810:
7811: sub active_dc_picker {
7812: my ($dom,$curr_dc) = @_;
7813: my %domcoords = &get_active_dcs($dom);
7814: my @dcs = sort(keys(%domcoords));
7815: my $numdcs = scalar(@dcs);
7816: my $datatable;
7817: my $numinrow = 2;
7818: if ($numdcs > 1) {
7819: $datatable = '<table>';
7820: for (my $i=0; $i<@dcs; $i++) {
7821: my $rem = $i%($numinrow);
7822: if ($rem == 0) {
7823: if ($i > 0) {
7824: $datatable .= '</tr>';
7825: }
7826: $datatable .= '<tr>';
7827: }
7828: my $check = ' ';
7829: if ($curr_dc eq '') {
7830: if (!$i) {
7831: $check = ' checked="checked" ';
7832: }
7833: } elsif ($dcs[$i] eq $curr_dc) {
7834: $check = ' checked="checked" ';
7835: }
7836: if ($i == @dcs - 1) {
7837: my $colsleft = $numinrow - $rem;
7838: if ($colsleft > 1) {
7839: $datatable .= '<td colspan="'.$colsleft.'">';
7840: } else {
7841: $datatable .= '<td>';
7842: }
7843: } else {
7844: $datatable .= '<td>';
7845: }
7846: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7847: $datatable .= '<span class="LC_nobreak"><label>'.
7848: '<input type="radio" name="autocreate_xmldc"'.
7849: ' value="'.$dcs[$i].'"'.$check.'/>'.
7850: &Apache::loncommon::plainname($dcname,$dcdom).
7851: '</label></span></td>';
7852: }
7853: $datatable .= '</tr></table>';
7854: } elsif (@dcs) {
7855: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7856: $dcs[0].'" />';
7857: }
7858: return ($numdcs,$datatable);
7859: }
7860:
1.137 raeburn 7861: sub usersession_titles {
7862: return &Apache::lonlocal::texthash(
7863: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7864:
7865: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 7866: spares => 'Servers offloaded to, when busy',
1.137 raeburn 7867: version => 'LON-CAPA version requirement',
1.138 raeburn 7868: excludedomain => 'Allow all, but exclude specific domains',
7869: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 7870: primary => 'Primary (checked first)',
7871: default => 'Default',
1.137 raeburn 7872: );
7873: }
7874:
1.152 ! raeburn 7875: sub id_for_thisdom {
! 7876: my (%servers) = @_;
! 7877: my %altids;
! 7878: foreach my $server (keys(%servers)) {
! 7879: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
! 7880: if ($serverhome ne $server) {
! 7881: $altids{$serverhome} = $server;
! 7882: }
! 7883: }
! 7884: return %altids;
! 7885: }
! 7886:
1.150 raeburn 7887: sub count_servers {
7888: my ($currbalancer,%servers) = @_;
7889: my (@spares,$numspares);
7890: foreach my $lonhost (sort(keys(%servers))) {
7891: next if ($currbalancer eq $lonhost);
7892: push(@spares,$lonhost);
7893: }
7894: if ($currbalancer) {
7895: $numspares = scalar(@spares);
7896: } else {
7897: $numspares = scalar(@spares) - 1;
7898: }
7899: return ($numspares,@spares);
7900: }
7901:
7902: sub lonbalance_targets_js {
7903: my ($dom,$types,$servers) = @_;
7904: my $select = &mt('Select');
7905: my ($alltargets,$allishome,$allinsttypes,@alltypes);
7906: if (ref($servers) eq 'HASH') {
7907: $alltargets = join("','",sort(keys(%{$servers})));
7908: my @homedoms;
7909: foreach my $server (sort(keys(%{$servers}))) {
7910: if (&Apache::lonnet::host_domain($server) eq $dom) {
7911: push(@homedoms,'1');
7912: } else {
7913: push(@homedoms,'0');
7914: }
7915: }
7916: $allishome = join("','",@homedoms);
7917: }
7918: if (ref($types) eq 'ARRAY') {
7919: if (@{$types} > 0) {
7920: @alltypes = @{$types};
7921: }
7922: }
7923: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
7924: $allinsttypes = join("','",@alltypes);
7925: return <<"END";
7926:
7927: <script type="text/javascript">
7928: // <![CDATA[
7929:
7930: function toggleTargets() {
7931: var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
7932: if (balancer == '') {
7933: hideSpares();
7934: } else {
7935: var homedoms = new Array('$allishome');
7936: var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
7937: showSpares(balancer,ishomedom);
7938: }
7939: return;
7940: }
7941:
7942: function showSpares(balancer,ishomedom) {
7943: var alltargets = new Array('$alltargets');
7944: var insttypes = new Array('$allinsttypes');
1.151 raeburn 7945: var offloadtypes = new Array('primary','default');
7946:
1.150 raeburn 7947: document.getElementById('loadbalancing_targets').style.display='block';
7948: document.getElementById('loadbalancing_disabled').style.display='none';
1.152 ! raeburn 7949:
1.151 raeburn 7950: for (var i=0; i<offloadtypes.length; i++) {
7951: var count = 0;
7952: for (var j=0; j<alltargets.length; j++) {
7953: if (alltargets[j] != balancer) {
7954: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
7955: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
7956: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
7957: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
7958: count ++;
7959: }
1.150 raeburn 7960: }
7961: }
1.151 raeburn 7962: for (var k=0; k<insttypes.length; k++) {
7963: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 7964: if (ishomedom == 1) {
1.151 raeburn 7965: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
7966: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 7967: } else {
1.151 raeburn 7968: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
7969: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150 raeburn 7970:
7971: }
7972: } else {
1.151 raeburn 7973: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
7974: document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150 raeburn 7975: }
1.151 raeburn 7976: if ((insttypes[k] != '_LC_external') &&
7977: ((insttypes[k] != '_LC_internetdom') ||
7978: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
7979: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
7980: for (var m=0; m<alltargets.length; m++) {
7981: var idx = m+1;
7982: if (alltargets[m] != balancer) {
7983: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 7984: }
7985: }
7986: }
7987: }
7988: return;
7989: }
7990:
7991: function hideSpares() {
7992: var alltargets = new Array('$alltargets');
7993: var insttypes = new Array('$allinsttypes');
7994: var offloadtypes = new Array('primary','default');
7995:
7996: document.getElementById('loadbalancing_targets').style.display='none';
7997: document.getElementById('loadbalancing_disabled').style.display='block';
7998:
7999: var total = alltargets.length - 1;
8000: for (var i=0; i<offloadtypes; i++) {
8001: for (var j=0; j<total; j++) {
8002: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
8003: document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
8004: document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8005: }
1.150 raeburn 8006: }
8007: for (var k=0; k<insttypes.length; k++) {
1.151 raeburn 8008: document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
8009: document.getElementById('balancerule_'+insttypes[k]).style.display='none';
8010: if (insttypes[k] != '_LC_external') {
8011: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
8012: document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8013: }
8014: }
8015: return;
8016: }
8017:
8018: function checkOffloads(item,type) {
8019: var alltargets = new Array('$alltargets');
8020: var offloadtypes = new Array('primary','default');
8021: if (item.checked) {
8022: var total = alltargets.length - 1;
8023: var other;
8024: if (type == offloadtypes[0]) {
1.151 raeburn 8025: other = offloadtypes[1];
1.150 raeburn 8026: } else {
1.151 raeburn 8027: other = offloadtypes[0];
1.150 raeburn 8028: }
8029: for (var i=0; i<total; i++) {
8030: var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
8031: if (server == item.value) {
8032: if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
8033: document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
8034: }
8035: }
8036: }
8037: }
8038: return;
8039: }
8040:
8041: function singleServerToggle(type) {
8042: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
8043: if (offloadtoSelIdx == 0) {
8044: document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
8045: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8046:
8047: } else {
8048: document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
8049: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8050: }
8051: return;
8052: }
8053:
8054: function balanceruleChange(formname,type) {
8055: if (type == '_LC_external') {
8056: return;
8057: }
8058: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
8059: for (var i=0; i<typesRules.length; i++) {
8060: if (formname.elements[typesRules[i]].checked) {
8061: if (formname.elements[typesRules[i]].value != 'specific') {
8062: document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
8063: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
8064: } else {
8065: document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
8066: }
8067: }
8068: }
8069: return;
8070: }
8071:
1.152 ! raeburn 8072: // ]]>
! 8073: </script>
! 8074:
! 8075: END
! 8076: }
! 8077:
! 8078: sub new_spares_js {
! 8079: my @sparestypes = ('primary','default');
! 8080: my $types = join("','",@sparestypes);
! 8081: my $select = &mt('Select');
! 8082: return <<"END";
! 8083:
! 8084: <script type="text/javascript">
! 8085: // <![CDATA[
! 8086:
! 8087: function updateNewSpares(formname,lonhost) {
! 8088: var types = new Array('$types');
! 8089: var include = new Array();
! 8090: var exclude = new Array();
! 8091: for (var i=0; i<types.length; i++) {
! 8092: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
! 8093: for (var j=0; j<spareboxes.length; j++) {
! 8094: if (formname.elements[spareboxes[j]].checked) {
! 8095: exclude.push(formname.elements[spareboxes[j]].value);
! 8096: } else {
! 8097: include.push(formname.elements[spareboxes[j]].value);
! 8098: }
! 8099: }
! 8100: }
! 8101: for (var i=0; i<types.length; i++) {
! 8102: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
! 8103: var selIdx = newSpare.selectedIndex;
! 8104: var currnew = newSpare.options[selIdx].value;
! 8105: var okSpares = new Array();
! 8106: for (var j=0; j<newSpare.options.length; j++) {
! 8107: var possible = newSpare.options[j].value;
! 8108: if (possible != '') {
! 8109: if (exclude.indexOf(possible) == -1) {
! 8110: okSpares.push(possible);
! 8111: } else {
! 8112: if (currnew == possible) {
! 8113: selIdx = 0;
! 8114: }
! 8115: }
! 8116: }
! 8117: }
! 8118: for (var k=0; k<include.length; k++) {
! 8119: if (okSpares.indexOf(include[k]) == -1) {
! 8120: okSpares.push(include[k]);
! 8121: }
! 8122: }
! 8123: okSpares.sort();
! 8124: newSpare.options.length = 0;
! 8125: if (selIdx == 0) {
! 8126: newSpare.options[0] = new Option("$select","",true,true);
! 8127: } else {
! 8128: newSpare.options[0] = new Option("$select","",false,false);
! 8129: }
! 8130: for (var m=0; m<okSpares.length; m++) {
! 8131: var idx = m+1;
! 8132: var selThis = 0;
! 8133: if (selIdx != 0) {
! 8134: if (okSpares[m] == currnew) {
! 8135: selThis = 1;
! 8136: }
! 8137: }
! 8138: if (selThis == 1) {
! 8139: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
! 8140: } else {
! 8141: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
! 8142: }
! 8143: }
! 8144: }
! 8145: return;
! 8146: }
! 8147:
! 8148: function checkNewSpares(lonhost,type) {
! 8149: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
! 8150: var chosen = newSpare.options[newSpare.selectedIndex].value;
! 8151: if (chosen != '') {
! 8152: var othertype;
! 8153: var othernewSpare;
! 8154: if (type == 'primary') {
! 8155: othernewSpare = document.getElementById('newspare_default_'+lonhost);
! 8156: }
! 8157: if (type == 'default') {
! 8158: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
! 8159: }
! 8160: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
! 8161: othernewSpare.selectedIndex = 0;
! 8162: }
! 8163: }
! 8164: return;
! 8165: }
! 8166:
! 8167: // ]]>
! 8168: </script>
! 8169:
! 8170: END
! 8171:
! 8172: }
! 8173:
! 8174: sub common_domprefs_js {
! 8175: return <<"END";
! 8176:
! 8177: <script type="text/javascript">
! 8178: // <![CDATA[
! 8179:
1.150 raeburn 8180: function getIndicesByName(formname,item) {
1.152 ! raeburn 8181: var group = new Array();
1.150 raeburn 8182: for (var i=0;i<formname.elements.length;i++) {
8183: if (formname.elements[i].name == item) {
1.152 ! raeburn 8184: group.push(formname.elements[i].id);
1.150 raeburn 8185: }
8186: }
1.152 ! raeburn 8187: return group;
1.150 raeburn 8188: }
8189:
8190: // ]]>
8191: </script>
8192:
8193: END
1.152 ! raeburn 8194:
1.150 raeburn 8195: }
8196:
1.3 raeburn 8197: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>