Annotation of loncom/interface/domainprefs.pm, revision 1.180
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.180 ! raeburn 4: # $Id: domainprefs.pm,v 1.179 2012/12/20 02:43:28 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
1.163 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
1.104 raeburn 108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 109: which have the following effects:
110:
111: 0
112:
113: =over
114:
115: - course requests are not allowed for this course types/affiliation
116:
117: =back
118:
1.104 raeburn 119: approval
1.101 raeburn 120:
121: =over
122:
123: - course requests must be approved by a Doman Coordinator in the
124: course's domain
125:
126: =back
127:
128: validate
129:
130: =over
131:
132: - an institutional validation (e.g., check requestor is instructor
133: of record) needs to be passed before the course will be created. The required
134: validation is in localenroll.pm on the primary library server for the course
135: domain.
136:
137: =back
138:
139: autolimit
140:
141: =over
142:
1.143 raeburn 143: - course requests will be processed automatically up to a limit of
1.101 raeburn 144: N requests for the course type for the particular requestor.
145: If N is undefined, there is no limit to the number of course requests
146: which a course owner may submit and have processed automatically.
147:
148: =back
149:
150: =item modify_quotas()
151:
152: =back
153:
154: =cut
155:
1.1 raeburn 156: package Apache::domainprefs;
157:
158: use strict;
159: use Apache::Constants qw(:common :http);
160: use Apache::lonnet;
161: use Apache::loncommon();
162: use Apache::lonhtmlcommon();
163: use Apache::lonlocal;
1.43 raeburn 164: use Apache::lonmsg();
1.91 raeburn 165: use Apache::lonconfigsettings;
1.69 raeburn 166: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 167: use LONCAPA::Enrollment;
1.81 raeburn 168: use LONCAPA::lonauthcgi();
1.9 raeburn 169: use File::Copy;
1.43 raeburn 170: use Locale::Language;
1.62 raeburn 171: use DateTime::TimeZone;
1.68 raeburn 172: use DateTime::Locale;
1.1 raeburn 173:
1.155 raeburn 174: my $registered_cleanup;
175: my $modified_urls;
176:
1.1 raeburn 177: sub handler {
178: my $r=shift;
179: if ($r->header_only) {
180: &Apache::loncommon::content_type($r,'text/html');
181: $r->send_http_header;
182: return OK;
183: }
184:
1.91 raeburn 185: my $context = 'domain';
1.1 raeburn 186: my $dom = $env{'request.role.domain'};
1.5 albertel 187: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 188: if (&Apache::lonnet::allowed('mau',$dom)) {
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: } else {
192: $env{'user.error.msg'}=
193: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
194: return HTTP_NOT_ACCEPTABLE;
195: }
1.155 raeburn 196:
197: $registered_cleanup=0;
198: @{$modified_urls}=();
199:
1.1 raeburn 200: &Apache::lonhtmlcommon::clear_breadcrumbs();
201: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 202: ['phase','actions']);
1.30 raeburn 203: my $phase = 'pickactions';
1.3 raeburn 204: if ( exists($env{'form.phase'}) ) {
205: $phase = $env{'form.phase'};
206: }
1.150 raeburn 207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 208: my %domconfig =
1.6 raeburn 209: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 210: 'quotas','autoenroll','autoupdate','autocreate',
211: 'directorysrch','usercreation','usermodification',
212: 'contacts','defaults','scantron','coursecategories',
213: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 214: 'coursedefaults','usersessions','loadbalancing',
215: 'requestauthor'],$dom);
1.43 raeburn 216: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 217: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 218: 'usercreation','usermodification','scantron',
1.163 raeburn 219: 'requestcourses','requestauthor','coursecategories',
220: 'serverstatuses','helpsettings',
1.137 raeburn 221: 'coursedefaults','usersessions');
1.171 raeburn 222: my %existing;
223: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
224: %existing = %{$domconfig{'loadbalancing'}};
225: }
226: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 227: push(@prefs_order,'loadbalancing');
228: }
1.30 raeburn 229: my %prefs = (
230: 'rolecolors' =>
231: { text => 'Default color schemes',
1.67 raeburn 232: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 233: header => [{col1 => 'Student Settings',
234: col2 => '',},
235: {col1 => 'Coordinator Settings',
236: col2 => '',},
237: {col1 => 'Author Settings',
238: col2 => '',},
239: {col1 => 'Administrator Settings',
240: col2 => '',}],
241: },
1.110 raeburn 242: 'login' =>
1.30 raeburn 243: { text => 'Log-in page options',
1.67 raeburn 244: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 245: header => [{col1 => 'Log-in Page Items',
246: col2 => '',},
247: {col1 => 'Log-in Help',
248: col2 => 'Value'}],
1.30 raeburn 249: },
1.43 raeburn 250: 'defaults' =>
1.141 raeburn 251: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 252: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 253: header => [{col1 => 'Setting',
254: col2 => 'Value'}],
255: },
1.30 raeburn 256: 'quotas' =>
1.162 raeburn 257: { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67 raeburn 258: help => 'Domain_Configuration_Quotas',
1.77 raeburn 259: header => [{col1 => 'User affiliation',
1.72 raeburn 260: col2 => 'Available tools',
261: col3 => 'Portfolio quota',}],
1.30 raeburn 262: },
263: 'autoenroll' =>
264: { text => 'Auto-enrollment settings',
1.67 raeburn 265: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 266: header => [{col1 => 'Configuration setting',
267: col2 => 'Value(s)'}],
268: },
269: 'autoupdate' =>
270: { text => 'Auto-update settings',
1.67 raeburn 271: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 272: header => [{col1 => 'Setting',
273: col2 => 'Value',},
1.131 raeburn 274: {col1 => 'Setting',
275: col2 => 'Affiliation'},
1.43 raeburn 276: {col1 => 'User population',
1.131 raeburn 277: col2 => 'Updateable user data'}],
1.30 raeburn 278: },
1.125 raeburn 279: 'autocreate' =>
280: { text => 'Auto-course creation settings',
281: help => 'Domain_Configuration_Auto_Creation',
282: header => [{col1 => 'Configuration Setting',
283: col2 => 'Value',}],
284: },
1.30 raeburn 285: 'directorysrch' =>
286: { text => 'Institutional directory searches',
1.67 raeburn 287: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 288: header => [{col1 => 'Setting',
289: col2 => 'Value',}],
290: },
291: 'contacts' =>
292: { text => 'Contact Information',
1.67 raeburn 293: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 294: header => [{col1 => 'Setting',
295: col2 => 'Value',}],
296: },
297:
298: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.69 raeburn 308: 'usermodification' =>
1.33 raeburn 309: { text => 'User modification',
1.67 raeburn 310: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 311: header => [{col1 => 'Target user has role',
312: col2 => 'User information updateable in author context'},
313: {col1 => 'Target user has role',
1.63 raeburn 314: col2 => 'User information updateable in course context'},
315: {col1 => "Status of user",
316: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 317: },
1.69 raeburn 318: 'scantron' =>
1.95 www 319: { text => 'Bubblesheet format file',
1.67 raeburn 320: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 321: header => [ {col1 => 'Item',
322: col2 => '',
323: }],
324: },
1.86 raeburn 325: 'requestcourses' =>
326: {text => 'Request creation of courses',
327: help => 'Domain_Configuration_Request_Courses',
328: header => [{col1 => 'User affiliation',
1.102 raeburn 329: col2 => 'Availability/Processing of requests',},
330: {col1 => 'Setting',
331: col2 => 'Value'}],
1.86 raeburn 332: },
1.163 raeburn 333: 'requestauthor' =>
334: {text => 'Request authoring space',
335: help => 'Domain_Configuration_Request_Author',
336: header => [{col1 => 'User affiliation',
337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
339: col2 => 'Value'}],
340: },
1.69 raeburn 341: 'coursecategories' =>
1.120 raeburn 342: { text => 'Cataloging of courses/communities',
1.67 raeburn 343: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 344: header => [{col1 => 'Category settings',
1.57 raeburn 345: col2 => '',},
346: {col1 => 'Categories',
347: col2 => '',
348: }],
1.69 raeburn 349: },
350: 'serverstatuses' =>
1.77 raeburn 351: {text => 'Access to server status pages',
1.69 raeburn 352: help => 'Domain_Configuration_Server_Status',
353: header => [{col1 => 'Status Page',
354: col2 => 'Other named users',
355: col3 => 'Specific IPs',
356: }],
357: },
1.118 jms 358: 'helpsettings' =>
359: {text => 'Help page settings',
360: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 361: header => [{col1 => 'Help Settings (logged-in users)',
362: col2 => 'Value'}],
1.118 jms 363: },
1.121 raeburn 364: 'coursedefaults' =>
365: {text => 'Course/Community defaults',
366: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 367: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
368: col2 => 'Value',},
369: {col1 => 'Defaults which can be overridden for each course by a DC',
370: col2 => 'Value',},],
1.121 raeburn 371: },
1.120 raeburn 372: 'privacy' =>
373: {text => 'User Privacy',
374: help => 'Domain_Configuration_User_Privacy',
375: header => [{col1 => 'Setting',
376: col2 => 'Value',}],
377: },
1.141 raeburn 378: 'usersessions' =>
1.145 raeburn 379: {text => 'User session hosting/offloading',
1.137 raeburn 380: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 381: header => [{col1 => 'Domain server',
382: col2 => 'Servers to offload sessions to when busy'},
383: {col1 => 'Hosting of users from other domains',
1.137 raeburn 384: col2 => 'Rules'},
385: {col1 => "Hosting domain's own users elsewhere",
386: col2 => 'Rules'}],
387: },
1.150 raeburn 388: 'loadbalancing' =>
389: {text => 'Dedicated Load Balancer',
390: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 391: header => [{col1 => 'Balancers',
1.150 raeburn 392: col2 => 'Default destinations',
393: col3 => 'User affliation',
394: col4 => 'Overrides'},
395: ],
396: },
1.3 raeburn 397: );
1.110 raeburn 398: if (keys(%servers) > 1) {
399: $prefs{'login'} = { text => 'Log-in page options',
400: help => 'Domain_Configuration_Login_Page',
401: header => [{col1 => 'Log-in Service',
402: col2 => 'Server Setting',},
403: {col1 => 'Log-in Page Items',
1.168 raeburn 404: col2 => ''},
405: {col1 => 'Log-in Help',
406: col2 => 'Value'}],
1.110 raeburn 407: };
408: }
1.174 foxr 409:
410:
411:
1.6 raeburn 412: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 413: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 414: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 415: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 416: text=>"Settings to display/modify"});
1.9 raeburn 417: my $confname = $dom.'-domainconfig';
1.174 foxr 418:
1.3 raeburn 419: if ($phase eq 'process') {
1.91 raeburn 420: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 421: } elsif ($phase eq 'display') {
1.165 raeburn 422: my $js = &recaptcha_js();
1.171 raeburn 423: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 424: my ($othertitle,$usertypes,$types) =
425: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 426: $js .= &lonbalance_targets_js($dom,$types,\%servers,
427: $domconfig{'loadbalancing'}).
1.170 raeburn 428: &new_spares_js().
429: &common_domprefs_js().
430: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 431: }
1.150 raeburn 432: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 433: } else {
1.180 ! raeburn 434: # check if domconfig user exists for the domain.
! 435: my $servadm = $r->dir_config('lonAdmEMail');
! 436: my ($configuserok,$author_ok,$switchserver) =
! 437: &config_check($dom,$confname,$servadm);
! 438: unless ($configuserok eq 'ok') {
! 439: &Apache::lonconfigsettings::print_header($r,$phase,$context).
! 440: &mt('The domain configuration user "[_1]" has yet to be created.',
! 441: $confname).
! 442: '<br />';
! 443: if ($switchserver) {
! 444: &mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
! 445: '<br />'.
! 446: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
! 447: '<br />'.
! 448: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
! 449: '<br />'.
! 450: &mt("To do that now, use the following link: [_1],$switchserver);
! 451: } else {
! 452: &mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
! 453: '<br />'.
! 454: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain');
! 455: }
! 456: $r->print(&Apache::loncommon::end_page());
! 457: return OK;
! 458: }
1.21 raeburn 459: if (keys(%domconfig) == 0) {
460: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 461: my @ids=&Apache::lonnet::current_machine_ids();
462: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 463: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 464: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 465: my $custom_img_count = 0;
466: foreach my $img (@loginimages) {
467: if ($designhash{$dom.'.login.'.$img} ne '') {
468: $custom_img_count ++;
469: }
470: }
471: foreach my $role (@roles) {
472: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
473: $custom_img_count ++;
474: }
475: }
476: if ($custom_img_count > 0) {
1.94 raeburn 477: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 478: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 479: $r->print(
480: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
481: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
482: &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 />'.
483: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
484: if ($switch_server) {
1.30 raeburn 485: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 486: }
1.91 raeburn 487: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 488: return OK;
489: }
490: }
491: }
1.174 foxr 492:
1.91 raeburn 493: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 494: }
495: return OK;
496: }
497:
498: sub process_changes {
1.92 raeburn 499: my ($r,$dom,$confname,$action,$roles,$values) = @_;
500: my %domconfig;
501: if (ref($values) eq 'HASH') {
502: %domconfig = %{$values};
503: }
1.3 raeburn 504: my $output;
505: if ($action eq 'login') {
1.9 raeburn 506: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 507: } elsif ($action eq 'rolecolors') {
1.9 raeburn 508: $output = &modify_rolecolors($r,$dom,$confname,$roles,
509: %domconfig);
1.3 raeburn 510: } elsif ($action eq 'quotas') {
1.86 raeburn 511: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 512: } elsif ($action eq 'autoenroll') {
513: $output = &modify_autoenroll($dom,%domconfig);
514: } elsif ($action eq 'autoupdate') {
515: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 516: } elsif ($action eq 'autocreate') {
517: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 518: } elsif ($action eq 'directorysrch') {
519: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 520: } elsif ($action eq 'usercreation') {
1.28 raeburn 521: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 522: } elsif ($action eq 'usermodification') {
523: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 524: } elsif ($action eq 'contacts') {
525: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 526: } elsif ($action eq 'defaults') {
527: $output = &modify_defaults($dom,$r);
1.46 raeburn 528: } elsif ($action eq 'scantron') {
1.48 raeburn 529: $output = &modify_scantron($r,$dom,$confname,%domconfig);
530: } elsif ($action eq 'coursecategories') {
531: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 532: } elsif ($action eq 'serverstatuses') {
533: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 534: } elsif ($action eq 'requestcourses') {
535: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 536: } elsif ($action eq 'requestauthor') {
537: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 538: } elsif ($action eq 'helpsettings') {
1.122 jms 539: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 540: } elsif ($action eq 'coursedefaults') {
541: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 542: } elsif ($action eq 'usersessions') {
543: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 544: } elsif ($action eq 'loadbalancing') {
545: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 546: }
547: return $output;
548: }
549:
550: sub print_config_box {
1.9 raeburn 551: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 552: my $rowtotal = 0;
1.49 raeburn 553: my $output;
1.174 foxr 554:
1.49 raeburn 555: if ($action eq 'coursecategories') {
556: $output = &coursecategories_javascript($settings);
1.91 raeburn 557: }
1.49 raeburn 558: $output .=
1.30 raeburn 559: '<table class="LC_nested_outer">
1.3 raeburn 560: <tr>
1.66 raeburn 561: <th align="left" valign="middle"><span class="LC_nobreak">'.
562: &mt($item->{text}).' '.
563: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
564: '</tr>';
1.30 raeburn 565: $rowtotal ++;
1.110 raeburn 566: my $numheaders = 1;
567: if (ref($item->{'header'}) eq 'ARRAY') {
568: $numheaders = scalar(@{$item->{'header'}});
569: }
570: if ($numheaders > 1) {
1.64 raeburn 571: my $colspan = '';
1.145 raeburn 572: my $rightcolspan = '';
1.168 raeburn 573: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
574: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 575: $colspan = ' colspan="2"';
576: }
1.145 raeburn 577: if ($action eq 'usersessions') {
578: $rightcolspan = ' colspan="3"';
579: }
1.30 raeburn 580: $output .= '
1.3 raeburn 581: <tr>
582: <td>
583: <table class="LC_nested">
584: <tr class="LC_info_row">
1.59 bisitz 585: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 586: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 587: </tr>';
1.69 raeburn 588: $rowtotal ++;
1.6 raeburn 589: if ($action eq 'autoupdate') {
1.30 raeburn 590: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 591: } elsif ($action eq 'usercreation') {
1.33 raeburn 592: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
593: } elsif ($action eq 'usermodification') {
594: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 595: } elsif ($action eq 'coursecategories') {
596: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 597: } elsif ($action eq 'login') {
1.168 raeburn 598: if ($numheaders == 3) {
599: $colspan = ' colspan="2"';
600: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
601: } else {
602: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
603: }
1.102 raeburn 604: } elsif ($action eq 'requestcourses') {
605: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 606: } elsif ($action eq 'requestauthor') {
607: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 608: } elsif ($action eq 'usersessions') {
609: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 610: } elsif ($action eq 'rolecolors') {
1.30 raeburn 611: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 612: } elsif ($action eq 'coursedefaults') {
613: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 614: }
1.30 raeburn 615: $output .= '
1.6 raeburn 616: </table>
617: </td>
618: </tr>
619: <tr>
620: <td>
621: <table class="LC_nested">
622: <tr class="LC_info_row">
1.59 bisitz 623: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 624: $output .= '
1.59 bisitz 625: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 626: </tr>';
627: $rowtotal ++;
1.6 raeburn 628: if ($action eq 'autoupdate') {
1.131 raeburn 629: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
630: </table>
631: </td>
632: </tr>
633: <tr>
634: <td>
635: <table class="LC_nested">
636: <tr class="LC_info_row">
637: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
638: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
639: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
640: $rowtotal ++;
1.28 raeburn 641: } elsif ($action eq 'usercreation') {
1.34 raeburn 642: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
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'}->[2]->{'col1'}).'</td>
651: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 652: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
653: $rowtotal ++;
1.33 raeburn 654: } elsif ($action eq 'usermodification') {
1.63 raeburn 655: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
656: </table>
657: </td>
658: </tr>
659: <tr>
660: <td>
661: <table class="LC_nested">
662: <tr class="LC_info_row">
663: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
664: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
665: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
666: $rowtotal ++;
1.57 raeburn 667: } elsif ($action eq 'coursecategories') {
668: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 669: } elsif ($action eq 'login') {
1.168 raeburn 670: if ($numheaders == 3) {
671: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
672: </table>
673: </td>
674: </tr>
675: <tr>
676: <td>
677: <table class="LC_nested">
678: <tr class="LC_info_row">
679: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
680: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
681: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
682: $rowtotal ++;
683: } else {
684: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
685: }
1.102 raeburn 686: } elsif ($action eq 'requestcourses') {
1.163 raeburn 687: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
688: } elsif ($action eq 'requestauthor') {
689: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 690: } elsif ($action eq 'usersessions') {
1.145 raeburn 691: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
692: </table>
693: </td>
694: </tr>
695: <tr>
696: <td>
697: <table class="LC_nested">
698: <tr class="LC_info_row">
699: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
700: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
701: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
702: $rowtotal ++;
1.139 raeburn 703: } elsif ($action eq 'coursedefaults') {
704: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 705: } elsif ($action eq 'rolecolors') {
1.30 raeburn 706: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 707: </table>
708: </td>
709: </tr>
710: <tr>
711: <td>
712: <table class="LC_nested">
713: <tr class="LC_info_row">
1.69 raeburn 714: <td class="LC_left_item"'.$colspan.' valign="top">'.
715: &mt($item->{'header'}->[2]->{'col1'}).'</td>
716: <td class="LC_right_item" valign="top">'.
717: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 718: </tr>'.
1.30 raeburn 719: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 720: </table>
721: </td>
722: </tr>
723: <tr>
724: <td>
725: <table class="LC_nested">
726: <tr class="LC_info_row">
1.59 bisitz 727: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
728: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 729: </tr>'.
1.30 raeburn 730: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
731: $rowtotal += 2;
1.6 raeburn 732: }
1.3 raeburn 733: } else {
1.30 raeburn 734: $output .= '
1.3 raeburn 735: <tr>
736: <td>
737: <table class="LC_nested">
1.30 raeburn 738: <tr class="LC_info_row">';
1.24 raeburn 739: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 740: $output .= '
1.59 bisitz 741: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 742: } elsif ($action eq 'serverstatuses') {
743: $output .= '
744: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
745: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
746:
1.6 raeburn 747: } else {
1.30 raeburn 748: $output .= '
1.69 raeburn 749: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
750: }
1.72 raeburn 751: if (defined($item->{'header'}->[0]->{'col3'})) {
752: $output .= '<td class="LC_left_item" valign="top">'.
753: &mt($item->{'header'}->[0]->{'col2'});
754: if ($action eq 'serverstatuses') {
755: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
756: }
1.69 raeburn 757: } else {
758: $output .= '<td class="LC_right_item" valign="top">'.
759: &mt($item->{'header'}->[0]->{'col2'});
760: }
761: $output .= '</td>';
762: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 763: if (defined($item->{'header'}->[0]->{'col4'})) {
764: $output .= '<td class="LC_left_item" valign="top">'.
765: &mt($item->{'header'}->[0]->{'col3'});
766: } else {
767: $output .= '<td class="LC_right_item" valign="top">'.
768: &mt($item->{'header'}->[0]->{'col3'});
769: }
1.69 raeburn 770: if ($action eq 'serverstatuses') {
771: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
772: }
773: $output .= '</td>';
1.6 raeburn 774: }
1.150 raeburn 775: if ($item->{'header'}->[0]->{'col4'}) {
776: $output .= '<td class="LC_right_item" valign="top">'.
777: &mt($item->{'header'}->[0]->{'col4'});
778: }
1.69 raeburn 779: $output .= '</tr>';
1.48 raeburn 780: $rowtotal ++;
1.168 raeburn 781: if ($action eq 'quotas') {
1.86 raeburn 782: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 783: } elsif ($action eq 'autoenroll') {
1.30 raeburn 784: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 785: } elsif ($action eq 'autocreate') {
786: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 787: } elsif ($action eq 'directorysrch') {
1.30 raeburn 788: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 789: } elsif ($action eq 'contacts') {
1.30 raeburn 790: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 791: } elsif ($action eq 'defaults') {
792: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 793: } elsif ($action eq 'scantron') {
794: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 795: } elsif ($action eq 'serverstatuses') {
796: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 797: } elsif ($action eq 'helpsettings') {
1.168 raeburn 798: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 799: } elsif ($action eq 'loadbalancing') {
800: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 801: }
1.3 raeburn 802: }
1.30 raeburn 803: $output .= '
1.3 raeburn 804: </table>
805: </td>
806: </tr>
1.30 raeburn 807: </table><br />';
808: return ($output,$rowtotal);
1.1 raeburn 809: }
810:
1.3 raeburn 811: sub print_login {
1.168 raeburn 812: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 813: my ($css_class,$datatable);
1.6 raeburn 814: my %choices = &login_choices();
1.110 raeburn 815:
1.168 raeburn 816: if ($caller eq 'service') {
1.149 raeburn 817: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 818: my $choice = $choices{'disallowlogin'};
819: $css_class = ' class="LC_odd_row"';
1.128 raeburn 820: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 821: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 822: '<th>'.$choices{'server'}.'</th>'.
823: '<th>'.$choices{'serverpath'}.'</th>'.
824: '<th>'.$choices{'custompath'}.'</th>'.
825: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 826: my %disallowed;
827: if (ref($settings) eq 'HASH') {
828: if (ref($settings->{'loginvia'}) eq 'HASH') {
829: %disallowed = %{$settings->{'loginvia'}};
830: }
831: }
832: foreach my $lonhost (sort(keys(%servers))) {
833: my $direct = 'selected="selected"';
1.128 raeburn 834: if (ref($disallowed{$lonhost}) eq 'HASH') {
835: if ($disallowed{$lonhost}{'server'} ne '') {
836: $direct = '';
837: }
1.110 raeburn 838: }
1.115 raeburn 839: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 840: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 841: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
842: '</option>';
1.177 bisitz 843: foreach my $hostid (sort keys(%servers)) {
1.115 raeburn 844: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 845: my $selected = '';
1.128 raeburn 846: if (ref($disallowed{$lonhost}) eq 'HASH') {
847: if ($hostid eq $disallowed{$lonhost}{'server'}) {
848: $selected = 'selected="selected"';
849: }
1.110 raeburn 850: }
851: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
852: $servers{$hostid}.'</option>';
853: }
1.128 raeburn 854: $datatable .= '</select></td>'.
855: '<td><select name="'.$lonhost.'_serverpath">';
856: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
857: my $pathname = $path;
858: if ($path eq 'custom') {
859: $pathname = &mt('Custom Path').' ->';
860: }
861: my $selected = '';
862: if (ref($disallowed{$lonhost}) eq 'HASH') {
863: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
864: $selected = 'selected="selected"';
865: }
866: } elsif ($path eq '') {
867: $selected = 'selected="selected"';
868: }
869: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
870: }
871: $datatable .= '</select></td>';
872: my ($custom,$exempt);
873: if (ref($disallowed{$lonhost}) eq 'HASH') {
874: $custom = $disallowed{$lonhost}{'custompath'};
875: $exempt = $disallowed{$lonhost}{'exempt'};
876: }
877: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
878: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
879: '</tr>';
1.110 raeburn 880: }
881: $datatable .= '</table></td></tr>';
882: return $datatable;
1.168 raeburn 883: } elsif ($caller eq 'page') {
884: my %defaultchecked = (
885: 'coursecatalog' => 'on',
886: 'adminmail' => 'off',
887: 'newuser' => 'off',
888: );
889: my @toggles = ('coursecatalog','adminmail','newuser');
890: my (%checkedon,%checkedoff);
1.42 raeburn 891: foreach my $item (@toggles) {
1.168 raeburn 892: if ($defaultchecked{$item} eq 'on') {
893: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 894: $checkedoff{$item} = ' ';
1.168 raeburn 895: } elsif ($defaultchecked{$item} eq 'off') {
896: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 897: $checkedon{$item} = ' ';
898: }
1.1 raeburn 899: }
1.168 raeburn 900: my @images = ('img','logo','domlogo','login');
901: my @logintext = ('textcol','bgcol');
902: my @bgs = ('pgbg','mainbg','sidebg');
903: my @links = ('link','alink','vlink');
904: my %designhash = &Apache::loncommon::get_domainconf($dom);
905: my %defaultdesign = %Apache::loncommon::defaultdesign;
906: my (%is_custom,%designs);
907: my %defaults = (
908: font => $defaultdesign{'login.font'},
909: );
1.6 raeburn 910: foreach my $item (@images) {
1.168 raeburn 911: $defaults{$item} = $defaultdesign{'login.'.$item};
912: $defaults{'showlogo'}{$item} = 1;
913: }
914: foreach my $item (@bgs) {
915: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 916: }
1.41 raeburn 917: foreach my $item (@logintext) {
1.168 raeburn 918: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 919: }
1.168 raeburn 920: foreach my $item (@links) {
921: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 922: }
1.168 raeburn 923: if (ref($settings) eq 'HASH') {
924: foreach my $item (@toggles) {
925: if ($settings->{$item} eq '1') {
926: $checkedon{$item} = ' checked="checked" ';
927: $checkedoff{$item} = ' ';
928: } elsif ($settings->{$item} eq '0') {
929: $checkedoff{$item} = ' checked="checked" ';
930: $checkedon{$item} = ' ';
931: }
932: }
933: foreach my $item (@images) {
934: if (defined($settings->{$item})) {
935: $designs{$item} = $settings->{$item};
936: $is_custom{$item} = 1;
937: }
938: if (defined($settings->{'showlogo'}{$item})) {
939: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
940: }
941: }
942: foreach my $item (@logintext) {
943: if ($settings->{$item} ne '') {
944: $designs{'logintext'}{$item} = $settings->{$item};
945: $is_custom{$item} = 1;
946: }
947: }
948: if ($settings->{'font'} ne '') {
949: $designs{'font'} = $settings->{'font'};
950: $is_custom{'font'} = 1;
951: }
952: foreach my $item (@bgs) {
953: if ($settings->{$item} ne '') {
954: $designs{'bgs'}{$item} = $settings->{$item};
955: $is_custom{$item} = 1;
956: }
957: }
958: foreach my $item (@links) {
959: if ($settings->{$item} ne '') {
960: $designs{'links'}{$item} = $settings->{$item};
961: $is_custom{$item} = 1;
962: }
963: }
964: } else {
965: if ($designhash{$dom.'.login.font'} ne '') {
966: $designs{'font'} = $designhash{$dom.'.login.font'};
967: $is_custom{'font'} = 1;
968: }
969: foreach my $item (@images) {
970: if ($designhash{$dom.'.login.'.$item} ne '') {
971: $designs{$item} = $designhash{$dom.'.login.'.$item};
972: $is_custom{$item} = 1;
973: }
974: }
975: foreach my $item (@bgs) {
976: if ($designhash{$dom.'.login.'.$item} ne '') {
977: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
978: $is_custom{$item} = 1;
979: }
1.6 raeburn 980: }
1.168 raeburn 981: foreach my $item (@links) {
982: if ($designhash{$dom.'.login.'.$item} ne '') {
983: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
984: $is_custom{$item} = 1;
985: }
1.6 raeburn 986: }
987: }
1.168 raeburn 988: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
989: logo => 'Institution Logo',
990: domlogo => 'Domain Logo',
991: login => 'Login box');
992: my $itemcount = 1;
993: foreach my $item (@toggles) {
994: $css_class = $itemcount%2?' class="LC_odd_row"':'';
995: $datatable .=
996: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
997: '</td><td>'.
998: '<span class="LC_nobreak"><label><input type="radio" name="'.
999: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1000: '</label> <label><input type="radio" name="'.$item.'"'.
1001: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1002: '</tr>';
1003: $itemcount ++;
1.6 raeburn 1004: }
1.168 raeburn 1005: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1006: $datatable .= '</tr></table></td></tr>';
1007: } elsif ($caller eq 'help') {
1008: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1009: my $switchserver = &check_switchserver($dom,$confname);
1010: my $itemcount = 1;
1011: $defaulturl = '/adm/loginproblems.html';
1012: $defaulttype = 'default';
1013: %lt = &Apache::lonlocal::texthash (
1014: del => 'Delete?',
1015: rep => 'Replace:',
1016: upl => 'Upload:',
1017: default => 'Default',
1018: custom => 'Custom',
1019: );
1020: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1021: my @currlangs;
1022: if (ref($settings) eq 'HASH') {
1023: if (ref($settings->{'helpurl'}) eq 'HASH') {
1024: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1025: next if ($settings->{'helpurl'}{$key} eq '');
1026: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1027: $type{$key} = 'custom';
1028: unless ($key eq 'nolang') {
1029: push(@currlangs,$key);
1030: }
1031: }
1032: } elsif ($settings->{'helpurl'} ne '') {
1033: $type{'nolang'} = 'custom';
1034: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1035: }
1036: }
1.168 raeburn 1037: foreach my $lang ('nolang',sort(@currlangs)) {
1038: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1039: $datatable .= '<tr'.$css_class.'>';
1040: if ($url{$lang} eq '') {
1041: $url{$lang} = $defaulturl;
1042: }
1043: if ($type{$lang} eq '') {
1044: $type{$lang} = $defaulttype;
1045: }
1046: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1047: if ($lang eq 'nolang') {
1048: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1049: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1050: } else {
1051: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1052: $langchoices{$lang},
1053: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1054: }
1055: $datatable .= '</span></td>'."\n".
1056: '<td class="LC_left_item">';
1057: if ($type{$lang} eq 'custom') {
1058: $datatable .= '<span class="LC_nobreak"><label>'.
1059: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1060: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1061: } else {
1062: $datatable .= $lt{'upl'};
1063: }
1064: $datatable .='<br />';
1065: if ($switchserver) {
1066: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1067: } else {
1068: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1069: }
1.168 raeburn 1070: $datatable .= '</td></tr>';
1071: $itemcount ++;
1.6 raeburn 1072: }
1.168 raeburn 1073: my @addlangs;
1074: foreach my $lang (sort(keys(%langchoices))) {
1075: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1076: push(@addlangs,$lang);
1077: }
1078: if (@addlangs > 0) {
1079: my %toadd;
1080: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1081: $toadd{''} = &mt('Select');
1082: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1083: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1084: &mt('Add log-in help page for a specific language:').' '.
1085: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1086: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1087: if ($switchserver) {
1088: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1089: } else {
1090: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1091: }
1.168 raeburn 1092: $datatable .= '</td></tr>';
1.169 raeburn 1093: $itemcount ++;
1.6 raeburn 1094: }
1.169 raeburn 1095: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1096: }
1.6 raeburn 1097: return $datatable;
1098: }
1099:
1100: sub login_choices {
1101: my %choices =
1102: &Apache::lonlocal::texthash (
1.116 bisitz 1103: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1104: adminmail => "Display Administrator's E-mail Address?",
1105: disallowlogin => "Login page requests redirected",
1106: hostid => "Server",
1.128 raeburn 1107: server => "Redirect to:",
1108: serverpath => "Path",
1109: custompath => "Custom",
1110: exempt => "Exempt IP(s)",
1.110 raeburn 1111: directlogin => "No redirect",
1112: newuser => "Link to create a user account",
1113: img => "Header",
1114: logo => "Main Logo",
1115: domlogo => "Domain Logo",
1116: login => "Log-in Header",
1117: textcol => "Text color",
1118: bgcol => "Box color",
1119: bgs => "Background colors",
1120: links => "Link colors",
1121: font => "Font color",
1122: pgbg => "Header",
1123: mainbg => "Page",
1124: sidebg => "Login box",
1125: link => "Link",
1126: alink => "Active link",
1127: vlink => "Visited link",
1.6 raeburn 1128: );
1129: return %choices;
1130: }
1131:
1132: sub print_rolecolors {
1.30 raeburn 1133: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1134: my %choices = &color_font_choices();
1135: my @bgs = ('pgbg','tabbg','sidebg');
1136: my @links = ('link','alink','vlink');
1137: my @images = ('img');
1138: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1139: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1140: my %defaultdesign = %Apache::loncommon::defaultdesign;
1141: my (%is_custom,%designs);
1142: my %defaults = (
1143: img => $defaultdesign{$role.'.img'},
1144: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1145: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1146: );
1147: foreach my $item (@bgs) {
1148: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1149: }
1150: foreach my $item (@links) {
1151: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1152: }
1153: if (ref($settings) eq 'HASH') {
1154: if (ref($settings->{$role}) eq 'HASH') {
1155: if ($settings->{$role}->{'img'} ne '') {
1156: $designs{'img'} = $settings->{$role}->{'img'};
1157: $is_custom{'img'} = 1;
1158: }
1159: if ($settings->{$role}->{'font'} ne '') {
1160: $designs{'font'} = $settings->{$role}->{'font'};
1161: $is_custom{'font'} = 1;
1162: }
1.97 tempelho 1163: if ($settings->{$role}->{'fontmenu'} ne '') {
1164: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1165: $is_custom{'fontmenu'} = 1;
1166: }
1.6 raeburn 1167: foreach my $item (@bgs) {
1168: if ($settings->{$role}->{$item} ne '') {
1169: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1170: $is_custom{$item} = 1;
1171: }
1172: }
1173: foreach my $item (@links) {
1174: if ($settings->{$role}->{$item} ne '') {
1175: $designs{'links'}{$item} = $settings->{$role}->{$item};
1176: $is_custom{$item} = 1;
1177: }
1178: }
1179: }
1180: } else {
1181: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1182: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1183: $is_custom{'img'} = 1;
1184: }
1.97 tempelho 1185: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1186: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1187: $is_custom{'fontmenu'} = 1;
1188: }
1.6 raeburn 1189: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1190: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1191: $is_custom{'font'} = 1;
1192: }
1193: foreach my $item (@bgs) {
1194: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1195: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1196: $is_custom{$item} = 1;
1197:
1198: }
1199: }
1200: foreach my $item (@links) {
1201: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1202: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1203: $is_custom{$item} = 1;
1204: }
1205: }
1206: }
1207: my $itemcount = 1;
1.30 raeburn 1208: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1209: $datatable .= '</tr></table></td></tr>';
1210: return $datatable;
1211: }
1212:
1213: sub display_color_options {
1.9 raeburn 1214: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1215: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1216: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1217: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1218: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1219: '<td>'.$choices->{'font'}.'</td>';
1220: if (!$is_custom->{'font'}) {
1.30 raeburn 1221: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1222: } else {
1223: $datatable .= '<td> </td>';
1224: }
1.174 foxr 1225: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1226:
1.8 raeburn 1227: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1228: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1229: ' value="'.$current_color.'" /> '.
1230: ' </td></tr>';
1.107 raeburn 1231: unless ($role eq 'login') {
1232: $datatable .= '<tr'.$css_class.'>'.
1233: '<td>'.$choices->{'fontmenu'}.'</td>';
1234: if (!$is_custom->{'fontmenu'}) {
1235: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1236: } else {
1237: $datatable .= '<td> </td>';
1238: }
1.174 foxr 1239: $current_color = $designs->{'fontmenu'} ?
1240: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1241: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1242: '<input class="colorchooser" type="text" size="10" name="'
1243: .$role.'_fontmenu"'.
1244: ' value="'.$current_color.'" /> '.
1245: ' </td></tr>';
1.97 tempelho 1246: }
1.9 raeburn 1247: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1248: foreach my $img (@{$images}) {
1.18 albertel 1249: $itemcount ++;
1.6 raeburn 1250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1251: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1252: '<td>'.$choices->{$img};
1.41 raeburn 1253: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1254: if ($role eq 'login') {
1255: if ($img eq 'login') {
1256: $login_hdr_pick =
1.135 bisitz 1257: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1258: $logincolors =
1259: &login_text_colors($img,$role,$logintext,$phase,$choices,
1260: $designs);
1261: } elsif ($img ne 'domlogo') {
1262: $datatable.= &logo_display_options($img,$defaults,$designs);
1263: }
1264: }
1265: $datatable .= '</td>';
1.6 raeburn 1266: if ($designs->{$img} ne '') {
1267: $imgfile = $designs->{$img};
1.18 albertel 1268: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1269: } else {
1270: $imgfile = $defaults->{$img};
1271: }
1272: if ($imgfile) {
1.9 raeburn 1273: my ($showfile,$fullsize);
1274: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1275: my $urldir = $1;
1276: my $filename = $2;
1277: my @info = &Apache::lonnet::stat_file($designs->{$img});
1278: if (@info) {
1279: my $thumbfile = 'tn-'.$filename;
1280: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1281: if (@thumb) {
1282: $showfile = $urldir.'/'.$thumbfile;
1283: } else {
1284: $showfile = $imgfile;
1285: }
1286: } else {
1287: $showfile = '';
1288: }
1289: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1290: $showfile = $imgfile;
1.6 raeburn 1291: my $imgdir = $1;
1292: my $filename = $2;
1.159 raeburn 1293: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1294: $showfile = "/$imgdir/tn-".$filename;
1295: } else {
1.159 raeburn 1296: my $input = $londocroot.$imgfile;
1297: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1298: if (!-e $output) {
1.9 raeburn 1299: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1300: my ($fullwidth,$fullheight) = &check_dimensions($input);
1301: if ($fullwidth ne '' && $fullheight ne '') {
1302: if ($fullwidth > $width && $fullheight > $height) {
1303: my $size = $width.'x'.$height;
1304: system("convert -sample $size $input $output");
1.159 raeburn 1305: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1306: }
1307: }
1.6 raeburn 1308: }
1309: }
1.16 raeburn 1310: }
1.6 raeburn 1311: if ($showfile) {
1.40 raeburn 1312: if ($showfile =~ m{^/(adm|res)/}) {
1313: if ($showfile =~ m{^/res/}) {
1314: my $local_showfile =
1315: &Apache::lonnet::filelocation('',$showfile);
1316: &Apache::lonnet::repcopy($local_showfile);
1317: }
1318: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1319: }
1320: if ($imgfile) {
1321: if ($imgfile =~ m{^/(adm|res)/}) {
1322: if ($imgfile =~ m{^/res/}) {
1323: my $local_imgfile =
1324: &Apache::lonnet::filelocation('',$imgfile);
1325: &Apache::lonnet::repcopy($local_imgfile);
1326: }
1327: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1328: } else {
1329: $fullsize = $imgfile;
1330: }
1331: }
1.41 raeburn 1332: $datatable .= '<td>';
1333: if ($img eq 'login') {
1.135 bisitz 1334: $datatable .= $login_hdr_pick;
1335: }
1.41 raeburn 1336: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1337: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1338: } else {
1339: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1340: &mt('Upload:');
1341: }
1342: } else {
1343: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1344: &mt('Upload:');
1345: }
1.9 raeburn 1346: if ($switchserver) {
1347: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1348: } else {
1.135 bisitz 1349: if ($img ne 'login') { # suppress file selection for Log-in header
1350: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1351: }
1.9 raeburn 1352: }
1353: $datatable .= '</td></tr>';
1.6 raeburn 1354: }
1355: $itemcount ++;
1356: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1357: $datatable .= '<tr'.$css_class.'>'.
1358: '<td>'.$choices->{'bgs'}.'</td>';
1359: my $bgs_def;
1360: foreach my $item (@{$bgs}) {
1361: if (!$is_custom->{$item}) {
1.70 raeburn 1362: $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 1363: }
1364: }
1365: if ($bgs_def) {
1.8 raeburn 1366: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1367: } else {
1368: $datatable .= '<td> </td>';
1369: }
1370: $datatable .= '<td class="LC_right_item">'.
1371: '<table border="0"><tr>';
1.174 foxr 1372:
1373:
1.6 raeburn 1374: foreach my $item (@{$bgs}) {
1.174 foxr 1375: # my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1376: $datatable .= '<td align="center">';
1377: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1378: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1379: $datatable .= ' ';
1.6 raeburn 1380: }
1.174 foxr 1381: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1382: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1383: }
1384: $datatable .= '</tr></table></td></tr>';
1385: $itemcount ++;
1386: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1387: $datatable .= '<tr'.$css_class.'>'.
1388: '<td>'.$choices->{'links'}.'</td>';
1389: my $links_def;
1390: foreach my $item (@{$links}) {
1391: if (!$is_custom->{$item}) {
1.30 raeburn 1392: $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 1393: }
1394: }
1395: if ($links_def) {
1.8 raeburn 1396: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1397: } else {
1398: $datatable .= '<td> </td>';
1399: }
1400: $datatable .= '<td class="LC_right_item">'.
1401: '<table border="0"><tr>';
1402: foreach my $item (@{$links}) {
1.174 foxr 1403: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1404: $datatable .= '<td align="center">'."\n";
1405:
1.6 raeburn 1406: if ($designs->{'links'}{$item}) {
1.174 foxr 1407: $datatable.=' ';
1.6 raeburn 1408: }
1.174 foxr 1409: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1410: '" /></td>';
1411: }
1.30 raeburn 1412: $$rowtotal += $itemcount;
1.3 raeburn 1413: return $datatable;
1414: }
1415:
1.70 raeburn 1416: sub logo_display_options {
1417: my ($img,$defaults,$designs) = @_;
1418: my $checkedon;
1419: if (ref($defaults) eq 'HASH') {
1420: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1421: if ($defaults->{'showlogo'}{$img}) {
1422: $checkedon = 'checked="checked" ';
1423: }
1424: }
1425: }
1426: if (ref($designs) eq 'HASH') {
1427: if (ref($designs->{'showlogo'}) eq 'HASH') {
1428: if (defined($designs->{'showlogo'}{$img})) {
1429: if ($designs->{'showlogo'}{$img} == 0) {
1430: $checkedon = '';
1431: } elsif ($designs->{'showlogo'}{$img} == 1) {
1432: $checkedon = 'checked="checked" ';
1433: }
1434: }
1435: }
1436: }
1437: return '<br /><label> <input type="checkbox" name="'.
1438: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1439: &mt('show').'</label>'."\n";
1440: }
1441:
1.41 raeburn 1442: sub login_header_options {
1.135 bisitz 1443: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1444: my $output = '';
1.41 raeburn 1445: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1446: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1447: if (!$is_custom->{'textcol'}) {
1448: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1449: ' ';
1450: }
1451: if (!$is_custom->{'bgcol'}) {
1452: $output .= $choices->{'bgcol'}.': '.
1453: '<span id="css_'.$role.'_font" style="background-color: '.
1454: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1455: }
1456: $output .= '<br />';
1457: }
1458: $output .='<br />';
1459: return $output;
1460: }
1461:
1462: sub login_text_colors {
1463: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1464: my $color_menu = '<table border="0"><tr>';
1465: foreach my $item (@{$logintext}) {
1466: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1467: $color_menu .= '<td align="center">'.$link;
1468: if ($designs->{'logintext'}{$item}) {
1469: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1470: }
1471: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1472: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1473: '<td> </td>';
1474: }
1475: $color_menu .= '</tr></table><br />';
1476: return $color_menu;
1477: }
1478:
1479: sub image_changes {
1480: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1481: my $output;
1.135 bisitz 1482: if ($img eq 'login') {
1483: # suppress image for Log-in header
1484: } elsif (!$is_custom) {
1.70 raeburn 1485: if ($img ne 'domlogo') {
1.41 raeburn 1486: $output .= &mt('Default image:').'<br />';
1487: } else {
1488: $output .= &mt('Default in use:').'<br />';
1489: }
1490: }
1.135 bisitz 1491: if ($img eq 'login') { # suppress image for Log-in header
1492: $output .= '<td>'.$logincolors;
1.41 raeburn 1493: } else {
1.135 bisitz 1494: if ($img_import) {
1495: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1496: }
1497: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1498: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1499: if ($is_custom) {
1500: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1501: '<input type="checkbox" name="'.
1502: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1503: '</label> '.&mt('Replace:').'</span><br />';
1504: } else {
1505: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1506: }
1.41 raeburn 1507: }
1508: return $output;
1509: }
1510:
1.6 raeburn 1511: sub color_pick {
1512: my ($phase,$role,$item,$desc,$curcol) = @_;
1513: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1514: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1515: ');">'.$desc.'</a>';
1516: return $link;
1517: }
1518:
1.3 raeburn 1519: sub print_quotas {
1.86 raeburn 1520: my ($dom,$settings,$rowtotal,$action) = @_;
1521: my $context;
1522: if ($action eq 'quotas') {
1523: $context = 'tools';
1524: } else {
1525: $context = $action;
1526: }
1.101 raeburn 1527: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1528: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1529: my $typecount = 0;
1.101 raeburn 1530: my ($css_class,%titles);
1.86 raeburn 1531: if ($context eq 'requestcourses') {
1.98 raeburn 1532: @usertools = ('official','unofficial','community');
1.106 raeburn 1533: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1534: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1535: %titles = &courserequest_titles();
1.163 raeburn 1536: } elsif ($context eq 'requestauthor') {
1537: @usertools = ('author');
1538: @options = ('norequest','approval','automatic');
1539: %titles = &authorrequest_titles();
1.86 raeburn 1540: } else {
1.162 raeburn 1541: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1542: %titles = &tool_titles();
1.86 raeburn 1543: }
1.26 raeburn 1544: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1545: foreach my $type (@{$types}) {
1.72 raeburn 1546: my $currdefquota;
1.163 raeburn 1547: unless (($context eq 'requestcourses') ||
1548: ($context eq 'requestauthor')) {
1.86 raeburn 1549: if (ref($settings) eq 'HASH') {
1550: if (ref($settings->{defaultquota}) eq 'HASH') {
1551: $currdefquota = $settings->{defaultquota}->{$type};
1552: } else {
1553: $currdefquota = $settings->{$type};
1554: }
1.78 raeburn 1555: }
1.72 raeburn 1556: }
1.3 raeburn 1557: if (defined($usertypes->{$type})) {
1558: $typecount ++;
1559: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1560: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1561: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1562: '<td class="LC_left_item">';
1.101 raeburn 1563: if ($context eq 'requestcourses') {
1564: $datatable .= '<table><tr>';
1565: }
1566: my %cell;
1.72 raeburn 1567: foreach my $item (@usertools) {
1.101 raeburn 1568: if ($context eq 'requestcourses') {
1569: my ($curroption,$currlimit);
1570: if (ref($settings) eq 'HASH') {
1571: if (ref($settings->{$item}) eq 'HASH') {
1572: $curroption = $settings->{$item}->{$type};
1573: if ($curroption =~ /^autolimit=(\d*)$/) {
1574: $currlimit = $1;
1575: }
1576: }
1577: }
1578: if (!$curroption) {
1579: $curroption = 'norequest';
1580: }
1581: $datatable .= '<th>'.$titles{$item}.'</th>';
1582: foreach my $option (@options) {
1583: my $val = $option;
1584: if ($option eq 'norequest') {
1585: $val = 0;
1586: }
1587: if ($option eq 'validate') {
1588: my $canvalidate = 0;
1589: if (ref($validations{$item}) eq 'HASH') {
1590: if ($validations{$item}{$type}) {
1591: $canvalidate = 1;
1592: }
1593: }
1594: next if (!$canvalidate);
1595: }
1596: my $checked = '';
1597: if ($option eq $curroption) {
1598: $checked = ' checked="checked"';
1599: } elsif ($option eq 'autolimit') {
1600: if ($curroption =~ /^autolimit/) {
1601: $checked = ' checked="checked"';
1602: }
1603: }
1604: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1605: '<input type="radio" name="crsreq_'.$item.
1606: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1607: $titles{$option}.'</label>';
1.101 raeburn 1608: if ($option eq 'autolimit') {
1.127 raeburn 1609: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1610: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1611: 'value="'.$currlimit.'" />';
1.101 raeburn 1612: }
1.127 raeburn 1613: $cell{$item} .= '</span> ';
1.103 raeburn 1614: if ($option eq 'autolimit') {
1.127 raeburn 1615: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1616: }
1.101 raeburn 1617: }
1.163 raeburn 1618: } elsif ($context eq 'requestauthor') {
1619: my $curroption;
1620: if (ref($settings) eq 'HASH') {
1621: $curroption = $settings->{$type};
1622: }
1623: if (!$curroption) {
1624: $curroption = 'norequest';
1625: }
1626: foreach my $option (@options) {
1627: my $val = $option;
1628: if ($option eq 'norequest') {
1629: $val = 0;
1630: }
1631: my $checked = '';
1632: if ($option eq $curroption) {
1633: $checked = ' checked="checked"';
1634: }
1635: $datatable .= '<span class="LC_nobreak"><label>'.
1636: '<input type="radio" name="authorreq_'.$type.
1637: '" value="'.$val.'"'.$checked.' />'.
1638: $titles{$option}.'</label></span> ';
1639: }
1.101 raeburn 1640: } else {
1641: my $checked = 'checked="checked" ';
1642: if (ref($settings) eq 'HASH') {
1643: if (ref($settings->{$item}) eq 'HASH') {
1644: if ($settings->{$item}->{$type} == 0) {
1645: $checked = '';
1646: } elsif ($settings->{$item}->{$type} == 1) {
1647: $checked = 'checked="checked" ';
1648: }
1.78 raeburn 1649: }
1.72 raeburn 1650: }
1.101 raeburn 1651: $datatable .= '<span class="LC_nobreak"><label>'.
1652: '<input type="checkbox" name="'.$context.'_'.$item.
1653: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1654: '</label></span> ';
1.72 raeburn 1655: }
1.101 raeburn 1656: }
1657: if ($context eq 'requestcourses') {
1658: $datatable .= '</tr><tr>';
1659: foreach my $item (@usertools) {
1.106 raeburn 1660: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1661: }
1662: $datatable .= '</tr></table>';
1.72 raeburn 1663: }
1.86 raeburn 1664: $datatable .= '</td>';
1.163 raeburn 1665: unless (($context eq 'requestcourses') ||
1666: ($context eq 'requestauthor')) {
1.86 raeburn 1667: $datatable .=
1668: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1669: '<input type="text" name="quota_'.$type.
1.72 raeburn 1670: '" value="'.$currdefquota.
1.86 raeburn 1671: '" size="5" /> Mb</span></td>';
1672: }
1673: $datatable .= '</tr>';
1.3 raeburn 1674: }
1675: }
1676: }
1.163 raeburn 1677: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1678: $defaultquota = '20';
1679: if (ref($settings) eq 'HASH') {
1680: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1681: $defaultquota = $settings->{'defaultquota'}->{'default'};
1682: } elsif (defined($settings->{'default'})) {
1683: $defaultquota = $settings->{'default'};
1684: }
1.3 raeburn 1685: }
1686: }
1687: $typecount ++;
1688: $css_class = $typecount%2?' class="LC_odd_row"':'';
1689: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1690: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1691: '<td class="LC_left_item">';
1.101 raeburn 1692: if ($context eq 'requestcourses') {
1693: $datatable .= '<table><tr>';
1694: }
1695: my %defcell;
1.72 raeburn 1696: foreach my $item (@usertools) {
1.101 raeburn 1697: if ($context eq 'requestcourses') {
1698: my ($curroption,$currlimit);
1699: if (ref($settings) eq 'HASH') {
1700: if (ref($settings->{$item}) eq 'HASH') {
1701: $curroption = $settings->{$item}->{'default'};
1702: if ($curroption =~ /^autolimit=(\d*)$/) {
1703: $currlimit = $1;
1704: }
1705: }
1706: }
1707: if (!$curroption) {
1708: $curroption = 'norequest';
1709: }
1710: $datatable .= '<th>'.$titles{$item}.'</th>';
1711: foreach my $option (@options) {
1712: my $val = $option;
1713: if ($option eq 'norequest') {
1714: $val = 0;
1715: }
1716: if ($option eq 'validate') {
1717: my $canvalidate = 0;
1718: if (ref($validations{$item}) eq 'HASH') {
1719: if ($validations{$item}{'default'}) {
1720: $canvalidate = 1;
1721: }
1722: }
1723: next if (!$canvalidate);
1724: }
1725: my $checked = '';
1726: if ($option eq $curroption) {
1727: $checked = ' checked="checked"';
1728: } elsif ($option eq 'autolimit') {
1729: if ($curroption =~ /^autolimit/) {
1730: $checked = ' checked="checked"';
1731: }
1732: }
1733: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1734: '<input type="radio" name="crsreq_'.$item.
1735: '_default" value="'.$val.'"'.$checked.' />'.
1736: $titles{$option}.'</label>';
1737: if ($option eq 'autolimit') {
1.127 raeburn 1738: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1739: $item.'_limit_default" size="1" '.
1740: 'value="'.$currlimit.'" />';
1741: }
1.127 raeburn 1742: $defcell{$item} .= '</span> ';
1.104 raeburn 1743: if ($option eq 'autolimit') {
1.127 raeburn 1744: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1745: }
1.101 raeburn 1746: }
1.163 raeburn 1747: } elsif ($context eq 'requestauthor') {
1748: my $curroption;
1749: if (ref($settings) eq 'HASH') {
1.172 raeburn 1750: $curroption = $settings->{'default'};
1.163 raeburn 1751: }
1752: if (!$curroption) {
1753: $curroption = 'norequest';
1754: }
1755: foreach my $option (@options) {
1756: my $val = $option;
1757: if ($option eq 'norequest') {
1758: $val = 0;
1759: }
1760: my $checked = '';
1761: if ($option eq $curroption) {
1762: $checked = ' checked="checked"';
1763: }
1764: $datatable .= '<span class="LC_nobreak"><label>'.
1765: '<input type="radio" name="authorreq_default"'.
1766: ' value="'.$val.'"'.$checked.' />'.
1767: $titles{$option}.'</label></span> ';
1768: }
1.101 raeburn 1769: } else {
1770: my $checked = 'checked="checked" ';
1771: if (ref($settings) eq 'HASH') {
1772: if (ref($settings->{$item}) eq 'HASH') {
1773: if ($settings->{$item}->{'default'} == 0) {
1774: $checked = '';
1775: } elsif ($settings->{$item}->{'default'} == 1) {
1776: $checked = 'checked="checked" ';
1777: }
1.78 raeburn 1778: }
1.72 raeburn 1779: }
1.101 raeburn 1780: $datatable .= '<span class="LC_nobreak"><label>'.
1781: '<input type="checkbox" name="'.$context.'_'.$item.
1782: '" value="default" '.$checked.'/>'.$titles{$item}.
1783: '</label></span> ';
1784: }
1785: }
1786: if ($context eq 'requestcourses') {
1787: $datatable .= '</tr><tr>';
1788: foreach my $item (@usertools) {
1.106 raeburn 1789: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1790: }
1.101 raeburn 1791: $datatable .= '</tr></table>';
1.72 raeburn 1792: }
1.86 raeburn 1793: $datatable .= '</td>';
1.163 raeburn 1794: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1795: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1796: '<input type="text" name="defaultquota" value="'.
1797: $defaultquota.'" size="5" /> Mb</span></td>';
1798: }
1799: $datatable .= '</tr>';
1.72 raeburn 1800: $typecount ++;
1801: $css_class = $typecount%2?' class="LC_odd_row"':'';
1802: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1803: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1804: if ($context eq 'requestcourses') {
1.109 raeburn 1805: $datatable .= &mt('(overrides affiliation, if set)').
1806: '</td>'.
1807: '<td class="LC_left_item">'.
1808: '<table><tr>';
1.101 raeburn 1809: } else {
1.109 raeburn 1810: $datatable .= &mt('(overrides affiliation, if checked)').
1811: '</td>'.
1812: '<td class="LC_left_item" colspan="2">'.
1813: '<br />';
1.101 raeburn 1814: }
1815: my %advcell;
1.72 raeburn 1816: foreach my $item (@usertools) {
1.101 raeburn 1817: if ($context eq 'requestcourses') {
1818: my ($curroption,$currlimit);
1819: if (ref($settings) eq 'HASH') {
1820: if (ref($settings->{$item}) eq 'HASH') {
1821: $curroption = $settings->{$item}->{'_LC_adv'};
1822: if ($curroption =~ /^autolimit=(\d*)$/) {
1823: $currlimit = $1;
1824: }
1825: }
1826: }
1827: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1828: my $checked = '';
1829: if ($curroption eq '') {
1830: $checked = ' checked="checked"';
1831: }
1832: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1833: '<input type="radio" name="crsreq_'.$item.
1834: '__LC_adv" value=""'.$checked.' />'.
1835: &mt('No override set').'</label></span> ';
1.101 raeburn 1836: foreach my $option (@options) {
1837: my $val = $option;
1838: if ($option eq 'norequest') {
1839: $val = 0;
1840: }
1841: if ($option eq 'validate') {
1842: my $canvalidate = 0;
1843: if (ref($validations{$item}) eq 'HASH') {
1844: if ($validations{$item}{'_LC_adv'}) {
1845: $canvalidate = 1;
1846: }
1847: }
1848: next if (!$canvalidate);
1849: }
1850: my $checked = '';
1.104 raeburn 1851: if ($val eq $curroption) {
1.101 raeburn 1852: $checked = ' checked="checked"';
1853: } elsif ($option eq 'autolimit') {
1854: if ($curroption =~ /^autolimit/) {
1855: $checked = ' checked="checked"';
1856: }
1857: }
1858: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1859: '<input type="radio" name="crsreq_'.$item.
1860: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1861: $titles{$option}.'</label>';
1862: if ($option eq 'autolimit') {
1.127 raeburn 1863: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1864: $item.'_limit__LC_adv" size="1" '.
1865: 'value="'.$currlimit.'" />';
1866: }
1.127 raeburn 1867: $advcell{$item} .= '</span> ';
1.104 raeburn 1868: if ($option eq 'autolimit') {
1.127 raeburn 1869: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1870: }
1.101 raeburn 1871: }
1.163 raeburn 1872: } elsif ($context eq 'requestauthor') {
1873: my $curroption;
1874: if (ref($settings) eq 'HASH') {
1875: $curroption = $settings->{'_LC_adv'};
1876: }
1877: my $checked = '';
1878: if ($curroption eq '') {
1879: $checked = ' checked="checked"';
1880: }
1881: $datatable .= '<span class="LC_nobreak"><label>'.
1882: '<input type="radio" name="authorreq__LC_adv"'.
1883: ' value=""'.$checked.' />'.
1884: &mt('No override set').'</label></span> ';
1885: foreach my $option (@options) {
1886: my $val = $option;
1887: if ($option eq 'norequest') {
1888: $val = 0;
1889: }
1890: my $checked = '';
1891: if ($val eq $curroption) {
1892: $checked = ' checked="checked"';
1893: }
1894: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1895: '<input type="radio" name="authorreq__LC_adv"'.
1896: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1897: $titles{$option}.'</label></span> ';
1898: }
1.101 raeburn 1899: } else {
1900: my $checked = 'checked="checked" ';
1901: if (ref($settings) eq 'HASH') {
1902: if (ref($settings->{$item}) eq 'HASH') {
1903: if ($settings->{$item}->{'_LC_adv'} == 0) {
1904: $checked = '';
1905: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1906: $checked = 'checked="checked" ';
1907: }
1.79 raeburn 1908: }
1.72 raeburn 1909: }
1.101 raeburn 1910: $datatable .= '<span class="LC_nobreak"><label>'.
1911: '<input type="checkbox" name="'.$context.'_'.$item.
1912: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1913: '</label></span> ';
1914: }
1915: }
1916: if ($context eq 'requestcourses') {
1917: $datatable .= '</tr><tr>';
1918: foreach my $item (@usertools) {
1.106 raeburn 1919: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1920: }
1.101 raeburn 1921: $datatable .= '</tr></table>';
1.72 raeburn 1922: }
1.98 raeburn 1923: $datatable .= '</td></tr>';
1.30 raeburn 1924: $$rowtotal += $typecount;
1.3 raeburn 1925: return $datatable;
1926: }
1927:
1.163 raeburn 1928: sub print_requestmail {
1929: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1930: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1931: $now = time;
1932: $rows = 0;
1933: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1934: foreach my $server (keys(%dompersonnel)) {
1935: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1936: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1937: if (!grep(/^$uname:$udom$/,@domcoord)) {
1938: push(@domcoord,$uname.':'.$udom);
1939: }
1940: }
1941: }
1942: if (ref($settings) eq 'HASH') {
1943: if (ref($settings->{'notify'}) eq 'HASH') {
1944: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1945: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1946: }
1947: }
1948: }
1.104 raeburn 1949: if (@currapproval) {
1950: foreach my $dc (@currapproval) {
1.102 raeburn 1951: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1952: push(@domcoord,$dc);
1953: }
1954: }
1955: }
1956: @domcoord = sort(@domcoord);
1957: my $numinrow = 4;
1958: my $numdc = @domcoord;
1959: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1960: my $text;
1961: if ($action eq 'requestcourses') {
1962: $text = &mt('Receive notification of course requests requiring approval');
1963: } else {
1964: $text = &mt('Receive notification of authoring space requests requiring approval')
1965: }
1966: $datatable = '<tr '.$css_class.'>'.
1967: ' <td>'.$text.'</td>'.
1.102 raeburn 1968: ' <td class="LC_left_item">';
1969: if (@domcoord > 0) {
1970: $datatable .= '<table>';
1971: for (my $i=0; $i<$numdc; $i++) {
1972: my $rem = $i%($numinrow);
1973: if ($rem == 0) {
1974: if ($i > 0) {
1975: $datatable .= '</tr>';
1976: }
1977: $datatable .= '<tr>';
1978: $rows ++;
1979: }
1980: my $check = ' ';
1.104 raeburn 1981: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1982: $check = ' checked="checked" ';
1983: }
1984: my ($uname,$udom) = split(':',$domcoord[$i]);
1985: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1986: if ($i == $numdc-1) {
1987: my $colsleft = $numinrow-$rem;
1988: if ($colsleft > 1) {
1989: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1990: } else {
1991: $datatable .= '<td class="LC_left_item">';
1992: }
1993: } else {
1994: $datatable .= '<td class="LC_left_item">';
1995: }
1996: $datatable .= '<span class="LC_nobreak"><label>'.
1997: '<input type="checkbox" name="reqapprovalnotify" '.
1998: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175 bisitz 1999: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 2000: }
2001: $datatable .= '</tr></table>';
2002: } else {
2003: $datatable .= &mt('There are no active Domain Coordinators');
2004: $rows ++;
2005: }
2006: $datatable .='</td></tr>';
2007: $$rowtotal += $rows;
2008: return $datatable;
2009: }
2010:
1.3 raeburn 2011: sub print_autoenroll {
1.30 raeburn 2012: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2013: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2014: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2015: if (ref($settings) eq 'HASH') {
2016: if (exists($settings->{'run'})) {
2017: if ($settings->{'run'} eq '0') {
2018: $runoff = ' checked="checked" ';
2019: $runon = ' ';
2020: } else {
2021: $runon = ' checked="checked" ';
2022: $runoff = ' ';
2023: }
2024: } else {
2025: if ($autorun) {
2026: $runon = ' checked="checked" ';
2027: $runoff = ' ';
2028: } else {
2029: $runoff = ' checked="checked" ';
2030: $runon = ' ';
2031: }
2032: }
1.129 raeburn 2033: if (exists($settings->{'co-owners'})) {
2034: if ($settings->{'co-owners'} eq '0') {
2035: $coownersoff = ' checked="checked" ';
2036: $coownerson = ' ';
2037: } else {
2038: $coownerson = ' checked="checked" ';
2039: $coownersoff = ' ';
2040: }
2041: } else {
2042: $coownersoff = ' checked="checked" ';
2043: $coownerson = ' ';
2044: }
1.3 raeburn 2045: if (exists($settings->{'sender_domain'})) {
2046: $defdom = $settings->{'sender_domain'};
2047: }
1.14 raeburn 2048: } else {
2049: if ($autorun) {
2050: $runon = ' checked="checked" ';
2051: $runoff = ' ';
2052: } else {
2053: $runoff = ' checked="checked" ';
2054: $runon = ' ';
2055: }
1.3 raeburn 2056: }
2057: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2058: my $notif_sender;
2059: if (ref($settings) eq 'HASH') {
2060: $notif_sender = $settings->{'sender_uname'};
2061: }
1.3 raeburn 2062: my $datatable='<tr class="LC_odd_row">'.
2063: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2064: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2065: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2066: $runon.' value="1" />'.&mt('Yes').'</label> '.
2067: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2068: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2069: '</tr><tr>'.
2070: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2071: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2072: &mt('username').': '.
2073: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2074: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2075: ': '.$domform.'</span></td></tr>'.
2076: '<tr class="LC_odd_row">'.
2077: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2078: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2079: '<input type="radio" name="autoassign_coowners"'.
2080: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2081: '<label><input type="radio" name="autoassign_coowners"'.
2082: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2083: '</tr>';
2084: $$rowtotal += 3;
1.3 raeburn 2085: return $datatable;
2086: }
2087:
2088: sub print_autoupdate {
1.30 raeburn 2089: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2090: my $datatable;
2091: if ($position eq 'top') {
2092: my $updateon = ' ';
2093: my $updateoff = ' checked="checked" ';
2094: my $classlistson = ' ';
2095: my $classlistsoff = ' checked="checked" ';
2096: if (ref($settings) eq 'HASH') {
2097: if ($settings->{'run'} eq '1') {
2098: $updateon = $updateoff;
2099: $updateoff = ' ';
2100: }
2101: if ($settings->{'classlists'} eq '1') {
2102: $classlistson = $classlistsoff;
2103: $classlistsoff = ' ';
2104: }
2105: }
2106: my %title = (
2107: run => 'Auto-update active?',
2108: classlists => 'Update information in classlists?',
2109: );
2110: $datatable = '<tr class="LC_odd_row">'.
2111: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2112: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2113: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2114: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2115: '<label><input type="radio" name="autoupdate_run"'.
2116: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2117: '</tr><tr>'.
2118: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2119: '<td class="LC_right_item"><span class="LC_nobreak">'.
2120: '<label><input type="radio" name="classlists"'.
2121: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2122: '<label><input type="radio" name="classlists"'.
2123: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2124: '</tr>';
1.30 raeburn 2125: $$rowtotal += 2;
1.131 raeburn 2126: } elsif ($position eq 'middle') {
2127: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2128: my $numinrow = 3;
2129: my $locknamesettings;
2130: $datatable .= &insttypes_row($settings,$types,$usertypes,
2131: $dom,$numinrow,$othertitle,
2132: 'lockablenames');
2133: $$rowtotal ++;
1.3 raeburn 2134: } else {
1.44 raeburn 2135: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2136: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2137: 'permanentemail','id');
1.33 raeburn 2138: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2139: my $numrows = 0;
1.26 raeburn 2140: if (ref($types) eq 'ARRAY') {
2141: if (@{$types} > 0) {
2142: $datatable =
2143: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2144: \@fields,$types,\$numrows);
1.30 raeburn 2145: $$rowtotal += @{$types};
1.26 raeburn 2146: }
1.3 raeburn 2147: }
2148: $datatable .=
2149: &usertype_update_row($settings,{'default' => $othertitle},
2150: \%fieldtitles,\@fields,['default'],
2151: \$numrows);
1.30 raeburn 2152: $$rowtotal ++;
1.3 raeburn 2153: }
2154: return $datatable;
2155: }
2156:
1.125 raeburn 2157: sub print_autocreate {
2158: my ($dom,$settings,$rowtotal) = @_;
2159: my (%createon,%createoff);
2160: my $curr_dc;
2161: my @types = ('xml','req');
2162: if (ref($settings) eq 'HASH') {
2163: foreach my $item (@types) {
2164: $createoff{$item} = ' checked="checked" ';
2165: $createon{$item} = ' ';
2166: if (exists($settings->{$item})) {
2167: if ($settings->{$item}) {
2168: $createon{$item} = ' checked="checked" ';
2169: $createoff{$item} = ' ';
2170: }
2171: }
2172: }
2173: $curr_dc = $settings->{'xmldc'};
2174: } else {
2175: foreach my $item (@types) {
2176: $createoff{$item} = ' checked="checked" ';
2177: $createon{$item} = ' ';
2178: }
2179: }
2180: $$rowtotal += 2;
2181: my $datatable='<tr class="LC_odd_row">'.
2182: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2183: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2184: '<input type="radio" name="autocreate_xml"'.
2185: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2186: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2187: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2188: '</td></tr><tr>'.
2189: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2190: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2191: '<input type="radio" name="autocreate_req"'.
2192: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2193: '<label><input type="radio" name="autocreate_req"'.
2194: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2195: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2196: if ($numdc > 1) {
1.143 raeburn 2197: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2198: &mt('Course creation processed as: (choose Dom. Coord.)').
2199: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2200: $$rowtotal ++ ;
2201: } else {
1.143 raeburn 2202: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2203: }
2204: return $datatable;
2205: }
2206:
1.23 raeburn 2207: sub print_directorysrch {
1.30 raeburn 2208: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2209: my $srchon = ' ';
2210: my $srchoff = ' checked="checked" ';
1.25 raeburn 2211: my ($exacton,$containson,$beginson);
1.24 raeburn 2212: my $localon = ' ';
2213: my $localoff = ' checked="checked" ';
1.23 raeburn 2214: if (ref($settings) eq 'HASH') {
2215: if ($settings->{'available'} eq '1') {
2216: $srchon = $srchoff;
2217: $srchoff = ' ';
2218: }
1.24 raeburn 2219: if ($settings->{'localonly'} eq '1') {
2220: $localon = $localoff;
2221: $localoff = ' ';
2222: }
1.25 raeburn 2223: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2224: foreach my $type (@{$settings->{'searchtypes'}}) {
2225: if ($type eq 'exact') {
2226: $exacton = ' checked="checked" ';
2227: } elsif ($type eq 'contains') {
2228: $containson = ' checked="checked" ';
2229: } elsif ($type eq 'begins') {
2230: $beginson = ' checked="checked" ';
2231: }
2232: }
2233: } else {
2234: if ($settings->{'searchtypes'} eq 'exact') {
2235: $exacton = ' checked="checked" ';
2236: } elsif ($settings->{'searchtypes'} eq 'contains') {
2237: $containson = ' checked="checked" ';
2238: } elsif ($settings->{'searchtypes'} eq 'specify') {
2239: $exacton = ' checked="checked" ';
2240: $containson = ' checked="checked" ';
2241: }
1.23 raeburn 2242: }
2243: }
2244: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2245: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2246:
2247: my $numinrow = 4;
1.26 raeburn 2248: my $cansrchrow = 0;
1.23 raeburn 2249: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2250: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2251: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2252: '<input type="radio" name="dirsrch_available"'.
2253: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2254: '<label><input type="radio" name="dirsrch_available"'.
2255: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2256: '</tr><tr>'.
1.30 raeburn 2257: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2258: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2259: '<input type="radio" name="dirsrch_localonly"'.
2260: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2261: '<label><input type="radio" name="dirsrch_localonly"'.
2262: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2263: '</tr>';
1.30 raeburn 2264: $$rowtotal += 2;
1.26 raeburn 2265: if (ref($usertypes) eq 'HASH') {
2266: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2267: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2268: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2269: $cansrchrow = 1;
2270: }
2271: }
2272: if ($cansrchrow) {
1.30 raeburn 2273: $$rowtotal ++;
1.26 raeburn 2274: $datatable .= '<tr>';
2275: } else {
2276: $datatable .= '<tr class="LC_odd_row">';
2277: }
1.30 raeburn 2278: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2279: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2280: foreach my $title (@{$titleorder}) {
2281: if (defined($searchtitles->{$title})) {
2282: my $check = ' ';
1.93 raeburn 2283: if (ref($settings) eq 'HASH') {
1.39 raeburn 2284: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2285: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2286: $check = ' checked="checked" ';
2287: }
1.25 raeburn 2288: }
2289: }
2290: $datatable .= '<td class="LC_left_item">'.
2291: '<span class="LC_nobreak"><label>'.
2292: '<input type="checkbox" name="searchby" '.
2293: 'value="'.$title.'"'.$check.'/>'.
2294: $searchtitles->{$title}.'</label></span></td>';
2295: }
2296: }
1.26 raeburn 2297: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2298: $$rowtotal ++;
1.26 raeburn 2299: if ($cansrchrow) {
2300: $datatable .= '<tr class="LC_odd_row">';
2301: } else {
2302: $datatable .= '<tr>';
2303: }
1.30 raeburn 2304: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2305: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2306: '<span class="LC_nobreak"><label>'.
2307: '<input type="checkbox" name="searchtypes" '.
2308: $exacton.' value="exact" />'.&mt('Exact match').
2309: '</label> '.
2310: '<label><input type="checkbox" name="searchtypes" '.
2311: $beginson.' value="begins" />'.&mt('Begins with').
2312: '</label> '.
2313: '<label><input type="checkbox" name="searchtypes" '.
2314: $containson.' value="contains" />'.&mt('Contains').
2315: '</label></span></td></tr>';
1.30 raeburn 2316: $$rowtotal ++;
1.25 raeburn 2317: return $datatable;
2318: }
2319:
1.28 raeburn 2320: sub print_contacts {
1.30 raeburn 2321: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2322: my $datatable;
2323: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2324: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2325: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2326: 'requestsmail');
1.28 raeburn 2327: foreach my $type (@mailings) {
2328: $otheremails{$type} = '';
2329: }
1.134 raeburn 2330: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2331: if (ref($settings) eq 'HASH') {
2332: foreach my $item (@contacts) {
2333: if (exists($settings->{$item})) {
2334: $to{$item} = $settings->{$item};
2335: }
2336: }
2337: foreach my $type (@mailings) {
2338: if (exists($settings->{$type})) {
2339: if (ref($settings->{$type}) eq 'HASH') {
2340: foreach my $item (@contacts) {
2341: if ($settings->{$type}{$item}) {
2342: $checked{$type}{$item} = ' checked="checked" ';
2343: }
2344: }
2345: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2346: if ($type eq 'helpdeskmail') {
2347: $bccemails{$type} = $settings->{$type}{'bcc'};
2348: }
1.28 raeburn 2349: }
1.89 raeburn 2350: } elsif ($type eq 'lonstatusmail') {
2351: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2352: }
2353: }
2354: } else {
2355: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2356: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2357: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2358: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2359: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2360: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2361: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2362: }
2363: my ($titles,$short_titles) = &contact_titles();
2364: my $rownum = 0;
2365: my $css_class;
2366: foreach my $item (@contacts) {
1.69 raeburn 2367: $rownum ++;
2368: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2369: $datatable .= '<tr'.$css_class.'>'.
2370: '<td><span class="LC_nobreak">'.$titles->{$item}.
2371: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2372: '<input type="text" name="'.$item.'" value="'.
2373: $to{$item}.'" /></td></tr>';
2374: }
2375: foreach my $type (@mailings) {
1.69 raeburn 2376: $rownum ++;
2377: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2378: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2379: '<td><span class="LC_nobreak">'.
2380: $titles->{$type}.': </span></td>'.
1.28 raeburn 2381: '<td class="LC_left_item">'.
2382: '<span class="LC_nobreak">';
2383: foreach my $item (@contacts) {
2384: $datatable .= '<label>'.
2385: '<input type="checkbox" name="'.$type.'"'.
2386: $checked{$type}{$item}.
2387: ' value="'.$item.'" />'.$short_titles->{$item}.
2388: '</label> ';
2389: }
2390: $datatable .= '</span><br />'.&mt('Others').': '.
2391: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2392: 'value="'.$otheremails{$type}.'" />';
2393: if ($type eq 'helpdeskmail') {
1.136 raeburn 2394: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2395: '<input type="text" name="'.$type.'_bcc" '.
2396: 'value="'.$bccemails{$type}.'" />';
2397: }
2398: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2399: }
1.30 raeburn 2400: $$rowtotal += $rownum;
1.28 raeburn 2401: return $datatable;
2402: }
2403:
1.118 jms 2404: sub print_helpsettings {
1.168 raeburn 2405: my ($dom,$confname,$settings,$rowtotal) = @_;
2406: my ($datatable,$itemcount);
1.166 raeburn 2407: $itemcount = 1;
1.168 raeburn 2408: my (%choices,%defaultchecked,@toggles);
2409: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2410: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2411: &mt('LON-CAPA bug tracker'),600,500));
2412: %defaultchecked = ('submitbugs' => 'on');
2413: @toggles = ('submitbugs',);
1.166 raeburn 2414:
1.168 raeburn 2415: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2416: \%choices,$itemcount);
1.166 raeburn 2417: return $datatable;
1.121 raeburn 2418: }
2419:
2420: sub radiobutton_prefs {
2421: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2422: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2423: (ref($choices) eq 'HASH'));
2424:
1.170 raeburn 2425: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2426:
2427: foreach my $item (@{$toggles}) {
2428: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2429: $checkedon{$item} = ' checked="checked" ';
2430: $checkedoff{$item} = ' ';
1.121 raeburn 2431: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2432: $checkedoff{$item} = ' checked="checked" ';
2433: $checkedon{$item} = ' ';
2434: }
2435: }
2436: if (ref($settings) eq 'HASH') {
1.121 raeburn 2437: foreach my $item (@{$toggles}) {
1.118 jms 2438: if ($settings->{$item} eq '1') {
2439: $checkedon{$item} = ' checked="checked" ';
2440: $checkedoff{$item} = ' ';
2441: } elsif ($settings->{$item} eq '0') {
2442: $checkedoff{$item} = ' checked="checked" ';
2443: $checkedon{$item} = ' ';
2444: }
2445: }
1.121 raeburn 2446: }
2447: foreach my $item (@{$toggles}) {
1.118 jms 2448: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2449: $datatable .=
2450: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2451: '</span></td>'.
2452: '<td class="LC_right_item"><span class="LC_nobreak">'.
2453: '<label><input type="radio" name="'.
2454: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2455: '</label> <label><input type="radio" name="'.$item.'" '.
2456: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2457: '</span></td>'.
2458: '</tr>';
2459: $itemcount ++;
1.121 raeburn 2460: }
2461: return ($datatable,$itemcount);
2462: }
2463:
2464: sub print_coursedefaults {
1.139 raeburn 2465: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2466: my ($css_class,$datatable);
2467: my $itemcount = 1;
1.139 raeburn 2468: if ($position eq 'top') {
2469: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2470: %choices =
2471: &Apache::lonlocal::texthash (
2472: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2473: );
2474: %defaultchecked = ('canuse_pdfforms' => 'off');
2475: @toggles = ('canuse_pdfforms',);
2476: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2477: \%choices,$itemcount);
1.139 raeburn 2478: $$rowtotal += $itemcount;
2479: } else {
2480: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2481: my %choices =
2482: &Apache::lonlocal::texthash (
2483: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2484: );
2485: my $currdefresponder;
2486: if (ref($settings) eq 'HASH') {
2487: $currdefresponder = $settings->{'anonsurvey_threshold'};
2488: }
2489: if (!$currdefresponder) {
2490: $currdefresponder = 10;
2491: } elsif ($currdefresponder < 1) {
2492: $currdefresponder = 1;
2493: }
2494: $datatable .=
2495: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2496: '</span></td>'.
2497: '<td class="LC_right_item"><span class="LC_nobreak">'.
2498: '<input type="text" name="anonsurvey_threshold"'.
2499: ' value="'.$currdefresponder.'" size="5" /></span>'.
2500: '</td></tr>';
2501: }
1.121 raeburn 2502: return $datatable;
1.118 jms 2503: }
2504:
1.137 raeburn 2505: sub print_usersessions {
2506: my ($position,$dom,$settings,$rowtotal) = @_;
2507: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2508: my (%by_ip,%by_location,@intdoms);
2509: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2510:
2511: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2512: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2513: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2514: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2515: my $itemcount = 1;
2516: if ($position eq 'top') {
1.152 raeburn 2517: if (keys(%serverhomes) > 1) {
1.145 raeburn 2518: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2519: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2520: } else {
1.140 raeburn 2521: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2522: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2523: }
1.137 raeburn 2524: } else {
1.145 raeburn 2525: if (keys(%by_location) == 0) {
2526: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2527: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2528: } else {
2529: my %lt = &usersession_titles();
2530: my $numinrow = 5;
2531: my $prefix;
2532: my @types;
2533: if ($position eq 'bottom') {
2534: $prefix = 'remote';
2535: @types = ('version','excludedomain','includedomain');
2536: } else {
2537: $prefix = 'hosted';
2538: @types = ('excludedomain','includedomain');
2539: }
2540: my (%current,%checkedon,%checkedoff);
2541: my @lcversions = &Apache::lonnet::all_loncaparevs();
2542: my @locations = sort(keys(%by_location));
2543: foreach my $type (@types) {
2544: $checkedon{$type} = '';
2545: $checkedoff{$type} = ' checked="checked"';
2546: }
2547: if (ref($settings) eq 'HASH') {
2548: if (ref($settings->{$prefix}) eq 'HASH') {
2549: foreach my $key (keys(%{$settings->{$prefix}})) {
2550: $current{$key} = $settings->{$prefix}{$key};
2551: if ($key eq 'version') {
2552: if ($current{$key} ne '') {
2553: $checkedon{$key} = ' checked="checked"';
2554: $checkedoff{$key} = '';
2555: }
2556: } elsif (ref($current{$key}) eq 'ARRAY') {
2557: $checkedon{$key} = ' checked="checked"';
2558: $checkedoff{$key} = '';
2559: }
1.137 raeburn 2560: }
2561: }
2562: }
1.145 raeburn 2563: foreach my $type (@types) {
2564: next if ($type ne 'version' && !@locations);
2565: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2566: $datatable .= '<tr'.$css_class.'>
2567: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2568: <span class="LC_nobreak">
2569: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2570: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2571: if ($type eq 'version') {
2572: my $selector = '<select name="'.$prefix.'_version">';
2573: foreach my $version (@lcversions) {
2574: my $selected = '';
2575: if ($current{'version'} eq $version) {
2576: $selected = ' selected="selected"';
2577: }
2578: $selector .= ' <option value="'.$version.'"'.
2579: $selected.'>'.$version.'</option>';
2580: }
2581: $selector .= '</select> ';
2582: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2583: } else {
2584: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2585: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2586: ' />'.(' 'x2).
2587: '<input type="button" value="'.&mt('uncheck all').'" '.
2588: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2589: "\n".
2590: '</div><div><table>';
2591: my $rem;
2592: for (my $i=0; $i<@locations; $i++) {
2593: my ($showloc,$value,$checkedtype);
2594: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2595: my $ip = $by_location{$locations[$i]}->[0];
2596: if (ref($by_ip{$ip}) eq 'ARRAY') {
2597: $value = join(':',@{$by_ip{$ip}});
2598: $showloc = join(', ',@{$by_ip{$ip}});
2599: if (ref($current{$type}) eq 'ARRAY') {
2600: foreach my $loc (@{$by_ip{$ip}}) {
2601: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2602: $checkedtype = ' checked="checked"';
2603: last;
2604: }
2605: }
1.138 raeburn 2606: }
2607: }
2608: }
1.145 raeburn 2609: $rem = $i%($numinrow);
2610: if ($rem == 0) {
2611: if ($i > 0) {
2612: $datatable .= '</tr>';
2613: }
2614: $datatable .= '<tr>';
2615: }
2616: $datatable .= '<td class="LC_left_item">'.
2617: '<span class="LC_nobreak"><label>'.
2618: '<input type="checkbox" name="'.$prefix.'_'.$type.
2619: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2620: '</label></span></td>';
1.137 raeburn 2621: }
1.145 raeburn 2622: $rem = @locations%($numinrow);
2623: my $colsleft = $numinrow - $rem;
2624: if ($colsleft > 1 ) {
2625: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2626: ' </td>';
2627: } elsif ($colsleft == 1) {
2628: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2629: }
1.145 raeburn 2630: $datatable .= '</tr></table>';
1.137 raeburn 2631: }
1.145 raeburn 2632: $datatable .= '</td></tr>';
2633: $itemcount ++;
1.137 raeburn 2634: }
2635: }
2636: }
2637: $$rowtotal += $itemcount;
2638: return $datatable;
2639: }
2640:
1.138 raeburn 2641: sub build_location_hashes {
2642: my ($intdoms,$by_ip,$by_location) = @_;
2643: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2644: (ref($by_location) eq 'HASH'));
2645: my %iphost = &Apache::lonnet::get_iphost();
2646: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2647: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2648: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2649: foreach my $id (@{$iphost{$primary_ip}}) {
2650: my $intdom = &Apache::lonnet::internet_dom($id);
2651: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2652: push(@{$intdoms},$intdom);
2653: }
2654: }
2655: }
2656: foreach my $ip (keys(%iphost)) {
2657: if (ref($iphost{$ip}) eq 'ARRAY') {
2658: foreach my $id (@{$iphost{$ip}}) {
2659: my $location = &Apache::lonnet::internet_dom($id);
2660: if ($location) {
2661: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2662: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2663: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2664: push(@{$by_ip->{$ip}},$location);
2665: }
2666: } else {
2667: $by_ip->{$ip} = [$location];
2668: }
2669: }
2670: }
2671: }
2672: }
2673: foreach my $ip (sort(keys(%{$by_ip}))) {
2674: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2675: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2676: my $first = $by_ip->{$ip}->[0];
2677: if (ref($by_location->{$first}) eq 'ARRAY') {
2678: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2679: push(@{$by_location->{$first}},$ip);
2680: }
2681: } else {
2682: $by_location->{$first} = [$ip];
2683: }
2684: }
2685: }
2686: return;
2687: }
2688:
1.145 raeburn 2689: sub current_offloads_to {
2690: my ($dom,$settings,$servers) = @_;
2691: my (%spareid,%otherdomconfigs);
1.152 raeburn 2692: if (ref($servers) eq 'HASH') {
1.145 raeburn 2693: foreach my $lonhost (sort(keys(%{$servers}))) {
2694: my $gotspares;
1.152 raeburn 2695: if (ref($settings) eq 'HASH') {
2696: if (ref($settings->{'spares'}) eq 'HASH') {
2697: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2698: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2699: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2700: $gotspares = 1;
2701: }
1.145 raeburn 2702: }
2703: }
2704: unless ($gotspares) {
2705: my $gotspares;
2706: my $serverhomeID =
2707: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2708: my $serverhomedom =
2709: &Apache::lonnet::host_domain($serverhomeID);
2710: if ($serverhomedom ne $dom) {
2711: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2712: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2713: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2714: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2715: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2716: $gotspares = 1;
2717: }
2718: }
2719: } else {
2720: $otherdomconfigs{$serverhomedom} =
2721: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2722: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2723: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2724: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2725: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2726: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2727: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2728: $gotspares = 1;
2729: }
2730: }
2731: }
2732: }
2733: }
2734: }
2735: }
2736: unless ($gotspares) {
2737: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2738: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2739: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2740: } else {
2741: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2742: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2743: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2744: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2745: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2746: } else {
1.150 raeburn 2747: my %what = (
2748: spareid => 1,
2749: );
2750: my ($result,$returnhash) =
2751: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2752: if ($result eq 'ok') {
2753: if (ref($returnhash) eq 'HASH') {
2754: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2755: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2756: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2757: }
2758: }
1.145 raeburn 2759: }
2760: }
2761: }
2762: }
2763: }
2764: }
2765: return %spareid;
2766: }
2767:
2768: sub spares_row {
1.152 raeburn 2769: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2770: my $css_class;
2771: my $numinrow = 4;
2772: my $itemcount = 1;
2773: my $datatable;
1.152 raeburn 2774: my %typetitles = &sparestype_titles();
2775: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2776: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2777: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2778: my ($othercontrol,$serverdom);
2779: if ($serverhome ne $server) {
2780: $serverdom = &Apache::lonnet::host_domain($serverhome);
2781: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2782: } else {
2783: $serverdom = &Apache::lonnet::host_domain($server);
2784: if ($serverdom ne $dom) {
2785: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2786: }
2787: }
2788: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2789: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2790: $datatable .= '<tr'.$css_class.'>
2791: <td rowspan="2">
1.152 raeburn 2792: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2793: my (%current,%canselect);
1.152 raeburn 2794: my @choices =
2795: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2796: foreach my $type ('primary','default') {
2797: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2798: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2799: my @spares = @{$spareid->{$server}{$type}};
2800: if (@spares > 0) {
1.152 raeburn 2801: if ($othercontrol) {
2802: $current{$type} = join(', ',@spares);
2803: } else {
2804: $current{$type} .= '<table>';
2805: my $numspares = scalar(@spares);
2806: for (my $i=0; $i<@spares; $i++) {
2807: my $rem = $i%($numinrow);
2808: if ($rem == 0) {
2809: if ($i > 0) {
2810: $current{$type} .= '</tr>';
2811: }
2812: $current{$type} .= '<tr>';
1.145 raeburn 2813: }
1.152 raeburn 2814: $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'".');" /> '.
2815: $spareid->{$server}{$type}[$i].
2816: '</label></td>'."\n";
2817: }
2818: my $rem = @spares%($numinrow);
2819: my $colsleft = $numinrow - $rem;
2820: if ($colsleft > 1 ) {
2821: $current{$type} .= '<td colspan="'.$colsleft.
2822: '" class="LC_left_item">'.
2823: ' </td>';
2824: } elsif ($colsleft == 1) {
2825: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2826: }
1.152 raeburn 2827: $current{$type} .= '</tr></table>';
1.150 raeburn 2828: }
1.145 raeburn 2829: }
2830: }
2831: if ($current{$type} eq '') {
2832: $current{$type} = &mt('None specified');
2833: }
1.152 raeburn 2834: if ($othercontrol) {
2835: if ($type eq 'primary') {
2836: $canselect{$type} = $othercontrol;
2837: }
2838: } else {
2839: $canselect{$type} =
2840: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2841: '<select name="newspare_'.$type.'_'.$server.'" '.
2842: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2843: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2844: if (@choices > 0) {
2845: foreach my $lonhost (@choices) {
2846: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2847: }
2848: }
2849: $canselect{$type} .= '</select>'."\n";
2850: }
2851: } else {
2852: $current{$type} = &mt('Could not be determined');
2853: if ($type eq 'primary') {
2854: $canselect{$type} = $othercontrol;
2855: }
1.145 raeburn 2856: }
1.152 raeburn 2857: if ($type eq 'default') {
2858: $datatable .= '<tr'.$css_class.'>';
2859: }
2860: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2861: '<td>'.$current{$type}.'</td>'."\n".
2862: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2863: }
2864: $itemcount ++;
2865: }
2866: }
2867: $$rowtotal += $itemcount;
2868: return $datatable;
2869: }
2870:
1.152 raeburn 2871: sub possible_newspares {
2872: my ($server,$currspares,$serverhomes,$altids) = @_;
2873: my $serverhostname = &Apache::lonnet::hostname($server);
2874: my %excluded;
2875: if ($serverhostname ne '') {
2876: %excluded = (
2877: $serverhostname => 1,
2878: );
2879: }
2880: if (ref($currspares) eq 'HASH') {
2881: foreach my $type (keys(%{$currspares})) {
2882: if (ref($currspares->{$type}) eq 'ARRAY') {
2883: if (@{$currspares->{$type}} > 0) {
2884: foreach my $curr (@{$currspares->{$type}}) {
2885: my $hostname = &Apache::lonnet::hostname($curr);
2886: $excluded{$hostname} = 1;
2887: }
2888: }
2889: }
2890: }
2891: }
2892: my @choices;
2893: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2894: if (keys(%{$serverhomes}) > 1) {
2895: foreach my $name (sort(keys(%{$serverhomes}))) {
2896: unless ($excluded{$name}) {
2897: if (exists($altids->{$serverhomes->{$name}})) {
2898: push(@choices,$altids->{$serverhomes->{$name}});
2899: } else {
2900: push(@choices,$serverhomes->{$name});
1.145 raeburn 2901: }
2902: }
2903: }
2904: }
2905: }
1.152 raeburn 2906: return sort(@choices);
1.145 raeburn 2907: }
2908:
1.150 raeburn 2909: sub print_loadbalancing {
2910: my ($dom,$settings,$rowtotal) = @_;
2911: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2912: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2913: my $numinrow = 1;
2914: my $datatable;
2915: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2916: my (%currbalancer,%currtargets,%currrules,%existing);
2917: if (ref($settings) eq 'HASH') {
2918: %existing = %{$settings};
2919: }
2920: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2921: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2922: \%currtargets,\%currrules);
1.150 raeburn 2923: } else {
2924: return;
2925: }
2926: my ($othertitle,$usertypes,$types) =
2927: &Apache::loncommon::sorted_inst_types($dom);
2928: my $rownum = 6;
2929: if (ref($types) eq 'ARRAY') {
2930: $rownum += scalar(@{$types});
2931: }
1.171 raeburn 2932: my @css_class = ('LC_odd_row','LC_even_row');
2933: my $balnum = 0;
2934: my $islast;
2935: my (@toshow,$disabledtext);
2936: if (keys(%currbalancer) > 0) {
2937: @toshow = sort(keys(%currbalancer));
2938: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2939: push(@toshow,'');
2940: }
2941: } else {
2942: @toshow = ('');
2943: $disabledtext = &mt('No existing load balancer');
2944: }
2945: foreach my $lonhost (@toshow) {
2946: if ($balnum == scalar(@toshow)-1) {
2947: $islast = 1;
2948: } else {
2949: $islast = 0;
2950: }
2951: my $cssidx = $balnum%2;
2952: my $targets_div_style = 'display: none';
2953: my $disabled_div_style = 'display: block';
2954: my $homedom_div_style = 'display: none';
2955: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2956: '<td rowspan="'.$rownum.'" valign="top">'.
2957: '<p>';
2958: if ($lonhost eq '') {
2959: $datatable .= '<span class="LC_nobreak">';
2960: if (keys(%currbalancer) > 0) {
2961: $datatable .= &mt('Add balancer:');
2962: } else {
2963: $datatable .= &mt('Enable balancer:');
2964: }
2965: $datatable .= ' '.
2966: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2967: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2968: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2969: '<option value="" selected="selected">'.&mt('None').
2970: '</option>'."\n";
2971: foreach my $server (sort(keys(%servers))) {
2972: next if ($currbalancer{$server});
2973: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2974: }
2975: $datatable .=
2976: '</select>'."\n".
2977: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2978: } else {
2979: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2980: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2981: &mt('Stop balancing').'</label>'.
2982: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2983: $targets_div_style = 'display: block';
2984: $disabled_div_style = 'display: none';
2985: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2986: $homedom_div_style = 'display: block';
2987: }
2988: }
2989: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2990: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2991: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2992: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2993: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2994: my @sparestypes = ('primary','default');
2995: my %typetitles = &sparestype_titles();
2996: foreach my $sparetype (@sparestypes) {
2997: my $targettable;
2998: for (my $i=0; $i<$numspares; $i++) {
2999: my $checked;
3000: if (ref($currtargets{$lonhost}) eq 'HASH') {
3001: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3002: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3003: $checked = ' checked="checked"';
3004: }
3005: }
3006: }
3007: my ($chkboxval,$disabled);
3008: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3009: $chkboxval = $spares[$i];
3010: }
3011: if (exists($currbalancer{$spares[$i]})) {
3012: $disabled = ' disabled="disabled"';
3013: }
3014: $targettable .=
3015: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3016: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3017: '</span></label></td>';
3018: my $rem = $i%($numinrow);
3019: if ($rem == 0) {
3020: if (($i > 0) && ($i < $numspares-1)) {
3021: $targettable .= '</tr>';
3022: }
3023: if ($i < $numspares-1) {
3024: $targettable .= '<tr>';
1.150 raeburn 3025: }
3026: }
3027: }
1.171 raeburn 3028: if ($targettable ne '') {
3029: my $rem = $numspares%($numinrow);
3030: my $colsleft = $numinrow - $rem;
3031: if ($colsleft > 1 ) {
3032: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3033: ' </td>';
3034: } elsif ($colsleft == 1) {
3035: $targettable .= '<td class="LC_left_item"> </td>';
3036: }
3037: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3038: '<table><tr>'.$targettable.'</tr></table><br />';
3039: }
3040: }
3041: my $cssidx = $balnum%2;
3042: $datatable .= '</div></td></tr>'.
3043: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3044: $othertitle,$usertypes,$types,\%servers,
3045: \%currbalancer,$lonhost,
3046: $targets_div_style,$homedom_div_style,
3047: $css_class[$cssidx],$balnum,$islast);
3048: $$rowtotal += $rownum;
3049: $balnum ++;
3050: }
3051: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3052: return $datatable;
3053: }
3054:
3055: sub get_loadbalancers_config {
3056: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3057: return unless ((ref($servers) eq 'HASH') &&
3058: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3059: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3060: if (keys(%{$existing}) > 0) {
3061: my $oldlonhost;
3062: foreach my $key (sort(keys(%{$existing}))) {
3063: if ($key eq 'lonhost') {
3064: $oldlonhost = $existing->{'lonhost'};
3065: $currbalancer->{$oldlonhost} = 1;
3066: } elsif ($key eq 'targets') {
3067: if ($oldlonhost) {
3068: $currtargets->{$oldlonhost} = $existing->{'targets'};
3069: }
3070: } elsif ($key eq 'rules') {
3071: if ($oldlonhost) {
3072: $currrules->{$oldlonhost} = $existing->{'rules'};
3073: }
3074: } elsif (ref($existing->{$key}) eq 'HASH') {
3075: $currbalancer->{$key} = 1;
3076: $currtargets->{$key} = $existing->{$key}{'targets'};
3077: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3078: }
3079: }
1.171 raeburn 3080: } else {
3081: my ($balancerref,$targetsref) =
3082: &Apache::lonnet::get_lonbalancer_config($servers);
3083: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3084: foreach my $server (sort(keys(%{$balancerref}))) {
3085: $currbalancer->{$server} = 1;
3086: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3087: }
3088: }
3089: }
1.171 raeburn 3090: return;
1.150 raeburn 3091: }
3092:
3093: sub loadbalancing_rules {
3094: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3095: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3096: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3097: my $output;
1.171 raeburn 3098: my $num = 0;
1.150 raeburn 3099: my ($alltypes,$othertypes,$titles) =
3100: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3101: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3102: foreach my $type (@{$alltypes}) {
1.171 raeburn 3103: $num ++;
1.150 raeburn 3104: my $current;
3105: if (ref($currrules) eq 'HASH') {
3106: $current = $currrules->{$type};
3107: }
3108: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3109: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3110: $current = '';
3111: }
3112: }
3113: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3114: $servers,$currbalancer,$lonhost,$dom,
3115: $targets_div_style,$homedom_div_style,
3116: $css_class,$balnum,$num,$islast);
1.150 raeburn 3117: }
3118: }
3119: return $output;
3120: }
3121:
3122: sub loadbalancing_titles {
3123: my ($dom,$intdom,$usertypes,$types) = @_;
3124: my %othertypes = (
3125: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3126: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3127: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3128: '_LC_external' => &mt('Users not from [_1]',$intdom),
3129: );
3130: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3131: if (ref($types) eq 'ARRAY') {
3132: unshift(@alltypes,@{$types},'default');
3133: }
3134: my %titles;
3135: foreach my $type (@alltypes) {
3136: if ($type =~ /^_LC_/) {
3137: $titles{$type} = $othertypes{$type};
3138: } elsif ($type eq 'default') {
3139: $titles{$type} = &mt('All users from [_1]',$dom);
3140: if (ref($types) eq 'ARRAY') {
3141: if (@{$types} > 0) {
3142: $titles{$type} = &mt('Other users from [_1]',$dom);
3143: }
3144: }
3145: } elsif (ref($usertypes) eq 'HASH') {
3146: $titles{$type} = $usertypes->{$type};
3147: }
3148: }
3149: return (\@alltypes,\%othertypes,\%titles);
3150: }
3151:
3152: sub loadbalance_rule_row {
1.171 raeburn 3153: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3154: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3155: my @rulenames = ('default','homeserver');
3156: my %ruletitles = &offloadtype_text();
3157: if ($type eq '_LC_external') {
3158: push(@rulenames,'externalbalancer');
3159: } else {
3160: push(@rulenames,'specific');
3161: }
1.161 raeburn 3162: push(@rulenames,'none');
1.150 raeburn 3163: my $style = $targets_div_style;
3164: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3165: $style = $homedom_div_style;
3166: }
1.171 raeburn 3167: my $space;
3168: if ($islast && $num == 1) {
3169: $space = '<div display="inline-block"> </div>';
3170: }
1.150 raeburn 3171: my $output =
1.171 raeburn 3172: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3173: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3174: '<td valaign="top">'.$space.
3175: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3176: for (my $i=0; $i<@rulenames; $i++) {
3177: my $rule = $rulenames[$i];
3178: my ($checked,$extra);
3179: if ($rulenames[$i] eq 'default') {
3180: $rule = '';
3181: }
3182: if ($rulenames[$i] eq 'specific') {
3183: if (ref($servers) eq 'HASH') {
3184: my $default;
3185: if (($current ne '') && (exists($servers->{$current}))) {
3186: $checked = ' checked="checked"';
3187: }
3188: unless ($checked) {
3189: $default = ' selected="selected"';
3190: }
1.171 raeburn 3191: $extra =
3192: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3193: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3194: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3195: '<option value=""'.$default.'></option>'."\n";
3196: foreach my $server (sort(keys(%{$servers}))) {
3197: if (ref($currbalancer) eq 'HASH') {
3198: next if (exists($currbalancer->{$server}));
3199: }
1.150 raeburn 3200: my $selected;
1.171 raeburn 3201: if ($server eq $current) {
1.150 raeburn 3202: $selected = ' selected="selected"';
3203: }
1.171 raeburn 3204: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3205: }
3206: $extra .= '</select>';
3207: }
3208: } elsif ($rule eq $current) {
3209: $checked = ' checked="checked"';
3210: }
3211: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3212: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3213: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3214: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3215: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3216: '</label>'.$extra.'</span><br />'."\n";
3217: }
3218: $output .= '</div></td></tr>'."\n";
3219: return $output;
3220: }
3221:
3222: sub offloadtype_text {
3223: my %ruletitles = &Apache::lonlocal::texthash (
3224: 'default' => 'Offloads to default destinations',
3225: 'homeserver' => "Offloads to user's home server",
3226: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3227: 'specific' => 'Offloads to specific server',
1.161 raeburn 3228: 'none' => 'No offload',
1.150 raeburn 3229: );
3230: return %ruletitles;
3231: }
3232:
3233: sub sparestype_titles {
3234: my %typestitles = &Apache::lonlocal::texthash (
3235: 'primary' => 'primary',
3236: 'default' => 'default',
3237: );
3238: return %typestitles;
3239: }
3240:
1.28 raeburn 3241: sub contact_titles {
3242: my %titles = &Apache::lonlocal::texthash (
3243: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3244: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3245: 'errormail' => 'Error reports to be e-mailed to',
3246: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3247: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3248: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3249: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3250: );
3251: my %short_titles = &Apache::lonlocal::texthash (
3252: adminemail => 'Admin E-mail address',
3253: supportemail => 'Support E-mail',
3254: );
3255: return (\%titles,\%short_titles);
3256: }
3257:
1.72 raeburn 3258: sub tool_titles {
3259: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3260: aboutme => 'Personal web page',
1.86 raeburn 3261: blog => 'Blog',
1.162 raeburn 3262: webdav => 'WebDAV',
1.86 raeburn 3263: portfolio => 'Portfolio',
1.88 bisitz 3264: official => 'Official courses (with institutional codes)',
3265: unofficial => 'Unofficial courses',
1.98 raeburn 3266: community => 'Communities',
1.86 raeburn 3267: );
1.72 raeburn 3268: return %titles;
3269: }
3270:
1.101 raeburn 3271: sub courserequest_titles {
3272: my %titles = &Apache::lonlocal::texthash (
3273: official => 'Official',
3274: unofficial => 'Unofficial',
3275: community => 'Communities',
3276: norequest => 'Not allowed',
1.104 raeburn 3277: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3278: validate => 'With validation',
3279: autolimit => 'Numerical limit',
1.103 raeburn 3280: unlimited => '(blank for unlimited)',
1.101 raeburn 3281: );
3282: return %titles;
3283: }
3284:
1.163 raeburn 3285: sub authorrequest_titles {
3286: my %titles = &Apache::lonlocal::texthash (
3287: norequest => 'Not allowed',
3288: approval => 'Approval by Dom. Coord.',
3289: automatic => 'Automatic approval',
3290: );
3291: return %titles;
3292: }
3293:
1.101 raeburn 3294: sub courserequest_conditions {
3295: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3296: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3297: validate => '(Processing of request subject to instittutional validation).',
3298: );
3299: return %conditions;
3300: }
3301:
3302:
1.27 raeburn 3303: sub print_usercreation {
1.30 raeburn 3304: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3305: my $numinrow = 4;
1.28 raeburn 3306: my $datatable;
3307: if ($position eq 'top') {
1.30 raeburn 3308: $$rowtotal ++;
1.34 raeburn 3309: my $rowcount = 0;
1.32 raeburn 3310: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3311: if (ref($rules) eq 'HASH') {
3312: if (keys(%{$rules}) > 0) {
1.32 raeburn 3313: $datatable .= &user_formats_row('username',$settings,$rules,
3314: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3315: $$rowtotal ++;
1.32 raeburn 3316: $rowcount ++;
3317: }
3318: }
3319: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3320: if (ref($idrules) eq 'HASH') {
3321: if (keys(%{$idrules}) > 0) {
3322: $datatable .= &user_formats_row('id',$settings,$idrules,
3323: $idruleorder,$numinrow,$rowcount);
3324: $$rowtotal ++;
3325: $rowcount ++;
1.28 raeburn 3326: }
3327: }
1.43 raeburn 3328: my ($emailrules,$emailruleorder) =
3329: &Apache::lonnet::inst_userrules($dom,'email');
3330: if (ref($emailrules) eq 'HASH') {
3331: if (keys(%{$emailrules}) > 0) {
3332: $datatable .= &user_formats_row('email',$settings,$emailrules,
3333: $emailruleorder,$numinrow,$rowcount);
3334: $$rowtotal ++;
3335: $rowcount ++;
3336: }
3337: }
1.39 raeburn 3338: if ($rowcount == 0) {
3339: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3340: $$rowtotal ++;
3341: $rowcount ++;
3342: }
1.34 raeburn 3343: } elsif ($position eq 'middle') {
1.100 raeburn 3344: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3345: my ($rules,$ruleorder) =
3346: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3347: my %lt = &usercreation_types();
3348: my %checked;
1.50 raeburn 3349: my @selfcreate;
1.34 raeburn 3350: if (ref($settings) eq 'HASH') {
3351: if (ref($settings->{'cancreate'}) eq 'HASH') {
3352: foreach my $item (@creators) {
3353: $checked{$item} = $settings->{'cancreate'}{$item};
3354: }
1.50 raeburn 3355: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3356: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3357: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3358: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3359: @selfcreate = ('email','login','sso');
3360: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3361: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3362: }
3363: }
1.34 raeburn 3364: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3365: foreach my $item (@creators) {
3366: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3367: $checked{$item} = 'none';
3368: }
3369: }
3370: }
3371: }
3372: my $rownum = 0;
3373: foreach my $item (@creators) {
3374: $rownum ++;
1.50 raeburn 3375: if ($item ne 'selfcreate') {
3376: if ($checked{$item} eq '') {
1.43 raeburn 3377: $checked{$item} = 'any';
3378: }
1.34 raeburn 3379: }
3380: my $css_class;
3381: if ($rownum%2) {
3382: $css_class = '';
3383: } else {
3384: $css_class = ' class="LC_odd_row" ';
3385: }
3386: $datatable .= '<tr'.$css_class.'>'.
3387: '<td><span class="LC_nobreak">'.$lt{$item}.
3388: '</span></td><td align="right">';
1.50 raeburn 3389: my @options;
1.45 raeburn 3390: if ($item eq 'selfcreate') {
1.43 raeburn 3391: push(@options,('email','login','sso'));
3392: } else {
1.50 raeburn 3393: @options = ('any');
1.43 raeburn 3394: if (ref($rules) eq 'HASH') {
3395: if (keys(%{$rules}) > 0) {
3396: push(@options,('official','unofficial'));
3397: }
1.37 raeburn 3398: }
1.50 raeburn 3399: push(@options,'none');
1.37 raeburn 3400: }
3401: foreach my $option (@options) {
1.50 raeburn 3402: my $type = 'radio';
1.34 raeburn 3403: my $check = ' ';
1.50 raeburn 3404: if ($item eq 'selfcreate') {
3405: $type = 'checkbox';
3406: if (grep(/^\Q$option\E$/,@selfcreate)) {
3407: $check = ' checked="checked" ';
3408: }
3409: } else {
3410: if ($checked{$item} eq $option) {
3411: $check = ' checked="checked" ';
3412: }
1.34 raeburn 3413: }
3414: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3415: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3416: $item.'" value="'.$option.'"'.$check.'/> '.
3417: $lt{$option}.'</label> </span>';
3418: }
3419: $datatable .= '</td></tr>';
3420: }
1.93 raeburn 3421: my ($othertitle,$usertypes,$types) =
3422: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3423: my $createsettings;
3424: if (ref($settings) eq 'HASH') {
3425: $createsettings = $settings->{cancreate};
3426: }
1.93 raeburn 3427: if (ref($usertypes) eq 'HASH') {
3428: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3429: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3430: $dom,$numinrow,$othertitle,
3431: 'statustocreate');
3432: $$rowtotal ++;
1.169 raeburn 3433: $rownum ++;
1.93 raeburn 3434: }
3435: }
1.169 raeburn 3436: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3437: } else {
3438: my @contexts = ('author','course','domain');
3439: my @authtypes = ('int','krb4','krb5','loc');
3440: my %checked;
3441: if (ref($settings) eq 'HASH') {
3442: if (ref($settings->{'authtypes'}) eq 'HASH') {
3443: foreach my $item (@contexts) {
3444: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3445: foreach my $auth (@authtypes) {
3446: if ($settings->{'authtypes'}{$item}{$auth}) {
3447: $checked{$item}{$auth} = ' checked="checked" ';
3448: }
3449: }
3450: }
3451: }
1.27 raeburn 3452: }
1.35 raeburn 3453: } else {
3454: foreach my $item (@contexts) {
1.36 raeburn 3455: foreach my $auth (@authtypes) {
1.35 raeburn 3456: $checked{$item}{$auth} = ' checked="checked" ';
3457: }
3458: }
1.27 raeburn 3459: }
1.28 raeburn 3460: my %title = &context_names();
3461: my %authname = &authtype_names();
3462: my $rownum = 0;
3463: my $css_class;
3464: foreach my $item (@contexts) {
3465: if ($rownum%2) {
3466: $css_class = '';
3467: } else {
3468: $css_class = ' class="LC_odd_row" ';
3469: }
1.30 raeburn 3470: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3471: '<td>'.$title{$item}.
3472: '</td><td class="LC_left_item">'.
3473: '<span class="LC_nobreak">';
3474: foreach my $auth (@authtypes) {
3475: $datatable .= '<label>'.
3476: '<input type="checkbox" name="'.$item.'_auth" '.
3477: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3478: $authname{$auth}.'</label> ';
3479: }
3480: $datatable .= '</span></td></tr>';
3481: $rownum ++;
1.27 raeburn 3482: }
1.30 raeburn 3483: $$rowtotal += $rownum;
1.27 raeburn 3484: }
3485: return $datatable;
3486: }
3487:
1.165 raeburn 3488: sub captcha_choice {
1.169 raeburn 3489: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3490: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3491: my %lt = &captcha_phrases();
3492: $keyentry = 'hidden';
3493: if ($context eq 'cancreate') {
3494: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3495: } elsif ($context eq 'login') {
3496: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3497: }
3498: if (ref($settings) eq 'HASH') {
3499: if ($settings->{'captcha'}) {
3500: $checked{$settings->{'captcha'}} = ' checked="checked"';
3501: } else {
3502: $checked{'original'} = ' checked="checked"';
3503: }
3504: if ($settings->{'captcha'} eq 'recaptcha') {
3505: $pubtext = $lt{'pub'};
3506: $privtext = $lt{'priv'};
3507: $keyentry = 'text';
3508: }
3509: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3510: $currpub = $settings->{'recaptchakeys'}{'public'};
3511: $currpriv = $settings->{'recaptchakeys'}{'private'};
3512: }
3513: } else {
3514: $checked{'original'} = ' checked="checked"';
3515: }
1.169 raeburn 3516: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3517: my $output = '<tr'.$css_class.'>'.
3518: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3519: '<table><tr><td>'."\n";
3520: foreach my $option ('original','recaptcha','notused') {
3521: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3522: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3523: $lt{$option}.'</label></span>';
3524: unless ($option eq 'notused') {
3525: $output .= (' 'x2)."\n";
3526: }
3527: }
3528: #
3529: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3530: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3531: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3532: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3533: #
3534: $output .= '</td></tr>'."\n".
3535: '<tr><td>'."\n".
3536: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3537: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3538: $currpub.'" size="40" /></span><br />'."\n".
3539: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3540: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3541: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3542: '</td></tr>';
3543: return $output;
3544: }
3545:
1.32 raeburn 3546: sub user_formats_row {
3547: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3548: my $output;
3549: my %text = (
3550: 'username' => 'new usernames',
3551: 'id' => 'IDs',
1.45 raeburn 3552: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3553: );
3554: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3555: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3556: '<td><span class="LC_nobreak">';
3557: if ($type eq 'email') {
3558: $output .= &mt("Formats disallowed for $text{$type}: ");
3559: } else {
3560: $output .= &mt("Format rules to check for $text{$type}: ");
3561: }
3562: $output .= '</span></td>'.
3563: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3564: my $rem;
3565: if (ref($ruleorder) eq 'ARRAY') {
3566: for (my $i=0; $i<@{$ruleorder}; $i++) {
3567: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3568: my $rem = $i%($numinrow);
3569: if ($rem == 0) {
3570: if ($i > 0) {
3571: $output .= '</tr>';
3572: }
3573: $output .= '<tr>';
3574: }
3575: my $check = ' ';
1.39 raeburn 3576: if (ref($settings) eq 'HASH') {
3577: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3578: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3579: $check = ' checked="checked" ';
3580: }
1.27 raeburn 3581: }
3582: }
3583: $output .= '<td class="LC_left_item">'.
3584: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3585: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3586: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3587: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3588: }
3589: }
3590: $rem = @{$ruleorder}%($numinrow);
3591: }
3592: my $colsleft = $numinrow - $rem;
3593: if ($colsleft > 1 ) {
3594: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3595: ' </td>';
3596: } elsif ($colsleft == 1) {
3597: $output .= '<td class="LC_left_item"> </td>';
3598: }
3599: $output .= '</tr></table></td></tr>';
3600: return $output;
3601: }
3602:
1.34 raeburn 3603: sub usercreation_types {
3604: my %lt = &Apache::lonlocal::texthash (
3605: author => 'When adding a co-author',
3606: course => 'When adding a user to a course',
1.100 raeburn 3607: requestcrs => 'When requesting a course',
1.45 raeburn 3608: selfcreate => 'User creates own account',
1.34 raeburn 3609: any => 'Any',
3610: official => 'Institutional only ',
3611: unofficial => 'Non-institutional only',
1.85 schafran 3612: email => 'E-mail address',
1.43 raeburn 3613: login => 'Institutional Login',
3614: sso => 'SSO',
1.34 raeburn 3615: none => 'None',
3616: );
3617: return %lt;
1.48 raeburn 3618: }
1.34 raeburn 3619:
1.28 raeburn 3620: sub authtype_names {
3621: my %lt = &Apache::lonlocal::texthash(
3622: int => 'Internal',
3623: krb4 => 'Kerberos 4',
3624: krb5 => 'Kerberos 5',
3625: loc => 'Local',
3626: );
3627: return %lt;
3628: }
3629:
3630: sub context_names {
3631: my %context_title = &Apache::lonlocal::texthash(
3632: author => 'Creating users when an Author',
3633: course => 'Creating users when in a course',
3634: domain => 'Creating users when a Domain Coordinator',
3635: );
3636: return %context_title;
3637: }
3638:
1.33 raeburn 3639: sub print_usermodification {
3640: my ($position,$dom,$settings,$rowtotal) = @_;
3641: my $numinrow = 4;
3642: my ($context,$datatable,$rowcount);
3643: if ($position eq 'top') {
3644: $rowcount = 0;
3645: $context = 'author';
3646: foreach my $role ('ca','aa') {
3647: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3648: $numinrow,$rowcount);
3649: $$rowtotal ++;
3650: $rowcount ++;
3651: }
1.63 raeburn 3652: } elsif ($position eq 'middle') {
1.33 raeburn 3653: $context = 'course';
3654: $rowcount = 0;
3655: foreach my $role ('st','ep','ta','in','cr') {
3656: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3657: $numinrow,$rowcount);
3658: $$rowtotal ++;
3659: $rowcount ++;
3660: }
1.63 raeburn 3661: } elsif ($position eq 'bottom') {
3662: $context = 'selfcreate';
3663: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3664: $usertypes->{'default'} = $othertitle;
3665: if (ref($types) eq 'ARRAY') {
3666: push(@{$types},'default');
3667: $usertypes->{'default'} = $othertitle;
3668: foreach my $status (@{$types}) {
3669: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3670: $numinrow,$rowcount,$usertypes);
3671: $$rowtotal ++;
3672: $rowcount ++;
3673: }
3674: }
1.33 raeburn 3675: }
3676: return $datatable;
3677: }
3678:
1.43 raeburn 3679: sub print_defaults {
3680: my ($dom,$rowtotal) = @_;
1.68 raeburn 3681: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3682: 'datelocale_def','portal_def');
1.43 raeburn 3683: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3684: my $titles = &defaults_titles($dom);
1.43 raeburn 3685: my $rownum = 0;
3686: my ($datatable,$css_class);
3687: foreach my $item (@items) {
3688: if ($rownum%2) {
3689: $css_class = '';
3690: } else {
3691: $css_class = ' class="LC_odd_row" ';
3692: }
3693: $datatable .= '<tr'.$css_class.'>'.
3694: '<td><span class="LC_nobreak">'.$titles->{$item}.
3695: '</span></td><td class="LC_right_item">';
3696: if ($item eq 'auth_def') {
3697: my @authtypes = ('internal','krb4','krb5','localauth');
3698: my %shortauth = (
3699: internal => 'int',
3700: krb4 => 'krb4',
3701: krb5 => 'krb5',
3702: localauth => 'loc'
3703: );
3704: my %authnames = &authtype_names();
3705: foreach my $auth (@authtypes) {
3706: my $checked = ' ';
3707: if ($domdefaults{$item} eq $auth) {
3708: $checked = ' checked="checked" ';
3709: }
3710: $datatable .= '<label><input type="radio" name="'.$item.
3711: '" value="'.$auth.'"'.$checked.'/>'.
3712: $authnames{$shortauth{$auth}}.'</label> ';
3713: }
1.54 raeburn 3714: } elsif ($item eq 'timezone_def') {
3715: my $includeempty = 1;
3716: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3717: } elsif ($item eq 'datelocale_def') {
3718: my $includeempty = 1;
3719: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3720: } elsif ($item eq 'lang_def') {
1.168 raeburn 3721: my %langchoices = &get_languages_hash();
3722: $langchoices{''} = 'No language preference';
1.167 raeburn 3723: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3724: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3725: \%langchoices);
1.43 raeburn 3726: } else {
1.141 raeburn 3727: my $size;
3728: if ($item eq 'portal_def') {
3729: $size = ' size="25"';
3730: }
1.43 raeburn 3731: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3732: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3733: }
3734: $datatable .= '</td></tr>';
3735: $rownum ++;
3736: }
3737: $$rowtotal += $rownum;
3738: return $datatable;
3739: }
3740:
1.168 raeburn 3741: sub get_languages_hash {
3742: my %langchoices;
3743: foreach my $id (&Apache::loncommon::languageids()) {
3744: my $code = &Apache::loncommon::supportedlanguagecode($id);
3745: if ($code ne '') {
3746: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3747: }
3748: }
3749: return %langchoices;
3750: }
3751:
1.43 raeburn 3752: sub defaults_titles {
1.141 raeburn 3753: my ($dom) = @_;
1.43 raeburn 3754: my %titles = &Apache::lonlocal::texthash (
3755: 'auth_def' => 'Default authentication type',
3756: 'auth_arg_def' => 'Default authentication argument',
3757: 'lang_def' => 'Default language',
1.54 raeburn 3758: 'timezone_def' => 'Default timezone',
1.68 raeburn 3759: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3760: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3761: );
1.141 raeburn 3762: if ($dom) {
3763: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3764: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3765: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3766: $protocol = 'http' if ($protocol ne 'https');
3767: if ($uint_dom) {
3768: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3769: $uint_dom);
3770: }
3771: }
1.43 raeburn 3772: return (\%titles);
3773: }
3774:
1.46 raeburn 3775: sub print_scantronformat {
3776: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3777: my $itemcount = 1;
1.60 raeburn 3778: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3779: %confhash);
1.46 raeburn 3780: my $switchserver = &check_switchserver($dom,$confname);
3781: my %lt = &Apache::lonlocal::texthash (
1.95 www 3782: default => 'Default bubblesheet format file error',
3783: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3784: );
3785: my %scantronfiles = (
3786: default => 'default.tab',
3787: custom => 'custom.tab',
3788: );
3789: foreach my $key (keys(%scantronfiles)) {
3790: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3791: .$scantronfiles{$key};
3792: }
3793: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3794: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3795: if (!$switchserver) {
3796: my $servadm = $r->dir_config('lonAdmEMail');
3797: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3798: if ($configuserok eq 'ok') {
3799: if ($author_ok eq 'ok') {
3800: my %legacyfile = (
3801: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3802: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3803: );
3804: my %md5chk;
3805: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3806: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3807: chomp($md5chk{$type});
1.46 raeburn 3808: }
3809: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3810: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3811: ($scantronurls{$type},my $error) =
1.46 raeburn 3812: &legacy_scantronformat($r,$dom,$confname,
3813: $type,$legacyfile{$type},
3814: $scantronurls{$type},
3815: $scantronfiles{$type});
1.60 raeburn 3816: if ($error ne '') {
3817: $error{$type} = $error;
3818: }
3819: }
3820: if (keys(%error) == 0) {
3821: $is_custom = 1;
3822: $confhash{'scantron'}{'scantronformat'} =
3823: $scantronurls{'custom'};
3824: my $putresult =
3825: &Apache::lonnet::put_dom('configuration',
3826: \%confhash,$dom);
3827: if ($putresult ne 'ok') {
3828: $error{'custom'} =
3829: '<span class="LC_error">'.
3830: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3831: }
1.46 raeburn 3832: }
3833: } else {
1.60 raeburn 3834: ($scantronurls{'default'},my $error) =
1.46 raeburn 3835: &legacy_scantronformat($r,$dom,$confname,
3836: 'default',$legacyfile{'default'},
3837: $scantronurls{'default'},
3838: $scantronfiles{'default'});
1.60 raeburn 3839: if ($error eq '') {
3840: $confhash{'scantron'}{'scantronformat'} = '';
3841: my $putresult =
3842: &Apache::lonnet::put_dom('configuration',
3843: \%confhash,$dom);
3844: if ($putresult ne 'ok') {
3845: $error{'default'} =
3846: '<span class="LC_error">'.
3847: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3848: }
3849: } else {
3850: $error{'default'} = $error;
3851: }
1.46 raeburn 3852: }
3853: }
3854: }
3855: } else {
1.95 www 3856: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3857: }
3858: }
3859: if (ref($settings) eq 'HASH') {
3860: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3861: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3862: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3863: $scantronurl = '';
3864: } else {
3865: $scantronurl = $settings->{'scantronformat'};
3866: }
3867: $is_custom = 1;
3868: } else {
3869: $scantronurl = $scantronurls{'default'};
3870: }
3871: } else {
1.60 raeburn 3872: if ($is_custom) {
3873: $scantronurl = $scantronurls{'custom'};
3874: } else {
3875: $scantronurl = $scantronurls{'default'};
3876: }
1.46 raeburn 3877: }
3878: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3879: $datatable .= '<tr'.$css_class.'>';
3880: if (!$is_custom) {
1.65 raeburn 3881: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3882: '<span class="LC_nobreak">';
1.46 raeburn 3883: if ($scantronurl) {
3884: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3885: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3886: } else {
3887: $datatable = &mt('File unavailable for display');
3888: }
1.65 raeburn 3889: $datatable .= '</span></td>';
1.60 raeburn 3890: if (keys(%error) == 0) {
3891: $datatable .= '<td valign="bottom">';
3892: if (!$switchserver) {
3893: $datatable .= &mt('Upload:').'<br />';
3894: }
3895: } else {
3896: my $errorstr;
3897: foreach my $key (sort(keys(%error))) {
3898: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3899: }
3900: $datatable .= '<td>'.$errorstr;
3901: }
1.46 raeburn 3902: } else {
3903: if (keys(%error) > 0) {
3904: my $errorstr;
3905: foreach my $key (sort(keys(%error))) {
3906: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3907: }
1.60 raeburn 3908: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3909: } elsif ($scantronurl) {
1.65 raeburn 3910: $datatable .= '<td><span class="LC_nobreak">'.
3911: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3912: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3913: '<input type="checkbox" name="scantronformat_del"'.
3914: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3915: '<td><span class="LC_nobreak"> '.
3916: &mt('Replace:').'</span><br />';
1.46 raeburn 3917: }
3918: }
3919: if (keys(%error) == 0) {
3920: if ($switchserver) {
3921: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3922: } else {
1.65 raeburn 3923: $datatable .='<span class="LC_nobreak"> '.
3924: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3925: }
3926: }
3927: $datatable .= '</td></tr>';
3928: $$rowtotal ++;
3929: return $datatable;
3930: }
3931:
3932: sub legacy_scantronformat {
3933: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3934: my ($url,$error);
3935: my @statinfo = &Apache::lonnet::stat_file($newurl);
3936: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3937: (my $result,$url) =
3938: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3939: '','',$newfile);
3940: if ($result ne 'ok') {
1.130 raeburn 3941: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3942: }
3943: }
3944: return ($url,$error);
3945: }
1.43 raeburn 3946:
1.49 raeburn 3947: sub print_coursecategories {
1.57 raeburn 3948: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3949: my $datatable;
3950: if ($position eq 'top') {
3951: my $toggle_cats_crs = ' ';
3952: my $toggle_cats_dom = ' checked="checked" ';
3953: my $can_cat_crs = ' ';
3954: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3955: my $toggle_catscomm_comm = ' ';
3956: my $toggle_catscomm_dom = ' checked="checked" ';
3957: my $can_catcomm_comm = ' ';
3958: my $can_catcomm_dom = ' checked="checked" ';
3959:
1.57 raeburn 3960: if (ref($settings) eq 'HASH') {
3961: if ($settings->{'togglecats'} eq 'crs') {
3962: $toggle_cats_crs = $toggle_cats_dom;
3963: $toggle_cats_dom = ' ';
3964: }
3965: if ($settings->{'categorize'} eq 'crs') {
3966: $can_cat_crs = $can_cat_dom;
3967: $can_cat_dom = ' ';
3968: }
1.120 raeburn 3969: if ($settings->{'togglecatscomm'} eq 'comm') {
3970: $toggle_catscomm_comm = $toggle_catscomm_dom;
3971: $toggle_catscomm_dom = ' ';
3972: }
3973: if ($settings->{'categorizecomm'} eq 'comm') {
3974: $can_catcomm_comm = $can_catcomm_dom;
3975: $can_catcomm_dom = ' ';
3976: }
1.57 raeburn 3977: }
3978: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3979: togglecats => 'Show/Hide a course in catalog',
3980: togglecatscomm => 'Show/Hide a community in catalog',
3981: categorize => 'Assign a category to a course',
3982: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3983: );
3984: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3985: dom => 'Set in Domain',
3986: crs => 'Set in Course',
3987: comm => 'Set in Community',
1.57 raeburn 3988: );
3989: $datatable = '<tr class="LC_odd_row">'.
3990: '<td>'.$title{'togglecats'}.'</td>'.
3991: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3992: '<input type="radio" name="togglecats"'.
3993: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3994: '<label><input type="radio" name="togglecats"'.
3995: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3996: '</tr><tr>'.
3997: '<td>'.$title{'categorize'}.'</td>'.
3998: '<td class="LC_right_item"><span class="LC_nobreak">'.
3999: '<label><input type="radio" name="categorize"'.
4000: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4001: '<label><input type="radio" name="categorize"'.
4002: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4003: '</tr><tr class="LC_odd_row">'.
4004: '<td>'.$title{'togglecatscomm'}.'</td>'.
4005: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4006: '<input type="radio" name="togglecatscomm"'.
4007: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4008: '<label><input type="radio" name="togglecatscomm"'.
4009: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4010: '</tr><tr>'.
4011: '<td>'.$title{'categorizecomm'}.'</td>'.
4012: '<td class="LC_right_item"><span class="LC_nobreak">'.
4013: '<label><input type="radio" name="categorizecomm"'.
4014: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4015: '<label><input type="radio" name="categorizecomm"'.
4016: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4017: '</tr>';
1.120 raeburn 4018: $$rowtotal += 4;
1.57 raeburn 4019: } else {
4020: my $css_class;
4021: my $itemcount = 1;
4022: my $cathash;
4023: if (ref($settings) eq 'HASH') {
4024: $cathash = $settings->{'cats'};
4025: }
4026: if (ref($cathash) eq 'HASH') {
4027: my (@cats,@trails,%allitems,%idx,@jsarray);
4028: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4029: \%allitems,\%idx,\@jsarray);
4030: my $maxdepth = scalar(@cats);
4031: my $colattrib = '';
4032: if ($maxdepth > 2) {
4033: $colattrib = ' colspan="2" ';
4034: }
4035: my @path;
4036: if (@cats > 0) {
4037: if (ref($cats[0]) eq 'ARRAY') {
4038: my $numtop = @{$cats[0]};
4039: my $maxnum = $numtop;
1.120 raeburn 4040: my %default_names = (
4041: instcode => &mt('Official courses'),
4042: communities => &mt('Communities'),
4043: );
4044:
4045: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4046: ($cathash->{'instcode::0'} eq '') ||
4047: (!grep(/^communities$/,@{$cats[0]})) ||
4048: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4049: $maxnum ++;
4050: }
4051: my $lastidx;
4052: for (my $i=0; $i<$numtop; $i++) {
4053: my $parent = $cats[0][$i];
4054: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4055: my $item = &escape($parent).'::0';
4056: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4057: $lastidx = $idx{$item};
4058: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4059: .'<select name="'.$item.'"'.$chgstr.'>';
4060: for (my $k=0; $k<=$maxnum; $k++) {
4061: my $vpos = $k+1;
4062: my $selstr;
4063: if ($k == $i) {
4064: $selstr = ' selected="selected" ';
4065: }
4066: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4067: }
4068: $datatable .= '</select></td><td>';
1.120 raeburn 4069: if ($parent eq 'instcode' || $parent eq 'communities') {
4070: $datatable .= '<span class="LC_nobreak">'
4071: .$default_names{$parent}.'</span>';
4072: if ($parent eq 'instcode') {
4073: $datatable .= '<br /><span class="LC_nobreak">('
4074: .&mt('with institutional codes')
4075: .')</span></td><td'.$colattrib.'>';
4076: } else {
4077: $datatable .= '<table><tr><td>';
4078: }
4079: $datatable .= '<span class="LC_nobreak">'
4080: .'<label><input type="radio" name="'
4081: .$parent.'" value="1" checked="checked" />'
4082: .&mt('Display').'</label>';
4083: if ($parent eq 'instcode') {
4084: $datatable .= ' ';
4085: } else {
4086: $datatable .= '</span></td></tr><tr><td>'
4087: .'<span class="LC_nobreak">';
4088: }
4089: $datatable .= '<label><input type="radio" name="'
4090: .$parent.'" value="0" />'
4091: .&mt('Do not display').'</label></span>';
4092: if ($parent eq 'communities') {
4093: $datatable .= '</td></tr></table>';
4094: }
4095: $datatable .= '</td>';
1.57 raeburn 4096: } else {
4097: $datatable .= $parent
4098: .' <label><input type="checkbox" name="deletecategory" '
4099: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4100: }
4101: my $depth = 1;
4102: push(@path,$parent);
4103: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4104: pop(@path);
4105: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4106: $itemcount ++;
4107: }
1.48 raeburn 4108: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4109: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4110: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4111: for (my $k=0; $k<=$maxnum; $k++) {
4112: my $vpos = $k+1;
4113: my $selstr;
1.57 raeburn 4114: if ($k == $numtop) {
1.48 raeburn 4115: $selstr = ' selected="selected" ';
4116: }
4117: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4118: }
1.59 bisitz 4119: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4120: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4121: .'</tr>'."\n";
1.48 raeburn 4122: $itemcount ++;
1.120 raeburn 4123: foreach my $default ('instcode','communities') {
4124: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4125: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4126: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4127: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4128: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4129: for (my $k=0; $k<=$maxnum; $k++) {
4130: my $vpos = $k+1;
4131: my $selstr;
4132: if ($k == $maxnum) {
4133: $selstr = ' selected="selected" ';
4134: }
4135: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4136: }
1.120 raeburn 4137: $datatable .= '</select></span></td>'.
4138: '<td><span class="LC_nobreak">'.
4139: $default_names{$default}.'</span>';
4140: if ($default eq 'instcode') {
4141: $datatable .= '<br /><span class="LC_nobreak">('
4142: .&mt('with institutional codes').')</span>';
4143: }
4144: $datatable .= '</td>'
4145: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4146: .&mt('Display').'</label> '
4147: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4148: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4149: }
4150: }
4151: }
1.57 raeburn 4152: } else {
4153: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4154: }
4155: } else {
1.57 raeburn 4156: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4157: .&initialize_categories($itemcount);
1.48 raeburn 4158: }
1.57 raeburn 4159: $$rowtotal += $itemcount;
1.48 raeburn 4160: }
4161: return $datatable;
4162: }
4163:
1.69 raeburn 4164: sub print_serverstatuses {
4165: my ($dom,$settings,$rowtotal) = @_;
4166: my $datatable;
4167: my @pages = &serverstatus_pages();
4168: my (%namedaccess,%machineaccess);
4169: foreach my $type (@pages) {
4170: $namedaccess{$type} = '';
4171: $machineaccess{$type}= '';
4172: }
4173: if (ref($settings) eq 'HASH') {
4174: foreach my $type (@pages) {
4175: if (exists($settings->{$type})) {
4176: if (ref($settings->{$type}) eq 'HASH') {
4177: foreach my $key (keys(%{$settings->{$type}})) {
4178: if ($key eq 'namedusers') {
4179: $namedaccess{$type} = $settings->{$type}->{$key};
4180: } elsif ($key eq 'machines') {
4181: $machineaccess{$type} = $settings->{$type}->{$key};
4182: }
4183: }
4184: }
4185: }
4186: }
4187: }
1.81 raeburn 4188: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4189: my $rownum = 0;
4190: my $css_class;
4191: foreach my $type (@pages) {
4192: $rownum ++;
4193: $css_class = $rownum%2?' class="LC_odd_row"':'';
4194: $datatable .= '<tr'.$css_class.'>'.
4195: '<td><span class="LC_nobreak">'.
4196: $titles->{$type}.'</span></td>'.
4197: '<td class="LC_left_item">'.
4198: '<input type="text" name="'.$type.'_namedusers" '.
4199: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4200: '<td class="LC_right_item">'.
4201: '<span class="LC_nobreak">'.
4202: '<input type="text" name="'.$type.'_machines" '.
4203: 'value="'.$machineaccess{$type}.'" size="10" />'.
4204: '</td></tr>'."\n";
4205: }
4206: $$rowtotal += $rownum;
4207: return $datatable;
4208: }
4209:
4210: sub serverstatus_pages {
4211: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4212: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4213: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4214: }
4215:
1.49 raeburn 4216: sub coursecategories_javascript {
4217: my ($settings) = @_;
1.57 raeburn 4218: my ($output,$jstext,$cathash);
1.49 raeburn 4219: if (ref($settings) eq 'HASH') {
1.57 raeburn 4220: $cathash = $settings->{'cats'};
4221: }
4222: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4223: my (@cats,@jsarray,%idx);
1.57 raeburn 4224: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4225: if (@jsarray > 0) {
4226: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4227: for (my $i=0; $i<@jsarray; $i++) {
4228: if (ref($jsarray[$i]) eq 'ARRAY') {
4229: my $catstr = join('","',@{$jsarray[$i]});
4230: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4231: }
4232: }
4233: }
4234: } else {
4235: $jstext = ' var categories = Array(1);'."\n".
4236: ' categories[0] = Array("instcode_pos");'."\n";
4237: }
1.120 raeburn 4238: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4239: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4240: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4241: $output = <<"ENDSCRIPT";
4242: <script type="text/javascript">
1.109 raeburn 4243: // <![CDATA[
1.49 raeburn 4244: function reorderCats(form,parent,item,idx) {
4245: var changedVal;
4246: $jstext
4247: var newpos = 'addcategory_pos';
4248: var current = new Array;
4249: if (parent == '') {
4250: var has_instcode = 0;
4251: var maxtop = categories[idx].length;
4252: for (var j=0; j<maxtop; j++) {
4253: if (categories[idx][j] == 'instcode::0') {
4254: has_instcode == 1;
4255: }
4256: }
4257: if (has_instcode == 0) {
4258: categories[idx][maxtop] = 'instcode_pos';
4259: }
4260: } else {
4261: newpos += '_'+parent;
4262: }
4263: var maxh = 1 + categories[idx].length;
4264: var current = new Array;
4265: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4266: if (item == newpos) {
4267: changedVal = newitemVal;
4268: } else {
4269: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4270: current[newitemVal] = newpos;
4271: }
4272: for (var i=0; i<categories[idx].length; i++) {
4273: var elementName = categories[idx][i];
4274: if (elementName != item) {
4275: if (form.elements[elementName]) {
4276: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4277: current[currVal] = elementName;
4278: }
4279: }
4280: }
4281: var oldVal;
4282: for (var j=0; j<maxh; j++) {
4283: if (current[j] == undefined) {
4284: oldVal = j;
4285: }
4286: }
4287: if (oldVal < changedVal) {
4288: for (var k=oldVal+1; k<=changedVal ; k++) {
4289: var elementName = current[k];
4290: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4291: }
4292: } else {
4293: for (var k=changedVal; k<oldVal; k++) {
4294: var elementName = current[k];
4295: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4296: }
4297: }
4298: return;
4299: }
1.120 raeburn 4300:
4301: function categoryCheck(form) {
4302: if (form.elements['addcategory_name'].value == 'instcode') {
4303: alert('$instcode_reserved\\n$choose_again');
4304: return false;
4305: }
4306: if (form.elements['addcategory_name'].value == 'communities') {
4307: alert('$communities_reserved\\n$choose_again');
4308: return false;
4309: }
4310: return true;
4311: }
4312:
1.109 raeburn 4313: // ]]>
1.49 raeburn 4314: </script>
4315:
4316: ENDSCRIPT
4317: return $output;
4318: }
4319:
1.48 raeburn 4320: sub initialize_categories {
4321: my ($itemcount) = @_;
1.120 raeburn 4322: my ($datatable,$css_class,$chgstr);
4323: my %default_names = (
4324: instcode => 'Official courses (with institutional codes)',
4325: communities => 'Communities',
4326: );
4327: my $select0 = ' selected="selected"';
4328: my $select1 = '';
4329: foreach my $default ('instcode','communities') {
4330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4331: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4332: if ($default eq 'communities') {
4333: $select1 = $select0;
4334: $select0 = '';
4335: }
4336: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4337: .'<select name="'.$default.'_pos">'
4338: .'<option value="0"'.$select0.'>1</option>'
4339: .'<option value="1"'.$select1.'>2</option>'
4340: .'<option value="2">3</option></select> '
4341: .$default_names{$default}
4342: .'</span></td><td><span class="LC_nobreak">'
4343: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4344: .&mt('Display').'</label> <label>'
4345: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4346: .'</label></span></td></tr>';
1.120 raeburn 4347: $itemcount ++;
4348: }
1.48 raeburn 4349: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4350: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4351: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4352: .'<select name="addcategory_pos"'.$chgstr.'>'
4353: .'<option value="0">1</option>'
4354: .'<option value="1">2</option>'
4355: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4356: .&mt('Add category').'</td><td>'.&mt('Name:')
4357: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4358: return $datatable;
4359: }
4360:
4361: sub build_category_rows {
1.49 raeburn 4362: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4363: my ($text,$name,$item,$chgstr);
1.48 raeburn 4364: if (ref($cats) eq 'ARRAY') {
4365: my $maxdepth = scalar(@{$cats});
4366: if (ref($cats->[$depth]) eq 'HASH') {
4367: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4368: my $numchildren = @{$cats->[$depth]{$parent}};
4369: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4370: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4371: my ($idxnum,$parent_name,$parent_item);
4372: my $higher = $depth - 1;
4373: if ($higher == 0) {
4374: $parent_name = &escape($parent).'::'.$higher;
4375: } else {
4376: if (ref($path) eq 'ARRAY') {
4377: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4378: }
4379: }
4380: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4381: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4382: if ($j < $numchildren) {
1.48 raeburn 4383: $name = $cats->[$depth]{$parent}[$j];
4384: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4385: $idxnum = $idx->{$item};
4386: } else {
4387: $name = $parent_name;
4388: $item = $parent_item;
1.48 raeburn 4389: }
1.49 raeburn 4390: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4391: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4392: for (my $i=0; $i<=$numchildren; $i++) {
4393: my $vpos = $i+1;
4394: my $selstr;
4395: if ($j == $i) {
4396: $selstr = ' selected="selected" ';
4397: }
4398: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4399: }
4400: $text .= '</select> ';
4401: if ($j < $numchildren) {
4402: my $deeper = $depth+1;
4403: $text .= $name.' '
4404: .'<label><input type="checkbox" name="deletecategory" value="'
4405: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4406: if(ref($path) eq 'ARRAY') {
4407: push(@{$path},$name);
1.49 raeburn 4408: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4409: pop(@{$path});
4410: }
4411: } else {
1.59 bisitz 4412: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4413: if ($j == $numchildren) {
4414: $text .= $name;
4415: } else {
4416: $text .= $item;
4417: }
4418: $text .= '" value="" />';
4419: }
4420: $text .= '</td></tr>';
4421: }
4422: $text .= '</table></td>';
4423: } else {
4424: my $higher = $depth-1;
4425: if ($higher == 0) {
4426: $name = &escape($parent).'::'.$higher;
4427: } else {
4428: if (ref($path) eq 'ARRAY') {
4429: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4430: }
4431: }
4432: my $colspan;
4433: if ($parent ne 'instcode') {
4434: $colspan = $maxdepth - $depth - 1;
4435: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4436: }
4437: }
4438: }
4439: }
4440: return $text;
4441: }
4442:
1.33 raeburn 4443: sub modifiable_userdata_row {
1.63 raeburn 4444: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4445: my $rolename;
1.63 raeburn 4446: if ($context eq 'selfcreate') {
4447: if (ref($usertypes) eq 'HASH') {
4448: $rolename = $usertypes->{$role};
4449: } else {
4450: $rolename = $role;
4451: }
1.33 raeburn 4452: } else {
1.63 raeburn 4453: if ($role eq 'cr') {
4454: $rolename = &mt('Custom role');
4455: } else {
4456: $rolename = &Apache::lonnet::plaintext($role);
4457: }
1.33 raeburn 4458: }
4459: my @fields = ('lastname','firstname','middlename','generation',
4460: 'permanentemail','id');
4461: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4462: my $output;
4463: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4464: $output = '<tr '.$css_class.'>'.
4465: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4466: '<td class="LC_left_item" colspan="2"><table>';
4467: my $rem;
4468: my %checks;
4469: if (ref($settings) eq 'HASH') {
4470: if (ref($settings->{$context}) eq 'HASH') {
4471: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4472: foreach my $field (@fields) {
4473: if ($settings->{$context}->{$role}->{$field}) {
4474: $checks{$field} = ' checked="checked" ';
4475: }
4476: }
4477: }
4478: }
4479: }
4480: for (my $i=0; $i<@fields; $i++) {
4481: my $rem = $i%($numinrow);
4482: if ($rem == 0) {
4483: if ($i > 0) {
4484: $output .= '</tr>';
4485: }
4486: $output .= '<tr>';
4487: }
4488: my $check = ' ';
4489: if (exists($checks{$fields[$i]})) {
4490: $check = $checks{$fields[$i]}
4491: } else {
4492: if ($role eq 'st') {
4493: if (ref($settings) ne 'HASH') {
4494: $check = ' checked="checked" ';
4495: }
4496: }
4497: }
4498: $output .= '<td class="LC_left_item">'.
4499: '<span class="LC_nobreak"><label>'.
4500: '<input type="checkbox" name="canmodify_'.$role.'" '.
4501: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4502: '</label></span></td>';
4503: $rem = @fields%($numinrow);
4504: }
4505: my $colsleft = $numinrow - $rem;
4506: if ($colsleft > 1 ) {
4507: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4508: ' </td>';
4509: } elsif ($colsleft == 1) {
4510: $output .= '<td class="LC_left_item"> </td>';
4511: }
4512: $output .= '</tr></table></td></tr>';
4513: return $output;
4514: }
1.28 raeburn 4515:
1.93 raeburn 4516: sub insttypes_row {
4517: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4518: my %lt = &Apache::lonlocal::texthash (
4519: cansearch => 'Users allowed to search',
4520: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4521: lockablenames => 'User preference to lock name',
1.93 raeburn 4522: );
4523: my $showdom;
4524: if ($context eq 'cansearch') {
4525: $showdom = ' ('.$dom.')';
4526: }
1.165 raeburn 4527: my $class = 'LC_left_item';
4528: if ($context eq 'statustocreate') {
4529: $class = 'LC_right_item';
4530: }
1.25 raeburn 4531: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4532: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4533: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4534: my $rem;
4535: if (ref($types) eq 'ARRAY') {
4536: for (my $i=0; $i<@{$types}; $i++) {
4537: if (defined($usertypes->{$types->[$i]})) {
4538: my $rem = $i%($numinrow);
4539: if ($rem == 0) {
4540: if ($i > 0) {
4541: $output .= '</tr>';
4542: }
4543: $output .= '<tr>';
1.23 raeburn 4544: }
1.26 raeburn 4545: my $check = ' ';
1.99 raeburn 4546: if (ref($settings) eq 'HASH') {
4547: if (ref($settings->{$context}) eq 'ARRAY') {
4548: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4549: $check = ' checked="checked" ';
4550: }
4551: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4552: $check = ' checked="checked" ';
4553: }
1.23 raeburn 4554: }
1.26 raeburn 4555: $output .= '<td class="LC_left_item">'.
4556: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4557: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4558: 'value="'.$types->[$i].'"'.$check.'/>'.
4559: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4560: }
4561: }
1.26 raeburn 4562: $rem = @{$types}%($numinrow);
1.23 raeburn 4563: }
4564: my $colsleft = $numinrow - $rem;
1.131 raeburn 4565: if (($rem == 0) && (@{$types} > 0)) {
4566: $output .= '<tr>';
4567: }
1.23 raeburn 4568: if ($colsleft > 1) {
1.25 raeburn 4569: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4570: } else {
1.25 raeburn 4571: $output .= '<td class="LC_left_item">';
1.23 raeburn 4572: }
4573: my $defcheck = ' ';
1.99 raeburn 4574: if (ref($settings) eq 'HASH') {
4575: if (ref($settings->{$context}) eq 'ARRAY') {
4576: if (grep(/^default$/,@{$settings->{$context}})) {
4577: $defcheck = ' checked="checked" ';
4578: }
4579: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4580: $defcheck = ' checked="checked" ';
4581: }
1.23 raeburn 4582: }
1.25 raeburn 4583: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4584: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4585: 'value="default"'.$defcheck.'/>'.
4586: $othertitle.'</label></span></td>'.
4587: '</tr></table></td></tr>';
4588: return $output;
1.23 raeburn 4589: }
4590:
4591: sub sorted_searchtitles {
4592: my %searchtitles = &Apache::lonlocal::texthash(
4593: 'uname' => 'username',
4594: 'lastname' => 'last name',
4595: 'lastfirst' => 'last name, first name',
4596: );
4597: my @titleorder = ('uname','lastname','lastfirst');
4598: return (\%searchtitles,\@titleorder);
4599: }
4600:
1.25 raeburn 4601: sub sorted_searchtypes {
4602: my %srchtypes_desc = (
4603: exact => 'is exact match',
4604: contains => 'contains ..',
4605: begins => 'begins with ..',
4606: );
4607: my @srchtypeorder = ('exact','begins','contains');
4608: return (\%srchtypes_desc,\@srchtypeorder);
4609: }
4610:
1.3 raeburn 4611: sub usertype_update_row {
4612: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4613: my $datatable;
4614: my $numinrow = 4;
4615: foreach my $type (@{$types}) {
4616: if (defined($usertypes->{$type})) {
4617: $$rownums ++;
4618: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4619: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4620: '</td><td class="LC_left_item"><table>';
4621: for (my $i=0; $i<@{$fields}; $i++) {
4622: my $rem = $i%($numinrow);
4623: if ($rem == 0) {
4624: if ($i > 0) {
4625: $datatable .= '</tr>';
4626: }
4627: $datatable .= '<tr>';
4628: }
4629: my $check = ' ';
1.39 raeburn 4630: if (ref($settings) eq 'HASH') {
4631: if (ref($settings->{'fields'}) eq 'HASH') {
4632: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4633: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4634: $check = ' checked="checked" ';
4635: }
1.3 raeburn 4636: }
4637: }
4638: }
4639:
4640: if ($i == @{$fields}-1) {
4641: my $colsleft = $numinrow - $rem;
4642: if ($colsleft > 1) {
4643: $datatable .= '<td colspan="'.$colsleft.'">';
4644: } else {
4645: $datatable .= '<td>';
4646: }
4647: } else {
4648: $datatable .= '<td>';
4649: }
1.8 raeburn 4650: $datatable .= '<span class="LC_nobreak"><label>'.
4651: '<input type="checkbox" name="updateable_'.$type.
4652: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4653: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4654: }
4655: $datatable .= '</tr></table></td></tr>';
4656: }
4657: }
4658: return $datatable;
1.1 raeburn 4659: }
4660:
4661: sub modify_login {
1.9 raeburn 4662: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4663: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4664: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4665: %title = ( coursecatalog => 'Display course catalog',
4666: adminmail => 'Display administrator E-mail address',
4667: newuser => 'Link for visitors to create a user account',
4668: loginheader => 'Log-in box header');
4669: @offon = ('off','on');
1.112 raeburn 4670: if (ref($domconfig{login}) eq 'HASH') {
4671: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4672: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4673: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4674: }
4675: }
4676: }
1.9 raeburn 4677: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4678: \%domconfig,\%loginhash);
1.118 jms 4679: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4680: foreach my $item (@toggles) {
4681: $loginhash{login}{$item} = $env{'form.'.$item};
4682: }
1.41 raeburn 4683: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4684: if (ref($colchanges{'login'}) eq 'HASH') {
4685: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4686: \%loginhash);
4687: }
1.110 raeburn 4688:
1.149 raeburn 4689: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4690: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4691: if (keys(%servers) > 1) {
4692: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4693: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4694: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4695: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4696: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4697: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4698: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4699: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4700: $changes{'loginvia'}{$lonhost} = 1;
4701: } else {
4702: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4703: $changes{'loginvia'}{$lonhost} = 1;
4704: }
4705: } else {
4706: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4707: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4708: $changes{'loginvia'}{$lonhost} = 1;
4709: }
4710: }
4711: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4712: foreach my $item (@loginvia_attribs) {
4713: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4714: }
4715: } else {
4716: foreach my $item (@loginvia_attribs) {
4717: my $new = $env{'form.'.$lonhost.'_'.$item};
4718: if (($item eq 'serverpath') && ($new eq 'custom')) {
4719: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4720: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4721: $new = '/';
4722: }
4723: }
4724: if (($item eq 'custompath') &&
4725: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4726: $new = '';
4727: }
4728: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4729: $changes{'loginvia'}{$lonhost} = 1;
4730: }
4731: if ($item eq 'exempt') {
4732: $new =~ s/^\s+//;
4733: $new =~ s/\s+$//;
4734: my @poss_ips = split(/\s*[,:]\s*/,$new);
4735: my @okips;
4736: foreach my $ip (@poss_ips) {
4737: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4738: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4739: push(@okips,$ip);
4740: }
4741: }
4742: }
4743: if (@okips > 0) {
4744: $new = join(',',@okips);
4745: } else {
4746: $new = '';
4747: }
4748: }
4749: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4750: }
4751: }
1.112 raeburn 4752: } else {
1.128 raeburn 4753: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4754: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4755: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4756: foreach my $item (@loginvia_attribs) {
4757: my $new = $env{'form.'.$lonhost.'_'.$item};
4758: if (($item eq 'serverpath') && ($new eq 'custom')) {
4759: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4760: $new = '/';
4761: }
4762: }
4763: if (($item eq 'custompath') &&
4764: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4765: $new = '';
4766: }
4767: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4768: }
1.110 raeburn 4769: }
4770: }
4771: }
4772: }
1.119 raeburn 4773:
1.168 raeburn 4774: my $servadm = $r->dir_config('lonAdmEMail');
4775: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4776: if (ref($domconfig{'login'}) eq 'HASH') {
4777: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4778: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4779: if ($lang eq 'nolang') {
4780: push(@currlangs,$lang);
4781: } elsif (defined($langchoices{$lang})) {
4782: push(@currlangs,$lang);
4783: } else {
4784: next;
4785: }
4786: }
4787: }
4788: }
4789: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4790: if (@currlangs > 0) {
4791: foreach my $lang (@currlangs) {
4792: if (grep(/^\Q$lang\E$/,@delurls)) {
4793: $changes{'helpurl'}{$lang} = 1;
4794: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4795: $changes{'helpurl'}{$lang} = 1;
4796: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4797: push(@newlangs,$lang);
4798: } else {
4799: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4800: }
4801: }
4802: }
4803: unless (grep(/^nolang$/,@currlangs)) {
4804: if ($env{'form.loginhelpurl_nolang.filename'}) {
4805: $changes{'helpurl'}{'nolang'} = 1;
4806: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4807: push(@newlangs,'nolang');
4808: }
4809: }
4810: if ($env{'form.loginhelpurl_add_lang'}) {
4811: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4812: ($env{'form.loginhelpurl_add_file.filename'})) {
4813: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4814: $addedfile = $env{'form.loginhelpurl_add_lang'};
4815: }
4816: }
4817: if ((@newlangs > 0) || ($addedfile)) {
4818: my $error;
4819: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4820: if ($configuserok eq 'ok') {
4821: if ($switchserver) {
4822: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4823: } elsif ($author_ok eq 'ok') {
4824: my @allnew = @newlangs;
4825: if ($addedfile ne '') {
4826: push(@allnew,$addedfile);
4827: }
4828: foreach my $lang (@allnew) {
4829: my $formelem = 'loginhelpurl_'.$lang;
4830: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4831: $formelem = 'loginhelpurl_add_file';
4832: }
4833: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4834: "help/$lang",'','',$newfile{$lang});
4835: if ($result eq 'ok') {
4836: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4837: $changes{'helpurl'}{$lang} = 1;
4838: } else {
4839: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4840: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4841: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4842: (!grep(/^\Q$lang\E$/,@delurls))) {
4843:
4844: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4845: }
4846: }
4847: }
4848: } else {
4849: $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
4850: }
4851: } else {
4852: $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
4853: }
4854: if ($error) {
4855: &Apache::lonnet::logthis($error);
4856: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4857: }
4858: }
1.169 raeburn 4859: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4860:
4861: my $defaulthelpfile = '/adm/loginproblems.html';
4862: my $defaulttext = &mt('Default in use');
4863:
1.1 raeburn 4864: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4865: $dom);
4866: if ($putresult eq 'ok') {
1.118 jms 4867: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4868: my %defaultchecked = (
4869: 'coursecatalog' => 'on',
4870: 'adminmail' => 'off',
1.43 raeburn 4871: 'newuser' => 'off',
1.42 raeburn 4872: );
1.55 raeburn 4873: if (ref($domconfig{'login'}) eq 'HASH') {
4874: foreach my $item (@toggles) {
4875: if ($defaultchecked{$item} eq 'on') {
4876: if (($domconfig{'login'}{$item} eq '0') &&
4877: ($env{'form.'.$item} eq '1')) {
4878: $changes{$item} = 1;
4879: } elsif (($domconfig{'login'}{$item} eq '' ||
4880: $domconfig{'login'}{$item} eq '1') &&
4881: ($env{'form.'.$item} eq '0')) {
4882: $changes{$item} = 1;
4883: }
4884: } elsif ($defaultchecked{$item} eq 'off') {
4885: if (($domconfig{'login'}{$item} eq '1') &&
4886: ($env{'form.'.$item} eq '0')) {
4887: $changes{$item} = 1;
4888: } elsif (($domconfig{'login'}{$item} eq '' ||
4889: $domconfig{'login'}{$item} eq '0') &&
4890: ($env{'form.'.$item} eq '1')) {
4891: $changes{$item} = 1;
4892: }
1.42 raeburn 4893: }
4894: }
1.41 raeburn 4895: }
1.6 raeburn 4896: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4897: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4898: $resulttext = &mt('Changes made:').'<ul>';
4899: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4900: if ($item eq 'loginvia') {
1.112 raeburn 4901: if (ref($changes{$item}) eq 'HASH') {
4902: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4903: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4904: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4905: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4906: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4907: $protocol = 'http' if ($protocol ne 'https');
4908: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4909:
4910: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4911: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4912: } else {
4913: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4914: }
4915: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4916: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4917: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4918: }
4919: $resulttext .= '</li>';
4920: } else {
4921: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4922: }
1.112 raeburn 4923: } else {
1.128 raeburn 4924: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4925: }
4926: }
1.128 raeburn 4927: $resulttext .= '</ul></li>';
1.112 raeburn 4928: }
1.168 raeburn 4929: } elsif ($item eq 'helpurl') {
4930: if (ref($changes{$item}) eq 'HASH') {
4931: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4932: if (grep(/^\Q$lang\E$/,@delurls)) {
4933: my ($chg,$link);
4934: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4935: if ($lang eq 'nolang') {
4936: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4937: } else {
4938: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4939: }
4940: $resulttext .= '<li>'.$chg.'</li>';
4941: } else {
4942: my $chg;
4943: if ($lang eq 'nolang') {
4944: $chg = &mt('custom log-in help file for no preferred language');
4945: } else {
4946: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4947: }
4948: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4949: $loginhash{'login'}{'helpurl'}{$lang}.
4950: '?inhibitmenu=yes',$chg,600,500).
4951: '</li>';
4952: }
4953: }
4954: }
1.169 raeburn 4955: } elsif ($item eq 'captcha') {
4956: if (ref($loginhash{'login'}) eq 'HASH') {
4957: my $chgtxt;
4958: if ($loginhash{'login'}{$item} eq 'notused') {
4959: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4960: } else {
4961: my %captchas = &captcha_phrases();
4962: if ($captchas{$loginhash{'login'}{$item}}) {
4963: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4964: } else {
4965: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4966: }
4967: }
4968: $resulttext .= '<li>'.$chgtxt.'</li>';
4969: }
4970: } elsif ($item eq 'recaptchakeys') {
4971: if (ref($loginhash{'login'}) eq 'HASH') {
4972: my ($privkey,$pubkey);
4973: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4974: $pubkey = $loginhash{'login'}{$item}{'public'};
4975: $privkey = $loginhash{'login'}{$item}{'private'};
4976: }
4977: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4978: if (!$pubkey) {
4979: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4980: } else {
4981: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4982: }
4983: if (!$privkey) {
4984: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4985: } else {
4986: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4987: }
4988: $chgtxt .= '</ul>';
4989: $resulttext .= '<li>'.$chgtxt.'</li>';
4990: }
1.41 raeburn 4991: } else {
4992: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4993: }
1.1 raeburn 4994: }
1.6 raeburn 4995: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4996: } else {
4997: $resulttext = &mt('No changes made to log-in page settings');
4998: }
4999: } else {
1.11 albertel 5000: $resulttext = '<span class="LC_error">'.
5001: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5002: }
1.6 raeburn 5003: if ($errors) {
1.9 raeburn 5004: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5005: $errors.'</ul>';
5006: }
5007: return $resulttext;
5008: }
5009:
5010: sub color_font_choices {
5011: my %choices =
5012: &Apache::lonlocal::texthash (
5013: img => "Header",
5014: bgs => "Background colors",
5015: links => "Link colors",
1.55 raeburn 5016: images => "Images",
1.6 raeburn 5017: font => "Font color",
1.97 tempelho 5018: fontmenu => "Font Menu",
1.76 raeburn 5019: pgbg => "Page",
1.6 raeburn 5020: tabbg => "Header",
5021: sidebg => "Border",
5022: link => "Link",
5023: alink => "Active link",
5024: vlink => "Visited link",
5025: );
5026: return %choices;
5027: }
5028:
5029: sub modify_rolecolors {
1.9 raeburn 5030: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5031: my ($resulttext,%rolehash);
5032: $rolehash{'rolecolors'} = {};
1.55 raeburn 5033: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5034: if ($domconfig{'rolecolors'} eq '') {
5035: $domconfig{'rolecolors'} = {};
5036: }
5037: }
1.9 raeburn 5038: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5039: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5040: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5041: $dom);
5042: if ($putresult eq 'ok') {
5043: if (keys(%changes) > 0) {
1.41 raeburn 5044: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5045: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5046: $rolehash{'rolecolors'});
5047: } else {
5048: $resulttext = &mt('No changes made to default color schemes');
5049: }
5050: } else {
1.11 albertel 5051: $resulttext = '<span class="LC_error">'.
5052: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5053: }
5054: if ($errors) {
5055: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5056: $errors.'</ul>';
5057: }
5058: return $resulttext;
5059: }
5060:
5061: sub modify_colors {
1.9 raeburn 5062: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5063: my (%changes,%choices);
1.51 raeburn 5064: my @bgs;
1.6 raeburn 5065: my @links = ('link','alink','vlink');
1.41 raeburn 5066: my @logintext;
1.6 raeburn 5067: my @images;
5068: my $servadm = $r->dir_config('lonAdmEMail');
5069: my $errors;
5070: foreach my $role (@{$roles}) {
5071: if ($role eq 'login') {
1.12 raeburn 5072: %choices = &login_choices();
1.41 raeburn 5073: @logintext = ('textcol','bgcol');
1.12 raeburn 5074: } else {
5075: %choices = &color_font_choices();
1.107 raeburn 5076: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5077: }
5078: if ($role eq 'login') {
1.41 raeburn 5079: @images = ('img','logo','domlogo','login');
1.51 raeburn 5080: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5081: } else {
5082: @images = ('img');
1.51 raeburn 5083: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5084: }
5085: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5086: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5087: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5088: }
1.46 raeburn 5089: my ($configuserok,$author_ok,$switchserver) =
5090: &config_check($dom,$confname,$servadm);
1.9 raeburn 5091: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5092: if (ref($domconfig->{$role}) ne 'HASH') {
5093: $domconfig->{$role} = {};
5094: }
1.8 raeburn 5095: foreach my $img (@images) {
1.70 raeburn 5096: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5097: if (defined($env{'form.login_showlogo_'.$img})) {
5098: $confhash->{$role}{'showlogo'}{$img} = 1;
5099: } else {
5100: $confhash->{$role}{'showlogo'}{$img} = 0;
5101: }
5102: }
1.18 albertel 5103: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5104: && !defined($domconfig->{$role}{$img})
5105: && !$env{'form.'.$role.'_del_'.$img}
5106: && $env{'form.'.$role.'_import_'.$img}) {
5107: # import the old configured image from the .tab setting
5108: # if they haven't provided a new one
5109: $domconfig->{$role}{$img} =
5110: $env{'form.'.$role.'_import_'.$img};
5111: }
1.6 raeburn 5112: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5113: my $error;
1.6 raeburn 5114: if ($configuserok eq 'ok') {
1.9 raeburn 5115: if ($switchserver) {
1.12 raeburn 5116: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5117: } else {
5118: if ($author_ok eq 'ok') {
5119: my ($result,$logourl) =
5120: &publishlogo($r,'upload',$role.'_'.$img,
5121: $dom,$confname,$img,$width,$height);
5122: if ($result eq 'ok') {
5123: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5124: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5125: } else {
1.12 raeburn 5126: $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 5127: }
5128: } else {
1.46 raeburn 5129: $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 5130: }
5131: }
5132: } else {
1.46 raeburn 5133: $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 5134: }
5135: if ($error) {
1.8 raeburn 5136: &Apache::lonnet::logthis($error);
1.11 albertel 5137: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5138: }
5139: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5140: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5141: my $error;
5142: if ($configuserok eq 'ok') {
5143: # is confname an author?
5144: if ($switchserver eq '') {
5145: if ($author_ok eq 'ok') {
5146: my ($result,$logourl) =
5147: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5148: $dom,$confname,$img,$width,$height);
5149: if ($result eq 'ok') {
5150: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5151: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5152: }
5153: }
5154: }
5155: }
1.6 raeburn 5156: }
5157: }
5158: }
5159: if (ref($domconfig) eq 'HASH') {
5160: if (ref($domconfig->{$role}) eq 'HASH') {
5161: foreach my $img (@images) {
5162: if ($domconfig->{$role}{$img} ne '') {
5163: if ($env{'form.'.$role.'_del_'.$img}) {
5164: $confhash->{$role}{$img} = '';
1.12 raeburn 5165: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5166: } else {
1.9 raeburn 5167: if ($confhash->{$role}{$img} eq '') {
5168: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5169: }
1.6 raeburn 5170: }
5171: } else {
5172: if ($env{'form.'.$role.'_del_'.$img}) {
5173: $confhash->{$role}{$img} = '';
1.12 raeburn 5174: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5175: }
5176: }
1.70 raeburn 5177: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5178: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5179: if ($confhash->{$role}{'showlogo'}{$img} ne
5180: $domconfig->{$role}{'showlogo'}{$img}) {
5181: $changes{$role}{'showlogo'}{$img} = 1;
5182: }
5183: } else {
5184: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5185: $changes{$role}{'showlogo'}{$img} = 1;
5186: }
5187: }
5188: }
5189: }
1.6 raeburn 5190: if ($domconfig->{$role}{'font'} ne '') {
5191: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5192: $changes{$role}{'font'} = 1;
5193: }
5194: } else {
5195: if ($confhash->{$role}{'font'}) {
5196: $changes{$role}{'font'} = 1;
5197: }
5198: }
1.107 raeburn 5199: if ($role ne 'login') {
5200: if ($domconfig->{$role}{'fontmenu'} ne '') {
5201: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5202: $changes{$role}{'fontmenu'} = 1;
5203: }
5204: } else {
5205: if ($confhash->{$role}{'fontmenu'}) {
5206: $changes{$role}{'fontmenu'} = 1;
5207: }
1.97 tempelho 5208: }
5209: }
1.6 raeburn 5210: foreach my $item (@bgs) {
5211: if ($domconfig->{$role}{$item} ne '') {
5212: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5213: $changes{$role}{'bgs'}{$item} = 1;
5214: }
5215: } else {
5216: if ($confhash->{$role}{$item}) {
5217: $changes{$role}{'bgs'}{$item} = 1;
5218: }
5219: }
5220: }
5221: foreach my $item (@links) {
5222: if ($domconfig->{$role}{$item} ne '') {
5223: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5224: $changes{$role}{'links'}{$item} = 1;
5225: }
5226: } else {
5227: if ($confhash->{$role}{$item}) {
5228: $changes{$role}{'links'}{$item} = 1;
5229: }
5230: }
5231: }
1.41 raeburn 5232: foreach my $item (@logintext) {
5233: if ($domconfig->{$role}{$item} ne '') {
5234: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5235: $changes{$role}{'logintext'}{$item} = 1;
5236: }
5237: } else {
5238: if ($confhash->{$role}{$item}) {
5239: $changes{$role}{'logintext'}{$item} = 1;
5240: }
5241: }
5242: }
1.6 raeburn 5243: } else {
5244: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5245: \@logintext,$confhash,\%changes);
1.6 raeburn 5246: }
5247: } else {
5248: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5249: \@logintext,$confhash,\%changes);
1.6 raeburn 5250: }
5251: }
5252: return ($errors,%changes);
5253: }
5254:
1.46 raeburn 5255: sub config_check {
5256: my ($dom,$confname,$servadm) = @_;
5257: my ($configuserok,$author_ok,$switchserver,%currroles);
5258: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5259: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5260: $confname,$servadm);
5261: if ($configuserok eq 'ok') {
5262: $switchserver = &check_switchserver($dom,$confname);
5263: if ($switchserver eq '') {
5264: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5265: }
5266: }
5267: return ($configuserok,$author_ok,$switchserver);
5268: }
5269:
1.6 raeburn 5270: sub default_change_checker {
1.41 raeburn 5271: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5272: foreach my $item (@{$links}) {
5273: if ($confhash->{$role}{$item}) {
5274: $changes->{$role}{'links'}{$item} = 1;
5275: }
5276: }
5277: foreach my $item (@{$bgs}) {
5278: if ($confhash->{$role}{$item}) {
5279: $changes->{$role}{'bgs'}{$item} = 1;
5280: }
5281: }
1.41 raeburn 5282: foreach my $item (@{$logintext}) {
5283: if ($confhash->{$role}{$item}) {
5284: $changes->{$role}{'logintext'}{$item} = 1;
5285: }
5286: }
1.6 raeburn 5287: foreach my $img (@{$images}) {
5288: if ($env{'form.'.$role.'_del_'.$img}) {
5289: $confhash->{$role}{$img} = '';
1.12 raeburn 5290: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5291: }
1.70 raeburn 5292: if ($role eq 'login') {
5293: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5294: $changes->{$role}{'showlogo'}{$img} = 1;
5295: }
5296: }
1.6 raeburn 5297: }
5298: if ($confhash->{$role}{'font'}) {
5299: $changes->{$role}{'font'} = 1;
5300: }
1.48 raeburn 5301: }
1.6 raeburn 5302:
5303: sub display_colorchgs {
5304: my ($dom,$changes,$roles,$confhash) = @_;
5305: my (%choices,$resulttext);
5306: if (!grep(/^login$/,@{$roles})) {
5307: $resulttext = &mt('Changes made:').'<br />';
5308: }
5309: foreach my $role (@{$roles}) {
5310: if ($role eq 'login') {
5311: %choices = &login_choices();
5312: } else {
5313: %choices = &color_font_choices();
5314: }
5315: if (ref($changes->{$role}) eq 'HASH') {
5316: if ($role ne 'login') {
5317: $resulttext .= '<h4>'.&mt($role).'</h4>';
5318: }
5319: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5320: if ($role ne 'login') {
5321: $resulttext .= '<ul>';
5322: }
5323: if (ref($changes->{$role}{$key}) eq 'HASH') {
5324: if ($role ne 'login') {
5325: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5326: }
5327: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5328: if (($role eq 'login') && ($key eq 'showlogo')) {
5329: if ($confhash->{$role}{$key}{$item}) {
5330: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5331: } else {
5332: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5333: }
5334: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5335: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5336: } else {
1.12 raeburn 5337: my $newitem = $confhash->{$role}{$item};
5338: if ($key eq 'images') {
5339: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5340: }
5341: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5342: }
5343: }
5344: if ($role ne 'login') {
5345: $resulttext .= '</ul></li>';
5346: }
5347: } else {
5348: if ($confhash->{$role}{$key} eq '') {
5349: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5350: } else {
5351: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5352: }
5353: }
5354: if ($role ne 'login') {
5355: $resulttext .= '</ul>';
5356: }
5357: }
5358: }
5359: }
1.3 raeburn 5360: return $resulttext;
1.1 raeburn 5361: }
5362:
1.9 raeburn 5363: sub thumb_dimensions {
5364: return ('200','50');
5365: }
5366:
1.16 raeburn 5367: sub check_dimensions {
5368: my ($inputfile) = @_;
5369: my ($fullwidth,$fullheight);
5370: if ($inputfile =~ m|^[/\w.\-]+$|) {
5371: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5372: my $imageinfo = <PIPE>;
5373: if (!close(PIPE)) {
5374: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5375: }
5376: chomp($imageinfo);
5377: my ($fullsize) =
1.21 raeburn 5378: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5379: if ($fullsize) {
5380: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5381: }
5382: }
5383: }
5384: return ($fullwidth,$fullheight);
5385: }
5386:
1.9 raeburn 5387: sub check_configuser {
5388: my ($uhome,$dom,$confname,$servadm) = @_;
5389: my ($configuserok,%currroles);
5390: if ($uhome eq 'no_host') {
5391: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5392: my $configpass = &LONCAPA::Enrollment::create_password();
5393: $configuserok =
5394: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5395: $configpass,'','','','','',undef,$servadm);
5396: } else {
5397: $configuserok = 'ok';
5398: %currroles =
5399: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5400: }
5401: return ($configuserok,%currroles);
5402: }
5403:
5404: sub check_authorstatus {
5405: my ($dom,$confname,%currroles) = @_;
5406: my $author_ok;
1.40 raeburn 5407: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5408: my $start = time;
5409: my $end = 0;
5410: $author_ok =
5411: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5412: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5413: } else {
5414: $author_ok = 'ok';
5415: }
5416: return $author_ok;
5417: }
5418:
5419: sub publishlogo {
1.46 raeburn 5420: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5421: my ($output,$fname,$logourl);
5422: if ($action eq 'upload') {
5423: $fname=$env{'form.'.$formname.'.filename'};
5424: chop($env{'form.'.$formname});
5425: } else {
5426: ($fname) = ($formname =~ /([^\/]+)$/);
5427: }
1.46 raeburn 5428: if ($savefileas ne '') {
5429: $fname = $savefileas;
5430: }
1.9 raeburn 5431: $fname=&Apache::lonnet::clean_filename($fname);
5432: # See if there is anything left
5433: unless ($fname) { return ('error: no uploaded file'); }
5434: $fname="$subdir/$fname";
1.164 raeburn 5435: my $docroot=$r->dir_config('lonDocRoot');
5436: my $filepath="$docroot/priv";
5437: my $relpath = "$dom/$confname";
1.9 raeburn 5438: my ($fnamepath,$file,$fetchthumb);
5439: $file=$fname;
5440: if ($fname=~m|/|) {
5441: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5442: }
1.164 raeburn 5443: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5444: my $count;
1.164 raeburn 5445: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5446: $filepath.="/$parts[$count]";
5447: if ((-e $filepath)!=1) {
5448: mkdir($filepath,02770);
5449: }
5450: }
5451: # Check for bad extension and disallow upload
5452: if ($file=~/\.(\w+)$/ &&
5453: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5454: $output =
5455: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5456: } elsif ($file=~/\.(\w+)$/ &&
5457: !defined(&Apache::loncommon::fileembstyle($1))) {
5458: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5459: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5460: $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 5461: } elsif (-d "$filepath/$file") {
5462: $output = &mt('File name is a directory name - rename the file and re-upload');
5463: } else {
5464: my $source = $filepath.'/'.$file;
5465: my $logfile;
5466: if (!open($logfile,">>$source".'.log')) {
5467: return (&mt('No write permission to Construction Space'));
5468: }
5469: print $logfile
5470: "\n================= Publish ".localtime()." ================\n".
5471: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5472: # Save the file
5473: if (!open(FH,'>'.$source)) {
5474: &Apache::lonnet::logthis('Failed to create '.$source);
5475: return (&mt('Failed to create file'));
5476: }
5477: if ($action eq 'upload') {
5478: if (!print FH ($env{'form.'.$formname})) {
5479: &Apache::lonnet::logthis('Failed to write to '.$source);
5480: return (&mt('Failed to write file'));
5481: }
5482: } else {
5483: my $original = &Apache::lonnet::filelocation('',$formname);
5484: if(!copy($original,$source)) {
5485: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5486: return (&mt('Failed to write file'));
5487: }
5488: }
5489: close(FH);
5490: chmod(0660, $source); # Permissions to rw-rw---.
5491:
5492: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5493: my $copyfile=$targetdir.'/'.$file;
5494:
5495: my @parts=split(/\//,$targetdir);
5496: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5497: for (my $count=5;$count<=$#parts;$count++) {
5498: $path.="/$parts[$count]";
5499: if (!-e $path) {
5500: print $logfile "\nCreating directory ".$path;
5501: mkdir($path,02770);
5502: }
5503: }
5504: my $versionresult;
5505: if (-e $copyfile) {
5506: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5507: } else {
5508: $versionresult = 'ok';
5509: }
5510: if ($versionresult eq 'ok') {
5511: if (copy($source,$copyfile)) {
5512: print $logfile "\nCopied original source to ".$copyfile."\n";
5513: $output = 'ok';
5514: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5515: push(@{$modified_urls},[$copyfile,$source]);
5516: my $metaoutput =
5517: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5518: unless ($registered_cleanup) {
5519: my $handlers = $r->get_handlers('PerlCleanupHandler');
5520: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5521: $registered_cleanup=1;
5522: }
1.9 raeburn 5523: } else {
5524: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5525: $output = &mt('Failed to copy file to RES space').", $!";
5526: }
5527: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5528: my $inputfile = $filepath.'/'.$file;
5529: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5530: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5531: if ($fullwidth ne '' && $fullheight ne '') {
5532: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5533: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5534: system("convert -sample $thumbsize $inputfile $outfile");
5535: chmod(0660, $filepath.'/tn-'.$file);
5536: if (-e $outfile) {
5537: my $copyfile=$targetdir.'/tn-'.$file;
5538: if (copy($outfile,$copyfile)) {
5539: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5540: my $thumb_metaoutput =
5541: &write_metadata($dom,$confname,$formname,
5542: $targetdir,'tn-'.$file,$logfile);
5543: push(@{$modified_urls},[$copyfile,$outfile]);
5544: unless ($registered_cleanup) {
5545: my $handlers = $r->get_handlers('PerlCleanupHandler');
5546: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5547: $registered_cleanup=1;
5548: }
1.16 raeburn 5549: } else {
5550: print $logfile "\nUnable to write ".$copyfile.
5551: ':'.$!."\n";
5552: }
5553: }
1.9 raeburn 5554: }
5555: }
5556: }
5557: } else {
5558: $output = $versionresult;
5559: }
5560: }
5561: return ($output,$logourl);
5562: }
5563:
5564: sub logo_versioning {
5565: my ($targetdir,$file,$logfile) = @_;
5566: my $target = $targetdir.'/'.$file;
5567: my ($maxversion,$fn,$extn,$output);
5568: $maxversion = 0;
5569: if ($file =~ /^(.+)\.(\w+)$/) {
5570: $fn=$1;
5571: $extn=$2;
5572: }
5573: opendir(DIR,$targetdir);
5574: while (my $filename=readdir(DIR)) {
5575: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5576: $maxversion=($1>$maxversion)?$1:$maxversion;
5577: }
5578: }
5579: $maxversion++;
5580: print $logfile "\nCreating old version ".$maxversion."\n";
5581: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5582: if (copy($target,$copyfile)) {
5583: print $logfile "Copied old target to ".$copyfile."\n";
5584: $copyfile=$copyfile.'.meta';
5585: if (copy($target.'.meta',$copyfile)) {
5586: print $logfile "Copied old target metadata to ".$copyfile."\n";
5587: $output = 'ok';
5588: } else {
5589: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5590: $output = &mt('Failed to copy old meta').", $!, ";
5591: }
5592: } else {
5593: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5594: $output = &mt('Failed to copy old target').", $!, ";
5595: }
5596: return $output;
5597: }
5598:
5599: sub write_metadata {
5600: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5601: my (%metadatafields,%metadatakeys,$output);
5602: $metadatafields{'title'}=$formname;
5603: $metadatafields{'creationdate'}=time;
5604: $metadatafields{'lastrevisiondate'}=time;
5605: $metadatafields{'copyright'}='public';
5606: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5607: $env{'user.domain'};
5608: $metadatafields{'authorspace'}=$confname.':'.$dom;
5609: $metadatafields{'domain'}=$dom;
5610: {
5611: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5612: my $mfh;
1.155 raeburn 5613: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5614: foreach (sort keys %metadatafields) {
5615: unless ($_=~/\./) {
5616: my $unikey=$_;
5617: $unikey=~/^([A-Za-z]+)/;
5618: my $tag=$1;
5619: $tag=~tr/A-Z/a-z/;
5620: print $mfh "\n\<$tag";
5621: foreach (split(/\,/,$metadatakeys{$unikey})) {
5622: my $value=$metadatafields{$unikey.'.'.$_};
5623: $value=~s/\"/\'\'/g;
5624: print $mfh ' '.$_.'="'.$value.'"';
5625: }
5626: print $mfh '>'.
5627: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5628: .'</'.$tag.'>';
5629: }
5630: }
5631: $output = 'ok';
5632: print $logfile "\nWrote metadata";
5633: close($mfh);
5634: } else {
5635: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5636: $output = &mt('Could not write metadata');
5637: }
5638: }
1.155 raeburn 5639: return $output;
5640: }
5641:
5642: sub notifysubscribed {
5643: foreach my $targetsource (@{$modified_urls}){
5644: next unless (ref($targetsource) eq 'ARRAY');
5645: my ($target,$source)=@{$targetsource};
5646: if ($source ne '') {
5647: if (open(my $logfh,'>>'.$source.'.log')) {
5648: print $logfh "\nCleanup phase: Notifications\n";
5649: my @subscribed=&subscribed_hosts($target);
5650: foreach my $subhost (@subscribed) {
5651: print $logfh "\nNotifying host ".$subhost.':';
5652: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5653: print $logfh $reply;
5654: }
5655: my @subscribedmeta=&subscribed_hosts("$target.meta");
5656: foreach my $subhost (@subscribedmeta) {
5657: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5658: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5659: $subhost);
5660: print $logfh $reply;
5661: }
5662: print $logfh "\n============ Done ============\n";
1.160 raeburn 5663: close($logfh);
1.155 raeburn 5664: }
5665: }
5666: }
5667: return OK;
5668: }
5669:
5670: sub subscribed_hosts {
5671: my ($target) = @_;
5672: my @subscribed;
5673: if (open(my $fh,"<$target.subscription")) {
5674: while (my $subline=<$fh>) {
5675: if ($subline =~ /^($match_lonid):/) {
5676: my $host = $1;
5677: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5678: unless (grep(/^\Q$host\E$/,@subscribed)) {
5679: push(@subscribed,$host);
5680: }
5681: }
5682: }
5683: }
5684: }
5685: return @subscribed;
1.9 raeburn 5686: }
5687:
5688: sub check_switchserver {
5689: my ($dom,$confname) = @_;
5690: my ($allowed,$switchserver);
5691: my $home = &Apache::lonnet::homeserver($confname,$dom);
5692: if ($home eq 'no_host') {
5693: $home = &Apache::lonnet::domain($dom,'primary');
5694: }
5695: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5696: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5697: if (!$allowed) {
1.180 ! raeburn 5698: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5699: }
5700: return $switchserver;
5701: }
5702:
1.1 raeburn 5703: sub modify_quotas {
1.86 raeburn 5704: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5705: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5706: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5707: if ($action eq 'quotas') {
5708: $context = 'tools';
1.163 raeburn 5709: } else {
1.86 raeburn 5710: $context = $action;
5711: }
5712: if ($context eq 'requestcourses') {
1.98 raeburn 5713: @usertools = ('official','unofficial','community');
1.106 raeburn 5714: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5715: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5716: %titles = &courserequest_titles();
5717: $toolregexp = join('|',@usertools);
5718: %conditions = &courserequest_conditions();
1.163 raeburn 5719: } elsif ($context eq 'requestauthor') {
5720: @usertools = ('author');
5721: %titles = &authorrequest_titles();
1.86 raeburn 5722: } else {
1.162 raeburn 5723: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5724: %titles = &tool_titles();
1.86 raeburn 5725: }
1.72 raeburn 5726: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5727: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5728: foreach my $key (keys(%env)) {
1.101 raeburn 5729: if ($context eq 'requestcourses') {
5730: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5731: my $item = $1;
5732: my $type = $2;
5733: if ($type =~ /^limit_(.+)/) {
5734: $limithash{$item}{$1} = $env{$key};
5735: } else {
5736: $confhash{$item}{$type} = $env{$key};
5737: }
5738: }
1.163 raeburn 5739: } elsif ($context eq 'requestauthor') {
5740: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5741: $confhash{$1} = $env{$key};
5742: }
1.101 raeburn 5743: } else {
1.86 raeburn 5744: if ($key =~ /^form\.quota_(.+)$/) {
5745: $confhash{'defaultquota'}{$1} = $env{$key};
5746: }
1.101 raeburn 5747: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5748: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5749: }
1.72 raeburn 5750: }
5751: }
1.163 raeburn 5752: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5753: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5754: @approvalnotify = sort(@approvalnotify);
5755: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5756: if (ref($domconfig{$action}) eq 'HASH') {
5757: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5758: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5759: $changes{'notify'}{'approval'} = 1;
5760: }
5761: } else {
1.144 raeburn 5762: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5763: $changes{'notify'}{'approval'} = 1;
5764: }
5765: }
5766: } else {
1.144 raeburn 5767: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5768: $changes{'notify'}{'approval'} = 1;
5769: }
5770: }
5771: } else {
1.86 raeburn 5772: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5773: }
1.72 raeburn 5774: foreach my $item (@usertools) {
5775: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5776: my $unset;
1.101 raeburn 5777: if ($context eq 'requestcourses') {
1.104 raeburn 5778: $unset = '0';
5779: if ($type eq '_LC_adv') {
5780: $unset = '';
5781: }
1.101 raeburn 5782: if ($confhash{$item}{$type} eq 'autolimit') {
5783: $confhash{$item}{$type} .= '=';
5784: unless ($limithash{$item}{$type} =~ /\D/) {
5785: $confhash{$item}{$type} .= $limithash{$item}{$type};
5786: }
5787: }
1.163 raeburn 5788: } elsif ($context eq 'requestauthor') {
5789: $unset = '0';
5790: if ($type eq '_LC_adv') {
5791: $unset = '';
5792: }
1.72 raeburn 5793: } else {
1.101 raeburn 5794: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5795: $confhash{$item}{$type} = 1;
5796: } else {
5797: $confhash{$item}{$type} = 0;
5798: }
1.72 raeburn 5799: }
1.86 raeburn 5800: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5801: if ($action eq 'requestauthor') {
5802: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5803: $changes{$type} = 1;
5804: }
5805: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5806: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5807: $changes{$item}{$type} = 1;
5808: }
5809: } else {
5810: if ($context eq 'requestcourses') {
1.104 raeburn 5811: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5812: $changes{$item}{$type} = 1;
5813: }
5814: } else {
5815: if (!$confhash{$item}{$type}) {
5816: $changes{$item}{$type} = 1;
5817: }
5818: }
5819: }
5820: } else {
5821: if ($context eq 'requestcourses') {
1.104 raeburn 5822: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5823: $changes{$item}{$type} = 1;
5824: }
1.163 raeburn 5825: } elsif ($context eq 'requestauthor') {
5826: if ($confhash{$type} ne $unset) {
5827: $changes{$type} = 1;
5828: }
1.72 raeburn 5829: } else {
5830: if (!$confhash{$item}{$type}) {
5831: $changes{$item}{$type} = 1;
5832: }
5833: }
5834: }
1.1 raeburn 5835: }
5836: }
1.163 raeburn 5837: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5838: if (ref($domconfig{'quotas'}) eq 'HASH') {
5839: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5840: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5841: if (exists($confhash{'defaultquota'}{$key})) {
5842: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5843: $changes{'defaultquota'}{$key} = 1;
5844: }
5845: } else {
5846: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5847: }
5848: }
1.86 raeburn 5849: } else {
5850: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5851: if (exists($confhash{'defaultquota'}{$key})) {
5852: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5853: $changes{'defaultquota'}{$key} = 1;
5854: }
5855: } else {
5856: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5857: }
1.1 raeburn 5858: }
5859: }
5860: }
1.86 raeburn 5861: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5862: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5863: if (ref($domconfig{'quotas'}) eq 'HASH') {
5864: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5865: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5866: $changes{'defaultquota'}{$key} = 1;
5867: }
5868: } else {
5869: if (!exists($domconfig{'quotas'}{$key})) {
5870: $changes{'defaultquota'}{$key} = 1;
5871: }
1.72 raeburn 5872: }
5873: } else {
1.86 raeburn 5874: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5875: }
1.1 raeburn 5876: }
5877: }
5878: }
1.72 raeburn 5879:
1.163 raeburn 5880: if ($context eq 'requestauthor') {
5881: $domdefaults{'requestauthor'} = \%confhash;
5882: } else {
5883: foreach my $key (keys(%confhash)) {
5884: $domdefaults{$key} = $confhash{$key};
5885: }
1.72 raeburn 5886: }
1.163 raeburn 5887:
1.1 raeburn 5888: my %quotahash = (
1.86 raeburn 5889: $action => { %confhash }
1.1 raeburn 5890: );
5891: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5892: $dom);
5893: if ($putresult eq 'ok') {
5894: if (keys(%changes) > 0) {
1.72 raeburn 5895: my $cachetime = 24*60*60;
5896: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5897:
1.1 raeburn 5898: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5899: unless (($context eq 'requestcourses') ||
5900: ($context eq 'requestauthor')) {
1.86 raeburn 5901: if (ref($changes{'defaultquota'}) eq 'HASH') {
5902: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5903: foreach my $type (@{$types},'default') {
5904: if (defined($changes{'defaultquota'}{$type})) {
5905: my $typetitle = $usertypes->{$type};
5906: if ($type eq 'default') {
5907: $typetitle = $othertitle;
5908: }
5909: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5910: }
5911: }
1.86 raeburn 5912: $resulttext .= '</ul></li>';
1.72 raeburn 5913: }
5914: }
1.80 raeburn 5915: my %newenv;
1.72 raeburn 5916: foreach my $item (@usertools) {
1.163 raeburn 5917: my (%haschgs,%inconf);
5918: if ($context eq 'requestauthor') {
5919: %haschgs = %changes;
5920: %inconf = %confhash;
5921: } else {
5922: if (ref($changes{$item}) eq 'HASH') {
5923: %haschgs = %{$changes{$item}};
5924: }
5925: if (ref($confhash{$item}) eq 'HASH') {
5926: %inconf = %{$confhash{$item}};
5927: }
5928: }
5929: if (keys(%haschgs) > 0) {
1.80 raeburn 5930: my $newacc =
5931: &Apache::lonnet::usertools_access($env{'user.name'},
5932: $env{'user.domain'},
1.86 raeburn 5933: $item,'reload',$context);
1.163 raeburn 5934: if (($context eq 'requestcourses') ||
5935: ($context eq 'requestauthor')) {
1.108 raeburn 5936: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5937: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5938: }
5939: } else {
5940: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5941: $newenv{'environment.availabletools.'.$item} = $newacc;
5942: }
1.80 raeburn 5943: }
1.163 raeburn 5944: unless ($context eq 'requestauthor') {
5945: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5946: }
1.72 raeburn 5947: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5948: if ($haschgs{$type}) {
1.72 raeburn 5949: my $typetitle = $usertypes->{$type};
5950: if ($type eq 'default') {
5951: $typetitle = $othertitle;
5952: } elsif ($type eq '_LC_adv') {
5953: $typetitle = 'LON-CAPA Advanced Users';
5954: }
1.163 raeburn 5955: if ($inconf{$type}) {
1.101 raeburn 5956: if ($context eq 'requestcourses') {
5957: my $cond;
1.163 raeburn 5958: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5959: if ($1 eq '') {
5960: $cond = &mt('(Automatic processing of any request).');
5961: } else {
5962: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5963: }
5964: } else {
1.163 raeburn 5965: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5966: }
5967: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 5968: } elsif ($context eq 'requestauthor') {
5969: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5970: $titles{$inconf{$type}},$typetitle);
5971:
1.101 raeburn 5972: } else {
5973: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5974: }
1.72 raeburn 5975: } else {
1.104 raeburn 5976: if ($type eq '_LC_adv') {
1.163 raeburn 5977: if ($inconf{$type} eq '0') {
1.104 raeburn 5978: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5979: } else {
5980: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5981: }
5982: } else {
5983: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5984: }
1.72 raeburn 5985: }
5986: }
1.26 raeburn 5987: }
1.163 raeburn 5988: unless ($context eq 'requestauthor') {
5989: $resulttext .= '</ul></li>';
5990: }
1.26 raeburn 5991: }
1.1 raeburn 5992: }
1.163 raeburn 5993: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5994: if (ref($changes{'notify'}) eq 'HASH') {
5995: if ($changes{'notify'}{'approval'}) {
5996: if (ref($confhash{'notify'}) eq 'HASH') {
5997: if ($confhash{'notify'}{'approval'}) {
5998: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5999: } else {
1.163 raeburn 6000: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6001: }
6002: }
6003: }
6004: }
6005: }
1.1 raeburn 6006: $resulttext .= '</ul>';
1.80 raeburn 6007: if (keys(%newenv)) {
6008: &Apache::lonnet::appenv(\%newenv);
6009: }
1.1 raeburn 6010: } else {
1.86 raeburn 6011: if ($context eq 'requestcourses') {
6012: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6013: } elsif ($context eq 'requestauthor') {
6014: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6015: } else {
1.90 weissno 6016: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6017: }
1.1 raeburn 6018: }
6019: } else {
1.11 albertel 6020: $resulttext = '<span class="LC_error">'.
6021: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6022: }
1.3 raeburn 6023: return $resulttext;
1.1 raeburn 6024: }
6025:
1.3 raeburn 6026: sub modify_autoenroll {
6027: my ($dom,%domconfig) = @_;
1.1 raeburn 6028: my ($resulttext,%changes);
6029: my %currautoenroll;
6030: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6031: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6032: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6033: }
6034: }
6035: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6036: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6037: sender => 'Sender for notification messages',
6038: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6039: my @offon = ('off','on');
1.17 raeburn 6040: my $sender_uname = $env{'form.sender_uname'};
6041: my $sender_domain = $env{'form.sender_domain'};
6042: if ($sender_domain eq '') {
6043: $sender_uname = '';
6044: } elsif ($sender_uname eq '') {
6045: $sender_domain = '';
6046: }
1.129 raeburn 6047: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6048: my %autoenrollhash = (
1.129 raeburn 6049: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6050: 'sender_uname' => $sender_uname,
6051: 'sender_domain' => $sender_domain,
6052: 'co-owners' => $coowners,
1.1 raeburn 6053: }
6054: );
1.4 raeburn 6055: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6056: $dom);
1.1 raeburn 6057: if ($putresult eq 'ok') {
6058: if (exists($currautoenroll{'run'})) {
6059: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6060: $changes{'run'} = 1;
6061: }
6062: } elsif ($autorun) {
6063: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6064: $changes{'run'} = 1;
1.1 raeburn 6065: }
6066: }
1.17 raeburn 6067: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6068: $changes{'sender'} = 1;
6069: }
1.17 raeburn 6070: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6071: $changes{'sender'} = 1;
6072: }
1.129 raeburn 6073: if ($currautoenroll{'co-owners'} ne '') {
6074: if ($currautoenroll{'co-owners'} ne $coowners) {
6075: $changes{'coowners'} = 1;
6076: }
6077: } elsif ($coowners) {
6078: $changes{'coowners'} = 1;
6079: }
1.1 raeburn 6080: if (keys(%changes) > 0) {
6081: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6082: if ($changes{'run'}) {
1.1 raeburn 6083: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6084: }
6085: if ($changes{'sender'}) {
1.17 raeburn 6086: if ($sender_uname eq '' || $sender_domain eq '') {
6087: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6088: } else {
6089: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6090: }
1.1 raeburn 6091: }
1.129 raeburn 6092: if ($changes{'coowners'}) {
6093: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6094: &Apache::loncommon::devalidate_domconfig_cache($dom);
6095: }
1.1 raeburn 6096: $resulttext .= '</ul>';
6097: } else {
6098: $resulttext = &mt('No changes made to auto-enrollment settings');
6099: }
6100: } else {
1.11 albertel 6101: $resulttext = '<span class="LC_error">'.
6102: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6103: }
1.3 raeburn 6104: return $resulttext;
1.1 raeburn 6105: }
6106:
6107: sub modify_autoupdate {
1.3 raeburn 6108: my ($dom,%domconfig) = @_;
1.1 raeburn 6109: my ($resulttext,%currautoupdate,%fields,%changes);
6110: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6111: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6112: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6113: }
6114: }
6115: my @offon = ('off','on');
6116: my %title = &Apache::lonlocal::texthash (
6117: run => 'Auto-update:',
6118: classlists => 'Updates to user information in classlists?'
6119: );
1.44 raeburn 6120: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6121: my %fieldtitles = &Apache::lonlocal::texthash (
6122: id => 'Student/Employee ID',
1.20 raeburn 6123: permanentemail => 'E-mail address',
1.1 raeburn 6124: lastname => 'Last Name',
6125: firstname => 'First Name',
6126: middlename => 'Middle Name',
1.132 raeburn 6127: generation => 'Generation',
1.1 raeburn 6128: );
1.142 raeburn 6129: $othertitle = &mt('All users');
1.1 raeburn 6130: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6131: $othertitle = &mt('Other users');
1.1 raeburn 6132: }
6133: foreach my $key (keys(%env)) {
6134: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6135: my ($usertype,$item) = ($1,$2);
6136: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6137: if ($usertype eq 'default') {
6138: push(@{$fields{$1}},$2);
6139: } elsif (ref($types) eq 'ARRAY') {
6140: if (grep(/^\Q$usertype\E$/,@{$types})) {
6141: push(@{$fields{$1}},$2);
6142: }
6143: }
6144: }
1.1 raeburn 6145: }
6146: }
1.131 raeburn 6147: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6148: @lockablenames = sort(@lockablenames);
6149: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6150: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6151: if (@changed) {
6152: $changes{'lockablenames'} = 1;
6153: }
6154: } else {
6155: if (@lockablenames) {
6156: $changes{'lockablenames'} = 1;
6157: }
6158: }
1.1 raeburn 6159: my %updatehash = (
6160: autoupdate => { run => $env{'form.autoupdate_run'},
6161: classlists => $env{'form.classlists'},
6162: fields => {%fields},
1.131 raeburn 6163: lockablenames => \@lockablenames,
1.1 raeburn 6164: }
6165: );
6166: foreach my $key (keys(%currautoupdate)) {
6167: if (($key eq 'run') || ($key eq 'classlists')) {
6168: if (exists($updatehash{autoupdate}{$key})) {
6169: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6170: $changes{$key} = 1;
6171: }
6172: }
6173: } elsif ($key eq 'fields') {
6174: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6175: foreach my $item (@{$types},'default') {
1.1 raeburn 6176: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6177: my $change = 0;
6178: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6179: if (!exists($fields{$item})) {
6180: $change = 1;
1.132 raeburn 6181: last;
1.1 raeburn 6182: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6183: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6184: $change = 1;
1.132 raeburn 6185: last;
1.1 raeburn 6186: }
6187: }
6188: }
6189: if ($change) {
6190: push(@{$changes{$key}},$item);
6191: }
1.26 raeburn 6192: }
1.1 raeburn 6193: }
6194: }
1.131 raeburn 6195: } elsif ($key eq 'lockablenames') {
6196: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6197: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6198: if (@changed) {
6199: $changes{'lockablenames'} = 1;
6200: }
6201: } else {
6202: if (@lockablenames) {
6203: $changes{'lockablenames'} = 1;
6204: }
6205: }
6206: }
6207: }
6208: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6209: if (@lockablenames) {
6210: $changes{'lockablenames'} = 1;
1.1 raeburn 6211: }
6212: }
1.26 raeburn 6213: foreach my $item (@{$types},'default') {
6214: if (defined($fields{$item})) {
6215: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6216: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6217: my $change = 0;
6218: if (ref($fields{$item}) eq 'ARRAY') {
6219: foreach my $type (@{$fields{$item}}) {
6220: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6221: $change = 1;
6222: last;
6223: }
6224: }
6225: }
6226: if ($change) {
6227: push(@{$changes{'fields'}},$item);
6228: }
6229: } else {
1.26 raeburn 6230: push(@{$changes{'fields'}},$item);
6231: }
6232: } else {
6233: push(@{$changes{'fields'}},$item);
1.1 raeburn 6234: }
6235: }
6236: }
6237: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6238: $dom);
6239: if ($putresult eq 'ok') {
6240: if (keys(%changes) > 0) {
6241: $resulttext = &mt('Changes made:').'<ul>';
6242: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6243: if ($key eq 'lockablenames') {
6244: $resulttext .= '<li>';
6245: if (@lockablenames) {
6246: $usertypes->{'default'} = $othertitle;
6247: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6248: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6249: } else {
6250: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6251: }
6252: $resulttext .= '</li>';
6253: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6254: foreach my $item (@{$changes{$key}}) {
6255: my @newvalues;
6256: foreach my $type (@{$fields{$item}}) {
6257: push(@newvalues,$fieldtitles{$type});
6258: }
1.3 raeburn 6259: my $newvaluestr;
6260: if (@newvalues > 0) {
6261: $newvaluestr = join(', ',@newvalues);
6262: } else {
6263: $newvaluestr = &mt('none');
1.6 raeburn 6264: }
1.1 raeburn 6265: if ($item eq 'default') {
1.26 raeburn 6266: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6267: } else {
1.26 raeburn 6268: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6269: }
6270: }
6271: } else {
6272: my $newvalue;
6273: if ($key eq 'run') {
6274: $newvalue = $offon[$env{'form.autoupdate_run'}];
6275: } else {
6276: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6277: }
1.1 raeburn 6278: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6279: }
6280: }
6281: $resulttext .= '</ul>';
6282: } else {
1.3 raeburn 6283: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6284: }
6285: } else {
1.11 albertel 6286: $resulttext = '<span class="LC_error">'.
6287: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6288: }
1.3 raeburn 6289: return $resulttext;
1.1 raeburn 6290: }
6291:
1.125 raeburn 6292: sub modify_autocreate {
6293: my ($dom,%domconfig) = @_;
6294: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6295: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6296: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6297: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6298: }
6299: }
6300: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6301: req => 'Auto-creation of validated requests for official courses',
6302: xmldc => 'Identity of course creator of courses from XML files',
6303: );
6304: my @types = ('xml','req');
6305: foreach my $item (@types) {
6306: $newvals{$item} = $env{'form.autocreate_'.$item};
6307: $newvals{$item} =~ s/\D//g;
6308: $newvals{$item} = 0 if ($newvals{$item} eq '');
6309: }
6310: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6311: my %domcoords = &get_active_dcs($dom);
6312: unless (exists($domcoords{$newvals{'xmldc'}})) {
6313: $newvals{'xmldc'} = '';
6314: }
6315: %autocreatehash = (
6316: autocreate => { xml => $newvals{'xml'},
6317: req => $newvals{'req'},
6318: }
6319: );
6320: if ($newvals{'xmldc'} ne '') {
6321: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6322: }
6323: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6324: $dom);
6325: if ($putresult eq 'ok') {
6326: my @items = @types;
6327: if ($newvals{'xml'}) {
6328: push(@items,'xmldc');
6329: }
6330: foreach my $item (@items) {
6331: if (exists($currautocreate{$item})) {
6332: if ($currautocreate{$item} ne $newvals{$item}) {
6333: $changes{$item} = 1;
6334: }
6335: } elsif ($newvals{$item}) {
6336: $changes{$item} = 1;
6337: }
6338: }
6339: if (keys(%changes) > 0) {
6340: my @offon = ('off','on');
6341: $resulttext = &mt('Changes made:').'<ul>';
6342: foreach my $item (@types) {
6343: if ($changes{$item}) {
6344: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6345: $resulttext .= '<li>'.
6346: &mt("$title{$item} set to [_1]$newtxt [_2]",
6347: '<b>','</b>').
6348: '</li>';
1.125 raeburn 6349: }
6350: }
6351: if ($changes{'xmldc'}) {
6352: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6353: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6354: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6355: }
6356: $resulttext .= '</ul>';
6357: } else {
6358: $resulttext = &mt('No changes made to auto-creation settings');
6359: }
6360: } else {
6361: $resulttext = '<span class="LC_error">'.
6362: &mt('An error occurred: [_1]',$putresult).'</span>';
6363: }
6364: return $resulttext;
6365: }
6366:
1.23 raeburn 6367: sub modify_directorysrch {
6368: my ($dom,%domconfig) = @_;
6369: my ($resulttext,%changes);
6370: my %currdirsrch;
6371: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6372: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6373: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6374: }
6375: }
6376: my %title = ( available => 'Directory search available',
1.24 raeburn 6377: localonly => 'Other domains can search',
1.23 raeburn 6378: searchby => 'Search types',
6379: searchtypes => 'Search latitude');
6380: my @offon = ('off','on');
1.24 raeburn 6381: my @otherdoms = ('Yes','No');
1.23 raeburn 6382:
1.25 raeburn 6383: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6384: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6385: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6386:
1.44 raeburn 6387: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6388: if (keys(%{$usertypes}) == 0) {
6389: @cansearch = ('default');
6390: } else {
6391: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6392: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6393: if (!grep(/^\Q$type\E$/,@cansearch)) {
6394: push(@{$changes{'cansearch'}},$type);
6395: }
1.23 raeburn 6396: }
1.26 raeburn 6397: foreach my $type (@cansearch) {
6398: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6399: push(@{$changes{'cansearch'}},$type);
6400: }
1.23 raeburn 6401: }
1.26 raeburn 6402: } else {
6403: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6404: }
6405: }
6406:
6407: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6408: foreach my $by (@{$currdirsrch{'searchby'}}) {
6409: if (!grep(/^\Q$by\E$/,@searchby)) {
6410: push(@{$changes{'searchby'}},$by);
6411: }
6412: }
6413: foreach my $by (@searchby) {
6414: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6415: push(@{$changes{'searchby'}},$by);
6416: }
6417: }
6418: } else {
6419: push(@{$changes{'searchby'}},@searchby);
6420: }
1.25 raeburn 6421:
6422: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6423: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6424: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6425: push(@{$changes{'searchtypes'}},$type);
6426: }
6427: }
6428: foreach my $type (@searchtypes) {
6429: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6430: push(@{$changes{'searchtypes'}},$type);
6431: }
6432: }
6433: } else {
6434: if (exists($currdirsrch{'searchtypes'})) {
6435: foreach my $type (@searchtypes) {
6436: if ($type ne $currdirsrch{'searchtypes'}) {
6437: push(@{$changes{'searchtypes'}},$type);
6438: }
6439: }
6440: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6441: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6442: }
6443: } else {
6444: push(@{$changes{'searchtypes'}},@searchtypes);
6445: }
6446: }
6447:
1.23 raeburn 6448: my %dirsrch_hash = (
6449: directorysrch => { available => $env{'form.dirsrch_available'},
6450: cansearch => \@cansearch,
1.24 raeburn 6451: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6452: searchby => \@searchby,
1.25 raeburn 6453: searchtypes => \@searchtypes,
1.23 raeburn 6454: }
6455: );
6456: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6457: $dom);
6458: if ($putresult eq 'ok') {
6459: if (exists($currdirsrch{'available'})) {
6460: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6461: $changes{'available'} = 1;
6462: }
6463: } else {
6464: if ($env{'form.dirsrch_available'} eq '1') {
6465: $changes{'available'} = 1;
6466: }
6467: }
1.24 raeburn 6468: if (exists($currdirsrch{'localonly'})) {
6469: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6470: $changes{'localonly'} = 1;
6471: }
6472: } else {
6473: if ($env{'form.dirsrch_localonly'} eq '1') {
6474: $changes{'localonly'} = 1;
6475: }
6476: }
1.23 raeburn 6477: if (keys(%changes) > 0) {
6478: $resulttext = &mt('Changes made:').'<ul>';
6479: if ($changes{'available'}) {
6480: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6481: }
1.24 raeburn 6482: if ($changes{'localonly'}) {
6483: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6484: }
6485:
1.23 raeburn 6486: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6487: my $chgtext;
1.26 raeburn 6488: if (ref($usertypes) eq 'HASH') {
6489: if (keys(%{$usertypes}) > 0) {
6490: foreach my $type (@{$types}) {
6491: if (grep(/^\Q$type\E$/,@cansearch)) {
6492: $chgtext .= $usertypes->{$type}.'; ';
6493: }
6494: }
6495: if (grep(/^default$/,@cansearch)) {
6496: $chgtext .= $othertitle;
6497: } else {
6498: $chgtext =~ s/\; $//;
6499: }
1.178 raeburn 6500: $resulttext .=
6501: '<li>'.
6502: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6503: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6504: '</li>';
1.23 raeburn 6505: }
6506: }
6507: }
6508: if (ref($changes{'searchby'}) eq 'ARRAY') {
6509: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6510: my $chgtext;
6511: foreach my $type (@{$titleorder}) {
6512: if (grep(/^\Q$type\E$/,@searchby)) {
6513: if (defined($searchtitles->{$type})) {
6514: $chgtext .= $searchtitles->{$type}.'; ';
6515: }
6516: }
6517: }
6518: $chgtext =~ s/\; $//;
6519: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6520: }
1.25 raeburn 6521: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6522: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6523: my $chgtext;
6524: foreach my $type (@{$srchtypeorder}) {
6525: if (grep(/^\Q$type\E$/,@searchtypes)) {
6526: if (defined($srchtypes_desc->{$type})) {
6527: $chgtext .= $srchtypes_desc->{$type}.'; ';
6528: }
6529: }
6530: }
6531: $chgtext =~ s/\; $//;
1.178 raeburn 6532: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6533: }
6534: $resulttext .= '</ul>';
6535: } else {
6536: $resulttext = &mt('No changes made to institution directory search settings');
6537: }
6538: } else {
6539: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6540: &mt('An error occurred: [_1]',$putresult).'</span>';
6541: }
6542: return $resulttext;
6543: }
6544:
1.28 raeburn 6545: sub modify_contacts {
6546: my ($dom,%domconfig) = @_;
6547: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6548: if (ref($domconfig{'contacts'}) eq 'HASH') {
6549: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6550: $currsetting{$key} = $domconfig{'contacts'}{$key};
6551: }
6552: }
1.134 raeburn 6553: my (%others,%to,%bcc);
1.28 raeburn 6554: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6555: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6556: 'requestsmail');
1.28 raeburn 6557: foreach my $type (@mailings) {
6558: @{$newsetting{$type}} =
6559: &Apache::loncommon::get_env_multiple('form.'.$type);
6560: foreach my $item (@contacts) {
6561: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6562: $contacts_hash{contacts}{$type}{$item} = 1;
6563: } else {
6564: $contacts_hash{contacts}{$type}{$item} = 0;
6565: }
6566: }
6567: $others{$type} = $env{'form.'.$type.'_others'};
6568: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6569: if ($type eq 'helpdeskmail') {
6570: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6571: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6572: }
1.28 raeburn 6573: }
6574: foreach my $item (@contacts) {
6575: $to{$item} = $env{'form.'.$item};
6576: $contacts_hash{'contacts'}{$item} = $to{$item};
6577: }
6578: if (keys(%currsetting) > 0) {
6579: foreach my $item (@contacts) {
6580: if ($to{$item} ne $currsetting{$item}) {
6581: $changes{$item} = 1;
6582: }
6583: }
6584: foreach my $type (@mailings) {
6585: foreach my $item (@contacts) {
6586: if (ref($currsetting{$type}) eq 'HASH') {
6587: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6588: push(@{$changes{$type}},$item);
6589: }
6590: } else {
6591: push(@{$changes{$type}},@{$newsetting{$type}});
6592: }
6593: }
6594: if ($others{$type} ne $currsetting{$type}{'others'}) {
6595: push(@{$changes{$type}},'others');
6596: }
1.134 raeburn 6597: if ($type eq 'helpdeskmail') {
6598: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6599: push(@{$changes{$type}},'bcc');
6600: }
6601: }
1.28 raeburn 6602: }
6603: } else {
6604: my %default;
6605: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6606: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6607: $default{'errormail'} = 'adminemail';
6608: $default{'packagesmail'} = 'adminemail';
6609: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6610: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6611: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6612: foreach my $item (@contacts) {
6613: if ($to{$item} ne $default{$item}) {
6614: $changes{$item} = 1;
6615: }
6616: }
6617: foreach my $type (@mailings) {
6618: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6619:
6620: push(@{$changes{$type}},@{$newsetting{$type}});
6621: }
6622: if ($others{$type} ne '') {
6623: push(@{$changes{$type}},'others');
1.134 raeburn 6624: }
6625: if ($type eq 'helpdeskmail') {
6626: if ($bcc{$type} ne '') {
6627: push(@{$changes{$type}},'bcc');
6628: }
6629: }
1.28 raeburn 6630: }
6631: }
6632: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6633: $dom);
6634: if ($putresult eq 'ok') {
6635: if (keys(%changes) > 0) {
6636: my ($titles,$short_titles) = &contact_titles();
6637: $resulttext = &mt('Changes made:').'<ul>';
6638: foreach my $item (@contacts) {
6639: if ($changes{$item}) {
6640: $resulttext .= '<li>'.$titles->{$item}.
6641: &mt(' set to: ').
6642: '<span class="LC_cusr_emph">'.
6643: $to{$item}.'</span></li>';
6644: }
6645: }
6646: foreach my $type (@mailings) {
6647: if (ref($changes{$type}) eq 'ARRAY') {
6648: $resulttext .= '<li>'.$titles->{$type}.': ';
6649: my @text;
6650: foreach my $item (@{$newsetting{$type}}) {
6651: push(@text,$short_titles->{$item});
6652: }
6653: if ($others{$type} ne '') {
6654: push(@text,$others{$type});
6655: }
6656: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6657: join(', ',@text).'</span>';
6658: if ($type eq 'helpdeskmail') {
6659: if ($bcc{$type} ne '') {
6660: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6661: }
6662: }
6663: $resulttext .= '</li>';
1.28 raeburn 6664: }
6665: }
6666: $resulttext .= '</ul>';
6667: } else {
1.34 raeburn 6668: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6669: }
6670: } else {
6671: $resulttext = '<span class="LC_error">'.
6672: &mt('An error occurred: [_1].',$putresult).'</span>';
6673: }
6674: return $resulttext;
6675: }
6676:
6677: sub modify_usercreation {
1.27 raeburn 6678: my ($dom,%domconfig) = @_;
1.34 raeburn 6679: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6680: my $warningmsg;
1.27 raeburn 6681: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6682: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6683: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6684: }
6685: }
6686: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6687: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6688: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6689: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6690: foreach my $item(@contexts) {
1.45 raeburn 6691: if ($item eq 'selfcreate') {
1.50 raeburn 6692: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6693: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6694: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6695: if (ref($cancreate{$item}) eq 'ARRAY') {
6696: if (grep(/^login$/,@{$cancreate{$item}})) {
6697: $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.');
6698: }
1.43 raeburn 6699: }
6700: }
1.50 raeburn 6701: } else {
6702: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6703: }
1.34 raeburn 6704: }
1.93 raeburn 6705: my ($othertitle,$usertypes,$types) =
6706: &Apache::loncommon::sorted_inst_types($dom);
6707: if (ref($types) eq 'ARRAY') {
6708: if (@{$types} > 0) {
6709: @{$cancreate{'statustocreate'}} =
6710: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6711: } else {
6712: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6713: }
6714: push(@contexts,'statustocreate');
6715: }
1.165 raeburn 6716: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6717: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6718: foreach my $item (@contexts) {
1.93 raeburn 6719: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6720: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6721: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6722: if (ref($cancreate{$item}) eq 'ARRAY') {
6723: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6724: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6725: push(@{$changes{'cancreate'}},$item);
6726: }
1.50 raeburn 6727: }
6728: }
6729: }
6730: } else {
6731: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6732: if (@{$cancreate{$item}} > 0) {
6733: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6734: push(@{$changes{'cancreate'}},$item);
6735: }
6736: }
6737: } else {
6738: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6739: if (@{$cancreate{$item}} < 3) {
6740: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6741: push(@{$changes{'cancreate'}},$item);
6742: }
6743: }
6744: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6745: if (@{$cancreate{$item}} > 0) {
6746: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6747: push(@{$changes{'cancreate'}},$item);
6748: }
6749: }
6750: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6751: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6752: push(@{$changes{'cancreate'}},$item);
6753: }
6754: }
6755: }
6756: }
6757: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6758: foreach my $type (@{$cancreate{$item}}) {
6759: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6760: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6761: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6762: push(@{$changes{'cancreate'}},$item);
6763: }
6764: }
6765: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6766: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6767: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6768: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6769: push(@{$changes{'cancreate'}},$item);
6770: }
6771: }
6772: }
6773: }
6774: }
6775: } else {
6776: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6777: push(@{$changes{'cancreate'}},$item);
6778: }
6779: }
1.27 raeburn 6780: }
1.34 raeburn 6781: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6782: foreach my $item (@contexts) {
1.43 raeburn 6783: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6784: if ($cancreate{$item} ne 'any') {
6785: push(@{$changes{'cancreate'}},$item);
6786: }
6787: } else {
6788: if ($cancreate{$item} ne 'none') {
6789: push(@{$changes{'cancreate'}},$item);
6790: }
1.27 raeburn 6791: }
6792: }
6793: } else {
1.43 raeburn 6794: foreach my $item (@contexts) {
1.34 raeburn 6795: push(@{$changes{'cancreate'}},$item);
6796: }
1.27 raeburn 6797: }
1.34 raeburn 6798:
1.27 raeburn 6799: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6800: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6801: if (!grep(/^\Q$type\E$/,@username_rule)) {
6802: push(@{$changes{'username_rule'}},$type);
6803: }
6804: }
6805: foreach my $type (@username_rule) {
6806: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6807: push(@{$changes{'username_rule'}},$type);
6808: }
6809: }
6810: } else {
6811: push(@{$changes{'username_rule'}},@username_rule);
6812: }
6813:
1.32 raeburn 6814: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6815: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6816: if (!grep(/^\Q$type\E$/,@id_rule)) {
6817: push(@{$changes{'id_rule'}},$type);
6818: }
6819: }
6820: foreach my $type (@id_rule) {
6821: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6822: push(@{$changes{'id_rule'}},$type);
6823: }
6824: }
6825: } else {
6826: push(@{$changes{'id_rule'}},@id_rule);
6827: }
6828:
1.43 raeburn 6829: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6830: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6831: if (!grep(/^\Q$type\E$/,@email_rule)) {
6832: push(@{$changes{'email_rule'}},$type);
6833: }
6834: }
6835: foreach my $type (@email_rule) {
6836: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6837: push(@{$changes{'email_rule'}},$type);
6838: }
6839: }
6840: } else {
6841: push(@{$changes{'email_rule'}},@email_rule);
6842: }
6843:
6844: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6845: my @authtypes = ('int','krb4','krb5','loc');
6846: my %authhash;
1.43 raeburn 6847: foreach my $item (@authen_contexts) {
1.28 raeburn 6848: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6849: foreach my $auth (@authtypes) {
6850: if (grep(/^\Q$auth\E$/,@authallowed)) {
6851: $authhash{$item}{$auth} = 1;
6852: } else {
6853: $authhash{$item}{$auth} = 0;
6854: }
6855: }
6856: }
6857: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6858: foreach my $item (@authen_contexts) {
1.28 raeburn 6859: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6860: foreach my $auth (@authtypes) {
6861: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6862: push(@{$changes{'authtypes'}},$item);
6863: last;
6864: }
6865: }
6866: }
6867: }
6868: } else {
1.43 raeburn 6869: foreach my $item (@authen_contexts) {
1.28 raeburn 6870: push(@{$changes{'authtypes'}},$item);
6871: }
6872: }
6873:
1.27 raeburn 6874: my %usercreation_hash = (
1.28 raeburn 6875: usercreation => {
1.34 raeburn 6876: cancreate => \%cancreate,
1.27 raeburn 6877: username_rule => \@username_rule,
1.32 raeburn 6878: id_rule => \@id_rule,
1.43 raeburn 6879: email_rule => \@email_rule,
1.32 raeburn 6880: authtypes => \%authhash,
1.27 raeburn 6881: }
6882: );
6883:
6884: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6885: $dom);
1.50 raeburn 6886:
6887: my %selfcreatetypes = (
6888: sso => 'users authenticated by institutional single sign on',
6889: login => 'users authenticated by institutional log-in',
6890: email => 'users who provide a valid e-mail address for use as the username',
6891: );
1.27 raeburn 6892: if ($putresult eq 'ok') {
6893: if (keys(%changes) > 0) {
6894: $resulttext = &mt('Changes made:').'<ul>';
6895: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6896: my %lt = &usercreation_types();
6897: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6898: my $chgtext;
1.165 raeburn 6899: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6900: $chgtext = $lt{$type}.', ';
6901: }
1.45 raeburn 6902: if ($type eq 'selfcreate') {
1.50 raeburn 6903: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6904: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6905: } else {
1.100 raeburn 6906: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6907: foreach my $case (@{$cancreate{$type}}) {
6908: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6909: }
6910: $chgtext .= '</ul>';
1.100 raeburn 6911: if (ref($cancreate{$type}) eq 'ARRAY') {
6912: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6913: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6914: if (@{$cancreate{'statustocreate'}} == 0) {
6915: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6916: }
6917: }
6918: }
6919: }
1.43 raeburn 6920: }
1.93 raeburn 6921: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6922: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6923: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6924: if (@{$cancreate{'selfcreate'}} > 0) {
6925: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6926:
6927: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6928: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6929: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6930: }
1.96 raeburn 6931: } elsif (ref($usertypes) eq 'HASH') {
6932: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6933: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6934: } else {
6935: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6936: }
6937: $chgtext .= '<ul>';
6938: foreach my $case (@{$cancreate{$type}}) {
6939: if ($case eq 'default') {
6940: $chgtext .= '<li>'.$othertitle.'</li>';
6941: } else {
6942: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6943: }
6944: }
1.100 raeburn 6945: $chgtext .= '</ul>';
6946: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6947: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6948: }
6949: }
6950: } else {
6951: if (@{$cancreate{$type}} == 0) {
6952: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6953: } else {
6954: $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 6955: }
6956: }
6957: }
1.165 raeburn 6958: } elsif ($type eq 'captcha') {
6959: if ($cancreate{$type} eq 'notused') {
6960: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6961: } else {
6962: my %captchas = &captcha_phrases();
6963: if ($captchas{$cancreate{$type}}) {
6964: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6965: } else {
6966: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6967: }
6968: }
6969: } elsif ($type eq 'recaptchakeys') {
6970: my ($privkey,$pubkey);
6971: if (ref($cancreate{$type}) eq 'HASH') {
6972: $pubkey = $cancreate{$type}{'public'};
6973: $privkey = $cancreate{$type}{'private'};
6974: }
6975: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6976: if (!$pubkey) {
6977: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6978: } else {
6979: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6980: }
6981: if (!$privkey) {
6982: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6983: } else {
6984: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6985: }
6986: $chgtext .= '</ul>';
1.43 raeburn 6987: } else {
6988: if ($cancreate{$type} eq 'none') {
6989: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6990: } elsif ($cancreate{$type} eq 'any') {
6991: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6992: } elsif ($cancreate{$type} eq 'official') {
6993: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6994: } elsif ($cancreate{$type} eq 'unofficial') {
6995: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6996: }
1.34 raeburn 6997: }
6998: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6999: }
7000: }
7001: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7002: my ($rules,$ruleorder) =
7003: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7004: my $chgtext = '<ul>';
7005: foreach my $type (@username_rule) {
7006: if (ref($rules->{$type}) eq 'HASH') {
7007: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7008: }
7009: }
7010: $chgtext .= '</ul>';
7011: if (@username_rule > 0) {
7012: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7013: } else {
1.28 raeburn 7014: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7015: }
7016: }
1.32 raeburn 7017: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7018: my ($idrules,$idruleorder) =
7019: &Apache::lonnet::inst_userrules($dom,'id');
7020: my $chgtext = '<ul>';
7021: foreach my $type (@id_rule) {
7022: if (ref($idrules->{$type}) eq 'HASH') {
7023: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7024: }
7025: }
7026: $chgtext .= '</ul>';
7027: if (@id_rule > 0) {
7028: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7029: } else {
7030: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7031: }
7032: }
1.43 raeburn 7033: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7034: my ($emailrules,$emailruleorder) =
7035: &Apache::lonnet::inst_userrules($dom,'email');
7036: my $chgtext = '<ul>';
7037: foreach my $type (@email_rule) {
7038: if (ref($emailrules->{$type}) eq 'HASH') {
7039: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7040: }
7041: }
7042: $chgtext .= '</ul>';
7043: if (@email_rule > 0) {
7044: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7045: } else {
7046: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7047: }
7048: }
7049:
1.28 raeburn 7050: my %authname = &authtype_names();
7051: my %context_title = &context_names();
7052: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7053: my $chgtext = '<ul>';
7054: foreach my $type (@{$changes{'authtypes'}}) {
7055: my @allowed;
7056: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7057: foreach my $auth (@authtypes) {
7058: if ($authhash{$type}{$auth}) {
7059: push(@allowed,$authname{$auth});
7060: }
7061: }
1.43 raeburn 7062: if (@allowed > 0) {
7063: $chgtext .= join(', ',@allowed).'</li>';
7064: } else {
7065: $chgtext .= &mt('none').'</li>';
7066: }
1.28 raeburn 7067: }
7068: $chgtext .= '</ul>';
7069: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7070: $resulttext .= '</li>';
7071: }
1.27 raeburn 7072: $resulttext .= '</ul>';
7073: } else {
1.28 raeburn 7074: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7075: }
7076: } else {
7077: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7078: &mt('An error occurred: [_1]',$putresult).'</span>';
7079: }
1.43 raeburn 7080: if ($warningmsg ne '') {
7081: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7082: }
1.23 raeburn 7083: return $resulttext;
7084: }
7085:
1.165 raeburn 7086: sub process_captcha {
7087: my ($container,$changes,$newsettings,$current) = @_;
7088: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7089: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7090: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7091: $newsettings->{'captcha'} = 'original';
7092: }
7093: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7094: if ($container eq 'cancreate') {
7095: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7096: push(@{$changes->{'cancreate'}},'captcha');
7097: } elsif (!defined($changes->{'cancreate'})) {
7098: $changes->{'cancreate'} = ['captcha'];
7099: }
7100: } else {
7101: $changes->{'captcha'} = 1;
1.165 raeburn 7102: }
7103: }
7104: my ($newpub,$newpriv,$currpub,$currpriv);
7105: if ($newsettings->{'captcha'} eq 'recaptcha') {
7106: $newpub = $env{'form.'.$container.'_recaptchapub'};
7107: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7108: $newpub =~ s/\W//g;
7109: $newpriv =~ s/\W//g;
7110: $newsettings->{'recaptchakeys'} = {
7111: public => $newpub,
7112: private => $newpriv,
7113: };
1.165 raeburn 7114: }
7115: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7116: $currpub = $current->{'recaptchakeys'}{'public'};
7117: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7118: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7119: $newsettings->{'recaptchakeys'} = {
7120: public => '',
7121: private => '',
7122: }
7123: }
1.165 raeburn 7124: }
7125: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7126: if ($container eq 'cancreate') {
7127: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7128: push(@{$changes->{'cancreate'}},'recaptchakeys');
7129: } elsif (!defined($changes->{'cancreate'})) {
7130: $changes->{'cancreate'} = ['recaptchakeys'];
7131: }
7132: } else {
7133: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7134: }
7135: }
7136: return;
7137: }
7138:
1.33 raeburn 7139: sub modify_usermodification {
7140: my ($dom,%domconfig) = @_;
7141: my ($resulttext,%curr_usermodification,%changes);
7142: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7143: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7144: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7145: }
7146: }
1.63 raeburn 7147: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7148: my %context_title = (
7149: author => 'In author context',
7150: course => 'In course context',
1.63 raeburn 7151: selfcreate => 'When self creating account',
1.33 raeburn 7152: );
7153: my @fields = ('lastname','firstname','middlename','generation',
7154: 'permanentemail','id');
7155: my %roles = (
7156: author => ['ca','aa'],
7157: course => ['st','ep','ta','in','cr'],
7158: );
1.63 raeburn 7159: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7160: if (ref($types) eq 'ARRAY') {
7161: push(@{$types},'default');
7162: $usertypes->{'default'} = $othertitle;
7163: }
7164: $roles{'selfcreate'} = $types;
1.33 raeburn 7165: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7166: my %modifyhash;
7167: foreach my $context (@contexts) {
7168: foreach my $role (@{$roles{$context}}) {
7169: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7170: foreach my $item (@fields) {
7171: if (grep(/^\Q$item\E$/,@modifiable)) {
7172: $modifyhash{$context}{$role}{$item} = 1;
7173: } else {
7174: $modifyhash{$context}{$role}{$item} = 0;
7175: }
7176: }
7177: }
7178: if (ref($curr_usermodification{$context}) eq 'HASH') {
7179: foreach my $role (@{$roles{$context}}) {
7180: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7181: foreach my $field (@fields) {
7182: if ($modifyhash{$context}{$role}{$field} ne
7183: $curr_usermodification{$context}{$role}{$field}) {
7184: push(@{$changes{$context}},$role);
7185: last;
7186: }
7187: }
7188: }
7189: }
7190: } else {
7191: foreach my $context (@contexts) {
7192: foreach my $role (@{$roles{$context}}) {
7193: push(@{$changes{$context}},$role);
7194: }
7195: }
7196: }
7197: }
7198: my %usermodification_hash = (
7199: usermodification => \%modifyhash,
7200: );
7201: my $putresult = &Apache::lonnet::put_dom('configuration',
7202: \%usermodification_hash,$dom);
7203: if ($putresult eq 'ok') {
7204: if (keys(%changes) > 0) {
7205: $resulttext = &mt('Changes made: ').'<ul>';
7206: foreach my $context (@contexts) {
7207: if (ref($changes{$context}) eq 'ARRAY') {
7208: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7209: if (ref($changes{$context}) eq 'ARRAY') {
7210: foreach my $role (@{$changes{$context}}) {
7211: my $rolename;
1.63 raeburn 7212: if ($context eq 'selfcreate') {
7213: $rolename = $role;
7214: if (ref($usertypes) eq 'HASH') {
7215: if ($usertypes->{$role} ne '') {
7216: $rolename = $usertypes->{$role};
7217: }
7218: }
1.33 raeburn 7219: } else {
1.63 raeburn 7220: if ($role eq 'cr') {
7221: $rolename = &mt('Custom');
7222: } else {
7223: $rolename = &Apache::lonnet::plaintext($role);
7224: }
1.33 raeburn 7225: }
7226: my @modifiable;
1.63 raeburn 7227: if ($context eq 'selfcreate') {
1.126 bisitz 7228: $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 7229: } else {
7230: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7231: }
1.33 raeburn 7232: foreach my $field (@fields) {
7233: if ($modifyhash{$context}{$role}{$field}) {
7234: push(@modifiable,$fieldtitles{$field});
7235: }
7236: }
7237: if (@modifiable > 0) {
7238: $resulttext .= join(', ',@modifiable);
7239: } else {
7240: $resulttext .= &mt('none');
7241: }
7242: $resulttext .= '</li>';
7243: }
7244: $resulttext .= '</ul></li>';
7245: }
7246: }
7247: }
7248: $resulttext .= '</ul>';
7249: } else {
7250: $resulttext = &mt('No changes made to user modification settings');
7251: }
7252: } else {
7253: $resulttext = '<span class="LC_error">'.
7254: &mt('An error occurred: [_1]',$putresult).'</span>';
7255: }
7256: return $resulttext;
7257: }
7258:
1.43 raeburn 7259: sub modify_defaults {
7260: my ($dom,$r) = @_;
7261: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7262: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7263: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7264: my @authtypes = ('internal','krb4','krb5','localauth');
7265: foreach my $item (@items) {
7266: $newvalues{$item} = $env{'form.'.$item};
7267: if ($item eq 'auth_def') {
7268: if ($newvalues{$item} ne '') {
7269: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7270: push(@errors,$item);
7271: }
7272: }
7273: } elsif ($item eq 'lang_def') {
7274: if ($newvalues{$item} ne '') {
7275: if ($newvalues{$item} =~ /^(\w+)/) {
7276: my $langcode = $1;
1.103 raeburn 7277: if ($langcode ne 'x_chef') {
7278: if (code2language($langcode) eq '') {
7279: push(@errors,$item);
7280: }
1.43 raeburn 7281: }
7282: } else {
7283: push(@errors,$item);
7284: }
7285: }
1.54 raeburn 7286: } elsif ($item eq 'timezone_def') {
7287: if ($newvalues{$item} ne '') {
1.62 raeburn 7288: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7289: push(@errors,$item);
7290: }
7291: }
1.68 raeburn 7292: } elsif ($item eq 'datelocale_def') {
7293: if ($newvalues{$item} ne '') {
7294: my @datelocale_ids = DateTime::Locale->ids();
7295: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7296: push(@errors,$item);
7297: }
7298: }
1.141 raeburn 7299: } elsif ($item eq 'portal_def') {
7300: if ($newvalues{$item} ne '') {
7301: 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])\/?$/) {
7302: push(@errors,$item);
7303: }
7304: }
1.43 raeburn 7305: }
7306: if (grep(/^\Q$item\E$/,@errors)) {
7307: $newvalues{$item} = $domdefaults{$item};
7308: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7309: $changes{$item} = 1;
7310: }
1.72 raeburn 7311: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7312: }
7313: my %defaults_hash = (
1.72 raeburn 7314: defaults => \%newvalues,
7315: );
1.43 raeburn 7316: my $title = &defaults_titles();
7317: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7318: $dom);
7319: if ($putresult eq 'ok') {
7320: if (keys(%changes) > 0) {
7321: $resulttext = &mt('Changes made:').'<ul>';
7322: my $version = $r->dir_config('lonVersion');
7323: 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";
7324: foreach my $item (sort(keys(%changes))) {
7325: my $value = $env{'form.'.$item};
7326: if ($value eq '') {
7327: $value = &mt('none');
7328: } elsif ($item eq 'auth_def') {
7329: my %authnames = &authtype_names();
7330: my %shortauth = (
7331: internal => 'int',
7332: krb4 => 'krb4',
7333: krb5 => 'krb5',
7334: localauth => 'loc',
7335: );
7336: $value = $authnames{$shortauth{$value}};
7337: }
7338: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7339: $mailmsgtext .= "$title->{$item} set to $value\n";
7340: }
7341: $resulttext .= '</ul>';
7342: $mailmsgtext .= "\n";
7343: my $cachetime = 24*60*60;
1.72 raeburn 7344: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7345: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7346: my $sysmail = $r->dir_config('lonSysEMail');
7347: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7348: }
1.43 raeburn 7349: } else {
1.54 raeburn 7350: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7351: }
7352: } else {
7353: $resulttext = '<span class="LC_error">'.
7354: &mt('An error occurred: [_1]',$putresult).'</span>';
7355: }
7356: if (@errors > 0) {
7357: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7358: foreach my $item (@errors) {
7359: $resulttext .= ' "'.$title->{$item}.'",';
7360: }
7361: $resulttext =~ s/,$//;
7362: }
7363: return $resulttext;
7364: }
7365:
1.46 raeburn 7366: sub modify_scantron {
1.48 raeburn 7367: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7368: my ($resulttext,%confhash,%changes,$errors);
7369: my $custom = 'custom.tab';
7370: my $default = 'default.tab';
7371: my $servadm = $r->dir_config('lonAdmEMail');
7372: my ($configuserok,$author_ok,$switchserver) =
7373: &config_check($dom,$confname,$servadm);
7374: if ($env{'form.scantronformat.filename'} ne '') {
7375: my $error;
7376: if ($configuserok eq 'ok') {
7377: if ($switchserver) {
1.130 raeburn 7378: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7379: } else {
7380: if ($author_ok eq 'ok') {
7381: my ($result,$scantronurl) =
7382: &publishlogo($r,'upload','scantronformat',$dom,
7383: $confname,'scantron','','',$custom);
7384: if ($result eq 'ok') {
7385: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7386: $changes{'scantronformat'} = 1;
1.46 raeburn 7387: } else {
7388: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7389: }
7390: } else {
7391: $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);
7392: }
7393: }
7394: } else {
7395: $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);
7396: }
7397: if ($error) {
7398: &Apache::lonnet::logthis($error);
7399: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7400: }
7401: }
1.48 raeburn 7402: if (ref($domconfig{'scantron'}) eq 'HASH') {
7403: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7404: if ($env{'form.scantronformat_del'}) {
7405: $confhash{'scantron'}{'scantronformat'} = '';
7406: $changes{'scantronformat'} = 1;
1.46 raeburn 7407: }
7408: }
7409: }
7410: if (keys(%confhash) > 0) {
7411: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7412: $dom);
7413: if ($putresult eq 'ok') {
7414: if (keys(%changes) > 0) {
1.48 raeburn 7415: if (ref($confhash{'scantron'}) eq 'HASH') {
7416: $resulttext = &mt('Changes made:').'<ul>';
7417: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7418: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7419: } else {
1.130 raeburn 7420: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7421: }
1.48 raeburn 7422: $resulttext .= '</ul>';
7423: } else {
1.130 raeburn 7424: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7425: }
7426: $resulttext .= '</ul>';
7427: &Apache::loncommon::devalidate_domconfig_cache($dom);
7428: } else {
1.130 raeburn 7429: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7430: }
7431: } else {
7432: $resulttext = '<span class="LC_error">'.
7433: &mt('An error occurred: [_1]',$putresult).'</span>';
7434: }
7435: } else {
1.130 raeburn 7436: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7437: }
7438: if ($errors) {
7439: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7440: $errors.'</ul>';
7441: }
7442: return $resulttext;
7443: }
7444:
1.48 raeburn 7445: sub modify_coursecategories {
7446: my ($dom,%domconfig) = @_;
1.57 raeburn 7447: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7448: $cathash);
1.48 raeburn 7449: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7450: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7451: $cathash = $domconfig{'coursecategories'}{'cats'};
7452: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7453: $changes{'togglecats'} = 1;
7454: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7455: }
7456: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7457: $changes{'categorize'} = 1;
7458: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7459: }
1.120 raeburn 7460: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7461: $changes{'togglecatscomm'} = 1;
7462: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7463: }
7464: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7465: $changes{'categorizecomm'} = 1;
7466: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7467: }
1.57 raeburn 7468: } else {
7469: $changes{'togglecats'} = 1;
7470: $changes{'categorize'} = 1;
1.124 raeburn 7471: $changes{'togglecatscomm'} = 1;
7472: $changes{'categorizecomm'} = 1;
1.87 raeburn 7473: $domconfig{'coursecategories'} = {
7474: togglecats => $env{'form.togglecats'},
7475: categorize => $env{'form.categorize'},
1.124 raeburn 7476: togglecatscomm => $env{'form.togglecatscomm'},
7477: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7478: };
1.57 raeburn 7479: }
7480: if (ref($cathash) eq 'HASH') {
7481: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7482: push (@deletecategory,'instcode::0');
7483: }
1.120 raeburn 7484: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7485: push(@deletecategory,'communities::0');
7486: }
1.48 raeburn 7487: }
1.57 raeburn 7488: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7489: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7490: if (@deletecategory > 0) {
7491: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7492: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7493: foreach my $item (@deletecategory) {
1.57 raeburn 7494: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7495: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7496: $deletions{$item} = 1;
1.57 raeburn 7497: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7498: }
7499: }
7500: }
1.57 raeburn 7501: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7502: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7503: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7504: $reorderings{$item} = 1;
1.57 raeburn 7505: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7506: }
7507: if ($env{'form.addcategory_name_'.$item} ne '') {
7508: my $newcat = $env{'form.addcategory_name_'.$item};
7509: my $newdepth = $depth+1;
7510: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7511: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7512: $adds{$newitem} = 1;
7513: }
7514: if ($env{'form.subcat_'.$item} ne '') {
7515: my $newcat = $env{'form.subcat_'.$item};
7516: my $newdepth = $depth+1;
7517: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7518: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7519: $adds{$newitem} = 1;
7520: }
7521: }
7522: }
7523: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7524: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7525: my $newitem = 'instcode::0';
1.57 raeburn 7526: if ($cathash->{$newitem} eq '') {
7527: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7528: $adds{$newitem} = 1;
7529: }
7530: } else {
7531: my $newitem = 'instcode::0';
1.57 raeburn 7532: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7533: $adds{$newitem} = 1;
7534: }
7535: }
1.120 raeburn 7536: if ($env{'form.communities'} eq '1') {
7537: if (ref($cathash) eq 'HASH') {
7538: my $newitem = 'communities::0';
7539: if ($cathash->{$newitem} eq '') {
7540: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7541: $adds{$newitem} = 1;
7542: }
7543: } else {
7544: my $newitem = 'communities::0';
7545: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7546: $adds{$newitem} = 1;
7547: }
7548: }
1.48 raeburn 7549: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7550: if (($env{'form.addcategory_name'} ne 'instcode') &&
7551: ($env{'form.addcategory_name'} ne 'communities')) {
7552: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7553: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7554: $adds{$newitem} = 1;
7555: }
1.48 raeburn 7556: }
1.57 raeburn 7557: my $putresult;
1.48 raeburn 7558: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7559: if (keys(%deletions) > 0) {
7560: foreach my $key (keys(%deletions)) {
7561: if ($predelallitems{$key} ne '') {
7562: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7563: }
7564: }
7565: }
7566: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7567: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7568: if (ref($chkcats[0]) eq 'ARRAY') {
7569: my $depth = 0;
7570: my $chg = 0;
7571: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7572: my $name = $chkcats[0][$i];
7573: my $item;
7574: if ($name eq '') {
7575: $chg ++;
7576: } else {
7577: $item = &escape($name).'::0';
7578: if ($chg) {
1.57 raeburn 7579: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7580: }
7581: $depth ++;
1.57 raeburn 7582: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7583: $depth --;
7584: }
7585: }
7586: }
1.57 raeburn 7587: }
7588: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7589: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7590: if ($putresult eq 'ok') {
1.57 raeburn 7591: my %title = (
1.120 raeburn 7592: togglecats => 'Show/Hide a course in catalog',
7593: categorize => 'Assign a category to a course',
7594: togglecatscomm => 'Show/Hide a community in catalog',
7595: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7596: );
7597: my %level = (
1.120 raeburn 7598: dom => 'set in Domain ("Modify Course/Community")',
7599: crs => 'set in Course ("Course Configuration")',
7600: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7601: );
1.48 raeburn 7602: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7603: if ($changes{'togglecats'}) {
7604: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7605: }
7606: if ($changes{'categorize'}) {
7607: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7608: }
1.120 raeburn 7609: if ($changes{'togglecatscomm'}) {
7610: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7611: }
7612: if ($changes{'categorizecomm'}) {
7613: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7614: }
1.57 raeburn 7615: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7616: my $cathash;
7617: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7618: $cathash = $domconfig{'coursecategories'}{'cats'};
7619: } else {
7620: $cathash = {};
7621: }
7622: my (@cats,@trails,%allitems);
7623: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7624: if (keys(%deletions) > 0) {
7625: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7626: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7627: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7628: }
7629: $resulttext .= '</ul></li>';
7630: }
7631: if (keys(%reorderings) > 0) {
7632: my %sort_by_trail;
7633: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7634: foreach my $key (keys(%reorderings)) {
7635: if ($allitems{$key} ne '') {
7636: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7637: }
1.48 raeburn 7638: }
1.57 raeburn 7639: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7640: $resulttext .= '<li>'.$trails[$trail].'</li>';
7641: }
7642: $resulttext .= '</ul></li>';
1.48 raeburn 7643: }
1.57 raeburn 7644: if (keys(%adds) > 0) {
7645: my %sort_by_trail;
7646: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7647: foreach my $key (keys(%adds)) {
7648: if ($allitems{$key} ne '') {
7649: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7650: }
7651: }
7652: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7653: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7654: }
1.57 raeburn 7655: $resulttext .= '</ul></li>';
1.48 raeburn 7656: }
7657: }
7658: $resulttext .= '</ul>';
7659: } else {
7660: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7661: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7662: }
7663: } else {
1.120 raeburn 7664: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7665: }
7666: return $resulttext;
7667: }
7668:
1.69 raeburn 7669: sub modify_serverstatuses {
7670: my ($dom,%domconfig) = @_;
7671: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7672: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7673: %currserverstatus = %{$domconfig{'serverstatuses'}};
7674: }
7675: my @pages = &serverstatus_pages();
7676: foreach my $type (@pages) {
7677: $newserverstatus{$type}{'namedusers'} = '';
7678: $newserverstatus{$type}{'machines'} = '';
7679: if (defined($env{'form.'.$type.'_namedusers'})) {
7680: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7681: my @okusers;
7682: foreach my $user (@users) {
7683: my ($uname,$udom) = split(/:/,$user);
7684: if (($udom =~ /^$match_domain$/) &&
7685: (&Apache::lonnet::domain($udom)) &&
7686: ($uname =~ /^$match_username$/)) {
7687: if (!grep(/^\Q$user\E/,@okusers)) {
7688: push(@okusers,$user);
7689: }
7690: }
7691: }
7692: if (@okusers > 0) {
7693: @okusers = sort(@okusers);
7694: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7695: }
7696: }
7697: if (defined($env{'form.'.$type.'_machines'})) {
7698: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7699: my @okmachines;
7700: foreach my $ip (@machines) {
7701: my @parts = split(/\./,$ip);
7702: next if (@parts < 4);
7703: my $badip = 0;
7704: for (my $i=0; $i<4; $i++) {
7705: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7706: $badip = 1;
7707: last;
7708: }
7709: }
7710: if (!$badip) {
7711: push(@okmachines,$ip);
7712: }
7713: }
7714: @okmachines = sort(@okmachines);
7715: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7716: }
7717: }
7718: my %serverstatushash = (
7719: serverstatuses => \%newserverstatus,
7720: );
7721: foreach my $type (@pages) {
1.83 raeburn 7722: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7723: my (@current,@new);
1.83 raeburn 7724: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7725: if ($currserverstatus{$type}{$setting} ne '') {
7726: @current = split(/,/,$currserverstatus{$type}{$setting});
7727: }
7728: }
7729: if ($newserverstatus{$type}{$setting} ne '') {
7730: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7731: }
7732: if (@current > 0) {
7733: if (@new > 0) {
7734: foreach my $item (@current) {
7735: if (!grep(/^\Q$item\E$/,@new)) {
7736: $changes{$type}{$setting} = 1;
1.82 raeburn 7737: last;
7738: }
7739: }
1.84 raeburn 7740: foreach my $item (@new) {
7741: if (!grep(/^\Q$item\E$/,@current)) {
7742: $changes{$type}{$setting} = 1;
7743: last;
1.82 raeburn 7744: }
7745: }
7746: } else {
1.83 raeburn 7747: $changes{$type}{$setting} = 1;
1.69 raeburn 7748: }
1.83 raeburn 7749: } elsif (@new > 0) {
7750: $changes{$type}{$setting} = 1;
1.69 raeburn 7751: }
7752: }
7753: }
7754: if (keys(%changes) > 0) {
1.81 raeburn 7755: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7756: my $putresult = &Apache::lonnet::put_dom('configuration',
7757: \%serverstatushash,$dom);
7758: if ($putresult eq 'ok') {
7759: $resulttext .= &mt('Changes made:').'<ul>';
7760: foreach my $type (@pages) {
1.84 raeburn 7761: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7762: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7763: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7764: if ($newserverstatus{$type}{'namedusers'} eq '') {
7765: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7766: } else {
7767: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7768: }
1.84 raeburn 7769: }
7770: if ($changes{$type}{'machines'}) {
1.69 raeburn 7771: if ($newserverstatus{$type}{'machines'} eq '') {
7772: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7773: } else {
7774: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7775: }
7776:
7777: }
7778: $resulttext .= '</ul></li>';
7779: }
7780: }
7781: $resulttext .= '</ul>';
7782: } else {
7783: $resulttext = '<span class="LC_error">'.
7784: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7785:
7786: }
7787: } else {
7788: $resulttext = &mt('No changes made to access to server status pages');
7789: }
7790: return $resulttext;
7791: }
7792:
1.118 jms 7793: sub modify_helpsettings {
1.122 jms 7794: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7795: my ($resulttext,$errors,%changes,%helphash);
7796: my %defaultchecked = ('submitbugs' => 'on');
7797: my @offon = ('off','on');
1.118 jms 7798: my @toggles = ('submitbugs');
7799: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7800: foreach my $item (@toggles) {
1.166 raeburn 7801: if ($defaultchecked{$item} eq 'on') {
7802: if ($domconfig{'helpsettings'}{$item} eq '') {
7803: if ($env{'form.'.$item} eq '0') {
7804: $changes{$item} = 1;
7805: }
7806: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7807: $changes{$item} = 1;
7808: }
7809: } elsif ($defaultchecked{$item} eq 'off') {
7810: if ($domconfig{'helpsettings'}{$item} eq '') {
7811: if ($env{'form.'.$item} eq '1') {
7812: $changes{$item} = 1;
7813: }
7814: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7815: $changes{$item} = 1;
7816: }
7817: }
7818: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7819: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7820: }
7821: }
1.118 jms 7822: }
1.123 jms 7823: my $putresult;
7824: if (keys(%changes) > 0) {
1.166 raeburn 7825: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7826: if ($putresult eq 'ok') {
1.166 raeburn 7827: $resulttext = &mt('Changes made:').'<ul>';
7828: foreach my $item (sort(keys(%changes))) {
7829: if ($item eq 'submitbugs') {
7830: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7831: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7832: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7833: }
7834: }
7835: $resulttext .= '</ul>';
7836: } else {
7837: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7838: $errors .= '<li><span class="LC_error">'.
7839: &mt('An error occurred storing the settings: [_1]',
7840: $putresult).'</span></li>';
1.166 raeburn 7841: }
1.118 jms 7842: }
7843: if ($errors) {
1.168 raeburn 7844: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7845: $errors.'</ul>';
7846: }
7847: return $resulttext;
7848: }
7849:
1.121 raeburn 7850: sub modify_coursedefaults {
7851: my ($dom,%domconfig) = @_;
7852: my ($resulttext,$errors,%changes,%defaultshash);
7853: my %defaultchecked = ('canuse_pdfforms' => 'off');
7854: my @offon = ('off','on');
7855: my @toggles = ('canuse_pdfforms');
7856:
7857: $defaultshash{'coursedefaults'} = {};
7858:
7859: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7860: if ($domconfig{'coursedefaults'} eq '') {
7861: $domconfig{'coursedefaults'} = {};
7862: }
7863: }
7864:
7865: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7866: foreach my $item (@toggles) {
7867: if ($defaultchecked{$item} eq 'on') {
7868: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7869: ($env{'form.'.$item} eq '0')) {
7870: $changes{$item} = 1;
7871: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7872: $changes{$item} = 1;
7873: }
7874: } elsif ($defaultchecked{$item} eq 'off') {
7875: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7876: ($env{'form.'.$item} eq '1')) {
7877: $changes{$item} = 1;
7878: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7879: $changes{$item} = 1;
7880: }
7881: }
7882: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7883: }
1.139 raeburn 7884: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7885: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7886: $newdefresponder =~ s/\D//g;
7887: if ($newdefresponder eq '' || $newdefresponder < 1) {
7888: $newdefresponder = 1;
7889: }
7890: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7891: if ($currdefresponder ne $newdefresponder) {
7892: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7893: $changes{'anonsurvey_threshold'} = 1;
7894: }
7895: }
1.121 raeburn 7896: }
7897: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7898: $dom);
7899: if ($putresult eq 'ok') {
7900: if (keys(%changes) > 0) {
7901: if ($changes{'canuse_pdfforms'}) {
7902: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7903: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7904: my $cachetime = 24*60*60;
7905: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7906: }
7907: $resulttext = &mt('Changes made:').'<ul>';
7908: foreach my $item (sort(keys(%changes))) {
7909: if ($item eq 'canuse_pdfforms') {
7910: if ($env{'form.'.$item} eq '1') {
7911: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7912: } else {
7913: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7914: }
1.139 raeburn 7915: } elsif ($item eq 'anonsurvey_threshold') {
7916: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7917: }
1.121 raeburn 7918: }
7919: $resulttext .= '</ul>';
7920: } else {
7921: $resulttext = &mt('No changes made to course defaults');
7922: }
7923: } else {
7924: $resulttext = '<span class="LC_error">'.
7925: &mt('An error occurred: [_1]',$putresult).'</span>';
7926: }
7927: return $resulttext;
7928: }
7929:
1.137 raeburn 7930: sub modify_usersessions {
7931: my ($dom,%domconfig) = @_;
1.145 raeburn 7932: my @hostingtypes = ('version','excludedomain','includedomain');
7933: my @offloadtypes = ('primary','default');
7934: my %types = (
7935: remote => \@hostingtypes,
7936: hosted => \@hostingtypes,
7937: spares => \@offloadtypes,
7938: );
7939: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7940: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7941: my (%by_ip,%by_location,@intdoms);
7942: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7943: my @locations = sort(keys(%by_location));
1.137 raeburn 7944: my (%defaultshash,%changes);
7945: foreach my $prefix (@prefixes) {
7946: $defaultshash{'usersessions'}{$prefix} = {};
7947: }
7948: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7949: my $resulttext;
1.138 raeburn 7950: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7951: foreach my $prefix (@prefixes) {
1.145 raeburn 7952: next if ($prefix eq 'spares');
7953: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7954: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7955: if ($type eq 'version') {
7956: my $value = $env{'form.'.$prefix.'_'.$type};
7957: my $okvalue;
7958: if ($value ne '') {
7959: if (grep(/^\Q$value\E$/,@lcversions)) {
7960: $okvalue = $value;
7961: }
7962: }
7963: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7964: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7965: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7966: if ($inuse == 0) {
7967: $changes{$prefix}{$type} = 1;
7968: } else {
7969: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7970: $changes{$prefix}{$type} = 1;
7971: }
7972: if ($okvalue ne '') {
7973: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7974: }
7975: }
7976: } else {
7977: if (($inuse == 1) && ($okvalue ne '')) {
7978: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7979: $changes{$prefix}{$type} = 1;
7980: }
7981: }
7982: } else {
7983: if (($inuse == 1) && ($okvalue ne '')) {
7984: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7985: $changes{$prefix}{$type} = 1;
7986: }
7987: }
7988: } else {
7989: if (($inuse == 1) && ($okvalue ne '')) {
7990: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7991: $changes{$prefix}{$type} = 1;
7992: }
7993: }
7994: } else {
7995: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7996: my @okvals;
7997: foreach my $val (@vals) {
1.138 raeburn 7998: if ($val =~ /:/) {
7999: my @items = split(/:/,$val);
8000: foreach my $item (@items) {
8001: if (ref($by_location{$item}) eq 'ARRAY') {
8002: push(@okvals,$item);
8003: }
8004: }
8005: } else {
8006: if (ref($by_location{$val}) eq 'ARRAY') {
8007: push(@okvals,$val);
8008: }
1.137 raeburn 8009: }
8010: }
8011: @okvals = sort(@okvals);
8012: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8013: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8014: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8015: if ($inuse == 0) {
8016: $changes{$prefix}{$type} = 1;
8017: } else {
8018: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8019: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8020: if (@changed > 0) {
8021: $changes{$prefix}{$type} = 1;
8022: }
8023: }
8024: } else {
8025: if ($inuse == 1) {
8026: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8027: $changes{$prefix}{$type} = 1;
8028: }
8029: }
8030: } else {
8031: if ($inuse == 1) {
8032: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8033: $changes{$prefix}{$type} = 1;
8034: }
8035: }
8036: } else {
8037: if ($inuse == 1) {
8038: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8039: $changes{$prefix}{$type} = 1;
8040: }
8041: }
8042: }
8043: }
8044: }
1.145 raeburn 8045:
8046: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8047: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8048: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8049: my $savespares;
8050:
8051: foreach my $lonhost (sort(keys(%servers))) {
8052: my $serverhomeID =
8053: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8054: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8055: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8056: my %spareschg;
8057: foreach my $type (@{$types{'spares'}}) {
8058: my @okspares;
8059: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8060: foreach my $server (@checked) {
1.152 raeburn 8061: if (&Apache::lonnet::hostname($server) ne '') {
8062: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8063: unless (grep(/^\Q$server\E$/,@okspares)) {
8064: push(@okspares,$server);
8065: }
1.145 raeburn 8066: }
8067: }
8068: }
8069: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8070: my $newspare;
1.152 raeburn 8071: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8072: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8073: $newspare = $new;
8074: }
8075: }
1.152 raeburn 8076: my @spares;
8077: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8078: @spares = sort(@okspares,$newspare);
8079: } else {
8080: @spares = sort(@okspares);
8081: }
8082: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8083: if (ref($spareid{$lonhost}) eq 'HASH') {
8084: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8085: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8086: if (@diffs > 0) {
8087: $spareschg{$type} = 1;
8088: }
8089: }
8090: }
8091: }
8092: if (keys(%spareschg) > 0) {
8093: $changes{'spares'}{$lonhost} = \%spareschg;
8094: }
8095: }
8096:
8097: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8098: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8099: if (ref($changes{'spares'}) eq 'HASH') {
8100: if (keys(%{$changes{'spares'}}) > 0) {
8101: $savespares = 1;
8102: }
8103: }
8104: } else {
8105: $savespares = 1;
8106: }
8107: }
8108:
1.147 raeburn 8109: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8110: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8111: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8112: $dom);
8113: if ($putresult eq 'ok') {
8114: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8115: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8116: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8117: }
8118: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8119: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8120: }
8121: }
8122: my $cachetime = 24*60*60;
8123: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8124: if (keys(%changes) > 0) {
8125: my %lt = &usersession_titles();
8126: $resulttext = &mt('Changes made:').'<ul>';
8127: foreach my $prefix (@prefixes) {
8128: if (ref($changes{$prefix}) eq 'HASH') {
8129: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8130: if ($prefix eq 'spares') {
8131: if (ref($changes{$prefix}) eq 'HASH') {
8132: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8133: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8134: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8135: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8136: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8137: foreach my $type (@{$types{$prefix}}) {
8138: if ($changes{$prefix}{$lonhost}{$type}) {
8139: my $offloadto = &mt('None');
8140: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8141: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8142: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8143: }
1.145 raeburn 8144: }
1.147 raeburn 8145: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8146: }
1.137 raeburn 8147: }
8148: }
1.147 raeburn 8149: $resulttext .= '</li>';
1.137 raeburn 8150: }
8151: }
1.147 raeburn 8152: } else {
8153: foreach my $type (@{$types{$prefix}}) {
8154: if (defined($changes{$prefix}{$type})) {
8155: my $newvalue;
8156: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8157: if (ref($defaultshash{'usersessions'}{$prefix})) {
8158: if ($type eq 'version') {
8159: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8160: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8161: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8162: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8163: }
1.145 raeburn 8164: }
8165: }
8166: }
1.147 raeburn 8167: if ($newvalue eq '') {
8168: if ($type eq 'version') {
8169: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8170: } else {
8171: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8172: }
1.145 raeburn 8173: } else {
1.147 raeburn 8174: if ($type eq 'version') {
8175: $newvalue .= ' '.&mt('(or later)');
8176: }
8177: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8178: }
1.137 raeburn 8179: }
8180: }
8181: }
1.147 raeburn 8182: $resulttext .= '</ul>';
1.137 raeburn 8183: }
8184: }
1.147 raeburn 8185: $resulttext .= '</ul>';
8186: } else {
8187: $resulttext = $nochgmsg;
1.137 raeburn 8188: }
8189: } else {
8190: $resulttext = '<span class="LC_error">'.
8191: &mt('An error occurred: [_1]',$putresult).'</span>';
8192: }
8193: } else {
1.147 raeburn 8194: $resulttext = $nochgmsg;
1.137 raeburn 8195: }
8196: return $resulttext;
8197: }
8198:
1.150 raeburn 8199: sub modify_loadbalancing {
8200: my ($dom,%domconfig) = @_;
8201: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8202: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8203: my ($othertitle,$usertypes,$types) =
8204: &Apache::loncommon::sorted_inst_types($dom);
8205: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8206: my @sparestypes = ('primary','default');
8207: my %typetitles = &sparestype_titles();
8208: my $resulttext;
1.171 raeburn 8209: my (%currbalancer,%currtargets,%currrules,%existing);
8210: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8211: %existing = %{$domconfig{'loadbalancing'}};
8212: }
8213: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8214: \%currtargets,\%currrules);
8215: my ($saveloadbalancing,%defaultshash,%changes);
8216: my ($alltypes,$othertypes,$titles) =
8217: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8218: my %ruletitles = &offloadtype_text();
8219: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8220: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8221: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8222: if ($balancer eq '') {
8223: next;
8224: }
8225: if (!exists($servers{$balancer})) {
8226: if (exists($currbalancer{$balancer})) {
8227: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8228: }
1.171 raeburn 8229: next;
8230: }
8231: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8232: push(@{$changes{'delete'}},$balancer);
8233: next;
8234: }
8235: if (!exists($currbalancer{$balancer})) {
8236: push(@{$changes{'add'}},$balancer);
8237: }
8238: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8239: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8240: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8241: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8242: $saveloadbalancing = 1;
8243: }
8244: foreach my $sparetype (@sparestypes) {
8245: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8246: my @offloadto;
8247: foreach my $target (@targets) {
8248: if (($servers{$target}) && ($target ne $balancer)) {
8249: if ($sparetype eq 'default') {
8250: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8251: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8252: }
8253: }
1.171 raeburn 8254: unless(grep(/^\Q$target\E$/,@offloadto)) {
8255: push(@offloadto,$target);
8256: }
1.150 raeburn 8257: }
1.171 raeburn 8258: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8259: }
8260: }
1.171 raeburn 8261: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8262: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8263: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8264: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8265: if (@targetdiffs > 0) {
1.171 raeburn 8266: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8267: }
1.171 raeburn 8268: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8269: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8270: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8271: }
8272: }
8273: }
8274: } else {
1.171 raeburn 8275: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8276: foreach my $sparetype (@sparestypes) {
8277: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8278: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8279: $changes{'curr'}{$balancer}{'targets'} = 1;
8280: }
1.150 raeburn 8281: }
8282: }
8283: }
8284: }
8285: my $ishomedom;
1.171 raeburn 8286: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8287: $ishomedom = 1;
1.150 raeburn 8288: }
8289: if (ref($alltypes) eq 'ARRAY') {
8290: foreach my $type (@{$alltypes}) {
8291: my $rule;
1.171 raeburn 8292: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8293: (!$ishomedom)) {
1.171 raeburn 8294: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8295: }
8296: if ($rule eq 'specific') {
8297: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8298: }
1.171 raeburn 8299: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8300: if (ref($currrules{$balancer}) eq 'HASH') {
8301: if ($rule ne $currrules{$balancer}{$type}) {
8302: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8303: }
8304: } elsif ($rule ne '') {
1.171 raeburn 8305: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8306: }
8307: }
8308: }
1.171 raeburn 8309: }
8310: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8311: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8312: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8313: $defaultshash{'loadbalancing'} = {};
8314: }
8315: my $putresult = &Apache::lonnet::put_dom('configuration',
8316: \%defaultshash,$dom);
8317:
8318: if ($putresult eq 'ok') {
8319: if (keys(%changes) > 0) {
8320: if (ref($changes{'delete'}) eq 'ARRAY') {
8321: foreach my $balancer (sort(@{$changes{'delete'}})) {
8322: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8323: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8324: }
1.171 raeburn 8325: }
8326: if (ref($changes{'add'}) eq 'ARRAY') {
8327: foreach my $balancer (sort(@{$changes{'add'}})) {
8328: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8329: }
8330: }
8331: if (ref($changes{'curr'}) eq 'HASH') {
8332: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8333: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8334: if ($changes{'curr'}{$balancer}{'targets'}) {
8335: my %offloadstr;
8336: foreach my $sparetype (@sparestypes) {
8337: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8338: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8339: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8340: }
8341: }
1.150 raeburn 8342: }
1.171 raeburn 8343: if (keys(%offloadstr) == 0) {
8344: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8345: } else {
1.171 raeburn 8346: my $showoffload;
8347: foreach my $sparetype (@sparestypes) {
8348: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8349: if (defined($offloadstr{$sparetype})) {
8350: $showoffload .= $offloadstr{$sparetype};
8351: } else {
8352: $showoffload .= &mt('None');
8353: }
8354: $showoffload .= (' 'x3);
8355: }
8356: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8357: }
8358: }
8359: }
1.171 raeburn 8360: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8361: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8362: foreach my $type (@{$alltypes}) {
8363: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8364: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8365: my $balancetext;
8366: if ($rule eq '') {
8367: $balancetext = $ruletitles{'default'};
8368: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8369: $balancetext = $ruletitles{$rule};
8370: } else {
8371: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8372: }
8373: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8374: }
8375: }
8376: }
8377: }
1.171 raeburn 8378: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8379: }
1.171 raeburn 8380: }
8381: if ($resulttext ne '') {
8382: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8383: } else {
8384: $resulttext = $nochgmsg;
8385: }
8386: } else {
1.171 raeburn 8387: $resulttext = $nochgmsg;
1.150 raeburn 8388: }
8389: } else {
1.171 raeburn 8390: $resulttext = '<span class="LC_error">'.
8391: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8392: }
8393: } else {
1.171 raeburn 8394: $resulttext = $nochgmsg;
1.150 raeburn 8395: }
8396: return $resulttext;
8397: }
8398:
1.48 raeburn 8399: sub recurse_check {
8400: my ($chkcats,$categories,$depth,$name) = @_;
8401: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8402: my $chg = 0;
8403: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8404: my $category = $chkcats->[$depth]{$name}[$j];
8405: my $item;
8406: if ($category eq '') {
8407: $chg ++;
8408: } else {
8409: my $deeper = $depth + 1;
8410: $item = &escape($category).':'.&escape($name).':'.$depth;
8411: if ($chg) {
8412: $categories->{$item} -= $chg;
8413: }
8414: &recurse_check($chkcats,$categories,$deeper,$category);
8415: $deeper --;
8416: }
8417: }
8418: }
8419: return;
8420: }
8421:
8422: sub recurse_cat_deletes {
8423: my ($item,$coursecategories,$deletions) = @_;
8424: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8425: my $subdepth = $depth + 1;
8426: if (ref($coursecategories) eq 'HASH') {
8427: foreach my $subitem (keys(%{$coursecategories})) {
8428: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8429: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8430: delete($coursecategories->{$subitem});
8431: $deletions->{$subitem} = 1;
8432: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8433: }
1.48 raeburn 8434: }
8435: }
8436: return;
8437: }
8438:
1.125 raeburn 8439: sub get_active_dcs {
8440: my ($dom) = @_;
8441: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8442: my %domcoords;
8443: my $numdcs = 0;
8444: my $now = time;
8445: foreach my $server (keys(%dompersonnel)) {
8446: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8447: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8448: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8449: if (($end eq '') || ($end == 0) || ($end > $now)) {
8450: if ($start <= $now) {
8451: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8452: }
8453: }
8454: }
8455: }
8456: return %domcoords;
8457: }
8458:
8459: sub active_dc_picker {
8460: my ($dom,$curr_dc) = @_;
8461: my %domcoords = &get_active_dcs($dom);
8462: my @dcs = sort(keys(%domcoords));
8463: my $numdcs = scalar(@dcs);
8464: my $datatable;
8465: my $numinrow = 2;
8466: if ($numdcs > 1) {
8467: $datatable = '<table>';
8468: for (my $i=0; $i<@dcs; $i++) {
8469: my $rem = $i%($numinrow);
8470: if ($rem == 0) {
8471: if ($i > 0) {
8472: $datatable .= '</tr>';
8473: }
8474: $datatable .= '<tr>';
8475: }
8476: my $check = ' ';
8477: if ($curr_dc eq '') {
8478: if (!$i) {
8479: $check = ' checked="checked" ';
8480: }
8481: } elsif ($dcs[$i] eq $curr_dc) {
8482: $check = ' checked="checked" ';
8483: }
8484: if ($i == @dcs - 1) {
8485: my $colsleft = $numinrow - $rem;
8486: if ($colsleft > 1) {
8487: $datatable .= '<td colspan="'.$colsleft.'">';
8488: } else {
8489: $datatable .= '<td>';
8490: }
8491: } else {
8492: $datatable .= '<td>';
8493: }
8494: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8495: $datatable .= '<span class="LC_nobreak"><label>'.
8496: '<input type="radio" name="autocreate_xmldc"'.
8497: ' value="'.$dcs[$i].'"'.$check.'/>'.
8498: &Apache::loncommon::plainname($dcname,$dcdom).
1.177 bisitz 8499: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8500: '</label></span></td>';
8501: }
8502: $datatable .= '</tr></table>';
8503: } elsif (@dcs) {
8504: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8505: $dcs[0].'" />';
8506: }
8507: return ($numdcs,$datatable);
8508: }
8509:
1.137 raeburn 8510: sub usersession_titles {
8511: return &Apache::lonlocal::texthash(
8512: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8513: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8514: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8515: version => 'LON-CAPA version requirement',
1.138 raeburn 8516: excludedomain => 'Allow all, but exclude specific domains',
8517: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8518: primary => 'Primary (checked first)',
1.154 raeburn 8519: default => 'Default',
1.137 raeburn 8520: );
8521: }
8522:
1.152 raeburn 8523: sub id_for_thisdom {
8524: my (%servers) = @_;
8525: my %altids;
8526: foreach my $server (keys(%servers)) {
8527: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8528: if ($serverhome ne $server) {
8529: $altids{$serverhome} = $server;
8530: }
8531: }
8532: return %altids;
8533: }
8534:
1.150 raeburn 8535: sub count_servers {
8536: my ($currbalancer,%servers) = @_;
8537: my (@spares,$numspares);
8538: foreach my $lonhost (sort(keys(%servers))) {
8539: next if ($currbalancer eq $lonhost);
8540: push(@spares,$lonhost);
8541: }
8542: if ($currbalancer) {
8543: $numspares = scalar(@spares);
8544: } else {
8545: $numspares = scalar(@spares) - 1;
8546: }
8547: return ($numspares,@spares);
8548: }
8549:
8550: sub lonbalance_targets_js {
1.171 raeburn 8551: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8552: my $select = &mt('Select');
8553: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8554: if (ref($servers) eq 'HASH') {
8555: $alltargets = join("','",sort(keys(%{$servers})));
8556: my @homedoms;
8557: foreach my $server (sort(keys(%{$servers}))) {
8558: if (&Apache::lonnet::host_domain($server) eq $dom) {
8559: push(@homedoms,'1');
8560: } else {
8561: push(@homedoms,'0');
8562: }
8563: }
8564: $allishome = join("','",@homedoms);
8565: }
8566: if (ref($types) eq 'ARRAY') {
8567: if (@{$types} > 0) {
8568: @alltypes = @{$types};
8569: }
8570: }
8571: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8572: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8573: my (%currbalancer,%currtargets,%currrules,%existing);
8574: if (ref($settings) eq 'HASH') {
8575: %existing = %{$settings};
8576: }
8577: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8578: \%currtargets,\%currrules);
8579: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8580: return <<"END";
8581:
8582: <script type="text/javascript">
8583: // <![CDATA[
8584:
1.171 raeburn 8585: currBalancers = new Array('$balancers');
8586:
8587: function toggleTargets(balnum) {
8588: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8589: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8590: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8591: var prevbalancer = prevhostitem.value;
8592: var baltotal = document.getElementById('loadbalancing_total').value;
8593: prevhostitem.value = balancer;
8594: if (prevbalancer != '') {
8595: var prevIdx = currBalancers.indexOf(prevbalancer);
8596: if (prevIdx != -1) {
8597: currBalancers.splice(prevIdx,1);
8598: }
8599: }
1.150 raeburn 8600: if (balancer == '') {
1.171 raeburn 8601: hideSpares(balnum);
1.150 raeburn 8602: } else {
1.171 raeburn 8603: var currIdx = currBalancers.indexOf(balancer);
8604: if (currIdx == -1) {
8605: currBalancers.push(balancer);
8606: }
1.150 raeburn 8607: var homedoms = new Array('$allishome');
1.171 raeburn 8608: var ishomedom = homedoms[lonhostitem.selectedIndex];
8609: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8610: }
1.171 raeburn 8611: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8612: return;
8613: }
8614:
1.171 raeburn 8615: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8616: var alltargets = new Array('$alltargets');
8617: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8618: var offloadtypes = new Array('primary','default');
8619:
1.171 raeburn 8620: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8621: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8622:
1.151 raeburn 8623: for (var i=0; i<offloadtypes.length; i++) {
8624: var count = 0;
8625: for (var j=0; j<alltargets.length; j++) {
8626: if (alltargets[j] != balancer) {
1.171 raeburn 8627: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8628: item.value = alltargets[j];
8629: item.style.textAlign='left';
8630: item.style.textFace='normal';
8631: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8632: if (currBalancers.indexOf(alltargets[j]) == -1) {
8633: item.disabled = '';
8634: } else {
8635: item.disabled = 'disabled';
8636: item.checked = false;
8637: }
1.151 raeburn 8638: count ++;
8639: }
1.150 raeburn 8640: }
8641: }
1.151 raeburn 8642: for (var k=0; k<insttypes.length; k++) {
8643: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8644: if (ishomedom == 1) {
1.171 raeburn 8645: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8646: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8647: } else {
1.171 raeburn 8648: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8649: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8650:
8651: }
8652: } else {
1.171 raeburn 8653: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8654: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8655: }
1.151 raeburn 8656: if ((insttypes[k] != '_LC_external') &&
8657: ((insttypes[k] != '_LC_internetdom') ||
8658: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8659: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8660: item.options.length = 0;
8661: item.options[0] = new Option("","",true,true);
8662: var idx = 0;
1.151 raeburn 8663: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8664: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8665: idx ++;
8666: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8667:
1.150 raeburn 8668: }
8669: }
8670: }
8671: }
8672: return;
8673: }
8674:
1.171 raeburn 8675: function hideSpares(balnum) {
1.150 raeburn 8676: var alltargets = new Array('$alltargets');
8677: var insttypes = new Array('$allinsttypes');
8678: var offloadtypes = new Array('primary','default');
8679:
1.171 raeburn 8680: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8681: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8682:
8683: var total = alltargets.length - 1;
8684: for (var i=0; i<offloadtypes; i++) {
8685: for (var j=0; j<total; j++) {
1.171 raeburn 8686: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8687: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8688: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8689: }
1.150 raeburn 8690: }
8691: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8692: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8693: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8694: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8695: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8696: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8697: }
8698: }
8699: return;
8700: }
8701:
1.171 raeburn 8702: function checkOffloads(item,balnum,type) {
1.150 raeburn 8703: var alltargets = new Array('$alltargets');
8704: var offloadtypes = new Array('primary','default');
8705: if (item.checked) {
8706: var total = alltargets.length - 1;
8707: var other;
8708: if (type == offloadtypes[0]) {
1.151 raeburn 8709: other = offloadtypes[1];
1.150 raeburn 8710: } else {
1.151 raeburn 8711: other = offloadtypes[0];
1.150 raeburn 8712: }
8713: for (var i=0; i<total; i++) {
1.171 raeburn 8714: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8715: if (server == item.value) {
1.171 raeburn 8716: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8717: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8718: }
8719: }
8720: }
8721: }
8722: return;
8723: }
8724:
1.171 raeburn 8725: function singleServerToggle(balnum,type) {
8726: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8727: if (offloadtoSelIdx == 0) {
1.171 raeburn 8728: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8729: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8730:
8731: } else {
1.171 raeburn 8732: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8733: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8734: }
8735: return;
8736: }
8737:
1.171 raeburn 8738: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8739: if (type == '_LC_external') {
1.171 raeburn 8740: return;
1.150 raeburn 8741: }
1.171 raeburn 8742: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8743: for (var i=0; i<typesRules.length; i++) {
8744: if (formname.elements[typesRules[i]].checked) {
8745: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8746: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8747: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8748: } else {
1.171 raeburn 8749: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8750: }
8751: }
8752: }
8753: return;
8754: }
8755:
8756: function balancerDeleteChange(balnum) {
8757: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8758: var baltotal = document.getElementById('loadbalancing_total').value;
8759: var addtarget;
8760: var removetarget;
8761: var action = 'delete';
8762: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8763: var lonhost = hostitem.value;
8764: var currIdx = currBalancers.indexOf(lonhost);
8765: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8766: if (currIdx != -1) {
8767: currBalancers.splice(currIdx,1);
8768: }
8769: addtarget = lonhost;
8770: } else {
8771: if (currIdx == -1) {
8772: currBalancers.push(lonhost);
8773: }
8774: removetarget = lonhost;
8775: action = 'undelete';
8776: }
8777: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8778: }
8779: return;
8780: }
8781:
8782: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8783: if (baltotal > 1) {
8784: var offloadtypes = new Array('primary','default');
8785: var alltargets = new Array('$alltargets');
8786: var insttypes = new Array('$allinsttypes');
8787: for (var i=0; i<baltotal; i++) {
8788: if (i != balnum) {
8789: for (var j=0; j<offloadtypes.length; j++) {
8790: var total = alltargets.length - 1;
8791: for (var k=0; k<total; k++) {
8792: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8793: var server = serveritem.value;
8794: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8795: if (server == addtarget) {
8796: serveritem.disabled = '';
8797: }
8798: }
8799: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8800: if (server == removetarget) {
8801: serveritem.disabled = 'disabled';
8802: serveritem.checked = false;
8803: }
8804: }
8805: }
8806: }
8807: for (var j=0; j<insttypes.length; j++) {
8808: if (insttypes[j] != '_LC_external') {
8809: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8810: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8811: var currSel = singleserver.selectedIndex;
8812: var currVal = singleserver.options[currSel].value;
8813: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8814: var numoptions = singleserver.options.length;
8815: var needsnew = 1;
8816: for (var k=0; k<numoptions; k++) {
8817: if (singleserver.options[k] == addtarget) {
8818: needsnew = 0;
8819: break;
8820: }
8821: }
8822: if (needsnew == 1) {
8823: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8824: }
8825: }
8826: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8827: singleserver.options.length = 0;
8828: if ((currVal) && (currVal != removetarget)) {
8829: singleserver.options[0] = new Option("","",false,false);
8830: } else {
8831: singleserver.options[0] = new Option("","",true,true);
8832: }
8833: var idx = 0;
8834: for (var m=0; m<alltargets.length; m++) {
8835: if (currBalancers.indexOf(alltargets[m]) == -1) {
8836: idx ++;
8837: if (currVal == alltargets[m]) {
8838: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8839: } else {
8840: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8841: }
8842: }
8843: }
8844: }
8845: }
8846: }
8847: }
1.150 raeburn 8848: }
8849: }
8850: }
8851: return;
8852: }
8853:
1.152 raeburn 8854: // ]]>
8855: </script>
8856:
8857: END
8858: }
8859:
8860: sub new_spares_js {
8861: my @sparestypes = ('primary','default');
8862: my $types = join("','",@sparestypes);
8863: my $select = &mt('Select');
8864: return <<"END";
8865:
8866: <script type="text/javascript">
8867: // <![CDATA[
8868:
8869: function updateNewSpares(formname,lonhost) {
8870: var types = new Array('$types');
8871: var include = new Array();
8872: var exclude = new Array();
8873: for (var i=0; i<types.length; i++) {
8874: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8875: for (var j=0; j<spareboxes.length; j++) {
8876: if (formname.elements[spareboxes[j]].checked) {
8877: exclude.push(formname.elements[spareboxes[j]].value);
8878: } else {
8879: include.push(formname.elements[spareboxes[j]].value);
8880: }
8881: }
8882: }
8883: for (var i=0; i<types.length; i++) {
8884: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8885: var selIdx = newSpare.selectedIndex;
8886: var currnew = newSpare.options[selIdx].value;
8887: var okSpares = new Array();
8888: for (var j=0; j<newSpare.options.length; j++) {
8889: var possible = newSpare.options[j].value;
8890: if (possible != '') {
8891: if (exclude.indexOf(possible) == -1) {
8892: okSpares.push(possible);
8893: } else {
8894: if (currnew == possible) {
8895: selIdx = 0;
8896: }
8897: }
8898: }
8899: }
8900: for (var k=0; k<include.length; k++) {
8901: if (okSpares.indexOf(include[k]) == -1) {
8902: okSpares.push(include[k]);
8903: }
8904: }
8905: okSpares.sort();
8906: newSpare.options.length = 0;
8907: if (selIdx == 0) {
8908: newSpare.options[0] = new Option("$select","",true,true);
8909: } else {
8910: newSpare.options[0] = new Option("$select","",false,false);
8911: }
8912: for (var m=0; m<okSpares.length; m++) {
8913: var idx = m+1;
8914: var selThis = 0;
8915: if (selIdx != 0) {
8916: if (okSpares[m] == currnew) {
8917: selThis = 1;
8918: }
8919: }
8920: if (selThis == 1) {
8921: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8922: } else {
8923: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8924: }
8925: }
8926: }
8927: return;
8928: }
8929:
8930: function checkNewSpares(lonhost,type) {
8931: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8932: var chosen = newSpare.options[newSpare.selectedIndex].value;
8933: if (chosen != '') {
8934: var othertype;
8935: var othernewSpare;
8936: if (type == 'primary') {
8937: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8938: }
8939: if (type == 'default') {
8940: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8941: }
8942: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8943: othernewSpare.selectedIndex = 0;
8944: }
8945: }
8946: return;
8947: }
8948:
8949: // ]]>
8950: </script>
8951:
8952: END
8953:
8954: }
8955:
8956: sub common_domprefs_js {
8957: return <<"END";
8958:
8959: <script type="text/javascript">
8960: // <![CDATA[
8961:
1.150 raeburn 8962: function getIndicesByName(formname,item) {
1.152 raeburn 8963: var group = new Array();
1.150 raeburn 8964: for (var i=0;i<formname.elements.length;i++) {
8965: if (formname.elements[i].name == item) {
1.152 raeburn 8966: group.push(formname.elements[i].id);
1.150 raeburn 8967: }
8968: }
1.152 raeburn 8969: return group;
1.150 raeburn 8970: }
8971:
8972: // ]]>
8973: </script>
8974:
8975: END
1.152 raeburn 8976:
1.150 raeburn 8977: }
8978:
1.165 raeburn 8979: sub recaptcha_js {
8980: my %lt = &captcha_phrases();
8981: return <<"END";
8982:
8983: <script type="text/javascript">
8984: // <![CDATA[
8985:
8986: function updateCaptcha(caller,context) {
8987: var privitem;
8988: var pubitem;
8989: var privtext;
8990: var pubtext;
8991: if (document.getElementById(context+'_recaptchapub')) {
8992: pubitem = document.getElementById(context+'_recaptchapub');
8993: } else {
8994: return;
8995: }
8996: if (document.getElementById(context+'_recaptchapriv')) {
8997: privitem = document.getElementById(context+'_recaptchapriv');
8998: } else {
8999: return;
9000: }
9001: if (document.getElementById(context+'_recaptchapubtxt')) {
9002: pubtext = document.getElementById(context+'_recaptchapubtxt');
9003: } else {
9004: return;
9005: }
9006: if (document.getElementById(context+'_recaptchaprivtxt')) {
9007: privtext = document.getElementById(context+'_recaptchaprivtxt');
9008: } else {
9009: return;
9010: }
9011: if (caller.checked) {
9012: if (caller.value == 'recaptcha') {
9013: pubitem.type = 'text';
9014: privitem.type = 'text';
9015: pubitem.size = '40';
9016: privitem.size = '40';
9017: pubtext.innerHTML = "$lt{'pub'}";
9018: privtext.innerHTML = "$lt{'priv'}";
9019: } else {
9020: pubitem.type = 'hidden';
9021: privitem.type = 'hidden';
9022: pubtext.innerHTML = '';
9023: privtext.innerHTML = '';
9024: }
9025: }
9026: return;
9027: }
9028:
9029: // ]]>
9030: </script>
9031:
9032: END
9033:
9034: }
9035:
9036: sub captcha_phrases {
9037: return &Apache::lonlocal::texthash (
9038: priv => 'Private key',
9039: pub => 'Public key',
9040: original => 'original (CAPTCHA)',
9041: recaptcha => 'successor (ReCAPTCHA)',
9042: notused => 'unused',
9043: );
9044: }
9045:
1.3 raeburn 9046: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>