Annotation of loncom/interface/domainprefs.pm, revision 1.182
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.182 ! raeburn 4: # $Id: domainprefs.pm,v 1.181 2012/12/20 13:23:49 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') {
1.181 raeburn 439: &Apache::lonconfigsettings::print_header($r,$phase,$context);
440: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
441: $confname).
442: '<br />'
443: );
1.180 raeburn 444: if ($switchserver) {
1.181 raeburn 445: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
446: '<br />'.
447: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
448: '<br />'.
449: &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).
450: '<br />'.
451: &mt('To do that now, use the following link: [_1]',$switchserver)
452: );
453: } else {
454: $r->print(&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.').
455: '<br />'.
456: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
457: );
1.180 raeburn 458: }
459: $r->print(&Apache::loncommon::end_page());
460: return OK;
461: }
1.21 raeburn 462: if (keys(%domconfig) == 0) {
463: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 464: my @ids=&Apache::lonnet::current_machine_ids();
465: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 466: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 467: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 468: my $custom_img_count = 0;
469: foreach my $img (@loginimages) {
470: if ($designhash{$dom.'.login.'.$img} ne '') {
471: $custom_img_count ++;
472: }
473: }
474: foreach my $role (@roles) {
475: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
476: $custom_img_count ++;
477: }
478: }
479: if ($custom_img_count > 0) {
1.94 raeburn 480: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 481: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 482: $r->print(
483: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
484: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
485: &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 />'.
486: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
487: if ($switch_server) {
1.30 raeburn 488: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 489: }
1.91 raeburn 490: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 491: return OK;
492: }
493: }
494: }
1.174 foxr 495:
1.91 raeburn 496: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 497: }
498: return OK;
499: }
500:
501: sub process_changes {
1.92 raeburn 502: my ($r,$dom,$confname,$action,$roles,$values) = @_;
503: my %domconfig;
504: if (ref($values) eq 'HASH') {
505: %domconfig = %{$values};
506: }
1.3 raeburn 507: my $output;
508: if ($action eq 'login') {
1.9 raeburn 509: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 510: } elsif ($action eq 'rolecolors') {
1.9 raeburn 511: $output = &modify_rolecolors($r,$dom,$confname,$roles,
512: %domconfig);
1.3 raeburn 513: } elsif ($action eq 'quotas') {
1.86 raeburn 514: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 515: } elsif ($action eq 'autoenroll') {
516: $output = &modify_autoenroll($dom,%domconfig);
517: } elsif ($action eq 'autoupdate') {
518: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 519: } elsif ($action eq 'autocreate') {
520: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 521: } elsif ($action eq 'directorysrch') {
522: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 523: } elsif ($action eq 'usercreation') {
1.28 raeburn 524: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 525: } elsif ($action eq 'usermodification') {
526: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 527: } elsif ($action eq 'contacts') {
528: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 529: } elsif ($action eq 'defaults') {
530: $output = &modify_defaults($dom,$r);
1.46 raeburn 531: } elsif ($action eq 'scantron') {
1.48 raeburn 532: $output = &modify_scantron($r,$dom,$confname,%domconfig);
533: } elsif ($action eq 'coursecategories') {
534: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 535: } elsif ($action eq 'serverstatuses') {
536: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 537: } elsif ($action eq 'requestcourses') {
538: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 539: } elsif ($action eq 'requestauthor') {
540: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 541: } elsif ($action eq 'helpsettings') {
1.122 jms 542: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 543: } elsif ($action eq 'coursedefaults') {
544: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 545: } elsif ($action eq 'usersessions') {
546: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 547: } elsif ($action eq 'loadbalancing') {
548: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 549: }
550: return $output;
551: }
552:
553: sub print_config_box {
1.9 raeburn 554: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 555: my $rowtotal = 0;
1.49 raeburn 556: my $output;
1.174 foxr 557:
1.49 raeburn 558: if ($action eq 'coursecategories') {
559: $output = &coursecategories_javascript($settings);
1.91 raeburn 560: }
1.49 raeburn 561: $output .=
1.30 raeburn 562: '<table class="LC_nested_outer">
1.3 raeburn 563: <tr>
1.66 raeburn 564: <th align="left" valign="middle"><span class="LC_nobreak">'.
565: &mt($item->{text}).' '.
566: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
567: '</tr>';
1.30 raeburn 568: $rowtotal ++;
1.110 raeburn 569: my $numheaders = 1;
570: if (ref($item->{'header'}) eq 'ARRAY') {
571: $numheaders = scalar(@{$item->{'header'}});
572: }
573: if ($numheaders > 1) {
1.64 raeburn 574: my $colspan = '';
1.145 raeburn 575: my $rightcolspan = '';
1.168 raeburn 576: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
577: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 578: $colspan = ' colspan="2"';
579: }
1.145 raeburn 580: if ($action eq 'usersessions') {
581: $rightcolspan = ' colspan="3"';
582: }
1.30 raeburn 583: $output .= '
1.3 raeburn 584: <tr>
585: <td>
586: <table class="LC_nested">
587: <tr class="LC_info_row">
1.59 bisitz 588: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 589: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 590: </tr>';
1.69 raeburn 591: $rowtotal ++;
1.6 raeburn 592: if ($action eq 'autoupdate') {
1.30 raeburn 593: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 594: } elsif ($action eq 'usercreation') {
1.33 raeburn 595: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
596: } elsif ($action eq 'usermodification') {
597: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 598: } elsif ($action eq 'coursecategories') {
599: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 600: } elsif ($action eq 'login') {
1.168 raeburn 601: if ($numheaders == 3) {
602: $colspan = ' colspan="2"';
603: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
604: } else {
605: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
606: }
1.102 raeburn 607: } elsif ($action eq 'requestcourses') {
608: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 609: } elsif ($action eq 'requestauthor') {
610: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 611: } elsif ($action eq 'usersessions') {
612: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 613: } elsif ($action eq 'rolecolors') {
1.30 raeburn 614: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 615: } elsif ($action eq 'coursedefaults') {
616: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 617: }
1.30 raeburn 618: $output .= '
1.6 raeburn 619: </table>
620: </td>
621: </tr>
622: <tr>
623: <td>
624: <table class="LC_nested">
625: <tr class="LC_info_row">
1.59 bisitz 626: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 627: $output .= '
1.59 bisitz 628: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 629: </tr>';
630: $rowtotal ++;
1.6 raeburn 631: if ($action eq 'autoupdate') {
1.131 raeburn 632: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
633: </table>
634: </td>
635: </tr>
636: <tr>
637: <td>
638: <table class="LC_nested">
639: <tr class="LC_info_row">
640: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
641: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
642: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
643: $rowtotal ++;
1.28 raeburn 644: } elsif ($action eq 'usercreation') {
1.34 raeburn 645: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
646: </table>
647: </td>
648: </tr>
649: <tr>
650: <td>
651: <table class="LC_nested">
652: <tr class="LC_info_row">
1.59 bisitz 653: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
654: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 655: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
656: $rowtotal ++;
1.33 raeburn 657: } elsif ($action eq 'usermodification') {
1.63 raeburn 658: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
659: </table>
660: </td>
661: </tr>
662: <tr>
663: <td>
664: <table class="LC_nested">
665: <tr class="LC_info_row">
666: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
667: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
668: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
669: $rowtotal ++;
1.57 raeburn 670: } elsif ($action eq 'coursecategories') {
671: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 672: } elsif ($action eq 'login') {
1.168 raeburn 673: if ($numheaders == 3) {
674: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
675: </table>
676: </td>
677: </tr>
678: <tr>
679: <td>
680: <table class="LC_nested">
681: <tr class="LC_info_row">
682: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
683: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
684: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
685: $rowtotal ++;
686: } else {
687: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
688: }
1.102 raeburn 689: } elsif ($action eq 'requestcourses') {
1.163 raeburn 690: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
691: } elsif ($action eq 'requestauthor') {
692: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 693: } elsif ($action eq 'usersessions') {
1.145 raeburn 694: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
695: </table>
696: </td>
697: </tr>
698: <tr>
699: <td>
700: <table class="LC_nested">
701: <tr class="LC_info_row">
702: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
703: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
704: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
705: $rowtotal ++;
1.139 raeburn 706: } elsif ($action eq 'coursedefaults') {
707: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 708: } elsif ($action eq 'rolecolors') {
1.30 raeburn 709: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 710: </table>
711: </td>
712: </tr>
713: <tr>
714: <td>
715: <table class="LC_nested">
716: <tr class="LC_info_row">
1.69 raeburn 717: <td class="LC_left_item"'.$colspan.' valign="top">'.
718: &mt($item->{'header'}->[2]->{'col1'}).'</td>
719: <td class="LC_right_item" valign="top">'.
720: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 721: </tr>'.
1.30 raeburn 722: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 723: </table>
724: </td>
725: </tr>
726: <tr>
727: <td>
728: <table class="LC_nested">
729: <tr class="LC_info_row">
1.59 bisitz 730: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
731: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 732: </tr>'.
1.30 raeburn 733: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
734: $rowtotal += 2;
1.6 raeburn 735: }
1.3 raeburn 736: } else {
1.30 raeburn 737: $output .= '
1.3 raeburn 738: <tr>
739: <td>
740: <table class="LC_nested">
1.30 raeburn 741: <tr class="LC_info_row">';
1.24 raeburn 742: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 743: $output .= '
1.59 bisitz 744: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 745: } elsif ($action eq 'serverstatuses') {
746: $output .= '
747: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
748: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
749:
1.6 raeburn 750: } else {
1.30 raeburn 751: $output .= '
1.69 raeburn 752: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
753: }
1.72 raeburn 754: if (defined($item->{'header'}->[0]->{'col3'})) {
755: $output .= '<td class="LC_left_item" valign="top">'.
756: &mt($item->{'header'}->[0]->{'col2'});
757: if ($action eq 'serverstatuses') {
758: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
759: }
1.69 raeburn 760: } else {
761: $output .= '<td class="LC_right_item" valign="top">'.
762: &mt($item->{'header'}->[0]->{'col2'});
763: }
764: $output .= '</td>';
765: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 766: if (defined($item->{'header'}->[0]->{'col4'})) {
767: $output .= '<td class="LC_left_item" valign="top">'.
768: &mt($item->{'header'}->[0]->{'col3'});
769: } else {
770: $output .= '<td class="LC_right_item" valign="top">'.
771: &mt($item->{'header'}->[0]->{'col3'});
772: }
1.69 raeburn 773: if ($action eq 'serverstatuses') {
774: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
775: }
776: $output .= '</td>';
1.6 raeburn 777: }
1.150 raeburn 778: if ($item->{'header'}->[0]->{'col4'}) {
779: $output .= '<td class="LC_right_item" valign="top">'.
780: &mt($item->{'header'}->[0]->{'col4'});
781: }
1.69 raeburn 782: $output .= '</tr>';
1.48 raeburn 783: $rowtotal ++;
1.168 raeburn 784: if ($action eq 'quotas') {
1.86 raeburn 785: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 786: } elsif ($action eq 'autoenroll') {
1.30 raeburn 787: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 788: } elsif ($action eq 'autocreate') {
789: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 790: } elsif ($action eq 'directorysrch') {
1.30 raeburn 791: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 792: } elsif ($action eq 'contacts') {
1.30 raeburn 793: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 794: } elsif ($action eq 'defaults') {
795: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 796: } elsif ($action eq 'scantron') {
797: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 798: } elsif ($action eq 'serverstatuses') {
799: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 800: } elsif ($action eq 'helpsettings') {
1.168 raeburn 801: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 802: } elsif ($action eq 'loadbalancing') {
803: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 804: }
1.3 raeburn 805: }
1.30 raeburn 806: $output .= '
1.3 raeburn 807: </table>
808: </td>
809: </tr>
1.30 raeburn 810: </table><br />';
811: return ($output,$rowtotal);
1.1 raeburn 812: }
813:
1.3 raeburn 814: sub print_login {
1.168 raeburn 815: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 816: my ($css_class,$datatable);
1.6 raeburn 817: my %choices = &login_choices();
1.110 raeburn 818:
1.168 raeburn 819: if ($caller eq 'service') {
1.149 raeburn 820: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 821: my $choice = $choices{'disallowlogin'};
822: $css_class = ' class="LC_odd_row"';
1.128 raeburn 823: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 824: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 825: '<th>'.$choices{'server'}.'</th>'.
826: '<th>'.$choices{'serverpath'}.'</th>'.
827: '<th>'.$choices{'custompath'}.'</th>'.
828: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 829: my %disallowed;
830: if (ref($settings) eq 'HASH') {
831: if (ref($settings->{'loginvia'}) eq 'HASH') {
832: %disallowed = %{$settings->{'loginvia'}};
833: }
834: }
835: foreach my $lonhost (sort(keys(%servers))) {
836: my $direct = 'selected="selected"';
1.128 raeburn 837: if (ref($disallowed{$lonhost}) eq 'HASH') {
838: if ($disallowed{$lonhost}{'server'} ne '') {
839: $direct = '';
840: }
1.110 raeburn 841: }
1.115 raeburn 842: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 843: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 844: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
845: '</option>';
1.177 bisitz 846: foreach my $hostid (sort keys(%servers)) {
1.115 raeburn 847: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 848: my $selected = '';
1.128 raeburn 849: if (ref($disallowed{$lonhost}) eq 'HASH') {
850: if ($hostid eq $disallowed{$lonhost}{'server'}) {
851: $selected = 'selected="selected"';
852: }
1.110 raeburn 853: }
854: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
855: $servers{$hostid}.'</option>';
856: }
1.128 raeburn 857: $datatable .= '</select></td>'.
858: '<td><select name="'.$lonhost.'_serverpath">';
859: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
860: my $pathname = $path;
861: if ($path eq 'custom') {
862: $pathname = &mt('Custom Path').' ->';
863: }
864: my $selected = '';
865: if (ref($disallowed{$lonhost}) eq 'HASH') {
866: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
867: $selected = 'selected="selected"';
868: }
869: } elsif ($path eq '') {
870: $selected = 'selected="selected"';
871: }
872: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
873: }
874: $datatable .= '</select></td>';
875: my ($custom,$exempt);
876: if (ref($disallowed{$lonhost}) eq 'HASH') {
877: $custom = $disallowed{$lonhost}{'custompath'};
878: $exempt = $disallowed{$lonhost}{'exempt'};
879: }
880: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
881: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
882: '</tr>';
1.110 raeburn 883: }
884: $datatable .= '</table></td></tr>';
885: return $datatable;
1.168 raeburn 886: } elsif ($caller eq 'page') {
887: my %defaultchecked = (
888: 'coursecatalog' => 'on',
889: 'adminmail' => 'off',
890: 'newuser' => 'off',
891: );
892: my @toggles = ('coursecatalog','adminmail','newuser');
893: my (%checkedon,%checkedoff);
1.42 raeburn 894: foreach my $item (@toggles) {
1.168 raeburn 895: if ($defaultchecked{$item} eq 'on') {
896: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 897: $checkedoff{$item} = ' ';
1.168 raeburn 898: } elsif ($defaultchecked{$item} eq 'off') {
899: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 900: $checkedon{$item} = ' ';
901: }
1.1 raeburn 902: }
1.168 raeburn 903: my @images = ('img','logo','domlogo','login');
904: my @logintext = ('textcol','bgcol');
905: my @bgs = ('pgbg','mainbg','sidebg');
906: my @links = ('link','alink','vlink');
907: my %designhash = &Apache::loncommon::get_domainconf($dom);
908: my %defaultdesign = %Apache::loncommon::defaultdesign;
909: my (%is_custom,%designs);
910: my %defaults = (
911: font => $defaultdesign{'login.font'},
912: );
1.6 raeburn 913: foreach my $item (@images) {
1.168 raeburn 914: $defaults{$item} = $defaultdesign{'login.'.$item};
915: $defaults{'showlogo'}{$item} = 1;
916: }
917: foreach my $item (@bgs) {
918: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 919: }
1.41 raeburn 920: foreach my $item (@logintext) {
1.168 raeburn 921: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 922: }
1.168 raeburn 923: foreach my $item (@links) {
924: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 925: }
1.168 raeburn 926: if (ref($settings) eq 'HASH') {
927: foreach my $item (@toggles) {
928: if ($settings->{$item} eq '1') {
929: $checkedon{$item} = ' checked="checked" ';
930: $checkedoff{$item} = ' ';
931: } elsif ($settings->{$item} eq '0') {
932: $checkedoff{$item} = ' checked="checked" ';
933: $checkedon{$item} = ' ';
934: }
935: }
936: foreach my $item (@images) {
937: if (defined($settings->{$item})) {
938: $designs{$item} = $settings->{$item};
939: $is_custom{$item} = 1;
940: }
941: if (defined($settings->{'showlogo'}{$item})) {
942: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
943: }
944: }
945: foreach my $item (@logintext) {
946: if ($settings->{$item} ne '') {
947: $designs{'logintext'}{$item} = $settings->{$item};
948: $is_custom{$item} = 1;
949: }
950: }
951: if ($settings->{'font'} ne '') {
952: $designs{'font'} = $settings->{'font'};
953: $is_custom{'font'} = 1;
954: }
955: foreach my $item (@bgs) {
956: if ($settings->{$item} ne '') {
957: $designs{'bgs'}{$item} = $settings->{$item};
958: $is_custom{$item} = 1;
959: }
960: }
961: foreach my $item (@links) {
962: if ($settings->{$item} ne '') {
963: $designs{'links'}{$item} = $settings->{$item};
964: $is_custom{$item} = 1;
965: }
966: }
967: } else {
968: if ($designhash{$dom.'.login.font'} ne '') {
969: $designs{'font'} = $designhash{$dom.'.login.font'};
970: $is_custom{'font'} = 1;
971: }
972: foreach my $item (@images) {
973: if ($designhash{$dom.'.login.'.$item} ne '') {
974: $designs{$item} = $designhash{$dom.'.login.'.$item};
975: $is_custom{$item} = 1;
976: }
977: }
978: foreach my $item (@bgs) {
979: if ($designhash{$dom.'.login.'.$item} ne '') {
980: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
981: $is_custom{$item} = 1;
982: }
1.6 raeburn 983: }
1.168 raeburn 984: foreach my $item (@links) {
985: if ($designhash{$dom.'.login.'.$item} ne '') {
986: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
987: $is_custom{$item} = 1;
988: }
1.6 raeburn 989: }
990: }
1.168 raeburn 991: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
992: logo => 'Institution Logo',
993: domlogo => 'Domain Logo',
994: login => 'Login box');
995: my $itemcount = 1;
996: foreach my $item (@toggles) {
997: $css_class = $itemcount%2?' class="LC_odd_row"':'';
998: $datatable .=
999: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1000: '</td><td>'.
1001: '<span class="LC_nobreak"><label><input type="radio" name="'.
1002: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1003: '</label> <label><input type="radio" name="'.$item.'"'.
1004: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1005: '</tr>';
1006: $itemcount ++;
1.6 raeburn 1007: }
1.168 raeburn 1008: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1009: $datatable .= '</tr></table></td></tr>';
1010: } elsif ($caller eq 'help') {
1011: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1012: my $switchserver = &check_switchserver($dom,$confname);
1013: my $itemcount = 1;
1014: $defaulturl = '/adm/loginproblems.html';
1015: $defaulttype = 'default';
1016: %lt = &Apache::lonlocal::texthash (
1017: del => 'Delete?',
1018: rep => 'Replace:',
1019: upl => 'Upload:',
1020: default => 'Default',
1021: custom => 'Custom',
1022: );
1023: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1024: my @currlangs;
1025: if (ref($settings) eq 'HASH') {
1026: if (ref($settings->{'helpurl'}) eq 'HASH') {
1027: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1028: next if ($settings->{'helpurl'}{$key} eq '');
1029: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1030: $type{$key} = 'custom';
1031: unless ($key eq 'nolang') {
1032: push(@currlangs,$key);
1033: }
1034: }
1035: } elsif ($settings->{'helpurl'} ne '') {
1036: $type{'nolang'} = 'custom';
1037: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1038: }
1039: }
1.168 raeburn 1040: foreach my $lang ('nolang',sort(@currlangs)) {
1041: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1042: $datatable .= '<tr'.$css_class.'>';
1043: if ($url{$lang} eq '') {
1044: $url{$lang} = $defaulturl;
1045: }
1046: if ($type{$lang} eq '') {
1047: $type{$lang} = $defaulttype;
1048: }
1049: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1050: if ($lang eq 'nolang') {
1051: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1052: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1053: } else {
1054: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1055: $langchoices{$lang},
1056: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1057: }
1058: $datatable .= '</span></td>'."\n".
1059: '<td class="LC_left_item">';
1060: if ($type{$lang} eq 'custom') {
1061: $datatable .= '<span class="LC_nobreak"><label>'.
1062: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1063: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1064: } else {
1065: $datatable .= $lt{'upl'};
1066: }
1067: $datatable .='<br />';
1068: if ($switchserver) {
1069: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1070: } else {
1071: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1072: }
1.168 raeburn 1073: $datatable .= '</td></tr>';
1074: $itemcount ++;
1.6 raeburn 1075: }
1.168 raeburn 1076: my @addlangs;
1077: foreach my $lang (sort(keys(%langchoices))) {
1078: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1079: push(@addlangs,$lang);
1080: }
1081: if (@addlangs > 0) {
1082: my %toadd;
1083: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1084: $toadd{''} = &mt('Select');
1085: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1086: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1087: &mt('Add log-in help page for a specific language:').' '.
1088: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1089: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1090: if ($switchserver) {
1091: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1092: } else {
1093: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1094: }
1.168 raeburn 1095: $datatable .= '</td></tr>';
1.169 raeburn 1096: $itemcount ++;
1.6 raeburn 1097: }
1.169 raeburn 1098: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1099: }
1.6 raeburn 1100: return $datatable;
1101: }
1102:
1103: sub login_choices {
1104: my %choices =
1105: &Apache::lonlocal::texthash (
1.116 bisitz 1106: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1107: adminmail => "Display Administrator's E-mail Address?",
1108: disallowlogin => "Login page requests redirected",
1109: hostid => "Server",
1.128 raeburn 1110: server => "Redirect to:",
1111: serverpath => "Path",
1112: custompath => "Custom",
1113: exempt => "Exempt IP(s)",
1.110 raeburn 1114: directlogin => "No redirect",
1115: newuser => "Link to create a user account",
1116: img => "Header",
1117: logo => "Main Logo",
1118: domlogo => "Domain Logo",
1119: login => "Log-in Header",
1120: textcol => "Text color",
1121: bgcol => "Box color",
1122: bgs => "Background colors",
1123: links => "Link colors",
1124: font => "Font color",
1125: pgbg => "Header",
1126: mainbg => "Page",
1127: sidebg => "Login box",
1128: link => "Link",
1129: alink => "Active link",
1130: vlink => "Visited link",
1.6 raeburn 1131: );
1132: return %choices;
1133: }
1134:
1135: sub print_rolecolors {
1.30 raeburn 1136: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1137: my %choices = &color_font_choices();
1138: my @bgs = ('pgbg','tabbg','sidebg');
1139: my @links = ('link','alink','vlink');
1140: my @images = ('img');
1141: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1142: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1143: my %defaultdesign = %Apache::loncommon::defaultdesign;
1144: my (%is_custom,%designs);
1145: my %defaults = (
1146: img => $defaultdesign{$role.'.img'},
1147: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1148: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1149: );
1150: foreach my $item (@bgs) {
1151: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1152: }
1153: foreach my $item (@links) {
1154: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1155: }
1156: if (ref($settings) eq 'HASH') {
1157: if (ref($settings->{$role}) eq 'HASH') {
1158: if ($settings->{$role}->{'img'} ne '') {
1159: $designs{'img'} = $settings->{$role}->{'img'};
1160: $is_custom{'img'} = 1;
1161: }
1162: if ($settings->{$role}->{'font'} ne '') {
1163: $designs{'font'} = $settings->{$role}->{'font'};
1164: $is_custom{'font'} = 1;
1165: }
1.97 tempelho 1166: if ($settings->{$role}->{'fontmenu'} ne '') {
1167: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1168: $is_custom{'fontmenu'} = 1;
1169: }
1.6 raeburn 1170: foreach my $item (@bgs) {
1171: if ($settings->{$role}->{$item} ne '') {
1172: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1173: $is_custom{$item} = 1;
1174: }
1175: }
1176: foreach my $item (@links) {
1177: if ($settings->{$role}->{$item} ne '') {
1178: $designs{'links'}{$item} = $settings->{$role}->{$item};
1179: $is_custom{$item} = 1;
1180: }
1181: }
1182: }
1183: } else {
1184: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1185: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1186: $is_custom{'img'} = 1;
1187: }
1.97 tempelho 1188: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1189: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1190: $is_custom{'fontmenu'} = 1;
1191: }
1.6 raeburn 1192: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1193: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1194: $is_custom{'font'} = 1;
1195: }
1196: foreach my $item (@bgs) {
1197: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1198: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1199: $is_custom{$item} = 1;
1200:
1201: }
1202: }
1203: foreach my $item (@links) {
1204: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1205: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1206: $is_custom{$item} = 1;
1207: }
1208: }
1209: }
1210: my $itemcount = 1;
1.30 raeburn 1211: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1212: $datatable .= '</tr></table></td></tr>';
1213: return $datatable;
1214: }
1215:
1216: sub display_color_options {
1.9 raeburn 1217: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1218: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1219: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1220: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1221: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1222: '<td>'.$choices->{'font'}.'</td>';
1223: if (!$is_custom->{'font'}) {
1.30 raeburn 1224: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1225: } else {
1226: $datatable .= '<td> </td>';
1227: }
1.174 foxr 1228: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1229:
1.8 raeburn 1230: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1231: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1232: ' value="'.$current_color.'" /> '.
1233: ' </td></tr>';
1.107 raeburn 1234: unless ($role eq 'login') {
1235: $datatable .= '<tr'.$css_class.'>'.
1236: '<td>'.$choices->{'fontmenu'}.'</td>';
1237: if (!$is_custom->{'fontmenu'}) {
1238: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1239: } else {
1240: $datatable .= '<td> </td>';
1241: }
1.174 foxr 1242: $current_color = $designs->{'fontmenu'} ?
1243: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1244: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1245: '<input class="colorchooser" type="text" size="10" name="'
1246: .$role.'_fontmenu"'.
1247: ' value="'.$current_color.'" /> '.
1248: ' </td></tr>';
1.97 tempelho 1249: }
1.9 raeburn 1250: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1251: foreach my $img (@{$images}) {
1.18 albertel 1252: $itemcount ++;
1.6 raeburn 1253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1254: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1255: '<td>'.$choices->{$img};
1.41 raeburn 1256: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1257: if ($role eq 'login') {
1258: if ($img eq 'login') {
1259: $login_hdr_pick =
1.135 bisitz 1260: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1261: $logincolors =
1262: &login_text_colors($img,$role,$logintext,$phase,$choices,
1263: $designs);
1264: } elsif ($img ne 'domlogo') {
1265: $datatable.= &logo_display_options($img,$defaults,$designs);
1266: }
1267: }
1268: $datatable .= '</td>';
1.6 raeburn 1269: if ($designs->{$img} ne '') {
1270: $imgfile = $designs->{$img};
1.18 albertel 1271: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1272: } else {
1273: $imgfile = $defaults->{$img};
1274: }
1275: if ($imgfile) {
1.9 raeburn 1276: my ($showfile,$fullsize);
1277: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1278: my $urldir = $1;
1279: my $filename = $2;
1280: my @info = &Apache::lonnet::stat_file($designs->{$img});
1281: if (@info) {
1282: my $thumbfile = 'tn-'.$filename;
1283: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1284: if (@thumb) {
1285: $showfile = $urldir.'/'.$thumbfile;
1286: } else {
1287: $showfile = $imgfile;
1288: }
1289: } else {
1290: $showfile = '';
1291: }
1292: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1293: $showfile = $imgfile;
1.6 raeburn 1294: my $imgdir = $1;
1295: my $filename = $2;
1.159 raeburn 1296: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1297: $showfile = "/$imgdir/tn-".$filename;
1298: } else {
1.159 raeburn 1299: my $input = $londocroot.$imgfile;
1300: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1301: if (!-e $output) {
1.9 raeburn 1302: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1303: my ($fullwidth,$fullheight) = &check_dimensions($input);
1304: if ($fullwidth ne '' && $fullheight ne '') {
1305: if ($fullwidth > $width && $fullheight > $height) {
1306: my $size = $width.'x'.$height;
1307: system("convert -sample $size $input $output");
1.159 raeburn 1308: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1309: }
1310: }
1.6 raeburn 1311: }
1312: }
1.16 raeburn 1313: }
1.6 raeburn 1314: if ($showfile) {
1.40 raeburn 1315: if ($showfile =~ m{^/(adm|res)/}) {
1316: if ($showfile =~ m{^/res/}) {
1317: my $local_showfile =
1318: &Apache::lonnet::filelocation('',$showfile);
1319: &Apache::lonnet::repcopy($local_showfile);
1320: }
1321: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1322: }
1323: if ($imgfile) {
1324: if ($imgfile =~ m{^/(adm|res)/}) {
1325: if ($imgfile =~ m{^/res/}) {
1326: my $local_imgfile =
1327: &Apache::lonnet::filelocation('',$imgfile);
1328: &Apache::lonnet::repcopy($local_imgfile);
1329: }
1330: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1331: } else {
1332: $fullsize = $imgfile;
1333: }
1334: }
1.41 raeburn 1335: $datatable .= '<td>';
1336: if ($img eq 'login') {
1.135 bisitz 1337: $datatable .= $login_hdr_pick;
1338: }
1.41 raeburn 1339: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1340: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1341: } else {
1342: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1343: &mt('Upload:');
1344: }
1345: } else {
1346: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1347: &mt('Upload:');
1348: }
1.9 raeburn 1349: if ($switchserver) {
1350: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1351: } else {
1.135 bisitz 1352: if ($img ne 'login') { # suppress file selection for Log-in header
1353: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1354: }
1.9 raeburn 1355: }
1356: $datatable .= '</td></tr>';
1.6 raeburn 1357: }
1358: $itemcount ++;
1359: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1360: $datatable .= '<tr'.$css_class.'>'.
1361: '<td>'.$choices->{'bgs'}.'</td>';
1362: my $bgs_def;
1363: foreach my $item (@{$bgs}) {
1364: if (!$is_custom->{$item}) {
1.70 raeburn 1365: $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 1366: }
1367: }
1368: if ($bgs_def) {
1.8 raeburn 1369: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1370: } else {
1371: $datatable .= '<td> </td>';
1372: }
1373: $datatable .= '<td class="LC_right_item">'.
1374: '<table border="0"><tr>';
1.174 foxr 1375:
1376:
1.6 raeburn 1377: foreach my $item (@{$bgs}) {
1.174 foxr 1378: # my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1379: $datatable .= '<td align="center">';
1380: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1381: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1382: $datatable .= ' ';
1.6 raeburn 1383: }
1.174 foxr 1384: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1385: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1386: }
1387: $datatable .= '</tr></table></td></tr>';
1388: $itemcount ++;
1389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1390: $datatable .= '<tr'.$css_class.'>'.
1391: '<td>'.$choices->{'links'}.'</td>';
1392: my $links_def;
1393: foreach my $item (@{$links}) {
1394: if (!$is_custom->{$item}) {
1.30 raeburn 1395: $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 1396: }
1397: }
1398: if ($links_def) {
1.8 raeburn 1399: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1400: } else {
1401: $datatable .= '<td> </td>';
1402: }
1403: $datatable .= '<td class="LC_right_item">'.
1404: '<table border="0"><tr>';
1405: foreach my $item (@{$links}) {
1.174 foxr 1406: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1407: $datatable .= '<td align="center">'."\n";
1408:
1.6 raeburn 1409: if ($designs->{'links'}{$item}) {
1.174 foxr 1410: $datatable.=' ';
1.6 raeburn 1411: }
1.174 foxr 1412: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1413: '" /></td>';
1414: }
1.30 raeburn 1415: $$rowtotal += $itemcount;
1.3 raeburn 1416: return $datatable;
1417: }
1418:
1.70 raeburn 1419: sub logo_display_options {
1420: my ($img,$defaults,$designs) = @_;
1421: my $checkedon;
1422: if (ref($defaults) eq 'HASH') {
1423: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1424: if ($defaults->{'showlogo'}{$img}) {
1425: $checkedon = 'checked="checked" ';
1426: }
1427: }
1428: }
1429: if (ref($designs) eq 'HASH') {
1430: if (ref($designs->{'showlogo'}) eq 'HASH') {
1431: if (defined($designs->{'showlogo'}{$img})) {
1432: if ($designs->{'showlogo'}{$img} == 0) {
1433: $checkedon = '';
1434: } elsif ($designs->{'showlogo'}{$img} == 1) {
1435: $checkedon = 'checked="checked" ';
1436: }
1437: }
1438: }
1439: }
1440: return '<br /><label> <input type="checkbox" name="'.
1441: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1442: &mt('show').'</label>'."\n";
1443: }
1444:
1.41 raeburn 1445: sub login_header_options {
1.135 bisitz 1446: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1447: my $output = '';
1.41 raeburn 1448: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1449: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1450: if (!$is_custom->{'textcol'}) {
1451: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1452: ' ';
1453: }
1454: if (!$is_custom->{'bgcol'}) {
1455: $output .= $choices->{'bgcol'}.': '.
1456: '<span id="css_'.$role.'_font" style="background-color: '.
1457: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1458: }
1459: $output .= '<br />';
1460: }
1461: $output .='<br />';
1462: return $output;
1463: }
1464:
1465: sub login_text_colors {
1466: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1467: my $color_menu = '<table border="0"><tr>';
1468: foreach my $item (@{$logintext}) {
1469: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1470: $color_menu .= '<td align="center">'.$link;
1471: if ($designs->{'logintext'}{$item}) {
1472: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1473: }
1474: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1475: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1476: '<td> </td>';
1477: }
1478: $color_menu .= '</tr></table><br />';
1479: return $color_menu;
1480: }
1481:
1482: sub image_changes {
1483: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1484: my $output;
1.135 bisitz 1485: if ($img eq 'login') {
1486: # suppress image for Log-in header
1487: } elsif (!$is_custom) {
1.70 raeburn 1488: if ($img ne 'domlogo') {
1.41 raeburn 1489: $output .= &mt('Default image:').'<br />';
1490: } else {
1491: $output .= &mt('Default in use:').'<br />';
1492: }
1493: }
1.135 bisitz 1494: if ($img eq 'login') { # suppress image for Log-in header
1495: $output .= '<td>'.$logincolors;
1.41 raeburn 1496: } else {
1.135 bisitz 1497: if ($img_import) {
1498: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1499: }
1500: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1501: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1502: if ($is_custom) {
1503: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1504: '<input type="checkbox" name="'.
1505: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1506: '</label> '.&mt('Replace:').'</span><br />';
1507: } else {
1508: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1509: }
1.41 raeburn 1510: }
1511: return $output;
1512: }
1513:
1.6 raeburn 1514: sub color_pick {
1515: my ($phase,$role,$item,$desc,$curcol) = @_;
1516: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1517: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1518: ');">'.$desc.'</a>';
1519: return $link;
1520: }
1521:
1.3 raeburn 1522: sub print_quotas {
1.86 raeburn 1523: my ($dom,$settings,$rowtotal,$action) = @_;
1524: my $context;
1525: if ($action eq 'quotas') {
1526: $context = 'tools';
1527: } else {
1528: $context = $action;
1529: }
1.101 raeburn 1530: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1531: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1532: my $typecount = 0;
1.101 raeburn 1533: my ($css_class,%titles);
1.86 raeburn 1534: if ($context eq 'requestcourses') {
1.98 raeburn 1535: @usertools = ('official','unofficial','community');
1.106 raeburn 1536: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1537: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1538: %titles = &courserequest_titles();
1.163 raeburn 1539: } elsif ($context eq 'requestauthor') {
1540: @usertools = ('author');
1541: @options = ('norequest','approval','automatic');
1542: %titles = &authorrequest_titles();
1.86 raeburn 1543: } else {
1.162 raeburn 1544: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1545: %titles = &tool_titles();
1.86 raeburn 1546: }
1.26 raeburn 1547: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1548: foreach my $type (@{$types}) {
1.72 raeburn 1549: my $currdefquota;
1.163 raeburn 1550: unless (($context eq 'requestcourses') ||
1551: ($context eq 'requestauthor')) {
1.86 raeburn 1552: if (ref($settings) eq 'HASH') {
1553: if (ref($settings->{defaultquota}) eq 'HASH') {
1554: $currdefquota = $settings->{defaultquota}->{$type};
1555: } else {
1556: $currdefquota = $settings->{$type};
1557: }
1.78 raeburn 1558: }
1.72 raeburn 1559: }
1.3 raeburn 1560: if (defined($usertypes->{$type})) {
1561: $typecount ++;
1562: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1563: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1564: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1565: '<td class="LC_left_item">';
1.101 raeburn 1566: if ($context eq 'requestcourses') {
1567: $datatable .= '<table><tr>';
1568: }
1569: my %cell;
1.72 raeburn 1570: foreach my $item (@usertools) {
1.101 raeburn 1571: if ($context eq 'requestcourses') {
1572: my ($curroption,$currlimit);
1573: if (ref($settings) eq 'HASH') {
1574: if (ref($settings->{$item}) eq 'HASH') {
1575: $curroption = $settings->{$item}->{$type};
1576: if ($curroption =~ /^autolimit=(\d*)$/) {
1577: $currlimit = $1;
1578: }
1579: }
1580: }
1581: if (!$curroption) {
1582: $curroption = 'norequest';
1583: }
1584: $datatable .= '<th>'.$titles{$item}.'</th>';
1585: foreach my $option (@options) {
1586: my $val = $option;
1587: if ($option eq 'norequest') {
1588: $val = 0;
1589: }
1590: if ($option eq 'validate') {
1591: my $canvalidate = 0;
1592: if (ref($validations{$item}) eq 'HASH') {
1593: if ($validations{$item}{$type}) {
1594: $canvalidate = 1;
1595: }
1596: }
1597: next if (!$canvalidate);
1598: }
1599: my $checked = '';
1600: if ($option eq $curroption) {
1601: $checked = ' checked="checked"';
1602: } elsif ($option eq 'autolimit') {
1603: if ($curroption =~ /^autolimit/) {
1604: $checked = ' checked="checked"';
1605: }
1606: }
1607: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1608: '<input type="radio" name="crsreq_'.$item.
1609: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1610: $titles{$option}.'</label>';
1.101 raeburn 1611: if ($option eq 'autolimit') {
1.127 raeburn 1612: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1613: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1614: 'value="'.$currlimit.'" />';
1.101 raeburn 1615: }
1.127 raeburn 1616: $cell{$item} .= '</span> ';
1.103 raeburn 1617: if ($option eq 'autolimit') {
1.127 raeburn 1618: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1619: }
1.101 raeburn 1620: }
1.163 raeburn 1621: } elsif ($context eq 'requestauthor') {
1622: my $curroption;
1623: if (ref($settings) eq 'HASH') {
1624: $curroption = $settings->{$type};
1625: }
1626: if (!$curroption) {
1627: $curroption = 'norequest';
1628: }
1629: foreach my $option (@options) {
1630: my $val = $option;
1631: if ($option eq 'norequest') {
1632: $val = 0;
1633: }
1634: my $checked = '';
1635: if ($option eq $curroption) {
1636: $checked = ' checked="checked"';
1637: }
1638: $datatable .= '<span class="LC_nobreak"><label>'.
1639: '<input type="radio" name="authorreq_'.$type.
1640: '" value="'.$val.'"'.$checked.' />'.
1641: $titles{$option}.'</label></span> ';
1642: }
1.101 raeburn 1643: } else {
1644: my $checked = 'checked="checked" ';
1645: if (ref($settings) eq 'HASH') {
1646: if (ref($settings->{$item}) eq 'HASH') {
1647: if ($settings->{$item}->{$type} == 0) {
1648: $checked = '';
1649: } elsif ($settings->{$item}->{$type} == 1) {
1650: $checked = 'checked="checked" ';
1651: }
1.78 raeburn 1652: }
1.72 raeburn 1653: }
1.101 raeburn 1654: $datatable .= '<span class="LC_nobreak"><label>'.
1655: '<input type="checkbox" name="'.$context.'_'.$item.
1656: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1657: '</label></span> ';
1.72 raeburn 1658: }
1.101 raeburn 1659: }
1660: if ($context eq 'requestcourses') {
1661: $datatable .= '</tr><tr>';
1662: foreach my $item (@usertools) {
1.106 raeburn 1663: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1664: }
1665: $datatable .= '</tr></table>';
1.72 raeburn 1666: }
1.86 raeburn 1667: $datatable .= '</td>';
1.163 raeburn 1668: unless (($context eq 'requestcourses') ||
1669: ($context eq 'requestauthor')) {
1.86 raeburn 1670: $datatable .=
1671: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1672: '<input type="text" name="quota_'.$type.
1.72 raeburn 1673: '" value="'.$currdefquota.
1.86 raeburn 1674: '" size="5" /> Mb</span></td>';
1675: }
1676: $datatable .= '</tr>';
1.3 raeburn 1677: }
1678: }
1679: }
1.163 raeburn 1680: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1681: $defaultquota = '20';
1682: if (ref($settings) eq 'HASH') {
1683: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1684: $defaultquota = $settings->{'defaultquota'}->{'default'};
1685: } elsif (defined($settings->{'default'})) {
1686: $defaultquota = $settings->{'default'};
1687: }
1.3 raeburn 1688: }
1689: }
1690: $typecount ++;
1691: $css_class = $typecount%2?' class="LC_odd_row"':'';
1692: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1693: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1694: '<td class="LC_left_item">';
1.101 raeburn 1695: if ($context eq 'requestcourses') {
1696: $datatable .= '<table><tr>';
1697: }
1698: my %defcell;
1.72 raeburn 1699: foreach my $item (@usertools) {
1.101 raeburn 1700: if ($context eq 'requestcourses') {
1701: my ($curroption,$currlimit);
1702: if (ref($settings) eq 'HASH') {
1703: if (ref($settings->{$item}) eq 'HASH') {
1704: $curroption = $settings->{$item}->{'default'};
1705: if ($curroption =~ /^autolimit=(\d*)$/) {
1706: $currlimit = $1;
1707: }
1708: }
1709: }
1710: if (!$curroption) {
1711: $curroption = 'norequest';
1712: }
1713: $datatable .= '<th>'.$titles{$item}.'</th>';
1714: foreach my $option (@options) {
1715: my $val = $option;
1716: if ($option eq 'norequest') {
1717: $val = 0;
1718: }
1719: if ($option eq 'validate') {
1720: my $canvalidate = 0;
1721: if (ref($validations{$item}) eq 'HASH') {
1722: if ($validations{$item}{'default'}) {
1723: $canvalidate = 1;
1724: }
1725: }
1726: next if (!$canvalidate);
1727: }
1728: my $checked = '';
1729: if ($option eq $curroption) {
1730: $checked = ' checked="checked"';
1731: } elsif ($option eq 'autolimit') {
1732: if ($curroption =~ /^autolimit/) {
1733: $checked = ' checked="checked"';
1734: }
1735: }
1736: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1737: '<input type="radio" name="crsreq_'.$item.
1738: '_default" value="'.$val.'"'.$checked.' />'.
1739: $titles{$option}.'</label>';
1740: if ($option eq 'autolimit') {
1.127 raeburn 1741: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1742: $item.'_limit_default" size="1" '.
1743: 'value="'.$currlimit.'" />';
1744: }
1.127 raeburn 1745: $defcell{$item} .= '</span> ';
1.104 raeburn 1746: if ($option eq 'autolimit') {
1.127 raeburn 1747: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1748: }
1.101 raeburn 1749: }
1.163 raeburn 1750: } elsif ($context eq 'requestauthor') {
1751: my $curroption;
1752: if (ref($settings) eq 'HASH') {
1.172 raeburn 1753: $curroption = $settings->{'default'};
1.163 raeburn 1754: }
1755: if (!$curroption) {
1756: $curroption = 'norequest';
1757: }
1758: foreach my $option (@options) {
1759: my $val = $option;
1760: if ($option eq 'norequest') {
1761: $val = 0;
1762: }
1763: my $checked = '';
1764: if ($option eq $curroption) {
1765: $checked = ' checked="checked"';
1766: }
1767: $datatable .= '<span class="LC_nobreak"><label>'.
1768: '<input type="radio" name="authorreq_default"'.
1769: ' value="'.$val.'"'.$checked.' />'.
1770: $titles{$option}.'</label></span> ';
1771: }
1.101 raeburn 1772: } else {
1773: my $checked = 'checked="checked" ';
1774: if (ref($settings) eq 'HASH') {
1775: if (ref($settings->{$item}) eq 'HASH') {
1776: if ($settings->{$item}->{'default'} == 0) {
1777: $checked = '';
1778: } elsif ($settings->{$item}->{'default'} == 1) {
1779: $checked = 'checked="checked" ';
1780: }
1.78 raeburn 1781: }
1.72 raeburn 1782: }
1.101 raeburn 1783: $datatable .= '<span class="LC_nobreak"><label>'.
1784: '<input type="checkbox" name="'.$context.'_'.$item.
1785: '" value="default" '.$checked.'/>'.$titles{$item}.
1786: '</label></span> ';
1787: }
1788: }
1789: if ($context eq 'requestcourses') {
1790: $datatable .= '</tr><tr>';
1791: foreach my $item (@usertools) {
1.106 raeburn 1792: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1793: }
1.101 raeburn 1794: $datatable .= '</tr></table>';
1.72 raeburn 1795: }
1.86 raeburn 1796: $datatable .= '</td>';
1.163 raeburn 1797: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1798: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1799: '<input type="text" name="defaultquota" value="'.
1800: $defaultquota.'" size="5" /> Mb</span></td>';
1801: }
1802: $datatable .= '</tr>';
1.72 raeburn 1803: $typecount ++;
1804: $css_class = $typecount%2?' class="LC_odd_row"':'';
1805: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1806: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1807: if ($context eq 'requestcourses') {
1.109 raeburn 1808: $datatable .= &mt('(overrides affiliation, if set)').
1809: '</td>'.
1810: '<td class="LC_left_item">'.
1811: '<table><tr>';
1.101 raeburn 1812: } else {
1.109 raeburn 1813: $datatable .= &mt('(overrides affiliation, if checked)').
1814: '</td>'.
1815: '<td class="LC_left_item" colspan="2">'.
1816: '<br />';
1.101 raeburn 1817: }
1818: my %advcell;
1.72 raeburn 1819: foreach my $item (@usertools) {
1.101 raeburn 1820: if ($context eq 'requestcourses') {
1821: my ($curroption,$currlimit);
1822: if (ref($settings) eq 'HASH') {
1823: if (ref($settings->{$item}) eq 'HASH') {
1824: $curroption = $settings->{$item}->{'_LC_adv'};
1825: if ($curroption =~ /^autolimit=(\d*)$/) {
1826: $currlimit = $1;
1827: }
1828: }
1829: }
1830: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1831: my $checked = '';
1832: if ($curroption eq '') {
1833: $checked = ' checked="checked"';
1834: }
1835: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1836: '<input type="radio" name="crsreq_'.$item.
1837: '__LC_adv" value=""'.$checked.' />'.
1838: &mt('No override set').'</label></span> ';
1.101 raeburn 1839: foreach my $option (@options) {
1840: my $val = $option;
1841: if ($option eq 'norequest') {
1842: $val = 0;
1843: }
1844: if ($option eq 'validate') {
1845: my $canvalidate = 0;
1846: if (ref($validations{$item}) eq 'HASH') {
1847: if ($validations{$item}{'_LC_adv'}) {
1848: $canvalidate = 1;
1849: }
1850: }
1851: next if (!$canvalidate);
1852: }
1853: my $checked = '';
1.104 raeburn 1854: if ($val eq $curroption) {
1.101 raeburn 1855: $checked = ' checked="checked"';
1856: } elsif ($option eq 'autolimit') {
1857: if ($curroption =~ /^autolimit/) {
1858: $checked = ' checked="checked"';
1859: }
1860: }
1861: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1862: '<input type="radio" name="crsreq_'.$item.
1863: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1864: $titles{$option}.'</label>';
1865: if ($option eq 'autolimit') {
1.127 raeburn 1866: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1867: $item.'_limit__LC_adv" size="1" '.
1868: 'value="'.$currlimit.'" />';
1869: }
1.127 raeburn 1870: $advcell{$item} .= '</span> ';
1.104 raeburn 1871: if ($option eq 'autolimit') {
1.127 raeburn 1872: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1873: }
1.101 raeburn 1874: }
1.163 raeburn 1875: } elsif ($context eq 'requestauthor') {
1876: my $curroption;
1877: if (ref($settings) eq 'HASH') {
1878: $curroption = $settings->{'_LC_adv'};
1879: }
1880: my $checked = '';
1881: if ($curroption eq '') {
1882: $checked = ' checked="checked"';
1883: }
1884: $datatable .= '<span class="LC_nobreak"><label>'.
1885: '<input type="radio" name="authorreq__LC_adv"'.
1886: ' value=""'.$checked.' />'.
1887: &mt('No override set').'</label></span> ';
1888: foreach my $option (@options) {
1889: my $val = $option;
1890: if ($option eq 'norequest') {
1891: $val = 0;
1892: }
1893: my $checked = '';
1894: if ($val eq $curroption) {
1895: $checked = ' checked="checked"';
1896: }
1897: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1898: '<input type="radio" name="authorreq__LC_adv"'.
1899: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1900: $titles{$option}.'</label></span> ';
1901: }
1.101 raeburn 1902: } else {
1903: my $checked = 'checked="checked" ';
1904: if (ref($settings) eq 'HASH') {
1905: if (ref($settings->{$item}) eq 'HASH') {
1906: if ($settings->{$item}->{'_LC_adv'} == 0) {
1907: $checked = '';
1908: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1909: $checked = 'checked="checked" ';
1910: }
1.79 raeburn 1911: }
1.72 raeburn 1912: }
1.101 raeburn 1913: $datatable .= '<span class="LC_nobreak"><label>'.
1914: '<input type="checkbox" name="'.$context.'_'.$item.
1915: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1916: '</label></span> ';
1917: }
1918: }
1919: if ($context eq 'requestcourses') {
1920: $datatable .= '</tr><tr>';
1921: foreach my $item (@usertools) {
1.106 raeburn 1922: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1923: }
1.101 raeburn 1924: $datatable .= '</tr></table>';
1.72 raeburn 1925: }
1.98 raeburn 1926: $datatable .= '</td></tr>';
1.30 raeburn 1927: $$rowtotal += $typecount;
1.3 raeburn 1928: return $datatable;
1929: }
1930:
1.163 raeburn 1931: sub print_requestmail {
1932: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1933: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1934: $now = time;
1935: $rows = 0;
1936: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1937: foreach my $server (keys(%dompersonnel)) {
1938: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1939: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1940: if (!grep(/^$uname:$udom$/,@domcoord)) {
1941: push(@domcoord,$uname.':'.$udom);
1942: }
1943: }
1944: }
1945: if (ref($settings) eq 'HASH') {
1946: if (ref($settings->{'notify'}) eq 'HASH') {
1947: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1948: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1949: }
1950: }
1951: }
1.104 raeburn 1952: if (@currapproval) {
1953: foreach my $dc (@currapproval) {
1.102 raeburn 1954: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1955: push(@domcoord,$dc);
1956: }
1957: }
1958: }
1959: @domcoord = sort(@domcoord);
1960: my $numinrow = 4;
1961: my $numdc = @domcoord;
1962: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1963: my $text;
1964: if ($action eq 'requestcourses') {
1965: $text = &mt('Receive notification of course requests requiring approval');
1966: } else {
1967: $text = &mt('Receive notification of authoring space requests requiring approval')
1968: }
1969: $datatable = '<tr '.$css_class.'>'.
1970: ' <td>'.$text.'</td>'.
1.102 raeburn 1971: ' <td class="LC_left_item">';
1972: if (@domcoord > 0) {
1973: $datatable .= '<table>';
1974: for (my $i=0; $i<$numdc; $i++) {
1975: my $rem = $i%($numinrow);
1976: if ($rem == 0) {
1977: if ($i > 0) {
1978: $datatable .= '</tr>';
1979: }
1980: $datatable .= '<tr>';
1981: $rows ++;
1982: }
1983: my $check = ' ';
1.104 raeburn 1984: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1985: $check = ' checked="checked" ';
1986: }
1987: my ($uname,$udom) = split(':',$domcoord[$i]);
1988: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1989: if ($i == $numdc-1) {
1990: my $colsleft = $numinrow-$rem;
1991: if ($colsleft > 1) {
1992: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1993: } else {
1994: $datatable .= '<td class="LC_left_item">';
1995: }
1996: } else {
1997: $datatable .= '<td class="LC_left_item">';
1998: }
1999: $datatable .= '<span class="LC_nobreak"><label>'.
2000: '<input type="checkbox" name="reqapprovalnotify" '.
2001: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175 bisitz 2002: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 2003: }
2004: $datatable .= '</tr></table>';
2005: } else {
2006: $datatable .= &mt('There are no active Domain Coordinators');
2007: $rows ++;
2008: }
2009: $datatable .='</td></tr>';
2010: $$rowtotal += $rows;
2011: return $datatable;
2012: }
2013:
1.3 raeburn 2014: sub print_autoenroll {
1.30 raeburn 2015: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2016: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2017: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2018: if (ref($settings) eq 'HASH') {
2019: if (exists($settings->{'run'})) {
2020: if ($settings->{'run'} eq '0') {
2021: $runoff = ' checked="checked" ';
2022: $runon = ' ';
2023: } else {
2024: $runon = ' checked="checked" ';
2025: $runoff = ' ';
2026: }
2027: } else {
2028: if ($autorun) {
2029: $runon = ' checked="checked" ';
2030: $runoff = ' ';
2031: } else {
2032: $runoff = ' checked="checked" ';
2033: $runon = ' ';
2034: }
2035: }
1.129 raeburn 2036: if (exists($settings->{'co-owners'})) {
2037: if ($settings->{'co-owners'} eq '0') {
2038: $coownersoff = ' checked="checked" ';
2039: $coownerson = ' ';
2040: } else {
2041: $coownerson = ' checked="checked" ';
2042: $coownersoff = ' ';
2043: }
2044: } else {
2045: $coownersoff = ' checked="checked" ';
2046: $coownerson = ' ';
2047: }
1.3 raeburn 2048: if (exists($settings->{'sender_domain'})) {
2049: $defdom = $settings->{'sender_domain'};
2050: }
1.14 raeburn 2051: } else {
2052: if ($autorun) {
2053: $runon = ' checked="checked" ';
2054: $runoff = ' ';
2055: } else {
2056: $runoff = ' checked="checked" ';
2057: $runon = ' ';
2058: }
1.3 raeburn 2059: }
2060: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2061: my $notif_sender;
2062: if (ref($settings) eq 'HASH') {
2063: $notif_sender = $settings->{'sender_uname'};
2064: }
1.3 raeburn 2065: my $datatable='<tr class="LC_odd_row">'.
2066: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2067: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2068: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2069: $runon.' value="1" />'.&mt('Yes').'</label> '.
2070: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2071: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2072: '</tr><tr>'.
2073: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2074: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2075: &mt('username').': '.
2076: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2077: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2078: ': '.$domform.'</span></td></tr>'.
2079: '<tr class="LC_odd_row">'.
2080: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2081: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2082: '<input type="radio" name="autoassign_coowners"'.
2083: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2084: '<label><input type="radio" name="autoassign_coowners"'.
2085: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2086: '</tr>';
2087: $$rowtotal += 3;
1.3 raeburn 2088: return $datatable;
2089: }
2090:
2091: sub print_autoupdate {
1.30 raeburn 2092: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2093: my $datatable;
2094: if ($position eq 'top') {
2095: my $updateon = ' ';
2096: my $updateoff = ' checked="checked" ';
2097: my $classlistson = ' ';
2098: my $classlistsoff = ' checked="checked" ';
2099: if (ref($settings) eq 'HASH') {
2100: if ($settings->{'run'} eq '1') {
2101: $updateon = $updateoff;
2102: $updateoff = ' ';
2103: }
2104: if ($settings->{'classlists'} eq '1') {
2105: $classlistson = $classlistsoff;
2106: $classlistsoff = ' ';
2107: }
2108: }
2109: my %title = (
2110: run => 'Auto-update active?',
2111: classlists => 'Update information in classlists?',
2112: );
2113: $datatable = '<tr class="LC_odd_row">'.
2114: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2115: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2116: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2117: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2118: '<label><input type="radio" name="autoupdate_run"'.
2119: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2120: '</tr><tr>'.
2121: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2122: '<td class="LC_right_item"><span class="LC_nobreak">'.
2123: '<label><input type="radio" name="classlists"'.
2124: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2125: '<label><input type="radio" name="classlists"'.
2126: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2127: '</tr>';
1.30 raeburn 2128: $$rowtotal += 2;
1.131 raeburn 2129: } elsif ($position eq 'middle') {
2130: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2131: my $numinrow = 3;
2132: my $locknamesettings;
2133: $datatable .= &insttypes_row($settings,$types,$usertypes,
2134: $dom,$numinrow,$othertitle,
2135: 'lockablenames');
2136: $$rowtotal ++;
1.3 raeburn 2137: } else {
1.44 raeburn 2138: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2139: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2140: 'permanentemail','id');
1.33 raeburn 2141: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2142: my $numrows = 0;
1.26 raeburn 2143: if (ref($types) eq 'ARRAY') {
2144: if (@{$types} > 0) {
2145: $datatable =
2146: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2147: \@fields,$types,\$numrows);
1.30 raeburn 2148: $$rowtotal += @{$types};
1.26 raeburn 2149: }
1.3 raeburn 2150: }
2151: $datatable .=
2152: &usertype_update_row($settings,{'default' => $othertitle},
2153: \%fieldtitles,\@fields,['default'],
2154: \$numrows);
1.30 raeburn 2155: $$rowtotal ++;
1.3 raeburn 2156: }
2157: return $datatable;
2158: }
2159:
1.125 raeburn 2160: sub print_autocreate {
2161: my ($dom,$settings,$rowtotal) = @_;
2162: my (%createon,%createoff);
2163: my $curr_dc;
2164: my @types = ('xml','req');
2165: if (ref($settings) eq 'HASH') {
2166: foreach my $item (@types) {
2167: $createoff{$item} = ' checked="checked" ';
2168: $createon{$item} = ' ';
2169: if (exists($settings->{$item})) {
2170: if ($settings->{$item}) {
2171: $createon{$item} = ' checked="checked" ';
2172: $createoff{$item} = ' ';
2173: }
2174: }
2175: }
2176: $curr_dc = $settings->{'xmldc'};
2177: } else {
2178: foreach my $item (@types) {
2179: $createoff{$item} = ' checked="checked" ';
2180: $createon{$item} = ' ';
2181: }
2182: }
2183: $$rowtotal += 2;
2184: my $datatable='<tr class="LC_odd_row">'.
2185: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2186: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2187: '<input type="radio" name="autocreate_xml"'.
2188: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2189: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2190: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2191: '</td></tr><tr>'.
2192: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2193: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2194: '<input type="radio" name="autocreate_req"'.
2195: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2196: '<label><input type="radio" name="autocreate_req"'.
2197: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2198: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2199: if ($numdc > 1) {
1.143 raeburn 2200: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2201: &mt('Course creation processed as: (choose Dom. Coord.)').
2202: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2203: $$rowtotal ++ ;
2204: } else {
1.143 raeburn 2205: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2206: }
2207: return $datatable;
2208: }
2209:
1.23 raeburn 2210: sub print_directorysrch {
1.30 raeburn 2211: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2212: my $srchon = ' ';
2213: my $srchoff = ' checked="checked" ';
1.25 raeburn 2214: my ($exacton,$containson,$beginson);
1.24 raeburn 2215: my $localon = ' ';
2216: my $localoff = ' checked="checked" ';
1.23 raeburn 2217: if (ref($settings) eq 'HASH') {
2218: if ($settings->{'available'} eq '1') {
2219: $srchon = $srchoff;
2220: $srchoff = ' ';
2221: }
1.24 raeburn 2222: if ($settings->{'localonly'} eq '1') {
2223: $localon = $localoff;
2224: $localoff = ' ';
2225: }
1.25 raeburn 2226: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2227: foreach my $type (@{$settings->{'searchtypes'}}) {
2228: if ($type eq 'exact') {
2229: $exacton = ' checked="checked" ';
2230: } elsif ($type eq 'contains') {
2231: $containson = ' checked="checked" ';
2232: } elsif ($type eq 'begins') {
2233: $beginson = ' checked="checked" ';
2234: }
2235: }
2236: } else {
2237: if ($settings->{'searchtypes'} eq 'exact') {
2238: $exacton = ' checked="checked" ';
2239: } elsif ($settings->{'searchtypes'} eq 'contains') {
2240: $containson = ' checked="checked" ';
2241: } elsif ($settings->{'searchtypes'} eq 'specify') {
2242: $exacton = ' checked="checked" ';
2243: $containson = ' checked="checked" ';
2244: }
1.23 raeburn 2245: }
2246: }
2247: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2249:
2250: my $numinrow = 4;
1.26 raeburn 2251: my $cansrchrow = 0;
1.23 raeburn 2252: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2253: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2254: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2255: '<input type="radio" name="dirsrch_available"'.
2256: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2257: '<label><input type="radio" name="dirsrch_available"'.
2258: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2259: '</tr><tr>'.
1.30 raeburn 2260: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2261: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2262: '<input type="radio" name="dirsrch_localonly"'.
2263: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2264: '<label><input type="radio" name="dirsrch_localonly"'.
2265: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2266: '</tr>';
1.30 raeburn 2267: $$rowtotal += 2;
1.26 raeburn 2268: if (ref($usertypes) eq 'HASH') {
2269: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2270: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2271: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2272: $cansrchrow = 1;
2273: }
2274: }
2275: if ($cansrchrow) {
1.30 raeburn 2276: $$rowtotal ++;
1.26 raeburn 2277: $datatable .= '<tr>';
2278: } else {
2279: $datatable .= '<tr class="LC_odd_row">';
2280: }
1.30 raeburn 2281: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2282: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2283: foreach my $title (@{$titleorder}) {
2284: if (defined($searchtitles->{$title})) {
2285: my $check = ' ';
1.93 raeburn 2286: if (ref($settings) eq 'HASH') {
1.39 raeburn 2287: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2288: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2289: $check = ' checked="checked" ';
2290: }
1.25 raeburn 2291: }
2292: }
2293: $datatable .= '<td class="LC_left_item">'.
2294: '<span class="LC_nobreak"><label>'.
2295: '<input type="checkbox" name="searchby" '.
2296: 'value="'.$title.'"'.$check.'/>'.
2297: $searchtitles->{$title}.'</label></span></td>';
2298: }
2299: }
1.26 raeburn 2300: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2301: $$rowtotal ++;
1.26 raeburn 2302: if ($cansrchrow) {
2303: $datatable .= '<tr class="LC_odd_row">';
2304: } else {
2305: $datatable .= '<tr>';
2306: }
1.30 raeburn 2307: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2308: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2309: '<span class="LC_nobreak"><label>'.
2310: '<input type="checkbox" name="searchtypes" '.
2311: $exacton.' value="exact" />'.&mt('Exact match').
2312: '</label> '.
2313: '<label><input type="checkbox" name="searchtypes" '.
2314: $beginson.' value="begins" />'.&mt('Begins with').
2315: '</label> '.
2316: '<label><input type="checkbox" name="searchtypes" '.
2317: $containson.' value="contains" />'.&mt('Contains').
2318: '</label></span></td></tr>';
1.30 raeburn 2319: $$rowtotal ++;
1.25 raeburn 2320: return $datatable;
2321: }
2322:
1.28 raeburn 2323: sub print_contacts {
1.30 raeburn 2324: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2325: my $datatable;
2326: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2327: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2328: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2329: 'requestsmail');
1.28 raeburn 2330: foreach my $type (@mailings) {
2331: $otheremails{$type} = '';
2332: }
1.134 raeburn 2333: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2334: if (ref($settings) eq 'HASH') {
2335: foreach my $item (@contacts) {
2336: if (exists($settings->{$item})) {
2337: $to{$item} = $settings->{$item};
2338: }
2339: }
2340: foreach my $type (@mailings) {
2341: if (exists($settings->{$type})) {
2342: if (ref($settings->{$type}) eq 'HASH') {
2343: foreach my $item (@contacts) {
2344: if ($settings->{$type}{$item}) {
2345: $checked{$type}{$item} = ' checked="checked" ';
2346: }
2347: }
2348: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2349: if ($type eq 'helpdeskmail') {
2350: $bccemails{$type} = $settings->{$type}{'bcc'};
2351: }
1.28 raeburn 2352: }
1.89 raeburn 2353: } elsif ($type eq 'lonstatusmail') {
2354: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2355: }
2356: }
2357: } else {
2358: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2359: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2360: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2361: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2362: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2363: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2364: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2365: }
2366: my ($titles,$short_titles) = &contact_titles();
2367: my $rownum = 0;
2368: my $css_class;
2369: foreach my $item (@contacts) {
1.69 raeburn 2370: $rownum ++;
2371: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2372: $datatable .= '<tr'.$css_class.'>'.
2373: '<td><span class="LC_nobreak">'.$titles->{$item}.
2374: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2375: '<input type="text" name="'.$item.'" value="'.
2376: $to{$item}.'" /></td></tr>';
2377: }
2378: foreach my $type (@mailings) {
1.69 raeburn 2379: $rownum ++;
2380: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2381: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2382: '<td><span class="LC_nobreak">'.
2383: $titles->{$type}.': </span></td>'.
1.28 raeburn 2384: '<td class="LC_left_item">'.
2385: '<span class="LC_nobreak">';
2386: foreach my $item (@contacts) {
2387: $datatable .= '<label>'.
2388: '<input type="checkbox" name="'.$type.'"'.
2389: $checked{$type}{$item}.
2390: ' value="'.$item.'" />'.$short_titles->{$item}.
2391: '</label> ';
2392: }
2393: $datatable .= '</span><br />'.&mt('Others').': '.
2394: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2395: 'value="'.$otheremails{$type}.'" />';
2396: if ($type eq 'helpdeskmail') {
1.136 raeburn 2397: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2398: '<input type="text" name="'.$type.'_bcc" '.
2399: 'value="'.$bccemails{$type}.'" />';
2400: }
2401: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2402: }
1.30 raeburn 2403: $$rowtotal += $rownum;
1.28 raeburn 2404: return $datatable;
2405: }
2406:
1.118 jms 2407: sub print_helpsettings {
1.168 raeburn 2408: my ($dom,$confname,$settings,$rowtotal) = @_;
2409: my ($datatable,$itemcount);
1.166 raeburn 2410: $itemcount = 1;
1.168 raeburn 2411: my (%choices,%defaultchecked,@toggles);
2412: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2413: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2414: &mt('LON-CAPA bug tracker'),600,500));
2415: %defaultchecked = ('submitbugs' => 'on');
2416: @toggles = ('submitbugs',);
1.166 raeburn 2417:
1.168 raeburn 2418: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2419: \%choices,$itemcount);
1.166 raeburn 2420: return $datatable;
1.121 raeburn 2421: }
2422:
2423: sub radiobutton_prefs {
2424: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2425: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2426: (ref($choices) eq 'HASH'));
2427:
1.170 raeburn 2428: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2429:
2430: foreach my $item (@{$toggles}) {
2431: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2432: $checkedon{$item} = ' checked="checked" ';
2433: $checkedoff{$item} = ' ';
1.121 raeburn 2434: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2435: $checkedoff{$item} = ' checked="checked" ';
2436: $checkedon{$item} = ' ';
2437: }
2438: }
2439: if (ref($settings) eq 'HASH') {
1.121 raeburn 2440: foreach my $item (@{$toggles}) {
1.118 jms 2441: if ($settings->{$item} eq '1') {
2442: $checkedon{$item} = ' checked="checked" ';
2443: $checkedoff{$item} = ' ';
2444: } elsif ($settings->{$item} eq '0') {
2445: $checkedoff{$item} = ' checked="checked" ';
2446: $checkedon{$item} = ' ';
2447: }
2448: }
1.121 raeburn 2449: }
2450: foreach my $item (@{$toggles}) {
1.118 jms 2451: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2452: $datatable .=
2453: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2454: '</span></td>'.
2455: '<td class="LC_right_item"><span class="LC_nobreak">'.
2456: '<label><input type="radio" name="'.
2457: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2458: '</label> <label><input type="radio" name="'.$item.'" '.
2459: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2460: '</span></td>'.
2461: '</tr>';
2462: $itemcount ++;
1.121 raeburn 2463: }
2464: return ($datatable,$itemcount);
2465: }
2466:
2467: sub print_coursedefaults {
1.139 raeburn 2468: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2469: my ($css_class,$datatable);
2470: my $itemcount = 1;
1.139 raeburn 2471: if ($position eq 'top') {
2472: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2473: %choices =
2474: &Apache::lonlocal::texthash (
2475: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2476: );
2477: %defaultchecked = ('canuse_pdfforms' => 'off');
2478: @toggles = ('canuse_pdfforms',);
2479: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2480: \%choices,$itemcount);
1.139 raeburn 2481: $$rowtotal += $itemcount;
2482: } else {
2483: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2484: my %choices =
2485: &Apache::lonlocal::texthash (
2486: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2487: );
2488: my $currdefresponder;
2489: if (ref($settings) eq 'HASH') {
2490: $currdefresponder = $settings->{'anonsurvey_threshold'};
2491: }
2492: if (!$currdefresponder) {
2493: $currdefresponder = 10;
2494: } elsif ($currdefresponder < 1) {
2495: $currdefresponder = 1;
2496: }
2497: $datatable .=
2498: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2499: '</span></td>'.
2500: '<td class="LC_right_item"><span class="LC_nobreak">'.
2501: '<input type="text" name="anonsurvey_threshold"'.
2502: ' value="'.$currdefresponder.'" size="5" /></span>'.
2503: '</td></tr>';
2504: }
1.121 raeburn 2505: return $datatable;
1.118 jms 2506: }
2507:
1.137 raeburn 2508: sub print_usersessions {
2509: my ($position,$dom,$settings,$rowtotal) = @_;
2510: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2511: my (%by_ip,%by_location,@intdoms);
2512: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2513:
2514: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2515: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2516: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2517: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2518: my $itemcount = 1;
2519: if ($position eq 'top') {
1.152 raeburn 2520: if (keys(%serverhomes) > 1) {
1.145 raeburn 2521: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2522: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2523: } else {
1.140 raeburn 2524: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2525: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2526: }
1.137 raeburn 2527: } else {
1.145 raeburn 2528: if (keys(%by_location) == 0) {
2529: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2530: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2531: } else {
2532: my %lt = &usersession_titles();
2533: my $numinrow = 5;
2534: my $prefix;
2535: my @types;
2536: if ($position eq 'bottom') {
2537: $prefix = 'remote';
2538: @types = ('version','excludedomain','includedomain');
2539: } else {
2540: $prefix = 'hosted';
2541: @types = ('excludedomain','includedomain');
2542: }
2543: my (%current,%checkedon,%checkedoff);
2544: my @lcversions = &Apache::lonnet::all_loncaparevs();
2545: my @locations = sort(keys(%by_location));
2546: foreach my $type (@types) {
2547: $checkedon{$type} = '';
2548: $checkedoff{$type} = ' checked="checked"';
2549: }
2550: if (ref($settings) eq 'HASH') {
2551: if (ref($settings->{$prefix}) eq 'HASH') {
2552: foreach my $key (keys(%{$settings->{$prefix}})) {
2553: $current{$key} = $settings->{$prefix}{$key};
2554: if ($key eq 'version') {
2555: if ($current{$key} ne '') {
2556: $checkedon{$key} = ' checked="checked"';
2557: $checkedoff{$key} = '';
2558: }
2559: } elsif (ref($current{$key}) eq 'ARRAY') {
2560: $checkedon{$key} = ' checked="checked"';
2561: $checkedoff{$key} = '';
2562: }
1.137 raeburn 2563: }
2564: }
2565: }
1.145 raeburn 2566: foreach my $type (@types) {
2567: next if ($type ne 'version' && !@locations);
2568: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2569: $datatable .= '<tr'.$css_class.'>
2570: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2571: <span class="LC_nobreak">
2572: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2573: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2574: if ($type eq 'version') {
2575: my $selector = '<select name="'.$prefix.'_version">';
2576: foreach my $version (@lcversions) {
2577: my $selected = '';
2578: if ($current{'version'} eq $version) {
2579: $selected = ' selected="selected"';
2580: }
2581: $selector .= ' <option value="'.$version.'"'.
2582: $selected.'>'.$version.'</option>';
2583: }
2584: $selector .= '</select> ';
2585: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2586: } else {
2587: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2588: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2589: ' />'.(' 'x2).
2590: '<input type="button" value="'.&mt('uncheck all').'" '.
2591: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2592: "\n".
2593: '</div><div><table>';
2594: my $rem;
2595: for (my $i=0; $i<@locations; $i++) {
2596: my ($showloc,$value,$checkedtype);
2597: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2598: my $ip = $by_location{$locations[$i]}->[0];
2599: if (ref($by_ip{$ip}) eq 'ARRAY') {
2600: $value = join(':',@{$by_ip{$ip}});
2601: $showloc = join(', ',@{$by_ip{$ip}});
2602: if (ref($current{$type}) eq 'ARRAY') {
2603: foreach my $loc (@{$by_ip{$ip}}) {
2604: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2605: $checkedtype = ' checked="checked"';
2606: last;
2607: }
2608: }
1.138 raeburn 2609: }
2610: }
2611: }
1.145 raeburn 2612: $rem = $i%($numinrow);
2613: if ($rem == 0) {
2614: if ($i > 0) {
2615: $datatable .= '</tr>';
2616: }
2617: $datatable .= '<tr>';
2618: }
2619: $datatable .= '<td class="LC_left_item">'.
2620: '<span class="LC_nobreak"><label>'.
2621: '<input type="checkbox" name="'.$prefix.'_'.$type.
2622: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2623: '</label></span></td>';
1.137 raeburn 2624: }
1.145 raeburn 2625: $rem = @locations%($numinrow);
2626: my $colsleft = $numinrow - $rem;
2627: if ($colsleft > 1 ) {
2628: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2629: ' </td>';
2630: } elsif ($colsleft == 1) {
2631: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2632: }
1.145 raeburn 2633: $datatable .= '</tr></table>';
1.137 raeburn 2634: }
1.145 raeburn 2635: $datatable .= '</td></tr>';
2636: $itemcount ++;
1.137 raeburn 2637: }
2638: }
2639: }
2640: $$rowtotal += $itemcount;
2641: return $datatable;
2642: }
2643:
1.138 raeburn 2644: sub build_location_hashes {
2645: my ($intdoms,$by_ip,$by_location) = @_;
2646: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2647: (ref($by_location) eq 'HASH'));
2648: my %iphost = &Apache::lonnet::get_iphost();
2649: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2650: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2651: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2652: foreach my $id (@{$iphost{$primary_ip}}) {
2653: my $intdom = &Apache::lonnet::internet_dom($id);
2654: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2655: push(@{$intdoms},$intdom);
2656: }
2657: }
2658: }
2659: foreach my $ip (keys(%iphost)) {
2660: if (ref($iphost{$ip}) eq 'ARRAY') {
2661: foreach my $id (@{$iphost{$ip}}) {
2662: my $location = &Apache::lonnet::internet_dom($id);
2663: if ($location) {
2664: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2665: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2666: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2667: push(@{$by_ip->{$ip}},$location);
2668: }
2669: } else {
2670: $by_ip->{$ip} = [$location];
2671: }
2672: }
2673: }
2674: }
2675: }
2676: foreach my $ip (sort(keys(%{$by_ip}))) {
2677: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2678: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2679: my $first = $by_ip->{$ip}->[0];
2680: if (ref($by_location->{$first}) eq 'ARRAY') {
2681: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2682: push(@{$by_location->{$first}},$ip);
2683: }
2684: } else {
2685: $by_location->{$first} = [$ip];
2686: }
2687: }
2688: }
2689: return;
2690: }
2691:
1.145 raeburn 2692: sub current_offloads_to {
2693: my ($dom,$settings,$servers) = @_;
2694: my (%spareid,%otherdomconfigs);
1.152 raeburn 2695: if (ref($servers) eq 'HASH') {
1.145 raeburn 2696: foreach my $lonhost (sort(keys(%{$servers}))) {
2697: my $gotspares;
1.152 raeburn 2698: if (ref($settings) eq 'HASH') {
2699: if (ref($settings->{'spares'}) eq 'HASH') {
2700: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2701: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2702: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2703: $gotspares = 1;
2704: }
1.145 raeburn 2705: }
2706: }
2707: unless ($gotspares) {
2708: my $gotspares;
2709: my $serverhomeID =
2710: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2711: my $serverhomedom =
2712: &Apache::lonnet::host_domain($serverhomeID);
2713: if ($serverhomedom ne $dom) {
2714: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2715: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2716: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2717: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2718: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2719: $gotspares = 1;
2720: }
2721: }
2722: } else {
2723: $otherdomconfigs{$serverhomedom} =
2724: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2725: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2726: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2727: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2728: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2729: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2730: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2731: $gotspares = 1;
2732: }
2733: }
2734: }
2735: }
2736: }
2737: }
2738: }
2739: unless ($gotspares) {
2740: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2741: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2742: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2743: } else {
2744: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2745: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2746: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2747: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2748: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2749: } else {
1.150 raeburn 2750: my %what = (
2751: spareid => 1,
2752: );
2753: my ($result,$returnhash) =
2754: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2755: if ($result eq 'ok') {
2756: if (ref($returnhash) eq 'HASH') {
2757: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2758: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2759: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2760: }
2761: }
1.145 raeburn 2762: }
2763: }
2764: }
2765: }
2766: }
2767: }
2768: return %spareid;
2769: }
2770:
2771: sub spares_row {
1.152 raeburn 2772: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2773: my $css_class;
2774: my $numinrow = 4;
2775: my $itemcount = 1;
2776: my $datatable;
1.152 raeburn 2777: my %typetitles = &sparestype_titles();
2778: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2779: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2780: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2781: my ($othercontrol,$serverdom);
2782: if ($serverhome ne $server) {
2783: $serverdom = &Apache::lonnet::host_domain($serverhome);
2784: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2785: } else {
2786: $serverdom = &Apache::lonnet::host_domain($server);
2787: if ($serverdom ne $dom) {
2788: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2789: }
2790: }
2791: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2792: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2793: $datatable .= '<tr'.$css_class.'>
2794: <td rowspan="2">
1.152 raeburn 2795: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2796: my (%current,%canselect);
1.152 raeburn 2797: my @choices =
2798: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2799: foreach my $type ('primary','default') {
2800: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2801: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2802: my @spares = @{$spareid->{$server}{$type}};
2803: if (@spares > 0) {
1.152 raeburn 2804: if ($othercontrol) {
2805: $current{$type} = join(', ',@spares);
2806: } else {
2807: $current{$type} .= '<table>';
2808: my $numspares = scalar(@spares);
2809: for (my $i=0; $i<@spares; $i++) {
2810: my $rem = $i%($numinrow);
2811: if ($rem == 0) {
2812: if ($i > 0) {
2813: $current{$type} .= '</tr>';
2814: }
2815: $current{$type} .= '<tr>';
1.145 raeburn 2816: }
1.152 raeburn 2817: $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'".');" /> '.
2818: $spareid->{$server}{$type}[$i].
2819: '</label></td>'."\n";
2820: }
2821: my $rem = @spares%($numinrow);
2822: my $colsleft = $numinrow - $rem;
2823: if ($colsleft > 1 ) {
2824: $current{$type} .= '<td colspan="'.$colsleft.
2825: '" class="LC_left_item">'.
2826: ' </td>';
2827: } elsif ($colsleft == 1) {
2828: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2829: }
1.152 raeburn 2830: $current{$type} .= '</tr></table>';
1.150 raeburn 2831: }
1.145 raeburn 2832: }
2833: }
2834: if ($current{$type} eq '') {
2835: $current{$type} = &mt('None specified');
2836: }
1.152 raeburn 2837: if ($othercontrol) {
2838: if ($type eq 'primary') {
2839: $canselect{$type} = $othercontrol;
2840: }
2841: } else {
2842: $canselect{$type} =
2843: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2844: '<select name="newspare_'.$type.'_'.$server.'" '.
2845: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2846: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2847: if (@choices > 0) {
2848: foreach my $lonhost (@choices) {
2849: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2850: }
2851: }
2852: $canselect{$type} .= '</select>'."\n";
2853: }
2854: } else {
2855: $current{$type} = &mt('Could not be determined');
2856: if ($type eq 'primary') {
2857: $canselect{$type} = $othercontrol;
2858: }
1.145 raeburn 2859: }
1.152 raeburn 2860: if ($type eq 'default') {
2861: $datatable .= '<tr'.$css_class.'>';
2862: }
2863: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2864: '<td>'.$current{$type}.'</td>'."\n".
2865: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2866: }
2867: $itemcount ++;
2868: }
2869: }
2870: $$rowtotal += $itemcount;
2871: return $datatable;
2872: }
2873:
1.152 raeburn 2874: sub possible_newspares {
2875: my ($server,$currspares,$serverhomes,$altids) = @_;
2876: my $serverhostname = &Apache::lonnet::hostname($server);
2877: my %excluded;
2878: if ($serverhostname ne '') {
2879: %excluded = (
2880: $serverhostname => 1,
2881: );
2882: }
2883: if (ref($currspares) eq 'HASH') {
2884: foreach my $type (keys(%{$currspares})) {
2885: if (ref($currspares->{$type}) eq 'ARRAY') {
2886: if (@{$currspares->{$type}} > 0) {
2887: foreach my $curr (@{$currspares->{$type}}) {
2888: my $hostname = &Apache::lonnet::hostname($curr);
2889: $excluded{$hostname} = 1;
2890: }
2891: }
2892: }
2893: }
2894: }
2895: my @choices;
2896: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2897: if (keys(%{$serverhomes}) > 1) {
2898: foreach my $name (sort(keys(%{$serverhomes}))) {
2899: unless ($excluded{$name}) {
2900: if (exists($altids->{$serverhomes->{$name}})) {
2901: push(@choices,$altids->{$serverhomes->{$name}});
2902: } else {
2903: push(@choices,$serverhomes->{$name});
1.145 raeburn 2904: }
2905: }
2906: }
2907: }
2908: }
1.152 raeburn 2909: return sort(@choices);
1.145 raeburn 2910: }
2911:
1.150 raeburn 2912: sub print_loadbalancing {
2913: my ($dom,$settings,$rowtotal) = @_;
2914: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2915: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2916: my $numinrow = 1;
2917: my $datatable;
2918: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2919: my (%currbalancer,%currtargets,%currrules,%existing);
2920: if (ref($settings) eq 'HASH') {
2921: %existing = %{$settings};
2922: }
2923: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2924: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2925: \%currtargets,\%currrules);
1.150 raeburn 2926: } else {
2927: return;
2928: }
2929: my ($othertitle,$usertypes,$types) =
2930: &Apache::loncommon::sorted_inst_types($dom);
2931: my $rownum = 6;
2932: if (ref($types) eq 'ARRAY') {
2933: $rownum += scalar(@{$types});
2934: }
1.171 raeburn 2935: my @css_class = ('LC_odd_row','LC_even_row');
2936: my $balnum = 0;
2937: my $islast;
2938: my (@toshow,$disabledtext);
2939: if (keys(%currbalancer) > 0) {
2940: @toshow = sort(keys(%currbalancer));
2941: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2942: push(@toshow,'');
2943: }
2944: } else {
2945: @toshow = ('');
2946: $disabledtext = &mt('No existing load balancer');
2947: }
2948: foreach my $lonhost (@toshow) {
2949: if ($balnum == scalar(@toshow)-1) {
2950: $islast = 1;
2951: } else {
2952: $islast = 0;
2953: }
2954: my $cssidx = $balnum%2;
2955: my $targets_div_style = 'display: none';
2956: my $disabled_div_style = 'display: block';
2957: my $homedom_div_style = 'display: none';
2958: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2959: '<td rowspan="'.$rownum.'" valign="top">'.
2960: '<p>';
2961: if ($lonhost eq '') {
2962: $datatable .= '<span class="LC_nobreak">';
2963: if (keys(%currbalancer) > 0) {
2964: $datatable .= &mt('Add balancer:');
2965: } else {
2966: $datatable .= &mt('Enable balancer:');
2967: }
2968: $datatable .= ' '.
2969: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2970: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2971: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2972: '<option value="" selected="selected">'.&mt('None').
2973: '</option>'."\n";
2974: foreach my $server (sort(keys(%servers))) {
2975: next if ($currbalancer{$server});
2976: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2977: }
2978: $datatable .=
2979: '</select>'."\n".
2980: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2981: } else {
2982: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2983: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2984: &mt('Stop balancing').'</label>'.
2985: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2986: $targets_div_style = 'display: block';
2987: $disabled_div_style = 'display: none';
2988: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2989: $homedom_div_style = 'display: block';
2990: }
2991: }
2992: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2993: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2994: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2995: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2996: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2997: my @sparestypes = ('primary','default');
2998: my %typetitles = &sparestype_titles();
2999: foreach my $sparetype (@sparestypes) {
3000: my $targettable;
3001: for (my $i=0; $i<$numspares; $i++) {
3002: my $checked;
3003: if (ref($currtargets{$lonhost}) eq 'HASH') {
3004: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3005: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3006: $checked = ' checked="checked"';
3007: }
3008: }
3009: }
3010: my ($chkboxval,$disabled);
3011: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3012: $chkboxval = $spares[$i];
3013: }
3014: if (exists($currbalancer{$spares[$i]})) {
3015: $disabled = ' disabled="disabled"';
3016: }
3017: $targettable .=
3018: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3019: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3020: '</span></label></td>';
3021: my $rem = $i%($numinrow);
3022: if ($rem == 0) {
3023: if (($i > 0) && ($i < $numspares-1)) {
3024: $targettable .= '</tr>';
3025: }
3026: if ($i < $numspares-1) {
3027: $targettable .= '<tr>';
1.150 raeburn 3028: }
3029: }
3030: }
1.171 raeburn 3031: if ($targettable ne '') {
3032: my $rem = $numspares%($numinrow);
3033: my $colsleft = $numinrow - $rem;
3034: if ($colsleft > 1 ) {
3035: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3036: ' </td>';
3037: } elsif ($colsleft == 1) {
3038: $targettable .= '<td class="LC_left_item"> </td>';
3039: }
3040: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3041: '<table><tr>'.$targettable.'</tr></table><br />';
3042: }
3043: }
3044: $datatable .= '</div></td></tr>'.
3045: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3046: $othertitle,$usertypes,$types,\%servers,
3047: \%currbalancer,$lonhost,
3048: $targets_div_style,$homedom_div_style,
3049: $css_class[$cssidx],$balnum,$islast);
3050: $$rowtotal += $rownum;
3051: $balnum ++;
3052: }
3053: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3054: return $datatable;
3055: }
3056:
3057: sub get_loadbalancers_config {
3058: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3059: return unless ((ref($servers) eq 'HASH') &&
3060: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3061: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3062: if (keys(%{$existing}) > 0) {
3063: my $oldlonhost;
3064: foreach my $key (sort(keys(%{$existing}))) {
3065: if ($key eq 'lonhost') {
3066: $oldlonhost = $existing->{'lonhost'};
3067: $currbalancer->{$oldlonhost} = 1;
3068: } elsif ($key eq 'targets') {
3069: if ($oldlonhost) {
3070: $currtargets->{$oldlonhost} = $existing->{'targets'};
3071: }
3072: } elsif ($key eq 'rules') {
3073: if ($oldlonhost) {
3074: $currrules->{$oldlonhost} = $existing->{'rules'};
3075: }
3076: } elsif (ref($existing->{$key}) eq 'HASH') {
3077: $currbalancer->{$key} = 1;
3078: $currtargets->{$key} = $existing->{$key}{'targets'};
3079: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3080: }
3081: }
1.171 raeburn 3082: } else {
3083: my ($balancerref,$targetsref) =
3084: &Apache::lonnet::get_lonbalancer_config($servers);
3085: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3086: foreach my $server (sort(keys(%{$balancerref}))) {
3087: $currbalancer->{$server} = 1;
3088: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3089: }
3090: }
3091: }
1.171 raeburn 3092: return;
1.150 raeburn 3093: }
3094:
3095: sub loadbalancing_rules {
3096: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3097: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3098: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3099: my $output;
1.171 raeburn 3100: my $num = 0;
1.150 raeburn 3101: my ($alltypes,$othertypes,$titles) =
3102: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3103: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3104: foreach my $type (@{$alltypes}) {
1.171 raeburn 3105: $num ++;
1.150 raeburn 3106: my $current;
3107: if (ref($currrules) eq 'HASH') {
3108: $current = $currrules->{$type};
3109: }
3110: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3111: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3112: $current = '';
3113: }
3114: }
3115: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3116: $servers,$currbalancer,$lonhost,$dom,
3117: $targets_div_style,$homedom_div_style,
3118: $css_class,$balnum,$num,$islast);
1.150 raeburn 3119: }
3120: }
3121: return $output;
3122: }
3123:
3124: sub loadbalancing_titles {
3125: my ($dom,$intdom,$usertypes,$types) = @_;
3126: my %othertypes = (
3127: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3128: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3129: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3130: '_LC_external' => &mt('Users not from [_1]',$intdom),
3131: );
3132: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3133: if (ref($types) eq 'ARRAY') {
3134: unshift(@alltypes,@{$types},'default');
3135: }
3136: my %titles;
3137: foreach my $type (@alltypes) {
3138: if ($type =~ /^_LC_/) {
3139: $titles{$type} = $othertypes{$type};
3140: } elsif ($type eq 'default') {
3141: $titles{$type} = &mt('All users from [_1]',$dom);
3142: if (ref($types) eq 'ARRAY') {
3143: if (@{$types} > 0) {
3144: $titles{$type} = &mt('Other users from [_1]',$dom);
3145: }
3146: }
3147: } elsif (ref($usertypes) eq 'HASH') {
3148: $titles{$type} = $usertypes->{$type};
3149: }
3150: }
3151: return (\@alltypes,\%othertypes,\%titles);
3152: }
3153:
3154: sub loadbalance_rule_row {
1.171 raeburn 3155: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3156: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3157: my @rulenames = ('default','homeserver');
3158: my %ruletitles = &offloadtype_text();
3159: if ($type eq '_LC_external') {
3160: push(@rulenames,'externalbalancer');
3161: } else {
3162: push(@rulenames,'specific');
3163: }
1.161 raeburn 3164: push(@rulenames,'none');
1.150 raeburn 3165: my $style = $targets_div_style;
3166: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3167: $style = $homedom_div_style;
3168: }
1.171 raeburn 3169: my $space;
3170: if ($islast && $num == 1) {
3171: $space = '<div display="inline-block"> </div>';
3172: }
1.150 raeburn 3173: my $output =
1.171 raeburn 3174: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3175: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3176: '<td valaign="top">'.$space.
3177: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3178: for (my $i=0; $i<@rulenames; $i++) {
3179: my $rule = $rulenames[$i];
3180: my ($checked,$extra);
3181: if ($rulenames[$i] eq 'default') {
3182: $rule = '';
3183: }
3184: if ($rulenames[$i] eq 'specific') {
3185: if (ref($servers) eq 'HASH') {
3186: my $default;
3187: if (($current ne '') && (exists($servers->{$current}))) {
3188: $checked = ' checked="checked"';
3189: }
3190: unless ($checked) {
3191: $default = ' selected="selected"';
3192: }
1.171 raeburn 3193: $extra =
3194: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3195: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3196: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3197: '<option value=""'.$default.'></option>'."\n";
3198: foreach my $server (sort(keys(%{$servers}))) {
3199: if (ref($currbalancer) eq 'HASH') {
3200: next if (exists($currbalancer->{$server}));
3201: }
1.150 raeburn 3202: my $selected;
1.171 raeburn 3203: if ($server eq $current) {
1.150 raeburn 3204: $selected = ' selected="selected"';
3205: }
1.171 raeburn 3206: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3207: }
3208: $extra .= '</select>';
3209: }
3210: } elsif ($rule eq $current) {
3211: $checked = ' checked="checked"';
3212: }
3213: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3214: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3215: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3216: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3217: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3218: '</label>'.$extra.'</span><br />'."\n";
3219: }
3220: $output .= '</div></td></tr>'."\n";
3221: return $output;
3222: }
3223:
3224: sub offloadtype_text {
3225: my %ruletitles = &Apache::lonlocal::texthash (
3226: 'default' => 'Offloads to default destinations',
3227: 'homeserver' => "Offloads to user's home server",
3228: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3229: 'specific' => 'Offloads to specific server',
1.161 raeburn 3230: 'none' => 'No offload',
1.150 raeburn 3231: );
3232: return %ruletitles;
3233: }
3234:
3235: sub sparestype_titles {
3236: my %typestitles = &Apache::lonlocal::texthash (
3237: 'primary' => 'primary',
3238: 'default' => 'default',
3239: );
3240: return %typestitles;
3241: }
3242:
1.28 raeburn 3243: sub contact_titles {
3244: my %titles = &Apache::lonlocal::texthash (
3245: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3246: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3247: 'errormail' => 'Error reports to be e-mailed to',
3248: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3249: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3250: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3251: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3252: );
3253: my %short_titles = &Apache::lonlocal::texthash (
3254: adminemail => 'Admin E-mail address',
3255: supportemail => 'Support E-mail',
3256: );
3257: return (\%titles,\%short_titles);
3258: }
3259:
1.72 raeburn 3260: sub tool_titles {
3261: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3262: aboutme => 'Personal web page',
1.86 raeburn 3263: blog => 'Blog',
1.162 raeburn 3264: webdav => 'WebDAV',
1.86 raeburn 3265: portfolio => 'Portfolio',
1.88 bisitz 3266: official => 'Official courses (with institutional codes)',
3267: unofficial => 'Unofficial courses',
1.98 raeburn 3268: community => 'Communities',
1.86 raeburn 3269: );
1.72 raeburn 3270: return %titles;
3271: }
3272:
1.101 raeburn 3273: sub courserequest_titles {
3274: my %titles = &Apache::lonlocal::texthash (
3275: official => 'Official',
3276: unofficial => 'Unofficial',
3277: community => 'Communities',
3278: norequest => 'Not allowed',
1.104 raeburn 3279: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3280: validate => 'With validation',
3281: autolimit => 'Numerical limit',
1.103 raeburn 3282: unlimited => '(blank for unlimited)',
1.101 raeburn 3283: );
3284: return %titles;
3285: }
3286:
1.163 raeburn 3287: sub authorrequest_titles {
3288: my %titles = &Apache::lonlocal::texthash (
3289: norequest => 'Not allowed',
3290: approval => 'Approval by Dom. Coord.',
3291: automatic => 'Automatic approval',
3292: );
3293: return %titles;
3294: }
3295:
1.101 raeburn 3296: sub courserequest_conditions {
3297: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3298: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3299: validate => '(Processing of request subject to instittutional validation).',
3300: );
3301: return %conditions;
3302: }
3303:
3304:
1.27 raeburn 3305: sub print_usercreation {
1.30 raeburn 3306: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3307: my $numinrow = 4;
1.28 raeburn 3308: my $datatable;
3309: if ($position eq 'top') {
1.30 raeburn 3310: $$rowtotal ++;
1.34 raeburn 3311: my $rowcount = 0;
1.32 raeburn 3312: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3313: if (ref($rules) eq 'HASH') {
3314: if (keys(%{$rules}) > 0) {
1.32 raeburn 3315: $datatable .= &user_formats_row('username',$settings,$rules,
3316: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3317: $$rowtotal ++;
1.32 raeburn 3318: $rowcount ++;
3319: }
3320: }
3321: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3322: if (ref($idrules) eq 'HASH') {
3323: if (keys(%{$idrules}) > 0) {
3324: $datatable .= &user_formats_row('id',$settings,$idrules,
3325: $idruleorder,$numinrow,$rowcount);
3326: $$rowtotal ++;
3327: $rowcount ++;
1.28 raeburn 3328: }
3329: }
1.43 raeburn 3330: my ($emailrules,$emailruleorder) =
3331: &Apache::lonnet::inst_userrules($dom,'email');
3332: if (ref($emailrules) eq 'HASH') {
3333: if (keys(%{$emailrules}) > 0) {
3334: $datatable .= &user_formats_row('email',$settings,$emailrules,
3335: $emailruleorder,$numinrow,$rowcount);
3336: $$rowtotal ++;
3337: $rowcount ++;
3338: }
3339: }
1.39 raeburn 3340: if ($rowcount == 0) {
3341: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3342: $$rowtotal ++;
3343: $rowcount ++;
3344: }
1.34 raeburn 3345: } elsif ($position eq 'middle') {
1.100 raeburn 3346: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3347: my ($rules,$ruleorder) =
3348: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3349: my %lt = &usercreation_types();
3350: my %checked;
1.50 raeburn 3351: my @selfcreate;
1.34 raeburn 3352: if (ref($settings) eq 'HASH') {
3353: if (ref($settings->{'cancreate'}) eq 'HASH') {
3354: foreach my $item (@creators) {
3355: $checked{$item} = $settings->{'cancreate'}{$item};
3356: }
1.50 raeburn 3357: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3358: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3359: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3360: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3361: @selfcreate = ('email','login','sso');
3362: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3363: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3364: }
3365: }
1.34 raeburn 3366: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3367: foreach my $item (@creators) {
3368: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3369: $checked{$item} = 'none';
3370: }
3371: }
3372: }
3373: }
3374: my $rownum = 0;
3375: foreach my $item (@creators) {
3376: $rownum ++;
1.50 raeburn 3377: if ($item ne 'selfcreate') {
3378: if ($checked{$item} eq '') {
1.43 raeburn 3379: $checked{$item} = 'any';
3380: }
1.34 raeburn 3381: }
3382: my $css_class;
3383: if ($rownum%2) {
3384: $css_class = '';
3385: } else {
3386: $css_class = ' class="LC_odd_row" ';
3387: }
3388: $datatable .= '<tr'.$css_class.'>'.
3389: '<td><span class="LC_nobreak">'.$lt{$item}.
3390: '</span></td><td align="right">';
1.50 raeburn 3391: my @options;
1.45 raeburn 3392: if ($item eq 'selfcreate') {
1.43 raeburn 3393: push(@options,('email','login','sso'));
3394: } else {
1.50 raeburn 3395: @options = ('any');
1.43 raeburn 3396: if (ref($rules) eq 'HASH') {
3397: if (keys(%{$rules}) > 0) {
3398: push(@options,('official','unofficial'));
3399: }
1.37 raeburn 3400: }
1.50 raeburn 3401: push(@options,'none');
1.37 raeburn 3402: }
3403: foreach my $option (@options) {
1.50 raeburn 3404: my $type = 'radio';
1.34 raeburn 3405: my $check = ' ';
1.50 raeburn 3406: if ($item eq 'selfcreate') {
3407: $type = 'checkbox';
3408: if (grep(/^\Q$option\E$/,@selfcreate)) {
3409: $check = ' checked="checked" ';
3410: }
3411: } else {
3412: if ($checked{$item} eq $option) {
3413: $check = ' checked="checked" ';
3414: }
1.34 raeburn 3415: }
3416: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3417: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3418: $item.'" value="'.$option.'"'.$check.'/> '.
3419: $lt{$option}.'</label> </span>';
3420: }
3421: $datatable .= '</td></tr>';
3422: }
1.93 raeburn 3423: my ($othertitle,$usertypes,$types) =
3424: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3425: my $createsettings;
3426: if (ref($settings) eq 'HASH') {
3427: $createsettings = $settings->{cancreate};
3428: }
1.93 raeburn 3429: if (ref($usertypes) eq 'HASH') {
3430: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3431: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3432: $dom,$numinrow,$othertitle,
3433: 'statustocreate');
3434: $$rowtotal ++;
1.169 raeburn 3435: $rownum ++;
1.93 raeburn 3436: }
3437: }
1.169 raeburn 3438: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3439: } else {
3440: my @contexts = ('author','course','domain');
3441: my @authtypes = ('int','krb4','krb5','loc');
3442: my %checked;
3443: if (ref($settings) eq 'HASH') {
3444: if (ref($settings->{'authtypes'}) eq 'HASH') {
3445: foreach my $item (@contexts) {
3446: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3447: foreach my $auth (@authtypes) {
3448: if ($settings->{'authtypes'}{$item}{$auth}) {
3449: $checked{$item}{$auth} = ' checked="checked" ';
3450: }
3451: }
3452: }
3453: }
1.27 raeburn 3454: }
1.35 raeburn 3455: } else {
3456: foreach my $item (@contexts) {
1.36 raeburn 3457: foreach my $auth (@authtypes) {
1.35 raeburn 3458: $checked{$item}{$auth} = ' checked="checked" ';
3459: }
3460: }
1.27 raeburn 3461: }
1.28 raeburn 3462: my %title = &context_names();
3463: my %authname = &authtype_names();
3464: my $rownum = 0;
3465: my $css_class;
3466: foreach my $item (@contexts) {
3467: if ($rownum%2) {
3468: $css_class = '';
3469: } else {
3470: $css_class = ' class="LC_odd_row" ';
3471: }
1.30 raeburn 3472: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3473: '<td>'.$title{$item}.
3474: '</td><td class="LC_left_item">'.
3475: '<span class="LC_nobreak">';
3476: foreach my $auth (@authtypes) {
3477: $datatable .= '<label>'.
3478: '<input type="checkbox" name="'.$item.'_auth" '.
3479: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3480: $authname{$auth}.'</label> ';
3481: }
3482: $datatable .= '</span></td></tr>';
3483: $rownum ++;
1.27 raeburn 3484: }
1.30 raeburn 3485: $$rowtotal += $rownum;
1.27 raeburn 3486: }
3487: return $datatable;
3488: }
3489:
1.165 raeburn 3490: sub captcha_choice {
1.169 raeburn 3491: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3492: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3493: my %lt = &captcha_phrases();
3494: $keyentry = 'hidden';
3495: if ($context eq 'cancreate') {
3496: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3497: } elsif ($context eq 'login') {
3498: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3499: }
3500: if (ref($settings) eq 'HASH') {
3501: if ($settings->{'captcha'}) {
3502: $checked{$settings->{'captcha'}} = ' checked="checked"';
3503: } else {
3504: $checked{'original'} = ' checked="checked"';
3505: }
3506: if ($settings->{'captcha'} eq 'recaptcha') {
3507: $pubtext = $lt{'pub'};
3508: $privtext = $lt{'priv'};
3509: $keyentry = 'text';
3510: }
3511: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3512: $currpub = $settings->{'recaptchakeys'}{'public'};
3513: $currpriv = $settings->{'recaptchakeys'}{'private'};
3514: }
3515: } else {
3516: $checked{'original'} = ' checked="checked"';
3517: }
1.169 raeburn 3518: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3519: my $output = '<tr'.$css_class.'>'.
3520: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3521: '<table><tr><td>'."\n";
3522: foreach my $option ('original','recaptcha','notused') {
3523: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3524: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3525: $lt{$option}.'</label></span>';
3526: unless ($option eq 'notused') {
3527: $output .= (' 'x2)."\n";
3528: }
3529: }
3530: #
3531: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3532: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3533: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3534: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3535: #
3536: $output .= '</td></tr>'."\n".
3537: '<tr><td>'."\n".
3538: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3539: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3540: $currpub.'" size="40" /></span><br />'."\n".
3541: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3542: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3543: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3544: '</td></tr>';
3545: return $output;
3546: }
3547:
1.32 raeburn 3548: sub user_formats_row {
3549: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3550: my $output;
3551: my %text = (
3552: 'username' => 'new usernames',
3553: 'id' => 'IDs',
1.45 raeburn 3554: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3555: );
3556: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3557: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3558: '<td><span class="LC_nobreak">';
3559: if ($type eq 'email') {
3560: $output .= &mt("Formats disallowed for $text{$type}: ");
3561: } else {
3562: $output .= &mt("Format rules to check for $text{$type}: ");
3563: }
3564: $output .= '</span></td>'.
3565: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3566: my $rem;
3567: if (ref($ruleorder) eq 'ARRAY') {
3568: for (my $i=0; $i<@{$ruleorder}; $i++) {
3569: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3570: my $rem = $i%($numinrow);
3571: if ($rem == 0) {
3572: if ($i > 0) {
3573: $output .= '</tr>';
3574: }
3575: $output .= '<tr>';
3576: }
3577: my $check = ' ';
1.39 raeburn 3578: if (ref($settings) eq 'HASH') {
3579: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3580: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3581: $check = ' checked="checked" ';
3582: }
1.27 raeburn 3583: }
3584: }
3585: $output .= '<td class="LC_left_item">'.
3586: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3587: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3588: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3589: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3590: }
3591: }
3592: $rem = @{$ruleorder}%($numinrow);
3593: }
3594: my $colsleft = $numinrow - $rem;
3595: if ($colsleft > 1 ) {
3596: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3597: ' </td>';
3598: } elsif ($colsleft == 1) {
3599: $output .= '<td class="LC_left_item"> </td>';
3600: }
3601: $output .= '</tr></table></td></tr>';
3602: return $output;
3603: }
3604:
1.34 raeburn 3605: sub usercreation_types {
3606: my %lt = &Apache::lonlocal::texthash (
3607: author => 'When adding a co-author',
3608: course => 'When adding a user to a course',
1.100 raeburn 3609: requestcrs => 'When requesting a course',
1.45 raeburn 3610: selfcreate => 'User creates own account',
1.34 raeburn 3611: any => 'Any',
3612: official => 'Institutional only ',
3613: unofficial => 'Non-institutional only',
1.85 schafran 3614: email => 'E-mail address',
1.43 raeburn 3615: login => 'Institutional Login',
3616: sso => 'SSO',
1.34 raeburn 3617: none => 'None',
3618: );
3619: return %lt;
1.48 raeburn 3620: }
1.34 raeburn 3621:
1.28 raeburn 3622: sub authtype_names {
3623: my %lt = &Apache::lonlocal::texthash(
3624: int => 'Internal',
3625: krb4 => 'Kerberos 4',
3626: krb5 => 'Kerberos 5',
3627: loc => 'Local',
3628: );
3629: return %lt;
3630: }
3631:
3632: sub context_names {
3633: my %context_title = &Apache::lonlocal::texthash(
3634: author => 'Creating users when an Author',
3635: course => 'Creating users when in a course',
3636: domain => 'Creating users when a Domain Coordinator',
3637: );
3638: return %context_title;
3639: }
3640:
1.33 raeburn 3641: sub print_usermodification {
3642: my ($position,$dom,$settings,$rowtotal) = @_;
3643: my $numinrow = 4;
3644: my ($context,$datatable,$rowcount);
3645: if ($position eq 'top') {
3646: $rowcount = 0;
3647: $context = 'author';
3648: foreach my $role ('ca','aa') {
3649: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3650: $numinrow,$rowcount);
3651: $$rowtotal ++;
3652: $rowcount ++;
3653: }
1.63 raeburn 3654: } elsif ($position eq 'middle') {
1.33 raeburn 3655: $context = 'course';
3656: $rowcount = 0;
3657: foreach my $role ('st','ep','ta','in','cr') {
3658: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3659: $numinrow,$rowcount);
3660: $$rowtotal ++;
3661: $rowcount ++;
3662: }
1.63 raeburn 3663: } elsif ($position eq 'bottom') {
3664: $context = 'selfcreate';
3665: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3666: $usertypes->{'default'} = $othertitle;
3667: if (ref($types) eq 'ARRAY') {
3668: push(@{$types},'default');
3669: $usertypes->{'default'} = $othertitle;
3670: foreach my $status (@{$types}) {
3671: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3672: $numinrow,$rowcount,$usertypes);
3673: $$rowtotal ++;
3674: $rowcount ++;
3675: }
3676: }
1.33 raeburn 3677: }
3678: return $datatable;
3679: }
3680:
1.43 raeburn 3681: sub print_defaults {
3682: my ($dom,$rowtotal) = @_;
1.68 raeburn 3683: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3684: 'datelocale_def','portal_def');
1.43 raeburn 3685: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3686: my $titles = &defaults_titles($dom);
1.43 raeburn 3687: my $rownum = 0;
3688: my ($datatable,$css_class);
3689: foreach my $item (@items) {
3690: if ($rownum%2) {
3691: $css_class = '';
3692: } else {
3693: $css_class = ' class="LC_odd_row" ';
3694: }
3695: $datatable .= '<tr'.$css_class.'>'.
3696: '<td><span class="LC_nobreak">'.$titles->{$item}.
3697: '</span></td><td class="LC_right_item">';
3698: if ($item eq 'auth_def') {
3699: my @authtypes = ('internal','krb4','krb5','localauth');
3700: my %shortauth = (
3701: internal => 'int',
3702: krb4 => 'krb4',
3703: krb5 => 'krb5',
3704: localauth => 'loc'
3705: );
3706: my %authnames = &authtype_names();
3707: foreach my $auth (@authtypes) {
3708: my $checked = ' ';
3709: if ($domdefaults{$item} eq $auth) {
3710: $checked = ' checked="checked" ';
3711: }
3712: $datatable .= '<label><input type="radio" name="'.$item.
3713: '" value="'.$auth.'"'.$checked.'/>'.
3714: $authnames{$shortauth{$auth}}.'</label> ';
3715: }
1.54 raeburn 3716: } elsif ($item eq 'timezone_def') {
3717: my $includeempty = 1;
3718: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3719: } elsif ($item eq 'datelocale_def') {
3720: my $includeempty = 1;
3721: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3722: } elsif ($item eq 'lang_def') {
1.168 raeburn 3723: my %langchoices = &get_languages_hash();
3724: $langchoices{''} = 'No language preference';
1.167 raeburn 3725: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3726: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3727: \%langchoices);
1.43 raeburn 3728: } else {
1.141 raeburn 3729: my $size;
3730: if ($item eq 'portal_def') {
3731: $size = ' size="25"';
3732: }
1.43 raeburn 3733: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3734: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3735: }
3736: $datatable .= '</td></tr>';
3737: $rownum ++;
3738: }
3739: $$rowtotal += $rownum;
3740: return $datatable;
3741: }
3742:
1.168 raeburn 3743: sub get_languages_hash {
3744: my %langchoices;
3745: foreach my $id (&Apache::loncommon::languageids()) {
3746: my $code = &Apache::loncommon::supportedlanguagecode($id);
3747: if ($code ne '') {
3748: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3749: }
3750: }
3751: return %langchoices;
3752: }
3753:
1.43 raeburn 3754: sub defaults_titles {
1.141 raeburn 3755: my ($dom) = @_;
1.43 raeburn 3756: my %titles = &Apache::lonlocal::texthash (
3757: 'auth_def' => 'Default authentication type',
3758: 'auth_arg_def' => 'Default authentication argument',
3759: 'lang_def' => 'Default language',
1.54 raeburn 3760: 'timezone_def' => 'Default timezone',
1.68 raeburn 3761: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3762: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3763: );
1.141 raeburn 3764: if ($dom) {
3765: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3766: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3767: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3768: $protocol = 'http' if ($protocol ne 'https');
3769: if ($uint_dom) {
3770: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3771: $uint_dom);
3772: }
3773: }
1.43 raeburn 3774: return (\%titles);
3775: }
3776:
1.46 raeburn 3777: sub print_scantronformat {
3778: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3779: my $itemcount = 1;
1.60 raeburn 3780: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3781: %confhash);
1.46 raeburn 3782: my $switchserver = &check_switchserver($dom,$confname);
3783: my %lt = &Apache::lonlocal::texthash (
1.95 www 3784: default => 'Default bubblesheet format file error',
3785: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3786: );
3787: my %scantronfiles = (
3788: default => 'default.tab',
3789: custom => 'custom.tab',
3790: );
3791: foreach my $key (keys(%scantronfiles)) {
3792: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3793: .$scantronfiles{$key};
3794: }
3795: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3796: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3797: if (!$switchserver) {
3798: my $servadm = $r->dir_config('lonAdmEMail');
3799: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3800: if ($configuserok eq 'ok') {
3801: if ($author_ok eq 'ok') {
3802: my %legacyfile = (
3803: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3804: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3805: );
3806: my %md5chk;
3807: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3808: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3809: chomp($md5chk{$type});
1.46 raeburn 3810: }
3811: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3812: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3813: ($scantronurls{$type},my $error) =
1.46 raeburn 3814: &legacy_scantronformat($r,$dom,$confname,
3815: $type,$legacyfile{$type},
3816: $scantronurls{$type},
3817: $scantronfiles{$type});
1.60 raeburn 3818: if ($error ne '') {
3819: $error{$type} = $error;
3820: }
3821: }
3822: if (keys(%error) == 0) {
3823: $is_custom = 1;
3824: $confhash{'scantron'}{'scantronformat'} =
3825: $scantronurls{'custom'};
3826: my $putresult =
3827: &Apache::lonnet::put_dom('configuration',
3828: \%confhash,$dom);
3829: if ($putresult ne 'ok') {
3830: $error{'custom'} =
3831: '<span class="LC_error">'.
3832: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3833: }
1.46 raeburn 3834: }
3835: } else {
1.60 raeburn 3836: ($scantronurls{'default'},my $error) =
1.46 raeburn 3837: &legacy_scantronformat($r,$dom,$confname,
3838: 'default',$legacyfile{'default'},
3839: $scantronurls{'default'},
3840: $scantronfiles{'default'});
1.60 raeburn 3841: if ($error eq '') {
3842: $confhash{'scantron'}{'scantronformat'} = '';
3843: my $putresult =
3844: &Apache::lonnet::put_dom('configuration',
3845: \%confhash,$dom);
3846: if ($putresult ne 'ok') {
3847: $error{'default'} =
3848: '<span class="LC_error">'.
3849: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3850: }
3851: } else {
3852: $error{'default'} = $error;
3853: }
1.46 raeburn 3854: }
3855: }
3856: }
3857: } else {
1.95 www 3858: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3859: }
3860: }
3861: if (ref($settings) eq 'HASH') {
3862: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3863: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3864: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3865: $scantronurl = '';
3866: } else {
3867: $scantronurl = $settings->{'scantronformat'};
3868: }
3869: $is_custom = 1;
3870: } else {
3871: $scantronurl = $scantronurls{'default'};
3872: }
3873: } else {
1.60 raeburn 3874: if ($is_custom) {
3875: $scantronurl = $scantronurls{'custom'};
3876: } else {
3877: $scantronurl = $scantronurls{'default'};
3878: }
1.46 raeburn 3879: }
3880: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3881: $datatable .= '<tr'.$css_class.'>';
3882: if (!$is_custom) {
1.65 raeburn 3883: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3884: '<span class="LC_nobreak">';
1.46 raeburn 3885: if ($scantronurl) {
3886: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3887: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3888: } else {
3889: $datatable = &mt('File unavailable for display');
3890: }
1.65 raeburn 3891: $datatable .= '</span></td>';
1.60 raeburn 3892: if (keys(%error) == 0) {
3893: $datatable .= '<td valign="bottom">';
3894: if (!$switchserver) {
3895: $datatable .= &mt('Upload:').'<br />';
3896: }
3897: } else {
3898: my $errorstr;
3899: foreach my $key (sort(keys(%error))) {
3900: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3901: }
3902: $datatable .= '<td>'.$errorstr;
3903: }
1.46 raeburn 3904: } else {
3905: if (keys(%error) > 0) {
3906: my $errorstr;
3907: foreach my $key (sort(keys(%error))) {
3908: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3909: }
1.60 raeburn 3910: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3911: } elsif ($scantronurl) {
1.65 raeburn 3912: $datatable .= '<td><span class="LC_nobreak">'.
3913: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3914: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3915: '<input type="checkbox" name="scantronformat_del"'.
3916: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3917: '<td><span class="LC_nobreak"> '.
3918: &mt('Replace:').'</span><br />';
1.46 raeburn 3919: }
3920: }
3921: if (keys(%error) == 0) {
3922: if ($switchserver) {
3923: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3924: } else {
1.65 raeburn 3925: $datatable .='<span class="LC_nobreak"> '.
3926: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3927: }
3928: }
3929: $datatable .= '</td></tr>';
3930: $$rowtotal ++;
3931: return $datatable;
3932: }
3933:
3934: sub legacy_scantronformat {
3935: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3936: my ($url,$error);
3937: my @statinfo = &Apache::lonnet::stat_file($newurl);
3938: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3939: (my $result,$url) =
3940: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3941: '','',$newfile);
3942: if ($result ne 'ok') {
1.130 raeburn 3943: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3944: }
3945: }
3946: return ($url,$error);
3947: }
1.43 raeburn 3948:
1.49 raeburn 3949: sub print_coursecategories {
1.57 raeburn 3950: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3951: my $datatable;
3952: if ($position eq 'top') {
3953: my $toggle_cats_crs = ' ';
3954: my $toggle_cats_dom = ' checked="checked" ';
3955: my $can_cat_crs = ' ';
3956: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3957: my $toggle_catscomm_comm = ' ';
3958: my $toggle_catscomm_dom = ' checked="checked" ';
3959: my $can_catcomm_comm = ' ';
3960: my $can_catcomm_dom = ' checked="checked" ';
3961:
1.57 raeburn 3962: if (ref($settings) eq 'HASH') {
3963: if ($settings->{'togglecats'} eq 'crs') {
3964: $toggle_cats_crs = $toggle_cats_dom;
3965: $toggle_cats_dom = ' ';
3966: }
3967: if ($settings->{'categorize'} eq 'crs') {
3968: $can_cat_crs = $can_cat_dom;
3969: $can_cat_dom = ' ';
3970: }
1.120 raeburn 3971: if ($settings->{'togglecatscomm'} eq 'comm') {
3972: $toggle_catscomm_comm = $toggle_catscomm_dom;
3973: $toggle_catscomm_dom = ' ';
3974: }
3975: if ($settings->{'categorizecomm'} eq 'comm') {
3976: $can_catcomm_comm = $can_catcomm_dom;
3977: $can_catcomm_dom = ' ';
3978: }
1.57 raeburn 3979: }
3980: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3981: togglecats => 'Show/Hide a course in catalog',
3982: togglecatscomm => 'Show/Hide a community in catalog',
3983: categorize => 'Assign a category to a course',
3984: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3985: );
3986: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3987: dom => 'Set in Domain',
3988: crs => 'Set in Course',
3989: comm => 'Set in Community',
1.57 raeburn 3990: );
3991: $datatable = '<tr class="LC_odd_row">'.
3992: '<td>'.$title{'togglecats'}.'</td>'.
3993: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3994: '<input type="radio" name="togglecats"'.
3995: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3996: '<label><input type="radio" name="togglecats"'.
3997: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3998: '</tr><tr>'.
3999: '<td>'.$title{'categorize'}.'</td>'.
4000: '<td class="LC_right_item"><span class="LC_nobreak">'.
4001: '<label><input type="radio" name="categorize"'.
4002: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4003: '<label><input type="radio" name="categorize"'.
4004: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4005: '</tr><tr class="LC_odd_row">'.
4006: '<td>'.$title{'togglecatscomm'}.'</td>'.
4007: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4008: '<input type="radio" name="togglecatscomm"'.
4009: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4010: '<label><input type="radio" name="togglecatscomm"'.
4011: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4012: '</tr><tr>'.
4013: '<td>'.$title{'categorizecomm'}.'</td>'.
4014: '<td class="LC_right_item"><span class="LC_nobreak">'.
4015: '<label><input type="radio" name="categorizecomm"'.
4016: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4017: '<label><input type="radio" name="categorizecomm"'.
4018: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4019: '</tr>';
1.120 raeburn 4020: $$rowtotal += 4;
1.57 raeburn 4021: } else {
4022: my $css_class;
4023: my $itemcount = 1;
4024: my $cathash;
4025: if (ref($settings) eq 'HASH') {
4026: $cathash = $settings->{'cats'};
4027: }
4028: if (ref($cathash) eq 'HASH') {
4029: my (@cats,@trails,%allitems,%idx,@jsarray);
4030: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4031: \%allitems,\%idx,\@jsarray);
4032: my $maxdepth = scalar(@cats);
4033: my $colattrib = '';
4034: if ($maxdepth > 2) {
4035: $colattrib = ' colspan="2" ';
4036: }
4037: my @path;
4038: if (@cats > 0) {
4039: if (ref($cats[0]) eq 'ARRAY') {
4040: my $numtop = @{$cats[0]};
4041: my $maxnum = $numtop;
1.120 raeburn 4042: my %default_names = (
4043: instcode => &mt('Official courses'),
4044: communities => &mt('Communities'),
4045: );
4046:
4047: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4048: ($cathash->{'instcode::0'} eq '') ||
4049: (!grep(/^communities$/,@{$cats[0]})) ||
4050: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4051: $maxnum ++;
4052: }
4053: my $lastidx;
4054: for (my $i=0; $i<$numtop; $i++) {
4055: my $parent = $cats[0][$i];
4056: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4057: my $item = &escape($parent).'::0';
4058: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4059: $lastidx = $idx{$item};
4060: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4061: .'<select name="'.$item.'"'.$chgstr.'>';
4062: for (my $k=0; $k<=$maxnum; $k++) {
4063: my $vpos = $k+1;
4064: my $selstr;
4065: if ($k == $i) {
4066: $selstr = ' selected="selected" ';
4067: }
4068: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4069: }
4070: $datatable .= '</select></td><td>';
1.120 raeburn 4071: if ($parent eq 'instcode' || $parent eq 'communities') {
4072: $datatable .= '<span class="LC_nobreak">'
4073: .$default_names{$parent}.'</span>';
4074: if ($parent eq 'instcode') {
4075: $datatable .= '<br /><span class="LC_nobreak">('
4076: .&mt('with institutional codes')
4077: .')</span></td><td'.$colattrib.'>';
4078: } else {
4079: $datatable .= '<table><tr><td>';
4080: }
4081: $datatable .= '<span class="LC_nobreak">'
4082: .'<label><input type="radio" name="'
4083: .$parent.'" value="1" checked="checked" />'
4084: .&mt('Display').'</label>';
4085: if ($parent eq 'instcode') {
4086: $datatable .= ' ';
4087: } else {
4088: $datatable .= '</span></td></tr><tr><td>'
4089: .'<span class="LC_nobreak">';
4090: }
4091: $datatable .= '<label><input type="radio" name="'
4092: .$parent.'" value="0" />'
4093: .&mt('Do not display').'</label></span>';
4094: if ($parent eq 'communities') {
4095: $datatable .= '</td></tr></table>';
4096: }
4097: $datatable .= '</td>';
1.57 raeburn 4098: } else {
4099: $datatable .= $parent
4100: .' <label><input type="checkbox" name="deletecategory" '
4101: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4102: }
4103: my $depth = 1;
4104: push(@path,$parent);
4105: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4106: pop(@path);
4107: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4108: $itemcount ++;
4109: }
1.48 raeburn 4110: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4111: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4112: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4113: for (my $k=0; $k<=$maxnum; $k++) {
4114: my $vpos = $k+1;
4115: my $selstr;
1.57 raeburn 4116: if ($k == $numtop) {
1.48 raeburn 4117: $selstr = ' selected="selected" ';
4118: }
4119: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4120: }
1.59 bisitz 4121: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4122: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4123: .'</tr>'."\n";
1.48 raeburn 4124: $itemcount ++;
1.120 raeburn 4125: foreach my $default ('instcode','communities') {
4126: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4127: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4128: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4129: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4130: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4131: for (my $k=0; $k<=$maxnum; $k++) {
4132: my $vpos = $k+1;
4133: my $selstr;
4134: if ($k == $maxnum) {
4135: $selstr = ' selected="selected" ';
4136: }
4137: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4138: }
1.120 raeburn 4139: $datatable .= '</select></span></td>'.
4140: '<td><span class="LC_nobreak">'.
4141: $default_names{$default}.'</span>';
4142: if ($default eq 'instcode') {
4143: $datatable .= '<br /><span class="LC_nobreak">('
4144: .&mt('with institutional codes').')</span>';
4145: }
4146: $datatable .= '</td>'
4147: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4148: .&mt('Display').'</label> '
4149: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4150: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4151: }
4152: }
4153: }
1.57 raeburn 4154: } else {
4155: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4156: }
4157: } else {
1.57 raeburn 4158: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4159: .&initialize_categories($itemcount);
1.48 raeburn 4160: }
1.57 raeburn 4161: $$rowtotal += $itemcount;
1.48 raeburn 4162: }
4163: return $datatable;
4164: }
4165:
1.69 raeburn 4166: sub print_serverstatuses {
4167: my ($dom,$settings,$rowtotal) = @_;
4168: my $datatable;
4169: my @pages = &serverstatus_pages();
4170: my (%namedaccess,%machineaccess);
4171: foreach my $type (@pages) {
4172: $namedaccess{$type} = '';
4173: $machineaccess{$type}= '';
4174: }
4175: if (ref($settings) eq 'HASH') {
4176: foreach my $type (@pages) {
4177: if (exists($settings->{$type})) {
4178: if (ref($settings->{$type}) eq 'HASH') {
4179: foreach my $key (keys(%{$settings->{$type}})) {
4180: if ($key eq 'namedusers') {
4181: $namedaccess{$type} = $settings->{$type}->{$key};
4182: } elsif ($key eq 'machines') {
4183: $machineaccess{$type} = $settings->{$type}->{$key};
4184: }
4185: }
4186: }
4187: }
4188: }
4189: }
1.81 raeburn 4190: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4191: my $rownum = 0;
4192: my $css_class;
4193: foreach my $type (@pages) {
4194: $rownum ++;
4195: $css_class = $rownum%2?' class="LC_odd_row"':'';
4196: $datatable .= '<tr'.$css_class.'>'.
4197: '<td><span class="LC_nobreak">'.
4198: $titles->{$type}.'</span></td>'.
4199: '<td class="LC_left_item">'.
4200: '<input type="text" name="'.$type.'_namedusers" '.
4201: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4202: '<td class="LC_right_item">'.
4203: '<span class="LC_nobreak">'.
4204: '<input type="text" name="'.$type.'_machines" '.
4205: 'value="'.$machineaccess{$type}.'" size="10" />'.
4206: '</td></tr>'."\n";
4207: }
4208: $$rowtotal += $rownum;
4209: return $datatable;
4210: }
4211:
4212: sub serverstatus_pages {
4213: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4214: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4215: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4216: }
4217:
1.49 raeburn 4218: sub coursecategories_javascript {
4219: my ($settings) = @_;
1.57 raeburn 4220: my ($output,$jstext,$cathash);
1.49 raeburn 4221: if (ref($settings) eq 'HASH') {
1.57 raeburn 4222: $cathash = $settings->{'cats'};
4223: }
4224: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4225: my (@cats,@jsarray,%idx);
1.57 raeburn 4226: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4227: if (@jsarray > 0) {
4228: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4229: for (my $i=0; $i<@jsarray; $i++) {
4230: if (ref($jsarray[$i]) eq 'ARRAY') {
4231: my $catstr = join('","',@{$jsarray[$i]});
4232: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4233: }
4234: }
4235: }
4236: } else {
4237: $jstext = ' var categories = Array(1);'."\n".
4238: ' categories[0] = Array("instcode_pos");'."\n";
4239: }
1.120 raeburn 4240: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4241: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4242: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4243: $output = <<"ENDSCRIPT";
4244: <script type="text/javascript">
1.109 raeburn 4245: // <![CDATA[
1.49 raeburn 4246: function reorderCats(form,parent,item,idx) {
4247: var changedVal;
4248: $jstext
4249: var newpos = 'addcategory_pos';
4250: var current = new Array;
4251: if (parent == '') {
4252: var has_instcode = 0;
4253: var maxtop = categories[idx].length;
4254: for (var j=0; j<maxtop; j++) {
4255: if (categories[idx][j] == 'instcode::0') {
4256: has_instcode == 1;
4257: }
4258: }
4259: if (has_instcode == 0) {
4260: categories[idx][maxtop] = 'instcode_pos';
4261: }
4262: } else {
4263: newpos += '_'+parent;
4264: }
4265: var maxh = 1 + categories[idx].length;
4266: var current = new Array;
4267: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4268: if (item == newpos) {
4269: changedVal = newitemVal;
4270: } else {
4271: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4272: current[newitemVal] = newpos;
4273: }
4274: for (var i=0; i<categories[idx].length; i++) {
4275: var elementName = categories[idx][i];
4276: if (elementName != item) {
4277: if (form.elements[elementName]) {
4278: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4279: current[currVal] = elementName;
4280: }
4281: }
4282: }
4283: var oldVal;
4284: for (var j=0; j<maxh; j++) {
4285: if (current[j] == undefined) {
4286: oldVal = j;
4287: }
4288: }
4289: if (oldVal < changedVal) {
4290: for (var k=oldVal+1; k<=changedVal ; k++) {
4291: var elementName = current[k];
4292: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4293: }
4294: } else {
4295: for (var k=changedVal; k<oldVal; k++) {
4296: var elementName = current[k];
4297: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4298: }
4299: }
4300: return;
4301: }
1.120 raeburn 4302:
4303: function categoryCheck(form) {
4304: if (form.elements['addcategory_name'].value == 'instcode') {
4305: alert('$instcode_reserved\\n$choose_again');
4306: return false;
4307: }
4308: if (form.elements['addcategory_name'].value == 'communities') {
4309: alert('$communities_reserved\\n$choose_again');
4310: return false;
4311: }
4312: return true;
4313: }
4314:
1.109 raeburn 4315: // ]]>
1.49 raeburn 4316: </script>
4317:
4318: ENDSCRIPT
4319: return $output;
4320: }
4321:
1.48 raeburn 4322: sub initialize_categories {
4323: my ($itemcount) = @_;
1.120 raeburn 4324: my ($datatable,$css_class,$chgstr);
4325: my %default_names = (
4326: instcode => 'Official courses (with institutional codes)',
4327: communities => 'Communities',
4328: );
4329: my $select0 = ' selected="selected"';
4330: my $select1 = '';
4331: foreach my $default ('instcode','communities') {
4332: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4333: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4334: if ($default eq 'communities') {
4335: $select1 = $select0;
4336: $select0 = '';
4337: }
4338: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4339: .'<select name="'.$default.'_pos">'
4340: .'<option value="0"'.$select0.'>1</option>'
4341: .'<option value="1"'.$select1.'>2</option>'
4342: .'<option value="2">3</option></select> '
4343: .$default_names{$default}
4344: .'</span></td><td><span class="LC_nobreak">'
4345: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4346: .&mt('Display').'</label> <label>'
4347: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4348: .'</label></span></td></tr>';
1.120 raeburn 4349: $itemcount ++;
4350: }
1.48 raeburn 4351: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4352: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4353: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4354: .'<select name="addcategory_pos"'.$chgstr.'>'
4355: .'<option value="0">1</option>'
4356: .'<option value="1">2</option>'
4357: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4358: .&mt('Add category').'</td><td>'.&mt('Name:')
4359: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4360: return $datatable;
4361: }
4362:
4363: sub build_category_rows {
1.49 raeburn 4364: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4365: my ($text,$name,$item,$chgstr);
1.48 raeburn 4366: if (ref($cats) eq 'ARRAY') {
4367: my $maxdepth = scalar(@{$cats});
4368: if (ref($cats->[$depth]) eq 'HASH') {
4369: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4370: my $numchildren = @{$cats->[$depth]{$parent}};
4371: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4372: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4373: my ($idxnum,$parent_name,$parent_item);
4374: my $higher = $depth - 1;
4375: if ($higher == 0) {
4376: $parent_name = &escape($parent).'::'.$higher;
4377: } else {
4378: if (ref($path) eq 'ARRAY') {
4379: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4380: }
4381: }
4382: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4383: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4384: if ($j < $numchildren) {
1.48 raeburn 4385: $name = $cats->[$depth]{$parent}[$j];
4386: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4387: $idxnum = $idx->{$item};
4388: } else {
4389: $name = $parent_name;
4390: $item = $parent_item;
1.48 raeburn 4391: }
1.49 raeburn 4392: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4393: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4394: for (my $i=0; $i<=$numchildren; $i++) {
4395: my $vpos = $i+1;
4396: my $selstr;
4397: if ($j == $i) {
4398: $selstr = ' selected="selected" ';
4399: }
4400: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4401: }
4402: $text .= '</select> ';
4403: if ($j < $numchildren) {
4404: my $deeper = $depth+1;
4405: $text .= $name.' '
4406: .'<label><input type="checkbox" name="deletecategory" value="'
4407: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4408: if(ref($path) eq 'ARRAY') {
4409: push(@{$path},$name);
1.49 raeburn 4410: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4411: pop(@{$path});
4412: }
4413: } else {
1.59 bisitz 4414: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4415: if ($j == $numchildren) {
4416: $text .= $name;
4417: } else {
4418: $text .= $item;
4419: }
4420: $text .= '" value="" />';
4421: }
4422: $text .= '</td></tr>';
4423: }
4424: $text .= '</table></td>';
4425: } else {
4426: my $higher = $depth-1;
4427: if ($higher == 0) {
4428: $name = &escape($parent).'::'.$higher;
4429: } else {
4430: if (ref($path) eq 'ARRAY') {
4431: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4432: }
4433: }
4434: my $colspan;
4435: if ($parent ne 'instcode') {
4436: $colspan = $maxdepth - $depth - 1;
4437: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4438: }
4439: }
4440: }
4441: }
4442: return $text;
4443: }
4444:
1.33 raeburn 4445: sub modifiable_userdata_row {
1.63 raeburn 4446: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4447: my $rolename;
1.63 raeburn 4448: if ($context eq 'selfcreate') {
4449: if (ref($usertypes) eq 'HASH') {
4450: $rolename = $usertypes->{$role};
4451: } else {
4452: $rolename = $role;
4453: }
1.33 raeburn 4454: } else {
1.63 raeburn 4455: if ($role eq 'cr') {
4456: $rolename = &mt('Custom role');
4457: } else {
4458: $rolename = &Apache::lonnet::plaintext($role);
4459: }
1.33 raeburn 4460: }
4461: my @fields = ('lastname','firstname','middlename','generation',
4462: 'permanentemail','id');
4463: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4464: my $output;
4465: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4466: $output = '<tr '.$css_class.'>'.
4467: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4468: '<td class="LC_left_item" colspan="2"><table>';
4469: my $rem;
4470: my %checks;
4471: if (ref($settings) eq 'HASH') {
4472: if (ref($settings->{$context}) eq 'HASH') {
4473: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4474: foreach my $field (@fields) {
4475: if ($settings->{$context}->{$role}->{$field}) {
4476: $checks{$field} = ' checked="checked" ';
4477: }
4478: }
4479: }
4480: }
4481: }
4482: for (my $i=0; $i<@fields; $i++) {
4483: my $rem = $i%($numinrow);
4484: if ($rem == 0) {
4485: if ($i > 0) {
4486: $output .= '</tr>';
4487: }
4488: $output .= '<tr>';
4489: }
4490: my $check = ' ';
4491: if (exists($checks{$fields[$i]})) {
4492: $check = $checks{$fields[$i]}
4493: } else {
4494: if ($role eq 'st') {
4495: if (ref($settings) ne 'HASH') {
4496: $check = ' checked="checked" ';
4497: }
4498: }
4499: }
4500: $output .= '<td class="LC_left_item">'.
4501: '<span class="LC_nobreak"><label>'.
4502: '<input type="checkbox" name="canmodify_'.$role.'" '.
4503: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4504: '</label></span></td>';
4505: $rem = @fields%($numinrow);
4506: }
4507: my $colsleft = $numinrow - $rem;
4508: if ($colsleft > 1 ) {
4509: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4510: ' </td>';
4511: } elsif ($colsleft == 1) {
4512: $output .= '<td class="LC_left_item"> </td>';
4513: }
4514: $output .= '</tr></table></td></tr>';
4515: return $output;
4516: }
1.28 raeburn 4517:
1.93 raeburn 4518: sub insttypes_row {
4519: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4520: my %lt = &Apache::lonlocal::texthash (
4521: cansearch => 'Users allowed to search',
4522: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4523: lockablenames => 'User preference to lock name',
1.93 raeburn 4524: );
4525: my $showdom;
4526: if ($context eq 'cansearch') {
4527: $showdom = ' ('.$dom.')';
4528: }
1.165 raeburn 4529: my $class = 'LC_left_item';
4530: if ($context eq 'statustocreate') {
4531: $class = 'LC_right_item';
4532: }
1.25 raeburn 4533: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4534: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4535: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4536: my $rem;
4537: if (ref($types) eq 'ARRAY') {
4538: for (my $i=0; $i<@{$types}; $i++) {
4539: if (defined($usertypes->{$types->[$i]})) {
4540: my $rem = $i%($numinrow);
4541: if ($rem == 0) {
4542: if ($i > 0) {
4543: $output .= '</tr>';
4544: }
4545: $output .= '<tr>';
1.23 raeburn 4546: }
1.26 raeburn 4547: my $check = ' ';
1.99 raeburn 4548: if (ref($settings) eq 'HASH') {
4549: if (ref($settings->{$context}) eq 'ARRAY') {
4550: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4551: $check = ' checked="checked" ';
4552: }
4553: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4554: $check = ' checked="checked" ';
4555: }
1.23 raeburn 4556: }
1.26 raeburn 4557: $output .= '<td class="LC_left_item">'.
4558: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4559: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4560: 'value="'.$types->[$i].'"'.$check.'/>'.
4561: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4562: }
4563: }
1.26 raeburn 4564: $rem = @{$types}%($numinrow);
1.23 raeburn 4565: }
4566: my $colsleft = $numinrow - $rem;
1.131 raeburn 4567: if (($rem == 0) && (@{$types} > 0)) {
4568: $output .= '<tr>';
4569: }
1.23 raeburn 4570: if ($colsleft > 1) {
1.25 raeburn 4571: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4572: } else {
1.25 raeburn 4573: $output .= '<td class="LC_left_item">';
1.23 raeburn 4574: }
4575: my $defcheck = ' ';
1.99 raeburn 4576: if (ref($settings) eq 'HASH') {
4577: if (ref($settings->{$context}) eq 'ARRAY') {
4578: if (grep(/^default$/,@{$settings->{$context}})) {
4579: $defcheck = ' checked="checked" ';
4580: }
4581: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4582: $defcheck = ' checked="checked" ';
4583: }
1.23 raeburn 4584: }
1.25 raeburn 4585: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4586: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4587: 'value="default"'.$defcheck.'/>'.
4588: $othertitle.'</label></span></td>'.
4589: '</tr></table></td></tr>';
4590: return $output;
1.23 raeburn 4591: }
4592:
4593: sub sorted_searchtitles {
4594: my %searchtitles = &Apache::lonlocal::texthash(
4595: 'uname' => 'username',
4596: 'lastname' => 'last name',
4597: 'lastfirst' => 'last name, first name',
4598: );
4599: my @titleorder = ('uname','lastname','lastfirst');
4600: return (\%searchtitles,\@titleorder);
4601: }
4602:
1.25 raeburn 4603: sub sorted_searchtypes {
4604: my %srchtypes_desc = (
4605: exact => 'is exact match',
4606: contains => 'contains ..',
4607: begins => 'begins with ..',
4608: );
4609: my @srchtypeorder = ('exact','begins','contains');
4610: return (\%srchtypes_desc,\@srchtypeorder);
4611: }
4612:
1.3 raeburn 4613: sub usertype_update_row {
4614: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4615: my $datatable;
4616: my $numinrow = 4;
4617: foreach my $type (@{$types}) {
4618: if (defined($usertypes->{$type})) {
4619: $$rownums ++;
4620: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4621: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4622: '</td><td class="LC_left_item"><table>';
4623: for (my $i=0; $i<@{$fields}; $i++) {
4624: my $rem = $i%($numinrow);
4625: if ($rem == 0) {
4626: if ($i > 0) {
4627: $datatable .= '</tr>';
4628: }
4629: $datatable .= '<tr>';
4630: }
4631: my $check = ' ';
1.39 raeburn 4632: if (ref($settings) eq 'HASH') {
4633: if (ref($settings->{'fields'}) eq 'HASH') {
4634: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4635: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4636: $check = ' checked="checked" ';
4637: }
1.3 raeburn 4638: }
4639: }
4640: }
4641:
4642: if ($i == @{$fields}-1) {
4643: my $colsleft = $numinrow - $rem;
4644: if ($colsleft > 1) {
4645: $datatable .= '<td colspan="'.$colsleft.'">';
4646: } else {
4647: $datatable .= '<td>';
4648: }
4649: } else {
4650: $datatable .= '<td>';
4651: }
1.8 raeburn 4652: $datatable .= '<span class="LC_nobreak"><label>'.
4653: '<input type="checkbox" name="updateable_'.$type.
4654: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4655: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4656: }
4657: $datatable .= '</tr></table></td></tr>';
4658: }
4659: }
4660: return $datatable;
1.1 raeburn 4661: }
4662:
4663: sub modify_login {
1.9 raeburn 4664: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4665: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4666: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4667: %title = ( coursecatalog => 'Display course catalog',
4668: adminmail => 'Display administrator E-mail address',
4669: newuser => 'Link for visitors to create a user account',
4670: loginheader => 'Log-in box header');
4671: @offon = ('off','on');
1.112 raeburn 4672: if (ref($domconfig{login}) eq 'HASH') {
4673: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4674: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4675: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4676: }
4677: }
4678: }
1.9 raeburn 4679: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4680: \%domconfig,\%loginhash);
1.118 jms 4681: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4682: foreach my $item (@toggles) {
4683: $loginhash{login}{$item} = $env{'form.'.$item};
4684: }
1.41 raeburn 4685: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4686: if (ref($colchanges{'login'}) eq 'HASH') {
4687: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4688: \%loginhash);
4689: }
1.110 raeburn 4690:
1.149 raeburn 4691: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4692: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4693: if (keys(%servers) > 1) {
4694: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4695: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4696: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4697: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4698: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4699: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4700: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4701: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4702: $changes{'loginvia'}{$lonhost} = 1;
4703: } else {
4704: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4705: $changes{'loginvia'}{$lonhost} = 1;
4706: }
4707: } else {
4708: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4709: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4710: $changes{'loginvia'}{$lonhost} = 1;
4711: }
4712: }
4713: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4714: foreach my $item (@loginvia_attribs) {
4715: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4716: }
4717: } else {
4718: foreach my $item (@loginvia_attribs) {
4719: my $new = $env{'form.'.$lonhost.'_'.$item};
4720: if (($item eq 'serverpath') && ($new eq 'custom')) {
4721: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4722: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4723: $new = '/';
4724: }
4725: }
4726: if (($item eq 'custompath') &&
4727: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4728: $new = '';
4729: }
4730: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4731: $changes{'loginvia'}{$lonhost} = 1;
4732: }
4733: if ($item eq 'exempt') {
4734: $new =~ s/^\s+//;
4735: $new =~ s/\s+$//;
4736: my @poss_ips = split(/\s*[,:]\s*/,$new);
4737: my @okips;
4738: foreach my $ip (@poss_ips) {
4739: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4740: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4741: push(@okips,$ip);
4742: }
4743: }
4744: }
4745: if (@okips > 0) {
4746: $new = join(',',@okips);
4747: } else {
4748: $new = '';
4749: }
4750: }
4751: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4752: }
4753: }
1.112 raeburn 4754: } else {
1.128 raeburn 4755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4757: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4758: foreach my $item (@loginvia_attribs) {
4759: my $new = $env{'form.'.$lonhost.'_'.$item};
4760: if (($item eq 'serverpath') && ($new eq 'custom')) {
4761: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4762: $new = '/';
4763: }
4764: }
4765: if (($item eq 'custompath') &&
4766: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4767: $new = '';
4768: }
4769: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4770: }
1.110 raeburn 4771: }
4772: }
4773: }
4774: }
1.119 raeburn 4775:
1.168 raeburn 4776: my $servadm = $r->dir_config('lonAdmEMail');
4777: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4778: if (ref($domconfig{'login'}) eq 'HASH') {
4779: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4780: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4781: if ($lang eq 'nolang') {
4782: push(@currlangs,$lang);
4783: } elsif (defined($langchoices{$lang})) {
4784: push(@currlangs,$lang);
4785: } else {
4786: next;
4787: }
4788: }
4789: }
4790: }
4791: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4792: if (@currlangs > 0) {
4793: foreach my $lang (@currlangs) {
4794: if (grep(/^\Q$lang\E$/,@delurls)) {
4795: $changes{'helpurl'}{$lang} = 1;
4796: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4797: $changes{'helpurl'}{$lang} = 1;
4798: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4799: push(@newlangs,$lang);
4800: } else {
4801: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4802: }
4803: }
4804: }
4805: unless (grep(/^nolang$/,@currlangs)) {
4806: if ($env{'form.loginhelpurl_nolang.filename'}) {
4807: $changes{'helpurl'}{'nolang'} = 1;
4808: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4809: push(@newlangs,'nolang');
4810: }
4811: }
4812: if ($env{'form.loginhelpurl_add_lang'}) {
4813: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4814: ($env{'form.loginhelpurl_add_file.filename'})) {
4815: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4816: $addedfile = $env{'form.loginhelpurl_add_lang'};
4817: }
4818: }
4819: if ((@newlangs > 0) || ($addedfile)) {
4820: my $error;
4821: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4822: if ($configuserok eq 'ok') {
4823: if ($switchserver) {
4824: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4825: } elsif ($author_ok eq 'ok') {
4826: my @allnew = @newlangs;
4827: if ($addedfile ne '') {
4828: push(@allnew,$addedfile);
4829: }
4830: foreach my $lang (@allnew) {
4831: my $formelem = 'loginhelpurl_'.$lang;
4832: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4833: $formelem = 'loginhelpurl_add_file';
4834: }
4835: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4836: "help/$lang",'','',$newfile{$lang});
4837: if ($result eq 'ok') {
4838: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4839: $changes{'helpurl'}{$lang} = 1;
4840: } else {
4841: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4842: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4843: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4844: (!grep(/^\Q$lang\E$/,@delurls))) {
4845:
4846: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4847: }
4848: }
4849: }
4850: } else {
4851: $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);
4852: }
4853: } else {
4854: $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);
4855: }
4856: if ($error) {
4857: &Apache::lonnet::logthis($error);
4858: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4859: }
4860: }
1.169 raeburn 4861: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4862:
4863: my $defaulthelpfile = '/adm/loginproblems.html';
4864: my $defaulttext = &mt('Default in use');
4865:
1.1 raeburn 4866: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4867: $dom);
4868: if ($putresult eq 'ok') {
1.118 jms 4869: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4870: my %defaultchecked = (
4871: 'coursecatalog' => 'on',
4872: 'adminmail' => 'off',
1.43 raeburn 4873: 'newuser' => 'off',
1.42 raeburn 4874: );
1.55 raeburn 4875: if (ref($domconfig{'login'}) eq 'HASH') {
4876: foreach my $item (@toggles) {
4877: if ($defaultchecked{$item} eq 'on') {
4878: if (($domconfig{'login'}{$item} eq '0') &&
4879: ($env{'form.'.$item} eq '1')) {
4880: $changes{$item} = 1;
4881: } elsif (($domconfig{'login'}{$item} eq '' ||
4882: $domconfig{'login'}{$item} eq '1') &&
4883: ($env{'form.'.$item} eq '0')) {
4884: $changes{$item} = 1;
4885: }
4886: } elsif ($defaultchecked{$item} eq 'off') {
4887: if (($domconfig{'login'}{$item} eq '1') &&
4888: ($env{'form.'.$item} eq '0')) {
4889: $changes{$item} = 1;
4890: } elsif (($domconfig{'login'}{$item} eq '' ||
4891: $domconfig{'login'}{$item} eq '0') &&
4892: ($env{'form.'.$item} eq '1')) {
4893: $changes{$item} = 1;
4894: }
1.42 raeburn 4895: }
4896: }
1.41 raeburn 4897: }
1.6 raeburn 4898: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4899: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4900: $resulttext = &mt('Changes made:').'<ul>';
4901: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4902: if ($item eq 'loginvia') {
1.112 raeburn 4903: if (ref($changes{$item}) eq 'HASH') {
4904: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4905: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4906: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4907: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4908: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4909: $protocol = 'http' if ($protocol ne 'https');
4910: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4911:
4912: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4913: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4914: } else {
4915: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4916: }
4917: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4918: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4919: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4920: }
4921: $resulttext .= '</li>';
4922: } else {
4923: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4924: }
1.112 raeburn 4925: } else {
1.128 raeburn 4926: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4927: }
4928: }
1.128 raeburn 4929: $resulttext .= '</ul></li>';
1.112 raeburn 4930: }
1.168 raeburn 4931: } elsif ($item eq 'helpurl') {
4932: if (ref($changes{$item}) eq 'HASH') {
4933: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4934: if (grep(/^\Q$lang\E$/,@delurls)) {
4935: my ($chg,$link);
4936: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4937: if ($lang eq 'nolang') {
4938: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4939: } else {
4940: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4941: }
4942: $resulttext .= '<li>'.$chg.'</li>';
4943: } else {
4944: my $chg;
4945: if ($lang eq 'nolang') {
4946: $chg = &mt('custom log-in help file for no preferred language');
4947: } else {
4948: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4949: }
4950: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4951: $loginhash{'login'}{'helpurl'}{$lang}.
4952: '?inhibitmenu=yes',$chg,600,500).
4953: '</li>';
4954: }
4955: }
4956: }
1.169 raeburn 4957: } elsif ($item eq 'captcha') {
4958: if (ref($loginhash{'login'}) eq 'HASH') {
4959: my $chgtxt;
4960: if ($loginhash{'login'}{$item} eq 'notused') {
4961: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4962: } else {
4963: my %captchas = &captcha_phrases();
4964: if ($captchas{$loginhash{'login'}{$item}}) {
4965: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4966: } else {
4967: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4968: }
4969: }
4970: $resulttext .= '<li>'.$chgtxt.'</li>';
4971: }
4972: } elsif ($item eq 'recaptchakeys') {
4973: if (ref($loginhash{'login'}) eq 'HASH') {
4974: my ($privkey,$pubkey);
4975: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4976: $pubkey = $loginhash{'login'}{$item}{'public'};
4977: $privkey = $loginhash{'login'}{$item}{'private'};
4978: }
4979: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4980: if (!$pubkey) {
4981: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4982: } else {
4983: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4984: }
4985: if (!$privkey) {
4986: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4987: } else {
4988: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4989: }
4990: $chgtxt .= '</ul>';
4991: $resulttext .= '<li>'.$chgtxt.'</li>';
4992: }
1.41 raeburn 4993: } else {
4994: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4995: }
1.1 raeburn 4996: }
1.6 raeburn 4997: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4998: } else {
4999: $resulttext = &mt('No changes made to log-in page settings');
5000: }
5001: } else {
1.11 albertel 5002: $resulttext = '<span class="LC_error">'.
5003: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5004: }
1.6 raeburn 5005: if ($errors) {
1.9 raeburn 5006: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5007: $errors.'</ul>';
5008: }
5009: return $resulttext;
5010: }
5011:
5012: sub color_font_choices {
5013: my %choices =
5014: &Apache::lonlocal::texthash (
5015: img => "Header",
5016: bgs => "Background colors",
5017: links => "Link colors",
1.55 raeburn 5018: images => "Images",
1.6 raeburn 5019: font => "Font color",
1.97 tempelho 5020: fontmenu => "Font Menu",
1.76 raeburn 5021: pgbg => "Page",
1.6 raeburn 5022: tabbg => "Header",
5023: sidebg => "Border",
5024: link => "Link",
5025: alink => "Active link",
5026: vlink => "Visited link",
5027: );
5028: return %choices;
5029: }
5030:
5031: sub modify_rolecolors {
1.9 raeburn 5032: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5033: my ($resulttext,%rolehash);
5034: $rolehash{'rolecolors'} = {};
1.55 raeburn 5035: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5036: if ($domconfig{'rolecolors'} eq '') {
5037: $domconfig{'rolecolors'} = {};
5038: }
5039: }
1.9 raeburn 5040: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5041: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5042: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5043: $dom);
5044: if ($putresult eq 'ok') {
5045: if (keys(%changes) > 0) {
1.41 raeburn 5046: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5047: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5048: $rolehash{'rolecolors'});
5049: } else {
5050: $resulttext = &mt('No changes made to default color schemes');
5051: }
5052: } else {
1.11 albertel 5053: $resulttext = '<span class="LC_error">'.
5054: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5055: }
5056: if ($errors) {
5057: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5058: $errors.'</ul>';
5059: }
5060: return $resulttext;
5061: }
5062:
5063: sub modify_colors {
1.9 raeburn 5064: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5065: my (%changes,%choices);
1.51 raeburn 5066: my @bgs;
1.6 raeburn 5067: my @links = ('link','alink','vlink');
1.41 raeburn 5068: my @logintext;
1.6 raeburn 5069: my @images;
5070: my $servadm = $r->dir_config('lonAdmEMail');
5071: my $errors;
5072: foreach my $role (@{$roles}) {
5073: if ($role eq 'login') {
1.12 raeburn 5074: %choices = &login_choices();
1.41 raeburn 5075: @logintext = ('textcol','bgcol');
1.12 raeburn 5076: } else {
5077: %choices = &color_font_choices();
1.107 raeburn 5078: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5079: }
5080: if ($role eq 'login') {
1.41 raeburn 5081: @images = ('img','logo','domlogo','login');
1.51 raeburn 5082: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5083: } else {
5084: @images = ('img');
1.51 raeburn 5085: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5086: }
5087: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5088: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5089: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5090: }
1.46 raeburn 5091: my ($configuserok,$author_ok,$switchserver) =
5092: &config_check($dom,$confname,$servadm);
1.9 raeburn 5093: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5094: if (ref($domconfig->{$role}) ne 'HASH') {
5095: $domconfig->{$role} = {};
5096: }
1.8 raeburn 5097: foreach my $img (@images) {
1.70 raeburn 5098: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5099: if (defined($env{'form.login_showlogo_'.$img})) {
5100: $confhash->{$role}{'showlogo'}{$img} = 1;
5101: } else {
5102: $confhash->{$role}{'showlogo'}{$img} = 0;
5103: }
5104: }
1.18 albertel 5105: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5106: && !defined($domconfig->{$role}{$img})
5107: && !$env{'form.'.$role.'_del_'.$img}
5108: && $env{'form.'.$role.'_import_'.$img}) {
5109: # import the old configured image from the .tab setting
5110: # if they haven't provided a new one
5111: $domconfig->{$role}{$img} =
5112: $env{'form.'.$role.'_import_'.$img};
5113: }
1.6 raeburn 5114: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5115: my $error;
1.6 raeburn 5116: if ($configuserok eq 'ok') {
1.9 raeburn 5117: if ($switchserver) {
1.12 raeburn 5118: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5119: } else {
5120: if ($author_ok eq 'ok') {
5121: my ($result,$logourl) =
5122: &publishlogo($r,'upload',$role.'_'.$img,
5123: $dom,$confname,$img,$width,$height);
5124: if ($result eq 'ok') {
5125: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5126: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5127: } else {
1.12 raeburn 5128: $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 5129: }
5130: } else {
1.46 raeburn 5131: $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 5132: }
5133: }
5134: } else {
1.46 raeburn 5135: $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 5136: }
5137: if ($error) {
1.8 raeburn 5138: &Apache::lonnet::logthis($error);
1.11 albertel 5139: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5140: }
5141: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5142: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5143: my $error;
5144: if ($configuserok eq 'ok') {
5145: # is confname an author?
5146: if ($switchserver eq '') {
5147: if ($author_ok eq 'ok') {
5148: my ($result,$logourl) =
5149: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5150: $dom,$confname,$img,$width,$height);
5151: if ($result eq 'ok') {
5152: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5153: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5154: }
5155: }
5156: }
5157: }
1.6 raeburn 5158: }
5159: }
5160: }
5161: if (ref($domconfig) eq 'HASH') {
5162: if (ref($domconfig->{$role}) eq 'HASH') {
5163: foreach my $img (@images) {
5164: if ($domconfig->{$role}{$img} ne '') {
5165: if ($env{'form.'.$role.'_del_'.$img}) {
5166: $confhash->{$role}{$img} = '';
1.12 raeburn 5167: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5168: } else {
1.9 raeburn 5169: if ($confhash->{$role}{$img} eq '') {
5170: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5171: }
1.6 raeburn 5172: }
5173: } else {
5174: if ($env{'form.'.$role.'_del_'.$img}) {
5175: $confhash->{$role}{$img} = '';
1.12 raeburn 5176: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5177: }
5178: }
1.70 raeburn 5179: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5180: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5181: if ($confhash->{$role}{'showlogo'}{$img} ne
5182: $domconfig->{$role}{'showlogo'}{$img}) {
5183: $changes{$role}{'showlogo'}{$img} = 1;
5184: }
5185: } else {
5186: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5187: $changes{$role}{'showlogo'}{$img} = 1;
5188: }
5189: }
5190: }
5191: }
1.6 raeburn 5192: if ($domconfig->{$role}{'font'} ne '') {
5193: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5194: $changes{$role}{'font'} = 1;
5195: }
5196: } else {
5197: if ($confhash->{$role}{'font'}) {
5198: $changes{$role}{'font'} = 1;
5199: }
5200: }
1.107 raeburn 5201: if ($role ne 'login') {
5202: if ($domconfig->{$role}{'fontmenu'} ne '') {
5203: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5204: $changes{$role}{'fontmenu'} = 1;
5205: }
5206: } else {
5207: if ($confhash->{$role}{'fontmenu'}) {
5208: $changes{$role}{'fontmenu'} = 1;
5209: }
1.97 tempelho 5210: }
5211: }
1.6 raeburn 5212: foreach my $item (@bgs) {
5213: if ($domconfig->{$role}{$item} ne '') {
5214: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5215: $changes{$role}{'bgs'}{$item} = 1;
5216: }
5217: } else {
5218: if ($confhash->{$role}{$item}) {
5219: $changes{$role}{'bgs'}{$item} = 1;
5220: }
5221: }
5222: }
5223: foreach my $item (@links) {
5224: if ($domconfig->{$role}{$item} ne '') {
5225: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5226: $changes{$role}{'links'}{$item} = 1;
5227: }
5228: } else {
5229: if ($confhash->{$role}{$item}) {
5230: $changes{$role}{'links'}{$item} = 1;
5231: }
5232: }
5233: }
1.41 raeburn 5234: foreach my $item (@logintext) {
5235: if ($domconfig->{$role}{$item} ne '') {
5236: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5237: $changes{$role}{'logintext'}{$item} = 1;
5238: }
5239: } else {
5240: if ($confhash->{$role}{$item}) {
5241: $changes{$role}{'logintext'}{$item} = 1;
5242: }
5243: }
5244: }
1.6 raeburn 5245: } else {
5246: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5247: \@logintext,$confhash,\%changes);
1.6 raeburn 5248: }
5249: } else {
5250: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5251: \@logintext,$confhash,\%changes);
1.6 raeburn 5252: }
5253: }
5254: return ($errors,%changes);
5255: }
5256:
1.46 raeburn 5257: sub config_check {
5258: my ($dom,$confname,$servadm) = @_;
5259: my ($configuserok,$author_ok,$switchserver,%currroles);
5260: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5261: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5262: $confname,$servadm);
5263: if ($configuserok eq 'ok') {
5264: $switchserver = &check_switchserver($dom,$confname);
5265: if ($switchserver eq '') {
5266: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5267: }
5268: }
5269: return ($configuserok,$author_ok,$switchserver);
5270: }
5271:
1.6 raeburn 5272: sub default_change_checker {
1.41 raeburn 5273: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5274: foreach my $item (@{$links}) {
5275: if ($confhash->{$role}{$item}) {
5276: $changes->{$role}{'links'}{$item} = 1;
5277: }
5278: }
5279: foreach my $item (@{$bgs}) {
5280: if ($confhash->{$role}{$item}) {
5281: $changes->{$role}{'bgs'}{$item} = 1;
5282: }
5283: }
1.41 raeburn 5284: foreach my $item (@{$logintext}) {
5285: if ($confhash->{$role}{$item}) {
5286: $changes->{$role}{'logintext'}{$item} = 1;
5287: }
5288: }
1.6 raeburn 5289: foreach my $img (@{$images}) {
5290: if ($env{'form.'.$role.'_del_'.$img}) {
5291: $confhash->{$role}{$img} = '';
1.12 raeburn 5292: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5293: }
1.70 raeburn 5294: if ($role eq 'login') {
5295: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5296: $changes->{$role}{'showlogo'}{$img} = 1;
5297: }
5298: }
1.6 raeburn 5299: }
5300: if ($confhash->{$role}{'font'}) {
5301: $changes->{$role}{'font'} = 1;
5302: }
1.48 raeburn 5303: }
1.6 raeburn 5304:
5305: sub display_colorchgs {
5306: my ($dom,$changes,$roles,$confhash) = @_;
5307: my (%choices,$resulttext);
5308: if (!grep(/^login$/,@{$roles})) {
5309: $resulttext = &mt('Changes made:').'<br />';
5310: }
5311: foreach my $role (@{$roles}) {
5312: if ($role eq 'login') {
5313: %choices = &login_choices();
5314: } else {
5315: %choices = &color_font_choices();
5316: }
5317: if (ref($changes->{$role}) eq 'HASH') {
5318: if ($role ne 'login') {
5319: $resulttext .= '<h4>'.&mt($role).'</h4>';
5320: }
5321: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5322: if ($role ne 'login') {
5323: $resulttext .= '<ul>';
5324: }
5325: if (ref($changes->{$role}{$key}) eq 'HASH') {
5326: if ($role ne 'login') {
5327: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5328: }
5329: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5330: if (($role eq 'login') && ($key eq 'showlogo')) {
5331: if ($confhash->{$role}{$key}{$item}) {
5332: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5333: } else {
5334: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5335: }
5336: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5337: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5338: } else {
1.12 raeburn 5339: my $newitem = $confhash->{$role}{$item};
5340: if ($key eq 'images') {
5341: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5342: }
5343: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5344: }
5345: }
5346: if ($role ne 'login') {
5347: $resulttext .= '</ul></li>';
5348: }
5349: } else {
5350: if ($confhash->{$role}{$key} eq '') {
5351: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5352: } else {
5353: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5354: }
5355: }
5356: if ($role ne 'login') {
5357: $resulttext .= '</ul>';
5358: }
5359: }
5360: }
5361: }
1.3 raeburn 5362: return $resulttext;
1.1 raeburn 5363: }
5364:
1.9 raeburn 5365: sub thumb_dimensions {
5366: return ('200','50');
5367: }
5368:
1.16 raeburn 5369: sub check_dimensions {
5370: my ($inputfile) = @_;
5371: my ($fullwidth,$fullheight);
5372: if ($inputfile =~ m|^[/\w.\-]+$|) {
5373: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5374: my $imageinfo = <PIPE>;
5375: if (!close(PIPE)) {
5376: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5377: }
5378: chomp($imageinfo);
5379: my ($fullsize) =
1.21 raeburn 5380: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5381: if ($fullsize) {
5382: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5383: }
5384: }
5385: }
5386: return ($fullwidth,$fullheight);
5387: }
5388:
1.9 raeburn 5389: sub check_configuser {
5390: my ($uhome,$dom,$confname,$servadm) = @_;
5391: my ($configuserok,%currroles);
5392: if ($uhome eq 'no_host') {
5393: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5394: my $configpass = &LONCAPA::Enrollment::create_password();
5395: $configuserok =
5396: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5397: $configpass,'','','','','',undef,$servadm);
5398: } else {
5399: $configuserok = 'ok';
5400: %currroles =
5401: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5402: }
5403: return ($configuserok,%currroles);
5404: }
5405:
5406: sub check_authorstatus {
5407: my ($dom,$confname,%currroles) = @_;
5408: my $author_ok;
1.40 raeburn 5409: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5410: my $start = time;
5411: my $end = 0;
5412: $author_ok =
5413: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5414: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5415: } else {
5416: $author_ok = 'ok';
5417: }
5418: return $author_ok;
5419: }
5420:
5421: sub publishlogo {
1.46 raeburn 5422: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5423: my ($output,$fname,$logourl);
5424: if ($action eq 'upload') {
5425: $fname=$env{'form.'.$formname.'.filename'};
5426: chop($env{'form.'.$formname});
5427: } else {
5428: ($fname) = ($formname =~ /([^\/]+)$/);
5429: }
1.46 raeburn 5430: if ($savefileas ne '') {
5431: $fname = $savefileas;
5432: }
1.9 raeburn 5433: $fname=&Apache::lonnet::clean_filename($fname);
5434: # See if there is anything left
5435: unless ($fname) { return ('error: no uploaded file'); }
5436: $fname="$subdir/$fname";
1.164 raeburn 5437: my $docroot=$r->dir_config('lonDocRoot');
5438: my $filepath="$docroot/priv";
5439: my $relpath = "$dom/$confname";
1.9 raeburn 5440: my ($fnamepath,$file,$fetchthumb);
5441: $file=$fname;
5442: if ($fname=~m|/|) {
5443: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5444: }
1.164 raeburn 5445: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5446: my $count;
1.164 raeburn 5447: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5448: $filepath.="/$parts[$count]";
5449: if ((-e $filepath)!=1) {
5450: mkdir($filepath,02770);
5451: }
5452: }
5453: # Check for bad extension and disallow upload
5454: if ($file=~/\.(\w+)$/ &&
5455: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5456: $output =
5457: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5458: } elsif ($file=~/\.(\w+)$/ &&
5459: !defined(&Apache::loncommon::fileembstyle($1))) {
5460: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5461: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5462: $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 5463: } elsif (-d "$filepath/$file") {
5464: $output = &mt('File name is a directory name - rename the file and re-upload');
5465: } else {
5466: my $source = $filepath.'/'.$file;
5467: my $logfile;
5468: if (!open($logfile,">>$source".'.log')) {
5469: return (&mt('No write permission to Construction Space'));
5470: }
5471: print $logfile
5472: "\n================= Publish ".localtime()." ================\n".
5473: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5474: # Save the file
5475: if (!open(FH,'>'.$source)) {
5476: &Apache::lonnet::logthis('Failed to create '.$source);
5477: return (&mt('Failed to create file'));
5478: }
5479: if ($action eq 'upload') {
5480: if (!print FH ($env{'form.'.$formname})) {
5481: &Apache::lonnet::logthis('Failed to write to '.$source);
5482: return (&mt('Failed to write file'));
5483: }
5484: } else {
5485: my $original = &Apache::lonnet::filelocation('',$formname);
5486: if(!copy($original,$source)) {
5487: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5488: return (&mt('Failed to write file'));
5489: }
5490: }
5491: close(FH);
5492: chmod(0660, $source); # Permissions to rw-rw---.
5493:
5494: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5495: my $copyfile=$targetdir.'/'.$file;
5496:
5497: my @parts=split(/\//,$targetdir);
5498: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5499: for (my $count=5;$count<=$#parts;$count++) {
5500: $path.="/$parts[$count]";
5501: if (!-e $path) {
5502: print $logfile "\nCreating directory ".$path;
5503: mkdir($path,02770);
5504: }
5505: }
5506: my $versionresult;
5507: if (-e $copyfile) {
5508: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5509: } else {
5510: $versionresult = 'ok';
5511: }
5512: if ($versionresult eq 'ok') {
5513: if (copy($source,$copyfile)) {
5514: print $logfile "\nCopied original source to ".$copyfile."\n";
5515: $output = 'ok';
5516: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5517: push(@{$modified_urls},[$copyfile,$source]);
5518: my $metaoutput =
5519: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5520: unless ($registered_cleanup) {
5521: my $handlers = $r->get_handlers('PerlCleanupHandler');
5522: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5523: $registered_cleanup=1;
5524: }
1.9 raeburn 5525: } else {
5526: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5527: $output = &mt('Failed to copy file to RES space').", $!";
5528: }
5529: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5530: my $inputfile = $filepath.'/'.$file;
5531: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5532: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5533: if ($fullwidth ne '' && $fullheight ne '') {
5534: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5535: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5536: system("convert -sample $thumbsize $inputfile $outfile");
5537: chmod(0660, $filepath.'/tn-'.$file);
5538: if (-e $outfile) {
5539: my $copyfile=$targetdir.'/tn-'.$file;
5540: if (copy($outfile,$copyfile)) {
5541: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5542: my $thumb_metaoutput =
5543: &write_metadata($dom,$confname,$formname,
5544: $targetdir,'tn-'.$file,$logfile);
5545: push(@{$modified_urls},[$copyfile,$outfile]);
5546: unless ($registered_cleanup) {
5547: my $handlers = $r->get_handlers('PerlCleanupHandler');
5548: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5549: $registered_cleanup=1;
5550: }
1.16 raeburn 5551: } else {
5552: print $logfile "\nUnable to write ".$copyfile.
5553: ':'.$!."\n";
5554: }
5555: }
1.9 raeburn 5556: }
5557: }
5558: }
5559: } else {
5560: $output = $versionresult;
5561: }
5562: }
5563: return ($output,$logourl);
5564: }
5565:
5566: sub logo_versioning {
5567: my ($targetdir,$file,$logfile) = @_;
5568: my $target = $targetdir.'/'.$file;
5569: my ($maxversion,$fn,$extn,$output);
5570: $maxversion = 0;
5571: if ($file =~ /^(.+)\.(\w+)$/) {
5572: $fn=$1;
5573: $extn=$2;
5574: }
5575: opendir(DIR,$targetdir);
5576: while (my $filename=readdir(DIR)) {
5577: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5578: $maxversion=($1>$maxversion)?$1:$maxversion;
5579: }
5580: }
5581: $maxversion++;
5582: print $logfile "\nCreating old version ".$maxversion."\n";
5583: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5584: if (copy($target,$copyfile)) {
5585: print $logfile "Copied old target to ".$copyfile."\n";
5586: $copyfile=$copyfile.'.meta';
5587: if (copy($target.'.meta',$copyfile)) {
5588: print $logfile "Copied old target metadata to ".$copyfile."\n";
5589: $output = 'ok';
5590: } else {
5591: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5592: $output = &mt('Failed to copy old meta').", $!, ";
5593: }
5594: } else {
5595: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5596: $output = &mt('Failed to copy old target').", $!, ";
5597: }
5598: return $output;
5599: }
5600:
5601: sub write_metadata {
5602: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5603: my (%metadatafields,%metadatakeys,$output);
5604: $metadatafields{'title'}=$formname;
5605: $metadatafields{'creationdate'}=time;
5606: $metadatafields{'lastrevisiondate'}=time;
5607: $metadatafields{'copyright'}='public';
5608: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5609: $env{'user.domain'};
5610: $metadatafields{'authorspace'}=$confname.':'.$dom;
5611: $metadatafields{'domain'}=$dom;
5612: {
5613: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5614: my $mfh;
1.155 raeburn 5615: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5616: foreach (sort keys %metadatafields) {
5617: unless ($_=~/\./) {
5618: my $unikey=$_;
5619: $unikey=~/^([A-Za-z]+)/;
5620: my $tag=$1;
5621: $tag=~tr/A-Z/a-z/;
5622: print $mfh "\n\<$tag";
5623: foreach (split(/\,/,$metadatakeys{$unikey})) {
5624: my $value=$metadatafields{$unikey.'.'.$_};
5625: $value=~s/\"/\'\'/g;
5626: print $mfh ' '.$_.'="'.$value.'"';
5627: }
5628: print $mfh '>'.
5629: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5630: .'</'.$tag.'>';
5631: }
5632: }
5633: $output = 'ok';
5634: print $logfile "\nWrote metadata";
5635: close($mfh);
5636: } else {
5637: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5638: $output = &mt('Could not write metadata');
5639: }
5640: }
1.155 raeburn 5641: return $output;
5642: }
5643:
5644: sub notifysubscribed {
5645: foreach my $targetsource (@{$modified_urls}){
5646: next unless (ref($targetsource) eq 'ARRAY');
5647: my ($target,$source)=@{$targetsource};
5648: if ($source ne '') {
5649: if (open(my $logfh,'>>'.$source.'.log')) {
5650: print $logfh "\nCleanup phase: Notifications\n";
5651: my @subscribed=&subscribed_hosts($target);
5652: foreach my $subhost (@subscribed) {
5653: print $logfh "\nNotifying host ".$subhost.':';
5654: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5655: print $logfh $reply;
5656: }
5657: my @subscribedmeta=&subscribed_hosts("$target.meta");
5658: foreach my $subhost (@subscribedmeta) {
5659: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5660: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5661: $subhost);
5662: print $logfh $reply;
5663: }
5664: print $logfh "\n============ Done ============\n";
1.160 raeburn 5665: close($logfh);
1.155 raeburn 5666: }
5667: }
5668: }
5669: return OK;
5670: }
5671:
5672: sub subscribed_hosts {
5673: my ($target) = @_;
5674: my @subscribed;
5675: if (open(my $fh,"<$target.subscription")) {
5676: while (my $subline=<$fh>) {
5677: if ($subline =~ /^($match_lonid):/) {
5678: my $host = $1;
5679: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5680: unless (grep(/^\Q$host\E$/,@subscribed)) {
5681: push(@subscribed,$host);
5682: }
5683: }
5684: }
5685: }
5686: }
5687: return @subscribed;
1.9 raeburn 5688: }
5689:
5690: sub check_switchserver {
5691: my ($dom,$confname) = @_;
5692: my ($allowed,$switchserver);
5693: my $home = &Apache::lonnet::homeserver($confname,$dom);
5694: if ($home eq 'no_host') {
5695: $home = &Apache::lonnet::domain($dom,'primary');
5696: }
5697: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5698: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5699: if (!$allowed) {
1.180 raeburn 5700: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5701: }
5702: return $switchserver;
5703: }
5704:
1.1 raeburn 5705: sub modify_quotas {
1.86 raeburn 5706: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5707: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5708: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5709: if ($action eq 'quotas') {
5710: $context = 'tools';
1.163 raeburn 5711: } else {
1.86 raeburn 5712: $context = $action;
5713: }
5714: if ($context eq 'requestcourses') {
1.98 raeburn 5715: @usertools = ('official','unofficial','community');
1.106 raeburn 5716: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5717: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5718: %titles = &courserequest_titles();
5719: $toolregexp = join('|',@usertools);
5720: %conditions = &courserequest_conditions();
1.163 raeburn 5721: } elsif ($context eq 'requestauthor') {
5722: @usertools = ('author');
5723: %titles = &authorrequest_titles();
1.86 raeburn 5724: } else {
1.162 raeburn 5725: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5726: %titles = &tool_titles();
1.86 raeburn 5727: }
1.72 raeburn 5728: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5729: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5730: foreach my $key (keys(%env)) {
1.101 raeburn 5731: if ($context eq 'requestcourses') {
5732: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5733: my $item = $1;
5734: my $type = $2;
5735: if ($type =~ /^limit_(.+)/) {
5736: $limithash{$item}{$1} = $env{$key};
5737: } else {
5738: $confhash{$item}{$type} = $env{$key};
5739: }
5740: }
1.163 raeburn 5741: } elsif ($context eq 'requestauthor') {
5742: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5743: $confhash{$1} = $env{$key};
5744: }
1.101 raeburn 5745: } else {
1.86 raeburn 5746: if ($key =~ /^form\.quota_(.+)$/) {
5747: $confhash{'defaultquota'}{$1} = $env{$key};
5748: }
1.101 raeburn 5749: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5750: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5751: }
1.72 raeburn 5752: }
5753: }
1.163 raeburn 5754: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5755: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5756: @approvalnotify = sort(@approvalnotify);
5757: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5758: if (ref($domconfig{$action}) eq 'HASH') {
5759: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5760: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5761: $changes{'notify'}{'approval'} = 1;
5762: }
5763: } else {
1.144 raeburn 5764: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5765: $changes{'notify'}{'approval'} = 1;
5766: }
5767: }
5768: } else {
1.144 raeburn 5769: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5770: $changes{'notify'}{'approval'} = 1;
5771: }
5772: }
5773: } else {
1.86 raeburn 5774: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5775: }
1.72 raeburn 5776: foreach my $item (@usertools) {
5777: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5778: my $unset;
1.101 raeburn 5779: if ($context eq 'requestcourses') {
1.104 raeburn 5780: $unset = '0';
5781: if ($type eq '_LC_adv') {
5782: $unset = '';
5783: }
1.101 raeburn 5784: if ($confhash{$item}{$type} eq 'autolimit') {
5785: $confhash{$item}{$type} .= '=';
5786: unless ($limithash{$item}{$type} =~ /\D/) {
5787: $confhash{$item}{$type} .= $limithash{$item}{$type};
5788: }
5789: }
1.163 raeburn 5790: } elsif ($context eq 'requestauthor') {
5791: $unset = '0';
5792: if ($type eq '_LC_adv') {
5793: $unset = '';
5794: }
1.72 raeburn 5795: } else {
1.101 raeburn 5796: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5797: $confhash{$item}{$type} = 1;
5798: } else {
5799: $confhash{$item}{$type} = 0;
5800: }
1.72 raeburn 5801: }
1.86 raeburn 5802: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5803: if ($action eq 'requestauthor') {
5804: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5805: $changes{$type} = 1;
5806: }
5807: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5808: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5809: $changes{$item}{$type} = 1;
5810: }
5811: } else {
5812: if ($context eq 'requestcourses') {
1.104 raeburn 5813: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5814: $changes{$item}{$type} = 1;
5815: }
5816: } else {
5817: if (!$confhash{$item}{$type}) {
5818: $changes{$item}{$type} = 1;
5819: }
5820: }
5821: }
5822: } else {
5823: if ($context eq 'requestcourses') {
1.104 raeburn 5824: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5825: $changes{$item}{$type} = 1;
5826: }
1.163 raeburn 5827: } elsif ($context eq 'requestauthor') {
5828: if ($confhash{$type} ne $unset) {
5829: $changes{$type} = 1;
5830: }
1.72 raeburn 5831: } else {
5832: if (!$confhash{$item}{$type}) {
5833: $changes{$item}{$type} = 1;
5834: }
5835: }
5836: }
1.1 raeburn 5837: }
5838: }
1.163 raeburn 5839: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5840: if (ref($domconfig{'quotas'}) eq 'HASH') {
5841: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5842: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5843: if (exists($confhash{'defaultquota'}{$key})) {
5844: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5845: $changes{'defaultquota'}{$key} = 1;
5846: }
5847: } else {
5848: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5849: }
5850: }
1.86 raeburn 5851: } else {
5852: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5853: if (exists($confhash{'defaultquota'}{$key})) {
5854: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5855: $changes{'defaultquota'}{$key} = 1;
5856: }
5857: } else {
5858: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5859: }
1.1 raeburn 5860: }
5861: }
5862: }
1.86 raeburn 5863: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5864: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5865: if (ref($domconfig{'quotas'}) eq 'HASH') {
5866: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5867: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5868: $changes{'defaultquota'}{$key} = 1;
5869: }
5870: } else {
5871: if (!exists($domconfig{'quotas'}{$key})) {
5872: $changes{'defaultquota'}{$key} = 1;
5873: }
1.72 raeburn 5874: }
5875: } else {
1.86 raeburn 5876: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5877: }
1.1 raeburn 5878: }
5879: }
5880: }
1.72 raeburn 5881:
1.163 raeburn 5882: if ($context eq 'requestauthor') {
5883: $domdefaults{'requestauthor'} = \%confhash;
5884: } else {
5885: foreach my $key (keys(%confhash)) {
5886: $domdefaults{$key} = $confhash{$key};
5887: }
1.72 raeburn 5888: }
1.163 raeburn 5889:
1.1 raeburn 5890: my %quotahash = (
1.86 raeburn 5891: $action => { %confhash }
1.1 raeburn 5892: );
5893: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5894: $dom);
5895: if ($putresult eq 'ok') {
5896: if (keys(%changes) > 0) {
1.72 raeburn 5897: my $cachetime = 24*60*60;
5898: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5899:
1.1 raeburn 5900: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5901: unless (($context eq 'requestcourses') ||
5902: ($context eq 'requestauthor')) {
1.86 raeburn 5903: if (ref($changes{'defaultquota'}) eq 'HASH') {
5904: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5905: foreach my $type (@{$types},'default') {
5906: if (defined($changes{'defaultquota'}{$type})) {
5907: my $typetitle = $usertypes->{$type};
5908: if ($type eq 'default') {
5909: $typetitle = $othertitle;
5910: }
5911: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5912: }
5913: }
1.86 raeburn 5914: $resulttext .= '</ul></li>';
1.72 raeburn 5915: }
5916: }
1.80 raeburn 5917: my %newenv;
1.72 raeburn 5918: foreach my $item (@usertools) {
1.163 raeburn 5919: my (%haschgs,%inconf);
5920: if ($context eq 'requestauthor') {
5921: %haschgs = %changes;
5922: %inconf = %confhash;
5923: } else {
5924: if (ref($changes{$item}) eq 'HASH') {
5925: %haschgs = %{$changes{$item}};
5926: }
5927: if (ref($confhash{$item}) eq 'HASH') {
5928: %inconf = %{$confhash{$item}};
5929: }
5930: }
5931: if (keys(%haschgs) > 0) {
1.80 raeburn 5932: my $newacc =
5933: &Apache::lonnet::usertools_access($env{'user.name'},
5934: $env{'user.domain'},
1.86 raeburn 5935: $item,'reload',$context);
1.163 raeburn 5936: if (($context eq 'requestcourses') ||
5937: ($context eq 'requestauthor')) {
1.108 raeburn 5938: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5939: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5940: }
5941: } else {
5942: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5943: $newenv{'environment.availabletools.'.$item} = $newacc;
5944: }
1.80 raeburn 5945: }
1.163 raeburn 5946: unless ($context eq 'requestauthor') {
5947: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5948: }
1.72 raeburn 5949: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5950: if ($haschgs{$type}) {
1.72 raeburn 5951: my $typetitle = $usertypes->{$type};
5952: if ($type eq 'default') {
5953: $typetitle = $othertitle;
5954: } elsif ($type eq '_LC_adv') {
5955: $typetitle = 'LON-CAPA Advanced Users';
5956: }
1.163 raeburn 5957: if ($inconf{$type}) {
1.101 raeburn 5958: if ($context eq 'requestcourses') {
5959: my $cond;
1.163 raeburn 5960: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5961: if ($1 eq '') {
5962: $cond = &mt('(Automatic processing of any request).');
5963: } else {
5964: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5965: }
5966: } else {
1.163 raeburn 5967: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5968: }
5969: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 5970: } elsif ($context eq 'requestauthor') {
5971: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5972: $titles{$inconf{$type}},$typetitle);
5973:
1.101 raeburn 5974: } else {
5975: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5976: }
1.72 raeburn 5977: } else {
1.104 raeburn 5978: if ($type eq '_LC_adv') {
1.163 raeburn 5979: if ($inconf{$type} eq '0') {
1.104 raeburn 5980: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5981: } else {
5982: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5983: }
5984: } else {
5985: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5986: }
1.72 raeburn 5987: }
5988: }
1.26 raeburn 5989: }
1.163 raeburn 5990: unless ($context eq 'requestauthor') {
5991: $resulttext .= '</ul></li>';
5992: }
1.26 raeburn 5993: }
1.1 raeburn 5994: }
1.163 raeburn 5995: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5996: if (ref($changes{'notify'}) eq 'HASH') {
5997: if ($changes{'notify'}{'approval'}) {
5998: if (ref($confhash{'notify'}) eq 'HASH') {
5999: if ($confhash{'notify'}{'approval'}) {
6000: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6001: } else {
1.163 raeburn 6002: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6003: }
6004: }
6005: }
6006: }
6007: }
1.1 raeburn 6008: $resulttext .= '</ul>';
1.80 raeburn 6009: if (keys(%newenv)) {
6010: &Apache::lonnet::appenv(\%newenv);
6011: }
1.1 raeburn 6012: } else {
1.86 raeburn 6013: if ($context eq 'requestcourses') {
6014: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6015: } elsif ($context eq 'requestauthor') {
6016: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6017: } else {
1.90 weissno 6018: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6019: }
1.1 raeburn 6020: }
6021: } else {
1.11 albertel 6022: $resulttext = '<span class="LC_error">'.
6023: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6024: }
1.3 raeburn 6025: return $resulttext;
1.1 raeburn 6026: }
6027:
1.3 raeburn 6028: sub modify_autoenroll {
6029: my ($dom,%domconfig) = @_;
1.1 raeburn 6030: my ($resulttext,%changes);
6031: my %currautoenroll;
6032: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6033: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6034: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6035: }
6036: }
6037: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6038: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6039: sender => 'Sender for notification messages',
6040: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6041: my @offon = ('off','on');
1.17 raeburn 6042: my $sender_uname = $env{'form.sender_uname'};
6043: my $sender_domain = $env{'form.sender_domain'};
6044: if ($sender_domain eq '') {
6045: $sender_uname = '';
6046: } elsif ($sender_uname eq '') {
6047: $sender_domain = '';
6048: }
1.129 raeburn 6049: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6050: my %autoenrollhash = (
1.129 raeburn 6051: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6052: 'sender_uname' => $sender_uname,
6053: 'sender_domain' => $sender_domain,
6054: 'co-owners' => $coowners,
1.1 raeburn 6055: }
6056: );
1.4 raeburn 6057: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6058: $dom);
1.1 raeburn 6059: if ($putresult eq 'ok') {
6060: if (exists($currautoenroll{'run'})) {
6061: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6062: $changes{'run'} = 1;
6063: }
6064: } elsif ($autorun) {
6065: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6066: $changes{'run'} = 1;
1.1 raeburn 6067: }
6068: }
1.17 raeburn 6069: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6070: $changes{'sender'} = 1;
6071: }
1.17 raeburn 6072: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6073: $changes{'sender'} = 1;
6074: }
1.129 raeburn 6075: if ($currautoenroll{'co-owners'} ne '') {
6076: if ($currautoenroll{'co-owners'} ne $coowners) {
6077: $changes{'coowners'} = 1;
6078: }
6079: } elsif ($coowners) {
6080: $changes{'coowners'} = 1;
6081: }
1.1 raeburn 6082: if (keys(%changes) > 0) {
6083: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6084: if ($changes{'run'}) {
1.1 raeburn 6085: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6086: }
6087: if ($changes{'sender'}) {
1.17 raeburn 6088: if ($sender_uname eq '' || $sender_domain eq '') {
6089: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6090: } else {
6091: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6092: }
1.1 raeburn 6093: }
1.129 raeburn 6094: if ($changes{'coowners'}) {
6095: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6096: &Apache::loncommon::devalidate_domconfig_cache($dom);
6097: }
1.1 raeburn 6098: $resulttext .= '</ul>';
6099: } else {
6100: $resulttext = &mt('No changes made to auto-enrollment settings');
6101: }
6102: } else {
1.11 albertel 6103: $resulttext = '<span class="LC_error">'.
6104: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6105: }
1.3 raeburn 6106: return $resulttext;
1.1 raeburn 6107: }
6108:
6109: sub modify_autoupdate {
1.3 raeburn 6110: my ($dom,%domconfig) = @_;
1.1 raeburn 6111: my ($resulttext,%currautoupdate,%fields,%changes);
6112: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6113: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6114: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6115: }
6116: }
6117: my @offon = ('off','on');
6118: my %title = &Apache::lonlocal::texthash (
6119: run => 'Auto-update:',
6120: classlists => 'Updates to user information in classlists?'
6121: );
1.44 raeburn 6122: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6123: my %fieldtitles = &Apache::lonlocal::texthash (
6124: id => 'Student/Employee ID',
1.20 raeburn 6125: permanentemail => 'E-mail address',
1.1 raeburn 6126: lastname => 'Last Name',
6127: firstname => 'First Name',
6128: middlename => 'Middle Name',
1.132 raeburn 6129: generation => 'Generation',
1.1 raeburn 6130: );
1.142 raeburn 6131: $othertitle = &mt('All users');
1.1 raeburn 6132: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6133: $othertitle = &mt('Other users');
1.1 raeburn 6134: }
6135: foreach my $key (keys(%env)) {
6136: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6137: my ($usertype,$item) = ($1,$2);
6138: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6139: if ($usertype eq 'default') {
6140: push(@{$fields{$1}},$2);
6141: } elsif (ref($types) eq 'ARRAY') {
6142: if (grep(/^\Q$usertype\E$/,@{$types})) {
6143: push(@{$fields{$1}},$2);
6144: }
6145: }
6146: }
1.1 raeburn 6147: }
6148: }
1.131 raeburn 6149: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6150: @lockablenames = sort(@lockablenames);
6151: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6152: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6153: if (@changed) {
6154: $changes{'lockablenames'} = 1;
6155: }
6156: } else {
6157: if (@lockablenames) {
6158: $changes{'lockablenames'} = 1;
6159: }
6160: }
1.1 raeburn 6161: my %updatehash = (
6162: autoupdate => { run => $env{'form.autoupdate_run'},
6163: classlists => $env{'form.classlists'},
6164: fields => {%fields},
1.131 raeburn 6165: lockablenames => \@lockablenames,
1.1 raeburn 6166: }
6167: );
6168: foreach my $key (keys(%currautoupdate)) {
6169: if (($key eq 'run') || ($key eq 'classlists')) {
6170: if (exists($updatehash{autoupdate}{$key})) {
6171: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6172: $changes{$key} = 1;
6173: }
6174: }
6175: } elsif ($key eq 'fields') {
6176: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6177: foreach my $item (@{$types},'default') {
1.1 raeburn 6178: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6179: my $change = 0;
6180: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6181: if (!exists($fields{$item})) {
6182: $change = 1;
1.132 raeburn 6183: last;
1.1 raeburn 6184: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6185: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6186: $change = 1;
1.132 raeburn 6187: last;
1.1 raeburn 6188: }
6189: }
6190: }
6191: if ($change) {
6192: push(@{$changes{$key}},$item);
6193: }
1.26 raeburn 6194: }
1.1 raeburn 6195: }
6196: }
1.131 raeburn 6197: } elsif ($key eq 'lockablenames') {
6198: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6199: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6200: if (@changed) {
6201: $changes{'lockablenames'} = 1;
6202: }
6203: } else {
6204: if (@lockablenames) {
6205: $changes{'lockablenames'} = 1;
6206: }
6207: }
6208: }
6209: }
6210: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6211: if (@lockablenames) {
6212: $changes{'lockablenames'} = 1;
1.1 raeburn 6213: }
6214: }
1.26 raeburn 6215: foreach my $item (@{$types},'default') {
6216: if (defined($fields{$item})) {
6217: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6218: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6219: my $change = 0;
6220: if (ref($fields{$item}) eq 'ARRAY') {
6221: foreach my $type (@{$fields{$item}}) {
6222: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6223: $change = 1;
6224: last;
6225: }
6226: }
6227: }
6228: if ($change) {
6229: push(@{$changes{'fields'}},$item);
6230: }
6231: } else {
1.26 raeburn 6232: push(@{$changes{'fields'}},$item);
6233: }
6234: } else {
6235: push(@{$changes{'fields'}},$item);
1.1 raeburn 6236: }
6237: }
6238: }
6239: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6240: $dom);
6241: if ($putresult eq 'ok') {
6242: if (keys(%changes) > 0) {
6243: $resulttext = &mt('Changes made:').'<ul>';
6244: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6245: if ($key eq 'lockablenames') {
6246: $resulttext .= '<li>';
6247: if (@lockablenames) {
6248: $usertypes->{'default'} = $othertitle;
6249: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6250: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6251: } else {
6252: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6253: }
6254: $resulttext .= '</li>';
6255: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6256: foreach my $item (@{$changes{$key}}) {
6257: my @newvalues;
6258: foreach my $type (@{$fields{$item}}) {
6259: push(@newvalues,$fieldtitles{$type});
6260: }
1.3 raeburn 6261: my $newvaluestr;
6262: if (@newvalues > 0) {
6263: $newvaluestr = join(', ',@newvalues);
6264: } else {
6265: $newvaluestr = &mt('none');
1.6 raeburn 6266: }
1.1 raeburn 6267: if ($item eq 'default') {
1.26 raeburn 6268: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6269: } else {
1.26 raeburn 6270: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6271: }
6272: }
6273: } else {
6274: my $newvalue;
6275: if ($key eq 'run') {
6276: $newvalue = $offon[$env{'form.autoupdate_run'}];
6277: } else {
6278: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6279: }
1.1 raeburn 6280: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6281: }
6282: }
6283: $resulttext .= '</ul>';
6284: } else {
1.3 raeburn 6285: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6286: }
6287: } else {
1.11 albertel 6288: $resulttext = '<span class="LC_error">'.
6289: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6290: }
1.3 raeburn 6291: return $resulttext;
1.1 raeburn 6292: }
6293:
1.125 raeburn 6294: sub modify_autocreate {
6295: my ($dom,%domconfig) = @_;
6296: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6297: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6298: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6299: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6300: }
6301: }
6302: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6303: req => 'Auto-creation of validated requests for official courses',
6304: xmldc => 'Identity of course creator of courses from XML files',
6305: );
6306: my @types = ('xml','req');
6307: foreach my $item (@types) {
6308: $newvals{$item} = $env{'form.autocreate_'.$item};
6309: $newvals{$item} =~ s/\D//g;
6310: $newvals{$item} = 0 if ($newvals{$item} eq '');
6311: }
6312: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6313: my %domcoords = &get_active_dcs($dom);
6314: unless (exists($domcoords{$newvals{'xmldc'}})) {
6315: $newvals{'xmldc'} = '';
6316: }
6317: %autocreatehash = (
6318: autocreate => { xml => $newvals{'xml'},
6319: req => $newvals{'req'},
6320: }
6321: );
6322: if ($newvals{'xmldc'} ne '') {
6323: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6324: }
6325: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6326: $dom);
6327: if ($putresult eq 'ok') {
6328: my @items = @types;
6329: if ($newvals{'xml'}) {
6330: push(@items,'xmldc');
6331: }
6332: foreach my $item (@items) {
6333: if (exists($currautocreate{$item})) {
6334: if ($currautocreate{$item} ne $newvals{$item}) {
6335: $changes{$item} = 1;
6336: }
6337: } elsif ($newvals{$item}) {
6338: $changes{$item} = 1;
6339: }
6340: }
6341: if (keys(%changes) > 0) {
6342: my @offon = ('off','on');
6343: $resulttext = &mt('Changes made:').'<ul>';
6344: foreach my $item (@types) {
6345: if ($changes{$item}) {
6346: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6347: $resulttext .= '<li>'.
6348: &mt("$title{$item} set to [_1]$newtxt [_2]",
6349: '<b>','</b>').
6350: '</li>';
1.125 raeburn 6351: }
6352: }
6353: if ($changes{'xmldc'}) {
6354: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6355: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6356: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6357: }
6358: $resulttext .= '</ul>';
6359: } else {
6360: $resulttext = &mt('No changes made to auto-creation settings');
6361: }
6362: } else {
6363: $resulttext = '<span class="LC_error">'.
6364: &mt('An error occurred: [_1]',$putresult).'</span>';
6365: }
6366: return $resulttext;
6367: }
6368:
1.23 raeburn 6369: sub modify_directorysrch {
6370: my ($dom,%domconfig) = @_;
6371: my ($resulttext,%changes);
6372: my %currdirsrch;
6373: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6374: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6375: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6376: }
6377: }
6378: my %title = ( available => 'Directory search available',
1.24 raeburn 6379: localonly => 'Other domains can search',
1.23 raeburn 6380: searchby => 'Search types',
6381: searchtypes => 'Search latitude');
6382: my @offon = ('off','on');
1.24 raeburn 6383: my @otherdoms = ('Yes','No');
1.23 raeburn 6384:
1.25 raeburn 6385: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6386: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6387: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6388:
1.44 raeburn 6389: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6390: if (keys(%{$usertypes}) == 0) {
6391: @cansearch = ('default');
6392: } else {
6393: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6394: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6395: if (!grep(/^\Q$type\E$/,@cansearch)) {
6396: push(@{$changes{'cansearch'}},$type);
6397: }
1.23 raeburn 6398: }
1.26 raeburn 6399: foreach my $type (@cansearch) {
6400: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6401: push(@{$changes{'cansearch'}},$type);
6402: }
1.23 raeburn 6403: }
1.26 raeburn 6404: } else {
6405: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6406: }
6407: }
6408:
6409: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6410: foreach my $by (@{$currdirsrch{'searchby'}}) {
6411: if (!grep(/^\Q$by\E$/,@searchby)) {
6412: push(@{$changes{'searchby'}},$by);
6413: }
6414: }
6415: foreach my $by (@searchby) {
6416: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6417: push(@{$changes{'searchby'}},$by);
6418: }
6419: }
6420: } else {
6421: push(@{$changes{'searchby'}},@searchby);
6422: }
1.25 raeburn 6423:
6424: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6425: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6426: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6427: push(@{$changes{'searchtypes'}},$type);
6428: }
6429: }
6430: foreach my $type (@searchtypes) {
6431: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6432: push(@{$changes{'searchtypes'}},$type);
6433: }
6434: }
6435: } else {
6436: if (exists($currdirsrch{'searchtypes'})) {
6437: foreach my $type (@searchtypes) {
6438: if ($type ne $currdirsrch{'searchtypes'}) {
6439: push(@{$changes{'searchtypes'}},$type);
6440: }
6441: }
6442: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6443: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6444: }
6445: } else {
6446: push(@{$changes{'searchtypes'}},@searchtypes);
6447: }
6448: }
6449:
1.23 raeburn 6450: my %dirsrch_hash = (
6451: directorysrch => { available => $env{'form.dirsrch_available'},
6452: cansearch => \@cansearch,
1.24 raeburn 6453: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6454: searchby => \@searchby,
1.25 raeburn 6455: searchtypes => \@searchtypes,
1.23 raeburn 6456: }
6457: );
6458: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6459: $dom);
6460: if ($putresult eq 'ok') {
6461: if (exists($currdirsrch{'available'})) {
6462: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6463: $changes{'available'} = 1;
6464: }
6465: } else {
6466: if ($env{'form.dirsrch_available'} eq '1') {
6467: $changes{'available'} = 1;
6468: }
6469: }
1.24 raeburn 6470: if (exists($currdirsrch{'localonly'})) {
6471: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6472: $changes{'localonly'} = 1;
6473: }
6474: } else {
6475: if ($env{'form.dirsrch_localonly'} eq '1') {
6476: $changes{'localonly'} = 1;
6477: }
6478: }
1.23 raeburn 6479: if (keys(%changes) > 0) {
6480: $resulttext = &mt('Changes made:').'<ul>';
6481: if ($changes{'available'}) {
6482: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6483: }
1.24 raeburn 6484: if ($changes{'localonly'}) {
6485: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6486: }
6487:
1.23 raeburn 6488: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6489: my $chgtext;
1.26 raeburn 6490: if (ref($usertypes) eq 'HASH') {
6491: if (keys(%{$usertypes}) > 0) {
6492: foreach my $type (@{$types}) {
6493: if (grep(/^\Q$type\E$/,@cansearch)) {
6494: $chgtext .= $usertypes->{$type}.'; ';
6495: }
6496: }
6497: if (grep(/^default$/,@cansearch)) {
6498: $chgtext .= $othertitle;
6499: } else {
6500: $chgtext =~ s/\; $//;
6501: }
1.178 raeburn 6502: $resulttext .=
6503: '<li>'.
6504: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6505: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6506: '</li>';
1.23 raeburn 6507: }
6508: }
6509: }
6510: if (ref($changes{'searchby'}) eq 'ARRAY') {
6511: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6512: my $chgtext;
6513: foreach my $type (@{$titleorder}) {
6514: if (grep(/^\Q$type\E$/,@searchby)) {
6515: if (defined($searchtitles->{$type})) {
6516: $chgtext .= $searchtitles->{$type}.'; ';
6517: }
6518: }
6519: }
6520: $chgtext =~ s/\; $//;
6521: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6522: }
1.25 raeburn 6523: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6524: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6525: my $chgtext;
6526: foreach my $type (@{$srchtypeorder}) {
6527: if (grep(/^\Q$type\E$/,@searchtypes)) {
6528: if (defined($srchtypes_desc->{$type})) {
6529: $chgtext .= $srchtypes_desc->{$type}.'; ';
6530: }
6531: }
6532: }
6533: $chgtext =~ s/\; $//;
1.178 raeburn 6534: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6535: }
6536: $resulttext .= '</ul>';
6537: } else {
6538: $resulttext = &mt('No changes made to institution directory search settings');
6539: }
6540: } else {
6541: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6542: &mt('An error occurred: [_1]',$putresult).'</span>';
6543: }
6544: return $resulttext;
6545: }
6546:
1.28 raeburn 6547: sub modify_contacts {
6548: my ($dom,%domconfig) = @_;
6549: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6550: if (ref($domconfig{'contacts'}) eq 'HASH') {
6551: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6552: $currsetting{$key} = $domconfig{'contacts'}{$key};
6553: }
6554: }
1.134 raeburn 6555: my (%others,%to,%bcc);
1.28 raeburn 6556: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6557: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6558: 'requestsmail');
1.28 raeburn 6559: foreach my $type (@mailings) {
6560: @{$newsetting{$type}} =
6561: &Apache::loncommon::get_env_multiple('form.'.$type);
6562: foreach my $item (@contacts) {
6563: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6564: $contacts_hash{contacts}{$type}{$item} = 1;
6565: } else {
6566: $contacts_hash{contacts}{$type}{$item} = 0;
6567: }
6568: }
6569: $others{$type} = $env{'form.'.$type.'_others'};
6570: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6571: if ($type eq 'helpdeskmail') {
6572: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6573: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6574: }
1.28 raeburn 6575: }
6576: foreach my $item (@contacts) {
6577: $to{$item} = $env{'form.'.$item};
6578: $contacts_hash{'contacts'}{$item} = $to{$item};
6579: }
6580: if (keys(%currsetting) > 0) {
6581: foreach my $item (@contacts) {
6582: if ($to{$item} ne $currsetting{$item}) {
6583: $changes{$item} = 1;
6584: }
6585: }
6586: foreach my $type (@mailings) {
6587: foreach my $item (@contacts) {
6588: if (ref($currsetting{$type}) eq 'HASH') {
6589: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6590: push(@{$changes{$type}},$item);
6591: }
6592: } else {
6593: push(@{$changes{$type}},@{$newsetting{$type}});
6594: }
6595: }
6596: if ($others{$type} ne $currsetting{$type}{'others'}) {
6597: push(@{$changes{$type}},'others');
6598: }
1.134 raeburn 6599: if ($type eq 'helpdeskmail') {
6600: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6601: push(@{$changes{$type}},'bcc');
6602: }
6603: }
1.28 raeburn 6604: }
6605: } else {
6606: my %default;
6607: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6608: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6609: $default{'errormail'} = 'adminemail';
6610: $default{'packagesmail'} = 'adminemail';
6611: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6612: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6613: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6614: foreach my $item (@contacts) {
6615: if ($to{$item} ne $default{$item}) {
6616: $changes{$item} = 1;
6617: }
6618: }
6619: foreach my $type (@mailings) {
6620: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6621:
6622: push(@{$changes{$type}},@{$newsetting{$type}});
6623: }
6624: if ($others{$type} ne '') {
6625: push(@{$changes{$type}},'others');
1.134 raeburn 6626: }
6627: if ($type eq 'helpdeskmail') {
6628: if ($bcc{$type} ne '') {
6629: push(@{$changes{$type}},'bcc');
6630: }
6631: }
1.28 raeburn 6632: }
6633: }
6634: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6635: $dom);
6636: if ($putresult eq 'ok') {
6637: if (keys(%changes) > 0) {
6638: my ($titles,$short_titles) = &contact_titles();
6639: $resulttext = &mt('Changes made:').'<ul>';
6640: foreach my $item (@contacts) {
6641: if ($changes{$item}) {
6642: $resulttext .= '<li>'.$titles->{$item}.
6643: &mt(' set to: ').
6644: '<span class="LC_cusr_emph">'.
6645: $to{$item}.'</span></li>';
6646: }
6647: }
6648: foreach my $type (@mailings) {
6649: if (ref($changes{$type}) eq 'ARRAY') {
6650: $resulttext .= '<li>'.$titles->{$type}.': ';
6651: my @text;
6652: foreach my $item (@{$newsetting{$type}}) {
6653: push(@text,$short_titles->{$item});
6654: }
6655: if ($others{$type} ne '') {
6656: push(@text,$others{$type});
6657: }
6658: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6659: join(', ',@text).'</span>';
6660: if ($type eq 'helpdeskmail') {
6661: if ($bcc{$type} ne '') {
6662: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6663: }
6664: }
6665: $resulttext .= '</li>';
1.28 raeburn 6666: }
6667: }
6668: $resulttext .= '</ul>';
6669: } else {
1.34 raeburn 6670: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6671: }
6672: } else {
6673: $resulttext = '<span class="LC_error">'.
6674: &mt('An error occurred: [_1].',$putresult).'</span>';
6675: }
6676: return $resulttext;
6677: }
6678:
6679: sub modify_usercreation {
1.27 raeburn 6680: my ($dom,%domconfig) = @_;
1.34 raeburn 6681: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6682: my $warningmsg;
1.27 raeburn 6683: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6684: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6685: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6686: }
6687: }
6688: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6689: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6690: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6691: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6692: foreach my $item(@contexts) {
1.45 raeburn 6693: if ($item eq 'selfcreate') {
1.50 raeburn 6694: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6695: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6696: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6697: if (ref($cancreate{$item}) eq 'ARRAY') {
6698: if (grep(/^login$/,@{$cancreate{$item}})) {
6699: $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.');
6700: }
1.43 raeburn 6701: }
6702: }
1.50 raeburn 6703: } else {
6704: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6705: }
1.34 raeburn 6706: }
1.93 raeburn 6707: my ($othertitle,$usertypes,$types) =
6708: &Apache::loncommon::sorted_inst_types($dom);
6709: if (ref($types) eq 'ARRAY') {
6710: if (@{$types} > 0) {
6711: @{$cancreate{'statustocreate'}} =
6712: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6713: } else {
6714: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6715: }
6716: push(@contexts,'statustocreate');
6717: }
1.165 raeburn 6718: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6719: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6720: foreach my $item (@contexts) {
1.93 raeburn 6721: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6722: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6723: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6724: if (ref($cancreate{$item}) eq 'ARRAY') {
6725: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6726: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6727: push(@{$changes{'cancreate'}},$item);
6728: }
1.50 raeburn 6729: }
6730: }
6731: }
6732: } else {
6733: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6734: if (@{$cancreate{$item}} > 0) {
6735: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6736: push(@{$changes{'cancreate'}},$item);
6737: }
6738: }
6739: } else {
6740: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6741: if (@{$cancreate{$item}} < 3) {
6742: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6743: push(@{$changes{'cancreate'}},$item);
6744: }
6745: }
6746: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6747: if (@{$cancreate{$item}} > 0) {
6748: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6749: push(@{$changes{'cancreate'}},$item);
6750: }
6751: }
6752: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6753: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6754: push(@{$changes{'cancreate'}},$item);
6755: }
6756: }
6757: }
6758: }
6759: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6760: foreach my $type (@{$cancreate{$item}}) {
6761: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6762: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6763: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6764: push(@{$changes{'cancreate'}},$item);
6765: }
6766: }
6767: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6768: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6769: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6770: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6771: push(@{$changes{'cancreate'}},$item);
6772: }
6773: }
6774: }
6775: }
6776: }
6777: } else {
6778: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6779: push(@{$changes{'cancreate'}},$item);
6780: }
6781: }
1.27 raeburn 6782: }
1.34 raeburn 6783: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6784: foreach my $item (@contexts) {
1.43 raeburn 6785: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6786: if ($cancreate{$item} ne 'any') {
6787: push(@{$changes{'cancreate'}},$item);
6788: }
6789: } else {
6790: if ($cancreate{$item} ne 'none') {
6791: push(@{$changes{'cancreate'}},$item);
6792: }
1.27 raeburn 6793: }
6794: }
6795: } else {
1.43 raeburn 6796: foreach my $item (@contexts) {
1.34 raeburn 6797: push(@{$changes{'cancreate'}},$item);
6798: }
1.27 raeburn 6799: }
1.34 raeburn 6800:
1.27 raeburn 6801: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6802: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6803: if (!grep(/^\Q$type\E$/,@username_rule)) {
6804: push(@{$changes{'username_rule'}},$type);
6805: }
6806: }
6807: foreach my $type (@username_rule) {
6808: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6809: push(@{$changes{'username_rule'}},$type);
6810: }
6811: }
6812: } else {
6813: push(@{$changes{'username_rule'}},@username_rule);
6814: }
6815:
1.32 raeburn 6816: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6817: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6818: if (!grep(/^\Q$type\E$/,@id_rule)) {
6819: push(@{$changes{'id_rule'}},$type);
6820: }
6821: }
6822: foreach my $type (@id_rule) {
6823: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6824: push(@{$changes{'id_rule'}},$type);
6825: }
6826: }
6827: } else {
6828: push(@{$changes{'id_rule'}},@id_rule);
6829: }
6830:
1.43 raeburn 6831: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6832: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6833: if (!grep(/^\Q$type\E$/,@email_rule)) {
6834: push(@{$changes{'email_rule'}},$type);
6835: }
6836: }
6837: foreach my $type (@email_rule) {
6838: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6839: push(@{$changes{'email_rule'}},$type);
6840: }
6841: }
6842: } else {
6843: push(@{$changes{'email_rule'}},@email_rule);
6844: }
6845:
6846: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6847: my @authtypes = ('int','krb4','krb5','loc');
6848: my %authhash;
1.43 raeburn 6849: foreach my $item (@authen_contexts) {
1.28 raeburn 6850: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6851: foreach my $auth (@authtypes) {
6852: if (grep(/^\Q$auth\E$/,@authallowed)) {
6853: $authhash{$item}{$auth} = 1;
6854: } else {
6855: $authhash{$item}{$auth} = 0;
6856: }
6857: }
6858: }
6859: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6860: foreach my $item (@authen_contexts) {
1.28 raeburn 6861: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6862: foreach my $auth (@authtypes) {
6863: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6864: push(@{$changes{'authtypes'}},$item);
6865: last;
6866: }
6867: }
6868: }
6869: }
6870: } else {
1.43 raeburn 6871: foreach my $item (@authen_contexts) {
1.28 raeburn 6872: push(@{$changes{'authtypes'}},$item);
6873: }
6874: }
6875:
1.27 raeburn 6876: my %usercreation_hash = (
1.28 raeburn 6877: usercreation => {
1.34 raeburn 6878: cancreate => \%cancreate,
1.27 raeburn 6879: username_rule => \@username_rule,
1.32 raeburn 6880: id_rule => \@id_rule,
1.43 raeburn 6881: email_rule => \@email_rule,
1.32 raeburn 6882: authtypes => \%authhash,
1.27 raeburn 6883: }
6884: );
6885:
6886: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6887: $dom);
1.50 raeburn 6888:
6889: my %selfcreatetypes = (
6890: sso => 'users authenticated by institutional single sign on',
6891: login => 'users authenticated by institutional log-in',
6892: email => 'users who provide a valid e-mail address for use as the username',
6893: );
1.27 raeburn 6894: if ($putresult eq 'ok') {
6895: if (keys(%changes) > 0) {
6896: $resulttext = &mt('Changes made:').'<ul>';
6897: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6898: my %lt = &usercreation_types();
6899: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6900: my $chgtext;
1.165 raeburn 6901: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6902: $chgtext = $lt{$type}.', ';
6903: }
1.45 raeburn 6904: if ($type eq 'selfcreate') {
1.50 raeburn 6905: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6906: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6907: } else {
1.100 raeburn 6908: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6909: foreach my $case (@{$cancreate{$type}}) {
6910: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6911: }
6912: $chgtext .= '</ul>';
1.100 raeburn 6913: if (ref($cancreate{$type}) eq 'ARRAY') {
6914: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6915: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6916: if (@{$cancreate{'statustocreate'}} == 0) {
6917: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6918: }
6919: }
6920: }
6921: }
1.43 raeburn 6922: }
1.93 raeburn 6923: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6924: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6925: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6926: if (@{$cancreate{'selfcreate'}} > 0) {
6927: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6928:
6929: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6930: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6931: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6932: }
1.96 raeburn 6933: } elsif (ref($usertypes) eq 'HASH') {
6934: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6935: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6936: } else {
6937: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6938: }
6939: $chgtext .= '<ul>';
6940: foreach my $case (@{$cancreate{$type}}) {
6941: if ($case eq 'default') {
6942: $chgtext .= '<li>'.$othertitle.'</li>';
6943: } else {
6944: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6945: }
6946: }
1.100 raeburn 6947: $chgtext .= '</ul>';
6948: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6949: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6950: }
6951: }
6952: } else {
6953: if (@{$cancreate{$type}} == 0) {
6954: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6955: } else {
6956: $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 6957: }
6958: }
6959: }
1.165 raeburn 6960: } elsif ($type eq 'captcha') {
6961: if ($cancreate{$type} eq 'notused') {
6962: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6963: } else {
6964: my %captchas = &captcha_phrases();
6965: if ($captchas{$cancreate{$type}}) {
6966: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6967: } else {
6968: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6969: }
6970: }
6971: } elsif ($type eq 'recaptchakeys') {
6972: my ($privkey,$pubkey);
6973: if (ref($cancreate{$type}) eq 'HASH') {
6974: $pubkey = $cancreate{$type}{'public'};
6975: $privkey = $cancreate{$type}{'private'};
6976: }
6977: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6978: if (!$pubkey) {
6979: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6980: } else {
6981: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6982: }
6983: if (!$privkey) {
6984: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6985: } else {
6986: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6987: }
6988: $chgtext .= '</ul>';
1.43 raeburn 6989: } else {
6990: if ($cancreate{$type} eq 'none') {
6991: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6992: } elsif ($cancreate{$type} eq 'any') {
6993: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6994: } elsif ($cancreate{$type} eq 'official') {
6995: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6996: } elsif ($cancreate{$type} eq 'unofficial') {
6997: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6998: }
1.34 raeburn 6999: }
7000: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7001: }
7002: }
7003: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7004: my ($rules,$ruleorder) =
7005: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7006: my $chgtext = '<ul>';
7007: foreach my $type (@username_rule) {
7008: if (ref($rules->{$type}) eq 'HASH') {
7009: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7010: }
7011: }
7012: $chgtext .= '</ul>';
7013: if (@username_rule > 0) {
7014: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7015: } else {
1.28 raeburn 7016: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7017: }
7018: }
1.32 raeburn 7019: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7020: my ($idrules,$idruleorder) =
7021: &Apache::lonnet::inst_userrules($dom,'id');
7022: my $chgtext = '<ul>';
7023: foreach my $type (@id_rule) {
7024: if (ref($idrules->{$type}) eq 'HASH') {
7025: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7026: }
7027: }
7028: $chgtext .= '</ul>';
7029: if (@id_rule > 0) {
7030: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7031: } else {
7032: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7033: }
7034: }
1.43 raeburn 7035: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7036: my ($emailrules,$emailruleorder) =
7037: &Apache::lonnet::inst_userrules($dom,'email');
7038: my $chgtext = '<ul>';
7039: foreach my $type (@email_rule) {
7040: if (ref($emailrules->{$type}) eq 'HASH') {
7041: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7042: }
7043: }
7044: $chgtext .= '</ul>';
7045: if (@email_rule > 0) {
7046: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7047: } else {
7048: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7049: }
7050: }
7051:
1.28 raeburn 7052: my %authname = &authtype_names();
7053: my %context_title = &context_names();
7054: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7055: my $chgtext = '<ul>';
7056: foreach my $type (@{$changes{'authtypes'}}) {
7057: my @allowed;
7058: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7059: foreach my $auth (@authtypes) {
7060: if ($authhash{$type}{$auth}) {
7061: push(@allowed,$authname{$auth});
7062: }
7063: }
1.43 raeburn 7064: if (@allowed > 0) {
7065: $chgtext .= join(', ',@allowed).'</li>';
7066: } else {
7067: $chgtext .= &mt('none').'</li>';
7068: }
1.28 raeburn 7069: }
7070: $chgtext .= '</ul>';
7071: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7072: $resulttext .= '</li>';
7073: }
1.27 raeburn 7074: $resulttext .= '</ul>';
7075: } else {
1.28 raeburn 7076: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7077: }
7078: } else {
7079: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7080: &mt('An error occurred: [_1]',$putresult).'</span>';
7081: }
1.43 raeburn 7082: if ($warningmsg ne '') {
7083: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7084: }
1.23 raeburn 7085: return $resulttext;
7086: }
7087:
1.165 raeburn 7088: sub process_captcha {
7089: my ($container,$changes,$newsettings,$current) = @_;
7090: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7091: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7092: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7093: $newsettings->{'captcha'} = 'original';
7094: }
7095: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7096: if ($container eq 'cancreate') {
7097: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7098: push(@{$changes->{'cancreate'}},'captcha');
7099: } elsif (!defined($changes->{'cancreate'})) {
7100: $changes->{'cancreate'} = ['captcha'];
7101: }
7102: } else {
7103: $changes->{'captcha'} = 1;
1.165 raeburn 7104: }
7105: }
7106: my ($newpub,$newpriv,$currpub,$currpriv);
7107: if ($newsettings->{'captcha'} eq 'recaptcha') {
7108: $newpub = $env{'form.'.$container.'_recaptchapub'};
7109: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7110: $newpub =~ s/\W//g;
7111: $newpriv =~ s/\W//g;
7112: $newsettings->{'recaptchakeys'} = {
7113: public => $newpub,
7114: private => $newpriv,
7115: };
1.165 raeburn 7116: }
7117: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7118: $currpub = $current->{'recaptchakeys'}{'public'};
7119: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7120: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7121: $newsettings->{'recaptchakeys'} = {
7122: public => '',
7123: private => '',
7124: }
7125: }
1.165 raeburn 7126: }
7127: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7128: if ($container eq 'cancreate') {
7129: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7130: push(@{$changes->{'cancreate'}},'recaptchakeys');
7131: } elsif (!defined($changes->{'cancreate'})) {
7132: $changes->{'cancreate'} = ['recaptchakeys'];
7133: }
7134: } else {
7135: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7136: }
7137: }
7138: return;
7139: }
7140:
1.33 raeburn 7141: sub modify_usermodification {
7142: my ($dom,%domconfig) = @_;
7143: my ($resulttext,%curr_usermodification,%changes);
7144: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7145: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7146: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7147: }
7148: }
1.63 raeburn 7149: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7150: my %context_title = (
7151: author => 'In author context',
7152: course => 'In course context',
1.63 raeburn 7153: selfcreate => 'When self creating account',
1.33 raeburn 7154: );
7155: my @fields = ('lastname','firstname','middlename','generation',
7156: 'permanentemail','id');
7157: my %roles = (
7158: author => ['ca','aa'],
7159: course => ['st','ep','ta','in','cr'],
7160: );
1.63 raeburn 7161: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7162: if (ref($types) eq 'ARRAY') {
7163: push(@{$types},'default');
7164: $usertypes->{'default'} = $othertitle;
7165: }
7166: $roles{'selfcreate'} = $types;
1.33 raeburn 7167: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7168: my %modifyhash;
7169: foreach my $context (@contexts) {
7170: foreach my $role (@{$roles{$context}}) {
7171: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7172: foreach my $item (@fields) {
7173: if (grep(/^\Q$item\E$/,@modifiable)) {
7174: $modifyhash{$context}{$role}{$item} = 1;
7175: } else {
7176: $modifyhash{$context}{$role}{$item} = 0;
7177: }
7178: }
7179: }
7180: if (ref($curr_usermodification{$context}) eq 'HASH') {
7181: foreach my $role (@{$roles{$context}}) {
7182: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7183: foreach my $field (@fields) {
7184: if ($modifyhash{$context}{$role}{$field} ne
7185: $curr_usermodification{$context}{$role}{$field}) {
7186: push(@{$changes{$context}},$role);
7187: last;
7188: }
7189: }
7190: }
7191: }
7192: } else {
7193: foreach my $context (@contexts) {
7194: foreach my $role (@{$roles{$context}}) {
7195: push(@{$changes{$context}},$role);
7196: }
7197: }
7198: }
7199: }
7200: my %usermodification_hash = (
7201: usermodification => \%modifyhash,
7202: );
7203: my $putresult = &Apache::lonnet::put_dom('configuration',
7204: \%usermodification_hash,$dom);
7205: if ($putresult eq 'ok') {
7206: if (keys(%changes) > 0) {
7207: $resulttext = &mt('Changes made: ').'<ul>';
7208: foreach my $context (@contexts) {
7209: if (ref($changes{$context}) eq 'ARRAY') {
7210: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7211: if (ref($changes{$context}) eq 'ARRAY') {
7212: foreach my $role (@{$changes{$context}}) {
7213: my $rolename;
1.63 raeburn 7214: if ($context eq 'selfcreate') {
7215: $rolename = $role;
7216: if (ref($usertypes) eq 'HASH') {
7217: if ($usertypes->{$role} ne '') {
7218: $rolename = $usertypes->{$role};
7219: }
7220: }
1.33 raeburn 7221: } else {
1.63 raeburn 7222: if ($role eq 'cr') {
7223: $rolename = &mt('Custom');
7224: } else {
7225: $rolename = &Apache::lonnet::plaintext($role);
7226: }
1.33 raeburn 7227: }
7228: my @modifiable;
1.63 raeburn 7229: if ($context eq 'selfcreate') {
1.126 bisitz 7230: $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 7231: } else {
7232: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7233: }
1.33 raeburn 7234: foreach my $field (@fields) {
7235: if ($modifyhash{$context}{$role}{$field}) {
7236: push(@modifiable,$fieldtitles{$field});
7237: }
7238: }
7239: if (@modifiable > 0) {
7240: $resulttext .= join(', ',@modifiable);
7241: } else {
7242: $resulttext .= &mt('none');
7243: }
7244: $resulttext .= '</li>';
7245: }
7246: $resulttext .= '</ul></li>';
7247: }
7248: }
7249: }
7250: $resulttext .= '</ul>';
7251: } else {
7252: $resulttext = &mt('No changes made to user modification settings');
7253: }
7254: } else {
7255: $resulttext = '<span class="LC_error">'.
7256: &mt('An error occurred: [_1]',$putresult).'</span>';
7257: }
7258: return $resulttext;
7259: }
7260:
1.43 raeburn 7261: sub modify_defaults {
7262: my ($dom,$r) = @_;
7263: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7264: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7265: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7266: my @authtypes = ('internal','krb4','krb5','localauth');
7267: foreach my $item (@items) {
7268: $newvalues{$item} = $env{'form.'.$item};
7269: if ($item eq 'auth_def') {
7270: if ($newvalues{$item} ne '') {
7271: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7272: push(@errors,$item);
7273: }
7274: }
7275: } elsif ($item eq 'lang_def') {
7276: if ($newvalues{$item} ne '') {
7277: if ($newvalues{$item} =~ /^(\w+)/) {
7278: my $langcode = $1;
1.103 raeburn 7279: if ($langcode ne 'x_chef') {
7280: if (code2language($langcode) eq '') {
7281: push(@errors,$item);
7282: }
1.43 raeburn 7283: }
7284: } else {
7285: push(@errors,$item);
7286: }
7287: }
1.54 raeburn 7288: } elsif ($item eq 'timezone_def') {
7289: if ($newvalues{$item} ne '') {
1.62 raeburn 7290: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7291: push(@errors,$item);
7292: }
7293: }
1.68 raeburn 7294: } elsif ($item eq 'datelocale_def') {
7295: if ($newvalues{$item} ne '') {
7296: my @datelocale_ids = DateTime::Locale->ids();
7297: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7298: push(@errors,$item);
7299: }
7300: }
1.141 raeburn 7301: } elsif ($item eq 'portal_def') {
7302: if ($newvalues{$item} ne '') {
7303: 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])\/?$/) {
7304: push(@errors,$item);
7305: }
7306: }
1.43 raeburn 7307: }
7308: if (grep(/^\Q$item\E$/,@errors)) {
7309: $newvalues{$item} = $domdefaults{$item};
7310: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7311: $changes{$item} = 1;
7312: }
1.72 raeburn 7313: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7314: }
7315: my %defaults_hash = (
1.72 raeburn 7316: defaults => \%newvalues,
7317: );
1.43 raeburn 7318: my $title = &defaults_titles();
7319: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7320: $dom);
7321: if ($putresult eq 'ok') {
7322: if (keys(%changes) > 0) {
7323: $resulttext = &mt('Changes made:').'<ul>';
7324: my $version = $r->dir_config('lonVersion');
7325: 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";
7326: foreach my $item (sort(keys(%changes))) {
7327: my $value = $env{'form.'.$item};
7328: if ($value eq '') {
7329: $value = &mt('none');
7330: } elsif ($item eq 'auth_def') {
7331: my %authnames = &authtype_names();
7332: my %shortauth = (
7333: internal => 'int',
7334: krb4 => 'krb4',
7335: krb5 => 'krb5',
7336: localauth => 'loc',
7337: );
7338: $value = $authnames{$shortauth{$value}};
7339: }
7340: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7341: $mailmsgtext .= "$title->{$item} set to $value\n";
7342: }
7343: $resulttext .= '</ul>';
7344: $mailmsgtext .= "\n";
7345: my $cachetime = 24*60*60;
1.72 raeburn 7346: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7347: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7348: my $sysmail = $r->dir_config('lonSysEMail');
7349: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7350: }
1.43 raeburn 7351: } else {
1.54 raeburn 7352: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7353: }
7354: } else {
7355: $resulttext = '<span class="LC_error">'.
7356: &mt('An error occurred: [_1]',$putresult).'</span>';
7357: }
7358: if (@errors > 0) {
7359: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7360: foreach my $item (@errors) {
7361: $resulttext .= ' "'.$title->{$item}.'",';
7362: }
7363: $resulttext =~ s/,$//;
7364: }
7365: return $resulttext;
7366: }
7367:
1.46 raeburn 7368: sub modify_scantron {
1.48 raeburn 7369: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7370: my ($resulttext,%confhash,%changes,$errors);
7371: my $custom = 'custom.tab';
7372: my $default = 'default.tab';
7373: my $servadm = $r->dir_config('lonAdmEMail');
7374: my ($configuserok,$author_ok,$switchserver) =
7375: &config_check($dom,$confname,$servadm);
7376: if ($env{'form.scantronformat.filename'} ne '') {
7377: my $error;
7378: if ($configuserok eq 'ok') {
7379: if ($switchserver) {
1.130 raeburn 7380: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7381: } else {
7382: if ($author_ok eq 'ok') {
7383: my ($result,$scantronurl) =
7384: &publishlogo($r,'upload','scantronformat',$dom,
7385: $confname,'scantron','','',$custom);
7386: if ($result eq 'ok') {
7387: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7388: $changes{'scantronformat'} = 1;
1.46 raeburn 7389: } else {
7390: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7391: }
7392: } else {
7393: $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);
7394: }
7395: }
7396: } else {
7397: $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);
7398: }
7399: if ($error) {
7400: &Apache::lonnet::logthis($error);
7401: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7402: }
7403: }
1.48 raeburn 7404: if (ref($domconfig{'scantron'}) eq 'HASH') {
7405: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7406: if ($env{'form.scantronformat_del'}) {
7407: $confhash{'scantron'}{'scantronformat'} = '';
7408: $changes{'scantronformat'} = 1;
1.46 raeburn 7409: }
7410: }
7411: }
7412: if (keys(%confhash) > 0) {
7413: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7414: $dom);
7415: if ($putresult eq 'ok') {
7416: if (keys(%changes) > 0) {
1.48 raeburn 7417: if (ref($confhash{'scantron'}) eq 'HASH') {
7418: $resulttext = &mt('Changes made:').'<ul>';
7419: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7420: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7421: } else {
1.130 raeburn 7422: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7423: }
1.48 raeburn 7424: $resulttext .= '</ul>';
7425: } else {
1.130 raeburn 7426: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7427: }
7428: $resulttext .= '</ul>';
7429: &Apache::loncommon::devalidate_domconfig_cache($dom);
7430: } else {
1.130 raeburn 7431: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7432: }
7433: } else {
7434: $resulttext = '<span class="LC_error">'.
7435: &mt('An error occurred: [_1]',$putresult).'</span>';
7436: }
7437: } else {
1.130 raeburn 7438: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7439: }
7440: if ($errors) {
7441: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7442: $errors.'</ul>';
7443: }
7444: return $resulttext;
7445: }
7446:
1.48 raeburn 7447: sub modify_coursecategories {
7448: my ($dom,%domconfig) = @_;
1.57 raeburn 7449: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7450: $cathash);
1.48 raeburn 7451: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7452: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7453: $cathash = $domconfig{'coursecategories'}{'cats'};
7454: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7455: $changes{'togglecats'} = 1;
7456: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7457: }
7458: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7459: $changes{'categorize'} = 1;
7460: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7461: }
1.120 raeburn 7462: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7463: $changes{'togglecatscomm'} = 1;
7464: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7465: }
7466: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7467: $changes{'categorizecomm'} = 1;
7468: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7469: }
1.57 raeburn 7470: } else {
7471: $changes{'togglecats'} = 1;
7472: $changes{'categorize'} = 1;
1.124 raeburn 7473: $changes{'togglecatscomm'} = 1;
7474: $changes{'categorizecomm'} = 1;
1.87 raeburn 7475: $domconfig{'coursecategories'} = {
7476: togglecats => $env{'form.togglecats'},
7477: categorize => $env{'form.categorize'},
1.124 raeburn 7478: togglecatscomm => $env{'form.togglecatscomm'},
7479: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7480: };
1.57 raeburn 7481: }
7482: if (ref($cathash) eq 'HASH') {
7483: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7484: push (@deletecategory,'instcode::0');
7485: }
1.120 raeburn 7486: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7487: push(@deletecategory,'communities::0');
7488: }
1.48 raeburn 7489: }
1.57 raeburn 7490: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7491: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7492: if (@deletecategory > 0) {
7493: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7494: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7495: foreach my $item (@deletecategory) {
1.57 raeburn 7496: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7497: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7498: $deletions{$item} = 1;
1.57 raeburn 7499: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7500: }
7501: }
7502: }
1.57 raeburn 7503: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7504: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7505: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7506: $reorderings{$item} = 1;
1.57 raeburn 7507: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7508: }
7509: if ($env{'form.addcategory_name_'.$item} ne '') {
7510: my $newcat = $env{'form.addcategory_name_'.$item};
7511: my $newdepth = $depth+1;
7512: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7513: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7514: $adds{$newitem} = 1;
7515: }
7516: if ($env{'form.subcat_'.$item} ne '') {
7517: my $newcat = $env{'form.subcat_'.$item};
7518: my $newdepth = $depth+1;
7519: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7520: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7521: $adds{$newitem} = 1;
7522: }
7523: }
7524: }
7525: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7526: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7527: my $newitem = 'instcode::0';
1.57 raeburn 7528: if ($cathash->{$newitem} eq '') {
7529: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7530: $adds{$newitem} = 1;
7531: }
7532: } else {
7533: my $newitem = 'instcode::0';
1.57 raeburn 7534: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7535: $adds{$newitem} = 1;
7536: }
7537: }
1.120 raeburn 7538: if ($env{'form.communities'} eq '1') {
7539: if (ref($cathash) eq 'HASH') {
7540: my $newitem = 'communities::0';
7541: if ($cathash->{$newitem} eq '') {
7542: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7543: $adds{$newitem} = 1;
7544: }
7545: } else {
7546: my $newitem = 'communities::0';
7547: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7548: $adds{$newitem} = 1;
7549: }
7550: }
1.48 raeburn 7551: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7552: if (($env{'form.addcategory_name'} ne 'instcode') &&
7553: ($env{'form.addcategory_name'} ne 'communities')) {
7554: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7555: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7556: $adds{$newitem} = 1;
7557: }
1.48 raeburn 7558: }
1.57 raeburn 7559: my $putresult;
1.48 raeburn 7560: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7561: if (keys(%deletions) > 0) {
7562: foreach my $key (keys(%deletions)) {
7563: if ($predelallitems{$key} ne '') {
7564: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7565: }
7566: }
7567: }
7568: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7569: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7570: if (ref($chkcats[0]) eq 'ARRAY') {
7571: my $depth = 0;
7572: my $chg = 0;
7573: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7574: my $name = $chkcats[0][$i];
7575: my $item;
7576: if ($name eq '') {
7577: $chg ++;
7578: } else {
7579: $item = &escape($name).'::0';
7580: if ($chg) {
1.57 raeburn 7581: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7582: }
7583: $depth ++;
1.57 raeburn 7584: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7585: $depth --;
7586: }
7587: }
7588: }
1.57 raeburn 7589: }
7590: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7591: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7592: if ($putresult eq 'ok') {
1.57 raeburn 7593: my %title = (
1.120 raeburn 7594: togglecats => 'Show/Hide a course in catalog',
7595: categorize => 'Assign a category to a course',
7596: togglecatscomm => 'Show/Hide a community in catalog',
7597: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7598: );
7599: my %level = (
1.120 raeburn 7600: dom => 'set in Domain ("Modify Course/Community")',
7601: crs => 'set in Course ("Course Configuration")',
7602: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7603: );
1.48 raeburn 7604: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7605: if ($changes{'togglecats'}) {
7606: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7607: }
7608: if ($changes{'categorize'}) {
7609: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7610: }
1.120 raeburn 7611: if ($changes{'togglecatscomm'}) {
7612: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7613: }
7614: if ($changes{'categorizecomm'}) {
7615: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7616: }
1.57 raeburn 7617: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7618: my $cathash;
7619: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7620: $cathash = $domconfig{'coursecategories'}{'cats'};
7621: } else {
7622: $cathash = {};
7623: }
7624: my (@cats,@trails,%allitems);
7625: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7626: if (keys(%deletions) > 0) {
7627: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7628: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7629: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7630: }
7631: $resulttext .= '</ul></li>';
7632: }
7633: if (keys(%reorderings) > 0) {
7634: my %sort_by_trail;
7635: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7636: foreach my $key (keys(%reorderings)) {
7637: if ($allitems{$key} ne '') {
7638: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7639: }
1.48 raeburn 7640: }
1.57 raeburn 7641: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7642: $resulttext .= '<li>'.$trails[$trail].'</li>';
7643: }
7644: $resulttext .= '</ul></li>';
1.48 raeburn 7645: }
1.57 raeburn 7646: if (keys(%adds) > 0) {
7647: my %sort_by_trail;
7648: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7649: foreach my $key (keys(%adds)) {
7650: if ($allitems{$key} ne '') {
7651: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7652: }
7653: }
7654: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7655: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7656: }
1.57 raeburn 7657: $resulttext .= '</ul></li>';
1.48 raeburn 7658: }
7659: }
7660: $resulttext .= '</ul>';
7661: } else {
7662: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7663: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7664: }
7665: } else {
1.120 raeburn 7666: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7667: }
7668: return $resulttext;
7669: }
7670:
1.69 raeburn 7671: sub modify_serverstatuses {
7672: my ($dom,%domconfig) = @_;
7673: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7674: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7675: %currserverstatus = %{$domconfig{'serverstatuses'}};
7676: }
7677: my @pages = &serverstatus_pages();
7678: foreach my $type (@pages) {
7679: $newserverstatus{$type}{'namedusers'} = '';
7680: $newserverstatus{$type}{'machines'} = '';
7681: if (defined($env{'form.'.$type.'_namedusers'})) {
7682: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7683: my @okusers;
7684: foreach my $user (@users) {
7685: my ($uname,$udom) = split(/:/,$user);
7686: if (($udom =~ /^$match_domain$/) &&
7687: (&Apache::lonnet::domain($udom)) &&
7688: ($uname =~ /^$match_username$/)) {
7689: if (!grep(/^\Q$user\E/,@okusers)) {
7690: push(@okusers,$user);
7691: }
7692: }
7693: }
7694: if (@okusers > 0) {
7695: @okusers = sort(@okusers);
7696: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7697: }
7698: }
7699: if (defined($env{'form.'.$type.'_machines'})) {
7700: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7701: my @okmachines;
7702: foreach my $ip (@machines) {
7703: my @parts = split(/\./,$ip);
7704: next if (@parts < 4);
7705: my $badip = 0;
7706: for (my $i=0; $i<4; $i++) {
7707: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7708: $badip = 1;
7709: last;
7710: }
7711: }
7712: if (!$badip) {
7713: push(@okmachines,$ip);
7714: }
7715: }
7716: @okmachines = sort(@okmachines);
7717: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7718: }
7719: }
7720: my %serverstatushash = (
7721: serverstatuses => \%newserverstatus,
7722: );
7723: foreach my $type (@pages) {
1.83 raeburn 7724: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7725: my (@current,@new);
1.83 raeburn 7726: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7727: if ($currserverstatus{$type}{$setting} ne '') {
7728: @current = split(/,/,$currserverstatus{$type}{$setting});
7729: }
7730: }
7731: if ($newserverstatus{$type}{$setting} ne '') {
7732: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7733: }
7734: if (@current > 0) {
7735: if (@new > 0) {
7736: foreach my $item (@current) {
7737: if (!grep(/^\Q$item\E$/,@new)) {
7738: $changes{$type}{$setting} = 1;
1.82 raeburn 7739: last;
7740: }
7741: }
1.84 raeburn 7742: foreach my $item (@new) {
7743: if (!grep(/^\Q$item\E$/,@current)) {
7744: $changes{$type}{$setting} = 1;
7745: last;
1.82 raeburn 7746: }
7747: }
7748: } else {
1.83 raeburn 7749: $changes{$type}{$setting} = 1;
1.69 raeburn 7750: }
1.83 raeburn 7751: } elsif (@new > 0) {
7752: $changes{$type}{$setting} = 1;
1.69 raeburn 7753: }
7754: }
7755: }
7756: if (keys(%changes) > 0) {
1.81 raeburn 7757: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7758: my $putresult = &Apache::lonnet::put_dom('configuration',
7759: \%serverstatushash,$dom);
7760: if ($putresult eq 'ok') {
7761: $resulttext .= &mt('Changes made:').'<ul>';
7762: foreach my $type (@pages) {
1.84 raeburn 7763: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7764: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7765: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7766: if ($newserverstatus{$type}{'namedusers'} eq '') {
7767: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7768: } else {
7769: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7770: }
1.84 raeburn 7771: }
7772: if ($changes{$type}{'machines'}) {
1.69 raeburn 7773: if ($newserverstatus{$type}{'machines'} eq '') {
7774: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7775: } else {
7776: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7777: }
7778:
7779: }
7780: $resulttext .= '</ul></li>';
7781: }
7782: }
7783: $resulttext .= '</ul>';
7784: } else {
7785: $resulttext = '<span class="LC_error">'.
7786: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7787:
7788: }
7789: } else {
7790: $resulttext = &mt('No changes made to access to server status pages');
7791: }
7792: return $resulttext;
7793: }
7794:
1.118 jms 7795: sub modify_helpsettings {
1.122 jms 7796: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7797: my ($resulttext,$errors,%changes,%helphash);
7798: my %defaultchecked = ('submitbugs' => 'on');
7799: my @offon = ('off','on');
1.118 jms 7800: my @toggles = ('submitbugs');
7801: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7802: foreach my $item (@toggles) {
1.166 raeburn 7803: if ($defaultchecked{$item} eq 'on') {
7804: if ($domconfig{'helpsettings'}{$item} eq '') {
7805: if ($env{'form.'.$item} eq '0') {
7806: $changes{$item} = 1;
7807: }
7808: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7809: $changes{$item} = 1;
7810: }
7811: } elsif ($defaultchecked{$item} eq 'off') {
7812: if ($domconfig{'helpsettings'}{$item} eq '') {
7813: if ($env{'form.'.$item} eq '1') {
7814: $changes{$item} = 1;
7815: }
7816: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7817: $changes{$item} = 1;
7818: }
7819: }
7820: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7821: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7822: }
7823: }
1.118 jms 7824: }
1.123 jms 7825: my $putresult;
7826: if (keys(%changes) > 0) {
1.166 raeburn 7827: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7828: if ($putresult eq 'ok') {
1.166 raeburn 7829: $resulttext = &mt('Changes made:').'<ul>';
7830: foreach my $item (sort(keys(%changes))) {
7831: if ($item eq 'submitbugs') {
7832: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7833: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7834: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7835: }
7836: }
7837: $resulttext .= '</ul>';
7838: } else {
7839: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7840: $errors .= '<li><span class="LC_error">'.
7841: &mt('An error occurred storing the settings: [_1]',
7842: $putresult).'</span></li>';
1.166 raeburn 7843: }
1.118 jms 7844: }
7845: if ($errors) {
1.168 raeburn 7846: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7847: $errors.'</ul>';
7848: }
7849: return $resulttext;
7850: }
7851:
1.121 raeburn 7852: sub modify_coursedefaults {
7853: my ($dom,%domconfig) = @_;
7854: my ($resulttext,$errors,%changes,%defaultshash);
7855: my %defaultchecked = ('canuse_pdfforms' => 'off');
7856: my @offon = ('off','on');
7857: my @toggles = ('canuse_pdfforms');
7858:
7859: $defaultshash{'coursedefaults'} = {};
7860:
7861: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7862: if ($domconfig{'coursedefaults'} eq '') {
7863: $domconfig{'coursedefaults'} = {};
7864: }
7865: }
7866:
7867: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7868: foreach my $item (@toggles) {
7869: if ($defaultchecked{$item} eq 'on') {
7870: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7871: ($env{'form.'.$item} eq '0')) {
7872: $changes{$item} = 1;
7873: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7874: $changes{$item} = 1;
7875: }
7876: } elsif ($defaultchecked{$item} eq 'off') {
7877: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7878: ($env{'form.'.$item} eq '1')) {
7879: $changes{$item} = 1;
7880: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7881: $changes{$item} = 1;
7882: }
7883: }
7884: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7885: }
1.139 raeburn 7886: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7887: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7888: $newdefresponder =~ s/\D//g;
7889: if ($newdefresponder eq '' || $newdefresponder < 1) {
7890: $newdefresponder = 1;
7891: }
7892: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7893: if ($currdefresponder ne $newdefresponder) {
7894: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7895: $changes{'anonsurvey_threshold'} = 1;
7896: }
7897: }
1.121 raeburn 7898: }
7899: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7900: $dom);
7901: if ($putresult eq 'ok') {
7902: if (keys(%changes) > 0) {
7903: if ($changes{'canuse_pdfforms'}) {
7904: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7905: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7906: my $cachetime = 24*60*60;
7907: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7908: }
7909: $resulttext = &mt('Changes made:').'<ul>';
7910: foreach my $item (sort(keys(%changes))) {
7911: if ($item eq 'canuse_pdfforms') {
7912: if ($env{'form.'.$item} eq '1') {
7913: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7914: } else {
7915: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7916: }
1.139 raeburn 7917: } elsif ($item eq 'anonsurvey_threshold') {
7918: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7919: }
1.121 raeburn 7920: }
7921: $resulttext .= '</ul>';
7922: } else {
7923: $resulttext = &mt('No changes made to course defaults');
7924: }
7925: } else {
7926: $resulttext = '<span class="LC_error">'.
7927: &mt('An error occurred: [_1]',$putresult).'</span>';
7928: }
7929: return $resulttext;
7930: }
7931:
1.137 raeburn 7932: sub modify_usersessions {
7933: my ($dom,%domconfig) = @_;
1.145 raeburn 7934: my @hostingtypes = ('version','excludedomain','includedomain');
7935: my @offloadtypes = ('primary','default');
7936: my %types = (
7937: remote => \@hostingtypes,
7938: hosted => \@hostingtypes,
7939: spares => \@offloadtypes,
7940: );
7941: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7942: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7943: my (%by_ip,%by_location,@intdoms);
7944: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7945: my @locations = sort(keys(%by_location));
1.137 raeburn 7946: my (%defaultshash,%changes);
7947: foreach my $prefix (@prefixes) {
7948: $defaultshash{'usersessions'}{$prefix} = {};
7949: }
7950: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7951: my $resulttext;
1.138 raeburn 7952: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7953: foreach my $prefix (@prefixes) {
1.145 raeburn 7954: next if ($prefix eq 'spares');
7955: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7956: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7957: if ($type eq 'version') {
7958: my $value = $env{'form.'.$prefix.'_'.$type};
7959: my $okvalue;
7960: if ($value ne '') {
7961: if (grep(/^\Q$value\E$/,@lcversions)) {
7962: $okvalue = $value;
7963: }
7964: }
7965: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7966: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7967: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7968: if ($inuse == 0) {
7969: $changes{$prefix}{$type} = 1;
7970: } else {
7971: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7972: $changes{$prefix}{$type} = 1;
7973: }
7974: if ($okvalue ne '') {
7975: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7976: }
7977: }
7978: } else {
7979: if (($inuse == 1) && ($okvalue ne '')) {
7980: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7981: $changes{$prefix}{$type} = 1;
7982: }
7983: }
7984: } else {
7985: if (($inuse == 1) && ($okvalue ne '')) {
7986: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7987: $changes{$prefix}{$type} = 1;
7988: }
7989: }
7990: } else {
7991: if (($inuse == 1) && ($okvalue ne '')) {
7992: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7993: $changes{$prefix}{$type} = 1;
7994: }
7995: }
7996: } else {
7997: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7998: my @okvals;
7999: foreach my $val (@vals) {
1.138 raeburn 8000: if ($val =~ /:/) {
8001: my @items = split(/:/,$val);
8002: foreach my $item (@items) {
8003: if (ref($by_location{$item}) eq 'ARRAY') {
8004: push(@okvals,$item);
8005: }
8006: }
8007: } else {
8008: if (ref($by_location{$val}) eq 'ARRAY') {
8009: push(@okvals,$val);
8010: }
1.137 raeburn 8011: }
8012: }
8013: @okvals = sort(@okvals);
8014: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8015: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8016: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8017: if ($inuse == 0) {
8018: $changes{$prefix}{$type} = 1;
8019: } else {
8020: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8021: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8022: if (@changed > 0) {
8023: $changes{$prefix}{$type} = 1;
8024: }
8025: }
8026: } else {
8027: if ($inuse == 1) {
8028: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8029: $changes{$prefix}{$type} = 1;
8030: }
8031: }
8032: } else {
8033: if ($inuse == 1) {
8034: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8035: $changes{$prefix}{$type} = 1;
8036: }
8037: }
8038: } else {
8039: if ($inuse == 1) {
8040: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8041: $changes{$prefix}{$type} = 1;
8042: }
8043: }
8044: }
8045: }
8046: }
1.145 raeburn 8047:
8048: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8049: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8050: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8051: my $savespares;
8052:
8053: foreach my $lonhost (sort(keys(%servers))) {
8054: my $serverhomeID =
8055: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8056: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8057: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8058: my %spareschg;
8059: foreach my $type (@{$types{'spares'}}) {
8060: my @okspares;
8061: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8062: foreach my $server (@checked) {
1.152 raeburn 8063: if (&Apache::lonnet::hostname($server) ne '') {
8064: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8065: unless (grep(/^\Q$server\E$/,@okspares)) {
8066: push(@okspares,$server);
8067: }
1.145 raeburn 8068: }
8069: }
8070: }
8071: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8072: my $newspare;
1.152 raeburn 8073: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8074: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8075: $newspare = $new;
8076: }
8077: }
1.152 raeburn 8078: my @spares;
8079: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8080: @spares = sort(@okspares,$newspare);
8081: } else {
8082: @spares = sort(@okspares);
8083: }
8084: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8085: if (ref($spareid{$lonhost}) eq 'HASH') {
8086: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8087: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8088: if (@diffs > 0) {
8089: $spareschg{$type} = 1;
8090: }
8091: }
8092: }
8093: }
8094: if (keys(%spareschg) > 0) {
8095: $changes{'spares'}{$lonhost} = \%spareschg;
8096: }
8097: }
8098:
8099: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8100: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8101: if (ref($changes{'spares'}) eq 'HASH') {
8102: if (keys(%{$changes{'spares'}}) > 0) {
8103: $savespares = 1;
8104: }
8105: }
8106: } else {
8107: $savespares = 1;
8108: }
8109: }
8110:
1.147 raeburn 8111: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8112: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8113: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8114: $dom);
8115: if ($putresult eq 'ok') {
8116: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8117: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8118: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8119: }
8120: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8121: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8122: }
8123: }
8124: my $cachetime = 24*60*60;
8125: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8126: if (keys(%changes) > 0) {
8127: my %lt = &usersession_titles();
8128: $resulttext = &mt('Changes made:').'<ul>';
8129: foreach my $prefix (@prefixes) {
8130: if (ref($changes{$prefix}) eq 'HASH') {
8131: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8132: if ($prefix eq 'spares') {
8133: if (ref($changes{$prefix}) eq 'HASH') {
8134: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8135: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8136: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8137: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8138: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8139: foreach my $type (@{$types{$prefix}}) {
8140: if ($changes{$prefix}{$lonhost}{$type}) {
8141: my $offloadto = &mt('None');
8142: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8143: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8144: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8145: }
1.145 raeburn 8146: }
1.147 raeburn 8147: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8148: }
1.137 raeburn 8149: }
8150: }
1.147 raeburn 8151: $resulttext .= '</li>';
1.137 raeburn 8152: }
8153: }
1.147 raeburn 8154: } else {
8155: foreach my $type (@{$types{$prefix}}) {
8156: if (defined($changes{$prefix}{$type})) {
8157: my $newvalue;
8158: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8159: if (ref($defaultshash{'usersessions'}{$prefix})) {
8160: if ($type eq 'version') {
8161: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8162: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8163: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8164: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8165: }
1.145 raeburn 8166: }
8167: }
8168: }
1.147 raeburn 8169: if ($newvalue eq '') {
8170: if ($type eq 'version') {
8171: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8172: } else {
8173: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8174: }
1.145 raeburn 8175: } else {
1.147 raeburn 8176: if ($type eq 'version') {
8177: $newvalue .= ' '.&mt('(or later)');
8178: }
8179: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8180: }
1.137 raeburn 8181: }
8182: }
8183: }
1.147 raeburn 8184: $resulttext .= '</ul>';
1.137 raeburn 8185: }
8186: }
1.147 raeburn 8187: $resulttext .= '</ul>';
8188: } else {
8189: $resulttext = $nochgmsg;
1.137 raeburn 8190: }
8191: } else {
8192: $resulttext = '<span class="LC_error">'.
8193: &mt('An error occurred: [_1]',$putresult).'</span>';
8194: }
8195: } else {
1.147 raeburn 8196: $resulttext = $nochgmsg;
1.137 raeburn 8197: }
8198: return $resulttext;
8199: }
8200:
1.150 raeburn 8201: sub modify_loadbalancing {
8202: my ($dom,%domconfig) = @_;
8203: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8204: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8205: my ($othertitle,$usertypes,$types) =
8206: &Apache::loncommon::sorted_inst_types($dom);
8207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8208: my @sparestypes = ('primary','default');
8209: my %typetitles = &sparestype_titles();
8210: my $resulttext;
1.171 raeburn 8211: my (%currbalancer,%currtargets,%currrules,%existing);
8212: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8213: %existing = %{$domconfig{'loadbalancing'}};
8214: }
8215: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8216: \%currtargets,\%currrules);
8217: my ($saveloadbalancing,%defaultshash,%changes);
8218: my ($alltypes,$othertypes,$titles) =
8219: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8220: my %ruletitles = &offloadtype_text();
8221: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8222: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8223: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8224: if ($balancer eq '') {
8225: next;
8226: }
8227: if (!exists($servers{$balancer})) {
8228: if (exists($currbalancer{$balancer})) {
8229: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8230: }
1.171 raeburn 8231: next;
8232: }
8233: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8234: push(@{$changes{'delete'}},$balancer);
8235: next;
8236: }
8237: if (!exists($currbalancer{$balancer})) {
8238: push(@{$changes{'add'}},$balancer);
8239: }
8240: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8241: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8242: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8243: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8244: $saveloadbalancing = 1;
8245: }
8246: foreach my $sparetype (@sparestypes) {
8247: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8248: my @offloadto;
8249: foreach my $target (@targets) {
8250: if (($servers{$target}) && ($target ne $balancer)) {
8251: if ($sparetype eq 'default') {
8252: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8253: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8254: }
8255: }
1.171 raeburn 8256: unless(grep(/^\Q$target\E$/,@offloadto)) {
8257: push(@offloadto,$target);
8258: }
1.150 raeburn 8259: }
1.171 raeburn 8260: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8261: }
8262: }
1.171 raeburn 8263: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8264: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8265: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8266: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8267: if (@targetdiffs > 0) {
1.171 raeburn 8268: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8269: }
1.171 raeburn 8270: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8271: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8272: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8273: }
8274: }
8275: }
8276: } else {
1.171 raeburn 8277: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8278: foreach my $sparetype (@sparestypes) {
8279: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8280: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8281: $changes{'curr'}{$balancer}{'targets'} = 1;
8282: }
1.150 raeburn 8283: }
8284: }
8285: }
8286: }
8287: my $ishomedom;
1.171 raeburn 8288: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8289: $ishomedom = 1;
1.150 raeburn 8290: }
8291: if (ref($alltypes) eq 'ARRAY') {
8292: foreach my $type (@{$alltypes}) {
8293: my $rule;
1.171 raeburn 8294: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8295: (!$ishomedom)) {
1.171 raeburn 8296: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8297: }
8298: if ($rule eq 'specific') {
8299: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8300: }
1.171 raeburn 8301: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8302: if (ref($currrules{$balancer}) eq 'HASH') {
8303: if ($rule ne $currrules{$balancer}{$type}) {
8304: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8305: }
8306: } elsif ($rule ne '') {
1.171 raeburn 8307: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8308: }
8309: }
8310: }
1.171 raeburn 8311: }
8312: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8313: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8314: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8315: $defaultshash{'loadbalancing'} = {};
8316: }
8317: my $putresult = &Apache::lonnet::put_dom('configuration',
8318: \%defaultshash,$dom);
8319:
8320: if ($putresult eq 'ok') {
8321: if (keys(%changes) > 0) {
8322: if (ref($changes{'delete'}) eq 'ARRAY') {
8323: foreach my $balancer (sort(@{$changes{'delete'}})) {
8324: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8325: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8326: }
1.171 raeburn 8327: }
8328: if (ref($changes{'add'}) eq 'ARRAY') {
8329: foreach my $balancer (sort(@{$changes{'add'}})) {
8330: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8331: }
8332: }
8333: if (ref($changes{'curr'}) eq 'HASH') {
8334: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8335: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8336: if ($changes{'curr'}{$balancer}{'targets'}) {
8337: my %offloadstr;
8338: foreach my $sparetype (@sparestypes) {
8339: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8340: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8341: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8342: }
8343: }
1.150 raeburn 8344: }
1.171 raeburn 8345: if (keys(%offloadstr) == 0) {
8346: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8347: } else {
1.171 raeburn 8348: my $showoffload;
8349: foreach my $sparetype (@sparestypes) {
8350: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8351: if (defined($offloadstr{$sparetype})) {
8352: $showoffload .= $offloadstr{$sparetype};
8353: } else {
8354: $showoffload .= &mt('None');
8355: }
8356: $showoffload .= (' 'x3);
8357: }
8358: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8359: }
8360: }
8361: }
1.171 raeburn 8362: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8363: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8364: foreach my $type (@{$alltypes}) {
8365: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8366: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8367: my $balancetext;
8368: if ($rule eq '') {
8369: $balancetext = $ruletitles{'default'};
8370: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8371: $balancetext = $ruletitles{$rule};
8372: } else {
8373: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8374: }
8375: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8376: }
8377: }
8378: }
8379: }
1.171 raeburn 8380: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8381: }
1.171 raeburn 8382: }
8383: if ($resulttext ne '') {
8384: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8385: } else {
8386: $resulttext = $nochgmsg;
8387: }
8388: } else {
1.171 raeburn 8389: $resulttext = $nochgmsg;
1.150 raeburn 8390: }
8391: } else {
1.171 raeburn 8392: $resulttext = '<span class="LC_error">'.
8393: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8394: }
8395: } else {
1.171 raeburn 8396: $resulttext = $nochgmsg;
1.150 raeburn 8397: }
8398: return $resulttext;
8399: }
8400:
1.48 raeburn 8401: sub recurse_check {
8402: my ($chkcats,$categories,$depth,$name) = @_;
8403: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8404: my $chg = 0;
8405: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8406: my $category = $chkcats->[$depth]{$name}[$j];
8407: my $item;
8408: if ($category eq '') {
8409: $chg ++;
8410: } else {
8411: my $deeper = $depth + 1;
8412: $item = &escape($category).':'.&escape($name).':'.$depth;
8413: if ($chg) {
8414: $categories->{$item} -= $chg;
8415: }
8416: &recurse_check($chkcats,$categories,$deeper,$category);
8417: $deeper --;
8418: }
8419: }
8420: }
8421: return;
8422: }
8423:
8424: sub recurse_cat_deletes {
8425: my ($item,$coursecategories,$deletions) = @_;
8426: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8427: my $subdepth = $depth + 1;
8428: if (ref($coursecategories) eq 'HASH') {
8429: foreach my $subitem (keys(%{$coursecategories})) {
8430: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8431: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8432: delete($coursecategories->{$subitem});
8433: $deletions->{$subitem} = 1;
8434: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8435: }
1.48 raeburn 8436: }
8437: }
8438: return;
8439: }
8440:
1.125 raeburn 8441: sub get_active_dcs {
8442: my ($dom) = @_;
8443: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8444: my %domcoords;
8445: my $numdcs = 0;
8446: my $now = time;
8447: foreach my $server (keys(%dompersonnel)) {
8448: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8449: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8450: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8451: if (($end eq '') || ($end == 0) || ($end > $now)) {
8452: if ($start <= $now) {
8453: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8454: }
8455: }
8456: }
8457: }
8458: return %domcoords;
8459: }
8460:
8461: sub active_dc_picker {
8462: my ($dom,$curr_dc) = @_;
8463: my %domcoords = &get_active_dcs($dom);
8464: my @dcs = sort(keys(%domcoords));
8465: my $numdcs = scalar(@dcs);
8466: my $datatable;
8467: my $numinrow = 2;
8468: if ($numdcs > 1) {
8469: $datatable = '<table>';
8470: for (my $i=0; $i<@dcs; $i++) {
8471: my $rem = $i%($numinrow);
8472: if ($rem == 0) {
8473: if ($i > 0) {
8474: $datatable .= '</tr>';
8475: }
8476: $datatable .= '<tr>';
8477: }
8478: my $check = ' ';
8479: if ($curr_dc eq '') {
8480: if (!$i) {
8481: $check = ' checked="checked" ';
8482: }
8483: } elsif ($dcs[$i] eq $curr_dc) {
8484: $check = ' checked="checked" ';
8485: }
8486: if ($i == @dcs - 1) {
8487: my $colsleft = $numinrow - $rem;
8488: if ($colsleft > 1) {
8489: $datatable .= '<td colspan="'.$colsleft.'">';
8490: } else {
8491: $datatable .= '<td>';
8492: }
8493: } else {
8494: $datatable .= '<td>';
8495: }
8496: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8497: $datatable .= '<span class="LC_nobreak"><label>'.
8498: '<input type="radio" name="autocreate_xmldc"'.
8499: ' value="'.$dcs[$i].'"'.$check.'/>'.
8500: &Apache::loncommon::plainname($dcname,$dcdom).
1.177 bisitz 8501: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8502: '</label></span></td>';
8503: }
8504: $datatable .= '</tr></table>';
8505: } elsif (@dcs) {
8506: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8507: $dcs[0].'" />';
8508: }
8509: return ($numdcs,$datatable);
8510: }
8511:
1.137 raeburn 8512: sub usersession_titles {
8513: return &Apache::lonlocal::texthash(
8514: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8515: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8516: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8517: version => 'LON-CAPA version requirement',
1.138 raeburn 8518: excludedomain => 'Allow all, but exclude specific domains',
8519: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8520: primary => 'Primary (checked first)',
1.154 raeburn 8521: default => 'Default',
1.137 raeburn 8522: );
8523: }
8524:
1.152 raeburn 8525: sub id_for_thisdom {
8526: my (%servers) = @_;
8527: my %altids;
8528: foreach my $server (keys(%servers)) {
8529: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8530: if ($serverhome ne $server) {
8531: $altids{$serverhome} = $server;
8532: }
8533: }
8534: return %altids;
8535: }
8536:
1.150 raeburn 8537: sub count_servers {
8538: my ($currbalancer,%servers) = @_;
8539: my (@spares,$numspares);
8540: foreach my $lonhost (sort(keys(%servers))) {
8541: next if ($currbalancer eq $lonhost);
8542: push(@spares,$lonhost);
8543: }
8544: if ($currbalancer) {
8545: $numspares = scalar(@spares);
8546: } else {
8547: $numspares = scalar(@spares) - 1;
8548: }
8549: return ($numspares,@spares);
8550: }
8551:
8552: sub lonbalance_targets_js {
1.171 raeburn 8553: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8554: my $select = &mt('Select');
8555: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8556: if (ref($servers) eq 'HASH') {
8557: $alltargets = join("','",sort(keys(%{$servers})));
8558: my @homedoms;
8559: foreach my $server (sort(keys(%{$servers}))) {
8560: if (&Apache::lonnet::host_domain($server) eq $dom) {
8561: push(@homedoms,'1');
8562: } else {
8563: push(@homedoms,'0');
8564: }
8565: }
8566: $allishome = join("','",@homedoms);
8567: }
8568: if (ref($types) eq 'ARRAY') {
8569: if (@{$types} > 0) {
8570: @alltypes = @{$types};
8571: }
8572: }
8573: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8574: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8575: my (%currbalancer,%currtargets,%currrules,%existing);
8576: if (ref($settings) eq 'HASH') {
8577: %existing = %{$settings};
8578: }
8579: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8580: \%currtargets,\%currrules);
8581: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8582: return <<"END";
8583:
8584: <script type="text/javascript">
8585: // <![CDATA[
8586:
1.171 raeburn 8587: currBalancers = new Array('$balancers');
8588:
8589: function toggleTargets(balnum) {
8590: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8591: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8592: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8593: var prevbalancer = prevhostitem.value;
8594: var baltotal = document.getElementById('loadbalancing_total').value;
8595: prevhostitem.value = balancer;
8596: if (prevbalancer != '') {
8597: var prevIdx = currBalancers.indexOf(prevbalancer);
8598: if (prevIdx != -1) {
8599: currBalancers.splice(prevIdx,1);
8600: }
8601: }
1.150 raeburn 8602: if (balancer == '') {
1.171 raeburn 8603: hideSpares(balnum);
1.150 raeburn 8604: } else {
1.171 raeburn 8605: var currIdx = currBalancers.indexOf(balancer);
8606: if (currIdx == -1) {
8607: currBalancers.push(balancer);
8608: }
1.150 raeburn 8609: var homedoms = new Array('$allishome');
1.171 raeburn 8610: var ishomedom = homedoms[lonhostitem.selectedIndex];
8611: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8612: }
1.171 raeburn 8613: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8614: return;
8615: }
8616:
1.171 raeburn 8617: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8618: var alltargets = new Array('$alltargets');
8619: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8620: var offloadtypes = new Array('primary','default');
8621:
1.171 raeburn 8622: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8623: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8624:
1.151 raeburn 8625: for (var i=0; i<offloadtypes.length; i++) {
8626: var count = 0;
8627: for (var j=0; j<alltargets.length; j++) {
8628: if (alltargets[j] != balancer) {
1.171 raeburn 8629: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8630: item.value = alltargets[j];
8631: item.style.textAlign='left';
8632: item.style.textFace='normal';
8633: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8634: if (currBalancers.indexOf(alltargets[j]) == -1) {
8635: item.disabled = '';
8636: } else {
8637: item.disabled = 'disabled';
8638: item.checked = false;
8639: }
1.151 raeburn 8640: count ++;
8641: }
1.150 raeburn 8642: }
8643: }
1.151 raeburn 8644: for (var k=0; k<insttypes.length; k++) {
8645: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8646: if (ishomedom == 1) {
1.171 raeburn 8647: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8648: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8649: } else {
1.171 raeburn 8650: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8651: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8652:
8653: }
8654: } else {
1.171 raeburn 8655: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8656: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8657: }
1.151 raeburn 8658: if ((insttypes[k] != '_LC_external') &&
8659: ((insttypes[k] != '_LC_internetdom') ||
8660: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8661: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8662: item.options.length = 0;
8663: item.options[0] = new Option("","",true,true);
8664: var idx = 0;
1.151 raeburn 8665: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8666: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8667: idx ++;
8668: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8669:
1.150 raeburn 8670: }
8671: }
8672: }
8673: }
8674: return;
8675: }
8676:
1.171 raeburn 8677: function hideSpares(balnum) {
1.150 raeburn 8678: var alltargets = new Array('$alltargets');
8679: var insttypes = new Array('$allinsttypes');
8680: var offloadtypes = new Array('primary','default');
8681:
1.171 raeburn 8682: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8683: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8684:
8685: var total = alltargets.length - 1;
8686: for (var i=0; i<offloadtypes; i++) {
8687: for (var j=0; j<total; j++) {
1.171 raeburn 8688: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8689: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8690: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8691: }
1.150 raeburn 8692: }
8693: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8694: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8695: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8696: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8697: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8698: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8699: }
8700: }
8701: return;
8702: }
8703:
1.171 raeburn 8704: function checkOffloads(item,balnum,type) {
1.150 raeburn 8705: var alltargets = new Array('$alltargets');
8706: var offloadtypes = new Array('primary','default');
8707: if (item.checked) {
8708: var total = alltargets.length - 1;
8709: var other;
8710: if (type == offloadtypes[0]) {
1.151 raeburn 8711: other = offloadtypes[1];
1.150 raeburn 8712: } else {
1.151 raeburn 8713: other = offloadtypes[0];
1.150 raeburn 8714: }
8715: for (var i=0; i<total; i++) {
1.171 raeburn 8716: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8717: if (server == item.value) {
1.171 raeburn 8718: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8719: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8720: }
8721: }
8722: }
8723: }
8724: return;
8725: }
8726:
1.171 raeburn 8727: function singleServerToggle(balnum,type) {
8728: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8729: if (offloadtoSelIdx == 0) {
1.171 raeburn 8730: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8731: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8732:
8733: } else {
1.171 raeburn 8734: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8735: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8736: }
8737: return;
8738: }
8739:
1.171 raeburn 8740: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8741: if (type == '_LC_external') {
1.171 raeburn 8742: return;
1.150 raeburn 8743: }
1.171 raeburn 8744: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8745: for (var i=0; i<typesRules.length; i++) {
8746: if (formname.elements[typesRules[i]].checked) {
8747: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8748: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8749: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8750: } else {
1.171 raeburn 8751: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8752: }
8753: }
8754: }
8755: return;
8756: }
8757:
8758: function balancerDeleteChange(balnum) {
8759: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8760: var baltotal = document.getElementById('loadbalancing_total').value;
8761: var addtarget;
8762: var removetarget;
8763: var action = 'delete';
8764: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8765: var lonhost = hostitem.value;
8766: var currIdx = currBalancers.indexOf(lonhost);
8767: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8768: if (currIdx != -1) {
8769: currBalancers.splice(currIdx,1);
8770: }
8771: addtarget = lonhost;
8772: } else {
8773: if (currIdx == -1) {
8774: currBalancers.push(lonhost);
8775: }
8776: removetarget = lonhost;
8777: action = 'undelete';
8778: }
8779: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8780: }
8781: return;
8782: }
8783:
8784: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8785: if (baltotal > 1) {
8786: var offloadtypes = new Array('primary','default');
8787: var alltargets = new Array('$alltargets');
8788: var insttypes = new Array('$allinsttypes');
8789: for (var i=0; i<baltotal; i++) {
8790: if (i != balnum) {
8791: for (var j=0; j<offloadtypes.length; j++) {
8792: var total = alltargets.length - 1;
8793: for (var k=0; k<total; k++) {
8794: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8795: var server = serveritem.value;
8796: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8797: if (server == addtarget) {
8798: serveritem.disabled = '';
8799: }
8800: }
8801: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8802: if (server == removetarget) {
8803: serveritem.disabled = 'disabled';
8804: serveritem.checked = false;
8805: }
8806: }
8807: }
8808: }
8809: for (var j=0; j<insttypes.length; j++) {
8810: if (insttypes[j] != '_LC_external') {
8811: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8812: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8813: var currSel = singleserver.selectedIndex;
8814: var currVal = singleserver.options[currSel].value;
8815: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8816: var numoptions = singleserver.options.length;
8817: var needsnew = 1;
8818: for (var k=0; k<numoptions; k++) {
8819: if (singleserver.options[k] == addtarget) {
8820: needsnew = 0;
8821: break;
8822: }
8823: }
8824: if (needsnew == 1) {
8825: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8826: }
8827: }
8828: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8829: singleserver.options.length = 0;
8830: if ((currVal) && (currVal != removetarget)) {
8831: singleserver.options[0] = new Option("","",false,false);
8832: } else {
8833: singleserver.options[0] = new Option("","",true,true);
8834: }
8835: var idx = 0;
8836: for (var m=0; m<alltargets.length; m++) {
8837: if (currBalancers.indexOf(alltargets[m]) == -1) {
8838: idx ++;
8839: if (currVal == alltargets[m]) {
8840: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8841: } else {
8842: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8843: }
8844: }
8845: }
8846: }
8847: }
8848: }
8849: }
1.150 raeburn 8850: }
8851: }
8852: }
8853: return;
8854: }
8855:
1.152 raeburn 8856: // ]]>
8857: </script>
8858:
8859: END
8860: }
8861:
8862: sub new_spares_js {
8863: my @sparestypes = ('primary','default');
8864: my $types = join("','",@sparestypes);
8865: my $select = &mt('Select');
8866: return <<"END";
8867:
8868: <script type="text/javascript">
8869: // <![CDATA[
8870:
8871: function updateNewSpares(formname,lonhost) {
8872: var types = new Array('$types');
8873: var include = new Array();
8874: var exclude = new Array();
8875: for (var i=0; i<types.length; i++) {
8876: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8877: for (var j=0; j<spareboxes.length; j++) {
8878: if (formname.elements[spareboxes[j]].checked) {
8879: exclude.push(formname.elements[spareboxes[j]].value);
8880: } else {
8881: include.push(formname.elements[spareboxes[j]].value);
8882: }
8883: }
8884: }
8885: for (var i=0; i<types.length; i++) {
8886: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8887: var selIdx = newSpare.selectedIndex;
8888: var currnew = newSpare.options[selIdx].value;
8889: var okSpares = new Array();
8890: for (var j=0; j<newSpare.options.length; j++) {
8891: var possible = newSpare.options[j].value;
8892: if (possible != '') {
8893: if (exclude.indexOf(possible) == -1) {
8894: okSpares.push(possible);
8895: } else {
8896: if (currnew == possible) {
8897: selIdx = 0;
8898: }
8899: }
8900: }
8901: }
8902: for (var k=0; k<include.length; k++) {
8903: if (okSpares.indexOf(include[k]) == -1) {
8904: okSpares.push(include[k]);
8905: }
8906: }
8907: okSpares.sort();
8908: newSpare.options.length = 0;
8909: if (selIdx == 0) {
8910: newSpare.options[0] = new Option("$select","",true,true);
8911: } else {
8912: newSpare.options[0] = new Option("$select","",false,false);
8913: }
8914: for (var m=0; m<okSpares.length; m++) {
8915: var idx = m+1;
8916: var selThis = 0;
8917: if (selIdx != 0) {
8918: if (okSpares[m] == currnew) {
8919: selThis = 1;
8920: }
8921: }
8922: if (selThis == 1) {
8923: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8924: } else {
8925: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8926: }
8927: }
8928: }
8929: return;
8930: }
8931:
8932: function checkNewSpares(lonhost,type) {
8933: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8934: var chosen = newSpare.options[newSpare.selectedIndex].value;
8935: if (chosen != '') {
8936: var othertype;
8937: var othernewSpare;
8938: if (type == 'primary') {
8939: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8940: }
8941: if (type == 'default') {
8942: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8943: }
8944: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8945: othernewSpare.selectedIndex = 0;
8946: }
8947: }
8948: return;
8949: }
8950:
8951: // ]]>
8952: </script>
8953:
8954: END
8955:
8956: }
8957:
8958: sub common_domprefs_js {
8959: return <<"END";
8960:
8961: <script type="text/javascript">
8962: // <![CDATA[
8963:
1.150 raeburn 8964: function getIndicesByName(formname,item) {
1.152 raeburn 8965: var group = new Array();
1.150 raeburn 8966: for (var i=0;i<formname.elements.length;i++) {
8967: if (formname.elements[i].name == item) {
1.152 raeburn 8968: group.push(formname.elements[i].id);
1.150 raeburn 8969: }
8970: }
1.152 raeburn 8971: return group;
1.150 raeburn 8972: }
8973:
8974: // ]]>
8975: </script>
8976:
8977: END
1.152 raeburn 8978:
1.150 raeburn 8979: }
8980:
1.165 raeburn 8981: sub recaptcha_js {
8982: my %lt = &captcha_phrases();
8983: return <<"END";
8984:
8985: <script type="text/javascript">
8986: // <![CDATA[
8987:
8988: function updateCaptcha(caller,context) {
8989: var privitem;
8990: var pubitem;
8991: var privtext;
8992: var pubtext;
8993: if (document.getElementById(context+'_recaptchapub')) {
8994: pubitem = document.getElementById(context+'_recaptchapub');
8995: } else {
8996: return;
8997: }
8998: if (document.getElementById(context+'_recaptchapriv')) {
8999: privitem = document.getElementById(context+'_recaptchapriv');
9000: } else {
9001: return;
9002: }
9003: if (document.getElementById(context+'_recaptchapubtxt')) {
9004: pubtext = document.getElementById(context+'_recaptchapubtxt');
9005: } else {
9006: return;
9007: }
9008: if (document.getElementById(context+'_recaptchaprivtxt')) {
9009: privtext = document.getElementById(context+'_recaptchaprivtxt');
9010: } else {
9011: return;
9012: }
9013: if (caller.checked) {
9014: if (caller.value == 'recaptcha') {
9015: pubitem.type = 'text';
9016: privitem.type = 'text';
9017: pubitem.size = '40';
9018: privitem.size = '40';
9019: pubtext.innerHTML = "$lt{'pub'}";
9020: privtext.innerHTML = "$lt{'priv'}";
9021: } else {
9022: pubitem.type = 'hidden';
9023: privitem.type = 'hidden';
9024: pubtext.innerHTML = '';
9025: privtext.innerHTML = '';
9026: }
9027: }
9028: return;
9029: }
9030:
9031: // ]]>
9032: </script>
9033:
9034: END
9035:
9036: }
9037:
9038: sub captcha_phrases {
9039: return &Apache::lonlocal::texthash (
9040: priv => 'Private key',
9041: pub => 'Public key',
9042: original => 'original (CAPTCHA)',
9043: recaptcha => 'successor (ReCAPTCHA)',
9044: notused => 'unused',
9045: );
9046: }
9047:
1.3 raeburn 9048: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>