Annotation of loncom/interface/domainprefs.pm, revision 1.187
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.187 ! raeburn 4: # $Id: domainprefs.pm,v 1.186 2013/01/09 21:30:27 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
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 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' =>
1.185 raeburn 389: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 390: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 391: header => [{col1 => 'Balancers',
1.150 raeburn 392: col2 => 'Default destinations',
1.183 bisitz 393: col3 => 'User affiliation',
1.150 raeburn 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:
1.6 raeburn 410: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 411: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 412: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 413: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 414: text=>"Settings to display/modify"});
1.9 raeburn 415: my $confname = $dom.'-domainconfig';
1.174 foxr 416:
1.3 raeburn 417: if ($phase eq 'process') {
1.91 raeburn 418: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 419: } elsif ($phase eq 'display') {
1.165 raeburn 420: my $js = &recaptcha_js();
1.171 raeburn 421: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 422: my ($othertitle,$usertypes,$types) =
423: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 424: $js .= &lonbalance_targets_js($dom,$types,\%servers,
425: $domconfig{'loadbalancing'}).
1.170 raeburn 426: &new_spares_js().
427: &common_domprefs_js().
428: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 429: }
1.150 raeburn 430: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 431: } else {
1.180 raeburn 432: # check if domconfig user exists for the domain.
433: my $servadm = $r->dir_config('lonAdmEMail');
434: my ($configuserok,$author_ok,$switchserver) =
435: &config_check($dom,$confname,$servadm);
436: unless ($configuserok eq 'ok') {
1.181 raeburn 437: &Apache::lonconfigsettings::print_header($r,$phase,$context);
438: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
439: $confname).
440: '<br />'
441: );
1.180 raeburn 442: if ($switchserver) {
1.181 raeburn 443: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
444: '<br />'.
445: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
446: '<br />'.
447: &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).
448: '<br />'.
449: &mt('To do that now, use the following link: [_1]',$switchserver)
450: );
451: } else {
452: $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.').
453: '<br />'.
454: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
455: );
1.180 raeburn 456: }
457: $r->print(&Apache::loncommon::end_page());
458: return OK;
459: }
1.21 raeburn 460: if (keys(%domconfig) == 0) {
461: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 462: my @ids=&Apache::lonnet::current_machine_ids();
463: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 464: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 465: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 466: my $custom_img_count = 0;
467: foreach my $img (@loginimages) {
468: if ($designhash{$dom.'.login.'.$img} ne '') {
469: $custom_img_count ++;
470: }
471: }
472: foreach my $role (@roles) {
473: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
474: $custom_img_count ++;
475: }
476: }
477: if ($custom_img_count > 0) {
1.94 raeburn 478: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 479: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 480: $r->print(
481: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
482: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
483: &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 />'.
484: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
485: if ($switch_server) {
1.30 raeburn 486: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 487: }
1.91 raeburn 488: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 489: return OK;
490: }
491: }
492: }
1.91 raeburn 493: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 494: }
495: return OK;
496: }
497:
498: sub process_changes {
1.92 raeburn 499: my ($r,$dom,$confname,$action,$roles,$values) = @_;
500: my %domconfig;
501: if (ref($values) eq 'HASH') {
502: %domconfig = %{$values};
503: }
1.3 raeburn 504: my $output;
505: if ($action eq 'login') {
1.9 raeburn 506: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 507: } elsif ($action eq 'rolecolors') {
1.9 raeburn 508: $output = &modify_rolecolors($r,$dom,$confname,$roles,
509: %domconfig);
1.3 raeburn 510: } elsif ($action eq 'quotas') {
1.86 raeburn 511: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 512: } elsif ($action eq 'autoenroll') {
513: $output = &modify_autoenroll($dom,%domconfig);
514: } elsif ($action eq 'autoupdate') {
515: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 516: } elsif ($action eq 'autocreate') {
517: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 518: } elsif ($action eq 'directorysrch') {
519: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 520: } elsif ($action eq 'usercreation') {
1.28 raeburn 521: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 522: } elsif ($action eq 'usermodification') {
523: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 524: } elsif ($action eq 'contacts') {
525: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 526: } elsif ($action eq 'defaults') {
527: $output = &modify_defaults($dom,$r);
1.46 raeburn 528: } elsif ($action eq 'scantron') {
1.48 raeburn 529: $output = &modify_scantron($r,$dom,$confname,%domconfig);
530: } elsif ($action eq 'coursecategories') {
531: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 532: } elsif ($action eq 'serverstatuses') {
533: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 534: } elsif ($action eq 'requestcourses') {
535: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 536: } elsif ($action eq 'requestauthor') {
537: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 538: } elsif ($action eq 'helpsettings') {
1.122 jms 539: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 540: } elsif ($action eq 'coursedefaults') {
541: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 542: } elsif ($action eq 'usersessions') {
543: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 544: } elsif ($action eq 'loadbalancing') {
545: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 546: }
547: return $output;
548: }
549:
550: sub print_config_box {
1.9 raeburn 551: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 552: my $rowtotal = 0;
1.49 raeburn 553: my $output;
554: if ($action eq 'coursecategories') {
555: $output = &coursecategories_javascript($settings);
1.91 raeburn 556: }
1.49 raeburn 557: $output .=
1.30 raeburn 558: '<table class="LC_nested_outer">
1.3 raeburn 559: <tr>
1.66 raeburn 560: <th align="left" valign="middle"><span class="LC_nobreak">'.
561: &mt($item->{text}).' '.
562: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
563: '</tr>';
1.30 raeburn 564: $rowtotal ++;
1.110 raeburn 565: my $numheaders = 1;
566: if (ref($item->{'header'}) eq 'ARRAY') {
567: $numheaders = scalar(@{$item->{'header'}});
568: }
569: if ($numheaders > 1) {
1.64 raeburn 570: my $colspan = '';
1.145 raeburn 571: my $rightcolspan = '';
1.168 raeburn 572: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
573: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 574: $colspan = ' colspan="2"';
575: }
1.145 raeburn 576: if ($action eq 'usersessions') {
577: $rightcolspan = ' colspan="3"';
578: }
1.30 raeburn 579: $output .= '
1.3 raeburn 580: <tr>
581: <td>
582: <table class="LC_nested">
583: <tr class="LC_info_row">
1.59 bisitz 584: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 585: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 586: </tr>';
1.69 raeburn 587: $rowtotal ++;
1.6 raeburn 588: if ($action eq 'autoupdate') {
1.30 raeburn 589: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 590: } elsif ($action eq 'usercreation') {
1.33 raeburn 591: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
592: } elsif ($action eq 'usermodification') {
593: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 594: } elsif ($action eq 'coursecategories') {
595: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 596: } elsif ($action eq 'login') {
1.168 raeburn 597: if ($numheaders == 3) {
598: $colspan = ' colspan="2"';
599: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
600: } else {
601: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
602: }
1.102 raeburn 603: } elsif ($action eq 'requestcourses') {
604: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 605: } elsif ($action eq 'requestauthor') {
606: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 607: } elsif ($action eq 'usersessions') {
608: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 609: } elsif ($action eq 'rolecolors') {
1.30 raeburn 610: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 611: } elsif ($action eq 'coursedefaults') {
612: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 613: }
1.30 raeburn 614: $output .= '
1.6 raeburn 615: </table>
616: </td>
617: </tr>
618: <tr>
619: <td>
620: <table class="LC_nested">
621: <tr class="LC_info_row">
1.59 bisitz 622: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 623: $output .= '
1.59 bisitz 624: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 625: </tr>';
626: $rowtotal ++;
1.6 raeburn 627: if ($action eq 'autoupdate') {
1.131 raeburn 628: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
629: </table>
630: </td>
631: </tr>
632: <tr>
633: <td>
634: <table class="LC_nested">
635: <tr class="LC_info_row">
636: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
637: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
638: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
639: $rowtotal ++;
1.28 raeburn 640: } elsif ($action eq 'usercreation') {
1.34 raeburn 641: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
642: </table>
643: </td>
644: </tr>
645: <tr>
646: <td>
647: <table class="LC_nested">
648: <tr class="LC_info_row">
1.59 bisitz 649: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
650: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 651: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
652: $rowtotal ++;
1.33 raeburn 653: } elsif ($action eq 'usermodification') {
1.63 raeburn 654: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
655: </table>
656: </td>
657: </tr>
658: <tr>
659: <td>
660: <table class="LC_nested">
661: <tr class="LC_info_row">
662: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
663: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
664: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
665: $rowtotal ++;
1.57 raeburn 666: } elsif ($action eq 'coursecategories') {
667: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 668: } elsif ($action eq 'login') {
1.168 raeburn 669: if ($numheaders == 3) {
670: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
671: </table>
672: </td>
673: </tr>
674: <tr>
675: <td>
676: <table class="LC_nested">
677: <tr class="LC_info_row">
678: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
679: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
680: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
681: $rowtotal ++;
682: } else {
683: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
684: }
1.102 raeburn 685: } elsif ($action eq 'requestcourses') {
1.163 raeburn 686: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
687: } elsif ($action eq 'requestauthor') {
688: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 689: } elsif ($action eq 'usersessions') {
1.145 raeburn 690: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
691: </table>
692: </td>
693: </tr>
694: <tr>
695: <td>
696: <table class="LC_nested">
697: <tr class="LC_info_row">
698: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
699: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
700: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
701: $rowtotal ++;
1.139 raeburn 702: } elsif ($action eq 'coursedefaults') {
703: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 704: } elsif ($action eq 'rolecolors') {
1.30 raeburn 705: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 706: </table>
707: </td>
708: </tr>
709: <tr>
710: <td>
711: <table class="LC_nested">
712: <tr class="LC_info_row">
1.69 raeburn 713: <td class="LC_left_item"'.$colspan.' valign="top">'.
714: &mt($item->{'header'}->[2]->{'col1'}).'</td>
715: <td class="LC_right_item" valign="top">'.
716: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 717: </tr>'.
1.30 raeburn 718: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 719: </table>
720: </td>
721: </tr>
722: <tr>
723: <td>
724: <table class="LC_nested">
725: <tr class="LC_info_row">
1.59 bisitz 726: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
727: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 728: </tr>'.
1.30 raeburn 729: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
730: $rowtotal += 2;
1.6 raeburn 731: }
1.3 raeburn 732: } else {
1.30 raeburn 733: $output .= '
1.3 raeburn 734: <tr>
735: <td>
736: <table class="LC_nested">
1.30 raeburn 737: <tr class="LC_info_row">';
1.24 raeburn 738: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 739: $output .= '
1.59 bisitz 740: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 741: } elsif ($action eq 'serverstatuses') {
742: $output .= '
743: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
744: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
745:
1.6 raeburn 746: } else {
1.30 raeburn 747: $output .= '
1.69 raeburn 748: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
749: }
1.72 raeburn 750: if (defined($item->{'header'}->[0]->{'col3'})) {
751: $output .= '<td class="LC_left_item" valign="top">'.
752: &mt($item->{'header'}->[0]->{'col2'});
753: if ($action eq 'serverstatuses') {
754: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
755: }
1.69 raeburn 756: } else {
757: $output .= '<td class="LC_right_item" valign="top">'.
758: &mt($item->{'header'}->[0]->{'col2'});
759: }
760: $output .= '</td>';
761: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 762: if (defined($item->{'header'}->[0]->{'col4'})) {
763: $output .= '<td class="LC_left_item" valign="top">'.
764: &mt($item->{'header'}->[0]->{'col3'});
765: } else {
766: $output .= '<td class="LC_right_item" valign="top">'.
767: &mt($item->{'header'}->[0]->{'col3'});
768: }
1.69 raeburn 769: if ($action eq 'serverstatuses') {
770: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
771: }
772: $output .= '</td>';
1.6 raeburn 773: }
1.150 raeburn 774: if ($item->{'header'}->[0]->{'col4'}) {
775: $output .= '<td class="LC_right_item" valign="top">'.
776: &mt($item->{'header'}->[0]->{'col4'});
777: }
1.69 raeburn 778: $output .= '</tr>';
1.48 raeburn 779: $rowtotal ++;
1.168 raeburn 780: if ($action eq 'quotas') {
1.86 raeburn 781: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 782: } elsif ($action eq 'autoenroll') {
1.30 raeburn 783: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 784: } elsif ($action eq 'autocreate') {
785: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 786: } elsif ($action eq 'directorysrch') {
1.30 raeburn 787: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 788: } elsif ($action eq 'contacts') {
1.30 raeburn 789: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 790: } elsif ($action eq 'defaults') {
791: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 792: } elsif ($action eq 'scantron') {
793: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 794: } elsif ($action eq 'serverstatuses') {
795: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 796: } elsif ($action eq 'helpsettings') {
1.168 raeburn 797: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 798: } elsif ($action eq 'loadbalancing') {
799: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 800: }
1.3 raeburn 801: }
1.30 raeburn 802: $output .= '
1.3 raeburn 803: </table>
804: </td>
805: </tr>
1.30 raeburn 806: </table><br />';
807: return ($output,$rowtotal);
1.1 raeburn 808: }
809:
1.3 raeburn 810: sub print_login {
1.168 raeburn 811: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 812: my ($css_class,$datatable);
1.6 raeburn 813: my %choices = &login_choices();
1.110 raeburn 814:
1.168 raeburn 815: if ($caller eq 'service') {
1.149 raeburn 816: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 817: my $choice = $choices{'disallowlogin'};
818: $css_class = ' class="LC_odd_row"';
1.128 raeburn 819: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 820: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 821: '<th>'.$choices{'server'}.'</th>'.
822: '<th>'.$choices{'serverpath'}.'</th>'.
823: '<th>'.$choices{'custompath'}.'</th>'.
824: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 825: my %disallowed;
826: if (ref($settings) eq 'HASH') {
827: if (ref($settings->{'loginvia'}) eq 'HASH') {
828: %disallowed = %{$settings->{'loginvia'}};
829: }
830: }
831: foreach my $lonhost (sort(keys(%servers))) {
832: my $direct = 'selected="selected"';
1.128 raeburn 833: if (ref($disallowed{$lonhost}) eq 'HASH') {
834: if ($disallowed{$lonhost}{'server'} ne '') {
835: $direct = '';
836: }
1.110 raeburn 837: }
1.115 raeburn 838: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 839: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 840: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
841: '</option>';
1.184 raeburn 842: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 843: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 844: my $selected = '';
1.128 raeburn 845: if (ref($disallowed{$lonhost}) eq 'HASH') {
846: if ($hostid eq $disallowed{$lonhost}{'server'}) {
847: $selected = 'selected="selected"';
848: }
1.110 raeburn 849: }
850: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
851: $servers{$hostid}.'</option>';
852: }
1.128 raeburn 853: $datatable .= '</select></td>'.
854: '<td><select name="'.$lonhost.'_serverpath">';
855: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
856: my $pathname = $path;
857: if ($path eq 'custom') {
858: $pathname = &mt('Custom Path').' ->';
859: }
860: my $selected = '';
861: if (ref($disallowed{$lonhost}) eq 'HASH') {
862: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
863: $selected = 'selected="selected"';
864: }
865: } elsif ($path eq '') {
866: $selected = 'selected="selected"';
867: }
868: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
869: }
870: $datatable .= '</select></td>';
871: my ($custom,$exempt);
872: if (ref($disallowed{$lonhost}) eq 'HASH') {
873: $custom = $disallowed{$lonhost}{'custompath'};
874: $exempt = $disallowed{$lonhost}{'exempt'};
875: }
876: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
877: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
878: '</tr>';
1.110 raeburn 879: }
880: $datatable .= '</table></td></tr>';
881: return $datatable;
1.168 raeburn 882: } elsif ($caller eq 'page') {
883: my %defaultchecked = (
884: 'coursecatalog' => 'on',
885: 'adminmail' => 'off',
886: 'newuser' => 'off',
887: );
888: my @toggles = ('coursecatalog','adminmail','newuser');
889: my (%checkedon,%checkedoff);
1.42 raeburn 890: foreach my $item (@toggles) {
1.168 raeburn 891: if ($defaultchecked{$item} eq 'on') {
892: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 893: $checkedoff{$item} = ' ';
1.168 raeburn 894: } elsif ($defaultchecked{$item} eq 'off') {
895: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 896: $checkedon{$item} = ' ';
897: }
1.1 raeburn 898: }
1.168 raeburn 899: my @images = ('img','logo','domlogo','login');
900: my @logintext = ('textcol','bgcol');
901: my @bgs = ('pgbg','mainbg','sidebg');
902: my @links = ('link','alink','vlink');
903: my %designhash = &Apache::loncommon::get_domainconf($dom);
904: my %defaultdesign = %Apache::loncommon::defaultdesign;
905: my (%is_custom,%designs);
906: my %defaults = (
907: font => $defaultdesign{'login.font'},
908: );
1.6 raeburn 909: foreach my $item (@images) {
1.168 raeburn 910: $defaults{$item} = $defaultdesign{'login.'.$item};
911: $defaults{'showlogo'}{$item} = 1;
912: }
913: foreach my $item (@bgs) {
914: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 915: }
1.41 raeburn 916: foreach my $item (@logintext) {
1.168 raeburn 917: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 918: }
1.168 raeburn 919: foreach my $item (@links) {
920: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 921: }
1.168 raeburn 922: if (ref($settings) eq 'HASH') {
923: foreach my $item (@toggles) {
924: if ($settings->{$item} eq '1') {
925: $checkedon{$item} = ' checked="checked" ';
926: $checkedoff{$item} = ' ';
927: } elsif ($settings->{$item} eq '0') {
928: $checkedoff{$item} = ' checked="checked" ';
929: $checkedon{$item} = ' ';
930: }
931: }
932: foreach my $item (@images) {
933: if (defined($settings->{$item})) {
934: $designs{$item} = $settings->{$item};
935: $is_custom{$item} = 1;
936: }
937: if (defined($settings->{'showlogo'}{$item})) {
938: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
939: }
940: }
941: foreach my $item (@logintext) {
942: if ($settings->{$item} ne '') {
943: $designs{'logintext'}{$item} = $settings->{$item};
944: $is_custom{$item} = 1;
945: }
946: }
947: if ($settings->{'font'} ne '') {
948: $designs{'font'} = $settings->{'font'};
949: $is_custom{'font'} = 1;
950: }
951: foreach my $item (@bgs) {
952: if ($settings->{$item} ne '') {
953: $designs{'bgs'}{$item} = $settings->{$item};
954: $is_custom{$item} = 1;
955: }
956: }
957: foreach my $item (@links) {
958: if ($settings->{$item} ne '') {
959: $designs{'links'}{$item} = $settings->{$item};
960: $is_custom{$item} = 1;
961: }
962: }
963: } else {
964: if ($designhash{$dom.'.login.font'} ne '') {
965: $designs{'font'} = $designhash{$dom.'.login.font'};
966: $is_custom{'font'} = 1;
967: }
968: foreach my $item (@images) {
969: if ($designhash{$dom.'.login.'.$item} ne '') {
970: $designs{$item} = $designhash{$dom.'.login.'.$item};
971: $is_custom{$item} = 1;
972: }
973: }
974: foreach my $item (@bgs) {
975: if ($designhash{$dom.'.login.'.$item} ne '') {
976: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
977: $is_custom{$item} = 1;
978: }
1.6 raeburn 979: }
1.168 raeburn 980: foreach my $item (@links) {
981: if ($designhash{$dom.'.login.'.$item} ne '') {
982: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
983: $is_custom{$item} = 1;
984: }
1.6 raeburn 985: }
986: }
1.168 raeburn 987: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
988: logo => 'Institution Logo',
989: domlogo => 'Domain Logo',
990: login => 'Login box');
991: my $itemcount = 1;
992: foreach my $item (@toggles) {
993: $css_class = $itemcount%2?' class="LC_odd_row"':'';
994: $datatable .=
995: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
996: '</td><td>'.
997: '<span class="LC_nobreak"><label><input type="radio" name="'.
998: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
999: '</label> <label><input type="radio" name="'.$item.'"'.
1000: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1001: '</tr>';
1002: $itemcount ++;
1.6 raeburn 1003: }
1.168 raeburn 1004: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1005: $datatable .= '</tr></table></td></tr>';
1006: } elsif ($caller eq 'help') {
1007: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1008: my $switchserver = &check_switchserver($dom,$confname);
1009: my $itemcount = 1;
1010: $defaulturl = '/adm/loginproblems.html';
1011: $defaulttype = 'default';
1012: %lt = &Apache::lonlocal::texthash (
1013: del => 'Delete?',
1014: rep => 'Replace:',
1015: upl => 'Upload:',
1016: default => 'Default',
1017: custom => 'Custom',
1018: );
1019: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1020: my @currlangs;
1021: if (ref($settings) eq 'HASH') {
1022: if (ref($settings->{'helpurl'}) eq 'HASH') {
1023: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1024: next if ($settings->{'helpurl'}{$key} eq '');
1025: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1026: $type{$key} = 'custom';
1027: unless ($key eq 'nolang') {
1028: push(@currlangs,$key);
1029: }
1030: }
1031: } elsif ($settings->{'helpurl'} ne '') {
1032: $type{'nolang'} = 'custom';
1033: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1034: }
1035: }
1.168 raeburn 1036: foreach my $lang ('nolang',sort(@currlangs)) {
1037: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1038: $datatable .= '<tr'.$css_class.'>';
1039: if ($url{$lang} eq '') {
1040: $url{$lang} = $defaulturl;
1041: }
1042: if ($type{$lang} eq '') {
1043: $type{$lang} = $defaulttype;
1044: }
1045: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1046: if ($lang eq 'nolang') {
1047: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1048: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1049: } else {
1050: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1051: $langchoices{$lang},
1052: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1053: }
1054: $datatable .= '</span></td>'."\n".
1055: '<td class="LC_left_item">';
1056: if ($type{$lang} eq 'custom') {
1057: $datatable .= '<span class="LC_nobreak"><label>'.
1058: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1059: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1060: } else {
1061: $datatable .= $lt{'upl'};
1062: }
1063: $datatable .='<br />';
1064: if ($switchserver) {
1065: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1066: } else {
1067: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1068: }
1.168 raeburn 1069: $datatable .= '</td></tr>';
1070: $itemcount ++;
1.6 raeburn 1071: }
1.168 raeburn 1072: my @addlangs;
1073: foreach my $lang (sort(keys(%langchoices))) {
1074: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1075: push(@addlangs,$lang);
1076: }
1077: if (@addlangs > 0) {
1078: my %toadd;
1079: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1080: $toadd{''} = &mt('Select');
1081: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1082: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1083: &mt('Add log-in help page for a specific language:').' '.
1084: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1085: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1086: if ($switchserver) {
1087: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1088: } else {
1089: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1090: }
1.168 raeburn 1091: $datatable .= '</td></tr>';
1.169 raeburn 1092: $itemcount ++;
1.6 raeburn 1093: }
1.169 raeburn 1094: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1095: }
1.6 raeburn 1096: return $datatable;
1097: }
1098:
1099: sub login_choices {
1100: my %choices =
1101: &Apache::lonlocal::texthash (
1.116 bisitz 1102: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1103: adminmail => "Display Administrator's E-mail Address?",
1104: disallowlogin => "Login page requests redirected",
1105: hostid => "Server",
1.128 raeburn 1106: server => "Redirect to:",
1107: serverpath => "Path",
1108: custompath => "Custom",
1109: exempt => "Exempt IP(s)",
1.110 raeburn 1110: directlogin => "No redirect",
1111: newuser => "Link to create a user account",
1112: img => "Header",
1113: logo => "Main Logo",
1114: domlogo => "Domain Logo",
1115: login => "Log-in Header",
1116: textcol => "Text color",
1117: bgcol => "Box color",
1118: bgs => "Background colors",
1119: links => "Link colors",
1120: font => "Font color",
1121: pgbg => "Header",
1122: mainbg => "Page",
1123: sidebg => "Login box",
1124: link => "Link",
1125: alink => "Active link",
1126: vlink => "Visited link",
1.6 raeburn 1127: );
1128: return %choices;
1129: }
1130:
1131: sub print_rolecolors {
1.30 raeburn 1132: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1133: my %choices = &color_font_choices();
1134: my @bgs = ('pgbg','tabbg','sidebg');
1135: my @links = ('link','alink','vlink');
1136: my @images = ('img');
1137: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1138: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1139: my %defaultdesign = %Apache::loncommon::defaultdesign;
1140: my (%is_custom,%designs);
1141: my %defaults = (
1142: img => $defaultdesign{$role.'.img'},
1143: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1144: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1145: );
1146: foreach my $item (@bgs) {
1147: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1148: }
1149: foreach my $item (@links) {
1150: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1151: }
1152: if (ref($settings) eq 'HASH') {
1153: if (ref($settings->{$role}) eq 'HASH') {
1154: if ($settings->{$role}->{'img'} ne '') {
1155: $designs{'img'} = $settings->{$role}->{'img'};
1156: $is_custom{'img'} = 1;
1157: }
1158: if ($settings->{$role}->{'font'} ne '') {
1159: $designs{'font'} = $settings->{$role}->{'font'};
1160: $is_custom{'font'} = 1;
1161: }
1.97 tempelho 1162: if ($settings->{$role}->{'fontmenu'} ne '') {
1163: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1164: $is_custom{'fontmenu'} = 1;
1165: }
1.6 raeburn 1166: foreach my $item (@bgs) {
1167: if ($settings->{$role}->{$item} ne '') {
1168: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1169: $is_custom{$item} = 1;
1170: }
1171: }
1172: foreach my $item (@links) {
1173: if ($settings->{$role}->{$item} ne '') {
1174: $designs{'links'}{$item} = $settings->{$role}->{$item};
1175: $is_custom{$item} = 1;
1176: }
1177: }
1178: }
1179: } else {
1180: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1181: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1182: $is_custom{'img'} = 1;
1183: }
1.97 tempelho 1184: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1185: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1186: $is_custom{'fontmenu'} = 1;
1187: }
1.6 raeburn 1188: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1189: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1190: $is_custom{'font'} = 1;
1191: }
1192: foreach my $item (@bgs) {
1193: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1194: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1195: $is_custom{$item} = 1;
1196:
1197: }
1198: }
1199: foreach my $item (@links) {
1200: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1201: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1202: $is_custom{$item} = 1;
1203: }
1204: }
1205: }
1206: my $itemcount = 1;
1.30 raeburn 1207: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1208: $datatable .= '</tr></table></td></tr>';
1209: return $datatable;
1210: }
1211:
1212: sub display_color_options {
1.9 raeburn 1213: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1214: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1215: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1216: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1217: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1218: '<td>'.$choices->{'font'}.'</td>';
1219: if (!$is_custom->{'font'}) {
1.30 raeburn 1220: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1221: } else {
1222: $datatable .= '<td> </td>';
1223: }
1.174 foxr 1224: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1225:
1.8 raeburn 1226: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1227: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1228: ' value="'.$current_color.'" /> '.
1229: ' </td></tr>';
1.107 raeburn 1230: unless ($role eq 'login') {
1231: $datatable .= '<tr'.$css_class.'>'.
1232: '<td>'.$choices->{'fontmenu'}.'</td>';
1233: if (!$is_custom->{'fontmenu'}) {
1234: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1235: } else {
1236: $datatable .= '<td> </td>';
1237: }
1.174 foxr 1238: $current_color = $designs->{'fontmenu'} ?
1239: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1240: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1241: '<input class="colorchooser" type="text" size="10" name="'
1242: .$role.'_fontmenu"'.
1243: ' value="'.$current_color.'" /> '.
1244: ' </td></tr>';
1.97 tempelho 1245: }
1.9 raeburn 1246: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1247: foreach my $img (@{$images}) {
1.18 albertel 1248: $itemcount ++;
1.6 raeburn 1249: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1250: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1251: '<td>'.$choices->{$img};
1.41 raeburn 1252: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1253: if ($role eq 'login') {
1254: if ($img eq 'login') {
1255: $login_hdr_pick =
1.135 bisitz 1256: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1257: $logincolors =
1258: &login_text_colors($img,$role,$logintext,$phase,$choices,
1259: $designs);
1260: } elsif ($img ne 'domlogo') {
1261: $datatable.= &logo_display_options($img,$defaults,$designs);
1262: }
1263: }
1264: $datatable .= '</td>';
1.6 raeburn 1265: if ($designs->{$img} ne '') {
1266: $imgfile = $designs->{$img};
1.18 albertel 1267: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1268: } else {
1269: $imgfile = $defaults->{$img};
1270: }
1271: if ($imgfile) {
1.9 raeburn 1272: my ($showfile,$fullsize);
1273: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1274: my $urldir = $1;
1275: my $filename = $2;
1276: my @info = &Apache::lonnet::stat_file($designs->{$img});
1277: if (@info) {
1278: my $thumbfile = 'tn-'.$filename;
1279: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1280: if (@thumb) {
1281: $showfile = $urldir.'/'.$thumbfile;
1282: } else {
1283: $showfile = $imgfile;
1284: }
1285: } else {
1286: $showfile = '';
1287: }
1288: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1289: $showfile = $imgfile;
1.6 raeburn 1290: my $imgdir = $1;
1291: my $filename = $2;
1.159 raeburn 1292: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1293: $showfile = "/$imgdir/tn-".$filename;
1294: } else {
1.159 raeburn 1295: my $input = $londocroot.$imgfile;
1296: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1297: if (!-e $output) {
1.9 raeburn 1298: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1299: my ($fullwidth,$fullheight) = &check_dimensions($input);
1300: if ($fullwidth ne '' && $fullheight ne '') {
1301: if ($fullwidth > $width && $fullheight > $height) {
1302: my $size = $width.'x'.$height;
1303: system("convert -sample $size $input $output");
1.159 raeburn 1304: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1305: }
1306: }
1.6 raeburn 1307: }
1308: }
1.16 raeburn 1309: }
1.6 raeburn 1310: if ($showfile) {
1.40 raeburn 1311: if ($showfile =~ m{^/(adm|res)/}) {
1312: if ($showfile =~ m{^/res/}) {
1313: my $local_showfile =
1314: &Apache::lonnet::filelocation('',$showfile);
1315: &Apache::lonnet::repcopy($local_showfile);
1316: }
1317: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1318: }
1319: if ($imgfile) {
1320: if ($imgfile =~ m{^/(adm|res)/}) {
1321: if ($imgfile =~ m{^/res/}) {
1322: my $local_imgfile =
1323: &Apache::lonnet::filelocation('',$imgfile);
1324: &Apache::lonnet::repcopy($local_imgfile);
1325: }
1326: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1327: } else {
1328: $fullsize = $imgfile;
1329: }
1330: }
1.41 raeburn 1331: $datatable .= '<td>';
1332: if ($img eq 'login') {
1.135 bisitz 1333: $datatable .= $login_hdr_pick;
1334: }
1.41 raeburn 1335: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1336: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1337: } else {
1338: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1339: &mt('Upload:');
1340: }
1341: } else {
1342: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1343: &mt('Upload:');
1344: }
1.9 raeburn 1345: if ($switchserver) {
1346: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1347: } else {
1.135 bisitz 1348: if ($img ne 'login') { # suppress file selection for Log-in header
1349: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1350: }
1.9 raeburn 1351: }
1352: $datatable .= '</td></tr>';
1.6 raeburn 1353: }
1354: $itemcount ++;
1355: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1356: $datatable .= '<tr'.$css_class.'>'.
1357: '<td>'.$choices->{'bgs'}.'</td>';
1358: my $bgs_def;
1359: foreach my $item (@{$bgs}) {
1360: if (!$is_custom->{$item}) {
1.70 raeburn 1361: $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 1362: }
1363: }
1364: if ($bgs_def) {
1.8 raeburn 1365: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1366: } else {
1367: $datatable .= '<td> </td>';
1368: }
1369: $datatable .= '<td class="LC_right_item">'.
1370: '<table border="0"><tr>';
1.174 foxr 1371:
1.6 raeburn 1372: foreach my $item (@{$bgs}) {
1.174 foxr 1373: $datatable .= '<td align="center">';
1374: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1375: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1376: $datatable .= ' ';
1.6 raeburn 1377: }
1.174 foxr 1378: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1379: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1380: }
1381: $datatable .= '</tr></table></td></tr>';
1382: $itemcount ++;
1383: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1384: $datatable .= '<tr'.$css_class.'>'.
1385: '<td>'.$choices->{'links'}.'</td>';
1386: my $links_def;
1387: foreach my $item (@{$links}) {
1388: if (!$is_custom->{$item}) {
1.30 raeburn 1389: $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 1390: }
1391: }
1392: if ($links_def) {
1.8 raeburn 1393: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1394: } else {
1395: $datatable .= '<td> </td>';
1396: }
1397: $datatable .= '<td class="LC_right_item">'.
1398: '<table border="0"><tr>';
1399: foreach my $item (@{$links}) {
1.174 foxr 1400: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1401: $datatable .= '<td align="center">'."\n";
1402:
1.6 raeburn 1403: if ($designs->{'links'}{$item}) {
1.174 foxr 1404: $datatable.=' ';
1.6 raeburn 1405: }
1.174 foxr 1406: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1407: '" /></td>';
1408: }
1.30 raeburn 1409: $$rowtotal += $itemcount;
1.3 raeburn 1410: return $datatable;
1411: }
1412:
1.70 raeburn 1413: sub logo_display_options {
1414: my ($img,$defaults,$designs) = @_;
1415: my $checkedon;
1416: if (ref($defaults) eq 'HASH') {
1417: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1418: if ($defaults->{'showlogo'}{$img}) {
1419: $checkedon = 'checked="checked" ';
1420: }
1421: }
1422: }
1423: if (ref($designs) eq 'HASH') {
1424: if (ref($designs->{'showlogo'}) eq 'HASH') {
1425: if (defined($designs->{'showlogo'}{$img})) {
1426: if ($designs->{'showlogo'}{$img} == 0) {
1427: $checkedon = '';
1428: } elsif ($designs->{'showlogo'}{$img} == 1) {
1429: $checkedon = 'checked="checked" ';
1430: }
1431: }
1432: }
1433: }
1434: return '<br /><label> <input type="checkbox" name="'.
1435: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1436: &mt('show').'</label>'."\n";
1437: }
1438:
1.41 raeburn 1439: sub login_header_options {
1.135 bisitz 1440: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1441: my $output = '';
1.41 raeburn 1442: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1443: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1444: if (!$is_custom->{'textcol'}) {
1445: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1446: ' ';
1447: }
1448: if (!$is_custom->{'bgcol'}) {
1449: $output .= $choices->{'bgcol'}.': '.
1450: '<span id="css_'.$role.'_font" style="background-color: '.
1451: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1452: }
1453: $output .= '<br />';
1454: }
1455: $output .='<br />';
1456: return $output;
1457: }
1458:
1459: sub login_text_colors {
1460: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1461: my $color_menu = '<table border="0"><tr>';
1462: foreach my $item (@{$logintext}) {
1463: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1464: $color_menu .= '<td align="center">'.$link;
1465: if ($designs->{'logintext'}{$item}) {
1466: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1467: }
1468: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1469: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1470: '<td> </td>';
1471: }
1472: $color_menu .= '</tr></table><br />';
1473: return $color_menu;
1474: }
1475:
1476: sub image_changes {
1477: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1478: my $output;
1.135 bisitz 1479: if ($img eq 'login') {
1480: # suppress image for Log-in header
1481: } elsif (!$is_custom) {
1.70 raeburn 1482: if ($img ne 'domlogo') {
1.41 raeburn 1483: $output .= &mt('Default image:').'<br />';
1484: } else {
1485: $output .= &mt('Default in use:').'<br />';
1486: }
1487: }
1.135 bisitz 1488: if ($img eq 'login') { # suppress image for Log-in header
1489: $output .= '<td>'.$logincolors;
1.41 raeburn 1490: } else {
1.135 bisitz 1491: if ($img_import) {
1492: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1493: }
1494: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1495: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1496: if ($is_custom) {
1497: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1498: '<input type="checkbox" name="'.
1499: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1500: '</label> '.&mt('Replace:').'</span><br />';
1501: } else {
1502: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1503: }
1.41 raeburn 1504: }
1505: return $output;
1506: }
1507:
1.6 raeburn 1508: sub color_pick {
1509: my ($phase,$role,$item,$desc,$curcol) = @_;
1510: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1511: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1512: ');">'.$desc.'</a>';
1513: return $link;
1514: }
1515:
1.3 raeburn 1516: sub print_quotas {
1.86 raeburn 1517: my ($dom,$settings,$rowtotal,$action) = @_;
1518: my $context;
1519: if ($action eq 'quotas') {
1520: $context = 'tools';
1521: } else {
1522: $context = $action;
1523: }
1.101 raeburn 1524: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1525: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1526: my $typecount = 0;
1.101 raeburn 1527: my ($css_class,%titles);
1.86 raeburn 1528: if ($context eq 'requestcourses') {
1.98 raeburn 1529: @usertools = ('official','unofficial','community');
1.106 raeburn 1530: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1531: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1532: %titles = &courserequest_titles();
1.163 raeburn 1533: } elsif ($context eq 'requestauthor') {
1534: @usertools = ('author');
1535: @options = ('norequest','approval','automatic');
1536: %titles = &authorrequest_titles();
1.86 raeburn 1537: } else {
1.162 raeburn 1538: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1539: %titles = &tool_titles();
1.86 raeburn 1540: }
1.26 raeburn 1541: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1542: foreach my $type (@{$types}) {
1.72 raeburn 1543: my $currdefquota;
1.163 raeburn 1544: unless (($context eq 'requestcourses') ||
1545: ($context eq 'requestauthor')) {
1.86 raeburn 1546: if (ref($settings) eq 'HASH') {
1547: if (ref($settings->{defaultquota}) eq 'HASH') {
1548: $currdefquota = $settings->{defaultquota}->{$type};
1549: } else {
1550: $currdefquota = $settings->{$type};
1551: }
1.78 raeburn 1552: }
1.72 raeburn 1553: }
1.3 raeburn 1554: if (defined($usertypes->{$type})) {
1555: $typecount ++;
1556: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1557: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1558: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1559: '<td class="LC_left_item">';
1.101 raeburn 1560: if ($context eq 'requestcourses') {
1561: $datatable .= '<table><tr>';
1562: }
1563: my %cell;
1.72 raeburn 1564: foreach my $item (@usertools) {
1.101 raeburn 1565: if ($context eq 'requestcourses') {
1566: my ($curroption,$currlimit);
1567: if (ref($settings) eq 'HASH') {
1568: if (ref($settings->{$item}) eq 'HASH') {
1569: $curroption = $settings->{$item}->{$type};
1570: if ($curroption =~ /^autolimit=(\d*)$/) {
1571: $currlimit = $1;
1572: }
1573: }
1574: }
1575: if (!$curroption) {
1576: $curroption = 'norequest';
1577: }
1578: $datatable .= '<th>'.$titles{$item}.'</th>';
1579: foreach my $option (@options) {
1580: my $val = $option;
1581: if ($option eq 'norequest') {
1582: $val = 0;
1583: }
1584: if ($option eq 'validate') {
1585: my $canvalidate = 0;
1586: if (ref($validations{$item}) eq 'HASH') {
1587: if ($validations{$item}{$type}) {
1588: $canvalidate = 1;
1589: }
1590: }
1591: next if (!$canvalidate);
1592: }
1593: my $checked = '';
1594: if ($option eq $curroption) {
1595: $checked = ' checked="checked"';
1596: } elsif ($option eq 'autolimit') {
1597: if ($curroption =~ /^autolimit/) {
1598: $checked = ' checked="checked"';
1599: }
1600: }
1601: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1602: '<input type="radio" name="crsreq_'.$item.
1603: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1604: $titles{$option}.'</label>';
1.101 raeburn 1605: if ($option eq 'autolimit') {
1.127 raeburn 1606: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1607: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1608: 'value="'.$currlimit.'" />';
1.101 raeburn 1609: }
1.127 raeburn 1610: $cell{$item} .= '</span> ';
1.103 raeburn 1611: if ($option eq 'autolimit') {
1.127 raeburn 1612: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1613: }
1.101 raeburn 1614: }
1.163 raeburn 1615: } elsif ($context eq 'requestauthor') {
1616: my $curroption;
1617: if (ref($settings) eq 'HASH') {
1618: $curroption = $settings->{$type};
1619: }
1620: if (!$curroption) {
1621: $curroption = 'norequest';
1622: }
1623: foreach my $option (@options) {
1624: my $val = $option;
1625: if ($option eq 'norequest') {
1626: $val = 0;
1627: }
1628: my $checked = '';
1629: if ($option eq $curroption) {
1630: $checked = ' checked="checked"';
1631: }
1632: $datatable .= '<span class="LC_nobreak"><label>'.
1633: '<input type="radio" name="authorreq_'.$type.
1634: '" value="'.$val.'"'.$checked.' />'.
1635: $titles{$option}.'</label></span> ';
1636: }
1.101 raeburn 1637: } else {
1638: my $checked = 'checked="checked" ';
1639: if (ref($settings) eq 'HASH') {
1640: if (ref($settings->{$item}) eq 'HASH') {
1641: if ($settings->{$item}->{$type} == 0) {
1642: $checked = '';
1643: } elsif ($settings->{$item}->{$type} == 1) {
1644: $checked = 'checked="checked" ';
1645: }
1.78 raeburn 1646: }
1.72 raeburn 1647: }
1.101 raeburn 1648: $datatable .= '<span class="LC_nobreak"><label>'.
1649: '<input type="checkbox" name="'.$context.'_'.$item.
1650: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1651: '</label></span> ';
1.72 raeburn 1652: }
1.101 raeburn 1653: }
1654: if ($context eq 'requestcourses') {
1655: $datatable .= '</tr><tr>';
1656: foreach my $item (@usertools) {
1.106 raeburn 1657: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1658: }
1659: $datatable .= '</tr></table>';
1.72 raeburn 1660: }
1.86 raeburn 1661: $datatable .= '</td>';
1.163 raeburn 1662: unless (($context eq 'requestcourses') ||
1663: ($context eq 'requestauthor')) {
1.86 raeburn 1664: $datatable .=
1665: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1666: '<input type="text" name="quota_'.$type.
1.72 raeburn 1667: '" value="'.$currdefquota.
1.86 raeburn 1668: '" size="5" /> Mb</span></td>';
1669: }
1670: $datatable .= '</tr>';
1.3 raeburn 1671: }
1672: }
1673: }
1.163 raeburn 1674: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1675: $defaultquota = '20';
1676: if (ref($settings) eq 'HASH') {
1677: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1678: $defaultquota = $settings->{'defaultquota'}->{'default'};
1679: } elsif (defined($settings->{'default'})) {
1680: $defaultquota = $settings->{'default'};
1681: }
1.3 raeburn 1682: }
1683: }
1684: $typecount ++;
1685: $css_class = $typecount%2?' class="LC_odd_row"':'';
1686: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1687: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1688: '<td class="LC_left_item">';
1.101 raeburn 1689: if ($context eq 'requestcourses') {
1690: $datatable .= '<table><tr>';
1691: }
1692: my %defcell;
1.72 raeburn 1693: foreach my $item (@usertools) {
1.101 raeburn 1694: if ($context eq 'requestcourses') {
1695: my ($curroption,$currlimit);
1696: if (ref($settings) eq 'HASH') {
1697: if (ref($settings->{$item}) eq 'HASH') {
1698: $curroption = $settings->{$item}->{'default'};
1699: if ($curroption =~ /^autolimit=(\d*)$/) {
1700: $currlimit = $1;
1701: }
1702: }
1703: }
1704: if (!$curroption) {
1705: $curroption = 'norequest';
1706: }
1707: $datatable .= '<th>'.$titles{$item}.'</th>';
1708: foreach my $option (@options) {
1709: my $val = $option;
1710: if ($option eq 'norequest') {
1711: $val = 0;
1712: }
1713: if ($option eq 'validate') {
1714: my $canvalidate = 0;
1715: if (ref($validations{$item}) eq 'HASH') {
1716: if ($validations{$item}{'default'}) {
1717: $canvalidate = 1;
1718: }
1719: }
1720: next if (!$canvalidate);
1721: }
1722: my $checked = '';
1723: if ($option eq $curroption) {
1724: $checked = ' checked="checked"';
1725: } elsif ($option eq 'autolimit') {
1726: if ($curroption =~ /^autolimit/) {
1727: $checked = ' checked="checked"';
1728: }
1729: }
1730: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1731: '<input type="radio" name="crsreq_'.$item.
1732: '_default" value="'.$val.'"'.$checked.' />'.
1733: $titles{$option}.'</label>';
1734: if ($option eq 'autolimit') {
1.127 raeburn 1735: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1736: $item.'_limit_default" size="1" '.
1737: 'value="'.$currlimit.'" />';
1738: }
1.127 raeburn 1739: $defcell{$item} .= '</span> ';
1.104 raeburn 1740: if ($option eq 'autolimit') {
1.127 raeburn 1741: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1742: }
1.101 raeburn 1743: }
1.163 raeburn 1744: } elsif ($context eq 'requestauthor') {
1745: my $curroption;
1746: if (ref($settings) eq 'HASH') {
1.172 raeburn 1747: $curroption = $settings->{'default'};
1.163 raeburn 1748: }
1749: if (!$curroption) {
1750: $curroption = 'norequest';
1751: }
1752: foreach my $option (@options) {
1753: my $val = $option;
1754: if ($option eq 'norequest') {
1755: $val = 0;
1756: }
1757: my $checked = '';
1758: if ($option eq $curroption) {
1759: $checked = ' checked="checked"';
1760: }
1761: $datatable .= '<span class="LC_nobreak"><label>'.
1762: '<input type="radio" name="authorreq_default"'.
1763: ' value="'.$val.'"'.$checked.' />'.
1764: $titles{$option}.'</label></span> ';
1765: }
1.101 raeburn 1766: } else {
1767: my $checked = 'checked="checked" ';
1768: if (ref($settings) eq 'HASH') {
1769: if (ref($settings->{$item}) eq 'HASH') {
1770: if ($settings->{$item}->{'default'} == 0) {
1771: $checked = '';
1772: } elsif ($settings->{$item}->{'default'} == 1) {
1773: $checked = 'checked="checked" ';
1774: }
1.78 raeburn 1775: }
1.72 raeburn 1776: }
1.101 raeburn 1777: $datatable .= '<span class="LC_nobreak"><label>'.
1778: '<input type="checkbox" name="'.$context.'_'.$item.
1779: '" value="default" '.$checked.'/>'.$titles{$item}.
1780: '</label></span> ';
1781: }
1782: }
1783: if ($context eq 'requestcourses') {
1784: $datatable .= '</tr><tr>';
1785: foreach my $item (@usertools) {
1.106 raeburn 1786: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1787: }
1.101 raeburn 1788: $datatable .= '</tr></table>';
1.72 raeburn 1789: }
1.86 raeburn 1790: $datatable .= '</td>';
1.163 raeburn 1791: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1792: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1793: '<input type="text" name="defaultquota" value="'.
1794: $defaultquota.'" size="5" /> Mb</span></td>';
1795: }
1796: $datatable .= '</tr>';
1.72 raeburn 1797: $typecount ++;
1798: $css_class = $typecount%2?' class="LC_odd_row"':'';
1799: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1800: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1801: if ($context eq 'requestcourses') {
1.109 raeburn 1802: $datatable .= &mt('(overrides affiliation, if set)').
1803: '</td>'.
1804: '<td class="LC_left_item">'.
1805: '<table><tr>';
1.101 raeburn 1806: } else {
1.109 raeburn 1807: $datatable .= &mt('(overrides affiliation, if checked)').
1808: '</td>'.
1809: '<td class="LC_left_item" colspan="2">'.
1810: '<br />';
1.101 raeburn 1811: }
1812: my %advcell;
1.72 raeburn 1813: foreach my $item (@usertools) {
1.101 raeburn 1814: if ($context eq 'requestcourses') {
1815: my ($curroption,$currlimit);
1816: if (ref($settings) eq 'HASH') {
1817: if (ref($settings->{$item}) eq 'HASH') {
1818: $curroption = $settings->{$item}->{'_LC_adv'};
1819: if ($curroption =~ /^autolimit=(\d*)$/) {
1820: $currlimit = $1;
1821: }
1822: }
1823: }
1824: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1825: my $checked = '';
1826: if ($curroption eq '') {
1827: $checked = ' checked="checked"';
1828: }
1829: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1830: '<input type="radio" name="crsreq_'.$item.
1831: '__LC_adv" value=""'.$checked.' />'.
1832: &mt('No override set').'</label></span> ';
1.101 raeburn 1833: foreach my $option (@options) {
1834: my $val = $option;
1835: if ($option eq 'norequest') {
1836: $val = 0;
1837: }
1838: if ($option eq 'validate') {
1839: my $canvalidate = 0;
1840: if (ref($validations{$item}) eq 'HASH') {
1841: if ($validations{$item}{'_LC_adv'}) {
1842: $canvalidate = 1;
1843: }
1844: }
1845: next if (!$canvalidate);
1846: }
1847: my $checked = '';
1.104 raeburn 1848: if ($val eq $curroption) {
1.101 raeburn 1849: $checked = ' checked="checked"';
1850: } elsif ($option eq 'autolimit') {
1851: if ($curroption =~ /^autolimit/) {
1852: $checked = ' checked="checked"';
1853: }
1854: }
1855: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1856: '<input type="radio" name="crsreq_'.$item.
1857: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1858: $titles{$option}.'</label>';
1859: if ($option eq 'autolimit') {
1.127 raeburn 1860: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1861: $item.'_limit__LC_adv" size="1" '.
1862: 'value="'.$currlimit.'" />';
1863: }
1.127 raeburn 1864: $advcell{$item} .= '</span> ';
1.104 raeburn 1865: if ($option eq 'autolimit') {
1.127 raeburn 1866: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1867: }
1.101 raeburn 1868: }
1.163 raeburn 1869: } elsif ($context eq 'requestauthor') {
1870: my $curroption;
1871: if (ref($settings) eq 'HASH') {
1872: $curroption = $settings->{'_LC_adv'};
1873: }
1874: my $checked = '';
1875: if ($curroption eq '') {
1876: $checked = ' checked="checked"';
1877: }
1878: $datatable .= '<span class="LC_nobreak"><label>'.
1879: '<input type="radio" name="authorreq__LC_adv"'.
1880: ' value=""'.$checked.' />'.
1881: &mt('No override set').'</label></span> ';
1882: foreach my $option (@options) {
1883: my $val = $option;
1884: if ($option eq 'norequest') {
1885: $val = 0;
1886: }
1887: my $checked = '';
1888: if ($val eq $curroption) {
1889: $checked = ' checked="checked"';
1890: }
1891: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1892: '<input type="radio" name="authorreq__LC_adv"'.
1893: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1894: $titles{$option}.'</label></span> ';
1895: }
1.101 raeburn 1896: } else {
1897: my $checked = 'checked="checked" ';
1898: if (ref($settings) eq 'HASH') {
1899: if (ref($settings->{$item}) eq 'HASH') {
1900: if ($settings->{$item}->{'_LC_adv'} == 0) {
1901: $checked = '';
1902: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1903: $checked = 'checked="checked" ';
1904: }
1.79 raeburn 1905: }
1.72 raeburn 1906: }
1.101 raeburn 1907: $datatable .= '<span class="LC_nobreak"><label>'.
1908: '<input type="checkbox" name="'.$context.'_'.$item.
1909: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1910: '</label></span> ';
1911: }
1912: }
1913: if ($context eq 'requestcourses') {
1914: $datatable .= '</tr><tr>';
1915: foreach my $item (@usertools) {
1.106 raeburn 1916: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1917: }
1.101 raeburn 1918: $datatable .= '</tr></table>';
1.72 raeburn 1919: }
1.98 raeburn 1920: $datatable .= '</td></tr>';
1.30 raeburn 1921: $$rowtotal += $typecount;
1.3 raeburn 1922: return $datatable;
1923: }
1924:
1.163 raeburn 1925: sub print_requestmail {
1926: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1927: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1928: $now = time;
1929: $rows = 0;
1930: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1931: foreach my $server (keys(%dompersonnel)) {
1932: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1933: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1934: if (!grep(/^$uname:$udom$/,@domcoord)) {
1935: push(@domcoord,$uname.':'.$udom);
1936: }
1937: }
1938: }
1939: if (ref($settings) eq 'HASH') {
1940: if (ref($settings->{'notify'}) eq 'HASH') {
1941: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1942: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1943: }
1944: }
1945: }
1.104 raeburn 1946: if (@currapproval) {
1947: foreach my $dc (@currapproval) {
1.102 raeburn 1948: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1949: push(@domcoord,$dc);
1950: }
1951: }
1952: }
1953: @domcoord = sort(@domcoord);
1954: my $numinrow = 4;
1955: my $numdc = @domcoord;
1956: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1957: my $text;
1958: if ($action eq 'requestcourses') {
1959: $text = &mt('Receive notification of course requests requiring approval');
1960: } else {
1961: $text = &mt('Receive notification of authoring space requests requiring approval')
1962: }
1963: $datatable = '<tr '.$css_class.'>'.
1964: ' <td>'.$text.'</td>'.
1.102 raeburn 1965: ' <td class="LC_left_item">';
1966: if (@domcoord > 0) {
1967: $datatable .= '<table>';
1968: for (my $i=0; $i<$numdc; $i++) {
1969: my $rem = $i%($numinrow);
1970: if ($rem == 0) {
1971: if ($i > 0) {
1972: $datatable .= '</tr>';
1973: }
1974: $datatable .= '<tr>';
1975: $rows ++;
1976: }
1977: my $check = ' ';
1.104 raeburn 1978: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1979: $check = ' checked="checked" ';
1980: }
1981: my ($uname,$udom) = split(':',$domcoord[$i]);
1982: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1983: if ($i == $numdc-1) {
1984: my $colsleft = $numinrow-$rem;
1985: if ($colsleft > 1) {
1986: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1987: } else {
1988: $datatable .= '<td class="LC_left_item">';
1989: }
1990: } else {
1991: $datatable .= '<td class="LC_left_item">';
1992: }
1993: $datatable .= '<span class="LC_nobreak"><label>'.
1994: '<input type="checkbox" name="reqapprovalnotify" '.
1995: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175 bisitz 1996: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 1997: }
1998: $datatable .= '</tr></table>';
1999: } else {
2000: $datatable .= &mt('There are no active Domain Coordinators');
2001: $rows ++;
2002: }
2003: $datatable .='</td></tr>';
2004: $$rowtotal += $rows;
2005: return $datatable;
2006: }
2007:
1.3 raeburn 2008: sub print_autoenroll {
1.30 raeburn 2009: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2010: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2011: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2012: if (ref($settings) eq 'HASH') {
2013: if (exists($settings->{'run'})) {
2014: if ($settings->{'run'} eq '0') {
2015: $runoff = ' checked="checked" ';
2016: $runon = ' ';
2017: } else {
2018: $runon = ' checked="checked" ';
2019: $runoff = ' ';
2020: }
2021: } else {
2022: if ($autorun) {
2023: $runon = ' checked="checked" ';
2024: $runoff = ' ';
2025: } else {
2026: $runoff = ' checked="checked" ';
2027: $runon = ' ';
2028: }
2029: }
1.129 raeburn 2030: if (exists($settings->{'co-owners'})) {
2031: if ($settings->{'co-owners'} eq '0') {
2032: $coownersoff = ' checked="checked" ';
2033: $coownerson = ' ';
2034: } else {
2035: $coownerson = ' checked="checked" ';
2036: $coownersoff = ' ';
2037: }
2038: } else {
2039: $coownersoff = ' checked="checked" ';
2040: $coownerson = ' ';
2041: }
1.3 raeburn 2042: if (exists($settings->{'sender_domain'})) {
2043: $defdom = $settings->{'sender_domain'};
2044: }
1.14 raeburn 2045: } else {
2046: if ($autorun) {
2047: $runon = ' checked="checked" ';
2048: $runoff = ' ';
2049: } else {
2050: $runoff = ' checked="checked" ';
2051: $runon = ' ';
2052: }
1.3 raeburn 2053: }
2054: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2055: my $notif_sender;
2056: if (ref($settings) eq 'HASH') {
2057: $notif_sender = $settings->{'sender_uname'};
2058: }
1.3 raeburn 2059: my $datatable='<tr class="LC_odd_row">'.
2060: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2061: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2062: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2063: $runon.' value="1" />'.&mt('Yes').'</label> '.
2064: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2065: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2066: '</tr><tr>'.
2067: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2068: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2069: &mt('username').': '.
2070: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2071: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2072: ': '.$domform.'</span></td></tr>'.
2073: '<tr class="LC_odd_row">'.
2074: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2075: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2076: '<input type="radio" name="autoassign_coowners"'.
2077: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2078: '<label><input type="radio" name="autoassign_coowners"'.
2079: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2080: '</tr>';
2081: $$rowtotal += 3;
1.3 raeburn 2082: return $datatable;
2083: }
2084:
2085: sub print_autoupdate {
1.30 raeburn 2086: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2087: my $datatable;
2088: if ($position eq 'top') {
2089: my $updateon = ' ';
2090: my $updateoff = ' checked="checked" ';
2091: my $classlistson = ' ';
2092: my $classlistsoff = ' checked="checked" ';
2093: if (ref($settings) eq 'HASH') {
2094: if ($settings->{'run'} eq '1') {
2095: $updateon = $updateoff;
2096: $updateoff = ' ';
2097: }
2098: if ($settings->{'classlists'} eq '1') {
2099: $classlistson = $classlistsoff;
2100: $classlistsoff = ' ';
2101: }
2102: }
2103: my %title = (
2104: run => 'Auto-update active?',
2105: classlists => 'Update information in classlists?',
2106: );
2107: $datatable = '<tr class="LC_odd_row">'.
2108: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2109: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2110: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2111: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2112: '<label><input type="radio" name="autoupdate_run"'.
2113: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2114: '</tr><tr>'.
2115: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2116: '<td class="LC_right_item"><span class="LC_nobreak">'.
2117: '<label><input type="radio" name="classlists"'.
2118: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2119: '<label><input type="radio" name="classlists"'.
2120: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2121: '</tr>';
1.30 raeburn 2122: $$rowtotal += 2;
1.131 raeburn 2123: } elsif ($position eq 'middle') {
2124: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2125: my $numinrow = 3;
2126: my $locknamesettings;
2127: $datatable .= &insttypes_row($settings,$types,$usertypes,
2128: $dom,$numinrow,$othertitle,
2129: 'lockablenames');
2130: $$rowtotal ++;
1.3 raeburn 2131: } else {
1.44 raeburn 2132: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2133: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2134: 'permanentemail','id');
1.33 raeburn 2135: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2136: my $numrows = 0;
1.26 raeburn 2137: if (ref($types) eq 'ARRAY') {
2138: if (@{$types} > 0) {
2139: $datatable =
2140: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2141: \@fields,$types,\$numrows);
1.30 raeburn 2142: $$rowtotal += @{$types};
1.26 raeburn 2143: }
1.3 raeburn 2144: }
2145: $datatable .=
2146: &usertype_update_row($settings,{'default' => $othertitle},
2147: \%fieldtitles,\@fields,['default'],
2148: \$numrows);
1.30 raeburn 2149: $$rowtotal ++;
1.3 raeburn 2150: }
2151: return $datatable;
2152: }
2153:
1.125 raeburn 2154: sub print_autocreate {
2155: my ($dom,$settings,$rowtotal) = @_;
2156: my (%createon,%createoff);
2157: my $curr_dc;
2158: my @types = ('xml','req');
2159: if (ref($settings) eq 'HASH') {
2160: foreach my $item (@types) {
2161: $createoff{$item} = ' checked="checked" ';
2162: $createon{$item} = ' ';
2163: if (exists($settings->{$item})) {
2164: if ($settings->{$item}) {
2165: $createon{$item} = ' checked="checked" ';
2166: $createoff{$item} = ' ';
2167: }
2168: }
2169: }
2170: $curr_dc = $settings->{'xmldc'};
2171: } else {
2172: foreach my $item (@types) {
2173: $createoff{$item} = ' checked="checked" ';
2174: $createon{$item} = ' ';
2175: }
2176: }
2177: $$rowtotal += 2;
2178: my $datatable='<tr class="LC_odd_row">'.
2179: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2180: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2181: '<input type="radio" name="autocreate_xml"'.
2182: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2183: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2184: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2185: '</td></tr><tr>'.
2186: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2187: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2188: '<input type="radio" name="autocreate_req"'.
2189: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2190: '<label><input type="radio" name="autocreate_req"'.
2191: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2192: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2193: if ($numdc > 1) {
1.143 raeburn 2194: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2195: &mt('Course creation processed as: (choose Dom. Coord.)').
2196: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2197: $$rowtotal ++ ;
2198: } else {
1.143 raeburn 2199: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2200: }
2201: return $datatable;
2202: }
2203:
1.23 raeburn 2204: sub print_directorysrch {
1.30 raeburn 2205: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2206: my $srchon = ' ';
2207: my $srchoff = ' checked="checked" ';
1.25 raeburn 2208: my ($exacton,$containson,$beginson);
1.24 raeburn 2209: my $localon = ' ';
2210: my $localoff = ' checked="checked" ';
1.23 raeburn 2211: if (ref($settings) eq 'HASH') {
2212: if ($settings->{'available'} eq '1') {
2213: $srchon = $srchoff;
2214: $srchoff = ' ';
2215: }
1.24 raeburn 2216: if ($settings->{'localonly'} eq '1') {
2217: $localon = $localoff;
2218: $localoff = ' ';
2219: }
1.25 raeburn 2220: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2221: foreach my $type (@{$settings->{'searchtypes'}}) {
2222: if ($type eq 'exact') {
2223: $exacton = ' checked="checked" ';
2224: } elsif ($type eq 'contains') {
2225: $containson = ' checked="checked" ';
2226: } elsif ($type eq 'begins') {
2227: $beginson = ' checked="checked" ';
2228: }
2229: }
2230: } else {
2231: if ($settings->{'searchtypes'} eq 'exact') {
2232: $exacton = ' checked="checked" ';
2233: } elsif ($settings->{'searchtypes'} eq 'contains') {
2234: $containson = ' checked="checked" ';
2235: } elsif ($settings->{'searchtypes'} eq 'specify') {
2236: $exacton = ' checked="checked" ';
2237: $containson = ' checked="checked" ';
2238: }
1.23 raeburn 2239: }
2240: }
2241: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2242: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2243:
2244: my $numinrow = 4;
1.26 raeburn 2245: my $cansrchrow = 0;
1.23 raeburn 2246: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2247: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2248: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2249: '<input type="radio" name="dirsrch_available"'.
2250: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2251: '<label><input type="radio" name="dirsrch_available"'.
2252: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2253: '</tr><tr>'.
1.30 raeburn 2254: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2255: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2256: '<input type="radio" name="dirsrch_localonly"'.
2257: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2258: '<label><input type="radio" name="dirsrch_localonly"'.
2259: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2260: '</tr>';
1.30 raeburn 2261: $$rowtotal += 2;
1.26 raeburn 2262: if (ref($usertypes) eq 'HASH') {
2263: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2264: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2265: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2266: $cansrchrow = 1;
2267: }
2268: }
2269: if ($cansrchrow) {
1.30 raeburn 2270: $$rowtotal ++;
1.26 raeburn 2271: $datatable .= '<tr>';
2272: } else {
2273: $datatable .= '<tr class="LC_odd_row">';
2274: }
1.30 raeburn 2275: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2276: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2277: foreach my $title (@{$titleorder}) {
2278: if (defined($searchtitles->{$title})) {
2279: my $check = ' ';
1.93 raeburn 2280: if (ref($settings) eq 'HASH') {
1.39 raeburn 2281: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2282: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2283: $check = ' checked="checked" ';
2284: }
1.25 raeburn 2285: }
2286: }
2287: $datatable .= '<td class="LC_left_item">'.
2288: '<span class="LC_nobreak"><label>'.
2289: '<input type="checkbox" name="searchby" '.
2290: 'value="'.$title.'"'.$check.'/>'.
2291: $searchtitles->{$title}.'</label></span></td>';
2292: }
2293: }
1.26 raeburn 2294: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2295: $$rowtotal ++;
1.26 raeburn 2296: if ($cansrchrow) {
2297: $datatable .= '<tr class="LC_odd_row">';
2298: } else {
2299: $datatable .= '<tr>';
2300: }
1.30 raeburn 2301: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2302: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2303: '<span class="LC_nobreak"><label>'.
2304: '<input type="checkbox" name="searchtypes" '.
2305: $exacton.' value="exact" />'.&mt('Exact match').
2306: '</label> '.
2307: '<label><input type="checkbox" name="searchtypes" '.
2308: $beginson.' value="begins" />'.&mt('Begins with').
2309: '</label> '.
2310: '<label><input type="checkbox" name="searchtypes" '.
2311: $containson.' value="contains" />'.&mt('Contains').
2312: '</label></span></td></tr>';
1.30 raeburn 2313: $$rowtotal ++;
1.25 raeburn 2314: return $datatable;
2315: }
2316:
1.28 raeburn 2317: sub print_contacts {
1.30 raeburn 2318: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2319: my $datatable;
2320: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2321: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2322: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2323: 'requestsmail');
1.28 raeburn 2324: foreach my $type (@mailings) {
2325: $otheremails{$type} = '';
2326: }
1.134 raeburn 2327: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2328: if (ref($settings) eq 'HASH') {
2329: foreach my $item (@contacts) {
2330: if (exists($settings->{$item})) {
2331: $to{$item} = $settings->{$item};
2332: }
2333: }
2334: foreach my $type (@mailings) {
2335: if (exists($settings->{$type})) {
2336: if (ref($settings->{$type}) eq 'HASH') {
2337: foreach my $item (@contacts) {
2338: if ($settings->{$type}{$item}) {
2339: $checked{$type}{$item} = ' checked="checked" ';
2340: }
2341: }
2342: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2343: if ($type eq 'helpdeskmail') {
2344: $bccemails{$type} = $settings->{$type}{'bcc'};
2345: }
1.28 raeburn 2346: }
1.89 raeburn 2347: } elsif ($type eq 'lonstatusmail') {
2348: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2349: }
2350: }
2351: } else {
2352: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2353: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2354: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2355: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2356: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2357: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2358: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2359: }
2360: my ($titles,$short_titles) = &contact_titles();
2361: my $rownum = 0;
2362: my $css_class;
2363: foreach my $item (@contacts) {
1.69 raeburn 2364: $rownum ++;
2365: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2366: $datatable .= '<tr'.$css_class.'>'.
2367: '<td><span class="LC_nobreak">'.$titles->{$item}.
2368: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2369: '<input type="text" name="'.$item.'" value="'.
2370: $to{$item}.'" /></td></tr>';
2371: }
2372: foreach my $type (@mailings) {
1.69 raeburn 2373: $rownum ++;
2374: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2375: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2376: '<td><span class="LC_nobreak">'.
2377: $titles->{$type}.': </span></td>'.
1.28 raeburn 2378: '<td class="LC_left_item">'.
2379: '<span class="LC_nobreak">';
2380: foreach my $item (@contacts) {
2381: $datatable .= '<label>'.
2382: '<input type="checkbox" name="'.$type.'"'.
2383: $checked{$type}{$item}.
2384: ' value="'.$item.'" />'.$short_titles->{$item}.
2385: '</label> ';
2386: }
2387: $datatable .= '</span><br />'.&mt('Others').': '.
2388: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2389: 'value="'.$otheremails{$type}.'" />';
2390: if ($type eq 'helpdeskmail') {
1.136 raeburn 2391: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2392: '<input type="text" name="'.$type.'_bcc" '.
2393: 'value="'.$bccemails{$type}.'" />';
2394: }
2395: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2396: }
1.30 raeburn 2397: $$rowtotal += $rownum;
1.28 raeburn 2398: return $datatable;
2399: }
2400:
1.118 jms 2401: sub print_helpsettings {
1.168 raeburn 2402: my ($dom,$confname,$settings,$rowtotal) = @_;
2403: my ($datatable,$itemcount);
1.166 raeburn 2404: $itemcount = 1;
1.168 raeburn 2405: my (%choices,%defaultchecked,@toggles);
2406: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2407: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2408: &mt('LON-CAPA bug tracker'),600,500));
2409: %defaultchecked = ('submitbugs' => 'on');
2410: @toggles = ('submitbugs',);
1.166 raeburn 2411:
1.168 raeburn 2412: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2413: \%choices,$itemcount);
1.166 raeburn 2414: return $datatable;
1.121 raeburn 2415: }
2416:
2417: sub radiobutton_prefs {
2418: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2419: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2420: (ref($choices) eq 'HASH'));
2421:
1.170 raeburn 2422: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2423:
2424: foreach my $item (@{$toggles}) {
2425: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2426: $checkedon{$item} = ' checked="checked" ';
2427: $checkedoff{$item} = ' ';
1.121 raeburn 2428: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2429: $checkedoff{$item} = ' checked="checked" ';
2430: $checkedon{$item} = ' ';
2431: }
2432: }
2433: if (ref($settings) eq 'HASH') {
1.121 raeburn 2434: foreach my $item (@{$toggles}) {
1.118 jms 2435: if ($settings->{$item} eq '1') {
2436: $checkedon{$item} = ' checked="checked" ';
2437: $checkedoff{$item} = ' ';
2438: } elsif ($settings->{$item} eq '0') {
2439: $checkedoff{$item} = ' checked="checked" ';
2440: $checkedon{$item} = ' ';
2441: }
2442: }
1.121 raeburn 2443: }
2444: foreach my $item (@{$toggles}) {
1.118 jms 2445: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2446: $datatable .=
2447: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2448: '</span></td>'.
2449: '<td class="LC_right_item"><span class="LC_nobreak">'.
2450: '<label><input type="radio" name="'.
2451: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2452: '</label> <label><input type="radio" name="'.$item.'" '.
2453: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2454: '</span></td>'.
2455: '</tr>';
2456: $itemcount ++;
1.121 raeburn 2457: }
2458: return ($datatable,$itemcount);
2459: }
2460:
2461: sub print_coursedefaults {
1.139 raeburn 2462: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2463: my ($css_class,$datatable);
2464: my $itemcount = 1;
1.139 raeburn 2465: if ($position eq 'top') {
2466: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2467: %choices =
2468: &Apache::lonlocal::texthash (
2469: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2470: );
2471: %defaultchecked = ('canuse_pdfforms' => 'off');
2472: @toggles = ('canuse_pdfforms',);
2473: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2474: \%choices,$itemcount);
1.139 raeburn 2475: $$rowtotal += $itemcount;
2476: } else {
2477: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2478: my %choices =
2479: &Apache::lonlocal::texthash (
2480: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2481: );
2482: my $currdefresponder;
2483: if (ref($settings) eq 'HASH') {
2484: $currdefresponder = $settings->{'anonsurvey_threshold'};
2485: }
2486: if (!$currdefresponder) {
2487: $currdefresponder = 10;
2488: } elsif ($currdefresponder < 1) {
2489: $currdefresponder = 1;
2490: }
2491: $datatable .=
2492: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2493: '</span></td>'.
2494: '<td class="LC_right_item"><span class="LC_nobreak">'.
2495: '<input type="text" name="anonsurvey_threshold"'.
2496: ' value="'.$currdefresponder.'" size="5" /></span>'.
2497: '</td></tr>';
2498: }
1.121 raeburn 2499: return $datatable;
1.118 jms 2500: }
2501:
1.137 raeburn 2502: sub print_usersessions {
2503: my ($position,$dom,$settings,$rowtotal) = @_;
2504: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2505: my (%by_ip,%by_location,@intdoms);
2506: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2507:
2508: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2509: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2510: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2511: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2512: my $itemcount = 1;
2513: if ($position eq 'top') {
1.152 raeburn 2514: if (keys(%serverhomes) > 1) {
1.145 raeburn 2515: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2516: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2517: } else {
1.140 raeburn 2518: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2519: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2520: }
1.137 raeburn 2521: } else {
1.145 raeburn 2522: if (keys(%by_location) == 0) {
2523: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2524: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2525: } else {
2526: my %lt = &usersession_titles();
2527: my $numinrow = 5;
2528: my $prefix;
2529: my @types;
2530: if ($position eq 'bottom') {
2531: $prefix = 'remote';
2532: @types = ('version','excludedomain','includedomain');
2533: } else {
2534: $prefix = 'hosted';
2535: @types = ('excludedomain','includedomain');
2536: }
2537: my (%current,%checkedon,%checkedoff);
2538: my @lcversions = &Apache::lonnet::all_loncaparevs();
2539: my @locations = sort(keys(%by_location));
2540: foreach my $type (@types) {
2541: $checkedon{$type} = '';
2542: $checkedoff{$type} = ' checked="checked"';
2543: }
2544: if (ref($settings) eq 'HASH') {
2545: if (ref($settings->{$prefix}) eq 'HASH') {
2546: foreach my $key (keys(%{$settings->{$prefix}})) {
2547: $current{$key} = $settings->{$prefix}{$key};
2548: if ($key eq 'version') {
2549: if ($current{$key} ne '') {
2550: $checkedon{$key} = ' checked="checked"';
2551: $checkedoff{$key} = '';
2552: }
2553: } elsif (ref($current{$key}) eq 'ARRAY') {
2554: $checkedon{$key} = ' checked="checked"';
2555: $checkedoff{$key} = '';
2556: }
1.137 raeburn 2557: }
2558: }
2559: }
1.145 raeburn 2560: foreach my $type (@types) {
2561: next if ($type ne 'version' && !@locations);
2562: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2563: $datatable .= '<tr'.$css_class.'>
2564: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2565: <span class="LC_nobreak">
2566: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2567: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2568: if ($type eq 'version') {
2569: my $selector = '<select name="'.$prefix.'_version">';
2570: foreach my $version (@lcversions) {
2571: my $selected = '';
2572: if ($current{'version'} eq $version) {
2573: $selected = ' selected="selected"';
2574: }
2575: $selector .= ' <option value="'.$version.'"'.
2576: $selected.'>'.$version.'</option>';
2577: }
2578: $selector .= '</select> ';
2579: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2580: } else {
2581: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2582: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2583: ' />'.(' 'x2).
2584: '<input type="button" value="'.&mt('uncheck all').'" '.
2585: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2586: "\n".
2587: '</div><div><table>';
2588: my $rem;
2589: for (my $i=0; $i<@locations; $i++) {
2590: my ($showloc,$value,$checkedtype);
2591: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2592: my $ip = $by_location{$locations[$i]}->[0];
2593: if (ref($by_ip{$ip}) eq 'ARRAY') {
2594: $value = join(':',@{$by_ip{$ip}});
2595: $showloc = join(', ',@{$by_ip{$ip}});
2596: if (ref($current{$type}) eq 'ARRAY') {
2597: foreach my $loc (@{$by_ip{$ip}}) {
2598: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2599: $checkedtype = ' checked="checked"';
2600: last;
2601: }
2602: }
1.138 raeburn 2603: }
2604: }
2605: }
1.145 raeburn 2606: $rem = $i%($numinrow);
2607: if ($rem == 0) {
2608: if ($i > 0) {
2609: $datatable .= '</tr>';
2610: }
2611: $datatable .= '<tr>';
2612: }
2613: $datatable .= '<td class="LC_left_item">'.
2614: '<span class="LC_nobreak"><label>'.
2615: '<input type="checkbox" name="'.$prefix.'_'.$type.
2616: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2617: '</label></span></td>';
1.137 raeburn 2618: }
1.145 raeburn 2619: $rem = @locations%($numinrow);
2620: my $colsleft = $numinrow - $rem;
2621: if ($colsleft > 1 ) {
2622: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2623: ' </td>';
2624: } elsif ($colsleft == 1) {
2625: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2626: }
1.145 raeburn 2627: $datatable .= '</tr></table>';
1.137 raeburn 2628: }
1.145 raeburn 2629: $datatable .= '</td></tr>';
2630: $itemcount ++;
1.137 raeburn 2631: }
2632: }
2633: }
2634: $$rowtotal += $itemcount;
2635: return $datatable;
2636: }
2637:
1.138 raeburn 2638: sub build_location_hashes {
2639: my ($intdoms,$by_ip,$by_location) = @_;
2640: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2641: (ref($by_location) eq 'HASH'));
2642: my %iphost = &Apache::lonnet::get_iphost();
2643: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2644: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2645: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2646: foreach my $id (@{$iphost{$primary_ip}}) {
2647: my $intdom = &Apache::lonnet::internet_dom($id);
2648: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2649: push(@{$intdoms},$intdom);
2650: }
2651: }
2652: }
2653: foreach my $ip (keys(%iphost)) {
2654: if (ref($iphost{$ip}) eq 'ARRAY') {
2655: foreach my $id (@{$iphost{$ip}}) {
2656: my $location = &Apache::lonnet::internet_dom($id);
2657: if ($location) {
2658: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2659: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2660: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2661: push(@{$by_ip->{$ip}},$location);
2662: }
2663: } else {
2664: $by_ip->{$ip} = [$location];
2665: }
2666: }
2667: }
2668: }
2669: }
2670: foreach my $ip (sort(keys(%{$by_ip}))) {
2671: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2672: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2673: my $first = $by_ip->{$ip}->[0];
2674: if (ref($by_location->{$first}) eq 'ARRAY') {
2675: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2676: push(@{$by_location->{$first}},$ip);
2677: }
2678: } else {
2679: $by_location->{$first} = [$ip];
2680: }
2681: }
2682: }
2683: return;
2684: }
2685:
1.145 raeburn 2686: sub current_offloads_to {
2687: my ($dom,$settings,$servers) = @_;
2688: my (%spareid,%otherdomconfigs);
1.152 raeburn 2689: if (ref($servers) eq 'HASH') {
1.145 raeburn 2690: foreach my $lonhost (sort(keys(%{$servers}))) {
2691: my $gotspares;
1.152 raeburn 2692: if (ref($settings) eq 'HASH') {
2693: if (ref($settings->{'spares'}) eq 'HASH') {
2694: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2695: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2696: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2697: $gotspares = 1;
2698: }
1.145 raeburn 2699: }
2700: }
2701: unless ($gotspares) {
2702: my $gotspares;
2703: my $serverhomeID =
2704: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2705: my $serverhomedom =
2706: &Apache::lonnet::host_domain($serverhomeID);
2707: if ($serverhomedom ne $dom) {
2708: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2709: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2710: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2711: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2712: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2713: $gotspares = 1;
2714: }
2715: }
2716: } else {
2717: $otherdomconfigs{$serverhomedom} =
2718: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2719: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2720: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2721: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2722: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2723: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2724: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2725: $gotspares = 1;
2726: }
2727: }
2728: }
2729: }
2730: }
2731: }
2732: }
2733: unless ($gotspares) {
2734: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2735: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2736: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2737: } else {
2738: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2739: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2740: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2741: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2742: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2743: } else {
1.150 raeburn 2744: my %what = (
2745: spareid => 1,
2746: );
2747: my ($result,$returnhash) =
2748: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2749: if ($result eq 'ok') {
2750: if (ref($returnhash) eq 'HASH') {
2751: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2752: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2753: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2754: }
2755: }
1.145 raeburn 2756: }
2757: }
2758: }
2759: }
2760: }
2761: }
2762: return %spareid;
2763: }
2764:
2765: sub spares_row {
1.152 raeburn 2766: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2767: my $css_class;
2768: my $numinrow = 4;
2769: my $itemcount = 1;
2770: my $datatable;
1.152 raeburn 2771: my %typetitles = &sparestype_titles();
2772: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2773: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2774: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2775: my ($othercontrol,$serverdom);
2776: if ($serverhome ne $server) {
2777: $serverdom = &Apache::lonnet::host_domain($serverhome);
2778: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2779: } else {
2780: $serverdom = &Apache::lonnet::host_domain($server);
2781: if ($serverdom ne $dom) {
2782: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2783: }
2784: }
2785: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2786: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2787: $datatable .= '<tr'.$css_class.'>
2788: <td rowspan="2">
1.183 bisitz 2789: <span class="LC_nobreak">'.
2790: &mt('[_1] when busy, offloads to:'
2791: ,'<b>'.$server.'</b>').
2792: "\n";
1.145 raeburn 2793: my (%current,%canselect);
1.152 raeburn 2794: my @choices =
2795: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2796: foreach my $type ('primary','default') {
2797: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2798: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2799: my @spares = @{$spareid->{$server}{$type}};
2800: if (@spares > 0) {
1.152 raeburn 2801: if ($othercontrol) {
2802: $current{$type} = join(', ',@spares);
2803: } else {
2804: $current{$type} .= '<table>';
2805: my $numspares = scalar(@spares);
2806: for (my $i=0; $i<@spares; $i++) {
2807: my $rem = $i%($numinrow);
2808: if ($rem == 0) {
2809: if ($i > 0) {
2810: $current{$type} .= '</tr>';
2811: }
2812: $current{$type} .= '<tr>';
1.145 raeburn 2813: }
1.152 raeburn 2814: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
2815: $spareid->{$server}{$type}[$i].
2816: '</label></td>'."\n";
2817: }
2818: my $rem = @spares%($numinrow);
2819: my $colsleft = $numinrow - $rem;
2820: if ($colsleft > 1 ) {
2821: $current{$type} .= '<td colspan="'.$colsleft.
2822: '" class="LC_left_item">'.
2823: ' </td>';
2824: } elsif ($colsleft == 1) {
2825: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2826: }
1.152 raeburn 2827: $current{$type} .= '</tr></table>';
1.150 raeburn 2828: }
1.145 raeburn 2829: }
2830: }
2831: if ($current{$type} eq '') {
2832: $current{$type} = &mt('None specified');
2833: }
1.152 raeburn 2834: if ($othercontrol) {
2835: if ($type eq 'primary') {
2836: $canselect{$type} = $othercontrol;
2837: }
2838: } else {
2839: $canselect{$type} =
2840: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2841: '<select name="newspare_'.$type.'_'.$server.'" '.
2842: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2843: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2844: if (@choices > 0) {
2845: foreach my $lonhost (@choices) {
2846: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2847: }
2848: }
2849: $canselect{$type} .= '</select>'."\n";
2850: }
2851: } else {
2852: $current{$type} = &mt('Could not be determined');
2853: if ($type eq 'primary') {
2854: $canselect{$type} = $othercontrol;
2855: }
1.145 raeburn 2856: }
1.152 raeburn 2857: if ($type eq 'default') {
2858: $datatable .= '<tr'.$css_class.'>';
2859: }
2860: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2861: '<td>'.$current{$type}.'</td>'."\n".
2862: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2863: }
2864: $itemcount ++;
2865: }
2866: }
2867: $$rowtotal += $itemcount;
2868: return $datatable;
2869: }
2870:
1.152 raeburn 2871: sub possible_newspares {
2872: my ($server,$currspares,$serverhomes,$altids) = @_;
2873: my $serverhostname = &Apache::lonnet::hostname($server);
2874: my %excluded;
2875: if ($serverhostname ne '') {
2876: %excluded = (
2877: $serverhostname => 1,
2878: );
2879: }
2880: if (ref($currspares) eq 'HASH') {
2881: foreach my $type (keys(%{$currspares})) {
2882: if (ref($currspares->{$type}) eq 'ARRAY') {
2883: if (@{$currspares->{$type}} > 0) {
2884: foreach my $curr (@{$currspares->{$type}}) {
2885: my $hostname = &Apache::lonnet::hostname($curr);
2886: $excluded{$hostname} = 1;
2887: }
2888: }
2889: }
2890: }
2891: }
2892: my @choices;
2893: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2894: if (keys(%{$serverhomes}) > 1) {
2895: foreach my $name (sort(keys(%{$serverhomes}))) {
2896: unless ($excluded{$name}) {
2897: if (exists($altids->{$serverhomes->{$name}})) {
2898: push(@choices,$altids->{$serverhomes->{$name}});
2899: } else {
2900: push(@choices,$serverhomes->{$name});
1.145 raeburn 2901: }
2902: }
2903: }
2904: }
2905: }
1.152 raeburn 2906: return sort(@choices);
1.145 raeburn 2907: }
2908:
1.150 raeburn 2909: sub print_loadbalancing {
2910: my ($dom,$settings,$rowtotal) = @_;
2911: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2912: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2913: my $numinrow = 1;
2914: my $datatable;
2915: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2916: my (%currbalancer,%currtargets,%currrules,%existing);
2917: if (ref($settings) eq 'HASH') {
2918: %existing = %{$settings};
2919: }
2920: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2921: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2922: \%currtargets,\%currrules);
1.150 raeburn 2923: } else {
2924: return;
2925: }
2926: my ($othertitle,$usertypes,$types) =
2927: &Apache::loncommon::sorted_inst_types($dom);
2928: my $rownum = 6;
2929: if (ref($types) eq 'ARRAY') {
2930: $rownum += scalar(@{$types});
2931: }
1.171 raeburn 2932: my @css_class = ('LC_odd_row','LC_even_row');
2933: my $balnum = 0;
2934: my $islast;
2935: my (@toshow,$disabledtext);
2936: if (keys(%currbalancer) > 0) {
2937: @toshow = sort(keys(%currbalancer));
2938: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2939: push(@toshow,'');
2940: }
2941: } else {
2942: @toshow = ('');
2943: $disabledtext = &mt('No existing load balancer');
2944: }
2945: foreach my $lonhost (@toshow) {
2946: if ($balnum == scalar(@toshow)-1) {
2947: $islast = 1;
2948: } else {
2949: $islast = 0;
2950: }
2951: my $cssidx = $balnum%2;
2952: my $targets_div_style = 'display: none';
2953: my $disabled_div_style = 'display: block';
2954: my $homedom_div_style = 'display: none';
2955: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2956: '<td rowspan="'.$rownum.'" valign="top">'.
2957: '<p>';
2958: if ($lonhost eq '') {
2959: $datatable .= '<span class="LC_nobreak">';
2960: if (keys(%currbalancer) > 0) {
2961: $datatable .= &mt('Add balancer:');
2962: } else {
2963: $datatable .= &mt('Enable balancer:');
2964: }
2965: $datatable .= ' '.
2966: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2967: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2968: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2969: '<option value="" selected="selected">'.&mt('None').
2970: '</option>'."\n";
2971: foreach my $server (sort(keys(%servers))) {
2972: next if ($currbalancer{$server});
2973: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2974: }
2975: $datatable .=
2976: '</select>'."\n".
2977: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2978: } else {
2979: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2980: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2981: &mt('Stop balancing').'</label>'.
2982: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2983: $targets_div_style = 'display: block';
2984: $disabled_div_style = 'display: none';
2985: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2986: $homedom_div_style = 'display: block';
2987: }
2988: }
2989: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2990: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2991: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2992: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2993: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2994: my @sparestypes = ('primary','default');
2995: my %typetitles = &sparestype_titles();
2996: foreach my $sparetype (@sparestypes) {
2997: my $targettable;
2998: for (my $i=0; $i<$numspares; $i++) {
2999: my $checked;
3000: if (ref($currtargets{$lonhost}) eq 'HASH') {
3001: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3002: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3003: $checked = ' checked="checked"';
3004: }
3005: }
3006: }
3007: my ($chkboxval,$disabled);
3008: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3009: $chkboxval = $spares[$i];
3010: }
3011: if (exists($currbalancer{$spares[$i]})) {
3012: $disabled = ' disabled="disabled"';
3013: }
3014: $targettable .=
3015: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3016: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3017: '</span></label></td>';
3018: my $rem = $i%($numinrow);
3019: if ($rem == 0) {
3020: if (($i > 0) && ($i < $numspares-1)) {
3021: $targettable .= '</tr>';
3022: }
3023: if ($i < $numspares-1) {
3024: $targettable .= '<tr>';
1.150 raeburn 3025: }
3026: }
3027: }
1.171 raeburn 3028: if ($targettable ne '') {
3029: my $rem = $numspares%($numinrow);
3030: my $colsleft = $numinrow - $rem;
3031: if ($colsleft > 1 ) {
3032: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3033: ' </td>';
3034: } elsif ($colsleft == 1) {
3035: $targettable .= '<td class="LC_left_item"> </td>';
3036: }
3037: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3038: '<table><tr>'.$targettable.'</tr></table><br />';
3039: }
3040: }
3041: $datatable .= '</div></td></tr>'.
3042: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3043: $othertitle,$usertypes,$types,\%servers,
3044: \%currbalancer,$lonhost,
3045: $targets_div_style,$homedom_div_style,
3046: $css_class[$cssidx],$balnum,$islast);
3047: $$rowtotal += $rownum;
3048: $balnum ++;
3049: }
3050: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3051: return $datatable;
3052: }
3053:
3054: sub get_loadbalancers_config {
3055: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3056: return unless ((ref($servers) eq 'HASH') &&
3057: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3058: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3059: if (keys(%{$existing}) > 0) {
3060: my $oldlonhost;
3061: foreach my $key (sort(keys(%{$existing}))) {
3062: if ($key eq 'lonhost') {
3063: $oldlonhost = $existing->{'lonhost'};
3064: $currbalancer->{$oldlonhost} = 1;
3065: } elsif ($key eq 'targets') {
3066: if ($oldlonhost) {
3067: $currtargets->{$oldlonhost} = $existing->{'targets'};
3068: }
3069: } elsif ($key eq 'rules') {
3070: if ($oldlonhost) {
3071: $currrules->{$oldlonhost} = $existing->{'rules'};
3072: }
3073: } elsif (ref($existing->{$key}) eq 'HASH') {
3074: $currbalancer->{$key} = 1;
3075: $currtargets->{$key} = $existing->{$key}{'targets'};
3076: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3077: }
3078: }
1.171 raeburn 3079: } else {
3080: my ($balancerref,$targetsref) =
3081: &Apache::lonnet::get_lonbalancer_config($servers);
3082: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3083: foreach my $server (sort(keys(%{$balancerref}))) {
3084: $currbalancer->{$server} = 1;
3085: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3086: }
3087: }
3088: }
1.171 raeburn 3089: return;
1.150 raeburn 3090: }
3091:
3092: sub loadbalancing_rules {
3093: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3094: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3095: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3096: my $output;
1.171 raeburn 3097: my $num = 0;
1.150 raeburn 3098: my ($alltypes,$othertypes,$titles) =
3099: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3100: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3101: foreach my $type (@{$alltypes}) {
1.171 raeburn 3102: $num ++;
1.150 raeburn 3103: my $current;
3104: if (ref($currrules) eq 'HASH') {
3105: $current = $currrules->{$type};
3106: }
3107: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3108: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3109: $current = '';
3110: }
3111: }
3112: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3113: $servers,$currbalancer,$lonhost,$dom,
3114: $targets_div_style,$homedom_div_style,
3115: $css_class,$balnum,$num,$islast);
1.150 raeburn 3116: }
3117: }
3118: return $output;
3119: }
3120:
3121: sub loadbalancing_titles {
3122: my ($dom,$intdom,$usertypes,$types) = @_;
3123: my %othertypes = (
3124: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3125: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3126: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3127: '_LC_external' => &mt('Users not from [_1]',$intdom),
3128: );
3129: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3130: if (ref($types) eq 'ARRAY') {
3131: unshift(@alltypes,@{$types},'default');
3132: }
3133: my %titles;
3134: foreach my $type (@alltypes) {
3135: if ($type =~ /^_LC_/) {
3136: $titles{$type} = $othertypes{$type};
3137: } elsif ($type eq 'default') {
3138: $titles{$type} = &mt('All users from [_1]',$dom);
3139: if (ref($types) eq 'ARRAY') {
3140: if (@{$types} > 0) {
3141: $titles{$type} = &mt('Other users from [_1]',$dom);
3142: }
3143: }
3144: } elsif (ref($usertypes) eq 'HASH') {
3145: $titles{$type} = $usertypes->{$type};
3146: }
3147: }
3148: return (\@alltypes,\%othertypes,\%titles);
3149: }
3150:
3151: sub loadbalance_rule_row {
1.171 raeburn 3152: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3153: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3154: my @rulenames = ('default','homeserver');
3155: my %ruletitles = &offloadtype_text();
3156: if ($type eq '_LC_external') {
3157: push(@rulenames,'externalbalancer');
3158: } else {
3159: push(@rulenames,'specific');
3160: }
1.161 raeburn 3161: push(@rulenames,'none');
1.150 raeburn 3162: my $style = $targets_div_style;
3163: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3164: $style = $homedom_div_style;
3165: }
1.171 raeburn 3166: my $space;
3167: if ($islast && $num == 1) {
3168: $space = '<div display="inline-block"> </div>';
3169: }
1.150 raeburn 3170: my $output =
1.171 raeburn 3171: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3172: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3173: '<td valaign="top">'.$space.
3174: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3175: for (my $i=0; $i<@rulenames; $i++) {
3176: my $rule = $rulenames[$i];
3177: my ($checked,$extra);
3178: if ($rulenames[$i] eq 'default') {
3179: $rule = '';
3180: }
3181: if ($rulenames[$i] eq 'specific') {
3182: if (ref($servers) eq 'HASH') {
3183: my $default;
3184: if (($current ne '') && (exists($servers->{$current}))) {
3185: $checked = ' checked="checked"';
3186: }
3187: unless ($checked) {
3188: $default = ' selected="selected"';
3189: }
1.171 raeburn 3190: $extra =
3191: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3192: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3193: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3194: '<option value=""'.$default.'></option>'."\n";
3195: foreach my $server (sort(keys(%{$servers}))) {
3196: if (ref($currbalancer) eq 'HASH') {
3197: next if (exists($currbalancer->{$server}));
3198: }
1.150 raeburn 3199: my $selected;
1.171 raeburn 3200: if ($server eq $current) {
1.150 raeburn 3201: $selected = ' selected="selected"';
3202: }
1.171 raeburn 3203: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3204: }
3205: $extra .= '</select>';
3206: }
3207: } elsif ($rule eq $current) {
3208: $checked = ' checked="checked"';
3209: }
3210: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3211: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3212: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3213: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3214: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3215: '</label>'.$extra.'</span><br />'."\n";
3216: }
3217: $output .= '</div></td></tr>'."\n";
3218: return $output;
3219: }
3220:
3221: sub offloadtype_text {
3222: my %ruletitles = &Apache::lonlocal::texthash (
3223: 'default' => 'Offloads to default destinations',
3224: 'homeserver' => "Offloads to user's home server",
3225: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3226: 'specific' => 'Offloads to specific server',
1.161 raeburn 3227: 'none' => 'No offload',
1.150 raeburn 3228: );
3229: return %ruletitles;
3230: }
3231:
3232: sub sparestype_titles {
3233: my %typestitles = &Apache::lonlocal::texthash (
3234: 'primary' => 'primary',
3235: 'default' => 'default',
3236: );
3237: return %typestitles;
3238: }
3239:
1.28 raeburn 3240: sub contact_titles {
3241: my %titles = &Apache::lonlocal::texthash (
3242: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3243: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3244: 'errormail' => 'Error reports to be e-mailed to',
3245: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3246: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3247: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3248: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3249: );
3250: my %short_titles = &Apache::lonlocal::texthash (
3251: adminemail => 'Admin E-mail address',
3252: supportemail => 'Support E-mail',
3253: );
3254: return (\%titles,\%short_titles);
3255: }
3256:
1.72 raeburn 3257: sub tool_titles {
3258: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3259: aboutme => 'Personal web page',
1.86 raeburn 3260: blog => 'Blog',
1.162 raeburn 3261: webdav => 'WebDAV',
1.86 raeburn 3262: portfolio => 'Portfolio',
1.88 bisitz 3263: official => 'Official courses (with institutional codes)',
3264: unofficial => 'Unofficial courses',
1.98 raeburn 3265: community => 'Communities',
1.86 raeburn 3266: );
1.72 raeburn 3267: return %titles;
3268: }
3269:
1.101 raeburn 3270: sub courserequest_titles {
3271: my %titles = &Apache::lonlocal::texthash (
3272: official => 'Official',
3273: unofficial => 'Unofficial',
3274: community => 'Communities',
3275: norequest => 'Not allowed',
1.104 raeburn 3276: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3277: validate => 'With validation',
3278: autolimit => 'Numerical limit',
1.103 raeburn 3279: unlimited => '(blank for unlimited)',
1.101 raeburn 3280: );
3281: return %titles;
3282: }
3283:
1.163 raeburn 3284: sub authorrequest_titles {
3285: my %titles = &Apache::lonlocal::texthash (
3286: norequest => 'Not allowed',
3287: approval => 'Approval by Dom. Coord.',
3288: automatic => 'Automatic approval',
3289: );
3290: return %titles;
3291: }
3292:
1.101 raeburn 3293: sub courserequest_conditions {
3294: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3295: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3296: validate => '(Processing of request subject to instittutional validation).',
3297: );
3298: return %conditions;
3299: }
3300:
3301:
1.27 raeburn 3302: sub print_usercreation {
1.30 raeburn 3303: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3304: my $numinrow = 4;
1.28 raeburn 3305: my $datatable;
3306: if ($position eq 'top') {
1.30 raeburn 3307: $$rowtotal ++;
1.34 raeburn 3308: my $rowcount = 0;
1.32 raeburn 3309: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3310: if (ref($rules) eq 'HASH') {
3311: if (keys(%{$rules}) > 0) {
1.32 raeburn 3312: $datatable .= &user_formats_row('username',$settings,$rules,
3313: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3314: $$rowtotal ++;
1.32 raeburn 3315: $rowcount ++;
3316: }
3317: }
3318: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3319: if (ref($idrules) eq 'HASH') {
3320: if (keys(%{$idrules}) > 0) {
3321: $datatable .= &user_formats_row('id',$settings,$idrules,
3322: $idruleorder,$numinrow,$rowcount);
3323: $$rowtotal ++;
3324: $rowcount ++;
1.28 raeburn 3325: }
3326: }
1.43 raeburn 3327: my ($emailrules,$emailruleorder) =
3328: &Apache::lonnet::inst_userrules($dom,'email');
3329: if (ref($emailrules) eq 'HASH') {
3330: if (keys(%{$emailrules}) > 0) {
3331: $datatable .= &user_formats_row('email',$settings,$emailrules,
3332: $emailruleorder,$numinrow,$rowcount);
3333: $$rowtotal ++;
3334: $rowcount ++;
3335: }
3336: }
1.39 raeburn 3337: if ($rowcount == 0) {
3338: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3339: $$rowtotal ++;
3340: $rowcount ++;
3341: }
1.34 raeburn 3342: } elsif ($position eq 'middle') {
1.100 raeburn 3343: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3344: my ($rules,$ruleorder) =
3345: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3346: my %lt = &usercreation_types();
3347: my %checked;
1.50 raeburn 3348: my @selfcreate;
1.34 raeburn 3349: if (ref($settings) eq 'HASH') {
3350: if (ref($settings->{'cancreate'}) eq 'HASH') {
3351: foreach my $item (@creators) {
3352: $checked{$item} = $settings->{'cancreate'}{$item};
3353: }
1.50 raeburn 3354: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3355: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3356: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3357: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3358: @selfcreate = ('email','login','sso');
3359: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3360: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3361: }
3362: }
1.34 raeburn 3363: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3364: foreach my $item (@creators) {
3365: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3366: $checked{$item} = 'none';
3367: }
3368: }
3369: }
3370: }
3371: my $rownum = 0;
3372: foreach my $item (@creators) {
3373: $rownum ++;
1.50 raeburn 3374: if ($item ne 'selfcreate') {
3375: if ($checked{$item} eq '') {
1.43 raeburn 3376: $checked{$item} = 'any';
3377: }
1.34 raeburn 3378: }
3379: my $css_class;
3380: if ($rownum%2) {
3381: $css_class = '';
3382: } else {
3383: $css_class = ' class="LC_odd_row" ';
3384: }
3385: $datatable .= '<tr'.$css_class.'>'.
3386: '<td><span class="LC_nobreak">'.$lt{$item}.
3387: '</span></td><td align="right">';
1.50 raeburn 3388: my @options;
1.45 raeburn 3389: if ($item eq 'selfcreate') {
1.43 raeburn 3390: push(@options,('email','login','sso'));
3391: } else {
1.50 raeburn 3392: @options = ('any');
1.43 raeburn 3393: if (ref($rules) eq 'HASH') {
3394: if (keys(%{$rules}) > 0) {
3395: push(@options,('official','unofficial'));
3396: }
1.37 raeburn 3397: }
1.50 raeburn 3398: push(@options,'none');
1.37 raeburn 3399: }
3400: foreach my $option (@options) {
1.50 raeburn 3401: my $type = 'radio';
1.34 raeburn 3402: my $check = ' ';
1.50 raeburn 3403: if ($item eq 'selfcreate') {
3404: $type = 'checkbox';
3405: if (grep(/^\Q$option\E$/,@selfcreate)) {
3406: $check = ' checked="checked" ';
3407: }
3408: } else {
3409: if ($checked{$item} eq $option) {
3410: $check = ' checked="checked" ';
3411: }
1.34 raeburn 3412: }
3413: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3414: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3415: $item.'" value="'.$option.'"'.$check.'/> '.
3416: $lt{$option}.'</label> </span>';
3417: }
3418: $datatable .= '</td></tr>';
3419: }
1.93 raeburn 3420: my ($othertitle,$usertypes,$types) =
3421: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3422: my $createsettings;
3423: if (ref($settings) eq 'HASH') {
3424: $createsettings = $settings->{cancreate};
3425: }
1.93 raeburn 3426: if (ref($usertypes) eq 'HASH') {
3427: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3428: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3429: $dom,$numinrow,$othertitle,
3430: 'statustocreate');
3431: $$rowtotal ++;
1.169 raeburn 3432: $rownum ++;
1.93 raeburn 3433: }
3434: }
1.169 raeburn 3435: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3436: } else {
3437: my @contexts = ('author','course','domain');
3438: my @authtypes = ('int','krb4','krb5','loc');
3439: my %checked;
3440: if (ref($settings) eq 'HASH') {
3441: if (ref($settings->{'authtypes'}) eq 'HASH') {
3442: foreach my $item (@contexts) {
3443: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3444: foreach my $auth (@authtypes) {
3445: if ($settings->{'authtypes'}{$item}{$auth}) {
3446: $checked{$item}{$auth} = ' checked="checked" ';
3447: }
3448: }
3449: }
3450: }
1.27 raeburn 3451: }
1.35 raeburn 3452: } else {
3453: foreach my $item (@contexts) {
1.36 raeburn 3454: foreach my $auth (@authtypes) {
1.35 raeburn 3455: $checked{$item}{$auth} = ' checked="checked" ';
3456: }
3457: }
1.27 raeburn 3458: }
1.28 raeburn 3459: my %title = &context_names();
3460: my %authname = &authtype_names();
3461: my $rownum = 0;
3462: my $css_class;
3463: foreach my $item (@contexts) {
3464: if ($rownum%2) {
3465: $css_class = '';
3466: } else {
3467: $css_class = ' class="LC_odd_row" ';
3468: }
1.30 raeburn 3469: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3470: '<td>'.$title{$item}.
3471: '</td><td class="LC_left_item">'.
3472: '<span class="LC_nobreak">';
3473: foreach my $auth (@authtypes) {
3474: $datatable .= '<label>'.
3475: '<input type="checkbox" name="'.$item.'_auth" '.
3476: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3477: $authname{$auth}.'</label> ';
3478: }
3479: $datatable .= '</span></td></tr>';
3480: $rownum ++;
1.27 raeburn 3481: }
1.30 raeburn 3482: $$rowtotal += $rownum;
1.27 raeburn 3483: }
3484: return $datatable;
3485: }
3486:
1.165 raeburn 3487: sub captcha_choice {
1.169 raeburn 3488: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3489: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3490: my %lt = &captcha_phrases();
3491: $keyentry = 'hidden';
3492: if ($context eq 'cancreate') {
3493: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3494: } elsif ($context eq 'login') {
3495: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3496: }
3497: if (ref($settings) eq 'HASH') {
3498: if ($settings->{'captcha'}) {
3499: $checked{$settings->{'captcha'}} = ' checked="checked"';
3500: } else {
3501: $checked{'original'} = ' checked="checked"';
3502: }
3503: if ($settings->{'captcha'} eq 'recaptcha') {
3504: $pubtext = $lt{'pub'};
3505: $privtext = $lt{'priv'};
3506: $keyentry = 'text';
3507: }
3508: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3509: $currpub = $settings->{'recaptchakeys'}{'public'};
3510: $currpriv = $settings->{'recaptchakeys'}{'private'};
3511: }
3512: } else {
3513: $checked{'original'} = ' checked="checked"';
3514: }
1.169 raeburn 3515: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3516: my $output = '<tr'.$css_class.'>'.
3517: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3518: '<table><tr><td>'."\n";
3519: foreach my $option ('original','recaptcha','notused') {
3520: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3521: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3522: $lt{$option}.'</label></span>';
3523: unless ($option eq 'notused') {
3524: $output .= (' 'x2)."\n";
3525: }
3526: }
3527: #
3528: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3529: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3530: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3531: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3532: #
3533: $output .= '</td></tr>'."\n".
3534: '<tr><td>'."\n".
3535: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3536: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3537: $currpub.'" size="40" /></span><br />'."\n".
3538: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3539: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3540: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3541: '</td></tr>';
3542: return $output;
3543: }
3544:
1.32 raeburn 3545: sub user_formats_row {
3546: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3547: my $output;
3548: my %text = (
3549: 'username' => 'new usernames',
3550: 'id' => 'IDs',
1.45 raeburn 3551: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3552: );
3553: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3554: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3555: '<td><span class="LC_nobreak">';
3556: if ($type eq 'email') {
3557: $output .= &mt("Formats disallowed for $text{$type}: ");
3558: } else {
3559: $output .= &mt("Format rules to check for $text{$type}: ");
3560: }
3561: $output .= '</span></td>'.
3562: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3563: my $rem;
3564: if (ref($ruleorder) eq 'ARRAY') {
3565: for (my $i=0; $i<@{$ruleorder}; $i++) {
3566: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3567: my $rem = $i%($numinrow);
3568: if ($rem == 0) {
3569: if ($i > 0) {
3570: $output .= '</tr>';
3571: }
3572: $output .= '<tr>';
3573: }
3574: my $check = ' ';
1.39 raeburn 3575: if (ref($settings) eq 'HASH') {
3576: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3577: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3578: $check = ' checked="checked" ';
3579: }
1.27 raeburn 3580: }
3581: }
3582: $output .= '<td class="LC_left_item">'.
3583: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3584: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3585: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3586: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3587: }
3588: }
3589: $rem = @{$ruleorder}%($numinrow);
3590: }
3591: my $colsleft = $numinrow - $rem;
3592: if ($colsleft > 1 ) {
3593: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3594: ' </td>';
3595: } elsif ($colsleft == 1) {
3596: $output .= '<td class="LC_left_item"> </td>';
3597: }
3598: $output .= '</tr></table></td></tr>';
3599: return $output;
3600: }
3601:
1.34 raeburn 3602: sub usercreation_types {
3603: my %lt = &Apache::lonlocal::texthash (
3604: author => 'When adding a co-author',
3605: course => 'When adding a user to a course',
1.100 raeburn 3606: requestcrs => 'When requesting a course',
1.45 raeburn 3607: selfcreate => 'User creates own account',
1.34 raeburn 3608: any => 'Any',
3609: official => 'Institutional only ',
3610: unofficial => 'Non-institutional only',
1.85 schafran 3611: email => 'E-mail address',
1.43 raeburn 3612: login => 'Institutional Login',
3613: sso => 'SSO',
1.34 raeburn 3614: none => 'None',
3615: );
3616: return %lt;
1.48 raeburn 3617: }
1.34 raeburn 3618:
1.28 raeburn 3619: sub authtype_names {
3620: my %lt = &Apache::lonlocal::texthash(
3621: int => 'Internal',
3622: krb4 => 'Kerberos 4',
3623: krb5 => 'Kerberos 5',
3624: loc => 'Local',
3625: );
3626: return %lt;
3627: }
3628:
3629: sub context_names {
3630: my %context_title = &Apache::lonlocal::texthash(
3631: author => 'Creating users when an Author',
3632: course => 'Creating users when in a course',
3633: domain => 'Creating users when a Domain Coordinator',
3634: );
3635: return %context_title;
3636: }
3637:
1.33 raeburn 3638: sub print_usermodification {
3639: my ($position,$dom,$settings,$rowtotal) = @_;
3640: my $numinrow = 4;
3641: my ($context,$datatable,$rowcount);
3642: if ($position eq 'top') {
3643: $rowcount = 0;
3644: $context = 'author';
3645: foreach my $role ('ca','aa') {
3646: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3647: $numinrow,$rowcount);
3648: $$rowtotal ++;
3649: $rowcount ++;
3650: }
1.63 raeburn 3651: } elsif ($position eq 'middle') {
1.33 raeburn 3652: $context = 'course';
3653: $rowcount = 0;
3654: foreach my $role ('st','ep','ta','in','cr') {
3655: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3656: $numinrow,$rowcount);
3657: $$rowtotal ++;
3658: $rowcount ++;
3659: }
1.63 raeburn 3660: } elsif ($position eq 'bottom') {
3661: $context = 'selfcreate';
3662: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3663: $usertypes->{'default'} = $othertitle;
3664: if (ref($types) eq 'ARRAY') {
3665: push(@{$types},'default');
3666: $usertypes->{'default'} = $othertitle;
3667: foreach my $status (@{$types}) {
3668: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3669: $numinrow,$rowcount,$usertypes);
3670: $$rowtotal ++;
3671: $rowcount ++;
3672: }
3673: }
1.33 raeburn 3674: }
3675: return $datatable;
3676: }
3677:
1.43 raeburn 3678: sub print_defaults {
3679: my ($dom,$rowtotal) = @_;
1.68 raeburn 3680: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3681: 'datelocale_def','portal_def');
1.43 raeburn 3682: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3683: my $titles = &defaults_titles($dom);
1.43 raeburn 3684: my $rownum = 0;
3685: my ($datatable,$css_class);
3686: foreach my $item (@items) {
3687: if ($rownum%2) {
3688: $css_class = '';
3689: } else {
3690: $css_class = ' class="LC_odd_row" ';
3691: }
3692: $datatable .= '<tr'.$css_class.'>'.
3693: '<td><span class="LC_nobreak">'.$titles->{$item}.
3694: '</span></td><td class="LC_right_item">';
3695: if ($item eq 'auth_def') {
3696: my @authtypes = ('internal','krb4','krb5','localauth');
3697: my %shortauth = (
3698: internal => 'int',
3699: krb4 => 'krb4',
3700: krb5 => 'krb5',
3701: localauth => 'loc'
3702: );
3703: my %authnames = &authtype_names();
3704: foreach my $auth (@authtypes) {
3705: my $checked = ' ';
3706: if ($domdefaults{$item} eq $auth) {
3707: $checked = ' checked="checked" ';
3708: }
3709: $datatable .= '<label><input type="radio" name="'.$item.
3710: '" value="'.$auth.'"'.$checked.'/>'.
3711: $authnames{$shortauth{$auth}}.'</label> ';
3712: }
1.54 raeburn 3713: } elsif ($item eq 'timezone_def') {
3714: my $includeempty = 1;
3715: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3716: } elsif ($item eq 'datelocale_def') {
3717: my $includeempty = 1;
3718: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3719: } elsif ($item eq 'lang_def') {
1.168 raeburn 3720: my %langchoices = &get_languages_hash();
3721: $langchoices{''} = 'No language preference';
1.167 raeburn 3722: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3723: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3724: \%langchoices);
1.43 raeburn 3725: } else {
1.141 raeburn 3726: my $size;
3727: if ($item eq 'portal_def') {
3728: $size = ' size="25"';
3729: }
1.43 raeburn 3730: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3731: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3732: }
3733: $datatable .= '</td></tr>';
3734: $rownum ++;
3735: }
3736: $$rowtotal += $rownum;
3737: return $datatable;
3738: }
3739:
1.168 raeburn 3740: sub get_languages_hash {
3741: my %langchoices;
3742: foreach my $id (&Apache::loncommon::languageids()) {
3743: my $code = &Apache::loncommon::supportedlanguagecode($id);
3744: if ($code ne '') {
3745: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3746: }
3747: }
3748: return %langchoices;
3749: }
3750:
1.43 raeburn 3751: sub defaults_titles {
1.141 raeburn 3752: my ($dom) = @_;
1.43 raeburn 3753: my %titles = &Apache::lonlocal::texthash (
3754: 'auth_def' => 'Default authentication type',
3755: 'auth_arg_def' => 'Default authentication argument',
3756: 'lang_def' => 'Default language',
1.54 raeburn 3757: 'timezone_def' => 'Default timezone',
1.68 raeburn 3758: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3759: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3760: );
1.141 raeburn 3761: if ($dom) {
3762: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3763: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3764: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3765: $protocol = 'http' if ($protocol ne 'https');
3766: if ($uint_dom) {
3767: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3768: $uint_dom);
3769: }
3770: }
1.43 raeburn 3771: return (\%titles);
3772: }
3773:
1.46 raeburn 3774: sub print_scantronformat {
3775: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3776: my $itemcount = 1;
1.60 raeburn 3777: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3778: %confhash);
1.46 raeburn 3779: my $switchserver = &check_switchserver($dom,$confname);
3780: my %lt = &Apache::lonlocal::texthash (
1.95 www 3781: default => 'Default bubblesheet format file error',
3782: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3783: );
3784: my %scantronfiles = (
3785: default => 'default.tab',
3786: custom => 'custom.tab',
3787: );
3788: foreach my $key (keys(%scantronfiles)) {
3789: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3790: .$scantronfiles{$key};
3791: }
3792: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3793: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3794: if (!$switchserver) {
3795: my $servadm = $r->dir_config('lonAdmEMail');
3796: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3797: if ($configuserok eq 'ok') {
3798: if ($author_ok eq 'ok') {
3799: my %legacyfile = (
3800: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3801: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3802: );
3803: my %md5chk;
3804: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3805: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3806: chomp($md5chk{$type});
1.46 raeburn 3807: }
3808: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3809: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3810: ($scantronurls{$type},my $error) =
1.46 raeburn 3811: &legacy_scantronformat($r,$dom,$confname,
3812: $type,$legacyfile{$type},
3813: $scantronurls{$type},
3814: $scantronfiles{$type});
1.60 raeburn 3815: if ($error ne '') {
3816: $error{$type} = $error;
3817: }
3818: }
3819: if (keys(%error) == 0) {
3820: $is_custom = 1;
3821: $confhash{'scantron'}{'scantronformat'} =
3822: $scantronurls{'custom'};
3823: my $putresult =
3824: &Apache::lonnet::put_dom('configuration',
3825: \%confhash,$dom);
3826: if ($putresult ne 'ok') {
3827: $error{'custom'} =
3828: '<span class="LC_error">'.
3829: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3830: }
1.46 raeburn 3831: }
3832: } else {
1.60 raeburn 3833: ($scantronurls{'default'},my $error) =
1.46 raeburn 3834: &legacy_scantronformat($r,$dom,$confname,
3835: 'default',$legacyfile{'default'},
3836: $scantronurls{'default'},
3837: $scantronfiles{'default'});
1.60 raeburn 3838: if ($error eq '') {
3839: $confhash{'scantron'}{'scantronformat'} = '';
3840: my $putresult =
3841: &Apache::lonnet::put_dom('configuration',
3842: \%confhash,$dom);
3843: if ($putresult ne 'ok') {
3844: $error{'default'} =
3845: '<span class="LC_error">'.
3846: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3847: }
3848: } else {
3849: $error{'default'} = $error;
3850: }
1.46 raeburn 3851: }
3852: }
3853: }
3854: } else {
1.95 www 3855: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3856: }
3857: }
3858: if (ref($settings) eq 'HASH') {
3859: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3860: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3861: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3862: $scantronurl = '';
3863: } else {
3864: $scantronurl = $settings->{'scantronformat'};
3865: }
3866: $is_custom = 1;
3867: } else {
3868: $scantronurl = $scantronurls{'default'};
3869: }
3870: } else {
1.60 raeburn 3871: if ($is_custom) {
3872: $scantronurl = $scantronurls{'custom'};
3873: } else {
3874: $scantronurl = $scantronurls{'default'};
3875: }
1.46 raeburn 3876: }
3877: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3878: $datatable .= '<tr'.$css_class.'>';
3879: if (!$is_custom) {
1.65 raeburn 3880: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3881: '<span class="LC_nobreak">';
1.46 raeburn 3882: if ($scantronurl) {
3883: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3884: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3885: } else {
3886: $datatable = &mt('File unavailable for display');
3887: }
1.65 raeburn 3888: $datatable .= '</span></td>';
1.60 raeburn 3889: if (keys(%error) == 0) {
3890: $datatable .= '<td valign="bottom">';
3891: if (!$switchserver) {
3892: $datatable .= &mt('Upload:').'<br />';
3893: }
3894: } else {
3895: my $errorstr;
3896: foreach my $key (sort(keys(%error))) {
3897: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3898: }
3899: $datatable .= '<td>'.$errorstr;
3900: }
1.46 raeburn 3901: } else {
3902: if (keys(%error) > 0) {
3903: my $errorstr;
3904: foreach my $key (sort(keys(%error))) {
3905: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3906: }
1.60 raeburn 3907: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3908: } elsif ($scantronurl) {
1.65 raeburn 3909: $datatable .= '<td><span class="LC_nobreak">'.
3910: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3911: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3912: '<input type="checkbox" name="scantronformat_del"'.
3913: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3914: '<td><span class="LC_nobreak"> '.
3915: &mt('Replace:').'</span><br />';
1.46 raeburn 3916: }
3917: }
3918: if (keys(%error) == 0) {
3919: if ($switchserver) {
3920: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3921: } else {
1.65 raeburn 3922: $datatable .='<span class="LC_nobreak"> '.
3923: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3924: }
3925: }
3926: $datatable .= '</td></tr>';
3927: $$rowtotal ++;
3928: return $datatable;
3929: }
3930:
3931: sub legacy_scantronformat {
3932: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3933: my ($url,$error);
3934: my @statinfo = &Apache::lonnet::stat_file($newurl);
3935: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3936: (my $result,$url) =
3937: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3938: '','',$newfile);
3939: if ($result ne 'ok') {
1.130 raeburn 3940: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3941: }
3942: }
3943: return ($url,$error);
3944: }
1.43 raeburn 3945:
1.49 raeburn 3946: sub print_coursecategories {
1.57 raeburn 3947: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3948: my $datatable;
3949: if ($position eq 'top') {
3950: my $toggle_cats_crs = ' ';
3951: my $toggle_cats_dom = ' checked="checked" ';
3952: my $can_cat_crs = ' ';
3953: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3954: my $toggle_catscomm_comm = ' ';
3955: my $toggle_catscomm_dom = ' checked="checked" ';
3956: my $can_catcomm_comm = ' ';
3957: my $can_catcomm_dom = ' checked="checked" ';
3958:
1.57 raeburn 3959: if (ref($settings) eq 'HASH') {
3960: if ($settings->{'togglecats'} eq 'crs') {
3961: $toggle_cats_crs = $toggle_cats_dom;
3962: $toggle_cats_dom = ' ';
3963: }
3964: if ($settings->{'categorize'} eq 'crs') {
3965: $can_cat_crs = $can_cat_dom;
3966: $can_cat_dom = ' ';
3967: }
1.120 raeburn 3968: if ($settings->{'togglecatscomm'} eq 'comm') {
3969: $toggle_catscomm_comm = $toggle_catscomm_dom;
3970: $toggle_catscomm_dom = ' ';
3971: }
3972: if ($settings->{'categorizecomm'} eq 'comm') {
3973: $can_catcomm_comm = $can_catcomm_dom;
3974: $can_catcomm_dom = ' ';
3975: }
1.57 raeburn 3976: }
3977: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3978: togglecats => 'Show/Hide a course in catalog',
3979: togglecatscomm => 'Show/Hide a community in catalog',
3980: categorize => 'Assign a category to a course',
3981: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3982: );
3983: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3984: dom => 'Set in Domain',
3985: crs => 'Set in Course',
3986: comm => 'Set in Community',
1.57 raeburn 3987: );
3988: $datatable = '<tr class="LC_odd_row">'.
3989: '<td>'.$title{'togglecats'}.'</td>'.
3990: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3991: '<input type="radio" name="togglecats"'.
3992: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3993: '<label><input type="radio" name="togglecats"'.
3994: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3995: '</tr><tr>'.
3996: '<td>'.$title{'categorize'}.'</td>'.
3997: '<td class="LC_right_item"><span class="LC_nobreak">'.
3998: '<label><input type="radio" name="categorize"'.
3999: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4000: '<label><input type="radio" name="categorize"'.
4001: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4002: '</tr><tr class="LC_odd_row">'.
4003: '<td>'.$title{'togglecatscomm'}.'</td>'.
4004: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4005: '<input type="radio" name="togglecatscomm"'.
4006: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4007: '<label><input type="radio" name="togglecatscomm"'.
4008: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4009: '</tr><tr>'.
4010: '<td>'.$title{'categorizecomm'}.'</td>'.
4011: '<td class="LC_right_item"><span class="LC_nobreak">'.
4012: '<label><input type="radio" name="categorizecomm"'.
4013: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4014: '<label><input type="radio" name="categorizecomm"'.
4015: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4016: '</tr>';
1.120 raeburn 4017: $$rowtotal += 4;
1.57 raeburn 4018: } else {
4019: my $css_class;
4020: my $itemcount = 1;
4021: my $cathash;
4022: if (ref($settings) eq 'HASH') {
4023: $cathash = $settings->{'cats'};
4024: }
4025: if (ref($cathash) eq 'HASH') {
4026: my (@cats,@trails,%allitems,%idx,@jsarray);
4027: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4028: \%allitems,\%idx,\@jsarray);
4029: my $maxdepth = scalar(@cats);
4030: my $colattrib = '';
4031: if ($maxdepth > 2) {
4032: $colattrib = ' colspan="2" ';
4033: }
4034: my @path;
4035: if (@cats > 0) {
4036: if (ref($cats[0]) eq 'ARRAY') {
4037: my $numtop = @{$cats[0]};
4038: my $maxnum = $numtop;
1.120 raeburn 4039: my %default_names = (
4040: instcode => &mt('Official courses'),
4041: communities => &mt('Communities'),
4042: );
4043:
4044: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4045: ($cathash->{'instcode::0'} eq '') ||
4046: (!grep(/^communities$/,@{$cats[0]})) ||
4047: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4048: $maxnum ++;
4049: }
4050: my $lastidx;
4051: for (my $i=0; $i<$numtop; $i++) {
4052: my $parent = $cats[0][$i];
4053: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4054: my $item = &escape($parent).'::0';
4055: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4056: $lastidx = $idx{$item};
4057: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4058: .'<select name="'.$item.'"'.$chgstr.'>';
4059: for (my $k=0; $k<=$maxnum; $k++) {
4060: my $vpos = $k+1;
4061: my $selstr;
4062: if ($k == $i) {
4063: $selstr = ' selected="selected" ';
4064: }
4065: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4066: }
4067: $datatable .= '</select></td><td>';
1.120 raeburn 4068: if ($parent eq 'instcode' || $parent eq 'communities') {
4069: $datatable .= '<span class="LC_nobreak">'
4070: .$default_names{$parent}.'</span>';
4071: if ($parent eq 'instcode') {
4072: $datatable .= '<br /><span class="LC_nobreak">('
4073: .&mt('with institutional codes')
4074: .')</span></td><td'.$colattrib.'>';
4075: } else {
4076: $datatable .= '<table><tr><td>';
4077: }
4078: $datatable .= '<span class="LC_nobreak">'
4079: .'<label><input type="radio" name="'
4080: .$parent.'" value="1" checked="checked" />'
4081: .&mt('Display').'</label>';
4082: if ($parent eq 'instcode') {
4083: $datatable .= ' ';
4084: } else {
4085: $datatable .= '</span></td></tr><tr><td>'
4086: .'<span class="LC_nobreak">';
4087: }
4088: $datatable .= '<label><input type="radio" name="'
4089: .$parent.'" value="0" />'
4090: .&mt('Do not display').'</label></span>';
4091: if ($parent eq 'communities') {
4092: $datatable .= '</td></tr></table>';
4093: }
4094: $datatable .= '</td>';
1.57 raeburn 4095: } else {
4096: $datatable .= $parent
4097: .' <label><input type="checkbox" name="deletecategory" '
4098: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4099: }
4100: my $depth = 1;
4101: push(@path,$parent);
4102: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4103: pop(@path);
4104: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4105: $itemcount ++;
4106: }
1.48 raeburn 4107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4108: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4109: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4110: for (my $k=0; $k<=$maxnum; $k++) {
4111: my $vpos = $k+1;
4112: my $selstr;
1.57 raeburn 4113: if ($k == $numtop) {
1.48 raeburn 4114: $selstr = ' selected="selected" ';
4115: }
4116: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4117: }
1.59 bisitz 4118: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4119: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4120: .'</tr>'."\n";
1.48 raeburn 4121: $itemcount ++;
1.120 raeburn 4122: foreach my $default ('instcode','communities') {
4123: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4124: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4125: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4126: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4127: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4128: for (my $k=0; $k<=$maxnum; $k++) {
4129: my $vpos = $k+1;
4130: my $selstr;
4131: if ($k == $maxnum) {
4132: $selstr = ' selected="selected" ';
4133: }
4134: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4135: }
1.120 raeburn 4136: $datatable .= '</select></span></td>'.
4137: '<td><span class="LC_nobreak">'.
4138: $default_names{$default}.'</span>';
4139: if ($default eq 'instcode') {
4140: $datatable .= '<br /><span class="LC_nobreak">('
4141: .&mt('with institutional codes').')</span>';
4142: }
4143: $datatable .= '</td>'
4144: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4145: .&mt('Display').'</label> '
4146: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4147: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4148: }
4149: }
4150: }
1.57 raeburn 4151: } else {
4152: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4153: }
4154: } else {
1.57 raeburn 4155: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4156: .&initialize_categories($itemcount);
1.48 raeburn 4157: }
1.57 raeburn 4158: $$rowtotal += $itemcount;
1.48 raeburn 4159: }
4160: return $datatable;
4161: }
4162:
1.69 raeburn 4163: sub print_serverstatuses {
4164: my ($dom,$settings,$rowtotal) = @_;
4165: my $datatable;
4166: my @pages = &serverstatus_pages();
4167: my (%namedaccess,%machineaccess);
4168: foreach my $type (@pages) {
4169: $namedaccess{$type} = '';
4170: $machineaccess{$type}= '';
4171: }
4172: if (ref($settings) eq 'HASH') {
4173: foreach my $type (@pages) {
4174: if (exists($settings->{$type})) {
4175: if (ref($settings->{$type}) eq 'HASH') {
4176: foreach my $key (keys(%{$settings->{$type}})) {
4177: if ($key eq 'namedusers') {
4178: $namedaccess{$type} = $settings->{$type}->{$key};
4179: } elsif ($key eq 'machines') {
4180: $machineaccess{$type} = $settings->{$type}->{$key};
4181: }
4182: }
4183: }
4184: }
4185: }
4186: }
1.81 raeburn 4187: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4188: my $rownum = 0;
4189: my $css_class;
4190: foreach my $type (@pages) {
4191: $rownum ++;
4192: $css_class = $rownum%2?' class="LC_odd_row"':'';
4193: $datatable .= '<tr'.$css_class.'>'.
4194: '<td><span class="LC_nobreak">'.
4195: $titles->{$type}.'</span></td>'.
4196: '<td class="LC_left_item">'.
4197: '<input type="text" name="'.$type.'_namedusers" '.
4198: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4199: '<td class="LC_right_item">'.
4200: '<span class="LC_nobreak">'.
4201: '<input type="text" name="'.$type.'_machines" '.
4202: 'value="'.$machineaccess{$type}.'" size="10" />'.
4203: '</td></tr>'."\n";
4204: }
4205: $$rowtotal += $rownum;
4206: return $datatable;
4207: }
4208:
4209: sub serverstatus_pages {
4210: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4211: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4212: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4213: }
4214:
1.49 raeburn 4215: sub coursecategories_javascript {
4216: my ($settings) = @_;
1.57 raeburn 4217: my ($output,$jstext,$cathash);
1.49 raeburn 4218: if (ref($settings) eq 'HASH') {
1.57 raeburn 4219: $cathash = $settings->{'cats'};
4220: }
4221: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4222: my (@cats,@jsarray,%idx);
1.57 raeburn 4223: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4224: if (@jsarray > 0) {
4225: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4226: for (my $i=0; $i<@jsarray; $i++) {
4227: if (ref($jsarray[$i]) eq 'ARRAY') {
4228: my $catstr = join('","',@{$jsarray[$i]});
4229: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4230: }
4231: }
4232: }
4233: } else {
4234: $jstext = ' var categories = Array(1);'."\n".
4235: ' categories[0] = Array("instcode_pos");'."\n";
4236: }
1.120 raeburn 4237: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4238: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4239: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4240: $output = <<"ENDSCRIPT";
4241: <script type="text/javascript">
1.109 raeburn 4242: // <![CDATA[
1.49 raeburn 4243: function reorderCats(form,parent,item,idx) {
4244: var changedVal;
4245: $jstext
4246: var newpos = 'addcategory_pos';
4247: var current = new Array;
4248: if (parent == '') {
4249: var has_instcode = 0;
4250: var maxtop = categories[idx].length;
4251: for (var j=0; j<maxtop; j++) {
4252: if (categories[idx][j] == 'instcode::0') {
4253: has_instcode == 1;
4254: }
4255: }
4256: if (has_instcode == 0) {
4257: categories[idx][maxtop] = 'instcode_pos';
4258: }
4259: } else {
4260: newpos += '_'+parent;
4261: }
4262: var maxh = 1 + categories[idx].length;
4263: var current = new Array;
4264: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4265: if (item == newpos) {
4266: changedVal = newitemVal;
4267: } else {
4268: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4269: current[newitemVal] = newpos;
4270: }
4271: for (var i=0; i<categories[idx].length; i++) {
4272: var elementName = categories[idx][i];
4273: if (elementName != item) {
4274: if (form.elements[elementName]) {
4275: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4276: current[currVal] = elementName;
4277: }
4278: }
4279: }
4280: var oldVal;
4281: for (var j=0; j<maxh; j++) {
4282: if (current[j] == undefined) {
4283: oldVal = j;
4284: }
4285: }
4286: if (oldVal < changedVal) {
4287: for (var k=oldVal+1; k<=changedVal ; k++) {
4288: var elementName = current[k];
4289: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4290: }
4291: } else {
4292: for (var k=changedVal; k<oldVal; k++) {
4293: var elementName = current[k];
4294: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4295: }
4296: }
4297: return;
4298: }
1.120 raeburn 4299:
4300: function categoryCheck(form) {
4301: if (form.elements['addcategory_name'].value == 'instcode') {
4302: alert('$instcode_reserved\\n$choose_again');
4303: return false;
4304: }
4305: if (form.elements['addcategory_name'].value == 'communities') {
4306: alert('$communities_reserved\\n$choose_again');
4307: return false;
4308: }
4309: return true;
4310: }
4311:
1.109 raeburn 4312: // ]]>
1.49 raeburn 4313: </script>
4314:
4315: ENDSCRIPT
4316: return $output;
4317: }
4318:
1.48 raeburn 4319: sub initialize_categories {
4320: my ($itemcount) = @_;
1.120 raeburn 4321: my ($datatable,$css_class,$chgstr);
4322: my %default_names = (
4323: instcode => 'Official courses (with institutional codes)',
4324: communities => 'Communities',
4325: );
4326: my $select0 = ' selected="selected"';
4327: my $select1 = '';
4328: foreach my $default ('instcode','communities') {
4329: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4330: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4331: if ($default eq 'communities') {
4332: $select1 = $select0;
4333: $select0 = '';
4334: }
4335: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4336: .'<select name="'.$default.'_pos">'
4337: .'<option value="0"'.$select0.'>1</option>'
4338: .'<option value="1"'.$select1.'>2</option>'
4339: .'<option value="2">3</option></select> '
4340: .$default_names{$default}
4341: .'</span></td><td><span class="LC_nobreak">'
4342: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4343: .&mt('Display').'</label> <label>'
4344: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4345: .'</label></span></td></tr>';
1.120 raeburn 4346: $itemcount ++;
4347: }
1.48 raeburn 4348: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4349: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4350: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4351: .'<select name="addcategory_pos"'.$chgstr.'>'
4352: .'<option value="0">1</option>'
4353: .'<option value="1">2</option>'
4354: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4355: .&mt('Add category').'</td><td>'.&mt('Name:')
4356: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4357: return $datatable;
4358: }
4359:
4360: sub build_category_rows {
1.49 raeburn 4361: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4362: my ($text,$name,$item,$chgstr);
1.48 raeburn 4363: if (ref($cats) eq 'ARRAY') {
4364: my $maxdepth = scalar(@{$cats});
4365: if (ref($cats->[$depth]) eq 'HASH') {
4366: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4367: my $numchildren = @{$cats->[$depth]{$parent}};
4368: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4369: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4370: my ($idxnum,$parent_name,$parent_item);
4371: my $higher = $depth - 1;
4372: if ($higher == 0) {
4373: $parent_name = &escape($parent).'::'.$higher;
4374: } else {
4375: if (ref($path) eq 'ARRAY') {
4376: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4377: }
4378: }
4379: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4380: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4381: if ($j < $numchildren) {
1.48 raeburn 4382: $name = $cats->[$depth]{$parent}[$j];
4383: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4384: $idxnum = $idx->{$item};
4385: } else {
4386: $name = $parent_name;
4387: $item = $parent_item;
1.48 raeburn 4388: }
1.49 raeburn 4389: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4390: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4391: for (my $i=0; $i<=$numchildren; $i++) {
4392: my $vpos = $i+1;
4393: my $selstr;
4394: if ($j == $i) {
4395: $selstr = ' selected="selected" ';
4396: }
4397: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4398: }
4399: $text .= '</select> ';
4400: if ($j < $numchildren) {
4401: my $deeper = $depth+1;
4402: $text .= $name.' '
4403: .'<label><input type="checkbox" name="deletecategory" value="'
4404: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4405: if(ref($path) eq 'ARRAY') {
4406: push(@{$path},$name);
1.49 raeburn 4407: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4408: pop(@{$path});
4409: }
4410: } else {
1.59 bisitz 4411: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4412: if ($j == $numchildren) {
4413: $text .= $name;
4414: } else {
4415: $text .= $item;
4416: }
4417: $text .= '" value="" />';
4418: }
4419: $text .= '</td></tr>';
4420: }
4421: $text .= '</table></td>';
4422: } else {
4423: my $higher = $depth-1;
4424: if ($higher == 0) {
4425: $name = &escape($parent).'::'.$higher;
4426: } else {
4427: if (ref($path) eq 'ARRAY') {
4428: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4429: }
4430: }
4431: my $colspan;
4432: if ($parent ne 'instcode') {
4433: $colspan = $maxdepth - $depth - 1;
4434: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4435: }
4436: }
4437: }
4438: }
4439: return $text;
4440: }
4441:
1.33 raeburn 4442: sub modifiable_userdata_row {
1.63 raeburn 4443: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4444: my $rolename;
1.63 raeburn 4445: if ($context eq 'selfcreate') {
4446: if (ref($usertypes) eq 'HASH') {
4447: $rolename = $usertypes->{$role};
4448: } else {
4449: $rolename = $role;
4450: }
1.33 raeburn 4451: } else {
1.63 raeburn 4452: if ($role eq 'cr') {
4453: $rolename = &mt('Custom role');
4454: } else {
4455: $rolename = &Apache::lonnet::plaintext($role);
4456: }
1.33 raeburn 4457: }
4458: my @fields = ('lastname','firstname','middlename','generation',
4459: 'permanentemail','id');
4460: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4461: my $output;
4462: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4463: $output = '<tr '.$css_class.'>'.
4464: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4465: '<td class="LC_left_item" colspan="2"><table>';
4466: my $rem;
4467: my %checks;
4468: if (ref($settings) eq 'HASH') {
4469: if (ref($settings->{$context}) eq 'HASH') {
4470: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4471: foreach my $field (@fields) {
4472: if ($settings->{$context}->{$role}->{$field}) {
4473: $checks{$field} = ' checked="checked" ';
4474: }
4475: }
4476: }
4477: }
4478: }
4479: for (my $i=0; $i<@fields; $i++) {
4480: my $rem = $i%($numinrow);
4481: if ($rem == 0) {
4482: if ($i > 0) {
4483: $output .= '</tr>';
4484: }
4485: $output .= '<tr>';
4486: }
4487: my $check = ' ';
4488: if (exists($checks{$fields[$i]})) {
4489: $check = $checks{$fields[$i]}
4490: } else {
4491: if ($role eq 'st') {
4492: if (ref($settings) ne 'HASH') {
4493: $check = ' checked="checked" ';
4494: }
4495: }
4496: }
4497: $output .= '<td class="LC_left_item">'.
4498: '<span class="LC_nobreak"><label>'.
4499: '<input type="checkbox" name="canmodify_'.$role.'" '.
4500: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4501: '</label></span></td>';
4502: $rem = @fields%($numinrow);
4503: }
4504: my $colsleft = $numinrow - $rem;
4505: if ($colsleft > 1 ) {
4506: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4507: ' </td>';
4508: } elsif ($colsleft == 1) {
4509: $output .= '<td class="LC_left_item"> </td>';
4510: }
4511: $output .= '</tr></table></td></tr>';
4512: return $output;
4513: }
1.28 raeburn 4514:
1.93 raeburn 4515: sub insttypes_row {
4516: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4517: my %lt = &Apache::lonlocal::texthash (
4518: cansearch => 'Users allowed to search',
4519: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4520: lockablenames => 'User preference to lock name',
1.93 raeburn 4521: );
4522: my $showdom;
4523: if ($context eq 'cansearch') {
4524: $showdom = ' ('.$dom.')';
4525: }
1.165 raeburn 4526: my $class = 'LC_left_item';
4527: if ($context eq 'statustocreate') {
4528: $class = 'LC_right_item';
4529: }
1.25 raeburn 4530: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4531: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4532: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4533: my $rem;
4534: if (ref($types) eq 'ARRAY') {
4535: for (my $i=0; $i<@{$types}; $i++) {
4536: if (defined($usertypes->{$types->[$i]})) {
4537: my $rem = $i%($numinrow);
4538: if ($rem == 0) {
4539: if ($i > 0) {
4540: $output .= '</tr>';
4541: }
4542: $output .= '<tr>';
1.23 raeburn 4543: }
1.26 raeburn 4544: my $check = ' ';
1.99 raeburn 4545: if (ref($settings) eq 'HASH') {
4546: if (ref($settings->{$context}) eq 'ARRAY') {
4547: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4548: $check = ' checked="checked" ';
4549: }
4550: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4551: $check = ' checked="checked" ';
4552: }
1.23 raeburn 4553: }
1.26 raeburn 4554: $output .= '<td class="LC_left_item">'.
4555: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4556: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4557: 'value="'.$types->[$i].'"'.$check.'/>'.
4558: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4559: }
4560: }
1.26 raeburn 4561: $rem = @{$types}%($numinrow);
1.23 raeburn 4562: }
4563: my $colsleft = $numinrow - $rem;
1.131 raeburn 4564: if (($rem == 0) && (@{$types} > 0)) {
4565: $output .= '<tr>';
4566: }
1.23 raeburn 4567: if ($colsleft > 1) {
1.25 raeburn 4568: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4569: } else {
1.25 raeburn 4570: $output .= '<td class="LC_left_item">';
1.23 raeburn 4571: }
4572: my $defcheck = ' ';
1.99 raeburn 4573: if (ref($settings) eq 'HASH') {
4574: if (ref($settings->{$context}) eq 'ARRAY') {
4575: if (grep(/^default$/,@{$settings->{$context}})) {
4576: $defcheck = ' checked="checked" ';
4577: }
4578: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4579: $defcheck = ' checked="checked" ';
4580: }
1.23 raeburn 4581: }
1.25 raeburn 4582: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4583: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4584: 'value="default"'.$defcheck.'/>'.
4585: $othertitle.'</label></span></td>'.
4586: '</tr></table></td></tr>';
4587: return $output;
1.23 raeburn 4588: }
4589:
4590: sub sorted_searchtitles {
4591: my %searchtitles = &Apache::lonlocal::texthash(
4592: 'uname' => 'username',
4593: 'lastname' => 'last name',
4594: 'lastfirst' => 'last name, first name',
4595: );
4596: my @titleorder = ('uname','lastname','lastfirst');
4597: return (\%searchtitles,\@titleorder);
4598: }
4599:
1.25 raeburn 4600: sub sorted_searchtypes {
4601: my %srchtypes_desc = (
4602: exact => 'is exact match',
4603: contains => 'contains ..',
4604: begins => 'begins with ..',
4605: );
4606: my @srchtypeorder = ('exact','begins','contains');
4607: return (\%srchtypes_desc,\@srchtypeorder);
4608: }
4609:
1.3 raeburn 4610: sub usertype_update_row {
4611: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4612: my $datatable;
4613: my $numinrow = 4;
4614: foreach my $type (@{$types}) {
4615: if (defined($usertypes->{$type})) {
4616: $$rownums ++;
4617: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4618: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4619: '</td><td class="LC_left_item"><table>';
4620: for (my $i=0; $i<@{$fields}; $i++) {
4621: my $rem = $i%($numinrow);
4622: if ($rem == 0) {
4623: if ($i > 0) {
4624: $datatable .= '</tr>';
4625: }
4626: $datatable .= '<tr>';
4627: }
4628: my $check = ' ';
1.39 raeburn 4629: if (ref($settings) eq 'HASH') {
4630: if (ref($settings->{'fields'}) eq 'HASH') {
4631: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4632: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4633: $check = ' checked="checked" ';
4634: }
1.3 raeburn 4635: }
4636: }
4637: }
4638:
4639: if ($i == @{$fields}-1) {
4640: my $colsleft = $numinrow - $rem;
4641: if ($colsleft > 1) {
4642: $datatable .= '<td colspan="'.$colsleft.'">';
4643: } else {
4644: $datatable .= '<td>';
4645: }
4646: } else {
4647: $datatable .= '<td>';
4648: }
1.8 raeburn 4649: $datatable .= '<span class="LC_nobreak"><label>'.
4650: '<input type="checkbox" name="updateable_'.$type.
4651: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4652: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4653: }
4654: $datatable .= '</tr></table></td></tr>';
4655: }
4656: }
4657: return $datatable;
1.1 raeburn 4658: }
4659:
4660: sub modify_login {
1.9 raeburn 4661: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4662: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4663: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4664: %title = ( coursecatalog => 'Display course catalog',
4665: adminmail => 'Display administrator E-mail address',
4666: newuser => 'Link for visitors to create a user account',
4667: loginheader => 'Log-in box header');
4668: @offon = ('off','on');
1.112 raeburn 4669: if (ref($domconfig{login}) eq 'HASH') {
4670: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4671: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4672: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4673: }
4674: }
4675: }
1.9 raeburn 4676: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4677: \%domconfig,\%loginhash);
1.118 jms 4678: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4679: foreach my $item (@toggles) {
4680: $loginhash{login}{$item} = $env{'form.'.$item};
4681: }
1.41 raeburn 4682: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4683: if (ref($colchanges{'login'}) eq 'HASH') {
4684: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4685: \%loginhash);
4686: }
1.110 raeburn 4687:
1.149 raeburn 4688: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4689: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4690: if (keys(%servers) > 1) {
4691: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4692: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4693: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4694: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4695: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4696: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4697: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4698: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4699: $changes{'loginvia'}{$lonhost} = 1;
4700: } else {
4701: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4702: $changes{'loginvia'}{$lonhost} = 1;
4703: }
4704: } else {
4705: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4706: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4707: $changes{'loginvia'}{$lonhost} = 1;
4708: }
4709: }
4710: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4711: foreach my $item (@loginvia_attribs) {
4712: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4713: }
4714: } else {
4715: foreach my $item (@loginvia_attribs) {
4716: my $new = $env{'form.'.$lonhost.'_'.$item};
4717: if (($item eq 'serverpath') && ($new eq 'custom')) {
4718: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4719: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4720: $new = '/';
4721: }
4722: }
4723: if (($item eq 'custompath') &&
4724: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4725: $new = '';
4726: }
4727: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4728: $changes{'loginvia'}{$lonhost} = 1;
4729: }
4730: if ($item eq 'exempt') {
4731: $new =~ s/^\s+//;
4732: $new =~ s/\s+$//;
4733: my @poss_ips = split(/\s*[,:]\s*/,$new);
4734: my @okips;
4735: foreach my $ip (@poss_ips) {
4736: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4737: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4738: push(@okips,$ip);
4739: }
4740: }
4741: }
4742: if (@okips > 0) {
4743: $new = join(',',@okips);
4744: } else {
4745: $new = '';
4746: }
4747: }
4748: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4749: }
4750: }
1.112 raeburn 4751: } else {
1.128 raeburn 4752: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4753: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4754: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4755: foreach my $item (@loginvia_attribs) {
4756: my $new = $env{'form.'.$lonhost.'_'.$item};
4757: if (($item eq 'serverpath') && ($new eq 'custom')) {
4758: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4759: $new = '/';
4760: }
4761: }
4762: if (($item eq 'custompath') &&
4763: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4764: $new = '';
4765: }
4766: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4767: }
1.110 raeburn 4768: }
4769: }
4770: }
4771: }
1.119 raeburn 4772:
1.168 raeburn 4773: my $servadm = $r->dir_config('lonAdmEMail');
4774: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4775: if (ref($domconfig{'login'}) eq 'HASH') {
4776: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4777: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4778: if ($lang eq 'nolang') {
4779: push(@currlangs,$lang);
4780: } elsif (defined($langchoices{$lang})) {
4781: push(@currlangs,$lang);
4782: } else {
4783: next;
4784: }
4785: }
4786: }
4787: }
4788: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4789: if (@currlangs > 0) {
4790: foreach my $lang (@currlangs) {
4791: if (grep(/^\Q$lang\E$/,@delurls)) {
4792: $changes{'helpurl'}{$lang} = 1;
4793: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4794: $changes{'helpurl'}{$lang} = 1;
4795: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4796: push(@newlangs,$lang);
4797: } else {
4798: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4799: }
4800: }
4801: }
4802: unless (grep(/^nolang$/,@currlangs)) {
4803: if ($env{'form.loginhelpurl_nolang.filename'}) {
4804: $changes{'helpurl'}{'nolang'} = 1;
4805: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4806: push(@newlangs,'nolang');
4807: }
4808: }
4809: if ($env{'form.loginhelpurl_add_lang'}) {
4810: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4811: ($env{'form.loginhelpurl_add_file.filename'})) {
4812: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4813: $addedfile = $env{'form.loginhelpurl_add_lang'};
4814: }
4815: }
4816: if ((@newlangs > 0) || ($addedfile)) {
4817: my $error;
4818: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4819: if ($configuserok eq 'ok') {
4820: if ($switchserver) {
4821: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4822: } elsif ($author_ok eq 'ok') {
4823: my @allnew = @newlangs;
4824: if ($addedfile ne '') {
4825: push(@allnew,$addedfile);
4826: }
4827: foreach my $lang (@allnew) {
4828: my $formelem = 'loginhelpurl_'.$lang;
4829: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4830: $formelem = 'loginhelpurl_add_file';
4831: }
4832: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4833: "help/$lang",'','',$newfile{$lang});
4834: if ($result eq 'ok') {
4835: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4836: $changes{'helpurl'}{$lang} = 1;
4837: } else {
4838: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4839: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4840: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4841: (!grep(/^\Q$lang\E$/,@delurls))) {
4842:
4843: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4844: }
4845: }
4846: }
4847: } else {
4848: $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);
4849: }
4850: } else {
4851: $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);
4852: }
4853: if ($error) {
4854: &Apache::lonnet::logthis($error);
4855: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4856: }
4857: }
1.169 raeburn 4858: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4859:
4860: my $defaulthelpfile = '/adm/loginproblems.html';
4861: my $defaulttext = &mt('Default in use');
4862:
1.1 raeburn 4863: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4864: $dom);
4865: if ($putresult eq 'ok') {
1.118 jms 4866: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4867: my %defaultchecked = (
4868: 'coursecatalog' => 'on',
4869: 'adminmail' => 'off',
1.43 raeburn 4870: 'newuser' => 'off',
1.42 raeburn 4871: );
1.55 raeburn 4872: if (ref($domconfig{'login'}) eq 'HASH') {
4873: foreach my $item (@toggles) {
4874: if ($defaultchecked{$item} eq 'on') {
4875: if (($domconfig{'login'}{$item} eq '0') &&
4876: ($env{'form.'.$item} eq '1')) {
4877: $changes{$item} = 1;
4878: } elsif (($domconfig{'login'}{$item} eq '' ||
4879: $domconfig{'login'}{$item} eq '1') &&
4880: ($env{'form.'.$item} eq '0')) {
4881: $changes{$item} = 1;
4882: }
4883: } elsif ($defaultchecked{$item} eq 'off') {
4884: if (($domconfig{'login'}{$item} eq '1') &&
4885: ($env{'form.'.$item} eq '0')) {
4886: $changes{$item} = 1;
4887: } elsif (($domconfig{'login'}{$item} eq '' ||
4888: $domconfig{'login'}{$item} eq '0') &&
4889: ($env{'form.'.$item} eq '1')) {
4890: $changes{$item} = 1;
4891: }
1.42 raeburn 4892: }
4893: }
1.41 raeburn 4894: }
1.6 raeburn 4895: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4896: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4897: $resulttext = &mt('Changes made:').'<ul>';
4898: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4899: if ($item eq 'loginvia') {
1.112 raeburn 4900: if (ref($changes{$item}) eq 'HASH') {
4901: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4902: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4903: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4904: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4905: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4906: $protocol = 'http' if ($protocol ne 'https');
4907: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4908:
4909: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4910: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4911: } else {
4912: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4913: }
4914: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4915: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4916: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4917: }
4918: $resulttext .= '</li>';
4919: } else {
4920: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4921: }
1.112 raeburn 4922: } else {
1.128 raeburn 4923: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4924: }
4925: }
1.128 raeburn 4926: $resulttext .= '</ul></li>';
1.112 raeburn 4927: }
1.168 raeburn 4928: } elsif ($item eq 'helpurl') {
4929: if (ref($changes{$item}) eq 'HASH') {
4930: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4931: if (grep(/^\Q$lang\E$/,@delurls)) {
4932: my ($chg,$link);
4933: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4934: if ($lang eq 'nolang') {
4935: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4936: } else {
4937: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4938: }
4939: $resulttext .= '<li>'.$chg.'</li>';
4940: } else {
4941: my $chg;
4942: if ($lang eq 'nolang') {
4943: $chg = &mt('custom log-in help file for no preferred language');
4944: } else {
4945: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4946: }
4947: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4948: $loginhash{'login'}{'helpurl'}{$lang}.
4949: '?inhibitmenu=yes',$chg,600,500).
4950: '</li>';
4951: }
4952: }
4953: }
1.169 raeburn 4954: } elsif ($item eq 'captcha') {
4955: if (ref($loginhash{'login'}) eq 'HASH') {
4956: my $chgtxt;
4957: if ($loginhash{'login'}{$item} eq 'notused') {
4958: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4959: } else {
4960: my %captchas = &captcha_phrases();
4961: if ($captchas{$loginhash{'login'}{$item}}) {
4962: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4963: } else {
4964: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4965: }
4966: }
4967: $resulttext .= '<li>'.$chgtxt.'</li>';
4968: }
4969: } elsif ($item eq 'recaptchakeys') {
4970: if (ref($loginhash{'login'}) eq 'HASH') {
4971: my ($privkey,$pubkey);
4972: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4973: $pubkey = $loginhash{'login'}{$item}{'public'};
4974: $privkey = $loginhash{'login'}{$item}{'private'};
4975: }
4976: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4977: if (!$pubkey) {
4978: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4979: } else {
4980: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4981: }
4982: if (!$privkey) {
4983: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4984: } else {
4985: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4986: }
4987: $chgtxt .= '</ul>';
4988: $resulttext .= '<li>'.$chgtxt.'</li>';
4989: }
1.41 raeburn 4990: } else {
4991: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4992: }
1.1 raeburn 4993: }
1.6 raeburn 4994: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4995: } else {
4996: $resulttext = &mt('No changes made to log-in page settings');
4997: }
4998: } else {
1.11 albertel 4999: $resulttext = '<span class="LC_error">'.
5000: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5001: }
1.6 raeburn 5002: if ($errors) {
1.9 raeburn 5003: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5004: $errors.'</ul>';
5005: }
5006: return $resulttext;
5007: }
5008:
5009: sub color_font_choices {
5010: my %choices =
5011: &Apache::lonlocal::texthash (
5012: img => "Header",
5013: bgs => "Background colors",
5014: links => "Link colors",
1.55 raeburn 5015: images => "Images",
1.6 raeburn 5016: font => "Font color",
1.97 tempelho 5017: fontmenu => "Font Menu",
1.76 raeburn 5018: pgbg => "Page",
1.6 raeburn 5019: tabbg => "Header",
5020: sidebg => "Border",
5021: link => "Link",
5022: alink => "Active link",
5023: vlink => "Visited link",
5024: );
5025: return %choices;
5026: }
5027:
5028: sub modify_rolecolors {
1.9 raeburn 5029: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5030: my ($resulttext,%rolehash);
5031: $rolehash{'rolecolors'} = {};
1.55 raeburn 5032: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5033: if ($domconfig{'rolecolors'} eq '') {
5034: $domconfig{'rolecolors'} = {};
5035: }
5036: }
1.9 raeburn 5037: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5038: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5039: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5040: $dom);
5041: if ($putresult eq 'ok') {
5042: if (keys(%changes) > 0) {
1.41 raeburn 5043: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5044: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5045: $rolehash{'rolecolors'});
5046: } else {
5047: $resulttext = &mt('No changes made to default color schemes');
5048: }
5049: } else {
1.11 albertel 5050: $resulttext = '<span class="LC_error">'.
5051: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5052: }
5053: if ($errors) {
5054: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5055: $errors.'</ul>';
5056: }
5057: return $resulttext;
5058: }
5059:
5060: sub modify_colors {
1.9 raeburn 5061: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5062: my (%changes,%choices);
1.51 raeburn 5063: my @bgs;
1.6 raeburn 5064: my @links = ('link','alink','vlink');
1.41 raeburn 5065: my @logintext;
1.6 raeburn 5066: my @images;
5067: my $servadm = $r->dir_config('lonAdmEMail');
5068: my $errors;
5069: foreach my $role (@{$roles}) {
5070: if ($role eq 'login') {
1.12 raeburn 5071: %choices = &login_choices();
1.41 raeburn 5072: @logintext = ('textcol','bgcol');
1.12 raeburn 5073: } else {
5074: %choices = &color_font_choices();
1.107 raeburn 5075: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5076: }
5077: if ($role eq 'login') {
1.41 raeburn 5078: @images = ('img','logo','domlogo','login');
1.51 raeburn 5079: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5080: } else {
5081: @images = ('img');
1.51 raeburn 5082: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5083: }
5084: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5085: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5086: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5087: }
1.46 raeburn 5088: my ($configuserok,$author_ok,$switchserver) =
5089: &config_check($dom,$confname,$servadm);
1.9 raeburn 5090: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5091: if (ref($domconfig->{$role}) ne 'HASH') {
5092: $domconfig->{$role} = {};
5093: }
1.8 raeburn 5094: foreach my $img (@images) {
1.70 raeburn 5095: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5096: if (defined($env{'form.login_showlogo_'.$img})) {
5097: $confhash->{$role}{'showlogo'}{$img} = 1;
5098: } else {
5099: $confhash->{$role}{'showlogo'}{$img} = 0;
5100: }
5101: }
1.18 albertel 5102: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5103: && !defined($domconfig->{$role}{$img})
5104: && !$env{'form.'.$role.'_del_'.$img}
5105: && $env{'form.'.$role.'_import_'.$img}) {
5106: # import the old configured image from the .tab setting
5107: # if they haven't provided a new one
5108: $domconfig->{$role}{$img} =
5109: $env{'form.'.$role.'_import_'.$img};
5110: }
1.6 raeburn 5111: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5112: my $error;
1.6 raeburn 5113: if ($configuserok eq 'ok') {
1.9 raeburn 5114: if ($switchserver) {
1.12 raeburn 5115: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5116: } else {
5117: if ($author_ok eq 'ok') {
5118: my ($result,$logourl) =
5119: &publishlogo($r,'upload',$role.'_'.$img,
5120: $dom,$confname,$img,$width,$height);
5121: if ($result eq 'ok') {
5122: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5123: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5124: } else {
1.12 raeburn 5125: $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 5126: }
5127: } else {
1.46 raeburn 5128: $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 5129: }
5130: }
5131: } else {
1.46 raeburn 5132: $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 5133: }
5134: if ($error) {
1.8 raeburn 5135: &Apache::lonnet::logthis($error);
1.11 albertel 5136: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5137: }
5138: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5139: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5140: my $error;
5141: if ($configuserok eq 'ok') {
5142: # is confname an author?
5143: if ($switchserver eq '') {
5144: if ($author_ok eq 'ok') {
5145: my ($result,$logourl) =
5146: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5147: $dom,$confname,$img,$width,$height);
5148: if ($result eq 'ok') {
5149: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5150: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5151: }
5152: }
5153: }
5154: }
1.6 raeburn 5155: }
5156: }
5157: }
5158: if (ref($domconfig) eq 'HASH') {
5159: if (ref($domconfig->{$role}) eq 'HASH') {
5160: foreach my $img (@images) {
5161: if ($domconfig->{$role}{$img} ne '') {
5162: if ($env{'form.'.$role.'_del_'.$img}) {
5163: $confhash->{$role}{$img} = '';
1.12 raeburn 5164: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5165: } else {
1.9 raeburn 5166: if ($confhash->{$role}{$img} eq '') {
5167: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5168: }
1.6 raeburn 5169: }
5170: } else {
5171: if ($env{'form.'.$role.'_del_'.$img}) {
5172: $confhash->{$role}{$img} = '';
1.12 raeburn 5173: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5174: }
5175: }
1.70 raeburn 5176: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5177: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5178: if ($confhash->{$role}{'showlogo'}{$img} ne
5179: $domconfig->{$role}{'showlogo'}{$img}) {
5180: $changes{$role}{'showlogo'}{$img} = 1;
5181: }
5182: } else {
5183: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5184: $changes{$role}{'showlogo'}{$img} = 1;
5185: }
5186: }
5187: }
5188: }
1.6 raeburn 5189: if ($domconfig->{$role}{'font'} ne '') {
5190: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5191: $changes{$role}{'font'} = 1;
5192: }
5193: } else {
5194: if ($confhash->{$role}{'font'}) {
5195: $changes{$role}{'font'} = 1;
5196: }
5197: }
1.107 raeburn 5198: if ($role ne 'login') {
5199: if ($domconfig->{$role}{'fontmenu'} ne '') {
5200: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5201: $changes{$role}{'fontmenu'} = 1;
5202: }
5203: } else {
5204: if ($confhash->{$role}{'fontmenu'}) {
5205: $changes{$role}{'fontmenu'} = 1;
5206: }
1.97 tempelho 5207: }
5208: }
1.6 raeburn 5209: foreach my $item (@bgs) {
5210: if ($domconfig->{$role}{$item} ne '') {
5211: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5212: $changes{$role}{'bgs'}{$item} = 1;
5213: }
5214: } else {
5215: if ($confhash->{$role}{$item}) {
5216: $changes{$role}{'bgs'}{$item} = 1;
5217: }
5218: }
5219: }
5220: foreach my $item (@links) {
5221: if ($domconfig->{$role}{$item} ne '') {
5222: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5223: $changes{$role}{'links'}{$item} = 1;
5224: }
5225: } else {
5226: if ($confhash->{$role}{$item}) {
5227: $changes{$role}{'links'}{$item} = 1;
5228: }
5229: }
5230: }
1.41 raeburn 5231: foreach my $item (@logintext) {
5232: if ($domconfig->{$role}{$item} ne '') {
5233: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5234: $changes{$role}{'logintext'}{$item} = 1;
5235: }
5236: } else {
5237: if ($confhash->{$role}{$item}) {
5238: $changes{$role}{'logintext'}{$item} = 1;
5239: }
5240: }
5241: }
1.6 raeburn 5242: } else {
5243: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5244: \@logintext,$confhash,\%changes);
1.6 raeburn 5245: }
5246: } else {
5247: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5248: \@logintext,$confhash,\%changes);
1.6 raeburn 5249: }
5250: }
5251: return ($errors,%changes);
5252: }
5253:
1.46 raeburn 5254: sub config_check {
5255: my ($dom,$confname,$servadm) = @_;
5256: my ($configuserok,$author_ok,$switchserver,%currroles);
5257: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5258: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5259: $confname,$servadm);
5260: if ($configuserok eq 'ok') {
5261: $switchserver = &check_switchserver($dom,$confname);
5262: if ($switchserver eq '') {
5263: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5264: }
5265: }
5266: return ($configuserok,$author_ok,$switchserver);
5267: }
5268:
1.6 raeburn 5269: sub default_change_checker {
1.41 raeburn 5270: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5271: foreach my $item (@{$links}) {
5272: if ($confhash->{$role}{$item}) {
5273: $changes->{$role}{'links'}{$item} = 1;
5274: }
5275: }
5276: foreach my $item (@{$bgs}) {
5277: if ($confhash->{$role}{$item}) {
5278: $changes->{$role}{'bgs'}{$item} = 1;
5279: }
5280: }
1.41 raeburn 5281: foreach my $item (@{$logintext}) {
5282: if ($confhash->{$role}{$item}) {
5283: $changes->{$role}{'logintext'}{$item} = 1;
5284: }
5285: }
1.6 raeburn 5286: foreach my $img (@{$images}) {
5287: if ($env{'form.'.$role.'_del_'.$img}) {
5288: $confhash->{$role}{$img} = '';
1.12 raeburn 5289: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5290: }
1.70 raeburn 5291: if ($role eq 'login') {
5292: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5293: $changes->{$role}{'showlogo'}{$img} = 1;
5294: }
5295: }
1.6 raeburn 5296: }
5297: if ($confhash->{$role}{'font'}) {
5298: $changes->{$role}{'font'} = 1;
5299: }
1.48 raeburn 5300: }
1.6 raeburn 5301:
5302: sub display_colorchgs {
5303: my ($dom,$changes,$roles,$confhash) = @_;
5304: my (%choices,$resulttext);
5305: if (!grep(/^login$/,@{$roles})) {
5306: $resulttext = &mt('Changes made:').'<br />';
5307: }
5308: foreach my $role (@{$roles}) {
5309: if ($role eq 'login') {
5310: %choices = &login_choices();
5311: } else {
5312: %choices = &color_font_choices();
5313: }
5314: if (ref($changes->{$role}) eq 'HASH') {
5315: if ($role ne 'login') {
5316: $resulttext .= '<h4>'.&mt($role).'</h4>';
5317: }
5318: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5319: if ($role ne 'login') {
5320: $resulttext .= '<ul>';
5321: }
5322: if (ref($changes->{$role}{$key}) eq 'HASH') {
5323: if ($role ne 'login') {
5324: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5325: }
5326: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5327: if (($role eq 'login') && ($key eq 'showlogo')) {
5328: if ($confhash->{$role}{$key}{$item}) {
5329: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5330: } else {
5331: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5332: }
5333: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5334: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5335: } else {
1.12 raeburn 5336: my $newitem = $confhash->{$role}{$item};
5337: if ($key eq 'images') {
5338: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5339: }
5340: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5341: }
5342: }
5343: if ($role ne 'login') {
5344: $resulttext .= '</ul></li>';
5345: }
5346: } else {
5347: if ($confhash->{$role}{$key} eq '') {
5348: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5349: } else {
5350: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5351: }
5352: }
5353: if ($role ne 'login') {
5354: $resulttext .= '</ul>';
5355: }
5356: }
5357: }
5358: }
1.3 raeburn 5359: return $resulttext;
1.1 raeburn 5360: }
5361:
1.9 raeburn 5362: sub thumb_dimensions {
5363: return ('200','50');
5364: }
5365:
1.16 raeburn 5366: sub check_dimensions {
5367: my ($inputfile) = @_;
5368: my ($fullwidth,$fullheight);
5369: if ($inputfile =~ m|^[/\w.\-]+$|) {
5370: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5371: my $imageinfo = <PIPE>;
5372: if (!close(PIPE)) {
5373: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5374: }
5375: chomp($imageinfo);
5376: my ($fullsize) =
1.21 raeburn 5377: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5378: if ($fullsize) {
5379: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5380: }
5381: }
5382: }
5383: return ($fullwidth,$fullheight);
5384: }
5385:
1.9 raeburn 5386: sub check_configuser {
5387: my ($uhome,$dom,$confname,$servadm) = @_;
5388: my ($configuserok,%currroles);
5389: if ($uhome eq 'no_host') {
5390: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5391: my $configpass = &LONCAPA::Enrollment::create_password();
5392: $configuserok =
5393: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5394: $configpass,'','','','','',undef,$servadm);
5395: } else {
5396: $configuserok = 'ok';
5397: %currroles =
5398: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5399: }
5400: return ($configuserok,%currroles);
5401: }
5402:
5403: sub check_authorstatus {
5404: my ($dom,$confname,%currroles) = @_;
5405: my $author_ok;
1.40 raeburn 5406: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5407: my $start = time;
5408: my $end = 0;
5409: $author_ok =
5410: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5411: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5412: } else {
5413: $author_ok = 'ok';
5414: }
5415: return $author_ok;
5416: }
5417:
5418: sub publishlogo {
1.46 raeburn 5419: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5420: my ($output,$fname,$logourl);
5421: if ($action eq 'upload') {
5422: $fname=$env{'form.'.$formname.'.filename'};
5423: chop($env{'form.'.$formname});
5424: } else {
5425: ($fname) = ($formname =~ /([^\/]+)$/);
5426: }
1.46 raeburn 5427: if ($savefileas ne '') {
5428: $fname = $savefileas;
5429: }
1.9 raeburn 5430: $fname=&Apache::lonnet::clean_filename($fname);
5431: # See if there is anything left
5432: unless ($fname) { return ('error: no uploaded file'); }
5433: $fname="$subdir/$fname";
1.164 raeburn 5434: my $docroot=$r->dir_config('lonDocRoot');
5435: my $filepath="$docroot/priv";
5436: my $relpath = "$dom/$confname";
1.9 raeburn 5437: my ($fnamepath,$file,$fetchthumb);
5438: $file=$fname;
5439: if ($fname=~m|/|) {
5440: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5441: }
1.164 raeburn 5442: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5443: my $count;
1.164 raeburn 5444: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5445: $filepath.="/$parts[$count]";
5446: if ((-e $filepath)!=1) {
5447: mkdir($filepath,02770);
5448: }
5449: }
5450: # Check for bad extension and disallow upload
5451: if ($file=~/\.(\w+)$/ &&
5452: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5453: $output =
5454: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5455: } elsif ($file=~/\.(\w+)$/ &&
5456: !defined(&Apache::loncommon::fileembstyle($1))) {
5457: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5458: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5459: $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 5460: } elsif (-d "$filepath/$file") {
5461: $output = &mt('File name is a directory name - rename the file and re-upload');
5462: } else {
5463: my $source = $filepath.'/'.$file;
5464: my $logfile;
5465: if (!open($logfile,">>$source".'.log')) {
5466: return (&mt('No write permission to Construction Space'));
5467: }
5468: print $logfile
5469: "\n================= Publish ".localtime()." ================\n".
5470: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5471: # Save the file
5472: if (!open(FH,'>'.$source)) {
5473: &Apache::lonnet::logthis('Failed to create '.$source);
5474: return (&mt('Failed to create file'));
5475: }
5476: if ($action eq 'upload') {
5477: if (!print FH ($env{'form.'.$formname})) {
5478: &Apache::lonnet::logthis('Failed to write to '.$source);
5479: return (&mt('Failed to write file'));
5480: }
5481: } else {
5482: my $original = &Apache::lonnet::filelocation('',$formname);
5483: if(!copy($original,$source)) {
5484: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5485: return (&mt('Failed to write file'));
5486: }
5487: }
5488: close(FH);
5489: chmod(0660, $source); # Permissions to rw-rw---.
5490:
5491: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5492: my $copyfile=$targetdir.'/'.$file;
5493:
5494: my @parts=split(/\//,$targetdir);
5495: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5496: for (my $count=5;$count<=$#parts;$count++) {
5497: $path.="/$parts[$count]";
5498: if (!-e $path) {
5499: print $logfile "\nCreating directory ".$path;
5500: mkdir($path,02770);
5501: }
5502: }
5503: my $versionresult;
5504: if (-e $copyfile) {
5505: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5506: } else {
5507: $versionresult = 'ok';
5508: }
5509: if ($versionresult eq 'ok') {
5510: if (copy($source,$copyfile)) {
5511: print $logfile "\nCopied original source to ".$copyfile."\n";
5512: $output = 'ok';
5513: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5514: push(@{$modified_urls},[$copyfile,$source]);
5515: my $metaoutput =
5516: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5517: unless ($registered_cleanup) {
5518: my $handlers = $r->get_handlers('PerlCleanupHandler');
5519: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5520: $registered_cleanup=1;
5521: }
1.9 raeburn 5522: } else {
5523: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5524: $output = &mt('Failed to copy file to RES space').", $!";
5525: }
5526: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5527: my $inputfile = $filepath.'/'.$file;
5528: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5529: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5530: if ($fullwidth ne '' && $fullheight ne '') {
5531: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5532: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5533: system("convert -sample $thumbsize $inputfile $outfile");
5534: chmod(0660, $filepath.'/tn-'.$file);
5535: if (-e $outfile) {
5536: my $copyfile=$targetdir.'/tn-'.$file;
5537: if (copy($outfile,$copyfile)) {
5538: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5539: my $thumb_metaoutput =
5540: &write_metadata($dom,$confname,$formname,
5541: $targetdir,'tn-'.$file,$logfile);
5542: push(@{$modified_urls},[$copyfile,$outfile]);
5543: unless ($registered_cleanup) {
5544: my $handlers = $r->get_handlers('PerlCleanupHandler');
5545: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5546: $registered_cleanup=1;
5547: }
1.16 raeburn 5548: } else {
5549: print $logfile "\nUnable to write ".$copyfile.
5550: ':'.$!."\n";
5551: }
5552: }
1.9 raeburn 5553: }
5554: }
5555: }
5556: } else {
5557: $output = $versionresult;
5558: }
5559: }
5560: return ($output,$logourl);
5561: }
5562:
5563: sub logo_versioning {
5564: my ($targetdir,$file,$logfile) = @_;
5565: my $target = $targetdir.'/'.$file;
5566: my ($maxversion,$fn,$extn,$output);
5567: $maxversion = 0;
5568: if ($file =~ /^(.+)\.(\w+)$/) {
5569: $fn=$1;
5570: $extn=$2;
5571: }
5572: opendir(DIR,$targetdir);
5573: while (my $filename=readdir(DIR)) {
5574: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5575: $maxversion=($1>$maxversion)?$1:$maxversion;
5576: }
5577: }
5578: $maxversion++;
5579: print $logfile "\nCreating old version ".$maxversion."\n";
5580: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5581: if (copy($target,$copyfile)) {
5582: print $logfile "Copied old target to ".$copyfile."\n";
5583: $copyfile=$copyfile.'.meta';
5584: if (copy($target.'.meta',$copyfile)) {
5585: print $logfile "Copied old target metadata to ".$copyfile."\n";
5586: $output = 'ok';
5587: } else {
5588: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5589: $output = &mt('Failed to copy old meta').", $!, ";
5590: }
5591: } else {
5592: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5593: $output = &mt('Failed to copy old target').", $!, ";
5594: }
5595: return $output;
5596: }
5597:
5598: sub write_metadata {
5599: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5600: my (%metadatafields,%metadatakeys,$output);
5601: $metadatafields{'title'}=$formname;
5602: $metadatafields{'creationdate'}=time;
5603: $metadatafields{'lastrevisiondate'}=time;
5604: $metadatafields{'copyright'}='public';
5605: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5606: $env{'user.domain'};
5607: $metadatafields{'authorspace'}=$confname.':'.$dom;
5608: $metadatafields{'domain'}=$dom;
5609: {
5610: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5611: my $mfh;
1.155 raeburn 5612: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5613: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5614: unless ($_=~/\./) {
5615: my $unikey=$_;
5616: $unikey=~/^([A-Za-z]+)/;
5617: my $tag=$1;
5618: $tag=~tr/A-Z/a-z/;
5619: print $mfh "\n\<$tag";
5620: foreach (split(/\,/,$metadatakeys{$unikey})) {
5621: my $value=$metadatafields{$unikey.'.'.$_};
5622: $value=~s/\"/\'\'/g;
5623: print $mfh ' '.$_.'="'.$value.'"';
5624: }
5625: print $mfh '>'.
5626: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5627: .'</'.$tag.'>';
5628: }
5629: }
5630: $output = 'ok';
5631: print $logfile "\nWrote metadata";
5632: close($mfh);
5633: } else {
5634: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5635: $output = &mt('Could not write metadata');
5636: }
5637: }
1.155 raeburn 5638: return $output;
5639: }
5640:
5641: sub notifysubscribed {
5642: foreach my $targetsource (@{$modified_urls}){
5643: next unless (ref($targetsource) eq 'ARRAY');
5644: my ($target,$source)=@{$targetsource};
5645: if ($source ne '') {
5646: if (open(my $logfh,'>>'.$source.'.log')) {
5647: print $logfh "\nCleanup phase: Notifications\n";
5648: my @subscribed=&subscribed_hosts($target);
5649: foreach my $subhost (@subscribed) {
5650: print $logfh "\nNotifying host ".$subhost.':';
5651: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5652: print $logfh $reply;
5653: }
5654: my @subscribedmeta=&subscribed_hosts("$target.meta");
5655: foreach my $subhost (@subscribedmeta) {
5656: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5657: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5658: $subhost);
5659: print $logfh $reply;
5660: }
5661: print $logfh "\n============ Done ============\n";
1.160 raeburn 5662: close($logfh);
1.155 raeburn 5663: }
5664: }
5665: }
5666: return OK;
5667: }
5668:
5669: sub subscribed_hosts {
5670: my ($target) = @_;
5671: my @subscribed;
5672: if (open(my $fh,"<$target.subscription")) {
5673: while (my $subline=<$fh>) {
5674: if ($subline =~ /^($match_lonid):/) {
5675: my $host = $1;
5676: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5677: unless (grep(/^\Q$host\E$/,@subscribed)) {
5678: push(@subscribed,$host);
5679: }
5680: }
5681: }
5682: }
5683: }
5684: return @subscribed;
1.9 raeburn 5685: }
5686:
5687: sub check_switchserver {
5688: my ($dom,$confname) = @_;
5689: my ($allowed,$switchserver);
5690: my $home = &Apache::lonnet::homeserver($confname,$dom);
5691: if ($home eq 'no_host') {
5692: $home = &Apache::lonnet::domain($dom,'primary');
5693: }
5694: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5695: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5696: if (!$allowed) {
1.180 raeburn 5697: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5698: }
5699: return $switchserver;
5700: }
5701:
1.1 raeburn 5702: sub modify_quotas {
1.86 raeburn 5703: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5704: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5705: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5706: if ($action eq 'quotas') {
5707: $context = 'tools';
1.163 raeburn 5708: } else {
1.86 raeburn 5709: $context = $action;
5710: }
5711: if ($context eq 'requestcourses') {
1.98 raeburn 5712: @usertools = ('official','unofficial','community');
1.106 raeburn 5713: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5714: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5715: %titles = &courserequest_titles();
5716: $toolregexp = join('|',@usertools);
5717: %conditions = &courserequest_conditions();
1.163 raeburn 5718: } elsif ($context eq 'requestauthor') {
5719: @usertools = ('author');
5720: %titles = &authorrequest_titles();
1.86 raeburn 5721: } else {
1.162 raeburn 5722: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5723: %titles = &tool_titles();
1.86 raeburn 5724: }
1.72 raeburn 5725: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5726: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5727: foreach my $key (keys(%env)) {
1.101 raeburn 5728: if ($context eq 'requestcourses') {
5729: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5730: my $item = $1;
5731: my $type = $2;
5732: if ($type =~ /^limit_(.+)/) {
5733: $limithash{$item}{$1} = $env{$key};
5734: } else {
5735: $confhash{$item}{$type} = $env{$key};
5736: }
5737: }
1.163 raeburn 5738: } elsif ($context eq 'requestauthor') {
5739: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5740: $confhash{$1} = $env{$key};
5741: }
1.101 raeburn 5742: } else {
1.86 raeburn 5743: if ($key =~ /^form\.quota_(.+)$/) {
5744: $confhash{'defaultquota'}{$1} = $env{$key};
5745: }
1.101 raeburn 5746: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5747: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5748: }
1.72 raeburn 5749: }
5750: }
1.163 raeburn 5751: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5752: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5753: @approvalnotify = sort(@approvalnotify);
5754: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5755: if (ref($domconfig{$action}) eq 'HASH') {
5756: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5757: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5758: $changes{'notify'}{'approval'} = 1;
5759: }
5760: } else {
1.144 raeburn 5761: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5762: $changes{'notify'}{'approval'} = 1;
5763: }
5764: }
5765: } else {
1.144 raeburn 5766: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5767: $changes{'notify'}{'approval'} = 1;
5768: }
5769: }
5770: } else {
1.86 raeburn 5771: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5772: }
1.72 raeburn 5773: foreach my $item (@usertools) {
5774: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5775: my $unset;
1.101 raeburn 5776: if ($context eq 'requestcourses') {
1.104 raeburn 5777: $unset = '0';
5778: if ($type eq '_LC_adv') {
5779: $unset = '';
5780: }
1.101 raeburn 5781: if ($confhash{$item}{$type} eq 'autolimit') {
5782: $confhash{$item}{$type} .= '=';
5783: unless ($limithash{$item}{$type} =~ /\D/) {
5784: $confhash{$item}{$type} .= $limithash{$item}{$type};
5785: }
5786: }
1.163 raeburn 5787: } elsif ($context eq 'requestauthor') {
5788: $unset = '0';
5789: if ($type eq '_LC_adv') {
5790: $unset = '';
5791: }
1.72 raeburn 5792: } else {
1.101 raeburn 5793: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5794: $confhash{$item}{$type} = 1;
5795: } else {
5796: $confhash{$item}{$type} = 0;
5797: }
1.72 raeburn 5798: }
1.86 raeburn 5799: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5800: if ($action eq 'requestauthor') {
5801: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5802: $changes{$type} = 1;
5803: }
5804: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5805: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5806: $changes{$item}{$type} = 1;
5807: }
5808: } else {
5809: if ($context eq 'requestcourses') {
1.104 raeburn 5810: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5811: $changes{$item}{$type} = 1;
5812: }
5813: } else {
5814: if (!$confhash{$item}{$type}) {
5815: $changes{$item}{$type} = 1;
5816: }
5817: }
5818: }
5819: } else {
5820: if ($context eq 'requestcourses') {
1.104 raeburn 5821: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5822: $changes{$item}{$type} = 1;
5823: }
1.163 raeburn 5824: } elsif ($context eq 'requestauthor') {
5825: if ($confhash{$type} ne $unset) {
5826: $changes{$type} = 1;
5827: }
1.72 raeburn 5828: } else {
5829: if (!$confhash{$item}{$type}) {
5830: $changes{$item}{$type} = 1;
5831: }
5832: }
5833: }
1.1 raeburn 5834: }
5835: }
1.163 raeburn 5836: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5837: if (ref($domconfig{'quotas'}) eq 'HASH') {
5838: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5839: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5840: if (exists($confhash{'defaultquota'}{$key})) {
5841: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5842: $changes{'defaultquota'}{$key} = 1;
5843: }
5844: } else {
5845: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5846: }
5847: }
1.86 raeburn 5848: } else {
5849: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5850: if (exists($confhash{'defaultquota'}{$key})) {
5851: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5852: $changes{'defaultquota'}{$key} = 1;
5853: }
5854: } else {
5855: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5856: }
1.1 raeburn 5857: }
5858: }
5859: }
1.86 raeburn 5860: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5861: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5862: if (ref($domconfig{'quotas'}) eq 'HASH') {
5863: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5864: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5865: $changes{'defaultquota'}{$key} = 1;
5866: }
5867: } else {
5868: if (!exists($domconfig{'quotas'}{$key})) {
5869: $changes{'defaultquota'}{$key} = 1;
5870: }
1.72 raeburn 5871: }
5872: } else {
1.86 raeburn 5873: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5874: }
1.1 raeburn 5875: }
5876: }
5877: }
1.72 raeburn 5878:
1.163 raeburn 5879: if ($context eq 'requestauthor') {
5880: $domdefaults{'requestauthor'} = \%confhash;
5881: } else {
5882: foreach my $key (keys(%confhash)) {
5883: $domdefaults{$key} = $confhash{$key};
5884: }
1.72 raeburn 5885: }
1.163 raeburn 5886:
1.1 raeburn 5887: my %quotahash = (
1.86 raeburn 5888: $action => { %confhash }
1.1 raeburn 5889: );
5890: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5891: $dom);
5892: if ($putresult eq 'ok') {
5893: if (keys(%changes) > 0) {
1.72 raeburn 5894: my $cachetime = 24*60*60;
5895: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5896:
1.1 raeburn 5897: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5898: unless (($context eq 'requestcourses') ||
5899: ($context eq 'requestauthor')) {
1.86 raeburn 5900: if (ref($changes{'defaultquota'}) eq 'HASH') {
5901: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5902: foreach my $type (@{$types},'default') {
5903: if (defined($changes{'defaultquota'}{$type})) {
5904: my $typetitle = $usertypes->{$type};
5905: if ($type eq 'default') {
5906: $typetitle = $othertitle;
5907: }
5908: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5909: }
5910: }
1.86 raeburn 5911: $resulttext .= '</ul></li>';
1.72 raeburn 5912: }
5913: }
1.80 raeburn 5914: my %newenv;
1.72 raeburn 5915: foreach my $item (@usertools) {
1.163 raeburn 5916: my (%haschgs,%inconf);
5917: if ($context eq 'requestauthor') {
5918: %haschgs = %changes;
5919: %inconf = %confhash;
5920: } else {
5921: if (ref($changes{$item}) eq 'HASH') {
5922: %haschgs = %{$changes{$item}};
5923: }
5924: if (ref($confhash{$item}) eq 'HASH') {
5925: %inconf = %{$confhash{$item}};
5926: }
5927: }
5928: if (keys(%haschgs) > 0) {
1.80 raeburn 5929: my $newacc =
5930: &Apache::lonnet::usertools_access($env{'user.name'},
5931: $env{'user.domain'},
1.86 raeburn 5932: $item,'reload',$context);
1.163 raeburn 5933: if (($context eq 'requestcourses') ||
5934: ($context eq 'requestauthor')) {
1.108 raeburn 5935: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5936: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5937: }
5938: } else {
5939: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5940: $newenv{'environment.availabletools.'.$item} = $newacc;
5941: }
1.80 raeburn 5942: }
1.163 raeburn 5943: unless ($context eq 'requestauthor') {
5944: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5945: }
1.72 raeburn 5946: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5947: if ($haschgs{$type}) {
1.72 raeburn 5948: my $typetitle = $usertypes->{$type};
5949: if ($type eq 'default') {
5950: $typetitle = $othertitle;
5951: } elsif ($type eq '_LC_adv') {
5952: $typetitle = 'LON-CAPA Advanced Users';
5953: }
1.163 raeburn 5954: if ($inconf{$type}) {
1.101 raeburn 5955: if ($context eq 'requestcourses') {
5956: my $cond;
1.163 raeburn 5957: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5958: if ($1 eq '') {
5959: $cond = &mt('(Automatic processing of any request).');
5960: } else {
5961: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5962: }
5963: } else {
1.163 raeburn 5964: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5965: }
5966: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 5967: } elsif ($context eq 'requestauthor') {
5968: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5969: $titles{$inconf{$type}},$typetitle);
5970:
1.101 raeburn 5971: } else {
5972: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5973: }
1.72 raeburn 5974: } else {
1.104 raeburn 5975: if ($type eq '_LC_adv') {
1.163 raeburn 5976: if ($inconf{$type} eq '0') {
1.104 raeburn 5977: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5978: } else {
5979: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5980: }
5981: } else {
5982: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5983: }
1.72 raeburn 5984: }
5985: }
1.26 raeburn 5986: }
1.163 raeburn 5987: unless ($context eq 'requestauthor') {
5988: $resulttext .= '</ul></li>';
5989: }
1.26 raeburn 5990: }
1.1 raeburn 5991: }
1.163 raeburn 5992: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5993: if (ref($changes{'notify'}) eq 'HASH') {
5994: if ($changes{'notify'}{'approval'}) {
5995: if (ref($confhash{'notify'}) eq 'HASH') {
5996: if ($confhash{'notify'}{'approval'}) {
5997: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5998: } else {
1.163 raeburn 5999: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6000: }
6001: }
6002: }
6003: }
6004: }
1.1 raeburn 6005: $resulttext .= '</ul>';
1.80 raeburn 6006: if (keys(%newenv)) {
6007: &Apache::lonnet::appenv(\%newenv);
6008: }
1.1 raeburn 6009: } else {
1.86 raeburn 6010: if ($context eq 'requestcourses') {
6011: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6012: } elsif ($context eq 'requestauthor') {
6013: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6014: } else {
1.90 weissno 6015: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6016: }
1.1 raeburn 6017: }
6018: } else {
1.11 albertel 6019: $resulttext = '<span class="LC_error">'.
6020: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6021: }
1.3 raeburn 6022: return $resulttext;
1.1 raeburn 6023: }
6024:
1.3 raeburn 6025: sub modify_autoenroll {
6026: my ($dom,%domconfig) = @_;
1.1 raeburn 6027: my ($resulttext,%changes);
6028: my %currautoenroll;
6029: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6030: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6031: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6032: }
6033: }
6034: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6035: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6036: sender => 'Sender for notification messages',
6037: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6038: my @offon = ('off','on');
1.17 raeburn 6039: my $sender_uname = $env{'form.sender_uname'};
6040: my $sender_domain = $env{'form.sender_domain'};
6041: if ($sender_domain eq '') {
6042: $sender_uname = '';
6043: } elsif ($sender_uname eq '') {
6044: $sender_domain = '';
6045: }
1.129 raeburn 6046: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6047: my %autoenrollhash = (
1.129 raeburn 6048: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6049: 'sender_uname' => $sender_uname,
6050: 'sender_domain' => $sender_domain,
6051: 'co-owners' => $coowners,
1.1 raeburn 6052: }
6053: );
1.4 raeburn 6054: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6055: $dom);
1.1 raeburn 6056: if ($putresult eq 'ok') {
6057: if (exists($currautoenroll{'run'})) {
6058: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6059: $changes{'run'} = 1;
6060: }
6061: } elsif ($autorun) {
6062: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6063: $changes{'run'} = 1;
1.1 raeburn 6064: }
6065: }
1.17 raeburn 6066: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6067: $changes{'sender'} = 1;
6068: }
1.17 raeburn 6069: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6070: $changes{'sender'} = 1;
6071: }
1.129 raeburn 6072: if ($currautoenroll{'co-owners'} ne '') {
6073: if ($currautoenroll{'co-owners'} ne $coowners) {
6074: $changes{'coowners'} = 1;
6075: }
6076: } elsif ($coowners) {
6077: $changes{'coowners'} = 1;
6078: }
1.1 raeburn 6079: if (keys(%changes) > 0) {
6080: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6081: if ($changes{'run'}) {
1.1 raeburn 6082: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6083: }
6084: if ($changes{'sender'}) {
1.17 raeburn 6085: if ($sender_uname eq '' || $sender_domain eq '') {
6086: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6087: } else {
6088: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6089: }
1.1 raeburn 6090: }
1.129 raeburn 6091: if ($changes{'coowners'}) {
6092: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6093: &Apache::loncommon::devalidate_domconfig_cache($dom);
6094: }
1.1 raeburn 6095: $resulttext .= '</ul>';
6096: } else {
6097: $resulttext = &mt('No changes made to auto-enrollment settings');
6098: }
6099: } else {
1.11 albertel 6100: $resulttext = '<span class="LC_error">'.
6101: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6102: }
1.3 raeburn 6103: return $resulttext;
1.1 raeburn 6104: }
6105:
6106: sub modify_autoupdate {
1.3 raeburn 6107: my ($dom,%domconfig) = @_;
1.1 raeburn 6108: my ($resulttext,%currautoupdate,%fields,%changes);
6109: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6110: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6111: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6112: }
6113: }
6114: my @offon = ('off','on');
6115: my %title = &Apache::lonlocal::texthash (
6116: run => 'Auto-update:',
6117: classlists => 'Updates to user information in classlists?'
6118: );
1.44 raeburn 6119: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6120: my %fieldtitles = &Apache::lonlocal::texthash (
6121: id => 'Student/Employee ID',
1.20 raeburn 6122: permanentemail => 'E-mail address',
1.1 raeburn 6123: lastname => 'Last Name',
6124: firstname => 'First Name',
6125: middlename => 'Middle Name',
1.132 raeburn 6126: generation => 'Generation',
1.1 raeburn 6127: );
1.142 raeburn 6128: $othertitle = &mt('All users');
1.1 raeburn 6129: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6130: $othertitle = &mt('Other users');
1.1 raeburn 6131: }
6132: foreach my $key (keys(%env)) {
6133: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6134: my ($usertype,$item) = ($1,$2);
6135: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6136: if ($usertype eq 'default') {
6137: push(@{$fields{$1}},$2);
6138: } elsif (ref($types) eq 'ARRAY') {
6139: if (grep(/^\Q$usertype\E$/,@{$types})) {
6140: push(@{$fields{$1}},$2);
6141: }
6142: }
6143: }
1.1 raeburn 6144: }
6145: }
1.131 raeburn 6146: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6147: @lockablenames = sort(@lockablenames);
6148: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6149: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6150: if (@changed) {
6151: $changes{'lockablenames'} = 1;
6152: }
6153: } else {
6154: if (@lockablenames) {
6155: $changes{'lockablenames'} = 1;
6156: }
6157: }
1.1 raeburn 6158: my %updatehash = (
6159: autoupdate => { run => $env{'form.autoupdate_run'},
6160: classlists => $env{'form.classlists'},
6161: fields => {%fields},
1.131 raeburn 6162: lockablenames => \@lockablenames,
1.1 raeburn 6163: }
6164: );
6165: foreach my $key (keys(%currautoupdate)) {
6166: if (($key eq 'run') || ($key eq 'classlists')) {
6167: if (exists($updatehash{autoupdate}{$key})) {
6168: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6169: $changes{$key} = 1;
6170: }
6171: }
6172: } elsif ($key eq 'fields') {
6173: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6174: foreach my $item (@{$types},'default') {
1.1 raeburn 6175: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6176: my $change = 0;
6177: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6178: if (!exists($fields{$item})) {
6179: $change = 1;
1.132 raeburn 6180: last;
1.1 raeburn 6181: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6182: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6183: $change = 1;
1.132 raeburn 6184: last;
1.1 raeburn 6185: }
6186: }
6187: }
6188: if ($change) {
6189: push(@{$changes{$key}},$item);
6190: }
1.26 raeburn 6191: }
1.1 raeburn 6192: }
6193: }
1.131 raeburn 6194: } elsif ($key eq 'lockablenames') {
6195: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6196: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6197: if (@changed) {
6198: $changes{'lockablenames'} = 1;
6199: }
6200: } else {
6201: if (@lockablenames) {
6202: $changes{'lockablenames'} = 1;
6203: }
6204: }
6205: }
6206: }
6207: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6208: if (@lockablenames) {
6209: $changes{'lockablenames'} = 1;
1.1 raeburn 6210: }
6211: }
1.26 raeburn 6212: foreach my $item (@{$types},'default') {
6213: if (defined($fields{$item})) {
6214: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6215: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6216: my $change = 0;
6217: if (ref($fields{$item}) eq 'ARRAY') {
6218: foreach my $type (@{$fields{$item}}) {
6219: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6220: $change = 1;
6221: last;
6222: }
6223: }
6224: }
6225: if ($change) {
6226: push(@{$changes{'fields'}},$item);
6227: }
6228: } else {
1.26 raeburn 6229: push(@{$changes{'fields'}},$item);
6230: }
6231: } else {
6232: push(@{$changes{'fields'}},$item);
1.1 raeburn 6233: }
6234: }
6235: }
6236: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6237: $dom);
6238: if ($putresult eq 'ok') {
6239: if (keys(%changes) > 0) {
6240: $resulttext = &mt('Changes made:').'<ul>';
6241: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6242: if ($key eq 'lockablenames') {
6243: $resulttext .= '<li>';
6244: if (@lockablenames) {
6245: $usertypes->{'default'} = $othertitle;
6246: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6247: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6248: } else {
6249: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6250: }
6251: $resulttext .= '</li>';
6252: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6253: foreach my $item (@{$changes{$key}}) {
6254: my @newvalues;
6255: foreach my $type (@{$fields{$item}}) {
6256: push(@newvalues,$fieldtitles{$type});
6257: }
1.3 raeburn 6258: my $newvaluestr;
6259: if (@newvalues > 0) {
6260: $newvaluestr = join(', ',@newvalues);
6261: } else {
6262: $newvaluestr = &mt('none');
1.6 raeburn 6263: }
1.1 raeburn 6264: if ($item eq 'default') {
1.26 raeburn 6265: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6266: } else {
1.26 raeburn 6267: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6268: }
6269: }
6270: } else {
6271: my $newvalue;
6272: if ($key eq 'run') {
6273: $newvalue = $offon[$env{'form.autoupdate_run'}];
6274: } else {
6275: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6276: }
1.1 raeburn 6277: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6278: }
6279: }
6280: $resulttext .= '</ul>';
6281: } else {
1.3 raeburn 6282: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6283: }
6284: } else {
1.11 albertel 6285: $resulttext = '<span class="LC_error">'.
6286: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6287: }
1.3 raeburn 6288: return $resulttext;
1.1 raeburn 6289: }
6290:
1.125 raeburn 6291: sub modify_autocreate {
6292: my ($dom,%domconfig) = @_;
6293: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6294: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6295: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6296: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6297: }
6298: }
6299: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6300: req => 'Auto-creation of validated requests for official courses',
6301: xmldc => 'Identity of course creator of courses from XML files',
6302: );
6303: my @types = ('xml','req');
6304: foreach my $item (@types) {
6305: $newvals{$item} = $env{'form.autocreate_'.$item};
6306: $newvals{$item} =~ s/\D//g;
6307: $newvals{$item} = 0 if ($newvals{$item} eq '');
6308: }
6309: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6310: my %domcoords = &get_active_dcs($dom);
6311: unless (exists($domcoords{$newvals{'xmldc'}})) {
6312: $newvals{'xmldc'} = '';
6313: }
6314: %autocreatehash = (
6315: autocreate => { xml => $newvals{'xml'},
6316: req => $newvals{'req'},
6317: }
6318: );
6319: if ($newvals{'xmldc'} ne '') {
6320: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6321: }
6322: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6323: $dom);
6324: if ($putresult eq 'ok') {
6325: my @items = @types;
6326: if ($newvals{'xml'}) {
6327: push(@items,'xmldc');
6328: }
6329: foreach my $item (@items) {
6330: if (exists($currautocreate{$item})) {
6331: if ($currautocreate{$item} ne $newvals{$item}) {
6332: $changes{$item} = 1;
6333: }
6334: } elsif ($newvals{$item}) {
6335: $changes{$item} = 1;
6336: }
6337: }
6338: if (keys(%changes) > 0) {
6339: my @offon = ('off','on');
6340: $resulttext = &mt('Changes made:').'<ul>';
6341: foreach my $item (@types) {
6342: if ($changes{$item}) {
6343: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6344: $resulttext .= '<li>'.
6345: &mt("$title{$item} set to [_1]$newtxt [_2]",
6346: '<b>','</b>').
6347: '</li>';
1.125 raeburn 6348: }
6349: }
6350: if ($changes{'xmldc'}) {
6351: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6352: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6353: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6354: }
6355: $resulttext .= '</ul>';
6356: } else {
6357: $resulttext = &mt('No changes made to auto-creation settings');
6358: }
6359: } else {
6360: $resulttext = '<span class="LC_error">'.
6361: &mt('An error occurred: [_1]',$putresult).'</span>';
6362: }
6363: return $resulttext;
6364: }
6365:
1.23 raeburn 6366: sub modify_directorysrch {
6367: my ($dom,%domconfig) = @_;
6368: my ($resulttext,%changes);
6369: my %currdirsrch;
6370: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6371: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6372: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6373: }
6374: }
6375: my %title = ( available => 'Directory search available',
1.24 raeburn 6376: localonly => 'Other domains can search',
1.23 raeburn 6377: searchby => 'Search types',
6378: searchtypes => 'Search latitude');
6379: my @offon = ('off','on');
1.24 raeburn 6380: my @otherdoms = ('Yes','No');
1.23 raeburn 6381:
1.25 raeburn 6382: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6383: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6384: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6385:
1.44 raeburn 6386: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6387: if (keys(%{$usertypes}) == 0) {
6388: @cansearch = ('default');
6389: } else {
6390: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6391: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6392: if (!grep(/^\Q$type\E$/,@cansearch)) {
6393: push(@{$changes{'cansearch'}},$type);
6394: }
1.23 raeburn 6395: }
1.26 raeburn 6396: foreach my $type (@cansearch) {
6397: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6398: push(@{$changes{'cansearch'}},$type);
6399: }
1.23 raeburn 6400: }
1.26 raeburn 6401: } else {
6402: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6403: }
6404: }
6405:
6406: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6407: foreach my $by (@{$currdirsrch{'searchby'}}) {
6408: if (!grep(/^\Q$by\E$/,@searchby)) {
6409: push(@{$changes{'searchby'}},$by);
6410: }
6411: }
6412: foreach my $by (@searchby) {
6413: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6414: push(@{$changes{'searchby'}},$by);
6415: }
6416: }
6417: } else {
6418: push(@{$changes{'searchby'}},@searchby);
6419: }
1.25 raeburn 6420:
6421: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6422: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6423: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6424: push(@{$changes{'searchtypes'}},$type);
6425: }
6426: }
6427: foreach my $type (@searchtypes) {
6428: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6429: push(@{$changes{'searchtypes'}},$type);
6430: }
6431: }
6432: } else {
6433: if (exists($currdirsrch{'searchtypes'})) {
6434: foreach my $type (@searchtypes) {
6435: if ($type ne $currdirsrch{'searchtypes'}) {
6436: push(@{$changes{'searchtypes'}},$type);
6437: }
6438: }
6439: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6440: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6441: }
6442: } else {
6443: push(@{$changes{'searchtypes'}},@searchtypes);
6444: }
6445: }
6446:
1.23 raeburn 6447: my %dirsrch_hash = (
6448: directorysrch => { available => $env{'form.dirsrch_available'},
6449: cansearch => \@cansearch,
1.24 raeburn 6450: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6451: searchby => \@searchby,
1.25 raeburn 6452: searchtypes => \@searchtypes,
1.23 raeburn 6453: }
6454: );
6455: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6456: $dom);
6457: if ($putresult eq 'ok') {
6458: if (exists($currdirsrch{'available'})) {
6459: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6460: $changes{'available'} = 1;
6461: }
6462: } else {
6463: if ($env{'form.dirsrch_available'} eq '1') {
6464: $changes{'available'} = 1;
6465: }
6466: }
1.24 raeburn 6467: if (exists($currdirsrch{'localonly'})) {
6468: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6469: $changes{'localonly'} = 1;
6470: }
6471: } else {
6472: if ($env{'form.dirsrch_localonly'} eq '1') {
6473: $changes{'localonly'} = 1;
6474: }
6475: }
1.23 raeburn 6476: if (keys(%changes) > 0) {
6477: $resulttext = &mt('Changes made:').'<ul>';
6478: if ($changes{'available'}) {
6479: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6480: }
1.24 raeburn 6481: if ($changes{'localonly'}) {
6482: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6483: }
6484:
1.23 raeburn 6485: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6486: my $chgtext;
1.26 raeburn 6487: if (ref($usertypes) eq 'HASH') {
6488: if (keys(%{$usertypes}) > 0) {
6489: foreach my $type (@{$types}) {
6490: if (grep(/^\Q$type\E$/,@cansearch)) {
6491: $chgtext .= $usertypes->{$type}.'; ';
6492: }
6493: }
6494: if (grep(/^default$/,@cansearch)) {
6495: $chgtext .= $othertitle;
6496: } else {
6497: $chgtext =~ s/\; $//;
6498: }
1.178 raeburn 6499: $resulttext .=
6500: '<li>'.
6501: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6502: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6503: '</li>';
1.23 raeburn 6504: }
6505: }
6506: }
6507: if (ref($changes{'searchby'}) eq 'ARRAY') {
6508: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6509: my $chgtext;
6510: foreach my $type (@{$titleorder}) {
6511: if (grep(/^\Q$type\E$/,@searchby)) {
6512: if (defined($searchtitles->{$type})) {
6513: $chgtext .= $searchtitles->{$type}.'; ';
6514: }
6515: }
6516: }
6517: $chgtext =~ s/\; $//;
6518: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6519: }
1.25 raeburn 6520: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6521: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6522: my $chgtext;
6523: foreach my $type (@{$srchtypeorder}) {
6524: if (grep(/^\Q$type\E$/,@searchtypes)) {
6525: if (defined($srchtypes_desc->{$type})) {
6526: $chgtext .= $srchtypes_desc->{$type}.'; ';
6527: }
6528: }
6529: }
6530: $chgtext =~ s/\; $//;
1.178 raeburn 6531: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6532: }
6533: $resulttext .= '</ul>';
6534: } else {
6535: $resulttext = &mt('No changes made to institution directory search settings');
6536: }
6537: } else {
6538: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6539: &mt('An error occurred: [_1]',$putresult).'</span>';
6540: }
6541: return $resulttext;
6542: }
6543:
1.28 raeburn 6544: sub modify_contacts {
6545: my ($dom,%domconfig) = @_;
6546: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6547: if (ref($domconfig{'contacts'}) eq 'HASH') {
6548: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6549: $currsetting{$key} = $domconfig{'contacts'}{$key};
6550: }
6551: }
1.134 raeburn 6552: my (%others,%to,%bcc);
1.28 raeburn 6553: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6554: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6555: 'requestsmail');
1.28 raeburn 6556: foreach my $type (@mailings) {
6557: @{$newsetting{$type}} =
6558: &Apache::loncommon::get_env_multiple('form.'.$type);
6559: foreach my $item (@contacts) {
6560: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6561: $contacts_hash{contacts}{$type}{$item} = 1;
6562: } else {
6563: $contacts_hash{contacts}{$type}{$item} = 0;
6564: }
6565: }
6566: $others{$type} = $env{'form.'.$type.'_others'};
6567: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6568: if ($type eq 'helpdeskmail') {
6569: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6570: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6571: }
1.28 raeburn 6572: }
6573: foreach my $item (@contacts) {
6574: $to{$item} = $env{'form.'.$item};
6575: $contacts_hash{'contacts'}{$item} = $to{$item};
6576: }
6577: if (keys(%currsetting) > 0) {
6578: foreach my $item (@contacts) {
6579: if ($to{$item} ne $currsetting{$item}) {
6580: $changes{$item} = 1;
6581: }
6582: }
6583: foreach my $type (@mailings) {
6584: foreach my $item (@contacts) {
6585: if (ref($currsetting{$type}) eq 'HASH') {
6586: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6587: push(@{$changes{$type}},$item);
6588: }
6589: } else {
6590: push(@{$changes{$type}},@{$newsetting{$type}});
6591: }
6592: }
6593: if ($others{$type} ne $currsetting{$type}{'others'}) {
6594: push(@{$changes{$type}},'others');
6595: }
1.134 raeburn 6596: if ($type eq 'helpdeskmail') {
6597: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6598: push(@{$changes{$type}},'bcc');
6599: }
6600: }
1.28 raeburn 6601: }
6602: } else {
6603: my %default;
6604: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6605: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6606: $default{'errormail'} = 'adminemail';
6607: $default{'packagesmail'} = 'adminemail';
6608: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6609: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6610: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6611: foreach my $item (@contacts) {
6612: if ($to{$item} ne $default{$item}) {
6613: $changes{$item} = 1;
6614: }
6615: }
6616: foreach my $type (@mailings) {
6617: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6618:
6619: push(@{$changes{$type}},@{$newsetting{$type}});
6620: }
6621: if ($others{$type} ne '') {
6622: push(@{$changes{$type}},'others');
1.134 raeburn 6623: }
6624: if ($type eq 'helpdeskmail') {
6625: if ($bcc{$type} ne '') {
6626: push(@{$changes{$type}},'bcc');
6627: }
6628: }
1.28 raeburn 6629: }
6630: }
6631: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6632: $dom);
6633: if ($putresult eq 'ok') {
6634: if (keys(%changes) > 0) {
6635: my ($titles,$short_titles) = &contact_titles();
6636: $resulttext = &mt('Changes made:').'<ul>';
6637: foreach my $item (@contacts) {
6638: if ($changes{$item}) {
6639: $resulttext .= '<li>'.$titles->{$item}.
6640: &mt(' set to: ').
6641: '<span class="LC_cusr_emph">'.
6642: $to{$item}.'</span></li>';
6643: }
6644: }
6645: foreach my $type (@mailings) {
6646: if (ref($changes{$type}) eq 'ARRAY') {
6647: $resulttext .= '<li>'.$titles->{$type}.': ';
6648: my @text;
6649: foreach my $item (@{$newsetting{$type}}) {
6650: push(@text,$short_titles->{$item});
6651: }
6652: if ($others{$type} ne '') {
6653: push(@text,$others{$type});
6654: }
6655: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6656: join(', ',@text).'</span>';
6657: if ($type eq 'helpdeskmail') {
6658: if ($bcc{$type} ne '') {
6659: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6660: }
6661: }
6662: $resulttext .= '</li>';
1.28 raeburn 6663: }
6664: }
6665: $resulttext .= '</ul>';
6666: } else {
1.34 raeburn 6667: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6668: }
6669: } else {
6670: $resulttext = '<span class="LC_error">'.
6671: &mt('An error occurred: [_1].',$putresult).'</span>';
6672: }
6673: return $resulttext;
6674: }
6675:
6676: sub modify_usercreation {
1.27 raeburn 6677: my ($dom,%domconfig) = @_;
1.34 raeburn 6678: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6679: my $warningmsg;
1.27 raeburn 6680: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6681: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6682: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6683: }
6684: }
6685: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6686: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6687: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6688: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6689: foreach my $item(@contexts) {
1.45 raeburn 6690: if ($item eq 'selfcreate') {
1.50 raeburn 6691: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6692: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6693: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6694: if (ref($cancreate{$item}) eq 'ARRAY') {
6695: if (grep(/^login$/,@{$cancreate{$item}})) {
6696: $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.');
6697: }
1.43 raeburn 6698: }
6699: }
1.50 raeburn 6700: } else {
6701: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6702: }
1.34 raeburn 6703: }
1.93 raeburn 6704: my ($othertitle,$usertypes,$types) =
6705: &Apache::loncommon::sorted_inst_types($dom);
6706: if (ref($types) eq 'ARRAY') {
6707: if (@{$types} > 0) {
6708: @{$cancreate{'statustocreate'}} =
6709: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6710: } else {
6711: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6712: }
6713: push(@contexts,'statustocreate');
6714: }
1.165 raeburn 6715: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6716: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6717: foreach my $item (@contexts) {
1.93 raeburn 6718: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6719: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6720: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6721: if (ref($cancreate{$item}) eq 'ARRAY') {
6722: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6724: push(@{$changes{'cancreate'}},$item);
6725: }
1.50 raeburn 6726: }
6727: }
6728: }
6729: } else {
6730: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6731: if (@{$cancreate{$item}} > 0) {
6732: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6733: push(@{$changes{'cancreate'}},$item);
6734: }
6735: }
6736: } else {
6737: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6738: if (@{$cancreate{$item}} < 3) {
6739: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6740: push(@{$changes{'cancreate'}},$item);
6741: }
6742: }
6743: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6744: if (@{$cancreate{$item}} > 0) {
6745: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6746: push(@{$changes{'cancreate'}},$item);
6747: }
6748: }
6749: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6750: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6751: push(@{$changes{'cancreate'}},$item);
6752: }
6753: }
6754: }
6755: }
6756: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6757: foreach my $type (@{$cancreate{$item}}) {
6758: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6759: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6760: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6761: push(@{$changes{'cancreate'}},$item);
6762: }
6763: }
6764: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6765: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6766: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6767: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6768: push(@{$changes{'cancreate'}},$item);
6769: }
6770: }
6771: }
6772: }
6773: }
6774: } else {
6775: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6776: push(@{$changes{'cancreate'}},$item);
6777: }
6778: }
1.27 raeburn 6779: }
1.34 raeburn 6780: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6781: foreach my $item (@contexts) {
1.43 raeburn 6782: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6783: if ($cancreate{$item} ne 'any') {
6784: push(@{$changes{'cancreate'}},$item);
6785: }
6786: } else {
6787: if ($cancreate{$item} ne 'none') {
6788: push(@{$changes{'cancreate'}},$item);
6789: }
1.27 raeburn 6790: }
6791: }
6792: } else {
1.43 raeburn 6793: foreach my $item (@contexts) {
1.34 raeburn 6794: push(@{$changes{'cancreate'}},$item);
6795: }
1.27 raeburn 6796: }
1.34 raeburn 6797:
1.27 raeburn 6798: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6799: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6800: if (!grep(/^\Q$type\E$/,@username_rule)) {
6801: push(@{$changes{'username_rule'}},$type);
6802: }
6803: }
6804: foreach my $type (@username_rule) {
6805: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6806: push(@{$changes{'username_rule'}},$type);
6807: }
6808: }
6809: } else {
6810: push(@{$changes{'username_rule'}},@username_rule);
6811: }
6812:
1.32 raeburn 6813: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6814: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6815: if (!grep(/^\Q$type\E$/,@id_rule)) {
6816: push(@{$changes{'id_rule'}},$type);
6817: }
6818: }
6819: foreach my $type (@id_rule) {
6820: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6821: push(@{$changes{'id_rule'}},$type);
6822: }
6823: }
6824: } else {
6825: push(@{$changes{'id_rule'}},@id_rule);
6826: }
6827:
1.43 raeburn 6828: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6829: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6830: if (!grep(/^\Q$type\E$/,@email_rule)) {
6831: push(@{$changes{'email_rule'}},$type);
6832: }
6833: }
6834: foreach my $type (@email_rule) {
6835: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6836: push(@{$changes{'email_rule'}},$type);
6837: }
6838: }
6839: } else {
6840: push(@{$changes{'email_rule'}},@email_rule);
6841: }
6842:
6843: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6844: my @authtypes = ('int','krb4','krb5','loc');
6845: my %authhash;
1.43 raeburn 6846: foreach my $item (@authen_contexts) {
1.28 raeburn 6847: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6848: foreach my $auth (@authtypes) {
6849: if (grep(/^\Q$auth\E$/,@authallowed)) {
6850: $authhash{$item}{$auth} = 1;
6851: } else {
6852: $authhash{$item}{$auth} = 0;
6853: }
6854: }
6855: }
6856: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6857: foreach my $item (@authen_contexts) {
1.28 raeburn 6858: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6859: foreach my $auth (@authtypes) {
6860: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6861: push(@{$changes{'authtypes'}},$item);
6862: last;
6863: }
6864: }
6865: }
6866: }
6867: } else {
1.43 raeburn 6868: foreach my $item (@authen_contexts) {
1.28 raeburn 6869: push(@{$changes{'authtypes'}},$item);
6870: }
6871: }
6872:
1.27 raeburn 6873: my %usercreation_hash = (
1.28 raeburn 6874: usercreation => {
1.34 raeburn 6875: cancreate => \%cancreate,
1.27 raeburn 6876: username_rule => \@username_rule,
1.32 raeburn 6877: id_rule => \@id_rule,
1.43 raeburn 6878: email_rule => \@email_rule,
1.32 raeburn 6879: authtypes => \%authhash,
1.27 raeburn 6880: }
6881: );
6882:
6883: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6884: $dom);
1.50 raeburn 6885:
6886: my %selfcreatetypes = (
6887: sso => 'users authenticated by institutional single sign on',
6888: login => 'users authenticated by institutional log-in',
6889: email => 'users who provide a valid e-mail address for use as the username',
6890: );
1.27 raeburn 6891: if ($putresult eq 'ok') {
6892: if (keys(%changes) > 0) {
6893: $resulttext = &mt('Changes made:').'<ul>';
6894: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6895: my %lt = &usercreation_types();
6896: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6897: my $chgtext;
1.165 raeburn 6898: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6899: $chgtext = $lt{$type}.', ';
6900: }
1.45 raeburn 6901: if ($type eq 'selfcreate') {
1.50 raeburn 6902: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6903: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6904: } else {
1.100 raeburn 6905: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6906: foreach my $case (@{$cancreate{$type}}) {
6907: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6908: }
6909: $chgtext .= '</ul>';
1.100 raeburn 6910: if (ref($cancreate{$type}) eq 'ARRAY') {
6911: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6912: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6913: if (@{$cancreate{'statustocreate'}} == 0) {
6914: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6915: }
6916: }
6917: }
6918: }
1.43 raeburn 6919: }
1.93 raeburn 6920: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6921: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6922: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6923: if (@{$cancreate{'selfcreate'}} > 0) {
6924: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6925:
6926: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6927: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6928: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6929: }
1.96 raeburn 6930: } elsif (ref($usertypes) eq 'HASH') {
6931: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6932: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6933: } else {
6934: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6935: }
6936: $chgtext .= '<ul>';
6937: foreach my $case (@{$cancreate{$type}}) {
6938: if ($case eq 'default') {
6939: $chgtext .= '<li>'.$othertitle.'</li>';
6940: } else {
6941: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6942: }
6943: }
1.100 raeburn 6944: $chgtext .= '</ul>';
6945: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6946: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6947: }
6948: }
6949: } else {
6950: if (@{$cancreate{$type}} == 0) {
6951: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6952: } else {
6953: $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 6954: }
6955: }
6956: }
1.165 raeburn 6957: } elsif ($type eq 'captcha') {
6958: if ($cancreate{$type} eq 'notused') {
6959: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6960: } else {
6961: my %captchas = &captcha_phrases();
6962: if ($captchas{$cancreate{$type}}) {
6963: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6964: } else {
6965: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6966: }
6967: }
6968: } elsif ($type eq 'recaptchakeys') {
6969: my ($privkey,$pubkey);
6970: if (ref($cancreate{$type}) eq 'HASH') {
6971: $pubkey = $cancreate{$type}{'public'};
6972: $privkey = $cancreate{$type}{'private'};
6973: }
6974: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6975: if (!$pubkey) {
6976: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6977: } else {
6978: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6979: }
6980: if (!$privkey) {
6981: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6982: } else {
6983: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6984: }
6985: $chgtext .= '</ul>';
1.43 raeburn 6986: } else {
6987: if ($cancreate{$type} eq 'none') {
6988: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6989: } elsif ($cancreate{$type} eq 'any') {
6990: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6991: } elsif ($cancreate{$type} eq 'official') {
6992: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6993: } elsif ($cancreate{$type} eq 'unofficial') {
6994: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6995: }
1.34 raeburn 6996: }
6997: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6998: }
6999: }
7000: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7001: my ($rules,$ruleorder) =
7002: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7003: my $chgtext = '<ul>';
7004: foreach my $type (@username_rule) {
7005: if (ref($rules->{$type}) eq 'HASH') {
7006: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7007: }
7008: }
7009: $chgtext .= '</ul>';
7010: if (@username_rule > 0) {
7011: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7012: } else {
1.28 raeburn 7013: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7014: }
7015: }
1.32 raeburn 7016: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7017: my ($idrules,$idruleorder) =
7018: &Apache::lonnet::inst_userrules($dom,'id');
7019: my $chgtext = '<ul>';
7020: foreach my $type (@id_rule) {
7021: if (ref($idrules->{$type}) eq 'HASH') {
7022: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7023: }
7024: }
7025: $chgtext .= '</ul>';
7026: if (@id_rule > 0) {
7027: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7028: } else {
7029: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7030: }
7031: }
1.43 raeburn 7032: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7033: my ($emailrules,$emailruleorder) =
7034: &Apache::lonnet::inst_userrules($dom,'email');
7035: my $chgtext = '<ul>';
7036: foreach my $type (@email_rule) {
7037: if (ref($emailrules->{$type}) eq 'HASH') {
7038: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7039: }
7040: }
7041: $chgtext .= '</ul>';
7042: if (@email_rule > 0) {
7043: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7044: } else {
7045: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7046: }
7047: }
7048:
1.28 raeburn 7049: my %authname = &authtype_names();
7050: my %context_title = &context_names();
7051: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7052: my $chgtext = '<ul>';
7053: foreach my $type (@{$changes{'authtypes'}}) {
7054: my @allowed;
7055: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7056: foreach my $auth (@authtypes) {
7057: if ($authhash{$type}{$auth}) {
7058: push(@allowed,$authname{$auth});
7059: }
7060: }
1.43 raeburn 7061: if (@allowed > 0) {
7062: $chgtext .= join(', ',@allowed).'</li>';
7063: } else {
7064: $chgtext .= &mt('none').'</li>';
7065: }
1.28 raeburn 7066: }
7067: $chgtext .= '</ul>';
7068: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7069: $resulttext .= '</li>';
7070: }
1.27 raeburn 7071: $resulttext .= '</ul>';
7072: } else {
1.28 raeburn 7073: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7074: }
7075: } else {
7076: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7077: &mt('An error occurred: [_1]',$putresult).'</span>';
7078: }
1.43 raeburn 7079: if ($warningmsg ne '') {
7080: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7081: }
1.23 raeburn 7082: return $resulttext;
7083: }
7084:
1.165 raeburn 7085: sub process_captcha {
7086: my ($container,$changes,$newsettings,$current) = @_;
7087: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7088: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7089: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7090: $newsettings->{'captcha'} = 'original';
7091: }
7092: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7093: if ($container eq 'cancreate') {
7094: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7095: push(@{$changes->{'cancreate'}},'captcha');
7096: } elsif (!defined($changes->{'cancreate'})) {
7097: $changes->{'cancreate'} = ['captcha'];
7098: }
7099: } else {
7100: $changes->{'captcha'} = 1;
1.165 raeburn 7101: }
7102: }
7103: my ($newpub,$newpriv,$currpub,$currpriv);
7104: if ($newsettings->{'captcha'} eq 'recaptcha') {
7105: $newpub = $env{'form.'.$container.'_recaptchapub'};
7106: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7107: $newpub =~ s/\W//g;
7108: $newpriv =~ s/\W//g;
7109: $newsettings->{'recaptchakeys'} = {
7110: public => $newpub,
7111: private => $newpriv,
7112: };
1.165 raeburn 7113: }
7114: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7115: $currpub = $current->{'recaptchakeys'}{'public'};
7116: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7117: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7118: $newsettings->{'recaptchakeys'} = {
7119: public => '',
7120: private => '',
7121: }
7122: }
1.165 raeburn 7123: }
7124: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7125: if ($container eq 'cancreate') {
7126: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7127: push(@{$changes->{'cancreate'}},'recaptchakeys');
7128: } elsif (!defined($changes->{'cancreate'})) {
7129: $changes->{'cancreate'} = ['recaptchakeys'];
7130: }
7131: } else {
7132: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7133: }
7134: }
7135: return;
7136: }
7137:
1.33 raeburn 7138: sub modify_usermodification {
7139: my ($dom,%domconfig) = @_;
7140: my ($resulttext,%curr_usermodification,%changes);
7141: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7142: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7143: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7144: }
7145: }
1.63 raeburn 7146: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7147: my %context_title = (
7148: author => 'In author context',
7149: course => 'In course context',
1.63 raeburn 7150: selfcreate => 'When self creating account',
1.33 raeburn 7151: );
7152: my @fields = ('lastname','firstname','middlename','generation',
7153: 'permanentemail','id');
7154: my %roles = (
7155: author => ['ca','aa'],
7156: course => ['st','ep','ta','in','cr'],
7157: );
1.63 raeburn 7158: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7159: if (ref($types) eq 'ARRAY') {
7160: push(@{$types},'default');
7161: $usertypes->{'default'} = $othertitle;
7162: }
7163: $roles{'selfcreate'} = $types;
1.33 raeburn 7164: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7165: my %modifyhash;
7166: foreach my $context (@contexts) {
7167: foreach my $role (@{$roles{$context}}) {
7168: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7169: foreach my $item (@fields) {
7170: if (grep(/^\Q$item\E$/,@modifiable)) {
7171: $modifyhash{$context}{$role}{$item} = 1;
7172: } else {
7173: $modifyhash{$context}{$role}{$item} = 0;
7174: }
7175: }
7176: }
7177: if (ref($curr_usermodification{$context}) eq 'HASH') {
7178: foreach my $role (@{$roles{$context}}) {
7179: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7180: foreach my $field (@fields) {
7181: if ($modifyhash{$context}{$role}{$field} ne
7182: $curr_usermodification{$context}{$role}{$field}) {
7183: push(@{$changes{$context}},$role);
7184: last;
7185: }
7186: }
7187: }
7188: }
7189: } else {
7190: foreach my $context (@contexts) {
7191: foreach my $role (@{$roles{$context}}) {
7192: push(@{$changes{$context}},$role);
7193: }
7194: }
7195: }
7196: }
7197: my %usermodification_hash = (
7198: usermodification => \%modifyhash,
7199: );
7200: my $putresult = &Apache::lonnet::put_dom('configuration',
7201: \%usermodification_hash,$dom);
7202: if ($putresult eq 'ok') {
7203: if (keys(%changes) > 0) {
7204: $resulttext = &mt('Changes made: ').'<ul>';
7205: foreach my $context (@contexts) {
7206: if (ref($changes{$context}) eq 'ARRAY') {
7207: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7208: if (ref($changes{$context}) eq 'ARRAY') {
7209: foreach my $role (@{$changes{$context}}) {
7210: my $rolename;
1.63 raeburn 7211: if ($context eq 'selfcreate') {
7212: $rolename = $role;
7213: if (ref($usertypes) eq 'HASH') {
7214: if ($usertypes->{$role} ne '') {
7215: $rolename = $usertypes->{$role};
7216: }
7217: }
1.33 raeburn 7218: } else {
1.63 raeburn 7219: if ($role eq 'cr') {
7220: $rolename = &mt('Custom');
7221: } else {
7222: $rolename = &Apache::lonnet::plaintext($role);
7223: }
1.33 raeburn 7224: }
7225: my @modifiable;
1.63 raeburn 7226: if ($context eq 'selfcreate') {
1.126 bisitz 7227: $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 7228: } else {
7229: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7230: }
1.33 raeburn 7231: foreach my $field (@fields) {
7232: if ($modifyhash{$context}{$role}{$field}) {
7233: push(@modifiable,$fieldtitles{$field});
7234: }
7235: }
7236: if (@modifiable > 0) {
7237: $resulttext .= join(', ',@modifiable);
7238: } else {
7239: $resulttext .= &mt('none');
7240: }
7241: $resulttext .= '</li>';
7242: }
7243: $resulttext .= '</ul></li>';
7244: }
7245: }
7246: }
7247: $resulttext .= '</ul>';
7248: } else {
7249: $resulttext = &mt('No changes made to user modification settings');
7250: }
7251: } else {
7252: $resulttext = '<span class="LC_error">'.
7253: &mt('An error occurred: [_1]',$putresult).'</span>';
7254: }
7255: return $resulttext;
7256: }
7257:
1.43 raeburn 7258: sub modify_defaults {
7259: my ($dom,$r) = @_;
7260: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7261: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7262: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7263: my @authtypes = ('internal','krb4','krb5','localauth');
7264: foreach my $item (@items) {
7265: $newvalues{$item} = $env{'form.'.$item};
7266: if ($item eq 'auth_def') {
7267: if ($newvalues{$item} ne '') {
7268: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7269: push(@errors,$item);
7270: }
7271: }
7272: } elsif ($item eq 'lang_def') {
7273: if ($newvalues{$item} ne '') {
7274: if ($newvalues{$item} =~ /^(\w+)/) {
7275: my $langcode = $1;
1.103 raeburn 7276: if ($langcode ne 'x_chef') {
7277: if (code2language($langcode) eq '') {
7278: push(@errors,$item);
7279: }
1.43 raeburn 7280: }
7281: } else {
7282: push(@errors,$item);
7283: }
7284: }
1.54 raeburn 7285: } elsif ($item eq 'timezone_def') {
7286: if ($newvalues{$item} ne '') {
1.62 raeburn 7287: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7288: push(@errors,$item);
7289: }
7290: }
1.68 raeburn 7291: } elsif ($item eq 'datelocale_def') {
7292: if ($newvalues{$item} ne '') {
7293: my @datelocale_ids = DateTime::Locale->ids();
7294: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7295: push(@errors,$item);
7296: }
7297: }
1.141 raeburn 7298: } elsif ($item eq 'portal_def') {
7299: if ($newvalues{$item} ne '') {
7300: 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])\/?$/) {
7301: push(@errors,$item);
7302: }
7303: }
1.43 raeburn 7304: }
7305: if (grep(/^\Q$item\E$/,@errors)) {
7306: $newvalues{$item} = $domdefaults{$item};
7307: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7308: $changes{$item} = 1;
7309: }
1.72 raeburn 7310: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7311: }
7312: my %defaults_hash = (
1.72 raeburn 7313: defaults => \%newvalues,
7314: );
1.43 raeburn 7315: my $title = &defaults_titles();
7316: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7317: $dom);
7318: if ($putresult eq 'ok') {
7319: if (keys(%changes) > 0) {
7320: $resulttext = &mt('Changes made:').'<ul>';
7321: my $version = $r->dir_config('lonVersion');
7322: 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";
7323: foreach my $item (sort(keys(%changes))) {
7324: my $value = $env{'form.'.$item};
7325: if ($value eq '') {
7326: $value = &mt('none');
7327: } elsif ($item eq 'auth_def') {
7328: my %authnames = &authtype_names();
7329: my %shortauth = (
7330: internal => 'int',
7331: krb4 => 'krb4',
7332: krb5 => 'krb5',
7333: localauth => 'loc',
7334: );
7335: $value = $authnames{$shortauth{$value}};
7336: }
7337: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7338: $mailmsgtext .= "$title->{$item} set to $value\n";
7339: }
7340: $resulttext .= '</ul>';
7341: $mailmsgtext .= "\n";
7342: my $cachetime = 24*60*60;
1.72 raeburn 7343: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7344: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7345: my $sysmail = $r->dir_config('lonSysEMail');
7346: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7347: }
1.43 raeburn 7348: } else {
1.54 raeburn 7349: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7350: }
7351: } else {
7352: $resulttext = '<span class="LC_error">'.
7353: &mt('An error occurred: [_1]',$putresult).'</span>';
7354: }
7355: if (@errors > 0) {
7356: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7357: foreach my $item (@errors) {
7358: $resulttext .= ' "'.$title->{$item}.'",';
7359: }
7360: $resulttext =~ s/,$//;
7361: }
7362: return $resulttext;
7363: }
7364:
1.46 raeburn 7365: sub modify_scantron {
1.48 raeburn 7366: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7367: my ($resulttext,%confhash,%changes,$errors);
7368: my $custom = 'custom.tab';
7369: my $default = 'default.tab';
7370: my $servadm = $r->dir_config('lonAdmEMail');
7371: my ($configuserok,$author_ok,$switchserver) =
7372: &config_check($dom,$confname,$servadm);
7373: if ($env{'form.scantronformat.filename'} ne '') {
7374: my $error;
7375: if ($configuserok eq 'ok') {
7376: if ($switchserver) {
1.130 raeburn 7377: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7378: } else {
7379: if ($author_ok eq 'ok') {
7380: my ($result,$scantronurl) =
7381: &publishlogo($r,'upload','scantronformat',$dom,
7382: $confname,'scantron','','',$custom);
7383: if ($result eq 'ok') {
7384: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7385: $changes{'scantronformat'} = 1;
1.46 raeburn 7386: } else {
7387: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7388: }
7389: } else {
7390: $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);
7391: }
7392: }
7393: } else {
7394: $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);
7395: }
7396: if ($error) {
7397: &Apache::lonnet::logthis($error);
7398: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7399: }
7400: }
1.48 raeburn 7401: if (ref($domconfig{'scantron'}) eq 'HASH') {
7402: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7403: if ($env{'form.scantronformat_del'}) {
7404: $confhash{'scantron'}{'scantronformat'} = '';
7405: $changes{'scantronformat'} = 1;
1.46 raeburn 7406: }
7407: }
7408: }
7409: if (keys(%confhash) > 0) {
7410: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7411: $dom);
7412: if ($putresult eq 'ok') {
7413: if (keys(%changes) > 0) {
1.48 raeburn 7414: if (ref($confhash{'scantron'}) eq 'HASH') {
7415: $resulttext = &mt('Changes made:').'<ul>';
7416: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7417: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7418: } else {
1.130 raeburn 7419: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7420: }
1.48 raeburn 7421: $resulttext .= '</ul>';
7422: } else {
1.130 raeburn 7423: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7424: }
7425: $resulttext .= '</ul>';
7426: &Apache::loncommon::devalidate_domconfig_cache($dom);
7427: } else {
1.130 raeburn 7428: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7429: }
7430: } else {
7431: $resulttext = '<span class="LC_error">'.
7432: &mt('An error occurred: [_1]',$putresult).'</span>';
7433: }
7434: } else {
1.130 raeburn 7435: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7436: }
7437: if ($errors) {
7438: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7439: $errors.'</ul>';
7440: }
7441: return $resulttext;
7442: }
7443:
1.48 raeburn 7444: sub modify_coursecategories {
7445: my ($dom,%domconfig) = @_;
1.57 raeburn 7446: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7447: $cathash);
1.48 raeburn 7448: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7449: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7450: $cathash = $domconfig{'coursecategories'}{'cats'};
7451: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7452: $changes{'togglecats'} = 1;
7453: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7454: }
7455: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7456: $changes{'categorize'} = 1;
7457: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7458: }
1.120 raeburn 7459: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7460: $changes{'togglecatscomm'} = 1;
7461: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7462: }
7463: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7464: $changes{'categorizecomm'} = 1;
7465: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7466: }
1.57 raeburn 7467: } else {
7468: $changes{'togglecats'} = 1;
7469: $changes{'categorize'} = 1;
1.124 raeburn 7470: $changes{'togglecatscomm'} = 1;
7471: $changes{'categorizecomm'} = 1;
1.87 raeburn 7472: $domconfig{'coursecategories'} = {
7473: togglecats => $env{'form.togglecats'},
7474: categorize => $env{'form.categorize'},
1.124 raeburn 7475: togglecatscomm => $env{'form.togglecatscomm'},
7476: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7477: };
1.57 raeburn 7478: }
7479: if (ref($cathash) eq 'HASH') {
7480: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7481: push (@deletecategory,'instcode::0');
7482: }
1.120 raeburn 7483: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7484: push(@deletecategory,'communities::0');
7485: }
1.48 raeburn 7486: }
1.57 raeburn 7487: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7488: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7489: if (@deletecategory > 0) {
7490: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7491: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7492: foreach my $item (@deletecategory) {
1.57 raeburn 7493: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7494: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7495: $deletions{$item} = 1;
1.57 raeburn 7496: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7497: }
7498: }
7499: }
1.57 raeburn 7500: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7501: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7502: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7503: $reorderings{$item} = 1;
1.57 raeburn 7504: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7505: }
7506: if ($env{'form.addcategory_name_'.$item} ne '') {
7507: my $newcat = $env{'form.addcategory_name_'.$item};
7508: my $newdepth = $depth+1;
7509: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7510: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7511: $adds{$newitem} = 1;
7512: }
7513: if ($env{'form.subcat_'.$item} ne '') {
7514: my $newcat = $env{'form.subcat_'.$item};
7515: my $newdepth = $depth+1;
7516: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7517: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7518: $adds{$newitem} = 1;
7519: }
7520: }
7521: }
7522: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7523: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7524: my $newitem = 'instcode::0';
1.57 raeburn 7525: if ($cathash->{$newitem} eq '') {
7526: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7527: $adds{$newitem} = 1;
7528: }
7529: } else {
7530: my $newitem = 'instcode::0';
1.57 raeburn 7531: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7532: $adds{$newitem} = 1;
7533: }
7534: }
1.120 raeburn 7535: if ($env{'form.communities'} eq '1') {
7536: if (ref($cathash) eq 'HASH') {
7537: my $newitem = 'communities::0';
7538: if ($cathash->{$newitem} eq '') {
7539: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7540: $adds{$newitem} = 1;
7541: }
7542: } else {
7543: my $newitem = 'communities::0';
7544: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7545: $adds{$newitem} = 1;
7546: }
7547: }
1.48 raeburn 7548: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7549: if (($env{'form.addcategory_name'} ne 'instcode') &&
7550: ($env{'form.addcategory_name'} ne 'communities')) {
7551: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7552: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7553: $adds{$newitem} = 1;
7554: }
1.48 raeburn 7555: }
1.57 raeburn 7556: my $putresult;
1.48 raeburn 7557: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7558: if (keys(%deletions) > 0) {
7559: foreach my $key (keys(%deletions)) {
7560: if ($predelallitems{$key} ne '') {
7561: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7562: }
7563: }
7564: }
7565: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7566: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7567: if (ref($chkcats[0]) eq 'ARRAY') {
7568: my $depth = 0;
7569: my $chg = 0;
7570: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7571: my $name = $chkcats[0][$i];
7572: my $item;
7573: if ($name eq '') {
7574: $chg ++;
7575: } else {
7576: $item = &escape($name).'::0';
7577: if ($chg) {
1.57 raeburn 7578: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7579: }
7580: $depth ++;
1.57 raeburn 7581: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7582: $depth --;
7583: }
7584: }
7585: }
1.57 raeburn 7586: }
7587: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7588: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7589: if ($putresult eq 'ok') {
1.57 raeburn 7590: my %title = (
1.120 raeburn 7591: togglecats => 'Show/Hide a course in catalog',
7592: categorize => 'Assign a category to a course',
7593: togglecatscomm => 'Show/Hide a community in catalog',
7594: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7595: );
7596: my %level = (
1.120 raeburn 7597: dom => 'set in Domain ("Modify Course/Community")',
7598: crs => 'set in Course ("Course Configuration")',
7599: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7600: );
1.48 raeburn 7601: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7602: if ($changes{'togglecats'}) {
7603: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7604: }
7605: if ($changes{'categorize'}) {
7606: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7607: }
1.120 raeburn 7608: if ($changes{'togglecatscomm'}) {
7609: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7610: }
7611: if ($changes{'categorizecomm'}) {
7612: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7613: }
1.57 raeburn 7614: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7615: my $cathash;
7616: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7617: $cathash = $domconfig{'coursecategories'}{'cats'};
7618: } else {
7619: $cathash = {};
7620: }
7621: my (@cats,@trails,%allitems);
7622: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7623: if (keys(%deletions) > 0) {
7624: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7625: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7626: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7627: }
7628: $resulttext .= '</ul></li>';
7629: }
7630: if (keys(%reorderings) > 0) {
7631: my %sort_by_trail;
7632: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7633: foreach my $key (keys(%reorderings)) {
7634: if ($allitems{$key} ne '') {
7635: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7636: }
1.48 raeburn 7637: }
1.57 raeburn 7638: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7639: $resulttext .= '<li>'.$trails[$trail].'</li>';
7640: }
7641: $resulttext .= '</ul></li>';
1.48 raeburn 7642: }
1.57 raeburn 7643: if (keys(%adds) > 0) {
7644: my %sort_by_trail;
7645: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7646: foreach my $key (keys(%adds)) {
7647: if ($allitems{$key} ne '') {
7648: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7649: }
7650: }
7651: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7652: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7653: }
1.57 raeburn 7654: $resulttext .= '</ul></li>';
1.48 raeburn 7655: }
7656: }
7657: $resulttext .= '</ul>';
7658: } else {
7659: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7660: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7661: }
7662: } else {
1.120 raeburn 7663: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7664: }
7665: return $resulttext;
7666: }
7667:
1.69 raeburn 7668: sub modify_serverstatuses {
7669: my ($dom,%domconfig) = @_;
7670: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7671: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7672: %currserverstatus = %{$domconfig{'serverstatuses'}};
7673: }
7674: my @pages = &serverstatus_pages();
7675: foreach my $type (@pages) {
7676: $newserverstatus{$type}{'namedusers'} = '';
7677: $newserverstatus{$type}{'machines'} = '';
7678: if (defined($env{'form.'.$type.'_namedusers'})) {
7679: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7680: my @okusers;
7681: foreach my $user (@users) {
7682: my ($uname,$udom) = split(/:/,$user);
7683: if (($udom =~ /^$match_domain$/) &&
7684: (&Apache::lonnet::domain($udom)) &&
7685: ($uname =~ /^$match_username$/)) {
7686: if (!grep(/^\Q$user\E/,@okusers)) {
7687: push(@okusers,$user);
7688: }
7689: }
7690: }
7691: if (@okusers > 0) {
7692: @okusers = sort(@okusers);
7693: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7694: }
7695: }
7696: if (defined($env{'form.'.$type.'_machines'})) {
7697: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7698: my @okmachines;
7699: foreach my $ip (@machines) {
7700: my @parts = split(/\./,$ip);
7701: next if (@parts < 4);
7702: my $badip = 0;
7703: for (my $i=0; $i<4; $i++) {
7704: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7705: $badip = 1;
7706: last;
7707: }
7708: }
7709: if (!$badip) {
7710: push(@okmachines,$ip);
7711: }
7712: }
7713: @okmachines = sort(@okmachines);
7714: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7715: }
7716: }
7717: my %serverstatushash = (
7718: serverstatuses => \%newserverstatus,
7719: );
7720: foreach my $type (@pages) {
1.83 raeburn 7721: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7722: my (@current,@new);
1.83 raeburn 7723: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7724: if ($currserverstatus{$type}{$setting} ne '') {
7725: @current = split(/,/,$currserverstatus{$type}{$setting});
7726: }
7727: }
7728: if ($newserverstatus{$type}{$setting} ne '') {
7729: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7730: }
7731: if (@current > 0) {
7732: if (@new > 0) {
7733: foreach my $item (@current) {
7734: if (!grep(/^\Q$item\E$/,@new)) {
7735: $changes{$type}{$setting} = 1;
1.82 raeburn 7736: last;
7737: }
7738: }
1.84 raeburn 7739: foreach my $item (@new) {
7740: if (!grep(/^\Q$item\E$/,@current)) {
7741: $changes{$type}{$setting} = 1;
7742: last;
1.82 raeburn 7743: }
7744: }
7745: } else {
1.83 raeburn 7746: $changes{$type}{$setting} = 1;
1.69 raeburn 7747: }
1.83 raeburn 7748: } elsif (@new > 0) {
7749: $changes{$type}{$setting} = 1;
1.69 raeburn 7750: }
7751: }
7752: }
7753: if (keys(%changes) > 0) {
1.81 raeburn 7754: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7755: my $putresult = &Apache::lonnet::put_dom('configuration',
7756: \%serverstatushash,$dom);
7757: if ($putresult eq 'ok') {
7758: $resulttext .= &mt('Changes made:').'<ul>';
7759: foreach my $type (@pages) {
1.84 raeburn 7760: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7761: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7762: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7763: if ($newserverstatus{$type}{'namedusers'} eq '') {
7764: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7765: } else {
7766: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7767: }
1.84 raeburn 7768: }
7769: if ($changes{$type}{'machines'}) {
1.69 raeburn 7770: if ($newserverstatus{$type}{'machines'} eq '') {
7771: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7772: } else {
7773: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7774: }
7775:
7776: }
7777: $resulttext .= '</ul></li>';
7778: }
7779: }
7780: $resulttext .= '</ul>';
7781: } else {
7782: $resulttext = '<span class="LC_error">'.
7783: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7784:
7785: }
7786: } else {
7787: $resulttext = &mt('No changes made to access to server status pages');
7788: }
7789: return $resulttext;
7790: }
7791:
1.118 jms 7792: sub modify_helpsettings {
1.122 jms 7793: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7794: my ($resulttext,$errors,%changes,%helphash);
7795: my %defaultchecked = ('submitbugs' => 'on');
7796: my @offon = ('off','on');
1.118 jms 7797: my @toggles = ('submitbugs');
7798: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7799: foreach my $item (@toggles) {
1.166 raeburn 7800: if ($defaultchecked{$item} eq 'on') {
7801: if ($domconfig{'helpsettings'}{$item} eq '') {
7802: if ($env{'form.'.$item} eq '0') {
7803: $changes{$item} = 1;
7804: }
7805: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7806: $changes{$item} = 1;
7807: }
7808: } elsif ($defaultchecked{$item} eq 'off') {
7809: if ($domconfig{'helpsettings'}{$item} eq '') {
7810: if ($env{'form.'.$item} eq '1') {
7811: $changes{$item} = 1;
7812: }
7813: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7814: $changes{$item} = 1;
7815: }
7816: }
7817: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7818: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7819: }
7820: }
1.118 jms 7821: }
1.123 jms 7822: my $putresult;
7823: if (keys(%changes) > 0) {
1.166 raeburn 7824: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7825: if ($putresult eq 'ok') {
1.166 raeburn 7826: $resulttext = &mt('Changes made:').'<ul>';
7827: foreach my $item (sort(keys(%changes))) {
7828: if ($item eq 'submitbugs') {
7829: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7830: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7831: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7832: }
7833: }
7834: $resulttext .= '</ul>';
7835: } else {
7836: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7837: $errors .= '<li><span class="LC_error">'.
7838: &mt('An error occurred storing the settings: [_1]',
7839: $putresult).'</span></li>';
1.166 raeburn 7840: }
1.118 jms 7841: }
7842: if ($errors) {
1.168 raeburn 7843: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7844: $errors.'</ul>';
7845: }
7846: return $resulttext;
7847: }
7848:
1.121 raeburn 7849: sub modify_coursedefaults {
7850: my ($dom,%domconfig) = @_;
7851: my ($resulttext,$errors,%changes,%defaultshash);
7852: my %defaultchecked = ('canuse_pdfforms' => 'off');
7853: my @offon = ('off','on');
7854: my @toggles = ('canuse_pdfforms');
7855:
7856: $defaultshash{'coursedefaults'} = {};
7857:
7858: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7859: if ($domconfig{'coursedefaults'} eq '') {
7860: $domconfig{'coursedefaults'} = {};
7861: }
7862: }
7863:
7864: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7865: foreach my $item (@toggles) {
7866: if ($defaultchecked{$item} eq 'on') {
7867: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7868: ($env{'form.'.$item} eq '0')) {
7869: $changes{$item} = 1;
7870: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7871: $changes{$item} = 1;
7872: }
7873: } elsif ($defaultchecked{$item} eq 'off') {
7874: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7875: ($env{'form.'.$item} eq '1')) {
7876: $changes{$item} = 1;
7877: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7878: $changes{$item} = 1;
7879: }
7880: }
7881: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7882: }
1.139 raeburn 7883: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7884: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7885: $newdefresponder =~ s/\D//g;
7886: if ($newdefresponder eq '' || $newdefresponder < 1) {
7887: $newdefresponder = 1;
7888: }
7889: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7890: if ($currdefresponder ne $newdefresponder) {
7891: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7892: $changes{'anonsurvey_threshold'} = 1;
7893: }
7894: }
1.121 raeburn 7895: }
7896: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7897: $dom);
7898: if ($putresult eq 'ok') {
7899: if (keys(%changes) > 0) {
7900: if ($changes{'canuse_pdfforms'}) {
7901: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7902: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7903: my $cachetime = 24*60*60;
7904: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7905: }
7906: $resulttext = &mt('Changes made:').'<ul>';
7907: foreach my $item (sort(keys(%changes))) {
7908: if ($item eq 'canuse_pdfforms') {
7909: if ($env{'form.'.$item} eq '1') {
7910: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7911: } else {
7912: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7913: }
1.139 raeburn 7914: } elsif ($item eq 'anonsurvey_threshold') {
7915: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7916: }
1.121 raeburn 7917: }
7918: $resulttext .= '</ul>';
7919: } else {
7920: $resulttext = &mt('No changes made to course defaults');
7921: }
7922: } else {
7923: $resulttext = '<span class="LC_error">'.
7924: &mt('An error occurred: [_1]',$putresult).'</span>';
7925: }
7926: return $resulttext;
7927: }
7928:
1.137 raeburn 7929: sub modify_usersessions {
7930: my ($dom,%domconfig) = @_;
1.145 raeburn 7931: my @hostingtypes = ('version','excludedomain','includedomain');
7932: my @offloadtypes = ('primary','default');
7933: my %types = (
7934: remote => \@hostingtypes,
7935: hosted => \@hostingtypes,
7936: spares => \@offloadtypes,
7937: );
7938: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7939: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7940: my (%by_ip,%by_location,@intdoms);
7941: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7942: my @locations = sort(keys(%by_location));
1.137 raeburn 7943: my (%defaultshash,%changes);
7944: foreach my $prefix (@prefixes) {
7945: $defaultshash{'usersessions'}{$prefix} = {};
7946: }
7947: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7948: my $resulttext;
1.138 raeburn 7949: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7950: foreach my $prefix (@prefixes) {
1.145 raeburn 7951: next if ($prefix eq 'spares');
7952: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7953: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7954: if ($type eq 'version') {
7955: my $value = $env{'form.'.$prefix.'_'.$type};
7956: my $okvalue;
7957: if ($value ne '') {
7958: if (grep(/^\Q$value\E$/,@lcversions)) {
7959: $okvalue = $value;
7960: }
7961: }
7962: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7963: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7964: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7965: if ($inuse == 0) {
7966: $changes{$prefix}{$type} = 1;
7967: } else {
7968: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7969: $changes{$prefix}{$type} = 1;
7970: }
7971: if ($okvalue ne '') {
7972: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7973: }
7974: }
7975: } else {
7976: if (($inuse == 1) && ($okvalue ne '')) {
7977: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7978: $changes{$prefix}{$type} = 1;
7979: }
7980: }
7981: } else {
7982: if (($inuse == 1) && ($okvalue ne '')) {
7983: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7984: $changes{$prefix}{$type} = 1;
7985: }
7986: }
7987: } else {
7988: if (($inuse == 1) && ($okvalue ne '')) {
7989: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7990: $changes{$prefix}{$type} = 1;
7991: }
7992: }
7993: } else {
7994: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7995: my @okvals;
7996: foreach my $val (@vals) {
1.138 raeburn 7997: if ($val =~ /:/) {
7998: my @items = split(/:/,$val);
7999: foreach my $item (@items) {
8000: if (ref($by_location{$item}) eq 'ARRAY') {
8001: push(@okvals,$item);
8002: }
8003: }
8004: } else {
8005: if (ref($by_location{$val}) eq 'ARRAY') {
8006: push(@okvals,$val);
8007: }
1.137 raeburn 8008: }
8009: }
8010: @okvals = sort(@okvals);
8011: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8012: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8013: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8014: if ($inuse == 0) {
8015: $changes{$prefix}{$type} = 1;
8016: } else {
8017: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8018: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8019: if (@changed > 0) {
8020: $changes{$prefix}{$type} = 1;
8021: }
8022: }
8023: } else {
8024: if ($inuse == 1) {
8025: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8026: $changes{$prefix}{$type} = 1;
8027: }
8028: }
8029: } else {
8030: if ($inuse == 1) {
8031: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8032: $changes{$prefix}{$type} = 1;
8033: }
8034: }
8035: } else {
8036: if ($inuse == 1) {
8037: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8038: $changes{$prefix}{$type} = 1;
8039: }
8040: }
8041: }
8042: }
8043: }
1.145 raeburn 8044:
8045: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8046: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8047: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8048: my $savespares;
8049:
8050: foreach my $lonhost (sort(keys(%servers))) {
8051: my $serverhomeID =
8052: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8053: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8054: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8055: my %spareschg;
8056: foreach my $type (@{$types{'spares'}}) {
8057: my @okspares;
8058: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8059: foreach my $server (@checked) {
1.152 raeburn 8060: if (&Apache::lonnet::hostname($server) ne '') {
8061: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8062: unless (grep(/^\Q$server\E$/,@okspares)) {
8063: push(@okspares,$server);
8064: }
1.145 raeburn 8065: }
8066: }
8067: }
8068: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8069: my $newspare;
1.152 raeburn 8070: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8071: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8072: $newspare = $new;
8073: }
8074: }
1.152 raeburn 8075: my @spares;
8076: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8077: @spares = sort(@okspares,$newspare);
8078: } else {
8079: @spares = sort(@okspares);
8080: }
8081: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8082: if (ref($spareid{$lonhost}) eq 'HASH') {
8083: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8084: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8085: if (@diffs > 0) {
8086: $spareschg{$type} = 1;
8087: }
8088: }
8089: }
8090: }
8091: if (keys(%spareschg) > 0) {
8092: $changes{'spares'}{$lonhost} = \%spareschg;
8093: }
8094: }
8095:
8096: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8097: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8098: if (ref($changes{'spares'}) eq 'HASH') {
8099: if (keys(%{$changes{'spares'}}) > 0) {
8100: $savespares = 1;
8101: }
8102: }
8103: } else {
8104: $savespares = 1;
8105: }
8106: }
8107:
1.147 raeburn 8108: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8109: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8110: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8111: $dom);
8112: if ($putresult eq 'ok') {
8113: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8114: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8115: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8116: }
8117: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8118: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8119: }
8120: }
8121: my $cachetime = 24*60*60;
8122: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8123: if (keys(%changes) > 0) {
8124: my %lt = &usersession_titles();
8125: $resulttext = &mt('Changes made:').'<ul>';
8126: foreach my $prefix (@prefixes) {
8127: if (ref($changes{$prefix}) eq 'HASH') {
8128: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8129: if ($prefix eq 'spares') {
8130: if (ref($changes{$prefix}) eq 'HASH') {
8131: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8132: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8133: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8134: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8135: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8136: foreach my $type (@{$types{$prefix}}) {
8137: if ($changes{$prefix}{$lonhost}{$type}) {
8138: my $offloadto = &mt('None');
8139: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8140: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8141: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8142: }
1.145 raeburn 8143: }
1.147 raeburn 8144: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8145: }
1.137 raeburn 8146: }
8147: }
1.147 raeburn 8148: $resulttext .= '</li>';
1.137 raeburn 8149: }
8150: }
1.147 raeburn 8151: } else {
8152: foreach my $type (@{$types{$prefix}}) {
8153: if (defined($changes{$prefix}{$type})) {
8154: my $newvalue;
8155: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8156: if (ref($defaultshash{'usersessions'}{$prefix})) {
8157: if ($type eq 'version') {
8158: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8159: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8160: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8161: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8162: }
1.145 raeburn 8163: }
8164: }
8165: }
1.147 raeburn 8166: if ($newvalue eq '') {
8167: if ($type eq 'version') {
8168: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8169: } else {
8170: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8171: }
1.145 raeburn 8172: } else {
1.147 raeburn 8173: if ($type eq 'version') {
8174: $newvalue .= ' '.&mt('(or later)');
8175: }
8176: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8177: }
1.137 raeburn 8178: }
8179: }
8180: }
1.147 raeburn 8181: $resulttext .= '</ul>';
1.137 raeburn 8182: }
8183: }
1.147 raeburn 8184: $resulttext .= '</ul>';
8185: } else {
8186: $resulttext = $nochgmsg;
1.137 raeburn 8187: }
8188: } else {
8189: $resulttext = '<span class="LC_error">'.
8190: &mt('An error occurred: [_1]',$putresult).'</span>';
8191: }
8192: } else {
1.147 raeburn 8193: $resulttext = $nochgmsg;
1.137 raeburn 8194: }
8195: return $resulttext;
8196: }
8197:
1.150 raeburn 8198: sub modify_loadbalancing {
8199: my ($dom,%domconfig) = @_;
8200: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8201: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8202: my ($othertitle,$usertypes,$types) =
8203: &Apache::loncommon::sorted_inst_types($dom);
8204: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8205: my @sparestypes = ('primary','default');
8206: my %typetitles = &sparestype_titles();
8207: my $resulttext;
1.171 raeburn 8208: my (%currbalancer,%currtargets,%currrules,%existing);
8209: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8210: %existing = %{$domconfig{'loadbalancing'}};
8211: }
8212: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8213: \%currtargets,\%currrules);
8214: my ($saveloadbalancing,%defaultshash,%changes);
8215: my ($alltypes,$othertypes,$titles) =
8216: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8217: my %ruletitles = &offloadtype_text();
8218: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8219: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8220: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8221: if ($balancer eq '') {
8222: next;
8223: }
8224: if (!exists($servers{$balancer})) {
8225: if (exists($currbalancer{$balancer})) {
8226: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8227: }
1.171 raeburn 8228: next;
8229: }
8230: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8231: push(@{$changes{'delete'}},$balancer);
8232: next;
8233: }
8234: if (!exists($currbalancer{$balancer})) {
8235: push(@{$changes{'add'}},$balancer);
8236: }
8237: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8238: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8239: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8240: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8241: $saveloadbalancing = 1;
8242: }
8243: foreach my $sparetype (@sparestypes) {
8244: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8245: my @offloadto;
8246: foreach my $target (@targets) {
8247: if (($servers{$target}) && ($target ne $balancer)) {
8248: if ($sparetype eq 'default') {
8249: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8250: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8251: }
8252: }
1.171 raeburn 8253: unless(grep(/^\Q$target\E$/,@offloadto)) {
8254: push(@offloadto,$target);
8255: }
1.150 raeburn 8256: }
1.171 raeburn 8257: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8258: }
8259: }
1.171 raeburn 8260: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8261: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8262: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8263: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8264: if (@targetdiffs > 0) {
1.171 raeburn 8265: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8266: }
1.171 raeburn 8267: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8268: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8269: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8270: }
8271: }
8272: }
8273: } else {
1.171 raeburn 8274: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8275: foreach my $sparetype (@sparestypes) {
8276: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8277: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8278: $changes{'curr'}{$balancer}{'targets'} = 1;
8279: }
1.150 raeburn 8280: }
8281: }
8282: }
8283: }
8284: my $ishomedom;
1.171 raeburn 8285: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8286: $ishomedom = 1;
1.150 raeburn 8287: }
8288: if (ref($alltypes) eq 'ARRAY') {
8289: foreach my $type (@{$alltypes}) {
8290: my $rule;
1.171 raeburn 8291: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8292: (!$ishomedom)) {
1.171 raeburn 8293: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8294: }
8295: if ($rule eq 'specific') {
8296: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8297: }
1.171 raeburn 8298: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8299: if (ref($currrules{$balancer}) eq 'HASH') {
8300: if ($rule ne $currrules{$balancer}{$type}) {
8301: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8302: }
8303: } elsif ($rule ne '') {
1.171 raeburn 8304: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8305: }
8306: }
8307: }
1.171 raeburn 8308: }
8309: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8310: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8311: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8312: $defaultshash{'loadbalancing'} = {};
8313: }
8314: my $putresult = &Apache::lonnet::put_dom('configuration',
8315: \%defaultshash,$dom);
8316:
8317: if ($putresult eq 'ok') {
8318: if (keys(%changes) > 0) {
8319: if (ref($changes{'delete'}) eq 'ARRAY') {
8320: foreach my $balancer (sort(@{$changes{'delete'}})) {
8321: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8322: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8323: }
1.171 raeburn 8324: }
8325: if (ref($changes{'add'}) eq 'ARRAY') {
8326: foreach my $balancer (sort(@{$changes{'add'}})) {
8327: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8328: }
8329: }
8330: if (ref($changes{'curr'}) eq 'HASH') {
8331: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8332: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8333: if ($changes{'curr'}{$balancer}{'targets'}) {
8334: my %offloadstr;
8335: foreach my $sparetype (@sparestypes) {
8336: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8337: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8338: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8339: }
8340: }
1.150 raeburn 8341: }
1.171 raeburn 8342: if (keys(%offloadstr) == 0) {
8343: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8344: } else {
1.171 raeburn 8345: my $showoffload;
8346: foreach my $sparetype (@sparestypes) {
8347: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8348: if (defined($offloadstr{$sparetype})) {
8349: $showoffload .= $offloadstr{$sparetype};
8350: } else {
8351: $showoffload .= &mt('None');
8352: }
8353: $showoffload .= (' 'x3);
8354: }
8355: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8356: }
8357: }
8358: }
1.171 raeburn 8359: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8360: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8361: foreach my $type (@{$alltypes}) {
8362: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8363: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8364: my $balancetext;
8365: if ($rule eq '') {
8366: $balancetext = $ruletitles{'default'};
8367: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8368: $balancetext = $ruletitles{$rule};
8369: } else {
8370: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8371: }
8372: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8373: }
8374: }
8375: }
8376: }
1.171 raeburn 8377: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8378: }
1.171 raeburn 8379: }
8380: if ($resulttext ne '') {
8381: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8382: } else {
8383: $resulttext = $nochgmsg;
8384: }
8385: } else {
1.171 raeburn 8386: $resulttext = $nochgmsg;
1.150 raeburn 8387: }
8388: } else {
1.171 raeburn 8389: $resulttext = '<span class="LC_error">'.
8390: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8391: }
8392: } else {
1.171 raeburn 8393: $resulttext = $nochgmsg;
1.150 raeburn 8394: }
8395: return $resulttext;
8396: }
8397:
1.48 raeburn 8398: sub recurse_check {
8399: my ($chkcats,$categories,$depth,$name) = @_;
8400: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8401: my $chg = 0;
8402: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8403: my $category = $chkcats->[$depth]{$name}[$j];
8404: my $item;
8405: if ($category eq '') {
8406: $chg ++;
8407: } else {
8408: my $deeper = $depth + 1;
8409: $item = &escape($category).':'.&escape($name).':'.$depth;
8410: if ($chg) {
8411: $categories->{$item} -= $chg;
8412: }
8413: &recurse_check($chkcats,$categories,$deeper,$category);
8414: $deeper --;
8415: }
8416: }
8417: }
8418: return;
8419: }
8420:
8421: sub recurse_cat_deletes {
8422: my ($item,$coursecategories,$deletions) = @_;
8423: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8424: my $subdepth = $depth + 1;
8425: if (ref($coursecategories) eq 'HASH') {
8426: foreach my $subitem (keys(%{$coursecategories})) {
8427: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8428: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8429: delete($coursecategories->{$subitem});
8430: $deletions->{$subitem} = 1;
8431: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8432: }
1.48 raeburn 8433: }
8434: }
8435: return;
8436: }
8437:
1.125 raeburn 8438: sub get_active_dcs {
8439: my ($dom) = @_;
8440: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8441: my %domcoords;
8442: my $numdcs = 0;
8443: my $now = time;
8444: foreach my $server (keys(%dompersonnel)) {
8445: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8446: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8447: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8448: if (($end eq '') || ($end == 0) || ($end > $now)) {
8449: if ($start <= $now) {
8450: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8451: }
8452: }
8453: }
8454: }
8455: return %domcoords;
8456: }
8457:
8458: sub active_dc_picker {
8459: my ($dom,$curr_dc) = @_;
8460: my %domcoords = &get_active_dcs($dom);
8461: my @dcs = sort(keys(%domcoords));
8462: my $numdcs = scalar(@dcs);
8463: my $datatable;
8464: my $numinrow = 2;
8465: if ($numdcs > 1) {
8466: $datatable = '<table>';
8467: for (my $i=0; $i<@dcs; $i++) {
8468: my $rem = $i%($numinrow);
8469: if ($rem == 0) {
8470: if ($i > 0) {
8471: $datatable .= '</tr>';
8472: }
8473: $datatable .= '<tr>';
8474: }
8475: my $check = ' ';
8476: if ($curr_dc eq '') {
8477: if (!$i) {
8478: $check = ' checked="checked" ';
8479: }
8480: } elsif ($dcs[$i] eq $curr_dc) {
8481: $check = ' checked="checked" ';
8482: }
8483: if ($i == @dcs - 1) {
8484: my $colsleft = $numinrow - $rem;
8485: if ($colsleft > 1) {
8486: $datatable .= '<td colspan="'.$colsleft.'">';
8487: } else {
8488: $datatable .= '<td>';
8489: }
8490: } else {
8491: $datatable .= '<td>';
8492: }
8493: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8494: $datatable .= '<span class="LC_nobreak"><label>'.
8495: '<input type="radio" name="autocreate_xmldc"'.
8496: ' value="'.$dcs[$i].'"'.$check.'/>'.
8497: &Apache::loncommon::plainname($dcname,$dcdom).
1.177 bisitz 8498: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8499: '</label></span></td>';
8500: }
8501: $datatable .= '</tr></table>';
8502: } elsif (@dcs) {
8503: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8504: $dcs[0].'" />';
8505: }
8506: return ($numdcs,$datatable);
8507: }
8508:
1.137 raeburn 8509: sub usersession_titles {
8510: return &Apache::lonlocal::texthash(
8511: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8512: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8513: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8514: version => 'LON-CAPA version requirement',
1.138 raeburn 8515: excludedomain => 'Allow all, but exclude specific domains',
8516: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8517: primary => 'Primary (checked first)',
1.154 raeburn 8518: default => 'Default',
1.137 raeburn 8519: );
8520: }
8521:
1.152 raeburn 8522: sub id_for_thisdom {
8523: my (%servers) = @_;
8524: my %altids;
8525: foreach my $server (keys(%servers)) {
8526: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8527: if ($serverhome ne $server) {
8528: $altids{$serverhome} = $server;
8529: }
8530: }
8531: return %altids;
8532: }
8533:
1.150 raeburn 8534: sub count_servers {
8535: my ($currbalancer,%servers) = @_;
8536: my (@spares,$numspares);
8537: foreach my $lonhost (sort(keys(%servers))) {
8538: next if ($currbalancer eq $lonhost);
8539: push(@spares,$lonhost);
8540: }
8541: if ($currbalancer) {
8542: $numspares = scalar(@spares);
8543: } else {
8544: $numspares = scalar(@spares) - 1;
8545: }
8546: return ($numspares,@spares);
8547: }
8548:
8549: sub lonbalance_targets_js {
1.171 raeburn 8550: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8551: my $select = &mt('Select');
8552: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8553: if (ref($servers) eq 'HASH') {
8554: $alltargets = join("','",sort(keys(%{$servers})));
8555: my @homedoms;
8556: foreach my $server (sort(keys(%{$servers}))) {
8557: if (&Apache::lonnet::host_domain($server) eq $dom) {
8558: push(@homedoms,'1');
8559: } else {
8560: push(@homedoms,'0');
8561: }
8562: }
8563: $allishome = join("','",@homedoms);
8564: }
8565: if (ref($types) eq 'ARRAY') {
8566: if (@{$types} > 0) {
8567: @alltypes = @{$types};
8568: }
8569: }
8570: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8571: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8572: my (%currbalancer,%currtargets,%currrules,%existing);
8573: if (ref($settings) eq 'HASH') {
8574: %existing = %{$settings};
8575: }
8576: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8577: \%currtargets,\%currrules);
8578: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8579: return <<"END";
8580:
8581: <script type="text/javascript">
8582: // <![CDATA[
8583:
1.171 raeburn 8584: currBalancers = new Array('$balancers');
8585:
8586: function toggleTargets(balnum) {
8587: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8588: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8589: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8590: var prevbalancer = prevhostitem.value;
8591: var baltotal = document.getElementById('loadbalancing_total').value;
8592: prevhostitem.value = balancer;
8593: if (prevbalancer != '') {
8594: var prevIdx = currBalancers.indexOf(prevbalancer);
8595: if (prevIdx != -1) {
8596: currBalancers.splice(prevIdx,1);
8597: }
8598: }
1.150 raeburn 8599: if (balancer == '') {
1.171 raeburn 8600: hideSpares(balnum);
1.150 raeburn 8601: } else {
1.171 raeburn 8602: var currIdx = currBalancers.indexOf(balancer);
8603: if (currIdx == -1) {
8604: currBalancers.push(balancer);
8605: }
1.150 raeburn 8606: var homedoms = new Array('$allishome');
1.171 raeburn 8607: var ishomedom = homedoms[lonhostitem.selectedIndex];
8608: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8609: }
1.171 raeburn 8610: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8611: return;
8612: }
8613:
1.171 raeburn 8614: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8615: var alltargets = new Array('$alltargets');
8616: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8617: var offloadtypes = new Array('primary','default');
8618:
1.171 raeburn 8619: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8620: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8621:
1.151 raeburn 8622: for (var i=0; i<offloadtypes.length; i++) {
8623: var count = 0;
8624: for (var j=0; j<alltargets.length; j++) {
8625: if (alltargets[j] != balancer) {
1.171 raeburn 8626: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8627: item.value = alltargets[j];
8628: item.style.textAlign='left';
8629: item.style.textFace='normal';
8630: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8631: if (currBalancers.indexOf(alltargets[j]) == -1) {
8632: item.disabled = '';
8633: } else {
8634: item.disabled = 'disabled';
8635: item.checked = false;
8636: }
1.151 raeburn 8637: count ++;
8638: }
1.150 raeburn 8639: }
8640: }
1.151 raeburn 8641: for (var k=0; k<insttypes.length; k++) {
8642: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8643: if (ishomedom == 1) {
1.171 raeburn 8644: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8645: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8646: } else {
1.171 raeburn 8647: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8648: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8649:
8650: }
8651: } else {
1.171 raeburn 8652: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8653: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8654: }
1.151 raeburn 8655: if ((insttypes[k] != '_LC_external') &&
8656: ((insttypes[k] != '_LC_internetdom') ||
8657: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8658: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8659: item.options.length = 0;
8660: item.options[0] = new Option("","",true,true);
8661: var idx = 0;
1.151 raeburn 8662: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8663: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8664: idx ++;
8665: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8666:
1.150 raeburn 8667: }
8668: }
8669: }
8670: }
8671: return;
8672: }
8673:
1.171 raeburn 8674: function hideSpares(balnum) {
1.150 raeburn 8675: var alltargets = new Array('$alltargets');
8676: var insttypes = new Array('$allinsttypes');
8677: var offloadtypes = new Array('primary','default');
8678:
1.171 raeburn 8679: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8680: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8681:
8682: var total = alltargets.length - 1;
8683: for (var i=0; i<offloadtypes; i++) {
8684: for (var j=0; j<total; j++) {
1.171 raeburn 8685: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8686: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8687: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8688: }
1.150 raeburn 8689: }
8690: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8691: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8692: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8693: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8694: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8695: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8696: }
8697: }
8698: return;
8699: }
8700:
1.171 raeburn 8701: function checkOffloads(item,balnum,type) {
1.150 raeburn 8702: var alltargets = new Array('$alltargets');
8703: var offloadtypes = new Array('primary','default');
8704: if (item.checked) {
8705: var total = alltargets.length - 1;
8706: var other;
8707: if (type == offloadtypes[0]) {
1.151 raeburn 8708: other = offloadtypes[1];
1.150 raeburn 8709: } else {
1.151 raeburn 8710: other = offloadtypes[0];
1.150 raeburn 8711: }
8712: for (var i=0; i<total; i++) {
1.171 raeburn 8713: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8714: if (server == item.value) {
1.171 raeburn 8715: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8716: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8717: }
8718: }
8719: }
8720: }
8721: return;
8722: }
8723:
1.171 raeburn 8724: function singleServerToggle(balnum,type) {
8725: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8726: if (offloadtoSelIdx == 0) {
1.171 raeburn 8727: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8728: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8729:
8730: } else {
1.171 raeburn 8731: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8732: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8733: }
8734: return;
8735: }
8736:
1.171 raeburn 8737: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8738: if (type == '_LC_external') {
1.171 raeburn 8739: return;
1.150 raeburn 8740: }
1.171 raeburn 8741: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8742: for (var i=0; i<typesRules.length; i++) {
8743: if (formname.elements[typesRules[i]].checked) {
8744: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8745: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8746: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8747: } else {
1.171 raeburn 8748: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8749: }
8750: }
8751: }
8752: return;
8753: }
8754:
8755: function balancerDeleteChange(balnum) {
8756: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8757: var baltotal = document.getElementById('loadbalancing_total').value;
8758: var addtarget;
8759: var removetarget;
8760: var action = 'delete';
8761: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8762: var lonhost = hostitem.value;
8763: var currIdx = currBalancers.indexOf(lonhost);
8764: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8765: if (currIdx != -1) {
8766: currBalancers.splice(currIdx,1);
8767: }
8768: addtarget = lonhost;
8769: } else {
8770: if (currIdx == -1) {
8771: currBalancers.push(lonhost);
8772: }
8773: removetarget = lonhost;
8774: action = 'undelete';
8775: }
8776: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8777: }
8778: return;
8779: }
8780:
8781: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8782: if (baltotal > 1) {
8783: var offloadtypes = new Array('primary','default');
8784: var alltargets = new Array('$alltargets');
8785: var insttypes = new Array('$allinsttypes');
8786: for (var i=0; i<baltotal; i++) {
8787: if (i != balnum) {
8788: for (var j=0; j<offloadtypes.length; j++) {
8789: var total = alltargets.length - 1;
8790: for (var k=0; k<total; k++) {
8791: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8792: var server = serveritem.value;
8793: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8794: if (server == addtarget) {
8795: serveritem.disabled = '';
8796: }
8797: }
8798: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8799: if (server == removetarget) {
8800: serveritem.disabled = 'disabled';
8801: serveritem.checked = false;
8802: }
8803: }
8804: }
8805: }
8806: for (var j=0; j<insttypes.length; j++) {
8807: if (insttypes[j] != '_LC_external') {
8808: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8809: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8810: var currSel = singleserver.selectedIndex;
8811: var currVal = singleserver.options[currSel].value;
8812: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8813: var numoptions = singleserver.options.length;
8814: var needsnew = 1;
8815: for (var k=0; k<numoptions; k++) {
8816: if (singleserver.options[k] == addtarget) {
8817: needsnew = 0;
8818: break;
8819: }
8820: }
8821: if (needsnew == 1) {
8822: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8823: }
8824: }
8825: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8826: singleserver.options.length = 0;
8827: if ((currVal) && (currVal != removetarget)) {
8828: singleserver.options[0] = new Option("","",false,false);
8829: } else {
8830: singleserver.options[0] = new Option("","",true,true);
8831: }
8832: var idx = 0;
8833: for (var m=0; m<alltargets.length; m++) {
8834: if (currBalancers.indexOf(alltargets[m]) == -1) {
8835: idx ++;
8836: if (currVal == alltargets[m]) {
8837: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8838: } else {
8839: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8840: }
8841: }
8842: }
8843: }
8844: }
8845: }
8846: }
1.150 raeburn 8847: }
8848: }
8849: }
8850: return;
8851: }
8852:
1.152 raeburn 8853: // ]]>
8854: </script>
8855:
8856: END
8857: }
8858:
8859: sub new_spares_js {
8860: my @sparestypes = ('primary','default');
8861: my $types = join("','",@sparestypes);
8862: my $select = &mt('Select');
8863: return <<"END";
8864:
8865: <script type="text/javascript">
8866: // <![CDATA[
8867:
8868: function updateNewSpares(formname,lonhost) {
8869: var types = new Array('$types');
8870: var include = new Array();
8871: var exclude = new Array();
8872: for (var i=0; i<types.length; i++) {
8873: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8874: for (var j=0; j<spareboxes.length; j++) {
8875: if (formname.elements[spareboxes[j]].checked) {
8876: exclude.push(formname.elements[spareboxes[j]].value);
8877: } else {
8878: include.push(formname.elements[spareboxes[j]].value);
8879: }
8880: }
8881: }
8882: for (var i=0; i<types.length; i++) {
8883: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8884: var selIdx = newSpare.selectedIndex;
8885: var currnew = newSpare.options[selIdx].value;
8886: var okSpares = new Array();
8887: for (var j=0; j<newSpare.options.length; j++) {
8888: var possible = newSpare.options[j].value;
8889: if (possible != '') {
8890: if (exclude.indexOf(possible) == -1) {
8891: okSpares.push(possible);
8892: } else {
8893: if (currnew == possible) {
8894: selIdx = 0;
8895: }
8896: }
8897: }
8898: }
8899: for (var k=0; k<include.length; k++) {
8900: if (okSpares.indexOf(include[k]) == -1) {
8901: okSpares.push(include[k]);
8902: }
8903: }
8904: okSpares.sort();
8905: newSpare.options.length = 0;
8906: if (selIdx == 0) {
8907: newSpare.options[0] = new Option("$select","",true,true);
8908: } else {
8909: newSpare.options[0] = new Option("$select","",false,false);
8910: }
8911: for (var m=0; m<okSpares.length; m++) {
8912: var idx = m+1;
8913: var selThis = 0;
8914: if (selIdx != 0) {
8915: if (okSpares[m] == currnew) {
8916: selThis = 1;
8917: }
8918: }
8919: if (selThis == 1) {
8920: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8921: } else {
8922: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8923: }
8924: }
8925: }
8926: return;
8927: }
8928:
8929: function checkNewSpares(lonhost,type) {
8930: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8931: var chosen = newSpare.options[newSpare.selectedIndex].value;
8932: if (chosen != '') {
8933: var othertype;
8934: var othernewSpare;
8935: if (type == 'primary') {
8936: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8937: }
8938: if (type == 'default') {
8939: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8940: }
8941: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8942: othernewSpare.selectedIndex = 0;
8943: }
8944: }
8945: return;
8946: }
8947:
8948: // ]]>
8949: </script>
8950:
8951: END
8952:
8953: }
8954:
8955: sub common_domprefs_js {
8956: return <<"END";
8957:
8958: <script type="text/javascript">
8959: // <![CDATA[
8960:
1.150 raeburn 8961: function getIndicesByName(formname,item) {
1.152 raeburn 8962: var group = new Array();
1.150 raeburn 8963: for (var i=0;i<formname.elements.length;i++) {
8964: if (formname.elements[i].name == item) {
1.152 raeburn 8965: group.push(formname.elements[i].id);
1.150 raeburn 8966: }
8967: }
1.152 raeburn 8968: return group;
1.150 raeburn 8969: }
8970:
8971: // ]]>
8972: </script>
8973:
8974: END
1.152 raeburn 8975:
1.150 raeburn 8976: }
8977:
1.165 raeburn 8978: sub recaptcha_js {
8979: my %lt = &captcha_phrases();
8980: return <<"END";
8981:
8982: <script type="text/javascript">
8983: // <![CDATA[
8984:
8985: function updateCaptcha(caller,context) {
8986: var privitem;
8987: var pubitem;
8988: var privtext;
8989: var pubtext;
8990: if (document.getElementById(context+'_recaptchapub')) {
8991: pubitem = document.getElementById(context+'_recaptchapub');
8992: } else {
8993: return;
8994: }
8995: if (document.getElementById(context+'_recaptchapriv')) {
8996: privitem = document.getElementById(context+'_recaptchapriv');
8997: } else {
8998: return;
8999: }
9000: if (document.getElementById(context+'_recaptchapubtxt')) {
9001: pubtext = document.getElementById(context+'_recaptchapubtxt');
9002: } else {
9003: return;
9004: }
9005: if (document.getElementById(context+'_recaptchaprivtxt')) {
9006: privtext = document.getElementById(context+'_recaptchaprivtxt');
9007: } else {
9008: return;
9009: }
9010: if (caller.checked) {
9011: if (caller.value == 'recaptcha') {
9012: pubitem.type = 'text';
9013: privitem.type = 'text';
9014: pubitem.size = '40';
9015: privitem.size = '40';
9016: pubtext.innerHTML = "$lt{'pub'}";
9017: privtext.innerHTML = "$lt{'priv'}";
9018: } else {
9019: pubitem.type = 'hidden';
9020: privitem.type = 'hidden';
9021: pubtext.innerHTML = '';
9022: privtext.innerHTML = '';
9023: }
9024: }
9025: return;
9026: }
9027:
9028: // ]]>
9029: </script>
9030:
9031: END
9032:
9033: }
9034:
9035: sub captcha_phrases {
9036: return &Apache::lonlocal::texthash (
9037: priv => 'Private key',
9038: pub => 'Public key',
9039: original => 'original (CAPTCHA)',
9040: recaptcha => 'successor (ReCAPTCHA)',
9041: notused => 'unused',
9042: );
9043: }
9044:
1.3 raeburn 9045: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>