Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.14
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.14! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.13 2013/01/09 21:37:04 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.160.6.13 raeburn 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.160.6.5 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',
1.160.6.1 raeburn 213: 'serverstatuses','requestcourses','usersessions',
1.160.6.5 raeburn 214: 'loadbalancing','requestauthor'],$dom);
1.43 raeburn 215: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 216: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 217: 'usercreation','usermodification','scantron',
1.160.6.5 raeburn 218: 'requestcourses','requestauthor','coursecategories',
219: 'serverstatuses','usersessions');
1.160.6.7 raeburn 220: my %existing;
221: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
222: %existing = %{$domconfig{'loadbalancing'}};
223: }
224: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 225: push(@prefs_order,'loadbalancing');
226: }
1.30 raeburn 227: my %prefs = (
228: 'rolecolors' =>
229: { text => 'Default color schemes',
1.67 raeburn 230: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 231: header => [{col1 => 'Student Settings',
232: col2 => '',},
233: {col1 => 'Coordinator Settings',
234: col2 => '',},
235: {col1 => 'Author Settings',
236: col2 => '',},
237: {col1 => 'Administrator Settings',
238: col2 => '',}],
239: },
1.110 raeburn 240: 'login' =>
1.30 raeburn 241: { text => 'Log-in page options',
1.67 raeburn 242: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 243: header => [{col1 => 'Log-in Page Items',
244: col2 => '',},
245: {col1 => 'Log-in Help',
246: col2 => 'Value'}],
1.30 raeburn 247: },
1.43 raeburn 248: 'defaults' =>
1.141 raeburn 249: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 250: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 251: header => [{col1 => 'Setting',
252: col2 => 'Value'}],
253: },
1.30 raeburn 254: 'quotas' =>
1.160.6.4 raeburn 255: { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67 raeburn 256: help => 'Domain_Configuration_Quotas',
1.77 raeburn 257: header => [{col1 => 'User affiliation',
1.72 raeburn 258: col2 => 'Available tools',
259: col3 => 'Portfolio quota',}],
1.30 raeburn 260: },
261: 'autoenroll' =>
262: { text => 'Auto-enrollment settings',
1.67 raeburn 263: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 264: header => [{col1 => 'Configuration setting',
265: col2 => 'Value(s)'}],
266: },
267: 'autoupdate' =>
268: { text => 'Auto-update settings',
1.67 raeburn 269: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 270: header => [{col1 => 'Setting',
271: col2 => 'Value',},
1.131 raeburn 272: {col1 => 'Setting',
273: col2 => 'Affiliation'},
1.43 raeburn 274: {col1 => 'User population',
1.131 raeburn 275: col2 => 'Updateable user data'}],
1.30 raeburn 276: },
1.125 raeburn 277: 'autocreate' =>
278: { text => 'Auto-course creation settings',
279: help => 'Domain_Configuration_Auto_Creation',
280: header => [{col1 => 'Configuration Setting',
281: col2 => 'Value',}],
282: },
1.30 raeburn 283: 'directorysrch' =>
284: { text => 'Institutional directory searches',
1.67 raeburn 285: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 286: header => [{col1 => 'Setting',
287: col2 => 'Value',}],
288: },
289: 'contacts' =>
290: { text => 'Contact Information',
1.67 raeburn 291: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',}],
294: },
295:
296: 'usercreation' =>
297: { text => 'User creation',
1.67 raeburn 298: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 299: header => [{col1 => 'Format rule type',
300: col2 => 'Format rules in force'},
1.34 raeburn 301: {col1 => 'User account creation',
302: col2 => 'Usernames which may be created',},
1.30 raeburn 303: {col1 => 'Context',
1.43 raeburn 304: col2 => 'Assignable authentication types'}],
1.30 raeburn 305: },
1.69 raeburn 306: 'usermodification' =>
1.33 raeburn 307: { text => 'User modification',
1.67 raeburn 308: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 309: header => [{col1 => 'Target user has role',
310: col2 => 'User information updateable in author context'},
311: {col1 => 'Target user has role',
1.63 raeburn 312: col2 => 'User information updateable in course context'},
313: {col1 => "Status of user",
314: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 315: },
1.69 raeburn 316: 'scantron' =>
1.95 www 317: { text => 'Bubblesheet format file',
1.67 raeburn 318: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 319: header => [ {col1 => 'Item',
320: col2 => '',
321: }],
322: },
1.86 raeburn 323: 'requestcourses' =>
324: {text => 'Request creation of courses',
325: help => 'Domain_Configuration_Request_Courses',
326: header => [{col1 => 'User affiliation',
1.102 raeburn 327: col2 => 'Availability/Processing of requests',},
328: {col1 => 'Setting',
329: col2 => 'Value'}],
1.86 raeburn 330: },
1.160.6.5 raeburn 331: 'requestauthor' =>
332: {text => 'Request authoring space',
333: help => 'Domain_Configuration_Request_Author',
334: header => [{col1 => 'User affiliation',
335: col2 => 'Availability/Processing of requests',},
336: {col1 => 'Setting',
337: col2 => 'Value'}],
338: },
1.69 raeburn 339: 'coursecategories' =>
1.120 raeburn 340: { text => 'Cataloging of courses/communities',
1.67 raeburn 341: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 342: header => [{col1 => 'Category settings',
1.57 raeburn 343: col2 => '',},
344: {col1 => 'Categories',
345: col2 => '',
346: }],
1.69 raeburn 347: },
348: 'serverstatuses' =>
1.77 raeburn 349: {text => 'Access to server status pages',
1.69 raeburn 350: help => 'Domain_Configuration_Server_Status',
351: header => [{col1 => 'Status Page',
352: col2 => 'Other named users',
353: col3 => 'Specific IPs',
354: }],
355: },
1.141 raeburn 356: 'usersessions' =>
1.145 raeburn 357: {text => 'User session hosting/offloading',
1.137 raeburn 358: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 359: header => [{col1 => 'Domain server',
360: col2 => 'Servers to offload sessions to when busy'},
361: {col1 => 'Hosting of users from other domains',
1.137 raeburn 362: col2 => 'Rules'},
363: {col1 => "Hosting domain's own users elsewhere",
364: col2 => 'Rules'}],
365: },
1.150 raeburn 366: 'loadbalancing' =>
1.160.6.7 raeburn 367: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 368: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 369: header => [{col1 => 'Balancers',
1.150 raeburn 370: col2 => 'Default destinations',
1.160.6.13 raeburn 371: col3 => 'User affiliation',
1.150 raeburn 372: col4 => 'Overrides'},
373: ],
374: },
1.3 raeburn 375: );
1.110 raeburn 376: if (keys(%servers) > 1) {
377: $prefs{'login'} = { text => 'Log-in page options',
378: help => 'Domain_Configuration_Login_Page',
379: header => [{col1 => 'Log-in Service',
380: col2 => 'Server Setting',},
381: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 382: col2 => ''},
383: {col1 => 'Log-in Help',
384: col2 => 'Value'}],
1.110 raeburn 385: };
386: }
1.160.6.13 raeburn 387:
1.6 raeburn 388: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 389: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 390: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 391: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 392: text=>"Settings to display/modify"});
1.9 raeburn 393: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 394:
1.3 raeburn 395: if ($phase eq 'process') {
1.91 raeburn 396: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 397: } elsif ($phase eq 'display') {
1.160.6.5 raeburn 398: my $js = &recaptcha_js();
1.160.6.7 raeburn 399: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 400: my ($othertitle,$usertypes,$types) =
401: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 402: $js .= &lonbalance_targets_js($dom,$types,\%servers,
403: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 404: &new_spares_js().
405: &common_domprefs_js().
406: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 407: }
1.150 raeburn 408: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 409: } else {
1.160.6.11 raeburn 410: # check if domconfig user exists for the domain.
411: my $servadm = $r->dir_config('lonAdmEMail');
412: my ($configuserok,$author_ok,$switchserver) =
413: &config_check($dom,$confname,$servadm);
414: unless ($configuserok eq 'ok') {
415: &Apache::lonconfigsettings::print_header($r,$phase,$context);
416: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
417: $confname).
418: '<br />'
419: );
420: if ($switchserver) {
421: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
422: '<br />'.
423: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
424: '<br />'.
425: &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).
426: '<br />'.
427: &mt('To do that now, use the following link: [_1]',$switchserver)
428: );
429: } else {
430: $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.').
431: '<br />'.
432: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
433: );
434: }
435: $r->print(&Apache::loncommon::end_page());
436: return OK;
437: }
1.21 raeburn 438: if (keys(%domconfig) == 0) {
439: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 440: my @ids=&Apache::lonnet::current_machine_ids();
441: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 442: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 443: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 444: my $custom_img_count = 0;
445: foreach my $img (@loginimages) {
446: if ($designhash{$dom.'.login.'.$img} ne '') {
447: $custom_img_count ++;
448: }
449: }
450: foreach my $role (@roles) {
451: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
452: $custom_img_count ++;
453: }
454: }
455: if ($custom_img_count > 0) {
1.94 raeburn 456: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 457: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 458: $r->print(
459: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
460: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
461: &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 />'.
462: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
463: if ($switch_server) {
1.30 raeburn 464: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 465: }
1.91 raeburn 466: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 467: return OK;
468: }
469: }
470: }
1.91 raeburn 471: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 472: }
473: return OK;
474: }
475:
476: sub process_changes {
1.92 raeburn 477: my ($r,$dom,$confname,$action,$roles,$values) = @_;
478: my %domconfig;
479: if (ref($values) eq 'HASH') {
480: %domconfig = %{$values};
481: }
1.3 raeburn 482: my $output;
483: if ($action eq 'login') {
1.9 raeburn 484: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 485: } elsif ($action eq 'rolecolors') {
1.9 raeburn 486: $output = &modify_rolecolors($r,$dom,$confname,$roles,
487: %domconfig);
1.3 raeburn 488: } elsif ($action eq 'quotas') {
1.86 raeburn 489: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 490: } elsif ($action eq 'autoenroll') {
491: $output = &modify_autoenroll($dom,%domconfig);
492: } elsif ($action eq 'autoupdate') {
493: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 494: } elsif ($action eq 'autocreate') {
495: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 496: } elsif ($action eq 'directorysrch') {
497: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 498: } elsif ($action eq 'usercreation') {
1.28 raeburn 499: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 500: } elsif ($action eq 'usermodification') {
501: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 502: } elsif ($action eq 'contacts') {
503: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 504: } elsif ($action eq 'defaults') {
505: $output = &modify_defaults($dom,$r);
1.46 raeburn 506: } elsif ($action eq 'scantron') {
1.48 raeburn 507: $output = &modify_scantron($r,$dom,$confname,%domconfig);
508: } elsif ($action eq 'coursecategories') {
509: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 510: } elsif ($action eq 'serverstatuses') {
511: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 512: } elsif ($action eq 'requestcourses') {
513: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.5 raeburn 514: } elsif ($action eq 'requestauthor') {
515: $output = &modify_quotas($dom,$action,%domconfig);
1.137 raeburn 516: } elsif ($action eq 'usersessions') {
517: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 518: } elsif ($action eq 'loadbalancing') {
519: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 520: }
521: return $output;
522: }
523:
524: sub print_config_box {
1.9 raeburn 525: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 526: my $rowtotal = 0;
1.49 raeburn 527: my $output;
528: if ($action eq 'coursecategories') {
529: $output = &coursecategories_javascript($settings);
1.91 raeburn 530: }
1.49 raeburn 531: $output .=
1.30 raeburn 532: '<table class="LC_nested_outer">
1.3 raeburn 533: <tr>
1.66 raeburn 534: <th align="left" valign="middle"><span class="LC_nobreak">'.
535: &mt($item->{text}).' '.
536: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
537: '</tr>';
1.30 raeburn 538: $rowtotal ++;
1.110 raeburn 539: my $numheaders = 1;
540: if (ref($item->{'header'}) eq 'ARRAY') {
541: $numheaders = scalar(@{$item->{'header'}});
542: }
543: if ($numheaders > 1) {
1.64 raeburn 544: my $colspan = '';
1.145 raeburn 545: my $rightcolspan = '';
1.160.6.5 raeburn 546: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
547: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 548: $colspan = ' colspan="2"';
549: }
1.145 raeburn 550: if ($action eq 'usersessions') {
551: $rightcolspan = ' colspan="3"';
552: }
1.30 raeburn 553: $output .= '
1.3 raeburn 554: <tr>
555: <td>
556: <table class="LC_nested">
557: <tr class="LC_info_row">
1.59 bisitz 558: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 559: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 560: </tr>';
1.69 raeburn 561: $rowtotal ++;
1.6 raeburn 562: if ($action eq 'autoupdate') {
1.30 raeburn 563: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 564: } elsif ($action eq 'usercreation') {
1.33 raeburn 565: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
566: } elsif ($action eq 'usermodification') {
567: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 568: } elsif ($action eq 'coursecategories') {
569: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 570: } elsif ($action eq 'login') {
1.160.6.5 raeburn 571: if ($numheaders == 3) {
572: $colspan = ' colspan="2"';
573: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
574: } else {
575: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
576: }
1.102 raeburn 577: } elsif ($action eq 'requestcourses') {
578: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 579: } elsif ($action eq 'requestauthor') {
580: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 581: } elsif ($action eq 'usersessions') {
582: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 583: } elsif ($action eq 'rolecolors') {
1.30 raeburn 584: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 585: }
1.30 raeburn 586: $output .= '
1.6 raeburn 587: </table>
588: </td>
589: </tr>
590: <tr>
591: <td>
592: <table class="LC_nested">
593: <tr class="LC_info_row">
1.59 bisitz 594: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 595: $output .= '
1.59 bisitz 596: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 597: </tr>';
598: $rowtotal ++;
1.6 raeburn 599: if ($action eq 'autoupdate') {
1.131 raeburn 600: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
601: </table>
602: </td>
603: </tr>
604: <tr>
605: <td>
606: <table class="LC_nested">
607: <tr class="LC_info_row">
608: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
609: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
610: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
611: $rowtotal ++;
1.28 raeburn 612: } elsif ($action eq 'usercreation') {
1.34 raeburn 613: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
614: </table>
615: </td>
616: </tr>
617: <tr>
618: <td>
619: <table class="LC_nested">
620: <tr class="LC_info_row">
1.59 bisitz 621: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
622: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 623: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
624: $rowtotal ++;
1.33 raeburn 625: } elsif ($action eq 'usermodification') {
1.63 raeburn 626: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
627: </table>
628: </td>
629: </tr>
630: <tr>
631: <td>
632: <table class="LC_nested">
633: <tr class="LC_info_row">
634: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
635: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
636: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
637: $rowtotal ++;
1.57 raeburn 638: } elsif ($action eq 'coursecategories') {
639: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 640: } elsif ($action eq 'login') {
1.160.6.5 raeburn 641: if ($numheaders == 3) {
642: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
643: </table>
644: </td>
645: </tr>
646: <tr>
647: <td>
648: <table class="LC_nested">
649: <tr class="LC_info_row">
650: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
651: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
652: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
653: $rowtotal ++;
654: } else {
655: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
656: }
1.102 raeburn 657: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 658: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
659: } elsif ($action eq 'requestauthor') {
660: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 661: } elsif ($action eq 'usersessions') {
1.145 raeburn 662: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
663: </table>
664: </td>
665: </tr>
666: <tr>
667: <td>
668: <table class="LC_nested">
669: <tr class="LC_info_row">
670: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
671: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
672: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
673: $rowtotal ++;
1.139 raeburn 674: } elsif ($action eq 'coursedefaults') {
675: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 676: } elsif ($action eq 'rolecolors') {
1.30 raeburn 677: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 678: </table>
679: </td>
680: </tr>
681: <tr>
682: <td>
683: <table class="LC_nested">
684: <tr class="LC_info_row">
1.69 raeburn 685: <td class="LC_left_item"'.$colspan.' valign="top">'.
686: &mt($item->{'header'}->[2]->{'col1'}).'</td>
687: <td class="LC_right_item" valign="top">'.
688: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 689: </tr>'.
1.30 raeburn 690: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 691: </table>
692: </td>
693: </tr>
694: <tr>
695: <td>
696: <table class="LC_nested">
697: <tr class="LC_info_row">
1.59 bisitz 698: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
699: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 700: </tr>'.
1.30 raeburn 701: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
702: $rowtotal += 2;
1.6 raeburn 703: }
1.3 raeburn 704: } else {
1.30 raeburn 705: $output .= '
1.3 raeburn 706: <tr>
707: <td>
708: <table class="LC_nested">
1.30 raeburn 709: <tr class="LC_info_row">';
1.24 raeburn 710: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 711: $output .= '
1.59 bisitz 712: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 713: } elsif ($action eq 'serverstatuses') {
714: $output .= '
715: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
716: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
717:
1.6 raeburn 718: } else {
1.30 raeburn 719: $output .= '
1.69 raeburn 720: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
721: }
1.72 raeburn 722: if (defined($item->{'header'}->[0]->{'col3'})) {
723: $output .= '<td class="LC_left_item" valign="top">'.
724: &mt($item->{'header'}->[0]->{'col2'});
725: if ($action eq 'serverstatuses') {
726: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
727: }
1.69 raeburn 728: } else {
729: $output .= '<td class="LC_right_item" valign="top">'.
730: &mt($item->{'header'}->[0]->{'col2'});
731: }
732: $output .= '</td>';
733: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 734: if (defined($item->{'header'}->[0]->{'col4'})) {
735: $output .= '<td class="LC_left_item" valign="top">'.
736: &mt($item->{'header'}->[0]->{'col3'});
737: } else {
738: $output .= '<td class="LC_right_item" valign="top">'.
739: &mt($item->{'header'}->[0]->{'col3'});
740: }
1.69 raeburn 741: if ($action eq 'serverstatuses') {
742: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
743: }
744: $output .= '</td>';
1.6 raeburn 745: }
1.150 raeburn 746: if ($item->{'header'}->[0]->{'col4'}) {
747: $output .= '<td class="LC_right_item" valign="top">'.
748: &mt($item->{'header'}->[0]->{'col4'});
749: }
1.69 raeburn 750: $output .= '</tr>';
1.48 raeburn 751: $rowtotal ++;
1.160.6.5 raeburn 752: if ($action eq 'quotas') {
1.86 raeburn 753: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 754: } elsif ($action eq 'autoenroll') {
1.30 raeburn 755: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 756: } elsif ($action eq 'autocreate') {
757: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 758: } elsif ($action eq 'directorysrch') {
1.30 raeburn 759: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 760: } elsif ($action eq 'contacts') {
1.30 raeburn 761: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 762: } elsif ($action eq 'defaults') {
763: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 764: } elsif ($action eq 'scantron') {
765: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 766: } elsif ($action eq 'serverstatuses') {
767: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 768: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 769: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 770: } elsif ($action eq 'loadbalancing') {
771: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 772: }
1.3 raeburn 773: }
1.30 raeburn 774: $output .= '
1.3 raeburn 775: </table>
776: </td>
777: </tr>
1.30 raeburn 778: </table><br />';
779: return ($output,$rowtotal);
1.1 raeburn 780: }
781:
1.3 raeburn 782: sub print_login {
1.160.6.5 raeburn 783: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 784: my ($css_class,$datatable);
1.6 raeburn 785: my %choices = &login_choices();
1.110 raeburn 786:
1.160.6.5 raeburn 787: if ($caller eq 'service') {
1.149 raeburn 788: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 789: my $choice = $choices{'disallowlogin'};
790: $css_class = ' class="LC_odd_row"';
1.128 raeburn 791: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 792: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 793: '<th>'.$choices{'server'}.'</th>'.
794: '<th>'.$choices{'serverpath'}.'</th>'.
795: '<th>'.$choices{'custompath'}.'</th>'.
796: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 797: my %disallowed;
798: if (ref($settings) eq 'HASH') {
799: if (ref($settings->{'loginvia'}) eq 'HASH') {
800: %disallowed = %{$settings->{'loginvia'}};
801: }
802: }
803: foreach my $lonhost (sort(keys(%servers))) {
804: my $direct = 'selected="selected"';
1.128 raeburn 805: if (ref($disallowed{$lonhost}) eq 'HASH') {
806: if ($disallowed{$lonhost}{'server'} ne '') {
807: $direct = '';
808: }
1.110 raeburn 809: }
1.115 raeburn 810: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 811: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 812: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
813: '</option>';
1.160.6.13 raeburn 814: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 815: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 816: my $selected = '';
1.128 raeburn 817: if (ref($disallowed{$lonhost}) eq 'HASH') {
818: if ($hostid eq $disallowed{$lonhost}{'server'}) {
819: $selected = 'selected="selected"';
820: }
1.110 raeburn 821: }
822: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
823: $servers{$hostid}.'</option>';
824: }
1.128 raeburn 825: $datatable .= '</select></td>'.
826: '<td><select name="'.$lonhost.'_serverpath">';
827: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
828: my $pathname = $path;
829: if ($path eq 'custom') {
830: $pathname = &mt('Custom Path').' ->';
831: }
832: my $selected = '';
833: if (ref($disallowed{$lonhost}) eq 'HASH') {
834: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
835: $selected = 'selected="selected"';
836: }
837: } elsif ($path eq '') {
838: $selected = 'selected="selected"';
839: }
840: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
841: }
842: $datatable .= '</select></td>';
843: my ($custom,$exempt);
844: if (ref($disallowed{$lonhost}) eq 'HASH') {
845: $custom = $disallowed{$lonhost}{'custompath'};
846: $exempt = $disallowed{$lonhost}{'exempt'};
847: }
848: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
849: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
850: '</tr>';
1.110 raeburn 851: }
852: $datatable .= '</table></td></tr>';
853: return $datatable;
1.160.6.5 raeburn 854: } elsif ($caller eq 'page') {
855: my %defaultchecked = (
856: 'coursecatalog' => 'on',
1.160.6.14! raeburn 857: 'helpdesk' => 'on',
1.160.6.5 raeburn 858: 'adminmail' => 'off',
859: 'newuser' => 'off',
860: );
1.160.6.14! raeburn 861: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 862: my (%checkedon,%checkedoff);
1.42 raeburn 863: foreach my $item (@toggles) {
1.160.6.5 raeburn 864: if ($defaultchecked{$item} eq 'on') {
865: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 866: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 867: } elsif ($defaultchecked{$item} eq 'off') {
868: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 869: $checkedon{$item} = ' ';
870: }
1.1 raeburn 871: }
1.160.6.5 raeburn 872: my @images = ('img','logo','domlogo','login');
873: my @logintext = ('textcol','bgcol');
874: my @bgs = ('pgbg','mainbg','sidebg');
875: my @links = ('link','alink','vlink');
876: my %designhash = &Apache::loncommon::get_domainconf($dom);
877: my %defaultdesign = %Apache::loncommon::defaultdesign;
878: my (%is_custom,%designs);
879: my %defaults = (
880: font => $defaultdesign{'login.font'},
881: );
1.6 raeburn 882: foreach my $item (@images) {
1.160.6.5 raeburn 883: $defaults{$item} = $defaultdesign{'login.'.$item};
884: $defaults{'showlogo'}{$item} = 1;
885: }
886: foreach my $item (@bgs) {
887: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 888: }
1.41 raeburn 889: foreach my $item (@logintext) {
1.160.6.5 raeburn 890: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 891: }
1.160.6.5 raeburn 892: foreach my $item (@links) {
893: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 894: }
1.160.6.5 raeburn 895: if (ref($settings) eq 'HASH') {
896: foreach my $item (@toggles) {
897: if ($settings->{$item} eq '1') {
898: $checkedon{$item} = ' checked="checked" ';
899: $checkedoff{$item} = ' ';
900: } elsif ($settings->{$item} eq '0') {
901: $checkedoff{$item} = ' checked="checked" ';
902: $checkedon{$item} = ' ';
903: }
1.6 raeburn 904: }
1.160.6.5 raeburn 905: foreach my $item (@images) {
906: if (defined($settings->{$item})) {
907: $designs{$item} = $settings->{$item};
908: $is_custom{$item} = 1;
909: }
910: if (defined($settings->{'showlogo'}{$item})) {
911: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
912: }
913: }
914: foreach my $item (@logintext) {
915: if ($settings->{$item} ne '') {
916: $designs{'logintext'}{$item} = $settings->{$item};
917: $is_custom{$item} = 1;
918: }
919: }
920: if ($settings->{'font'} ne '') {
921: $designs{'font'} = $settings->{'font'};
922: $is_custom{'font'} = 1;
923: }
924: foreach my $item (@bgs) {
925: if ($settings->{$item} ne '') {
926: $designs{'bgs'}{$item} = $settings->{$item};
927: $is_custom{$item} = 1;
928: }
929: }
930: foreach my $item (@links) {
931: if ($settings->{$item} ne '') {
932: $designs{'links'}{$item} = $settings->{$item};
933: $is_custom{$item} = 1;
934: }
935: }
936: } else {
937: if ($designhash{$dom.'.login.font'} ne '') {
938: $designs{'font'} = $designhash{$dom.'.login.font'};
939: $is_custom{'font'} = 1;
940: }
941: foreach my $item (@images) {
942: if ($designhash{$dom.'.login.'.$item} ne '') {
943: $designs{$item} = $designhash{$dom.'.login.'.$item};
944: $is_custom{$item} = 1;
945: }
946: }
947: foreach my $item (@bgs) {
948: if ($designhash{$dom.'.login.'.$item} ne '') {
949: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
950: $is_custom{$item} = 1;
951: }
952: }
953: foreach my $item (@links) {
954: if ($designhash{$dom.'.login.'.$item} ne '') {
955: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
956: $is_custom{$item} = 1;
957: }
1.6 raeburn 958: }
959: }
1.160.6.5 raeburn 960: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
961: logo => 'Institution Logo',
962: domlogo => 'Domain Logo',
963: login => 'Login box');
964: my $itemcount = 1;
965: foreach my $item (@toggles) {
966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
967: $datatable .=
968: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
969: '</td><td>'.
970: '<span class="LC_nobreak"><label><input type="radio" name="'.
971: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
972: '</label> <label><input type="radio" name="'.$item.'"'.
973: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
974: '</tr>';
975: $itemcount ++;
1.6 raeburn 976: }
1.160.6.5 raeburn 977: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
978: $datatable .= '</tr></table></td></tr>';
979: } elsif ($caller eq 'help') {
980: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
981: my $switchserver = &check_switchserver($dom,$confname);
982: my $itemcount = 1;
983: $defaulturl = '/adm/loginproblems.html';
984: $defaulttype = 'default';
985: %lt = &Apache::lonlocal::texthash (
986: del => 'Delete?',
987: rep => 'Replace:',
988: upl => 'Upload:',
989: default => 'Default',
990: custom => 'Custom',
991: );
992: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
993: my @currlangs;
994: if (ref($settings) eq 'HASH') {
995: if (ref($settings->{'helpurl'}) eq 'HASH') {
996: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
997: next if ($settings->{'helpurl'}{$key} eq '');
998: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
999: $type{$key} = 'custom';
1000: unless ($key eq 'nolang') {
1001: push(@currlangs,$key);
1002: }
1003: }
1004: } elsif ($settings->{'helpurl'} ne '') {
1005: $type{'nolang'} = 'custom';
1006: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1007: }
1008: }
1.160.6.5 raeburn 1009: foreach my $lang ('nolang',sort(@currlangs)) {
1010: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1011: $datatable .= '<tr'.$css_class.'>';
1012: if ($url{$lang} eq '') {
1013: $url{$lang} = $defaulturl;
1014: }
1015: if ($type{$lang} eq '') {
1016: $type{$lang} = $defaulttype;
1017: }
1018: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1019: if ($lang eq 'nolang') {
1020: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1021: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1022: } else {
1023: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1024: $langchoices{$lang},
1025: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1026: }
1027: $datatable .= '</span></td>'."\n".
1028: '<td class="LC_left_item">';
1029: if ($type{$lang} eq 'custom') {
1030: $datatable .= '<span class="LC_nobreak"><label>'.
1031: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1032: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1033: } else {
1034: $datatable .= $lt{'upl'};
1035: }
1036: $datatable .='<br />';
1037: if ($switchserver) {
1038: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1039: } else {
1040: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1041: }
1.160.6.5 raeburn 1042: $datatable .= '</td></tr>';
1043: $itemcount ++;
1.6 raeburn 1044: }
1.160.6.5 raeburn 1045: my @addlangs;
1046: foreach my $lang (sort(keys(%langchoices))) {
1047: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1048: push(@addlangs,$lang);
1049: }
1050: if (@addlangs > 0) {
1051: my %toadd;
1052: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1053: $toadd{''} = &mt('Select');
1054: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1055: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1056: &mt('Add log-in help page for a specific language:').' '.
1057: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1058: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1059: if ($switchserver) {
1060: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1061: } else {
1062: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1063: }
1.160.6.5 raeburn 1064: $datatable .= '</td></tr>';
1065: $itemcount ++;
1.6 raeburn 1066: }
1.160.6.5 raeburn 1067: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1068: }
1.6 raeburn 1069: return $datatable;
1070: }
1071:
1072: sub login_choices {
1073: my %choices =
1074: &Apache::lonlocal::texthash (
1.116 bisitz 1075: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1076: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14! raeburn 1077: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1078: disallowlogin => "Login page requests redirected",
1079: hostid => "Server",
1.128 raeburn 1080: server => "Redirect to:",
1081: serverpath => "Path",
1082: custompath => "Custom",
1083: exempt => "Exempt IP(s)",
1.110 raeburn 1084: directlogin => "No redirect",
1085: newuser => "Link to create a user account",
1086: img => "Header",
1087: logo => "Main Logo",
1088: domlogo => "Domain Logo",
1089: login => "Log-in Header",
1090: textcol => "Text color",
1091: bgcol => "Box color",
1092: bgs => "Background colors",
1093: links => "Link colors",
1094: font => "Font color",
1095: pgbg => "Header",
1096: mainbg => "Page",
1097: sidebg => "Login box",
1098: link => "Link",
1099: alink => "Active link",
1100: vlink => "Visited link",
1.6 raeburn 1101: );
1102: return %choices;
1103: }
1104:
1105: sub print_rolecolors {
1.30 raeburn 1106: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1107: my %choices = &color_font_choices();
1108: my @bgs = ('pgbg','tabbg','sidebg');
1109: my @links = ('link','alink','vlink');
1110: my @images = ('img');
1111: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1112: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1113: my %defaultdesign = %Apache::loncommon::defaultdesign;
1114: my (%is_custom,%designs);
1115: my %defaults = (
1116: img => $defaultdesign{$role.'.img'},
1117: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1118: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1119: );
1120: foreach my $item (@bgs) {
1121: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1122: }
1123: foreach my $item (@links) {
1124: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1125: }
1126: if (ref($settings) eq 'HASH') {
1127: if (ref($settings->{$role}) eq 'HASH') {
1128: if ($settings->{$role}->{'img'} ne '') {
1129: $designs{'img'} = $settings->{$role}->{'img'};
1130: $is_custom{'img'} = 1;
1131: }
1132: if ($settings->{$role}->{'font'} ne '') {
1133: $designs{'font'} = $settings->{$role}->{'font'};
1134: $is_custom{'font'} = 1;
1135: }
1.97 tempelho 1136: if ($settings->{$role}->{'fontmenu'} ne '') {
1137: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1138: $is_custom{'fontmenu'} = 1;
1139: }
1.6 raeburn 1140: foreach my $item (@bgs) {
1141: if ($settings->{$role}->{$item} ne '') {
1142: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1143: $is_custom{$item} = 1;
1144: }
1145: }
1146: foreach my $item (@links) {
1147: if ($settings->{$role}->{$item} ne '') {
1148: $designs{'links'}{$item} = $settings->{$role}->{$item};
1149: $is_custom{$item} = 1;
1150: }
1151: }
1152: }
1153: } else {
1154: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1155: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1156: $is_custom{'img'} = 1;
1157: }
1.97 tempelho 1158: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1159: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1160: $is_custom{'fontmenu'} = 1;
1161: }
1.6 raeburn 1162: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1163: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1164: $is_custom{'font'} = 1;
1165: }
1166: foreach my $item (@bgs) {
1167: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1168: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1169: $is_custom{$item} = 1;
1170:
1171: }
1172: }
1173: foreach my $item (@links) {
1174: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1175: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1176: $is_custom{$item} = 1;
1177: }
1178: }
1179: }
1180: my $itemcount = 1;
1.30 raeburn 1181: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1182: $datatable .= '</tr></table></td></tr>';
1183: return $datatable;
1184: }
1185:
1186: sub display_color_options {
1.9 raeburn 1187: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1188: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1189: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1190: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1191: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1192: '<td>'.$choices->{'font'}.'</td>';
1193: if (!$is_custom->{'font'}) {
1.30 raeburn 1194: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1195: } else {
1196: $datatable .= '<td> </td>';
1197: }
1.160.6.9 raeburn 1198: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1199:
1.8 raeburn 1200: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1201: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1202: ' value="'.$current_color.'" /> '.
1203: ' </td></tr>';
1.107 raeburn 1204: unless ($role eq 'login') {
1205: $datatable .= '<tr'.$css_class.'>'.
1206: '<td>'.$choices->{'fontmenu'}.'</td>';
1207: if (!$is_custom->{'fontmenu'}) {
1208: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1209: } else {
1210: $datatable .= '<td> </td>';
1211: }
1.160.6.9 raeburn 1212: $current_color = $designs->{'fontmenu'} ?
1213: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1214: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1215: '<input class="colorchooser" type="text" size="10" name="'
1216: .$role.'_fontmenu"'.
1217: ' value="'.$current_color.'" /> '.
1218: ' </td></tr>';
1.97 tempelho 1219: }
1.9 raeburn 1220: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1221: foreach my $img (@{$images}) {
1.18 albertel 1222: $itemcount ++;
1.6 raeburn 1223: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1224: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1225: '<td>'.$choices->{$img};
1.41 raeburn 1226: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1227: if ($role eq 'login') {
1228: if ($img eq 'login') {
1229: $login_hdr_pick =
1.135 bisitz 1230: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1231: $logincolors =
1232: &login_text_colors($img,$role,$logintext,$phase,$choices,
1233: $designs);
1234: } elsif ($img ne 'domlogo') {
1235: $datatable.= &logo_display_options($img,$defaults,$designs);
1236: }
1237: }
1238: $datatable .= '</td>';
1.6 raeburn 1239: if ($designs->{$img} ne '') {
1240: $imgfile = $designs->{$img};
1.18 albertel 1241: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1242: } else {
1243: $imgfile = $defaults->{$img};
1244: }
1245: if ($imgfile) {
1.9 raeburn 1246: my ($showfile,$fullsize);
1247: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1248: my $urldir = $1;
1249: my $filename = $2;
1250: my @info = &Apache::lonnet::stat_file($designs->{$img});
1251: if (@info) {
1252: my $thumbfile = 'tn-'.$filename;
1253: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1254: if (@thumb) {
1255: $showfile = $urldir.'/'.$thumbfile;
1256: } else {
1257: $showfile = $imgfile;
1258: }
1259: } else {
1260: $showfile = '';
1261: }
1262: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1263: $showfile = $imgfile;
1.6 raeburn 1264: my $imgdir = $1;
1265: my $filename = $2;
1.159 raeburn 1266: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1267: $showfile = "/$imgdir/tn-".$filename;
1268: } else {
1.159 raeburn 1269: my $input = $londocroot.$imgfile;
1270: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1271: if (!-e $output) {
1.9 raeburn 1272: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1273: my ($fullwidth,$fullheight) = &check_dimensions($input);
1274: if ($fullwidth ne '' && $fullheight ne '') {
1275: if ($fullwidth > $width && $fullheight > $height) {
1276: my $size = $width.'x'.$height;
1277: system("convert -sample $size $input $output");
1.159 raeburn 1278: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1279: }
1280: }
1.6 raeburn 1281: }
1282: }
1.16 raeburn 1283: }
1.6 raeburn 1284: if ($showfile) {
1.40 raeburn 1285: if ($showfile =~ m{^/(adm|res)/}) {
1286: if ($showfile =~ m{^/res/}) {
1287: my $local_showfile =
1288: &Apache::lonnet::filelocation('',$showfile);
1289: &Apache::lonnet::repcopy($local_showfile);
1290: }
1291: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1292: }
1293: if ($imgfile) {
1294: if ($imgfile =~ m{^/(adm|res)/}) {
1295: if ($imgfile =~ m{^/res/}) {
1296: my $local_imgfile =
1297: &Apache::lonnet::filelocation('',$imgfile);
1298: &Apache::lonnet::repcopy($local_imgfile);
1299: }
1300: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1301: } else {
1302: $fullsize = $imgfile;
1303: }
1304: }
1.41 raeburn 1305: $datatable .= '<td>';
1306: if ($img eq 'login') {
1.135 bisitz 1307: $datatable .= $login_hdr_pick;
1308: }
1.41 raeburn 1309: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1310: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1311: } else {
1312: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1313: &mt('Upload:');
1314: }
1315: } else {
1316: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1317: &mt('Upload:');
1318: }
1.9 raeburn 1319: if ($switchserver) {
1320: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1321: } else {
1.135 bisitz 1322: if ($img ne 'login') { # suppress file selection for Log-in header
1323: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1324: }
1.9 raeburn 1325: }
1326: $datatable .= '</td></tr>';
1.6 raeburn 1327: }
1328: $itemcount ++;
1329: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1330: $datatable .= '<tr'.$css_class.'>'.
1331: '<td>'.$choices->{'bgs'}.'</td>';
1332: my $bgs_def;
1333: foreach my $item (@{$bgs}) {
1334: if (!$is_custom->{$item}) {
1.70 raeburn 1335: $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 1336: }
1337: }
1338: if ($bgs_def) {
1.8 raeburn 1339: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1340: } else {
1341: $datatable .= '<td> </td>';
1342: }
1343: $datatable .= '<td class="LC_right_item">'.
1344: '<table border="0"><tr>';
1.160.6.13 raeburn 1345:
1.6 raeburn 1346: foreach my $item (@{$bgs}) {
1.160.6.9 raeburn 1347: $datatable .= '<td align="center">';
1348: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1349: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1350: $datatable .= ' ';
1.6 raeburn 1351: }
1.160.6.9 raeburn 1352: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1353: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1354: }
1355: $datatable .= '</tr></table></td></tr>';
1356: $itemcount ++;
1357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1358: $datatable .= '<tr'.$css_class.'>'.
1359: '<td>'.$choices->{'links'}.'</td>';
1360: my $links_def;
1361: foreach my $item (@{$links}) {
1362: if (!$is_custom->{$item}) {
1.30 raeburn 1363: $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 1364: }
1365: }
1366: if ($links_def) {
1.8 raeburn 1367: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1368: } else {
1369: $datatable .= '<td> </td>';
1370: }
1371: $datatable .= '<td class="LC_right_item">'.
1372: '<table border="0"><tr>';
1373: foreach my $item (@{$links}) {
1.160.6.9 raeburn 1374: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1375: $datatable .= '<td align="center">'."\n";
1376:
1.6 raeburn 1377: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1378: $datatable.=' ';
1.6 raeburn 1379: }
1.160.6.9 raeburn 1380: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1381: '" /></td>';
1382: }
1.30 raeburn 1383: $$rowtotal += $itemcount;
1.3 raeburn 1384: return $datatable;
1385: }
1386:
1.70 raeburn 1387: sub logo_display_options {
1388: my ($img,$defaults,$designs) = @_;
1389: my $checkedon;
1390: if (ref($defaults) eq 'HASH') {
1391: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1392: if ($defaults->{'showlogo'}{$img}) {
1393: $checkedon = 'checked="checked" ';
1394: }
1395: }
1396: }
1397: if (ref($designs) eq 'HASH') {
1398: if (ref($designs->{'showlogo'}) eq 'HASH') {
1399: if (defined($designs->{'showlogo'}{$img})) {
1400: if ($designs->{'showlogo'}{$img} == 0) {
1401: $checkedon = '';
1402: } elsif ($designs->{'showlogo'}{$img} == 1) {
1403: $checkedon = 'checked="checked" ';
1404: }
1405: }
1406: }
1407: }
1408: return '<br /><label> <input type="checkbox" name="'.
1409: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1410: &mt('show').'</label>'."\n";
1411: }
1412:
1.41 raeburn 1413: sub login_header_options {
1.135 bisitz 1414: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1415: my $output = '';
1.41 raeburn 1416: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1417: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1418: if (!$is_custom->{'textcol'}) {
1419: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1420: ' ';
1421: }
1422: if (!$is_custom->{'bgcol'}) {
1423: $output .= $choices->{'bgcol'}.': '.
1424: '<span id="css_'.$role.'_font" style="background-color: '.
1425: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1426: }
1427: $output .= '<br />';
1428: }
1429: $output .='<br />';
1430: return $output;
1431: }
1432:
1433: sub login_text_colors {
1434: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1435: my $color_menu = '<table border="0"><tr>';
1436: foreach my $item (@{$logintext}) {
1437: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1438: $color_menu .= '<td align="center">'.$link;
1439: if ($designs->{'logintext'}{$item}) {
1440: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1441: }
1442: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1443: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1444: '<td> </td>';
1445: }
1446: $color_menu .= '</tr></table><br />';
1447: return $color_menu;
1448: }
1449:
1450: sub image_changes {
1451: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1452: my $output;
1.135 bisitz 1453: if ($img eq 'login') {
1454: # suppress image for Log-in header
1455: } elsif (!$is_custom) {
1.70 raeburn 1456: if ($img ne 'domlogo') {
1.41 raeburn 1457: $output .= &mt('Default image:').'<br />';
1458: } else {
1459: $output .= &mt('Default in use:').'<br />';
1460: }
1461: }
1.135 bisitz 1462: if ($img eq 'login') { # suppress image for Log-in header
1463: $output .= '<td>'.$logincolors;
1.41 raeburn 1464: } else {
1.135 bisitz 1465: if ($img_import) {
1466: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1467: }
1468: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1469: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1470: if ($is_custom) {
1471: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1472: '<input type="checkbox" name="'.
1473: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1474: '</label> '.&mt('Replace:').'</span><br />';
1475: } else {
1476: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1477: }
1.41 raeburn 1478: }
1479: return $output;
1480: }
1481:
1.6 raeburn 1482: sub color_pick {
1483: my ($phase,$role,$item,$desc,$curcol) = @_;
1484: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1485: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1486: ');">'.$desc.'</a>';
1487: return $link;
1488: }
1489:
1.3 raeburn 1490: sub print_quotas {
1.86 raeburn 1491: my ($dom,$settings,$rowtotal,$action) = @_;
1492: my $context;
1493: if ($action eq 'quotas') {
1494: $context = 'tools';
1495: } else {
1496: $context = $action;
1497: }
1.101 raeburn 1498: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1499: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1500: my $typecount = 0;
1.101 raeburn 1501: my ($css_class,%titles);
1.86 raeburn 1502: if ($context eq 'requestcourses') {
1.98 raeburn 1503: @usertools = ('official','unofficial','community');
1.106 raeburn 1504: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1505: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1506: %titles = &courserequest_titles();
1.160.6.5 raeburn 1507: } elsif ($context eq 'requestauthor') {
1508: @usertools = ('author');
1509: @options = ('norequest','approval','automatic');
1510: %titles = &authorrequest_titles();
1.86 raeburn 1511: } else {
1.160.6.4 raeburn 1512: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1513: %titles = &tool_titles();
1.86 raeburn 1514: }
1.26 raeburn 1515: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1516: foreach my $type (@{$types}) {
1.72 raeburn 1517: my $currdefquota;
1.160.6.5 raeburn 1518: unless (($context eq 'requestcourses') ||
1519: ($context eq 'requestauthor')) {
1.86 raeburn 1520: if (ref($settings) eq 'HASH') {
1521: if (ref($settings->{defaultquota}) eq 'HASH') {
1522: $currdefquota = $settings->{defaultquota}->{$type};
1523: } else {
1524: $currdefquota = $settings->{$type};
1525: }
1.78 raeburn 1526: }
1.72 raeburn 1527: }
1.3 raeburn 1528: if (defined($usertypes->{$type})) {
1529: $typecount ++;
1530: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1531: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1532: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1533: '<td class="LC_left_item">';
1.101 raeburn 1534: if ($context eq 'requestcourses') {
1535: $datatable .= '<table><tr>';
1536: }
1537: my %cell;
1.72 raeburn 1538: foreach my $item (@usertools) {
1.101 raeburn 1539: if ($context eq 'requestcourses') {
1540: my ($curroption,$currlimit);
1541: if (ref($settings) eq 'HASH') {
1542: if (ref($settings->{$item}) eq 'HASH') {
1543: $curroption = $settings->{$item}->{$type};
1544: if ($curroption =~ /^autolimit=(\d*)$/) {
1545: $currlimit = $1;
1546: }
1547: }
1548: }
1549: if (!$curroption) {
1550: $curroption = 'norequest';
1551: }
1552: $datatable .= '<th>'.$titles{$item}.'</th>';
1553: foreach my $option (@options) {
1554: my $val = $option;
1555: if ($option eq 'norequest') {
1556: $val = 0;
1557: }
1558: if ($option eq 'validate') {
1559: my $canvalidate = 0;
1560: if (ref($validations{$item}) eq 'HASH') {
1561: if ($validations{$item}{$type}) {
1562: $canvalidate = 1;
1563: }
1564: }
1565: next if (!$canvalidate);
1566: }
1567: my $checked = '';
1568: if ($option eq $curroption) {
1569: $checked = ' checked="checked"';
1570: } elsif ($option eq 'autolimit') {
1571: if ($curroption =~ /^autolimit/) {
1572: $checked = ' checked="checked"';
1573: }
1574: }
1575: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1576: '<input type="radio" name="crsreq_'.$item.
1577: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1578: $titles{$option}.'</label>';
1.101 raeburn 1579: if ($option eq 'autolimit') {
1.127 raeburn 1580: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1581: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1582: 'value="'.$currlimit.'" />';
1.101 raeburn 1583: }
1.127 raeburn 1584: $cell{$item} .= '</span> ';
1.103 raeburn 1585: if ($option eq 'autolimit') {
1.127 raeburn 1586: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1587: }
1.101 raeburn 1588: }
1.160.6.5 raeburn 1589: } elsif ($context eq 'requestauthor') {
1590: my $curroption;
1591: if (ref($settings) eq 'HASH') {
1592: $curroption = $settings->{$type};
1593: }
1594: if (!$curroption) {
1595: $curroption = 'norequest';
1596: }
1597: foreach my $option (@options) {
1598: my $val = $option;
1599: if ($option eq 'norequest') {
1600: $val = 0;
1601: }
1602: my $checked = '';
1603: if ($option eq $curroption) {
1604: $checked = ' checked="checked"';
1605: }
1606: $datatable .= '<span class="LC_nobreak"><label>'.
1607: '<input type="radio" name="authorreq_'.$type.
1608: '" value="'.$val.'"'.$checked.' />'.
1609: $titles{$option}.'</label></span> ';
1610: }
1.101 raeburn 1611: } else {
1612: my $checked = 'checked="checked" ';
1613: if (ref($settings) eq 'HASH') {
1614: if (ref($settings->{$item}) eq 'HASH') {
1615: if ($settings->{$item}->{$type} == 0) {
1616: $checked = '';
1617: } elsif ($settings->{$item}->{$type} == 1) {
1618: $checked = 'checked="checked" ';
1619: }
1.78 raeburn 1620: }
1.72 raeburn 1621: }
1.101 raeburn 1622: $datatable .= '<span class="LC_nobreak"><label>'.
1623: '<input type="checkbox" name="'.$context.'_'.$item.
1624: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1625: '</label></span> ';
1.72 raeburn 1626: }
1.101 raeburn 1627: }
1628: if ($context eq 'requestcourses') {
1629: $datatable .= '</tr><tr>';
1630: foreach my $item (@usertools) {
1.106 raeburn 1631: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1632: }
1633: $datatable .= '</tr></table>';
1.72 raeburn 1634: }
1.86 raeburn 1635: $datatable .= '</td>';
1.160.6.5 raeburn 1636: unless (($context eq 'requestcourses') ||
1637: ($context eq 'requestauthor')) {
1.86 raeburn 1638: $datatable .=
1639: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1640: '<input type="text" name="quota_'.$type.
1.72 raeburn 1641: '" value="'.$currdefquota.
1.86 raeburn 1642: '" size="5" /> Mb</span></td>';
1643: }
1644: $datatable .= '</tr>';
1.3 raeburn 1645: }
1646: }
1647: }
1.160.6.5 raeburn 1648: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1649: $defaultquota = '20';
1650: if (ref($settings) eq 'HASH') {
1651: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1652: $defaultquota = $settings->{'defaultquota'}->{'default'};
1653: } elsif (defined($settings->{'default'})) {
1654: $defaultquota = $settings->{'default'};
1655: }
1.3 raeburn 1656: }
1657: }
1658: $typecount ++;
1659: $css_class = $typecount%2?' class="LC_odd_row"':'';
1660: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1661: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1662: '<td class="LC_left_item">';
1.101 raeburn 1663: if ($context eq 'requestcourses') {
1664: $datatable .= '<table><tr>';
1665: }
1666: my %defcell;
1.72 raeburn 1667: foreach my $item (@usertools) {
1.101 raeburn 1668: if ($context eq 'requestcourses') {
1669: my ($curroption,$currlimit);
1670: if (ref($settings) eq 'HASH') {
1671: if (ref($settings->{$item}) eq 'HASH') {
1672: $curroption = $settings->{$item}->{'default'};
1673: if ($curroption =~ /^autolimit=(\d*)$/) {
1674: $currlimit = $1;
1675: }
1676: }
1677: }
1678: if (!$curroption) {
1679: $curroption = 'norequest';
1680: }
1681: $datatable .= '<th>'.$titles{$item}.'</th>';
1682: foreach my $option (@options) {
1683: my $val = $option;
1684: if ($option eq 'norequest') {
1685: $val = 0;
1686: }
1687: if ($option eq 'validate') {
1688: my $canvalidate = 0;
1689: if (ref($validations{$item}) eq 'HASH') {
1690: if ($validations{$item}{'default'}) {
1691: $canvalidate = 1;
1692: }
1693: }
1694: next if (!$canvalidate);
1695: }
1696: my $checked = '';
1697: if ($option eq $curroption) {
1698: $checked = ' checked="checked"';
1699: } elsif ($option eq 'autolimit') {
1700: if ($curroption =~ /^autolimit/) {
1701: $checked = ' checked="checked"';
1702: }
1703: }
1704: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1705: '<input type="radio" name="crsreq_'.$item.
1706: '_default" value="'.$val.'"'.$checked.' />'.
1707: $titles{$option}.'</label>';
1708: if ($option eq 'autolimit') {
1.127 raeburn 1709: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1710: $item.'_limit_default" size="1" '.
1711: 'value="'.$currlimit.'" />';
1712: }
1.127 raeburn 1713: $defcell{$item} .= '</span> ';
1.104 raeburn 1714: if ($option eq 'autolimit') {
1.127 raeburn 1715: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1716: }
1.101 raeburn 1717: }
1.160.6.5 raeburn 1718: } elsif ($context eq 'requestauthor') {
1719: my $curroption;
1720: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1721: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1722: }
1723: if (!$curroption) {
1724: $curroption = 'norequest';
1725: }
1726: foreach my $option (@options) {
1727: my $val = $option;
1728: if ($option eq 'norequest') {
1729: $val = 0;
1730: }
1731: my $checked = '';
1732: if ($option eq $curroption) {
1733: $checked = ' checked="checked"';
1734: }
1735: $datatable .= '<span class="LC_nobreak"><label>'.
1736: '<input type="radio" name="authorreq_default"'.
1737: ' value="'.$val.'"'.$checked.' />'.
1738: $titles{$option}.'</label></span> ';
1739: }
1.101 raeburn 1740: } else {
1741: my $checked = 'checked="checked" ';
1742: if (ref($settings) eq 'HASH') {
1743: if (ref($settings->{$item}) eq 'HASH') {
1744: if ($settings->{$item}->{'default'} == 0) {
1745: $checked = '';
1746: } elsif ($settings->{$item}->{'default'} == 1) {
1747: $checked = 'checked="checked" ';
1748: }
1.78 raeburn 1749: }
1.72 raeburn 1750: }
1.101 raeburn 1751: $datatable .= '<span class="LC_nobreak"><label>'.
1752: '<input type="checkbox" name="'.$context.'_'.$item.
1753: '" value="default" '.$checked.'/>'.$titles{$item}.
1754: '</label></span> ';
1755: }
1756: }
1757: if ($context eq 'requestcourses') {
1758: $datatable .= '</tr><tr>';
1759: foreach my $item (@usertools) {
1.106 raeburn 1760: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1761: }
1.101 raeburn 1762: $datatable .= '</tr></table>';
1.72 raeburn 1763: }
1.86 raeburn 1764: $datatable .= '</td>';
1.160.6.5 raeburn 1765: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1766: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1767: '<input type="text" name="defaultquota" value="'.
1768: $defaultquota.'" size="5" /> Mb</span></td>';
1769: }
1770: $datatable .= '</tr>';
1.72 raeburn 1771: $typecount ++;
1772: $css_class = $typecount%2?' class="LC_odd_row"':'';
1773: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1774: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1775: if ($context eq 'requestcourses') {
1.109 raeburn 1776: $datatable .= &mt('(overrides affiliation, if set)').
1777: '</td>'.
1778: '<td class="LC_left_item">'.
1779: '<table><tr>';
1.101 raeburn 1780: } else {
1.109 raeburn 1781: $datatable .= &mt('(overrides affiliation, if checked)').
1782: '</td>'.
1783: '<td class="LC_left_item" colspan="2">'.
1784: '<br />';
1.101 raeburn 1785: }
1786: my %advcell;
1.72 raeburn 1787: foreach my $item (@usertools) {
1.101 raeburn 1788: if ($context eq 'requestcourses') {
1789: my ($curroption,$currlimit);
1790: if (ref($settings) eq 'HASH') {
1791: if (ref($settings->{$item}) eq 'HASH') {
1792: $curroption = $settings->{$item}->{'_LC_adv'};
1793: if ($curroption =~ /^autolimit=(\d*)$/) {
1794: $currlimit = $1;
1795: }
1796: }
1797: }
1798: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1799: my $checked = '';
1800: if ($curroption eq '') {
1801: $checked = ' checked="checked"';
1802: }
1803: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1804: '<input type="radio" name="crsreq_'.$item.
1805: '__LC_adv" value=""'.$checked.' />'.
1806: &mt('No override set').'</label></span> ';
1.101 raeburn 1807: foreach my $option (@options) {
1808: my $val = $option;
1809: if ($option eq 'norequest') {
1810: $val = 0;
1811: }
1812: if ($option eq 'validate') {
1813: my $canvalidate = 0;
1814: if (ref($validations{$item}) eq 'HASH') {
1815: if ($validations{$item}{'_LC_adv'}) {
1816: $canvalidate = 1;
1817: }
1818: }
1819: next if (!$canvalidate);
1820: }
1821: my $checked = '';
1.104 raeburn 1822: if ($val eq $curroption) {
1.101 raeburn 1823: $checked = ' checked="checked"';
1824: } elsif ($option eq 'autolimit') {
1825: if ($curroption =~ /^autolimit/) {
1826: $checked = ' checked="checked"';
1827: }
1828: }
1829: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1830: '<input type="radio" name="crsreq_'.$item.
1831: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1832: $titles{$option}.'</label>';
1833: if ($option eq 'autolimit') {
1.127 raeburn 1834: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1835: $item.'_limit__LC_adv" size="1" '.
1836: 'value="'.$currlimit.'" />';
1837: }
1.127 raeburn 1838: $advcell{$item} .= '</span> ';
1.104 raeburn 1839: if ($option eq 'autolimit') {
1.127 raeburn 1840: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1841: }
1.101 raeburn 1842: }
1.160.6.5 raeburn 1843: } elsif ($context eq 'requestauthor') {
1844: my $curroption;
1845: if (ref($settings) eq 'HASH') {
1846: $curroption = $settings->{'_LC_adv'};
1847: }
1848: my $checked = '';
1849: if ($curroption eq '') {
1850: $checked = ' checked="checked"';
1851: }
1852: $datatable .= '<span class="LC_nobreak"><label>'.
1853: '<input type="radio" name="authorreq__LC_adv"'.
1854: ' value=""'.$checked.' />'.
1855: &mt('No override set').'</label></span> ';
1856: foreach my $option (@options) {
1857: my $val = $option;
1858: if ($option eq 'norequest') {
1859: $val = 0;
1860: }
1861: my $checked = '';
1862: if ($val eq $curroption) {
1863: $checked = ' checked="checked"';
1864: }
1865: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1866: '<input type="radio" name="authorreq__LC_adv"'.
1867: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1868: $titles{$option}.'</label></span> ';
1869: }
1.101 raeburn 1870: } else {
1871: my $checked = 'checked="checked" ';
1872: if (ref($settings) eq 'HASH') {
1873: if (ref($settings->{$item}) eq 'HASH') {
1874: if ($settings->{$item}->{'_LC_adv'} == 0) {
1875: $checked = '';
1876: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1877: $checked = 'checked="checked" ';
1878: }
1.79 raeburn 1879: }
1.72 raeburn 1880: }
1.101 raeburn 1881: $datatable .= '<span class="LC_nobreak"><label>'.
1882: '<input type="checkbox" name="'.$context.'_'.$item.
1883: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1884: '</label></span> ';
1885: }
1886: }
1887: if ($context eq 'requestcourses') {
1888: $datatable .= '</tr><tr>';
1889: foreach my $item (@usertools) {
1.106 raeburn 1890: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1891: }
1.101 raeburn 1892: $datatable .= '</tr></table>';
1.72 raeburn 1893: }
1.98 raeburn 1894: $datatable .= '</td></tr>';
1.30 raeburn 1895: $$rowtotal += $typecount;
1.3 raeburn 1896: return $datatable;
1897: }
1898:
1.160.6.5 raeburn 1899: sub print_requestmail {
1900: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1901: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1902: $now = time;
1903: $rows = 0;
1904: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1905: foreach my $server (keys(%dompersonnel)) {
1906: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1907: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1908: if (!grep(/^$uname:$udom$/,@domcoord)) {
1909: push(@domcoord,$uname.':'.$udom);
1910: }
1911: }
1912: }
1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{'notify'}) eq 'HASH') {
1915: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1916: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1917: }
1918: }
1919: }
1.104 raeburn 1920: if (@currapproval) {
1921: foreach my $dc (@currapproval) {
1.102 raeburn 1922: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1923: push(@domcoord,$dc);
1924: }
1925: }
1926: }
1927: @domcoord = sort(@domcoord);
1928: my $numinrow = 4;
1929: my $numdc = @domcoord;
1930: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1931: my $text;
1932: if ($action eq 'requestcourses') {
1933: $text = &mt('Receive notification of course requests requiring approval');
1934: } else {
1935: $text = &mt('Receive notification of authoring space requests requiring approval')
1936: }
1937: $datatable = '<tr '.$css_class.'>'.
1938: ' <td>'.$text.'</td>'.
1.102 raeburn 1939: ' <td class="LC_left_item">';
1940: if (@domcoord > 0) {
1941: $datatable .= '<table>';
1942: for (my $i=0; $i<$numdc; $i++) {
1943: my $rem = $i%($numinrow);
1944: if ($rem == 0) {
1945: if ($i > 0) {
1946: $datatable .= '</tr>';
1947: }
1948: $datatable .= '<tr>';
1949: $rows ++;
1950: }
1951: my $check = ' ';
1.104 raeburn 1952: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1953: $check = ' checked="checked" ';
1954: }
1955: my ($uname,$udom) = split(':',$domcoord[$i]);
1956: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1957: if ($i == $numdc-1) {
1958: my $colsleft = $numinrow-$rem;
1959: if ($colsleft > 1) {
1960: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1961: } else {
1962: $datatable .= '<td class="LC_left_item">';
1963: }
1964: } else {
1965: $datatable .= '<td class="LC_left_item">';
1966: }
1967: $datatable .= '<span class="LC_nobreak"><label>'.
1968: '<input type="checkbox" name="reqapprovalnotify" '.
1969: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.160.6.13 raeburn 1970: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 1971: }
1972: $datatable .= '</tr></table>';
1973: } else {
1974: $datatable .= &mt('There are no active Domain Coordinators');
1975: $rows ++;
1976: }
1977: $datatable .='</td></tr>';
1978: $$rowtotal += $rows;
1979: return $datatable;
1980: }
1981:
1.3 raeburn 1982: sub print_autoenroll {
1.30 raeburn 1983: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1984: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1985: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1986: if (ref($settings) eq 'HASH') {
1987: if (exists($settings->{'run'})) {
1988: if ($settings->{'run'} eq '0') {
1989: $runoff = ' checked="checked" ';
1990: $runon = ' ';
1991: } else {
1992: $runon = ' checked="checked" ';
1993: $runoff = ' ';
1994: }
1995: } else {
1996: if ($autorun) {
1997: $runon = ' checked="checked" ';
1998: $runoff = ' ';
1999: } else {
2000: $runoff = ' checked="checked" ';
2001: $runon = ' ';
2002: }
2003: }
1.129 raeburn 2004: if (exists($settings->{'co-owners'})) {
2005: if ($settings->{'co-owners'} eq '0') {
2006: $coownersoff = ' checked="checked" ';
2007: $coownerson = ' ';
2008: } else {
2009: $coownerson = ' checked="checked" ';
2010: $coownersoff = ' ';
2011: }
2012: } else {
2013: $coownersoff = ' checked="checked" ';
2014: $coownerson = ' ';
2015: }
1.3 raeburn 2016: if (exists($settings->{'sender_domain'})) {
2017: $defdom = $settings->{'sender_domain'};
2018: }
1.14 raeburn 2019: } else {
2020: if ($autorun) {
2021: $runon = ' checked="checked" ';
2022: $runoff = ' ';
2023: } else {
2024: $runoff = ' checked="checked" ';
2025: $runon = ' ';
2026: }
1.3 raeburn 2027: }
2028: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2029: my $notif_sender;
2030: if (ref($settings) eq 'HASH') {
2031: $notif_sender = $settings->{'sender_uname'};
2032: }
1.3 raeburn 2033: my $datatable='<tr class="LC_odd_row">'.
2034: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2035: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2036: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2037: $runon.' value="1" />'.&mt('Yes').'</label> '.
2038: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2039: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2040: '</tr><tr>'.
2041: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2042: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2043: &mt('username').': '.
2044: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2045: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2046: ': '.$domform.'</span></td></tr>'.
2047: '<tr class="LC_odd_row">'.
2048: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2049: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2050: '<input type="radio" name="autoassign_coowners"'.
2051: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2052: '<label><input type="radio" name="autoassign_coowners"'.
2053: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2054: '</tr>';
2055: $$rowtotal += 3;
1.3 raeburn 2056: return $datatable;
2057: }
2058:
2059: sub print_autoupdate {
1.30 raeburn 2060: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2061: my $datatable;
2062: if ($position eq 'top') {
2063: my $updateon = ' ';
2064: my $updateoff = ' checked="checked" ';
2065: my $classlistson = ' ';
2066: my $classlistsoff = ' checked="checked" ';
2067: if (ref($settings) eq 'HASH') {
2068: if ($settings->{'run'} eq '1') {
2069: $updateon = $updateoff;
2070: $updateoff = ' ';
2071: }
2072: if ($settings->{'classlists'} eq '1') {
2073: $classlistson = $classlistsoff;
2074: $classlistsoff = ' ';
2075: }
2076: }
2077: my %title = (
2078: run => 'Auto-update active?',
2079: classlists => 'Update information in classlists?',
2080: );
2081: $datatable = '<tr class="LC_odd_row">'.
2082: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2083: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2084: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2085: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2086: '<label><input type="radio" name="autoupdate_run"'.
2087: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2088: '</tr><tr>'.
2089: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2090: '<td class="LC_right_item"><span class="LC_nobreak">'.
2091: '<label><input type="radio" name="classlists"'.
2092: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2093: '<label><input type="radio" name="classlists"'.
2094: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2095: '</tr>';
1.30 raeburn 2096: $$rowtotal += 2;
1.131 raeburn 2097: } elsif ($position eq 'middle') {
2098: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2099: my $numinrow = 3;
2100: my $locknamesettings;
2101: $datatable .= &insttypes_row($settings,$types,$usertypes,
2102: $dom,$numinrow,$othertitle,
2103: 'lockablenames');
2104: $$rowtotal ++;
1.3 raeburn 2105: } else {
1.44 raeburn 2106: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2107: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2108: 'permanentemail','id');
1.33 raeburn 2109: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2110: my $numrows = 0;
1.26 raeburn 2111: if (ref($types) eq 'ARRAY') {
2112: if (@{$types} > 0) {
2113: $datatable =
2114: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2115: \@fields,$types,\$numrows);
1.30 raeburn 2116: $$rowtotal += @{$types};
1.26 raeburn 2117: }
1.3 raeburn 2118: }
2119: $datatable .=
2120: &usertype_update_row($settings,{'default' => $othertitle},
2121: \%fieldtitles,\@fields,['default'],
2122: \$numrows);
1.30 raeburn 2123: $$rowtotal ++;
1.3 raeburn 2124: }
2125: return $datatable;
2126: }
2127:
1.125 raeburn 2128: sub print_autocreate {
2129: my ($dom,$settings,$rowtotal) = @_;
2130: my (%createon,%createoff);
2131: my $curr_dc;
2132: my @types = ('xml','req');
2133: if (ref($settings) eq 'HASH') {
2134: foreach my $item (@types) {
2135: $createoff{$item} = ' checked="checked" ';
2136: $createon{$item} = ' ';
2137: if (exists($settings->{$item})) {
2138: if ($settings->{$item}) {
2139: $createon{$item} = ' checked="checked" ';
2140: $createoff{$item} = ' ';
2141: }
2142: }
2143: }
2144: $curr_dc = $settings->{'xmldc'};
2145: } else {
2146: foreach my $item (@types) {
2147: $createoff{$item} = ' checked="checked" ';
2148: $createon{$item} = ' ';
2149: }
2150: }
2151: $$rowtotal += 2;
2152: my $datatable='<tr class="LC_odd_row">'.
2153: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2154: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2155: '<input type="radio" name="autocreate_xml"'.
2156: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2157: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2158: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2159: '</td></tr><tr>'.
2160: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2161: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2162: '<input type="radio" name="autocreate_req"'.
2163: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2164: '<label><input type="radio" name="autocreate_req"'.
2165: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2166: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2167: if ($numdc > 1) {
1.143 raeburn 2168: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2169: &mt('Course creation processed as: (choose Dom. Coord.)').
2170: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2171: $$rowtotal ++ ;
2172: } else {
1.143 raeburn 2173: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2174: }
2175: return $datatable;
2176: }
2177:
1.23 raeburn 2178: sub print_directorysrch {
1.30 raeburn 2179: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2180: my $srchon = ' ';
2181: my $srchoff = ' checked="checked" ';
1.25 raeburn 2182: my ($exacton,$containson,$beginson);
1.24 raeburn 2183: my $localon = ' ';
2184: my $localoff = ' checked="checked" ';
1.23 raeburn 2185: if (ref($settings) eq 'HASH') {
2186: if ($settings->{'available'} eq '1') {
2187: $srchon = $srchoff;
2188: $srchoff = ' ';
2189: }
1.24 raeburn 2190: if ($settings->{'localonly'} eq '1') {
2191: $localon = $localoff;
2192: $localoff = ' ';
2193: }
1.25 raeburn 2194: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2195: foreach my $type (@{$settings->{'searchtypes'}}) {
2196: if ($type eq 'exact') {
2197: $exacton = ' checked="checked" ';
2198: } elsif ($type eq 'contains') {
2199: $containson = ' checked="checked" ';
2200: } elsif ($type eq 'begins') {
2201: $beginson = ' checked="checked" ';
2202: }
2203: }
2204: } else {
2205: if ($settings->{'searchtypes'} eq 'exact') {
2206: $exacton = ' checked="checked" ';
2207: } elsif ($settings->{'searchtypes'} eq 'contains') {
2208: $containson = ' checked="checked" ';
2209: } elsif ($settings->{'searchtypes'} eq 'specify') {
2210: $exacton = ' checked="checked" ';
2211: $containson = ' checked="checked" ';
2212: }
1.23 raeburn 2213: }
2214: }
2215: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2217:
2218: my $numinrow = 4;
1.26 raeburn 2219: my $cansrchrow = 0;
1.23 raeburn 2220: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2221: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2222: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2223: '<input type="radio" name="dirsrch_available"'.
2224: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2225: '<label><input type="radio" name="dirsrch_available"'.
2226: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2227: '</tr><tr>'.
1.30 raeburn 2228: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2229: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2230: '<input type="radio" name="dirsrch_localonly"'.
2231: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2232: '<label><input type="radio" name="dirsrch_localonly"'.
2233: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2234: '</tr>';
1.30 raeburn 2235: $$rowtotal += 2;
1.26 raeburn 2236: if (ref($usertypes) eq 'HASH') {
2237: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2238: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2239: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2240: $cansrchrow = 1;
2241: }
2242: }
2243: if ($cansrchrow) {
1.30 raeburn 2244: $$rowtotal ++;
1.26 raeburn 2245: $datatable .= '<tr>';
2246: } else {
2247: $datatable .= '<tr class="LC_odd_row">';
2248: }
1.30 raeburn 2249: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2250: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2251: foreach my $title (@{$titleorder}) {
2252: if (defined($searchtitles->{$title})) {
2253: my $check = ' ';
1.93 raeburn 2254: if (ref($settings) eq 'HASH') {
1.39 raeburn 2255: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2256: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2257: $check = ' checked="checked" ';
2258: }
1.25 raeburn 2259: }
2260: }
2261: $datatable .= '<td class="LC_left_item">'.
2262: '<span class="LC_nobreak"><label>'.
2263: '<input type="checkbox" name="searchby" '.
2264: 'value="'.$title.'"'.$check.'/>'.
2265: $searchtitles->{$title}.'</label></span></td>';
2266: }
2267: }
1.26 raeburn 2268: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2269: $$rowtotal ++;
1.26 raeburn 2270: if ($cansrchrow) {
2271: $datatable .= '<tr class="LC_odd_row">';
2272: } else {
2273: $datatable .= '<tr>';
2274: }
1.30 raeburn 2275: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2276: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2277: '<span class="LC_nobreak"><label>'.
2278: '<input type="checkbox" name="searchtypes" '.
2279: $exacton.' value="exact" />'.&mt('Exact match').
2280: '</label> '.
2281: '<label><input type="checkbox" name="searchtypes" '.
2282: $beginson.' value="begins" />'.&mt('Begins with').
2283: '</label> '.
2284: '<label><input type="checkbox" name="searchtypes" '.
2285: $containson.' value="contains" />'.&mt('Contains').
2286: '</label></span></td></tr>';
1.30 raeburn 2287: $$rowtotal ++;
1.25 raeburn 2288: return $datatable;
2289: }
2290:
1.28 raeburn 2291: sub print_contacts {
1.30 raeburn 2292: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2293: my $datatable;
2294: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2295: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2296: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2297: 'requestsmail');
1.28 raeburn 2298: foreach my $type (@mailings) {
2299: $otheremails{$type} = '';
2300: }
1.134 raeburn 2301: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2302: if (ref($settings) eq 'HASH') {
2303: foreach my $item (@contacts) {
2304: if (exists($settings->{$item})) {
2305: $to{$item} = $settings->{$item};
2306: }
2307: }
2308: foreach my $type (@mailings) {
2309: if (exists($settings->{$type})) {
2310: if (ref($settings->{$type}) eq 'HASH') {
2311: foreach my $item (@contacts) {
2312: if ($settings->{$type}{$item}) {
2313: $checked{$type}{$item} = ' checked="checked" ';
2314: }
2315: }
2316: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2317: if ($type eq 'helpdeskmail') {
2318: $bccemails{$type} = $settings->{$type}{'bcc'};
2319: }
1.28 raeburn 2320: }
1.89 raeburn 2321: } elsif ($type eq 'lonstatusmail') {
2322: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2323: }
2324: }
2325: } else {
2326: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2327: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2328: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2329: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2330: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2331: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2332: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2333: }
2334: my ($titles,$short_titles) = &contact_titles();
2335: my $rownum = 0;
2336: my $css_class;
2337: foreach my $item (@contacts) {
1.69 raeburn 2338: $rownum ++;
2339: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2340: $datatable .= '<tr'.$css_class.'>'.
2341: '<td><span class="LC_nobreak">'.$titles->{$item}.
2342: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2343: '<input type="text" name="'.$item.'" value="'.
2344: $to{$item}.'" /></td></tr>';
2345: }
2346: foreach my $type (@mailings) {
1.69 raeburn 2347: $rownum ++;
2348: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2349: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2350: '<td><span class="LC_nobreak">'.
2351: $titles->{$type}.': </span></td>'.
1.28 raeburn 2352: '<td class="LC_left_item">'.
2353: '<span class="LC_nobreak">';
2354: foreach my $item (@contacts) {
2355: $datatable .= '<label>'.
2356: '<input type="checkbox" name="'.$type.'"'.
2357: $checked{$type}{$item}.
2358: ' value="'.$item.'" />'.$short_titles->{$item}.
2359: '</label> ';
2360: }
2361: $datatable .= '</span><br />'.&mt('Others').': '.
2362: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2363: 'value="'.$otheremails{$type}.'" />';
2364: if ($type eq 'helpdeskmail') {
1.136 raeburn 2365: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2366: '<input type="text" name="'.$type.'_bcc" '.
2367: 'value="'.$bccemails{$type}.'" />';
2368: }
2369: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2370: }
1.30 raeburn 2371: $$rowtotal += $rownum;
1.28 raeburn 2372: return $datatable;
2373: }
2374:
1.118 jms 2375: sub print_helpsettings {
1.160.6.5 raeburn 2376: my ($dom,$confname,$settings,$rowtotal) = @_;
2377: my ($datatable,$itemcount);
2378: $itemcount = 1;
2379: my (%choices,%defaultchecked,@toggles);
2380: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2381: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2382: &mt('LON-CAPA bug tracker'),600,500));
2383: %defaultchecked = ('submitbugs' => 'on');
2384: @toggles = ('submitbugs',);
1.122 jms 2385:
1.160.6.5 raeburn 2386: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2387: \%choices,$itemcount);
2388: return $datatable;
1.121 raeburn 2389: }
2390:
2391: sub radiobutton_prefs {
2392: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2393: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2394: (ref($choices) eq 'HASH'));
2395:
2396: my (%checkedon,%checkedoff,$datatable,$css_class);
2397:
2398: foreach my $item (@{$toggles}) {
2399: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2400: $checkedon{$item} = ' checked="checked" ';
2401: $checkedoff{$item} = ' ';
1.121 raeburn 2402: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2403: $checkedoff{$item} = ' checked="checked" ';
2404: $checkedon{$item} = ' ';
2405: }
2406: }
2407: if (ref($settings) eq 'HASH') {
1.121 raeburn 2408: foreach my $item (@{$toggles}) {
1.118 jms 2409: if ($settings->{$item} eq '1') {
2410: $checkedon{$item} = ' checked="checked" ';
2411: $checkedoff{$item} = ' ';
2412: } elsif ($settings->{$item} eq '0') {
2413: $checkedoff{$item} = ' checked="checked" ';
2414: $checkedon{$item} = ' ';
2415: }
2416: }
1.121 raeburn 2417: }
2418: foreach my $item (@{$toggles}) {
1.118 jms 2419: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2420: $datatable .=
2421: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2422: '</span></td>'.
2423: '<td class="LC_right_item"><span class="LC_nobreak">'.
2424: '<label><input type="radio" name="'.
2425: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2426: '</label> <label><input type="radio" name="'.$item.'" '.
2427: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2428: '</span></td>'.
2429: '</tr>';
2430: $itemcount ++;
1.121 raeburn 2431: }
2432: return ($datatable,$itemcount);
2433: }
2434:
2435: sub print_coursedefaults {
1.139 raeburn 2436: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2437: my ($css_class,$datatable);
2438: my $itemcount = 1;
1.139 raeburn 2439: if ($position eq 'top') {
2440: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2441: %choices =
2442: &Apache::lonlocal::texthash (
2443: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2444: );
2445: %defaultchecked = ('canuse_pdfforms' => 'off');
2446: @toggles = ('canuse_pdfforms',);
2447: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2448: \%choices,$itemcount);
1.139 raeburn 2449: $$rowtotal += $itemcount;
2450: } else {
2451: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2452: my %choices =
2453: &Apache::lonlocal::texthash (
2454: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2455: );
2456: my $currdefresponder;
2457: if (ref($settings) eq 'HASH') {
2458: $currdefresponder = $settings->{'anonsurvey_threshold'};
2459: }
2460: if (!$currdefresponder) {
2461: $currdefresponder = 10;
2462: } elsif ($currdefresponder < 1) {
2463: $currdefresponder = 1;
2464: }
2465: $datatable .=
2466: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2467: '</span></td>'.
2468: '<td class="LC_right_item"><span class="LC_nobreak">'.
2469: '<input type="text" name="anonsurvey_threshold"'.
2470: ' value="'.$currdefresponder.'" size="5" /></span>'.
2471: '</td></tr>';
2472: }
1.121 raeburn 2473: return $datatable;
1.118 jms 2474: }
2475:
1.137 raeburn 2476: sub print_usersessions {
2477: my ($position,$dom,$settings,$rowtotal) = @_;
2478: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2479: my (%by_ip,%by_location,@intdoms);
2480: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2481:
2482: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2483: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2484: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2485: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2486: my $itemcount = 1;
2487: if ($position eq 'top') {
1.152 raeburn 2488: if (keys(%serverhomes) > 1) {
1.145 raeburn 2489: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2490: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2491: } else {
1.140 raeburn 2492: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2493: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2494: }
1.137 raeburn 2495: } else {
1.145 raeburn 2496: if (keys(%by_location) == 0) {
2497: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2498: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2499: } else {
2500: my %lt = &usersession_titles();
2501: my $numinrow = 5;
2502: my $prefix;
2503: my @types;
2504: if ($position eq 'bottom') {
2505: $prefix = 'remote';
2506: @types = ('version','excludedomain','includedomain');
2507: } else {
2508: $prefix = 'hosted';
2509: @types = ('excludedomain','includedomain');
2510: }
2511: my (%current,%checkedon,%checkedoff);
2512: my @lcversions = &Apache::lonnet::all_loncaparevs();
2513: my @locations = sort(keys(%by_location));
2514: foreach my $type (@types) {
2515: $checkedon{$type} = '';
2516: $checkedoff{$type} = ' checked="checked"';
2517: }
2518: if (ref($settings) eq 'HASH') {
2519: if (ref($settings->{$prefix}) eq 'HASH') {
2520: foreach my $key (keys(%{$settings->{$prefix}})) {
2521: $current{$key} = $settings->{$prefix}{$key};
2522: if ($key eq 'version') {
2523: if ($current{$key} ne '') {
2524: $checkedon{$key} = ' checked="checked"';
2525: $checkedoff{$key} = '';
2526: }
2527: } elsif (ref($current{$key}) eq 'ARRAY') {
2528: $checkedon{$key} = ' checked="checked"';
2529: $checkedoff{$key} = '';
2530: }
1.137 raeburn 2531: }
2532: }
2533: }
1.145 raeburn 2534: foreach my $type (@types) {
2535: next if ($type ne 'version' && !@locations);
2536: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2537: $datatable .= '<tr'.$css_class.'>
2538: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2539: <span class="LC_nobreak">
2540: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2541: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2542: if ($type eq 'version') {
2543: my $selector = '<select name="'.$prefix.'_version">';
2544: foreach my $version (@lcversions) {
2545: my $selected = '';
2546: if ($current{'version'} eq $version) {
2547: $selected = ' selected="selected"';
2548: }
2549: $selector .= ' <option value="'.$version.'"'.
2550: $selected.'>'.$version.'</option>';
2551: }
2552: $selector .= '</select> ';
2553: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2554: } else {
2555: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2556: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2557: ' />'.(' 'x2).
2558: '<input type="button" value="'.&mt('uncheck all').'" '.
2559: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2560: "\n".
2561: '</div><div><table>';
2562: my $rem;
2563: for (my $i=0; $i<@locations; $i++) {
2564: my ($showloc,$value,$checkedtype);
2565: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2566: my $ip = $by_location{$locations[$i]}->[0];
2567: if (ref($by_ip{$ip}) eq 'ARRAY') {
2568: $value = join(':',@{$by_ip{$ip}});
2569: $showloc = join(', ',@{$by_ip{$ip}});
2570: if (ref($current{$type}) eq 'ARRAY') {
2571: foreach my $loc (@{$by_ip{$ip}}) {
2572: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2573: $checkedtype = ' checked="checked"';
2574: last;
2575: }
2576: }
1.138 raeburn 2577: }
2578: }
2579: }
1.145 raeburn 2580: $rem = $i%($numinrow);
2581: if ($rem == 0) {
2582: if ($i > 0) {
2583: $datatable .= '</tr>';
2584: }
2585: $datatable .= '<tr>';
2586: }
2587: $datatable .= '<td class="LC_left_item">'.
2588: '<span class="LC_nobreak"><label>'.
2589: '<input type="checkbox" name="'.$prefix.'_'.$type.
2590: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2591: '</label></span></td>';
1.137 raeburn 2592: }
1.145 raeburn 2593: $rem = @locations%($numinrow);
2594: my $colsleft = $numinrow - $rem;
2595: if ($colsleft > 1 ) {
2596: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2597: ' </td>';
2598: } elsif ($colsleft == 1) {
2599: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2600: }
1.145 raeburn 2601: $datatable .= '</tr></table>';
1.137 raeburn 2602: }
1.145 raeburn 2603: $datatable .= '</td></tr>';
2604: $itemcount ++;
1.137 raeburn 2605: }
2606: }
2607: }
2608: $$rowtotal += $itemcount;
2609: return $datatable;
2610: }
2611:
1.138 raeburn 2612: sub build_location_hashes {
2613: my ($intdoms,$by_ip,$by_location) = @_;
2614: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2615: (ref($by_location) eq 'HASH'));
2616: my %iphost = &Apache::lonnet::get_iphost();
2617: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2618: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2619: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2620: foreach my $id (@{$iphost{$primary_ip}}) {
2621: my $intdom = &Apache::lonnet::internet_dom($id);
2622: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2623: push(@{$intdoms},$intdom);
2624: }
2625: }
2626: }
2627: foreach my $ip (keys(%iphost)) {
2628: if (ref($iphost{$ip}) eq 'ARRAY') {
2629: foreach my $id (@{$iphost{$ip}}) {
2630: my $location = &Apache::lonnet::internet_dom($id);
2631: if ($location) {
2632: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2633: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2634: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2635: push(@{$by_ip->{$ip}},$location);
2636: }
2637: } else {
2638: $by_ip->{$ip} = [$location];
2639: }
2640: }
2641: }
2642: }
2643: }
2644: foreach my $ip (sort(keys(%{$by_ip}))) {
2645: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2646: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2647: my $first = $by_ip->{$ip}->[0];
2648: if (ref($by_location->{$first}) eq 'ARRAY') {
2649: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2650: push(@{$by_location->{$first}},$ip);
2651: }
2652: } else {
2653: $by_location->{$first} = [$ip];
2654: }
2655: }
2656: }
2657: return;
2658: }
2659:
1.145 raeburn 2660: sub current_offloads_to {
2661: my ($dom,$settings,$servers) = @_;
2662: my (%spareid,%otherdomconfigs);
1.152 raeburn 2663: if (ref($servers) eq 'HASH') {
1.145 raeburn 2664: foreach my $lonhost (sort(keys(%{$servers}))) {
2665: my $gotspares;
1.152 raeburn 2666: if (ref($settings) eq 'HASH') {
2667: if (ref($settings->{'spares'}) eq 'HASH') {
2668: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2669: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2670: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2671: $gotspares = 1;
2672: }
1.145 raeburn 2673: }
2674: }
2675: unless ($gotspares) {
2676: my $gotspares;
2677: my $serverhomeID =
2678: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2679: my $serverhomedom =
2680: &Apache::lonnet::host_domain($serverhomeID);
2681: if ($serverhomedom ne $dom) {
2682: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2683: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2684: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2685: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2686: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2687: $gotspares = 1;
2688: }
2689: }
2690: } else {
2691: $otherdomconfigs{$serverhomedom} =
2692: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2693: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2694: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2695: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2696: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2697: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2698: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2699: $gotspares = 1;
2700: }
2701: }
2702: }
2703: }
2704: }
2705: }
2706: }
2707: unless ($gotspares) {
2708: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2709: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2710: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2711: } else {
2712: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2713: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2714: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2715: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2716: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2717: } else {
1.150 raeburn 2718: my %what = (
2719: spareid => 1,
2720: );
2721: my ($result,$returnhash) =
2722: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2723: if ($result eq 'ok') {
2724: if (ref($returnhash) eq 'HASH') {
2725: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2726: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2727: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2728: }
2729: }
1.145 raeburn 2730: }
2731: }
2732: }
2733: }
2734: }
2735: }
2736: return %spareid;
2737: }
2738:
2739: sub spares_row {
1.152 raeburn 2740: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2741: my $css_class;
2742: my $numinrow = 4;
2743: my $itemcount = 1;
2744: my $datatable;
1.152 raeburn 2745: my %typetitles = &sparestype_titles();
2746: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2747: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2748: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2749: my ($othercontrol,$serverdom);
2750: if ($serverhome ne $server) {
2751: $serverdom = &Apache::lonnet::host_domain($serverhome);
2752: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2753: } else {
2754: $serverdom = &Apache::lonnet::host_domain($server);
2755: if ($serverdom ne $dom) {
2756: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2757: }
2758: }
2759: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2760: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2761: $datatable .= '<tr'.$css_class.'>
2762: <td rowspan="2">
1.160.6.13 raeburn 2763: <span class="LC_nobreak">'.
2764: &mt('[_1] when busy, offloads to:'
2765: ,'<b>'.$server.'</b>').
2766: "\n";
1.145 raeburn 2767: my (%current,%canselect);
1.152 raeburn 2768: my @choices =
2769: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2770: foreach my $type ('primary','default') {
2771: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2772: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2773: my @spares = @{$spareid->{$server}{$type}};
2774: if (@spares > 0) {
1.152 raeburn 2775: if ($othercontrol) {
2776: $current{$type} = join(', ',@spares);
2777: } else {
2778: $current{$type} .= '<table>';
2779: my $numspares = scalar(@spares);
2780: for (my $i=0; $i<@spares; $i++) {
2781: my $rem = $i%($numinrow);
2782: if ($rem == 0) {
2783: if ($i > 0) {
2784: $current{$type} .= '</tr>';
2785: }
2786: $current{$type} .= '<tr>';
1.145 raeburn 2787: }
1.152 raeburn 2788: $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'".');" /> '.
2789: $spareid->{$server}{$type}[$i].
2790: '</label></td>'."\n";
2791: }
2792: my $rem = @spares%($numinrow);
2793: my $colsleft = $numinrow - $rem;
2794: if ($colsleft > 1 ) {
2795: $current{$type} .= '<td colspan="'.$colsleft.
2796: '" class="LC_left_item">'.
2797: ' </td>';
2798: } elsif ($colsleft == 1) {
2799: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2800: }
1.152 raeburn 2801: $current{$type} .= '</tr></table>';
1.150 raeburn 2802: }
1.145 raeburn 2803: }
2804: }
2805: if ($current{$type} eq '') {
2806: $current{$type} = &mt('None specified');
2807: }
1.152 raeburn 2808: if ($othercontrol) {
2809: if ($type eq 'primary') {
2810: $canselect{$type} = $othercontrol;
2811: }
2812: } else {
2813: $canselect{$type} =
2814: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2815: '<select name="newspare_'.$type.'_'.$server.'" '.
2816: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2817: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2818: if (@choices > 0) {
2819: foreach my $lonhost (@choices) {
2820: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2821: }
2822: }
2823: $canselect{$type} .= '</select>'."\n";
2824: }
2825: } else {
2826: $current{$type} = &mt('Could not be determined');
2827: if ($type eq 'primary') {
2828: $canselect{$type} = $othercontrol;
2829: }
1.145 raeburn 2830: }
1.152 raeburn 2831: if ($type eq 'default') {
2832: $datatable .= '<tr'.$css_class.'>';
2833: }
2834: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2835: '<td>'.$current{$type}.'</td>'."\n".
2836: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2837: }
2838: $itemcount ++;
2839: }
2840: }
2841: $$rowtotal += $itemcount;
2842: return $datatable;
2843: }
2844:
1.152 raeburn 2845: sub possible_newspares {
2846: my ($server,$currspares,$serverhomes,$altids) = @_;
2847: my $serverhostname = &Apache::lonnet::hostname($server);
2848: my %excluded;
2849: if ($serverhostname ne '') {
2850: %excluded = (
2851: $serverhostname => 1,
2852: );
2853: }
2854: if (ref($currspares) eq 'HASH') {
2855: foreach my $type (keys(%{$currspares})) {
2856: if (ref($currspares->{$type}) eq 'ARRAY') {
2857: if (@{$currspares->{$type}} > 0) {
2858: foreach my $curr (@{$currspares->{$type}}) {
2859: my $hostname = &Apache::lonnet::hostname($curr);
2860: $excluded{$hostname} = 1;
2861: }
2862: }
2863: }
2864: }
2865: }
2866: my @choices;
2867: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2868: if (keys(%{$serverhomes}) > 1) {
2869: foreach my $name (sort(keys(%{$serverhomes}))) {
2870: unless ($excluded{$name}) {
2871: if (exists($altids->{$serverhomes->{$name}})) {
2872: push(@choices,$altids->{$serverhomes->{$name}});
2873: } else {
2874: push(@choices,$serverhomes->{$name});
1.145 raeburn 2875: }
2876: }
2877: }
2878: }
2879: }
1.152 raeburn 2880: return sort(@choices);
1.145 raeburn 2881: }
2882:
1.150 raeburn 2883: sub print_loadbalancing {
2884: my ($dom,$settings,$rowtotal) = @_;
2885: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2886: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2887: my $numinrow = 1;
2888: my $datatable;
2889: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2890: my (%currbalancer,%currtargets,%currrules,%existing);
2891: if (ref($settings) eq 'HASH') {
2892: %existing = %{$settings};
2893: }
2894: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2895: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2896: \%currtargets,\%currrules);
1.150 raeburn 2897: } else {
2898: return;
2899: }
2900: my ($othertitle,$usertypes,$types) =
2901: &Apache::loncommon::sorted_inst_types($dom);
2902: my $rownum = 6;
2903: if (ref($types) eq 'ARRAY') {
2904: $rownum += scalar(@{$types});
2905: }
1.160.6.7 raeburn 2906: my @css_class = ('LC_odd_row','LC_even_row');
2907: my $balnum = 0;
2908: my $islast;
2909: my (@toshow,$disabledtext);
2910: if (keys(%currbalancer) > 0) {
2911: @toshow = sort(keys(%currbalancer));
2912: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2913: push(@toshow,'');
2914: }
2915: } else {
2916: @toshow = ('');
2917: $disabledtext = &mt('No existing load balancer');
2918: }
2919: foreach my $lonhost (@toshow) {
2920: if ($balnum == scalar(@toshow)-1) {
2921: $islast = 1;
2922: } else {
2923: $islast = 0;
2924: }
2925: my $cssidx = $balnum%2;
2926: my $targets_div_style = 'display: none';
2927: my $disabled_div_style = 'display: block';
2928: my $homedom_div_style = 'display: none';
2929: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2930: '<td rowspan="'.$rownum.'" valign="top">'.
2931: '<p>';
2932: if ($lonhost eq '') {
2933: $datatable .= '<span class="LC_nobreak">';
2934: if (keys(%currbalancer) > 0) {
2935: $datatable .= &mt('Add balancer:');
2936: } else {
2937: $datatable .= &mt('Enable balancer:');
2938: }
2939: $datatable .= ' '.
2940: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2941: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2942: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2943: '<option value="" selected="selected">'.&mt('None').
2944: '</option>'."\n";
2945: foreach my $server (sort(keys(%servers))) {
2946: next if ($currbalancer{$server});
2947: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2948: }
2949: $datatable .=
2950: '</select>'."\n".
2951: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2952: } else {
2953: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2954: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2955: &mt('Stop balancing').'</label>'.
2956: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2957: $targets_div_style = 'display: block';
2958: $disabled_div_style = 'display: none';
2959: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2960: $homedom_div_style = 'display: block';
2961: }
2962: }
2963: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2964: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2965: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2966: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2967: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2968: my @sparestypes = ('primary','default');
2969: my %typetitles = &sparestype_titles();
2970: foreach my $sparetype (@sparestypes) {
2971: my $targettable;
2972: for (my $i=0; $i<$numspares; $i++) {
2973: my $checked;
2974: if (ref($currtargets{$lonhost}) eq 'HASH') {
2975: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
2976: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
2977: $checked = ' checked="checked"';
2978: }
2979: }
2980: }
2981: my ($chkboxval,$disabled);
2982: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
2983: $chkboxval = $spares[$i];
2984: }
2985: if (exists($currbalancer{$spares[$i]})) {
2986: $disabled = ' disabled="disabled"';
2987: }
2988: $targettable .=
2989: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
2990: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2991: '</span></label></td>';
2992: my $rem = $i%($numinrow);
2993: if ($rem == 0) {
2994: if (($i > 0) && ($i < $numspares-1)) {
2995: $targettable .= '</tr>';
2996: }
2997: if ($i < $numspares-1) {
2998: $targettable .= '<tr>';
1.150 raeburn 2999: }
3000: }
3001: }
1.160.6.7 raeburn 3002: if ($targettable ne '') {
3003: my $rem = $numspares%($numinrow);
3004: my $colsleft = $numinrow - $rem;
3005: if ($colsleft > 1 ) {
3006: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3007: ' </td>';
3008: } elsif ($colsleft == 1) {
3009: $targettable .= '<td class="LC_left_item"> </td>';
3010: }
3011: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3012: '<table><tr>'.$targettable.'</tr></table><br />';
3013: }
3014: }
3015: $datatable .= '</div></td></tr>'.
3016: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3017: $othertitle,$usertypes,$types,\%servers,
3018: \%currbalancer,$lonhost,
3019: $targets_div_style,$homedom_div_style,
3020: $css_class[$cssidx],$balnum,$islast);
3021: $$rowtotal += $rownum;
3022: $balnum ++;
3023: }
3024: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3025: return $datatable;
3026: }
3027:
3028: sub get_loadbalancers_config {
3029: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3030: return unless ((ref($servers) eq 'HASH') &&
3031: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3032: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3033: if (keys(%{$existing}) > 0) {
3034: my $oldlonhost;
3035: foreach my $key (sort(keys(%{$existing}))) {
3036: if ($key eq 'lonhost') {
3037: $oldlonhost = $existing->{'lonhost'};
3038: $currbalancer->{$oldlonhost} = 1;
3039: } elsif ($key eq 'targets') {
3040: if ($oldlonhost) {
3041: $currtargets->{$oldlonhost} = $existing->{'targets'};
3042: }
3043: } elsif ($key eq 'rules') {
3044: if ($oldlonhost) {
3045: $currrules->{$oldlonhost} = $existing->{'rules'};
3046: }
3047: } elsif (ref($existing->{$key}) eq 'HASH') {
3048: $currbalancer->{$key} = 1;
3049: $currtargets->{$key} = $existing->{$key}{'targets'};
3050: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3051: }
3052: }
1.160.6.7 raeburn 3053: } else {
3054: my ($balancerref,$targetsref) =
3055: &Apache::lonnet::get_lonbalancer_config($servers);
3056: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3057: foreach my $server (sort(keys(%{$balancerref}))) {
3058: $currbalancer->{$server} = 1;
3059: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3060: }
3061: }
3062: }
1.160.6.7 raeburn 3063: return;
1.150 raeburn 3064: }
3065:
3066: sub loadbalancing_rules {
3067: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3068: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3069: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3070: my $output;
1.160.6.7 raeburn 3071: my $num = 0;
3072: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3073: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3074: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3075: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3076: $num ++;
1.150 raeburn 3077: my $current;
3078: if (ref($currrules) eq 'HASH') {
3079: $current = $currrules->{$type};
3080: }
3081: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3082: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3083: $current = '';
3084: }
3085: }
3086: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3087: $servers,$currbalancer,$lonhost,$dom,
3088: $targets_div_style,$homedom_div_style,
3089: $css_class,$balnum,$num,$islast);
1.150 raeburn 3090: }
3091: }
3092: return $output;
3093: }
3094:
3095: sub loadbalancing_titles {
3096: my ($dom,$intdom,$usertypes,$types) = @_;
3097: my %othertypes = (
3098: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3099: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3100: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3101: '_LC_external' => &mt('Users not from [_1]',$intdom),
3102: );
3103: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3104: if (ref($types) eq 'ARRAY') {
3105: unshift(@alltypes,@{$types},'default');
3106: }
3107: my %titles;
3108: foreach my $type (@alltypes) {
3109: if ($type =~ /^_LC_/) {
3110: $titles{$type} = $othertypes{$type};
3111: } elsif ($type eq 'default') {
3112: $titles{$type} = &mt('All users from [_1]',$dom);
3113: if (ref($types) eq 'ARRAY') {
3114: if (@{$types} > 0) {
3115: $titles{$type} = &mt('Other users from [_1]',$dom);
3116: }
3117: }
3118: } elsif (ref($usertypes) eq 'HASH') {
3119: $titles{$type} = $usertypes->{$type};
3120: }
3121: }
3122: return (\@alltypes,\%othertypes,\%titles);
3123: }
3124:
3125: sub loadbalance_rule_row {
1.160.6.7 raeburn 3126: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3127: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3128: my @rulenames = ('default','homeserver');
3129: my %ruletitles = &offloadtype_text();
3130: if ($type eq '_LC_external') {
3131: push(@rulenames,'externalbalancer');
3132: } else {
3133: push(@rulenames,'specific');
3134: }
1.160.6.3 raeburn 3135: push(@rulenames,'none');
1.150 raeburn 3136: my $style = $targets_div_style;
3137: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3138: $style = $homedom_div_style;
3139: }
1.160.6.7 raeburn 3140: my $space;
3141: if ($islast && $num == 1) {
3142: $space = '<div display="inline-block"> </div>';
3143: }
3144: my $output =
3145: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3146: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3147: '<td valaign="top">'.$space.
3148: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3149: for (my $i=0; $i<@rulenames; $i++) {
3150: my $rule = $rulenames[$i];
3151: my ($checked,$extra);
3152: if ($rulenames[$i] eq 'default') {
3153: $rule = '';
3154: }
3155: if ($rulenames[$i] eq 'specific') {
3156: if (ref($servers) eq 'HASH') {
3157: my $default;
3158: if (($current ne '') && (exists($servers->{$current}))) {
3159: $checked = ' checked="checked"';
3160: }
3161: unless ($checked) {
3162: $default = ' selected="selected"';
3163: }
1.160.6.7 raeburn 3164: $extra =
3165: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3166: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3167: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3168: '<option value=""'.$default.'></option>'."\n";
3169: foreach my $server (sort(keys(%{$servers}))) {
3170: if (ref($currbalancer) eq 'HASH') {
3171: next if (exists($currbalancer->{$server}));
3172: }
1.150 raeburn 3173: my $selected;
1.160.6.7 raeburn 3174: if ($server eq $current) {
1.150 raeburn 3175: $selected = ' selected="selected"';
3176: }
1.160.6.7 raeburn 3177: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3178: }
3179: $extra .= '</select>';
3180: }
3181: } elsif ($rule eq $current) {
3182: $checked = ' checked="checked"';
3183: }
3184: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3185: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3186: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3187: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3188: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3189: '</label>'.$extra.'</span><br />'."\n";
3190: }
3191: $output .= '</div></td></tr>'."\n";
3192: return $output;
3193: }
3194:
3195: sub offloadtype_text {
3196: my %ruletitles = &Apache::lonlocal::texthash (
3197: 'default' => 'Offloads to default destinations',
3198: 'homeserver' => "Offloads to user's home server",
3199: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3200: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3201: 'none' => 'No offload',
1.150 raeburn 3202: );
3203: return %ruletitles;
3204: }
3205:
3206: sub sparestype_titles {
3207: my %typestitles = &Apache::lonlocal::texthash (
3208: 'primary' => 'primary',
3209: 'default' => 'default',
3210: );
3211: return %typestitles;
3212: }
3213:
1.28 raeburn 3214: sub contact_titles {
3215: my %titles = &Apache::lonlocal::texthash (
3216: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3217: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3218: 'errormail' => 'Error reports to be e-mailed to',
3219: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3220: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3221: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3222: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3223: );
3224: my %short_titles = &Apache::lonlocal::texthash (
3225: adminemail => 'Admin E-mail address',
3226: supportemail => 'Support E-mail',
3227: );
3228: return (\%titles,\%short_titles);
3229: }
3230:
1.72 raeburn 3231: sub tool_titles {
3232: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3233: aboutme => 'Personal web page',
1.86 raeburn 3234: blog => 'Blog',
1.160.6.4 raeburn 3235: webdav => 'WebDAV',
1.86 raeburn 3236: portfolio => 'Portfolio',
1.88 bisitz 3237: official => 'Official courses (with institutional codes)',
3238: unofficial => 'Unofficial courses',
1.98 raeburn 3239: community => 'Communities',
1.86 raeburn 3240: );
1.72 raeburn 3241: return %titles;
3242: }
3243:
1.101 raeburn 3244: sub courserequest_titles {
3245: my %titles = &Apache::lonlocal::texthash (
3246: official => 'Official',
3247: unofficial => 'Unofficial',
3248: community => 'Communities',
3249: norequest => 'Not allowed',
1.104 raeburn 3250: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3251: validate => 'With validation',
3252: autolimit => 'Numerical limit',
1.103 raeburn 3253: unlimited => '(blank for unlimited)',
1.101 raeburn 3254: );
3255: return %titles;
3256: }
3257:
1.160.6.5 raeburn 3258: sub authorrequest_titles {
3259: my %titles = &Apache::lonlocal::texthash (
3260: norequest => 'Not allowed',
3261: approval => 'Approval by Dom. Coord.',
3262: automatic => 'Automatic approval',
3263: );
3264: return %titles;
3265: }
3266:
1.101 raeburn 3267: sub courserequest_conditions {
3268: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3269: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3270: validate => '(Processing of request subject to instittutional validation).',
3271: );
3272: return %conditions;
3273: }
3274:
3275:
1.27 raeburn 3276: sub print_usercreation {
1.30 raeburn 3277: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3278: my $numinrow = 4;
1.28 raeburn 3279: my $datatable;
3280: if ($position eq 'top') {
1.30 raeburn 3281: $$rowtotal ++;
1.34 raeburn 3282: my $rowcount = 0;
1.32 raeburn 3283: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3284: if (ref($rules) eq 'HASH') {
3285: if (keys(%{$rules}) > 0) {
1.32 raeburn 3286: $datatable .= &user_formats_row('username',$settings,$rules,
3287: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3288: $$rowtotal ++;
1.32 raeburn 3289: $rowcount ++;
3290: }
3291: }
3292: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3293: if (ref($idrules) eq 'HASH') {
3294: if (keys(%{$idrules}) > 0) {
3295: $datatable .= &user_formats_row('id',$settings,$idrules,
3296: $idruleorder,$numinrow,$rowcount);
3297: $$rowtotal ++;
3298: $rowcount ++;
1.28 raeburn 3299: }
3300: }
1.43 raeburn 3301: my ($emailrules,$emailruleorder) =
3302: &Apache::lonnet::inst_userrules($dom,'email');
3303: if (ref($emailrules) eq 'HASH') {
3304: if (keys(%{$emailrules}) > 0) {
3305: $datatable .= &user_formats_row('email',$settings,$emailrules,
3306: $emailruleorder,$numinrow,$rowcount);
3307: $$rowtotal ++;
3308: $rowcount ++;
3309: }
3310: }
1.39 raeburn 3311: if ($rowcount == 0) {
3312: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3313: $$rowtotal ++;
3314: $rowcount ++;
3315: }
1.34 raeburn 3316: } elsif ($position eq 'middle') {
1.100 raeburn 3317: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3318: my ($rules,$ruleorder) =
3319: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3320: my %lt = &usercreation_types();
3321: my %checked;
1.50 raeburn 3322: my @selfcreate;
1.34 raeburn 3323: if (ref($settings) eq 'HASH') {
3324: if (ref($settings->{'cancreate'}) eq 'HASH') {
3325: foreach my $item (@creators) {
3326: $checked{$item} = $settings->{'cancreate'}{$item};
3327: }
1.50 raeburn 3328: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3329: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3330: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3331: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3332: @selfcreate = ('email','login','sso');
3333: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3334: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3335: }
3336: }
1.34 raeburn 3337: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3338: foreach my $item (@creators) {
3339: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3340: $checked{$item} = 'none';
3341: }
3342: }
3343: }
3344: }
3345: my $rownum = 0;
3346: foreach my $item (@creators) {
3347: $rownum ++;
1.50 raeburn 3348: if ($item ne 'selfcreate') {
3349: if ($checked{$item} eq '') {
1.43 raeburn 3350: $checked{$item} = 'any';
3351: }
1.34 raeburn 3352: }
3353: my $css_class;
3354: if ($rownum%2) {
3355: $css_class = '';
3356: } else {
3357: $css_class = ' class="LC_odd_row" ';
3358: }
3359: $datatable .= '<tr'.$css_class.'>'.
3360: '<td><span class="LC_nobreak">'.$lt{$item}.
3361: '</span></td><td align="right">';
1.50 raeburn 3362: my @options;
1.45 raeburn 3363: if ($item eq 'selfcreate') {
1.43 raeburn 3364: push(@options,('email','login','sso'));
3365: } else {
1.50 raeburn 3366: @options = ('any');
1.43 raeburn 3367: if (ref($rules) eq 'HASH') {
3368: if (keys(%{$rules}) > 0) {
3369: push(@options,('official','unofficial'));
3370: }
1.37 raeburn 3371: }
1.50 raeburn 3372: push(@options,'none');
1.37 raeburn 3373: }
3374: foreach my $option (@options) {
1.50 raeburn 3375: my $type = 'radio';
1.34 raeburn 3376: my $check = ' ';
1.50 raeburn 3377: if ($item eq 'selfcreate') {
3378: $type = 'checkbox';
3379: if (grep(/^\Q$option\E$/,@selfcreate)) {
3380: $check = ' checked="checked" ';
3381: }
3382: } else {
3383: if ($checked{$item} eq $option) {
3384: $check = ' checked="checked" ';
3385: }
1.34 raeburn 3386: }
3387: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3388: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3389: $item.'" value="'.$option.'"'.$check.'/> '.
3390: $lt{$option}.'</label> </span>';
3391: }
3392: $datatable .= '</td></tr>';
3393: }
1.93 raeburn 3394: my ($othertitle,$usertypes,$types) =
3395: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3396: my $createsettings;
3397: if (ref($settings) eq 'HASH') {
3398: $createsettings = $settings->{cancreate};
3399: }
1.93 raeburn 3400: if (ref($usertypes) eq 'HASH') {
3401: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3402: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3403: $dom,$numinrow,$othertitle,
3404: 'statustocreate');
3405: $$rowtotal ++;
1.160.6.5 raeburn 3406: $rownum ++;
1.93 raeburn 3407: }
3408: }
1.160.6.5 raeburn 3409: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3410: } else {
3411: my @contexts = ('author','course','domain');
3412: my @authtypes = ('int','krb4','krb5','loc');
3413: my %checked;
3414: if (ref($settings) eq 'HASH') {
3415: if (ref($settings->{'authtypes'}) eq 'HASH') {
3416: foreach my $item (@contexts) {
3417: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3418: foreach my $auth (@authtypes) {
3419: if ($settings->{'authtypes'}{$item}{$auth}) {
3420: $checked{$item}{$auth} = ' checked="checked" ';
3421: }
3422: }
3423: }
3424: }
1.27 raeburn 3425: }
1.35 raeburn 3426: } else {
3427: foreach my $item (@contexts) {
1.36 raeburn 3428: foreach my $auth (@authtypes) {
1.35 raeburn 3429: $checked{$item}{$auth} = ' checked="checked" ';
3430: }
3431: }
1.27 raeburn 3432: }
1.28 raeburn 3433: my %title = &context_names();
3434: my %authname = &authtype_names();
3435: my $rownum = 0;
3436: my $css_class;
3437: foreach my $item (@contexts) {
3438: if ($rownum%2) {
3439: $css_class = '';
3440: } else {
3441: $css_class = ' class="LC_odd_row" ';
3442: }
1.30 raeburn 3443: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3444: '<td>'.$title{$item}.
3445: '</td><td class="LC_left_item">'.
3446: '<span class="LC_nobreak">';
3447: foreach my $auth (@authtypes) {
3448: $datatable .= '<label>'.
3449: '<input type="checkbox" name="'.$item.'_auth" '.
3450: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3451: $authname{$auth}.'</label> ';
3452: }
3453: $datatable .= '</span></td></tr>';
3454: $rownum ++;
1.27 raeburn 3455: }
1.30 raeburn 3456: $$rowtotal += $rownum;
1.27 raeburn 3457: }
3458: return $datatable;
3459: }
3460:
1.160.6.5 raeburn 3461: sub captcha_choice {
3462: my ($context,$settings,$itemcount) = @_;
3463: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3464: my %lt = &captcha_phrases();
3465: $keyentry = 'hidden';
3466: if ($context eq 'cancreate') {
3467: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3468: } elsif ($context eq 'login') {
3469: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3470: }
3471: if (ref($settings) eq 'HASH') {
3472: if ($settings->{'captcha'}) {
3473: $checked{$settings->{'captcha'}} = ' checked="checked"';
3474: } else {
3475: $checked{'original'} = ' checked="checked"';
3476: }
3477: if ($settings->{'captcha'} eq 'recaptcha') {
3478: $pubtext = $lt{'pub'};
3479: $privtext = $lt{'priv'};
3480: $keyentry = 'text';
3481: }
3482: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3483: $currpub = $settings->{'recaptchakeys'}{'public'};
3484: $currpriv = $settings->{'recaptchakeys'}{'private'};
3485: }
3486: } else {
3487: $checked{'original'} = ' checked="checked"';
3488: }
3489: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3490: my $output = '<tr'.$css_class.'>'.
3491: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3492: '<table><tr><td>'."\n";
3493: foreach my $option ('original','recaptcha','notused') {
3494: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3495: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3496: $lt{$option}.'</label></span>';
3497: unless ($option eq 'notused') {
3498: $output .= (' 'x2)."\n";
3499: }
3500: }
3501: #
3502: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3503: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3504: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3505: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3506: #
3507: $output .= '</td></tr>'."\n".
3508: '<tr><td>'."\n".
3509: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3510: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3511: $currpub.'" size="40" /></span><br />'."\n".
3512: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3513: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3514: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3515: '</td></tr>';
3516: return $output;
3517: }
3518:
1.32 raeburn 3519: sub user_formats_row {
3520: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3521: my $output;
3522: my %text = (
3523: 'username' => 'new usernames',
3524: 'id' => 'IDs',
1.45 raeburn 3525: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3526: );
3527: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3528: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3529: '<td><span class="LC_nobreak">';
3530: if ($type eq 'email') {
3531: $output .= &mt("Formats disallowed for $text{$type}: ");
3532: } else {
3533: $output .= &mt("Format rules to check for $text{$type}: ");
3534: }
3535: $output .= '</span></td>'.
3536: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3537: my $rem;
3538: if (ref($ruleorder) eq 'ARRAY') {
3539: for (my $i=0; $i<@{$ruleorder}; $i++) {
3540: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3541: my $rem = $i%($numinrow);
3542: if ($rem == 0) {
3543: if ($i > 0) {
3544: $output .= '</tr>';
3545: }
3546: $output .= '<tr>';
3547: }
3548: my $check = ' ';
1.39 raeburn 3549: if (ref($settings) eq 'HASH') {
3550: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3551: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3552: $check = ' checked="checked" ';
3553: }
1.27 raeburn 3554: }
3555: }
3556: $output .= '<td class="LC_left_item">'.
3557: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3558: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3559: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3560: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3561: }
3562: }
3563: $rem = @{$ruleorder}%($numinrow);
3564: }
3565: my $colsleft = $numinrow - $rem;
3566: if ($colsleft > 1 ) {
3567: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3568: ' </td>';
3569: } elsif ($colsleft == 1) {
3570: $output .= '<td class="LC_left_item"> </td>';
3571: }
3572: $output .= '</tr></table></td></tr>';
3573: return $output;
3574: }
3575:
1.34 raeburn 3576: sub usercreation_types {
3577: my %lt = &Apache::lonlocal::texthash (
3578: author => 'When adding a co-author',
3579: course => 'When adding a user to a course',
1.100 raeburn 3580: requestcrs => 'When requesting a course',
1.45 raeburn 3581: selfcreate => 'User creates own account',
1.34 raeburn 3582: any => 'Any',
3583: official => 'Institutional only ',
3584: unofficial => 'Non-institutional only',
1.85 schafran 3585: email => 'E-mail address',
1.43 raeburn 3586: login => 'Institutional Login',
3587: sso => 'SSO',
1.34 raeburn 3588: none => 'None',
3589: );
3590: return %lt;
1.48 raeburn 3591: }
1.34 raeburn 3592:
1.28 raeburn 3593: sub authtype_names {
3594: my %lt = &Apache::lonlocal::texthash(
3595: int => 'Internal',
3596: krb4 => 'Kerberos 4',
3597: krb5 => 'Kerberos 5',
3598: loc => 'Local',
3599: );
3600: return %lt;
3601: }
3602:
3603: sub context_names {
3604: my %context_title = &Apache::lonlocal::texthash(
3605: author => 'Creating users when an Author',
3606: course => 'Creating users when in a course',
3607: domain => 'Creating users when a Domain Coordinator',
3608: );
3609: return %context_title;
3610: }
3611:
1.33 raeburn 3612: sub print_usermodification {
3613: my ($position,$dom,$settings,$rowtotal) = @_;
3614: my $numinrow = 4;
3615: my ($context,$datatable,$rowcount);
3616: if ($position eq 'top') {
3617: $rowcount = 0;
3618: $context = 'author';
3619: foreach my $role ('ca','aa') {
3620: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3621: $numinrow,$rowcount);
3622: $$rowtotal ++;
3623: $rowcount ++;
3624: }
1.63 raeburn 3625: } elsif ($position eq 'middle') {
1.33 raeburn 3626: $context = 'course';
3627: $rowcount = 0;
3628: foreach my $role ('st','ep','ta','in','cr') {
3629: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3630: $numinrow,$rowcount);
3631: $$rowtotal ++;
3632: $rowcount ++;
3633: }
1.63 raeburn 3634: } elsif ($position eq 'bottom') {
3635: $context = 'selfcreate';
3636: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3637: $usertypes->{'default'} = $othertitle;
3638: if (ref($types) eq 'ARRAY') {
3639: push(@{$types},'default');
3640: $usertypes->{'default'} = $othertitle;
3641: foreach my $status (@{$types}) {
3642: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3643: $numinrow,$rowcount,$usertypes);
3644: $$rowtotal ++;
3645: $rowcount ++;
3646: }
3647: }
1.33 raeburn 3648: }
3649: return $datatable;
3650: }
3651:
1.43 raeburn 3652: sub print_defaults {
3653: my ($dom,$rowtotal) = @_;
1.68 raeburn 3654: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3655: 'datelocale_def','portal_def');
1.43 raeburn 3656: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3657: my $titles = &defaults_titles($dom);
1.43 raeburn 3658: my $rownum = 0;
3659: my ($datatable,$css_class);
3660: foreach my $item (@items) {
3661: if ($rownum%2) {
3662: $css_class = '';
3663: } else {
3664: $css_class = ' class="LC_odd_row" ';
3665: }
3666: $datatable .= '<tr'.$css_class.'>'.
3667: '<td><span class="LC_nobreak">'.$titles->{$item}.
3668: '</span></td><td class="LC_right_item">';
3669: if ($item eq 'auth_def') {
3670: my @authtypes = ('internal','krb4','krb5','localauth');
3671: my %shortauth = (
3672: internal => 'int',
3673: krb4 => 'krb4',
3674: krb5 => 'krb5',
3675: localauth => 'loc'
3676: );
3677: my %authnames = &authtype_names();
3678: foreach my $auth (@authtypes) {
3679: my $checked = ' ';
3680: if ($domdefaults{$item} eq $auth) {
3681: $checked = ' checked="checked" ';
3682: }
3683: $datatable .= '<label><input type="radio" name="'.$item.
3684: '" value="'.$auth.'"'.$checked.'/>'.
3685: $authnames{$shortauth{$auth}}.'</label> ';
3686: }
1.54 raeburn 3687: } elsif ($item eq 'timezone_def') {
3688: my $includeempty = 1;
3689: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3690: } elsif ($item eq 'datelocale_def') {
3691: my $includeempty = 1;
3692: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3693: } elsif ($item eq 'lang_def') {
3694: my %langchoices = &get_languages_hash();
3695: $langchoices{''} = 'No language preference';
3696: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3697: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3698: \%langchoices);
1.43 raeburn 3699: } else {
1.141 raeburn 3700: my $size;
3701: if ($item eq 'portal_def') {
3702: $size = ' size="25"';
3703: }
1.43 raeburn 3704: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3705: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3706: }
3707: $datatable .= '</td></tr>';
3708: $rownum ++;
3709: }
3710: $$rowtotal += $rownum;
3711: return $datatable;
3712: }
3713:
1.160.6.5 raeburn 3714: sub get_languages_hash {
3715: my %langchoices;
3716: foreach my $id (&Apache::loncommon::languageids()) {
3717: my $code = &Apache::loncommon::supportedlanguagecode($id);
3718: if ($code ne '') {
3719: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3720: }
3721: }
3722: return %langchoices;
3723: }
3724:
1.43 raeburn 3725: sub defaults_titles {
1.141 raeburn 3726: my ($dom) = @_;
1.43 raeburn 3727: my %titles = &Apache::lonlocal::texthash (
3728: 'auth_def' => 'Default authentication type',
3729: 'auth_arg_def' => 'Default authentication argument',
3730: 'lang_def' => 'Default language',
1.54 raeburn 3731: 'timezone_def' => 'Default timezone',
1.68 raeburn 3732: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3733: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3734: );
1.141 raeburn 3735: if ($dom) {
3736: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3737: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3738: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3739: $protocol = 'http' if ($protocol ne 'https');
3740: if ($uint_dom) {
3741: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3742: $uint_dom);
3743: }
3744: }
1.43 raeburn 3745: return (\%titles);
3746: }
3747:
1.46 raeburn 3748: sub print_scantronformat {
3749: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3750: my $itemcount = 1;
1.60 raeburn 3751: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3752: %confhash);
1.46 raeburn 3753: my $switchserver = &check_switchserver($dom,$confname);
3754: my %lt = &Apache::lonlocal::texthash (
1.95 www 3755: default => 'Default bubblesheet format file error',
3756: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3757: );
3758: my %scantronfiles = (
3759: default => 'default.tab',
3760: custom => 'custom.tab',
3761: );
3762: foreach my $key (keys(%scantronfiles)) {
3763: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3764: .$scantronfiles{$key};
3765: }
3766: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3767: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3768: if (!$switchserver) {
3769: my $servadm = $r->dir_config('lonAdmEMail');
3770: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3771: if ($configuserok eq 'ok') {
3772: if ($author_ok eq 'ok') {
3773: my %legacyfile = (
3774: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3775: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3776: );
3777: my %md5chk;
3778: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3779: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3780: chomp($md5chk{$type});
1.46 raeburn 3781: }
3782: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3783: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3784: ($scantronurls{$type},my $error) =
1.46 raeburn 3785: &legacy_scantronformat($r,$dom,$confname,
3786: $type,$legacyfile{$type},
3787: $scantronurls{$type},
3788: $scantronfiles{$type});
1.60 raeburn 3789: if ($error ne '') {
3790: $error{$type} = $error;
3791: }
3792: }
3793: if (keys(%error) == 0) {
3794: $is_custom = 1;
3795: $confhash{'scantron'}{'scantronformat'} =
3796: $scantronurls{'custom'};
3797: my $putresult =
3798: &Apache::lonnet::put_dom('configuration',
3799: \%confhash,$dom);
3800: if ($putresult ne 'ok') {
3801: $error{'custom'} =
3802: '<span class="LC_error">'.
3803: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3804: }
1.46 raeburn 3805: }
3806: } else {
1.60 raeburn 3807: ($scantronurls{'default'},my $error) =
1.46 raeburn 3808: &legacy_scantronformat($r,$dom,$confname,
3809: 'default',$legacyfile{'default'},
3810: $scantronurls{'default'},
3811: $scantronfiles{'default'});
1.60 raeburn 3812: if ($error eq '') {
3813: $confhash{'scantron'}{'scantronformat'} = '';
3814: my $putresult =
3815: &Apache::lonnet::put_dom('configuration',
3816: \%confhash,$dom);
3817: if ($putresult ne 'ok') {
3818: $error{'default'} =
3819: '<span class="LC_error">'.
3820: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3821: }
3822: } else {
3823: $error{'default'} = $error;
3824: }
1.46 raeburn 3825: }
3826: }
3827: }
3828: } else {
1.95 www 3829: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3830: }
3831: }
3832: if (ref($settings) eq 'HASH') {
3833: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3834: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3835: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3836: $scantronurl = '';
3837: } else {
3838: $scantronurl = $settings->{'scantronformat'};
3839: }
3840: $is_custom = 1;
3841: } else {
3842: $scantronurl = $scantronurls{'default'};
3843: }
3844: } else {
1.60 raeburn 3845: if ($is_custom) {
3846: $scantronurl = $scantronurls{'custom'};
3847: } else {
3848: $scantronurl = $scantronurls{'default'};
3849: }
1.46 raeburn 3850: }
3851: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3852: $datatable .= '<tr'.$css_class.'>';
3853: if (!$is_custom) {
1.65 raeburn 3854: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3855: '<span class="LC_nobreak">';
1.46 raeburn 3856: if ($scantronurl) {
3857: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3858: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3859: } else {
3860: $datatable = &mt('File unavailable for display');
3861: }
1.65 raeburn 3862: $datatable .= '</span></td>';
1.60 raeburn 3863: if (keys(%error) == 0) {
3864: $datatable .= '<td valign="bottom">';
3865: if (!$switchserver) {
3866: $datatable .= &mt('Upload:').'<br />';
3867: }
3868: } else {
3869: my $errorstr;
3870: foreach my $key (sort(keys(%error))) {
3871: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3872: }
3873: $datatable .= '<td>'.$errorstr;
3874: }
1.46 raeburn 3875: } else {
3876: if (keys(%error) > 0) {
3877: my $errorstr;
3878: foreach my $key (sort(keys(%error))) {
3879: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3880: }
1.60 raeburn 3881: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3882: } elsif ($scantronurl) {
1.65 raeburn 3883: $datatable .= '<td><span class="LC_nobreak">'.
3884: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3885: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3886: '<input type="checkbox" name="scantronformat_del"'.
3887: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3888: '<td><span class="LC_nobreak"> '.
3889: &mt('Replace:').'</span><br />';
1.46 raeburn 3890: }
3891: }
3892: if (keys(%error) == 0) {
3893: if ($switchserver) {
3894: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3895: } else {
1.65 raeburn 3896: $datatable .='<span class="LC_nobreak"> '.
3897: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3898: }
3899: }
3900: $datatable .= '</td></tr>';
3901: $$rowtotal ++;
3902: return $datatable;
3903: }
3904:
3905: sub legacy_scantronformat {
3906: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3907: my ($url,$error);
3908: my @statinfo = &Apache::lonnet::stat_file($newurl);
3909: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3910: (my $result,$url) =
3911: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3912: '','',$newfile);
3913: if ($result ne 'ok') {
1.130 raeburn 3914: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3915: }
3916: }
3917: return ($url,$error);
3918: }
1.43 raeburn 3919:
1.49 raeburn 3920: sub print_coursecategories {
1.57 raeburn 3921: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3922: my $datatable;
3923: if ($position eq 'top') {
3924: my $toggle_cats_crs = ' ';
3925: my $toggle_cats_dom = ' checked="checked" ';
3926: my $can_cat_crs = ' ';
3927: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3928: my $toggle_catscomm_comm = ' ';
3929: my $toggle_catscomm_dom = ' checked="checked" ';
3930: my $can_catcomm_comm = ' ';
3931: my $can_catcomm_dom = ' checked="checked" ';
3932:
1.57 raeburn 3933: if (ref($settings) eq 'HASH') {
3934: if ($settings->{'togglecats'} eq 'crs') {
3935: $toggle_cats_crs = $toggle_cats_dom;
3936: $toggle_cats_dom = ' ';
3937: }
3938: if ($settings->{'categorize'} eq 'crs') {
3939: $can_cat_crs = $can_cat_dom;
3940: $can_cat_dom = ' ';
3941: }
1.120 raeburn 3942: if ($settings->{'togglecatscomm'} eq 'comm') {
3943: $toggle_catscomm_comm = $toggle_catscomm_dom;
3944: $toggle_catscomm_dom = ' ';
3945: }
3946: if ($settings->{'categorizecomm'} eq 'comm') {
3947: $can_catcomm_comm = $can_catcomm_dom;
3948: $can_catcomm_dom = ' ';
3949: }
1.57 raeburn 3950: }
3951: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3952: togglecats => 'Show/Hide a course in catalog',
3953: togglecatscomm => 'Show/Hide a community in catalog',
3954: categorize => 'Assign a category to a course',
3955: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3956: );
3957: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3958: dom => 'Set in Domain',
3959: crs => 'Set in Course',
3960: comm => 'Set in Community',
1.57 raeburn 3961: );
3962: $datatable = '<tr class="LC_odd_row">'.
3963: '<td>'.$title{'togglecats'}.'</td>'.
3964: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3965: '<input type="radio" name="togglecats"'.
3966: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3967: '<label><input type="radio" name="togglecats"'.
3968: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3969: '</tr><tr>'.
3970: '<td>'.$title{'categorize'}.'</td>'.
3971: '<td class="LC_right_item"><span class="LC_nobreak">'.
3972: '<label><input type="radio" name="categorize"'.
3973: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3974: '<label><input type="radio" name="categorize"'.
3975: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3976: '</tr><tr class="LC_odd_row">'.
3977: '<td>'.$title{'togglecatscomm'}.'</td>'.
3978: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3979: '<input type="radio" name="togglecatscomm"'.
3980: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3981: '<label><input type="radio" name="togglecatscomm"'.
3982: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3983: '</tr><tr>'.
3984: '<td>'.$title{'categorizecomm'}.'</td>'.
3985: '<td class="LC_right_item"><span class="LC_nobreak">'.
3986: '<label><input type="radio" name="categorizecomm"'.
3987: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3988: '<label><input type="radio" name="categorizecomm"'.
3989: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3990: '</tr>';
1.120 raeburn 3991: $$rowtotal += 4;
1.57 raeburn 3992: } else {
3993: my $css_class;
3994: my $itemcount = 1;
3995: my $cathash;
3996: if (ref($settings) eq 'HASH') {
3997: $cathash = $settings->{'cats'};
3998: }
3999: if (ref($cathash) eq 'HASH') {
4000: my (@cats,@trails,%allitems,%idx,@jsarray);
4001: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4002: \%allitems,\%idx,\@jsarray);
4003: my $maxdepth = scalar(@cats);
4004: my $colattrib = '';
4005: if ($maxdepth > 2) {
4006: $colattrib = ' colspan="2" ';
4007: }
4008: my @path;
4009: if (@cats > 0) {
4010: if (ref($cats[0]) eq 'ARRAY') {
4011: my $numtop = @{$cats[0]};
4012: my $maxnum = $numtop;
1.120 raeburn 4013: my %default_names = (
4014: instcode => &mt('Official courses'),
4015: communities => &mt('Communities'),
4016: );
4017:
4018: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4019: ($cathash->{'instcode::0'} eq '') ||
4020: (!grep(/^communities$/,@{$cats[0]})) ||
4021: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4022: $maxnum ++;
4023: }
4024: my $lastidx;
4025: for (my $i=0; $i<$numtop; $i++) {
4026: my $parent = $cats[0][$i];
4027: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4028: my $item = &escape($parent).'::0';
4029: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4030: $lastidx = $idx{$item};
4031: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4032: .'<select name="'.$item.'"'.$chgstr.'>';
4033: for (my $k=0; $k<=$maxnum; $k++) {
4034: my $vpos = $k+1;
4035: my $selstr;
4036: if ($k == $i) {
4037: $selstr = ' selected="selected" ';
4038: }
4039: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4040: }
4041: $datatable .= '</select></td><td>';
1.120 raeburn 4042: if ($parent eq 'instcode' || $parent eq 'communities') {
4043: $datatable .= '<span class="LC_nobreak">'
4044: .$default_names{$parent}.'</span>';
4045: if ($parent eq 'instcode') {
4046: $datatable .= '<br /><span class="LC_nobreak">('
4047: .&mt('with institutional codes')
4048: .')</span></td><td'.$colattrib.'>';
4049: } else {
4050: $datatable .= '<table><tr><td>';
4051: }
4052: $datatable .= '<span class="LC_nobreak">'
4053: .'<label><input type="radio" name="'
4054: .$parent.'" value="1" checked="checked" />'
4055: .&mt('Display').'</label>';
4056: if ($parent eq 'instcode') {
4057: $datatable .= ' ';
4058: } else {
4059: $datatable .= '</span></td></tr><tr><td>'
4060: .'<span class="LC_nobreak">';
4061: }
4062: $datatable .= '<label><input type="radio" name="'
4063: .$parent.'" value="0" />'
4064: .&mt('Do not display').'</label></span>';
4065: if ($parent eq 'communities') {
4066: $datatable .= '</td></tr></table>';
4067: }
4068: $datatable .= '</td>';
1.57 raeburn 4069: } else {
4070: $datatable .= $parent
4071: .' <label><input type="checkbox" name="deletecategory" '
4072: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4073: }
4074: my $depth = 1;
4075: push(@path,$parent);
4076: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4077: pop(@path);
4078: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4079: $itemcount ++;
4080: }
1.48 raeburn 4081: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4082: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4083: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4084: for (my $k=0; $k<=$maxnum; $k++) {
4085: my $vpos = $k+1;
4086: my $selstr;
1.57 raeburn 4087: if ($k == $numtop) {
1.48 raeburn 4088: $selstr = ' selected="selected" ';
4089: }
4090: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4091: }
1.59 bisitz 4092: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4093: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4094: .'</tr>'."\n";
1.48 raeburn 4095: $itemcount ++;
1.120 raeburn 4096: foreach my $default ('instcode','communities') {
4097: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4098: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4099: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4100: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4101: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4102: for (my $k=0; $k<=$maxnum; $k++) {
4103: my $vpos = $k+1;
4104: my $selstr;
4105: if ($k == $maxnum) {
4106: $selstr = ' selected="selected" ';
4107: }
4108: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4109: }
1.120 raeburn 4110: $datatable .= '</select></span></td>'.
4111: '<td><span class="LC_nobreak">'.
4112: $default_names{$default}.'</span>';
4113: if ($default eq 'instcode') {
4114: $datatable .= '<br /><span class="LC_nobreak">('
4115: .&mt('with institutional codes').')</span>';
4116: }
4117: $datatable .= '</td>'
4118: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4119: .&mt('Display').'</label> '
4120: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4121: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4122: }
4123: }
4124: }
1.57 raeburn 4125: } else {
4126: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4127: }
4128: } else {
1.57 raeburn 4129: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4130: .&initialize_categories($itemcount);
1.48 raeburn 4131: }
1.57 raeburn 4132: $$rowtotal += $itemcount;
1.48 raeburn 4133: }
4134: return $datatable;
4135: }
4136:
1.69 raeburn 4137: sub print_serverstatuses {
4138: my ($dom,$settings,$rowtotal) = @_;
4139: my $datatable;
4140: my @pages = &serverstatus_pages();
4141: my (%namedaccess,%machineaccess);
4142: foreach my $type (@pages) {
4143: $namedaccess{$type} = '';
4144: $machineaccess{$type}= '';
4145: }
4146: if (ref($settings) eq 'HASH') {
4147: foreach my $type (@pages) {
4148: if (exists($settings->{$type})) {
4149: if (ref($settings->{$type}) eq 'HASH') {
4150: foreach my $key (keys(%{$settings->{$type}})) {
4151: if ($key eq 'namedusers') {
4152: $namedaccess{$type} = $settings->{$type}->{$key};
4153: } elsif ($key eq 'machines') {
4154: $machineaccess{$type} = $settings->{$type}->{$key};
4155: }
4156: }
4157: }
4158: }
4159: }
4160: }
1.81 raeburn 4161: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4162: my $rownum = 0;
4163: my $css_class;
4164: foreach my $type (@pages) {
4165: $rownum ++;
4166: $css_class = $rownum%2?' class="LC_odd_row"':'';
4167: $datatable .= '<tr'.$css_class.'>'.
4168: '<td><span class="LC_nobreak">'.
4169: $titles->{$type}.'</span></td>'.
4170: '<td class="LC_left_item">'.
4171: '<input type="text" name="'.$type.'_namedusers" '.
4172: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4173: '<td class="LC_right_item">'.
4174: '<span class="LC_nobreak">'.
4175: '<input type="text" name="'.$type.'_machines" '.
4176: 'value="'.$machineaccess{$type}.'" size="10" />'.
4177: '</td></tr>'."\n";
4178: }
4179: $$rowtotal += $rownum;
4180: return $datatable;
4181: }
4182:
4183: sub serverstatus_pages {
4184: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4185: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4186: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4187: }
4188:
1.49 raeburn 4189: sub coursecategories_javascript {
4190: my ($settings) = @_;
1.57 raeburn 4191: my ($output,$jstext,$cathash);
1.49 raeburn 4192: if (ref($settings) eq 'HASH') {
1.57 raeburn 4193: $cathash = $settings->{'cats'};
4194: }
4195: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4196: my (@cats,@jsarray,%idx);
1.57 raeburn 4197: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4198: if (@jsarray > 0) {
4199: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4200: for (my $i=0; $i<@jsarray; $i++) {
4201: if (ref($jsarray[$i]) eq 'ARRAY') {
4202: my $catstr = join('","',@{$jsarray[$i]});
4203: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4204: }
4205: }
4206: }
4207: } else {
4208: $jstext = ' var categories = Array(1);'."\n".
4209: ' categories[0] = Array("instcode_pos");'."\n";
4210: }
1.120 raeburn 4211: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4212: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4213: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4214: $output = <<"ENDSCRIPT";
4215: <script type="text/javascript">
1.109 raeburn 4216: // <![CDATA[
1.49 raeburn 4217: function reorderCats(form,parent,item,idx) {
4218: var changedVal;
4219: $jstext
4220: var newpos = 'addcategory_pos';
4221: var current = new Array;
4222: if (parent == '') {
4223: var has_instcode = 0;
4224: var maxtop = categories[idx].length;
4225: for (var j=0; j<maxtop; j++) {
4226: if (categories[idx][j] == 'instcode::0') {
4227: has_instcode == 1;
4228: }
4229: }
4230: if (has_instcode == 0) {
4231: categories[idx][maxtop] = 'instcode_pos';
4232: }
4233: } else {
4234: newpos += '_'+parent;
4235: }
4236: var maxh = 1 + categories[idx].length;
4237: var current = new Array;
4238: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4239: if (item == newpos) {
4240: changedVal = newitemVal;
4241: } else {
4242: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4243: current[newitemVal] = newpos;
4244: }
4245: for (var i=0; i<categories[idx].length; i++) {
4246: var elementName = categories[idx][i];
4247: if (elementName != item) {
4248: if (form.elements[elementName]) {
4249: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4250: current[currVal] = elementName;
4251: }
4252: }
4253: }
4254: var oldVal;
4255: for (var j=0; j<maxh; j++) {
4256: if (current[j] == undefined) {
4257: oldVal = j;
4258: }
4259: }
4260: if (oldVal < changedVal) {
4261: for (var k=oldVal+1; k<=changedVal ; k++) {
4262: var elementName = current[k];
4263: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4264: }
4265: } else {
4266: for (var k=changedVal; k<oldVal; k++) {
4267: var elementName = current[k];
4268: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4269: }
4270: }
4271: return;
4272: }
1.120 raeburn 4273:
4274: function categoryCheck(form) {
4275: if (form.elements['addcategory_name'].value == 'instcode') {
4276: alert('$instcode_reserved\\n$choose_again');
4277: return false;
4278: }
4279: if (form.elements['addcategory_name'].value == 'communities') {
4280: alert('$communities_reserved\\n$choose_again');
4281: return false;
4282: }
4283: return true;
4284: }
4285:
1.109 raeburn 4286: // ]]>
1.49 raeburn 4287: </script>
4288:
4289: ENDSCRIPT
4290: return $output;
4291: }
4292:
1.48 raeburn 4293: sub initialize_categories {
4294: my ($itemcount) = @_;
1.120 raeburn 4295: my ($datatable,$css_class,$chgstr);
4296: my %default_names = (
4297: instcode => 'Official courses (with institutional codes)',
4298: communities => 'Communities',
4299: );
4300: my $select0 = ' selected="selected"';
4301: my $select1 = '';
4302: foreach my $default ('instcode','communities') {
4303: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4304: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4305: if ($default eq 'communities') {
4306: $select1 = $select0;
4307: $select0 = '';
4308: }
4309: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4310: .'<select name="'.$default.'_pos">'
4311: .'<option value="0"'.$select0.'>1</option>'
4312: .'<option value="1"'.$select1.'>2</option>'
4313: .'<option value="2">3</option></select> '
4314: .$default_names{$default}
4315: .'</span></td><td><span class="LC_nobreak">'
4316: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4317: .&mt('Display').'</label> <label>'
4318: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4319: .'</label></span></td></tr>';
1.120 raeburn 4320: $itemcount ++;
4321: }
1.48 raeburn 4322: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4323: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4324: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4325: .'<select name="addcategory_pos"'.$chgstr.'>'
4326: .'<option value="0">1</option>'
4327: .'<option value="1">2</option>'
4328: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4329: .&mt('Add category').'</td><td>'.&mt('Name:')
4330: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4331: return $datatable;
4332: }
4333:
4334: sub build_category_rows {
1.49 raeburn 4335: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4336: my ($text,$name,$item,$chgstr);
1.48 raeburn 4337: if (ref($cats) eq 'ARRAY') {
4338: my $maxdepth = scalar(@{$cats});
4339: if (ref($cats->[$depth]) eq 'HASH') {
4340: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4341: my $numchildren = @{$cats->[$depth]{$parent}};
4342: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4343: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4344: my ($idxnum,$parent_name,$parent_item);
4345: my $higher = $depth - 1;
4346: if ($higher == 0) {
4347: $parent_name = &escape($parent).'::'.$higher;
4348: } else {
4349: if (ref($path) eq 'ARRAY') {
4350: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4351: }
4352: }
4353: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4354: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4355: if ($j < $numchildren) {
1.48 raeburn 4356: $name = $cats->[$depth]{$parent}[$j];
4357: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4358: $idxnum = $idx->{$item};
4359: } else {
4360: $name = $parent_name;
4361: $item = $parent_item;
1.48 raeburn 4362: }
1.49 raeburn 4363: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4364: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4365: for (my $i=0; $i<=$numchildren; $i++) {
4366: my $vpos = $i+1;
4367: my $selstr;
4368: if ($j == $i) {
4369: $selstr = ' selected="selected" ';
4370: }
4371: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4372: }
4373: $text .= '</select> ';
4374: if ($j < $numchildren) {
4375: my $deeper = $depth+1;
4376: $text .= $name.' '
4377: .'<label><input type="checkbox" name="deletecategory" value="'
4378: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4379: if(ref($path) eq 'ARRAY') {
4380: push(@{$path},$name);
1.49 raeburn 4381: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4382: pop(@{$path});
4383: }
4384: } else {
1.59 bisitz 4385: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4386: if ($j == $numchildren) {
4387: $text .= $name;
4388: } else {
4389: $text .= $item;
4390: }
4391: $text .= '" value="" />';
4392: }
4393: $text .= '</td></tr>';
4394: }
4395: $text .= '</table></td>';
4396: } else {
4397: my $higher = $depth-1;
4398: if ($higher == 0) {
4399: $name = &escape($parent).'::'.$higher;
4400: } else {
4401: if (ref($path) eq 'ARRAY') {
4402: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4403: }
4404: }
4405: my $colspan;
4406: if ($parent ne 'instcode') {
4407: $colspan = $maxdepth - $depth - 1;
4408: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4409: }
4410: }
4411: }
4412: }
4413: return $text;
4414: }
4415:
1.33 raeburn 4416: sub modifiable_userdata_row {
1.63 raeburn 4417: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4418: my $rolename;
1.63 raeburn 4419: if ($context eq 'selfcreate') {
4420: if (ref($usertypes) eq 'HASH') {
4421: $rolename = $usertypes->{$role};
4422: } else {
4423: $rolename = $role;
4424: }
1.33 raeburn 4425: } else {
1.63 raeburn 4426: if ($role eq 'cr') {
4427: $rolename = &mt('Custom role');
4428: } else {
4429: $rolename = &Apache::lonnet::plaintext($role);
4430: }
1.33 raeburn 4431: }
4432: my @fields = ('lastname','firstname','middlename','generation',
4433: 'permanentemail','id');
4434: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4435: my $output;
4436: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4437: $output = '<tr '.$css_class.'>'.
4438: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4439: '<td class="LC_left_item" colspan="2"><table>';
4440: my $rem;
4441: my %checks;
4442: if (ref($settings) eq 'HASH') {
4443: if (ref($settings->{$context}) eq 'HASH') {
4444: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4445: foreach my $field (@fields) {
4446: if ($settings->{$context}->{$role}->{$field}) {
4447: $checks{$field} = ' checked="checked" ';
4448: }
4449: }
4450: }
4451: }
4452: }
4453: for (my $i=0; $i<@fields; $i++) {
4454: my $rem = $i%($numinrow);
4455: if ($rem == 0) {
4456: if ($i > 0) {
4457: $output .= '</tr>';
4458: }
4459: $output .= '<tr>';
4460: }
4461: my $check = ' ';
4462: if (exists($checks{$fields[$i]})) {
4463: $check = $checks{$fields[$i]}
4464: } else {
4465: if ($role eq 'st') {
4466: if (ref($settings) ne 'HASH') {
4467: $check = ' checked="checked" ';
4468: }
4469: }
4470: }
4471: $output .= '<td class="LC_left_item">'.
4472: '<span class="LC_nobreak"><label>'.
4473: '<input type="checkbox" name="canmodify_'.$role.'" '.
4474: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4475: '</label></span></td>';
4476: $rem = @fields%($numinrow);
4477: }
4478: my $colsleft = $numinrow - $rem;
4479: if ($colsleft > 1 ) {
4480: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4481: ' </td>';
4482: } elsif ($colsleft == 1) {
4483: $output .= '<td class="LC_left_item"> </td>';
4484: }
4485: $output .= '</tr></table></td></tr>';
4486: return $output;
4487: }
1.28 raeburn 4488:
1.93 raeburn 4489: sub insttypes_row {
4490: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4491: my %lt = &Apache::lonlocal::texthash (
4492: cansearch => 'Users allowed to search',
4493: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4494: lockablenames => 'User preference to lock name',
1.93 raeburn 4495: );
4496: my $showdom;
4497: if ($context eq 'cansearch') {
4498: $showdom = ' ('.$dom.')';
4499: }
1.160.6.5 raeburn 4500: my $class = 'LC_left_item';
4501: if ($context eq 'statustocreate') {
4502: $class = 'LC_right_item';
4503: }
1.25 raeburn 4504: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4505: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4506: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4507: my $rem;
4508: if (ref($types) eq 'ARRAY') {
4509: for (my $i=0; $i<@{$types}; $i++) {
4510: if (defined($usertypes->{$types->[$i]})) {
4511: my $rem = $i%($numinrow);
4512: if ($rem == 0) {
4513: if ($i > 0) {
4514: $output .= '</tr>';
4515: }
4516: $output .= '<tr>';
1.23 raeburn 4517: }
1.26 raeburn 4518: my $check = ' ';
1.99 raeburn 4519: if (ref($settings) eq 'HASH') {
4520: if (ref($settings->{$context}) eq 'ARRAY') {
4521: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4522: $check = ' checked="checked" ';
4523: }
4524: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4525: $check = ' checked="checked" ';
4526: }
1.23 raeburn 4527: }
1.26 raeburn 4528: $output .= '<td class="LC_left_item">'.
4529: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4530: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4531: 'value="'.$types->[$i].'"'.$check.'/>'.
4532: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4533: }
4534: }
1.26 raeburn 4535: $rem = @{$types}%($numinrow);
1.23 raeburn 4536: }
4537: my $colsleft = $numinrow - $rem;
1.131 raeburn 4538: if (($rem == 0) && (@{$types} > 0)) {
4539: $output .= '<tr>';
4540: }
1.23 raeburn 4541: if ($colsleft > 1) {
1.25 raeburn 4542: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4543: } else {
1.25 raeburn 4544: $output .= '<td class="LC_left_item">';
1.23 raeburn 4545: }
4546: my $defcheck = ' ';
1.99 raeburn 4547: if (ref($settings) eq 'HASH') {
4548: if (ref($settings->{$context}) eq 'ARRAY') {
4549: if (grep(/^default$/,@{$settings->{$context}})) {
4550: $defcheck = ' checked="checked" ';
4551: }
4552: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4553: $defcheck = ' checked="checked" ';
4554: }
1.23 raeburn 4555: }
1.25 raeburn 4556: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4557: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4558: 'value="default"'.$defcheck.'/>'.
4559: $othertitle.'</label></span></td>'.
4560: '</tr></table></td></tr>';
4561: return $output;
1.23 raeburn 4562: }
4563:
4564: sub sorted_searchtitles {
4565: my %searchtitles = &Apache::lonlocal::texthash(
4566: 'uname' => 'username',
4567: 'lastname' => 'last name',
4568: 'lastfirst' => 'last name, first name',
4569: );
4570: my @titleorder = ('uname','lastname','lastfirst');
4571: return (\%searchtitles,\@titleorder);
4572: }
4573:
1.25 raeburn 4574: sub sorted_searchtypes {
4575: my %srchtypes_desc = (
4576: exact => 'is exact match',
4577: contains => 'contains ..',
4578: begins => 'begins with ..',
4579: );
4580: my @srchtypeorder = ('exact','begins','contains');
4581: return (\%srchtypes_desc,\@srchtypeorder);
4582: }
4583:
1.3 raeburn 4584: sub usertype_update_row {
4585: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4586: my $datatable;
4587: my $numinrow = 4;
4588: foreach my $type (@{$types}) {
4589: if (defined($usertypes->{$type})) {
4590: $$rownums ++;
4591: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4592: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4593: '</td><td class="LC_left_item"><table>';
4594: for (my $i=0; $i<@{$fields}; $i++) {
4595: my $rem = $i%($numinrow);
4596: if ($rem == 0) {
4597: if ($i > 0) {
4598: $datatable .= '</tr>';
4599: }
4600: $datatable .= '<tr>';
4601: }
4602: my $check = ' ';
1.39 raeburn 4603: if (ref($settings) eq 'HASH') {
4604: if (ref($settings->{'fields'}) eq 'HASH') {
4605: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4606: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4607: $check = ' checked="checked" ';
4608: }
1.3 raeburn 4609: }
4610: }
4611: }
4612:
4613: if ($i == @{$fields}-1) {
4614: my $colsleft = $numinrow - $rem;
4615: if ($colsleft > 1) {
4616: $datatable .= '<td colspan="'.$colsleft.'">';
4617: } else {
4618: $datatable .= '<td>';
4619: }
4620: } else {
4621: $datatable .= '<td>';
4622: }
1.8 raeburn 4623: $datatable .= '<span class="LC_nobreak"><label>'.
4624: '<input type="checkbox" name="updateable_'.$type.
4625: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4626: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4627: }
4628: $datatable .= '</tr></table></td></tr>';
4629: }
4630: }
4631: return $datatable;
1.1 raeburn 4632: }
4633:
4634: sub modify_login {
1.9 raeburn 4635: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4636: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4637: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4638: %title = ( coursecatalog => 'Display course catalog',
4639: adminmail => 'Display administrator E-mail address',
1.160.6.14! raeburn 4640: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4641: newuser => 'Link for visitors to create a user account',
4642: loginheader => 'Log-in box header');
4643: @offon = ('off','on');
1.112 raeburn 4644: if (ref($domconfig{login}) eq 'HASH') {
4645: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4646: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4647: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4648: }
4649: }
4650: }
1.9 raeburn 4651: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4652: \%domconfig,\%loginhash);
1.160.6.14! raeburn 4653: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4654: foreach my $item (@toggles) {
4655: $loginhash{login}{$item} = $env{'form.'.$item};
4656: }
1.41 raeburn 4657: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4658: if (ref($colchanges{'login'}) eq 'HASH') {
4659: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4660: \%loginhash);
4661: }
1.110 raeburn 4662:
1.149 raeburn 4663: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4664: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4665: if (keys(%servers) > 1) {
4666: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4667: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4668: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4669: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4670: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4671: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4672: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4673: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4674: $changes{'loginvia'}{$lonhost} = 1;
4675: } else {
4676: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4677: $changes{'loginvia'}{$lonhost} = 1;
4678: }
4679: } else {
4680: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4681: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4682: $changes{'loginvia'}{$lonhost} = 1;
4683: }
4684: }
4685: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4686: foreach my $item (@loginvia_attribs) {
4687: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4688: }
4689: } else {
4690: foreach my $item (@loginvia_attribs) {
4691: my $new = $env{'form.'.$lonhost.'_'.$item};
4692: if (($item eq 'serverpath') && ($new eq 'custom')) {
4693: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4694: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4695: $new = '/';
4696: }
4697: }
4698: if (($item eq 'custompath') &&
4699: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4700: $new = '';
4701: }
4702: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4703: $changes{'loginvia'}{$lonhost} = 1;
4704: }
4705: if ($item eq 'exempt') {
4706: $new =~ s/^\s+//;
4707: $new =~ s/\s+$//;
4708: my @poss_ips = split(/\s*[,:]\s*/,$new);
4709: my @okips;
4710: foreach my $ip (@poss_ips) {
4711: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4712: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4713: push(@okips,$ip);
4714: }
4715: }
4716: }
4717: if (@okips > 0) {
4718: $new = join(',',@okips);
4719: } else {
4720: $new = '';
4721: }
4722: }
4723: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4724: }
4725: }
1.112 raeburn 4726: } else {
1.128 raeburn 4727: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4728: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4729: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4730: foreach my $item (@loginvia_attribs) {
4731: my $new = $env{'form.'.$lonhost.'_'.$item};
4732: if (($item eq 'serverpath') && ($new eq 'custom')) {
4733: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4734: $new = '/';
4735: }
4736: }
4737: if (($item eq 'custompath') &&
4738: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4739: $new = '';
4740: }
4741: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4742: }
1.110 raeburn 4743: }
4744: }
4745: }
4746: }
1.119 raeburn 4747:
1.160.6.5 raeburn 4748: my $servadm = $r->dir_config('lonAdmEMail');
4749: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4750: if (ref($domconfig{'login'}) eq 'HASH') {
4751: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4752: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4753: if ($lang eq 'nolang') {
4754: push(@currlangs,$lang);
4755: } elsif (defined($langchoices{$lang})) {
4756: push(@currlangs,$lang);
4757: } else {
4758: next;
4759: }
4760: }
4761: }
4762: }
4763: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4764: if (@currlangs > 0) {
4765: foreach my $lang (@currlangs) {
4766: if (grep(/^\Q$lang\E$/,@delurls)) {
4767: $changes{'helpurl'}{$lang} = 1;
4768: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4769: $changes{'helpurl'}{$lang} = 1;
4770: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4771: push(@newlangs,$lang);
4772: } else {
4773: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4774: }
4775: }
4776: }
4777: unless (grep(/^nolang$/,@currlangs)) {
4778: if ($env{'form.loginhelpurl_nolang.filename'}) {
4779: $changes{'helpurl'}{'nolang'} = 1;
4780: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4781: push(@newlangs,'nolang');
4782: }
4783: }
4784: if ($env{'form.loginhelpurl_add_lang'}) {
4785: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4786: ($env{'form.loginhelpurl_add_file.filename'})) {
4787: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4788: $addedfile = $env{'form.loginhelpurl_add_lang'};
4789: }
4790: }
4791: if ((@newlangs > 0) || ($addedfile)) {
4792: my $error;
4793: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4794: if ($configuserok eq 'ok') {
4795: if ($switchserver) {
4796: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4797: } elsif ($author_ok eq 'ok') {
4798: my @allnew = @newlangs;
4799: if ($addedfile ne '') {
4800: push(@allnew,$addedfile);
4801: }
4802: foreach my $lang (@allnew) {
4803: my $formelem = 'loginhelpurl_'.$lang;
4804: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4805: $formelem = 'loginhelpurl_add_file';
4806: }
4807: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4808: "help/$lang",'','',$newfile{$lang});
4809: if ($result eq 'ok') {
4810: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4811: $changes{'helpurl'}{$lang} = 1;
4812: } else {
4813: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4814: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4815: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4816: (!grep(/^\Q$lang\E$/,@delurls))) {
4817:
4818: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4819: }
4820: }
4821: }
4822: } else {
4823: $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);
4824: }
4825: } else {
4826: $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);
4827: }
4828: if ($error) {
4829: &Apache::lonnet::logthis($error);
4830: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4831: }
4832: }
4833: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4834:
4835: my $defaulthelpfile = '/adm/loginproblems.html';
4836: my $defaulttext = &mt('Default in use');
4837:
1.1 raeburn 4838: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4839: $dom);
4840: if ($putresult eq 'ok') {
1.160.6.14! raeburn 4841: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4842: my %defaultchecked = (
4843: 'coursecatalog' => 'on',
1.160.6.14! raeburn 4844: 'helpdesk' => 'on',
1.42 raeburn 4845: 'adminmail' => 'off',
1.43 raeburn 4846: 'newuser' => 'off',
1.42 raeburn 4847: );
1.55 raeburn 4848: if (ref($domconfig{'login'}) eq 'HASH') {
4849: foreach my $item (@toggles) {
4850: if ($defaultchecked{$item} eq 'on') {
4851: if (($domconfig{'login'}{$item} eq '0') &&
4852: ($env{'form.'.$item} eq '1')) {
4853: $changes{$item} = 1;
4854: } elsif (($domconfig{'login'}{$item} eq '' ||
4855: $domconfig{'login'}{$item} eq '1') &&
4856: ($env{'form.'.$item} eq '0')) {
4857: $changes{$item} = 1;
4858: }
4859: } elsif ($defaultchecked{$item} eq 'off') {
4860: if (($domconfig{'login'}{$item} eq '1') &&
4861: ($env{'form.'.$item} eq '0')) {
4862: $changes{$item} = 1;
4863: } elsif (($domconfig{'login'}{$item} eq '' ||
4864: $domconfig{'login'}{$item} eq '0') &&
4865: ($env{'form.'.$item} eq '1')) {
4866: $changes{$item} = 1;
4867: }
1.42 raeburn 4868: }
4869: }
1.41 raeburn 4870: }
1.6 raeburn 4871: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4872: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4873: $resulttext = &mt('Changes made:').'<ul>';
4874: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4875: if ($item eq 'loginvia') {
1.112 raeburn 4876: if (ref($changes{$item}) eq 'HASH') {
4877: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4878: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4879: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4880: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4881: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4882: $protocol = 'http' if ($protocol ne 'https');
4883: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4884:
4885: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4886: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4887: } else {
4888: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4889: }
4890: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4891: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4892: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4893: }
4894: $resulttext .= '</li>';
4895: } else {
4896: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4897: }
1.112 raeburn 4898: } else {
1.128 raeburn 4899: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4900: }
4901: }
1.128 raeburn 4902: $resulttext .= '</ul></li>';
1.112 raeburn 4903: }
1.160.6.5 raeburn 4904: } elsif ($item eq 'helpurl') {
4905: if (ref($changes{$item}) eq 'HASH') {
4906: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4907: if (grep(/^\Q$lang\E$/,@delurls)) {
4908: my ($chg,$link);
4909: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4910: if ($lang eq 'nolang') {
4911: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4912: } else {
4913: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4914: }
4915: $resulttext .= '<li>'.$chg.'</li>';
4916: } else {
4917: my $chg;
4918: if ($lang eq 'nolang') {
4919: $chg = &mt('custom log-in help file for no preferred language');
4920: } else {
4921: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4922: }
4923: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4924: $loginhash{'login'}{'helpurl'}{$lang}.
4925: '?inhibitmenu=yes',$chg,600,500).
4926: '</li>';
4927: }
4928: }
4929: }
4930: } elsif ($item eq 'captcha') {
4931: if (ref($loginhash{'login'}) eq 'HASH') {
4932: my $chgtxt;
4933: if ($loginhash{'login'}{$item} eq 'notused') {
4934: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4935: } else {
4936: my %captchas = &captcha_phrases();
4937: if ($captchas{$loginhash{'login'}{$item}}) {
4938: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4939: } else {
4940: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4941: }
4942: }
4943: $resulttext .= '<li>'.$chgtxt.'</li>';
4944: }
4945: } elsif ($item eq 'recaptchakeys') {
4946: if (ref($loginhash{'login'}) eq 'HASH') {
4947: my ($privkey,$pubkey);
4948: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4949: $pubkey = $loginhash{'login'}{$item}{'public'};
4950: $privkey = $loginhash{'login'}{$item}{'private'};
4951: }
4952: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4953: if (!$pubkey) {
4954: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4955: } else {
4956: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4957: }
4958: if (!$privkey) {
4959: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4960: } else {
4961: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4962: }
4963: $chgtxt .= '</ul>';
4964: $resulttext .= '<li>'.$chgtxt.'</li>';
4965: }
1.41 raeburn 4966: } else {
4967: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4968: }
1.1 raeburn 4969: }
1.6 raeburn 4970: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4971: } else {
4972: $resulttext = &mt('No changes made to log-in page settings');
4973: }
4974: } else {
1.11 albertel 4975: $resulttext = '<span class="LC_error">'.
4976: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4977: }
1.6 raeburn 4978: if ($errors) {
1.9 raeburn 4979: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4980: $errors.'</ul>';
4981: }
4982: return $resulttext;
4983: }
4984:
4985: sub color_font_choices {
4986: my %choices =
4987: &Apache::lonlocal::texthash (
4988: img => "Header",
4989: bgs => "Background colors",
4990: links => "Link colors",
1.55 raeburn 4991: images => "Images",
1.6 raeburn 4992: font => "Font color",
1.97 tempelho 4993: fontmenu => "Font Menu",
1.76 raeburn 4994: pgbg => "Page",
1.6 raeburn 4995: tabbg => "Header",
4996: sidebg => "Border",
4997: link => "Link",
4998: alink => "Active link",
4999: vlink => "Visited link",
5000: );
5001: return %choices;
5002: }
5003:
5004: sub modify_rolecolors {
1.9 raeburn 5005: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5006: my ($resulttext,%rolehash);
5007: $rolehash{'rolecolors'} = {};
1.55 raeburn 5008: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5009: if ($domconfig{'rolecolors'} eq '') {
5010: $domconfig{'rolecolors'} = {};
5011: }
5012: }
1.9 raeburn 5013: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5014: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5015: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5016: $dom);
5017: if ($putresult eq 'ok') {
5018: if (keys(%changes) > 0) {
1.41 raeburn 5019: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5020: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5021: $rolehash{'rolecolors'});
5022: } else {
5023: $resulttext = &mt('No changes made to default color schemes');
5024: }
5025: } else {
1.11 albertel 5026: $resulttext = '<span class="LC_error">'.
5027: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5028: }
5029: if ($errors) {
5030: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5031: $errors.'</ul>';
5032: }
5033: return $resulttext;
5034: }
5035:
5036: sub modify_colors {
1.9 raeburn 5037: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5038: my (%changes,%choices);
1.51 raeburn 5039: my @bgs;
1.6 raeburn 5040: my @links = ('link','alink','vlink');
1.41 raeburn 5041: my @logintext;
1.6 raeburn 5042: my @images;
5043: my $servadm = $r->dir_config('lonAdmEMail');
5044: my $errors;
5045: foreach my $role (@{$roles}) {
5046: if ($role eq 'login') {
1.12 raeburn 5047: %choices = &login_choices();
1.41 raeburn 5048: @logintext = ('textcol','bgcol');
1.12 raeburn 5049: } else {
5050: %choices = &color_font_choices();
1.107 raeburn 5051: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5052: }
5053: if ($role eq 'login') {
1.41 raeburn 5054: @images = ('img','logo','domlogo','login');
1.51 raeburn 5055: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5056: } else {
5057: @images = ('img');
1.51 raeburn 5058: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5059: }
5060: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5061: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5062: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5063: }
1.46 raeburn 5064: my ($configuserok,$author_ok,$switchserver) =
5065: &config_check($dom,$confname,$servadm);
1.9 raeburn 5066: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5067: if (ref($domconfig->{$role}) ne 'HASH') {
5068: $domconfig->{$role} = {};
5069: }
1.8 raeburn 5070: foreach my $img (@images) {
1.70 raeburn 5071: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5072: if (defined($env{'form.login_showlogo_'.$img})) {
5073: $confhash->{$role}{'showlogo'}{$img} = 1;
5074: } else {
5075: $confhash->{$role}{'showlogo'}{$img} = 0;
5076: }
5077: }
1.18 albertel 5078: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5079: && !defined($domconfig->{$role}{$img})
5080: && !$env{'form.'.$role.'_del_'.$img}
5081: && $env{'form.'.$role.'_import_'.$img}) {
5082: # import the old configured image from the .tab setting
5083: # if they haven't provided a new one
5084: $domconfig->{$role}{$img} =
5085: $env{'form.'.$role.'_import_'.$img};
5086: }
1.6 raeburn 5087: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5088: my $error;
1.6 raeburn 5089: if ($configuserok eq 'ok') {
1.9 raeburn 5090: if ($switchserver) {
1.12 raeburn 5091: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5092: } else {
5093: if ($author_ok eq 'ok') {
5094: my ($result,$logourl) =
5095: &publishlogo($r,'upload',$role.'_'.$img,
5096: $dom,$confname,$img,$width,$height);
5097: if ($result eq 'ok') {
5098: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5099: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5100: } else {
1.12 raeburn 5101: $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 5102: }
5103: } else {
1.46 raeburn 5104: $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 5105: }
5106: }
5107: } else {
1.46 raeburn 5108: $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 5109: }
5110: if ($error) {
1.8 raeburn 5111: &Apache::lonnet::logthis($error);
1.11 albertel 5112: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5113: }
5114: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5115: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5116: my $error;
5117: if ($configuserok eq 'ok') {
5118: # is confname an author?
5119: if ($switchserver eq '') {
5120: if ($author_ok eq 'ok') {
5121: my ($result,$logourl) =
5122: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5123: $dom,$confname,$img,$width,$height);
5124: if ($result eq 'ok') {
5125: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5126: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5127: }
5128: }
5129: }
5130: }
1.6 raeburn 5131: }
5132: }
5133: }
5134: if (ref($domconfig) eq 'HASH') {
5135: if (ref($domconfig->{$role}) eq 'HASH') {
5136: foreach my $img (@images) {
5137: if ($domconfig->{$role}{$img} ne '') {
5138: if ($env{'form.'.$role.'_del_'.$img}) {
5139: $confhash->{$role}{$img} = '';
1.12 raeburn 5140: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5141: } else {
1.9 raeburn 5142: if ($confhash->{$role}{$img} eq '') {
5143: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5144: }
1.6 raeburn 5145: }
5146: } else {
5147: if ($env{'form.'.$role.'_del_'.$img}) {
5148: $confhash->{$role}{$img} = '';
1.12 raeburn 5149: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5150: }
5151: }
1.70 raeburn 5152: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5153: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5154: if ($confhash->{$role}{'showlogo'}{$img} ne
5155: $domconfig->{$role}{'showlogo'}{$img}) {
5156: $changes{$role}{'showlogo'}{$img} = 1;
5157: }
5158: } else {
5159: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5160: $changes{$role}{'showlogo'}{$img} = 1;
5161: }
5162: }
5163: }
5164: }
1.6 raeburn 5165: if ($domconfig->{$role}{'font'} ne '') {
5166: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5167: $changes{$role}{'font'} = 1;
5168: }
5169: } else {
5170: if ($confhash->{$role}{'font'}) {
5171: $changes{$role}{'font'} = 1;
5172: }
5173: }
1.107 raeburn 5174: if ($role ne 'login') {
5175: if ($domconfig->{$role}{'fontmenu'} ne '') {
5176: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5177: $changes{$role}{'fontmenu'} = 1;
5178: }
5179: } else {
5180: if ($confhash->{$role}{'fontmenu'}) {
5181: $changes{$role}{'fontmenu'} = 1;
5182: }
1.97 tempelho 5183: }
5184: }
1.6 raeburn 5185: foreach my $item (@bgs) {
5186: if ($domconfig->{$role}{$item} ne '') {
5187: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5188: $changes{$role}{'bgs'}{$item} = 1;
5189: }
5190: } else {
5191: if ($confhash->{$role}{$item}) {
5192: $changes{$role}{'bgs'}{$item} = 1;
5193: }
5194: }
5195: }
5196: foreach my $item (@links) {
5197: if ($domconfig->{$role}{$item} ne '') {
5198: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5199: $changes{$role}{'links'}{$item} = 1;
5200: }
5201: } else {
5202: if ($confhash->{$role}{$item}) {
5203: $changes{$role}{'links'}{$item} = 1;
5204: }
5205: }
5206: }
1.41 raeburn 5207: foreach my $item (@logintext) {
5208: if ($domconfig->{$role}{$item} ne '') {
5209: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5210: $changes{$role}{'logintext'}{$item} = 1;
5211: }
5212: } else {
5213: if ($confhash->{$role}{$item}) {
5214: $changes{$role}{'logintext'}{$item} = 1;
5215: }
5216: }
5217: }
1.6 raeburn 5218: } else {
5219: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5220: \@logintext,$confhash,\%changes);
1.6 raeburn 5221: }
5222: } else {
5223: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5224: \@logintext,$confhash,\%changes);
1.6 raeburn 5225: }
5226: }
5227: return ($errors,%changes);
5228: }
5229:
1.46 raeburn 5230: sub config_check {
5231: my ($dom,$confname,$servadm) = @_;
5232: my ($configuserok,$author_ok,$switchserver,%currroles);
5233: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5234: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5235: $confname,$servadm);
5236: if ($configuserok eq 'ok') {
5237: $switchserver = &check_switchserver($dom,$confname);
5238: if ($switchserver eq '') {
5239: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5240: }
5241: }
5242: return ($configuserok,$author_ok,$switchserver);
5243: }
5244:
1.6 raeburn 5245: sub default_change_checker {
1.41 raeburn 5246: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5247: foreach my $item (@{$links}) {
5248: if ($confhash->{$role}{$item}) {
5249: $changes->{$role}{'links'}{$item} = 1;
5250: }
5251: }
5252: foreach my $item (@{$bgs}) {
5253: if ($confhash->{$role}{$item}) {
5254: $changes->{$role}{'bgs'}{$item} = 1;
5255: }
5256: }
1.41 raeburn 5257: foreach my $item (@{$logintext}) {
5258: if ($confhash->{$role}{$item}) {
5259: $changes->{$role}{'logintext'}{$item} = 1;
5260: }
5261: }
1.6 raeburn 5262: foreach my $img (@{$images}) {
5263: if ($env{'form.'.$role.'_del_'.$img}) {
5264: $confhash->{$role}{$img} = '';
1.12 raeburn 5265: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5266: }
1.70 raeburn 5267: if ($role eq 'login') {
5268: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5269: $changes->{$role}{'showlogo'}{$img} = 1;
5270: }
5271: }
1.6 raeburn 5272: }
5273: if ($confhash->{$role}{'font'}) {
5274: $changes->{$role}{'font'} = 1;
5275: }
1.48 raeburn 5276: }
1.6 raeburn 5277:
5278: sub display_colorchgs {
5279: my ($dom,$changes,$roles,$confhash) = @_;
5280: my (%choices,$resulttext);
5281: if (!grep(/^login$/,@{$roles})) {
5282: $resulttext = &mt('Changes made:').'<br />';
5283: }
5284: foreach my $role (@{$roles}) {
5285: if ($role eq 'login') {
5286: %choices = &login_choices();
5287: } else {
5288: %choices = &color_font_choices();
5289: }
5290: if (ref($changes->{$role}) eq 'HASH') {
5291: if ($role ne 'login') {
5292: $resulttext .= '<h4>'.&mt($role).'</h4>';
5293: }
5294: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5295: if ($role ne 'login') {
5296: $resulttext .= '<ul>';
5297: }
5298: if (ref($changes->{$role}{$key}) eq 'HASH') {
5299: if ($role ne 'login') {
5300: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5301: }
5302: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5303: if (($role eq 'login') && ($key eq 'showlogo')) {
5304: if ($confhash->{$role}{$key}{$item}) {
5305: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5306: } else {
5307: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5308: }
5309: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5310: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5311: } else {
1.12 raeburn 5312: my $newitem = $confhash->{$role}{$item};
5313: if ($key eq 'images') {
5314: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5315: }
5316: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5317: }
5318: }
5319: if ($role ne 'login') {
5320: $resulttext .= '</ul></li>';
5321: }
5322: } else {
5323: if ($confhash->{$role}{$key} eq '') {
5324: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5325: } else {
5326: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5327: }
5328: }
5329: if ($role ne 'login') {
5330: $resulttext .= '</ul>';
5331: }
5332: }
5333: }
5334: }
1.3 raeburn 5335: return $resulttext;
1.1 raeburn 5336: }
5337:
1.9 raeburn 5338: sub thumb_dimensions {
5339: return ('200','50');
5340: }
5341:
1.16 raeburn 5342: sub check_dimensions {
5343: my ($inputfile) = @_;
5344: my ($fullwidth,$fullheight);
5345: if ($inputfile =~ m|^[/\w.\-]+$|) {
5346: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5347: my $imageinfo = <PIPE>;
5348: if (!close(PIPE)) {
5349: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5350: }
5351: chomp($imageinfo);
5352: my ($fullsize) =
1.21 raeburn 5353: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5354: if ($fullsize) {
5355: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5356: }
5357: }
5358: }
5359: return ($fullwidth,$fullheight);
5360: }
5361:
1.9 raeburn 5362: sub check_configuser {
5363: my ($uhome,$dom,$confname,$servadm) = @_;
5364: my ($configuserok,%currroles);
5365: if ($uhome eq 'no_host') {
5366: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5367: my $configpass = &LONCAPA::Enrollment::create_password();
5368: $configuserok =
5369: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5370: $configpass,'','','','','',undef,$servadm);
5371: } else {
5372: $configuserok = 'ok';
5373: %currroles =
5374: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5375: }
5376: return ($configuserok,%currroles);
5377: }
5378:
5379: sub check_authorstatus {
5380: my ($dom,$confname,%currroles) = @_;
5381: my $author_ok;
1.40 raeburn 5382: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5383: my $start = time;
5384: my $end = 0;
5385: $author_ok =
5386: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5387: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5388: } else {
5389: $author_ok = 'ok';
5390: }
5391: return $author_ok;
5392: }
5393:
5394: sub publishlogo {
1.46 raeburn 5395: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5396: my ($output,$fname,$logourl);
5397: if ($action eq 'upload') {
5398: $fname=$env{'form.'.$formname.'.filename'};
5399: chop($env{'form.'.$formname});
5400: } else {
5401: ($fname) = ($formname =~ /([^\/]+)$/);
5402: }
1.46 raeburn 5403: if ($savefileas ne '') {
5404: $fname = $savefileas;
5405: }
1.9 raeburn 5406: $fname=&Apache::lonnet::clean_filename($fname);
5407: # See if there is anything left
5408: unless ($fname) { return ('error: no uploaded file'); }
5409: $fname="$subdir/$fname";
1.160.6.5 raeburn 5410: my $docroot=$r->dir_config('lonDocRoot');
5411: my $filepath="$docroot/priv";
5412: my $relpath = "$dom/$confname";
1.9 raeburn 5413: my ($fnamepath,$file,$fetchthumb);
5414: $file=$fname;
5415: if ($fname=~m|/|) {
5416: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5417: }
1.160.6.5 raeburn 5418: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5419: my $count;
1.160.6.5 raeburn 5420: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5421: $filepath.="/$parts[$count]";
5422: if ((-e $filepath)!=1) {
5423: mkdir($filepath,02770);
5424: }
5425: }
5426: # Check for bad extension and disallow upload
5427: if ($file=~/\.(\w+)$/ &&
5428: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5429: $output =
5430: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5431: } elsif ($file=~/\.(\w+)$/ &&
5432: !defined(&Apache::loncommon::fileembstyle($1))) {
5433: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5434: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5435: $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 5436: } elsif (-d "$filepath/$file") {
5437: $output = &mt('File name is a directory name - rename the file and re-upload');
5438: } else {
5439: my $source = $filepath.'/'.$file;
5440: my $logfile;
5441: if (!open($logfile,">>$source".'.log')) {
5442: return (&mt('No write permission to Construction Space'));
5443: }
5444: print $logfile
5445: "\n================= Publish ".localtime()." ================\n".
5446: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5447: # Save the file
5448: if (!open(FH,'>'.$source)) {
5449: &Apache::lonnet::logthis('Failed to create '.$source);
5450: return (&mt('Failed to create file'));
5451: }
5452: if ($action eq 'upload') {
5453: if (!print FH ($env{'form.'.$formname})) {
5454: &Apache::lonnet::logthis('Failed to write to '.$source);
5455: return (&mt('Failed to write file'));
5456: }
5457: } else {
5458: my $original = &Apache::lonnet::filelocation('',$formname);
5459: if(!copy($original,$source)) {
5460: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5461: return (&mt('Failed to write file'));
5462: }
5463: }
5464: close(FH);
5465: chmod(0660, $source); # Permissions to rw-rw---.
5466:
5467: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5468: my $copyfile=$targetdir.'/'.$file;
5469:
5470: my @parts=split(/\//,$targetdir);
5471: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5472: for (my $count=5;$count<=$#parts;$count++) {
5473: $path.="/$parts[$count]";
5474: if (!-e $path) {
5475: print $logfile "\nCreating directory ".$path;
5476: mkdir($path,02770);
5477: }
5478: }
5479: my $versionresult;
5480: if (-e $copyfile) {
5481: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5482: } else {
5483: $versionresult = 'ok';
5484: }
5485: if ($versionresult eq 'ok') {
5486: if (copy($source,$copyfile)) {
5487: print $logfile "\nCopied original source to ".$copyfile."\n";
5488: $output = 'ok';
5489: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5490: push(@{$modified_urls},[$copyfile,$source]);
5491: my $metaoutput =
5492: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5493: unless ($registered_cleanup) {
5494: my $handlers = $r->get_handlers('PerlCleanupHandler');
5495: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5496: $registered_cleanup=1;
5497: }
1.9 raeburn 5498: } else {
5499: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5500: $output = &mt('Failed to copy file to RES space').", $!";
5501: }
5502: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5503: my $inputfile = $filepath.'/'.$file;
5504: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5505: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5506: if ($fullwidth ne '' && $fullheight ne '') {
5507: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5508: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5509: system("convert -sample $thumbsize $inputfile $outfile");
5510: chmod(0660, $filepath.'/tn-'.$file);
5511: if (-e $outfile) {
5512: my $copyfile=$targetdir.'/tn-'.$file;
5513: if (copy($outfile,$copyfile)) {
5514: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5515: my $thumb_metaoutput =
5516: &write_metadata($dom,$confname,$formname,
5517: $targetdir,'tn-'.$file,$logfile);
5518: push(@{$modified_urls},[$copyfile,$outfile]);
5519: unless ($registered_cleanup) {
5520: my $handlers = $r->get_handlers('PerlCleanupHandler');
5521: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5522: $registered_cleanup=1;
5523: }
1.16 raeburn 5524: } else {
5525: print $logfile "\nUnable to write ".$copyfile.
5526: ':'.$!."\n";
5527: }
5528: }
1.9 raeburn 5529: }
5530: }
5531: }
5532: } else {
5533: $output = $versionresult;
5534: }
5535: }
5536: return ($output,$logourl);
5537: }
5538:
5539: sub logo_versioning {
5540: my ($targetdir,$file,$logfile) = @_;
5541: my $target = $targetdir.'/'.$file;
5542: my ($maxversion,$fn,$extn,$output);
5543: $maxversion = 0;
5544: if ($file =~ /^(.+)\.(\w+)$/) {
5545: $fn=$1;
5546: $extn=$2;
5547: }
5548: opendir(DIR,$targetdir);
5549: while (my $filename=readdir(DIR)) {
5550: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5551: $maxversion=($1>$maxversion)?$1:$maxversion;
5552: }
5553: }
5554: $maxversion++;
5555: print $logfile "\nCreating old version ".$maxversion."\n";
5556: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5557: if (copy($target,$copyfile)) {
5558: print $logfile "Copied old target to ".$copyfile."\n";
5559: $copyfile=$copyfile.'.meta';
5560: if (copy($target.'.meta',$copyfile)) {
5561: print $logfile "Copied old target metadata to ".$copyfile."\n";
5562: $output = 'ok';
5563: } else {
5564: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5565: $output = &mt('Failed to copy old meta').", $!, ";
5566: }
5567: } else {
5568: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5569: $output = &mt('Failed to copy old target').", $!, ";
5570: }
5571: return $output;
5572: }
5573:
5574: sub write_metadata {
5575: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5576: my (%metadatafields,%metadatakeys,$output);
5577: $metadatafields{'title'}=$formname;
5578: $metadatafields{'creationdate'}=time;
5579: $metadatafields{'lastrevisiondate'}=time;
5580: $metadatafields{'copyright'}='public';
5581: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5582: $env{'user.domain'};
5583: $metadatafields{'authorspace'}=$confname.':'.$dom;
5584: $metadatafields{'domain'}=$dom;
5585: {
5586: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5587: my $mfh;
1.155 raeburn 5588: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5589: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5590: unless ($_=~/\./) {
5591: my $unikey=$_;
5592: $unikey=~/^([A-Za-z]+)/;
5593: my $tag=$1;
5594: $tag=~tr/A-Z/a-z/;
5595: print $mfh "\n\<$tag";
5596: foreach (split(/\,/,$metadatakeys{$unikey})) {
5597: my $value=$metadatafields{$unikey.'.'.$_};
5598: $value=~s/\"/\'\'/g;
5599: print $mfh ' '.$_.'="'.$value.'"';
5600: }
5601: print $mfh '>'.
5602: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5603: .'</'.$tag.'>';
5604: }
5605: }
5606: $output = 'ok';
5607: print $logfile "\nWrote metadata";
5608: close($mfh);
5609: } else {
5610: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5611: $output = &mt('Could not write metadata');
5612: }
5613: }
1.155 raeburn 5614: return $output;
5615: }
5616:
5617: sub notifysubscribed {
5618: foreach my $targetsource (@{$modified_urls}){
5619: next unless (ref($targetsource) eq 'ARRAY');
5620: my ($target,$source)=@{$targetsource};
5621: if ($source ne '') {
5622: if (open(my $logfh,'>>'.$source.'.log')) {
5623: print $logfh "\nCleanup phase: Notifications\n";
5624: my @subscribed=&subscribed_hosts($target);
5625: foreach my $subhost (@subscribed) {
5626: print $logfh "\nNotifying host ".$subhost.':';
5627: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5628: print $logfh $reply;
5629: }
5630: my @subscribedmeta=&subscribed_hosts("$target.meta");
5631: foreach my $subhost (@subscribedmeta) {
5632: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5633: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5634: $subhost);
5635: print $logfh $reply;
5636: }
5637: print $logfh "\n============ Done ============\n";
1.160 raeburn 5638: close($logfh);
1.155 raeburn 5639: }
5640: }
5641: }
5642: return OK;
5643: }
5644:
5645: sub subscribed_hosts {
5646: my ($target) = @_;
5647: my @subscribed;
5648: if (open(my $fh,"<$target.subscription")) {
5649: while (my $subline=<$fh>) {
5650: if ($subline =~ /^($match_lonid):/) {
5651: my $host = $1;
5652: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5653: unless (grep(/^\Q$host\E$/,@subscribed)) {
5654: push(@subscribed,$host);
5655: }
5656: }
5657: }
5658: }
5659: }
5660: return @subscribed;
1.9 raeburn 5661: }
5662:
5663: sub check_switchserver {
5664: my ($dom,$confname) = @_;
5665: my ($allowed,$switchserver);
5666: my $home = &Apache::lonnet::homeserver($confname,$dom);
5667: if ($home eq 'no_host') {
5668: $home = &Apache::lonnet::domain($dom,'primary');
5669: }
5670: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5671: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5672: if (!$allowed) {
1.160.6.11 raeburn 5673: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5674: }
5675: return $switchserver;
5676: }
5677:
1.1 raeburn 5678: sub modify_quotas {
1.86 raeburn 5679: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5680: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5681: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5682: if ($action eq 'quotas') {
5683: $context = 'tools';
5684: } else {
5685: $context = $action;
5686: }
5687: if ($context eq 'requestcourses') {
1.98 raeburn 5688: @usertools = ('official','unofficial','community');
1.106 raeburn 5689: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5690: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5691: %titles = &courserequest_titles();
5692: $toolregexp = join('|',@usertools);
5693: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5694: } elsif ($context eq 'requestauthor') {
5695: @usertools = ('author');
5696: %titles = &authorrequest_titles();
1.86 raeburn 5697: } else {
1.160.6.4 raeburn 5698: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5699: %titles = &tool_titles();
1.86 raeburn 5700: }
1.72 raeburn 5701: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5702: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5703: foreach my $key (keys(%env)) {
1.101 raeburn 5704: if ($context eq 'requestcourses') {
5705: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5706: my $item = $1;
5707: my $type = $2;
5708: if ($type =~ /^limit_(.+)/) {
5709: $limithash{$item}{$1} = $env{$key};
5710: } else {
5711: $confhash{$item}{$type} = $env{$key};
5712: }
5713: }
1.160.6.5 raeburn 5714: } elsif ($context eq 'requestauthor') {
5715: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5716: $confhash{$1} = $env{$key};
5717: }
1.101 raeburn 5718: } else {
1.86 raeburn 5719: if ($key =~ /^form\.quota_(.+)$/) {
5720: $confhash{'defaultquota'}{$1} = $env{$key};
5721: }
1.101 raeburn 5722: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5723: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5724: }
1.72 raeburn 5725: }
5726: }
1.160.6.5 raeburn 5727: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5728: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5729: @approvalnotify = sort(@approvalnotify);
5730: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5731: if (ref($domconfig{$action}) eq 'HASH') {
5732: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5733: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5734: $changes{'notify'}{'approval'} = 1;
5735: }
5736: } else {
1.144 raeburn 5737: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5738: $changes{'notify'}{'approval'} = 1;
5739: }
5740: }
5741: } else {
1.144 raeburn 5742: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5743: $changes{'notify'}{'approval'} = 1;
5744: }
5745: }
5746: } else {
1.86 raeburn 5747: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5748: }
1.72 raeburn 5749: foreach my $item (@usertools) {
5750: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5751: my $unset;
1.101 raeburn 5752: if ($context eq 'requestcourses') {
1.104 raeburn 5753: $unset = '0';
5754: if ($type eq '_LC_adv') {
5755: $unset = '';
5756: }
1.101 raeburn 5757: if ($confhash{$item}{$type} eq 'autolimit') {
5758: $confhash{$item}{$type} .= '=';
5759: unless ($limithash{$item}{$type} =~ /\D/) {
5760: $confhash{$item}{$type} .= $limithash{$item}{$type};
5761: }
5762: }
1.160.6.5 raeburn 5763: } elsif ($context eq 'requestauthor') {
5764: $unset = '0';
5765: if ($type eq '_LC_adv') {
5766: $unset = '';
5767: }
1.72 raeburn 5768: } else {
1.101 raeburn 5769: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5770: $confhash{$item}{$type} = 1;
5771: } else {
5772: $confhash{$item}{$type} = 0;
5773: }
1.72 raeburn 5774: }
1.86 raeburn 5775: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5776: if ($action eq 'requestauthor') {
5777: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5778: $changes{$type} = 1;
5779: }
5780: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5781: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5782: $changes{$item}{$type} = 1;
5783: }
5784: } else {
5785: if ($context eq 'requestcourses') {
1.104 raeburn 5786: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5787: $changes{$item}{$type} = 1;
5788: }
5789: } else {
5790: if (!$confhash{$item}{$type}) {
5791: $changes{$item}{$type} = 1;
5792: }
5793: }
5794: }
5795: } else {
5796: if ($context eq 'requestcourses') {
1.104 raeburn 5797: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5798: $changes{$item}{$type} = 1;
5799: }
1.160.6.5 raeburn 5800: } elsif ($context eq 'requestauthor') {
5801: if ($confhash{$type} ne $unset) {
5802: $changes{$type} = 1;
5803: }
1.72 raeburn 5804: } else {
5805: if (!$confhash{$item}{$type}) {
5806: $changes{$item}{$type} = 1;
5807: }
5808: }
5809: }
1.1 raeburn 5810: }
5811: }
1.160.6.5 raeburn 5812: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5813: if (ref($domconfig{'quotas'}) eq 'HASH') {
5814: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5815: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5816: if (exists($confhash{'defaultquota'}{$key})) {
5817: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5818: $changes{'defaultquota'}{$key} = 1;
5819: }
5820: } else {
5821: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5822: }
5823: }
1.86 raeburn 5824: } else {
5825: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5826: if (exists($confhash{'defaultquota'}{$key})) {
5827: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5828: $changes{'defaultquota'}{$key} = 1;
5829: }
5830: } else {
5831: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5832: }
1.1 raeburn 5833: }
5834: }
5835: }
1.86 raeburn 5836: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5837: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5838: if (ref($domconfig{'quotas'}) eq 'HASH') {
5839: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5840: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5841: $changes{'defaultquota'}{$key} = 1;
5842: }
5843: } else {
5844: if (!exists($domconfig{'quotas'}{$key})) {
5845: $changes{'defaultquota'}{$key} = 1;
5846: }
1.72 raeburn 5847: }
5848: } else {
1.86 raeburn 5849: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5850: }
1.1 raeburn 5851: }
5852: }
5853: }
1.72 raeburn 5854:
1.160.6.5 raeburn 5855: if ($context eq 'requestauthor') {
5856: $domdefaults{'requestauthor'} = \%confhash;
5857: } else {
5858: foreach my $key (keys(%confhash)) {
5859: $domdefaults{$key} = $confhash{$key};
5860: }
1.72 raeburn 5861: }
1.160.6.5 raeburn 5862:
1.1 raeburn 5863: my %quotahash = (
1.86 raeburn 5864: $action => { %confhash }
1.1 raeburn 5865: );
5866: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5867: $dom);
5868: if ($putresult eq 'ok') {
5869: if (keys(%changes) > 0) {
1.72 raeburn 5870: my $cachetime = 24*60*60;
5871: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5872:
1.1 raeburn 5873: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 5874: unless (($context eq 'requestcourses') ||
5875: ($context eq 'requestauthor')) {
1.86 raeburn 5876: if (ref($changes{'defaultquota'}) eq 'HASH') {
5877: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5878: foreach my $type (@{$types},'default') {
5879: if (defined($changes{'defaultquota'}{$type})) {
5880: my $typetitle = $usertypes->{$type};
5881: if ($type eq 'default') {
5882: $typetitle = $othertitle;
5883: }
5884: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5885: }
5886: }
1.86 raeburn 5887: $resulttext .= '</ul></li>';
1.72 raeburn 5888: }
5889: }
1.80 raeburn 5890: my %newenv;
1.72 raeburn 5891: foreach my $item (@usertools) {
1.160.6.5 raeburn 5892: my (%haschgs,%inconf);
5893: if ($context eq 'requestauthor') {
5894: %haschgs = %changes;
5895: %inconf = %confhash;
5896: } else {
5897: if (ref($changes{$item}) eq 'HASH') {
5898: %haschgs = %{$changes{$item}};
5899: }
5900: if (ref($confhash{$item}) eq 'HASH') {
5901: %inconf = %{$confhash{$item}};
5902: }
5903: }
5904: if (keys(%haschgs) > 0) {
1.80 raeburn 5905: my $newacc =
5906: &Apache::lonnet::usertools_access($env{'user.name'},
5907: $env{'user.domain'},
1.86 raeburn 5908: $item,'reload',$context);
1.160.6.5 raeburn 5909: if (($context eq 'requestcourses') ||
5910: ($context eq 'requestauthor')) {
1.108 raeburn 5911: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5912: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5913: }
5914: } else {
5915: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5916: $newenv{'environment.availabletools.'.$item} = $newacc;
5917: }
1.80 raeburn 5918: }
1.160.6.5 raeburn 5919: unless ($context eq 'requestauthor') {
5920: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5921: }
1.72 raeburn 5922: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 5923: if ($haschgs{$type}) {
1.72 raeburn 5924: my $typetitle = $usertypes->{$type};
5925: if ($type eq 'default') {
5926: $typetitle = $othertitle;
5927: } elsif ($type eq '_LC_adv') {
5928: $typetitle = 'LON-CAPA Advanced Users';
5929: }
1.160.6.5 raeburn 5930: if ($inconf{$type}) {
1.101 raeburn 5931: if ($context eq 'requestcourses') {
5932: my $cond;
1.160.6.5 raeburn 5933: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5934: if ($1 eq '') {
5935: $cond = &mt('(Automatic processing of any request).');
5936: } else {
5937: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5938: }
5939: } else {
1.160.6.5 raeburn 5940: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5941: }
5942: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 5943: } elsif ($context eq 'requestauthor') {
5944: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5945: $titles{$inconf{$type}},$typetitle);
5946:
1.101 raeburn 5947: } else {
5948: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5949: }
1.72 raeburn 5950: } else {
1.104 raeburn 5951: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 5952: if ($inconf{$type} eq '0') {
1.104 raeburn 5953: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5954: } else {
5955: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5956: }
5957: } else {
5958: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5959: }
1.72 raeburn 5960: }
5961: }
1.26 raeburn 5962: }
1.160.6.5 raeburn 5963: unless ($context eq 'requestauthor') {
5964: $resulttext .= '</ul></li>';
5965: }
1.26 raeburn 5966: }
1.1 raeburn 5967: }
1.160.6.5 raeburn 5968: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5969: if (ref($changes{'notify'}) eq 'HASH') {
5970: if ($changes{'notify'}{'approval'}) {
5971: if (ref($confhash{'notify'}) eq 'HASH') {
5972: if ($confhash{'notify'}{'approval'}) {
5973: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5974: } else {
1.160.6.5 raeburn 5975: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5976: }
5977: }
5978: }
5979: }
5980: }
1.1 raeburn 5981: $resulttext .= '</ul>';
1.80 raeburn 5982: if (keys(%newenv)) {
5983: &Apache::lonnet::appenv(\%newenv);
5984: }
1.1 raeburn 5985: } else {
1.86 raeburn 5986: if ($context eq 'requestcourses') {
5987: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 5988: } elsif ($context eq 'requestauthor') {
5989: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5990: } else {
1.90 weissno 5991: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5992: }
1.1 raeburn 5993: }
5994: } else {
1.11 albertel 5995: $resulttext = '<span class="LC_error">'.
5996: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5997: }
1.3 raeburn 5998: return $resulttext;
1.1 raeburn 5999: }
6000:
1.3 raeburn 6001: sub modify_autoenroll {
6002: my ($dom,%domconfig) = @_;
1.1 raeburn 6003: my ($resulttext,%changes);
6004: my %currautoenroll;
6005: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6006: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6007: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6008: }
6009: }
6010: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6011: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6012: sender => 'Sender for notification messages',
6013: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6014: my @offon = ('off','on');
1.17 raeburn 6015: my $sender_uname = $env{'form.sender_uname'};
6016: my $sender_domain = $env{'form.sender_domain'};
6017: if ($sender_domain eq '') {
6018: $sender_uname = '';
6019: } elsif ($sender_uname eq '') {
6020: $sender_domain = '';
6021: }
1.129 raeburn 6022: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6023: my %autoenrollhash = (
1.129 raeburn 6024: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6025: 'sender_uname' => $sender_uname,
6026: 'sender_domain' => $sender_domain,
6027: 'co-owners' => $coowners,
1.1 raeburn 6028: }
6029: );
1.4 raeburn 6030: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6031: $dom);
1.1 raeburn 6032: if ($putresult eq 'ok') {
6033: if (exists($currautoenroll{'run'})) {
6034: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6035: $changes{'run'} = 1;
6036: }
6037: } elsif ($autorun) {
6038: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6039: $changes{'run'} = 1;
1.1 raeburn 6040: }
6041: }
1.17 raeburn 6042: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6043: $changes{'sender'} = 1;
6044: }
1.17 raeburn 6045: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6046: $changes{'sender'} = 1;
6047: }
1.129 raeburn 6048: if ($currautoenroll{'co-owners'} ne '') {
6049: if ($currautoenroll{'co-owners'} ne $coowners) {
6050: $changes{'coowners'} = 1;
6051: }
6052: } elsif ($coowners) {
6053: $changes{'coowners'} = 1;
6054: }
1.1 raeburn 6055: if (keys(%changes) > 0) {
6056: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6057: if ($changes{'run'}) {
1.1 raeburn 6058: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6059: }
6060: if ($changes{'sender'}) {
1.17 raeburn 6061: if ($sender_uname eq '' || $sender_domain eq '') {
6062: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6063: } else {
6064: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6065: }
1.1 raeburn 6066: }
1.129 raeburn 6067: if ($changes{'coowners'}) {
6068: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6069: &Apache::loncommon::devalidate_domconfig_cache($dom);
6070: }
1.1 raeburn 6071: $resulttext .= '</ul>';
6072: } else {
6073: $resulttext = &mt('No changes made to auto-enrollment settings');
6074: }
6075: } else {
1.11 albertel 6076: $resulttext = '<span class="LC_error">'.
6077: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6078: }
1.3 raeburn 6079: return $resulttext;
1.1 raeburn 6080: }
6081:
6082: sub modify_autoupdate {
1.3 raeburn 6083: my ($dom,%domconfig) = @_;
1.1 raeburn 6084: my ($resulttext,%currautoupdate,%fields,%changes);
6085: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6086: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6087: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6088: }
6089: }
6090: my @offon = ('off','on');
6091: my %title = &Apache::lonlocal::texthash (
6092: run => 'Auto-update:',
6093: classlists => 'Updates to user information in classlists?'
6094: );
1.44 raeburn 6095: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6096: my %fieldtitles = &Apache::lonlocal::texthash (
6097: id => 'Student/Employee ID',
1.20 raeburn 6098: permanentemail => 'E-mail address',
1.1 raeburn 6099: lastname => 'Last Name',
6100: firstname => 'First Name',
6101: middlename => 'Middle Name',
1.132 raeburn 6102: generation => 'Generation',
1.1 raeburn 6103: );
1.142 raeburn 6104: $othertitle = &mt('All users');
1.1 raeburn 6105: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6106: $othertitle = &mt('Other users');
1.1 raeburn 6107: }
6108: foreach my $key (keys(%env)) {
6109: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6110: my ($usertype,$item) = ($1,$2);
6111: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6112: if ($usertype eq 'default') {
6113: push(@{$fields{$1}},$2);
6114: } elsif (ref($types) eq 'ARRAY') {
6115: if (grep(/^\Q$usertype\E$/,@{$types})) {
6116: push(@{$fields{$1}},$2);
6117: }
6118: }
6119: }
1.1 raeburn 6120: }
6121: }
1.131 raeburn 6122: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6123: @lockablenames = sort(@lockablenames);
6124: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6125: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6126: if (@changed) {
6127: $changes{'lockablenames'} = 1;
6128: }
6129: } else {
6130: if (@lockablenames) {
6131: $changes{'lockablenames'} = 1;
6132: }
6133: }
1.1 raeburn 6134: my %updatehash = (
6135: autoupdate => { run => $env{'form.autoupdate_run'},
6136: classlists => $env{'form.classlists'},
6137: fields => {%fields},
1.131 raeburn 6138: lockablenames => \@lockablenames,
1.1 raeburn 6139: }
6140: );
6141: foreach my $key (keys(%currautoupdate)) {
6142: if (($key eq 'run') || ($key eq 'classlists')) {
6143: if (exists($updatehash{autoupdate}{$key})) {
6144: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6145: $changes{$key} = 1;
6146: }
6147: }
6148: } elsif ($key eq 'fields') {
6149: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6150: foreach my $item (@{$types},'default') {
1.1 raeburn 6151: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6152: my $change = 0;
6153: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6154: if (!exists($fields{$item})) {
6155: $change = 1;
1.132 raeburn 6156: last;
1.1 raeburn 6157: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6158: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6159: $change = 1;
1.132 raeburn 6160: last;
1.1 raeburn 6161: }
6162: }
6163: }
6164: if ($change) {
6165: push(@{$changes{$key}},$item);
6166: }
1.26 raeburn 6167: }
1.1 raeburn 6168: }
6169: }
1.131 raeburn 6170: } elsif ($key eq 'lockablenames') {
6171: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6172: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6173: if (@changed) {
6174: $changes{'lockablenames'} = 1;
6175: }
6176: } else {
6177: if (@lockablenames) {
6178: $changes{'lockablenames'} = 1;
6179: }
6180: }
6181: }
6182: }
6183: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6184: if (@lockablenames) {
6185: $changes{'lockablenames'} = 1;
1.1 raeburn 6186: }
6187: }
1.26 raeburn 6188: foreach my $item (@{$types},'default') {
6189: if (defined($fields{$item})) {
6190: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6191: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6192: my $change = 0;
6193: if (ref($fields{$item}) eq 'ARRAY') {
6194: foreach my $type (@{$fields{$item}}) {
6195: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6196: $change = 1;
6197: last;
6198: }
6199: }
6200: }
6201: if ($change) {
6202: push(@{$changes{'fields'}},$item);
6203: }
6204: } else {
1.26 raeburn 6205: push(@{$changes{'fields'}},$item);
6206: }
6207: } else {
6208: push(@{$changes{'fields'}},$item);
1.1 raeburn 6209: }
6210: }
6211: }
6212: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6213: $dom);
6214: if ($putresult eq 'ok') {
6215: if (keys(%changes) > 0) {
6216: $resulttext = &mt('Changes made:').'<ul>';
6217: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6218: if ($key eq 'lockablenames') {
6219: $resulttext .= '<li>';
6220: if (@lockablenames) {
6221: $usertypes->{'default'} = $othertitle;
6222: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6223: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6224: } else {
6225: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6226: }
6227: $resulttext .= '</li>';
6228: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6229: foreach my $item (@{$changes{$key}}) {
6230: my @newvalues;
6231: foreach my $type (@{$fields{$item}}) {
6232: push(@newvalues,$fieldtitles{$type});
6233: }
1.3 raeburn 6234: my $newvaluestr;
6235: if (@newvalues > 0) {
6236: $newvaluestr = join(', ',@newvalues);
6237: } else {
6238: $newvaluestr = &mt('none');
1.6 raeburn 6239: }
1.1 raeburn 6240: if ($item eq 'default') {
1.26 raeburn 6241: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6242: } else {
1.26 raeburn 6243: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6244: }
6245: }
6246: } else {
6247: my $newvalue;
6248: if ($key eq 'run') {
6249: $newvalue = $offon[$env{'form.autoupdate_run'}];
6250: } else {
6251: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6252: }
1.1 raeburn 6253: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6254: }
6255: }
6256: $resulttext .= '</ul>';
6257: } else {
1.3 raeburn 6258: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6259: }
6260: } else {
1.11 albertel 6261: $resulttext = '<span class="LC_error">'.
6262: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6263: }
1.3 raeburn 6264: return $resulttext;
1.1 raeburn 6265: }
6266:
1.125 raeburn 6267: sub modify_autocreate {
6268: my ($dom,%domconfig) = @_;
6269: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6270: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6271: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6272: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6273: }
6274: }
6275: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6276: req => 'Auto-creation of validated requests for official courses',
6277: xmldc => 'Identity of course creator of courses from XML files',
6278: );
6279: my @types = ('xml','req');
6280: foreach my $item (@types) {
6281: $newvals{$item} = $env{'form.autocreate_'.$item};
6282: $newvals{$item} =~ s/\D//g;
6283: $newvals{$item} = 0 if ($newvals{$item} eq '');
6284: }
6285: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6286: my %domcoords = &get_active_dcs($dom);
6287: unless (exists($domcoords{$newvals{'xmldc'}})) {
6288: $newvals{'xmldc'} = '';
6289: }
6290: %autocreatehash = (
6291: autocreate => { xml => $newvals{'xml'},
6292: req => $newvals{'req'},
6293: }
6294: );
6295: if ($newvals{'xmldc'} ne '') {
6296: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6297: }
6298: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6299: $dom);
6300: if ($putresult eq 'ok') {
6301: my @items = @types;
6302: if ($newvals{'xml'}) {
6303: push(@items,'xmldc');
6304: }
6305: foreach my $item (@items) {
6306: if (exists($currautocreate{$item})) {
6307: if ($currautocreate{$item} ne $newvals{$item}) {
6308: $changes{$item} = 1;
6309: }
6310: } elsif ($newvals{$item}) {
6311: $changes{$item} = 1;
6312: }
6313: }
6314: if (keys(%changes) > 0) {
6315: my @offon = ('off','on');
6316: $resulttext = &mt('Changes made:').'<ul>';
6317: foreach my $item (@types) {
6318: if ($changes{$item}) {
6319: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6320: $resulttext .= '<li>'.
6321: &mt("$title{$item} set to [_1]$newtxt [_2]",
6322: '<b>','</b>').
6323: '</li>';
1.125 raeburn 6324: }
6325: }
6326: if ($changes{'xmldc'}) {
6327: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6328: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6329: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6330: }
6331: $resulttext .= '</ul>';
6332: } else {
6333: $resulttext = &mt('No changes made to auto-creation settings');
6334: }
6335: } else {
6336: $resulttext = '<span class="LC_error">'.
6337: &mt('An error occurred: [_1]',$putresult).'</span>';
6338: }
6339: return $resulttext;
6340: }
6341:
1.23 raeburn 6342: sub modify_directorysrch {
6343: my ($dom,%domconfig) = @_;
6344: my ($resulttext,%changes);
6345: my %currdirsrch;
6346: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6347: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6348: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6349: }
6350: }
6351: my %title = ( available => 'Directory search available',
1.24 raeburn 6352: localonly => 'Other domains can search',
1.23 raeburn 6353: searchby => 'Search types',
6354: searchtypes => 'Search latitude');
6355: my @offon = ('off','on');
1.24 raeburn 6356: my @otherdoms = ('Yes','No');
1.23 raeburn 6357:
1.25 raeburn 6358: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6359: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6360: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6361:
1.44 raeburn 6362: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6363: if (keys(%{$usertypes}) == 0) {
6364: @cansearch = ('default');
6365: } else {
6366: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6367: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6368: if (!grep(/^\Q$type\E$/,@cansearch)) {
6369: push(@{$changes{'cansearch'}},$type);
6370: }
1.23 raeburn 6371: }
1.26 raeburn 6372: foreach my $type (@cansearch) {
6373: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6374: push(@{$changes{'cansearch'}},$type);
6375: }
1.23 raeburn 6376: }
1.26 raeburn 6377: } else {
6378: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6379: }
6380: }
6381:
6382: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6383: foreach my $by (@{$currdirsrch{'searchby'}}) {
6384: if (!grep(/^\Q$by\E$/,@searchby)) {
6385: push(@{$changes{'searchby'}},$by);
6386: }
6387: }
6388: foreach my $by (@searchby) {
6389: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6390: push(@{$changes{'searchby'}},$by);
6391: }
6392: }
6393: } else {
6394: push(@{$changes{'searchby'}},@searchby);
6395: }
1.25 raeburn 6396:
6397: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6398: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6399: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6400: push(@{$changes{'searchtypes'}},$type);
6401: }
6402: }
6403: foreach my $type (@searchtypes) {
6404: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6405: push(@{$changes{'searchtypes'}},$type);
6406: }
6407: }
6408: } else {
6409: if (exists($currdirsrch{'searchtypes'})) {
6410: foreach my $type (@searchtypes) {
6411: if ($type ne $currdirsrch{'searchtypes'}) {
6412: push(@{$changes{'searchtypes'}},$type);
6413: }
6414: }
6415: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6416: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6417: }
6418: } else {
6419: push(@{$changes{'searchtypes'}},@searchtypes);
6420: }
6421: }
6422:
1.23 raeburn 6423: my %dirsrch_hash = (
6424: directorysrch => { available => $env{'form.dirsrch_available'},
6425: cansearch => \@cansearch,
1.24 raeburn 6426: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6427: searchby => \@searchby,
1.25 raeburn 6428: searchtypes => \@searchtypes,
1.23 raeburn 6429: }
6430: );
6431: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6432: $dom);
6433: if ($putresult eq 'ok') {
6434: if (exists($currdirsrch{'available'})) {
6435: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6436: $changes{'available'} = 1;
6437: }
6438: } else {
6439: if ($env{'form.dirsrch_available'} eq '1') {
6440: $changes{'available'} = 1;
6441: }
6442: }
1.24 raeburn 6443: if (exists($currdirsrch{'localonly'})) {
6444: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6445: $changes{'localonly'} = 1;
6446: }
6447: } else {
6448: if ($env{'form.dirsrch_localonly'} eq '1') {
6449: $changes{'localonly'} = 1;
6450: }
6451: }
1.23 raeburn 6452: if (keys(%changes) > 0) {
6453: $resulttext = &mt('Changes made:').'<ul>';
6454: if ($changes{'available'}) {
6455: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6456: }
1.24 raeburn 6457: if ($changes{'localonly'}) {
6458: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6459: }
6460:
1.23 raeburn 6461: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6462: my $chgtext;
1.26 raeburn 6463: if (ref($usertypes) eq 'HASH') {
6464: if (keys(%{$usertypes}) > 0) {
6465: foreach my $type (@{$types}) {
6466: if (grep(/^\Q$type\E$/,@cansearch)) {
6467: $chgtext .= $usertypes->{$type}.'; ';
6468: }
6469: }
6470: if (grep(/^default$/,@cansearch)) {
6471: $chgtext .= $othertitle;
6472: } else {
6473: $chgtext =~ s/\; $//;
6474: }
1.160.6.13 raeburn 6475: $resulttext .=
6476: '<li>'.
6477: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6478: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6479: '</li>';
1.23 raeburn 6480: }
6481: }
6482: }
6483: if (ref($changes{'searchby'}) eq 'ARRAY') {
6484: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6485: my $chgtext;
6486: foreach my $type (@{$titleorder}) {
6487: if (grep(/^\Q$type\E$/,@searchby)) {
6488: if (defined($searchtitles->{$type})) {
6489: $chgtext .= $searchtitles->{$type}.'; ';
6490: }
6491: }
6492: }
6493: $chgtext =~ s/\; $//;
6494: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6495: }
1.25 raeburn 6496: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6497: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6498: my $chgtext;
6499: foreach my $type (@{$srchtypeorder}) {
6500: if (grep(/^\Q$type\E$/,@searchtypes)) {
6501: if (defined($srchtypes_desc->{$type})) {
6502: $chgtext .= $srchtypes_desc->{$type}.'; ';
6503: }
6504: }
6505: }
6506: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 6507: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6508: }
6509: $resulttext .= '</ul>';
6510: } else {
6511: $resulttext = &mt('No changes made to institution directory search settings');
6512: }
6513: } else {
6514: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6515: &mt('An error occurred: [_1]',$putresult).'</span>';
6516: }
6517: return $resulttext;
6518: }
6519:
1.28 raeburn 6520: sub modify_contacts {
6521: my ($dom,%domconfig) = @_;
6522: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6523: if (ref($domconfig{'contacts'}) eq 'HASH') {
6524: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6525: $currsetting{$key} = $domconfig{'contacts'}{$key};
6526: }
6527: }
1.134 raeburn 6528: my (%others,%to,%bcc);
1.28 raeburn 6529: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6530: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6531: 'requestsmail');
1.28 raeburn 6532: foreach my $type (@mailings) {
6533: @{$newsetting{$type}} =
6534: &Apache::loncommon::get_env_multiple('form.'.$type);
6535: foreach my $item (@contacts) {
6536: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6537: $contacts_hash{contacts}{$type}{$item} = 1;
6538: } else {
6539: $contacts_hash{contacts}{$type}{$item} = 0;
6540: }
6541: }
6542: $others{$type} = $env{'form.'.$type.'_others'};
6543: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6544: if ($type eq 'helpdeskmail') {
6545: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6546: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6547: }
1.28 raeburn 6548: }
6549: foreach my $item (@contacts) {
6550: $to{$item} = $env{'form.'.$item};
6551: $contacts_hash{'contacts'}{$item} = $to{$item};
6552: }
6553: if (keys(%currsetting) > 0) {
6554: foreach my $item (@contacts) {
6555: if ($to{$item} ne $currsetting{$item}) {
6556: $changes{$item} = 1;
6557: }
6558: }
6559: foreach my $type (@mailings) {
6560: foreach my $item (@contacts) {
6561: if (ref($currsetting{$type}) eq 'HASH') {
6562: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6563: push(@{$changes{$type}},$item);
6564: }
6565: } else {
6566: push(@{$changes{$type}},@{$newsetting{$type}});
6567: }
6568: }
6569: if ($others{$type} ne $currsetting{$type}{'others'}) {
6570: push(@{$changes{$type}},'others');
6571: }
1.134 raeburn 6572: if ($type eq 'helpdeskmail') {
6573: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6574: push(@{$changes{$type}},'bcc');
6575: }
6576: }
1.28 raeburn 6577: }
6578: } else {
6579: my %default;
6580: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6581: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6582: $default{'errormail'} = 'adminemail';
6583: $default{'packagesmail'} = 'adminemail';
6584: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6585: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6586: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6587: foreach my $item (@contacts) {
6588: if ($to{$item} ne $default{$item}) {
6589: $changes{$item} = 1;
6590: }
6591: }
6592: foreach my $type (@mailings) {
6593: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6594:
6595: push(@{$changes{$type}},@{$newsetting{$type}});
6596: }
6597: if ($others{$type} ne '') {
6598: push(@{$changes{$type}},'others');
1.134 raeburn 6599: }
6600: if ($type eq 'helpdeskmail') {
6601: if ($bcc{$type} ne '') {
6602: push(@{$changes{$type}},'bcc');
6603: }
6604: }
1.28 raeburn 6605: }
6606: }
6607: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6608: $dom);
6609: if ($putresult eq 'ok') {
6610: if (keys(%changes) > 0) {
6611: my ($titles,$short_titles) = &contact_titles();
6612: $resulttext = &mt('Changes made:').'<ul>';
6613: foreach my $item (@contacts) {
6614: if ($changes{$item}) {
6615: $resulttext .= '<li>'.$titles->{$item}.
6616: &mt(' set to: ').
6617: '<span class="LC_cusr_emph">'.
6618: $to{$item}.'</span></li>';
6619: }
6620: }
6621: foreach my $type (@mailings) {
6622: if (ref($changes{$type}) eq 'ARRAY') {
6623: $resulttext .= '<li>'.$titles->{$type}.': ';
6624: my @text;
6625: foreach my $item (@{$newsetting{$type}}) {
6626: push(@text,$short_titles->{$item});
6627: }
6628: if ($others{$type} ne '') {
6629: push(@text,$others{$type});
6630: }
6631: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6632: join(', ',@text).'</span>';
6633: if ($type eq 'helpdeskmail') {
6634: if ($bcc{$type} ne '') {
6635: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6636: }
6637: }
6638: $resulttext .= '</li>';
1.28 raeburn 6639: }
6640: }
6641: $resulttext .= '</ul>';
6642: } else {
1.34 raeburn 6643: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6644: }
6645: } else {
6646: $resulttext = '<span class="LC_error">'.
6647: &mt('An error occurred: [_1].',$putresult).'</span>';
6648: }
6649: return $resulttext;
6650: }
6651:
6652: sub modify_usercreation {
1.27 raeburn 6653: my ($dom,%domconfig) = @_;
1.34 raeburn 6654: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6655: my $warningmsg;
1.27 raeburn 6656: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6657: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6658: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6659: }
6660: }
6661: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6662: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6663: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6664: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6665: foreach my $item(@contexts) {
1.45 raeburn 6666: if ($item eq 'selfcreate') {
1.50 raeburn 6667: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6668: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6669: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6670: if (ref($cancreate{$item}) eq 'ARRAY') {
6671: if (grep(/^login$/,@{$cancreate{$item}})) {
6672: $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.');
6673: }
1.43 raeburn 6674: }
6675: }
1.50 raeburn 6676: } else {
6677: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6678: }
1.34 raeburn 6679: }
1.93 raeburn 6680: my ($othertitle,$usertypes,$types) =
6681: &Apache::loncommon::sorted_inst_types($dom);
6682: if (ref($types) eq 'ARRAY') {
6683: if (@{$types} > 0) {
6684: @{$cancreate{'statustocreate'}} =
6685: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6686: } else {
6687: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6688: }
6689: push(@contexts,'statustocreate');
6690: }
1.160.6.5 raeburn 6691: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6692: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6693: foreach my $item (@contexts) {
1.93 raeburn 6694: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6695: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6696: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6697: if (ref($cancreate{$item}) eq 'ARRAY') {
6698: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6699: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6700: push(@{$changes{'cancreate'}},$item);
6701: }
1.50 raeburn 6702: }
6703: }
6704: }
6705: } else {
6706: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6707: if (@{$cancreate{$item}} > 0) {
6708: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6709: push(@{$changes{'cancreate'}},$item);
6710: }
6711: }
6712: } else {
6713: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6714: if (@{$cancreate{$item}} < 3) {
6715: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6716: push(@{$changes{'cancreate'}},$item);
6717: }
6718: }
6719: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6720: if (@{$cancreate{$item}} > 0) {
6721: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6722: push(@{$changes{'cancreate'}},$item);
6723: }
6724: }
6725: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6726: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6727: push(@{$changes{'cancreate'}},$item);
6728: }
6729: }
6730: }
6731: }
6732: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6733: foreach my $type (@{$cancreate{$item}}) {
6734: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6735: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6736: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6737: push(@{$changes{'cancreate'}},$item);
6738: }
6739: }
6740: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6741: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6742: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6743: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6744: push(@{$changes{'cancreate'}},$item);
6745: }
6746: }
6747: }
6748: }
6749: }
6750: } else {
6751: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6752: push(@{$changes{'cancreate'}},$item);
6753: }
6754: }
1.27 raeburn 6755: }
1.34 raeburn 6756: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6757: foreach my $item (@contexts) {
1.43 raeburn 6758: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6759: if ($cancreate{$item} ne 'any') {
6760: push(@{$changes{'cancreate'}},$item);
6761: }
6762: } else {
6763: if ($cancreate{$item} ne 'none') {
6764: push(@{$changes{'cancreate'}},$item);
6765: }
1.27 raeburn 6766: }
6767: }
6768: } else {
1.43 raeburn 6769: foreach my $item (@contexts) {
1.34 raeburn 6770: push(@{$changes{'cancreate'}},$item);
6771: }
1.27 raeburn 6772: }
1.34 raeburn 6773:
1.27 raeburn 6774: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6775: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6776: if (!grep(/^\Q$type\E$/,@username_rule)) {
6777: push(@{$changes{'username_rule'}},$type);
6778: }
6779: }
6780: foreach my $type (@username_rule) {
6781: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6782: push(@{$changes{'username_rule'}},$type);
6783: }
6784: }
6785: } else {
6786: push(@{$changes{'username_rule'}},@username_rule);
6787: }
6788:
1.32 raeburn 6789: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6790: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6791: if (!grep(/^\Q$type\E$/,@id_rule)) {
6792: push(@{$changes{'id_rule'}},$type);
6793: }
6794: }
6795: foreach my $type (@id_rule) {
6796: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6797: push(@{$changes{'id_rule'}},$type);
6798: }
6799: }
6800: } else {
6801: push(@{$changes{'id_rule'}},@id_rule);
6802: }
6803:
1.43 raeburn 6804: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6805: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6806: if (!grep(/^\Q$type\E$/,@email_rule)) {
6807: push(@{$changes{'email_rule'}},$type);
6808: }
6809: }
6810: foreach my $type (@email_rule) {
6811: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6812: push(@{$changes{'email_rule'}},$type);
6813: }
6814: }
6815: } else {
6816: push(@{$changes{'email_rule'}},@email_rule);
6817: }
6818:
6819: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6820: my @authtypes = ('int','krb4','krb5','loc');
6821: my %authhash;
1.43 raeburn 6822: foreach my $item (@authen_contexts) {
1.28 raeburn 6823: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6824: foreach my $auth (@authtypes) {
6825: if (grep(/^\Q$auth\E$/,@authallowed)) {
6826: $authhash{$item}{$auth} = 1;
6827: } else {
6828: $authhash{$item}{$auth} = 0;
6829: }
6830: }
6831: }
6832: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6833: foreach my $item (@authen_contexts) {
1.28 raeburn 6834: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6835: foreach my $auth (@authtypes) {
6836: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6837: push(@{$changes{'authtypes'}},$item);
6838: last;
6839: }
6840: }
6841: }
6842: }
6843: } else {
1.43 raeburn 6844: foreach my $item (@authen_contexts) {
1.28 raeburn 6845: push(@{$changes{'authtypes'}},$item);
6846: }
6847: }
6848:
1.27 raeburn 6849: my %usercreation_hash = (
1.28 raeburn 6850: usercreation => {
1.34 raeburn 6851: cancreate => \%cancreate,
1.27 raeburn 6852: username_rule => \@username_rule,
1.32 raeburn 6853: id_rule => \@id_rule,
1.43 raeburn 6854: email_rule => \@email_rule,
1.32 raeburn 6855: authtypes => \%authhash,
1.27 raeburn 6856: }
6857: );
6858:
6859: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6860: $dom);
1.50 raeburn 6861:
6862: my %selfcreatetypes = (
6863: sso => 'users authenticated by institutional single sign on',
6864: login => 'users authenticated by institutional log-in',
6865: email => 'users who provide a valid e-mail address for use as the username',
6866: );
1.27 raeburn 6867: if ($putresult eq 'ok') {
6868: if (keys(%changes) > 0) {
6869: $resulttext = &mt('Changes made:').'<ul>';
6870: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6871: my %lt = &usercreation_types();
6872: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6873: my $chgtext;
1.160.6.5 raeburn 6874: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6875: $chgtext = $lt{$type}.', ';
6876: }
1.45 raeburn 6877: if ($type eq 'selfcreate') {
1.50 raeburn 6878: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6879: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6880: } else {
1.100 raeburn 6881: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6882: foreach my $case (@{$cancreate{$type}}) {
6883: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6884: }
6885: $chgtext .= '</ul>';
1.100 raeburn 6886: if (ref($cancreate{$type}) eq 'ARRAY') {
6887: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6888: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6889: if (@{$cancreate{'statustocreate'}} == 0) {
6890: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6891: }
6892: }
6893: }
6894: }
1.43 raeburn 6895: }
1.93 raeburn 6896: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6897: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6898: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6899: if (@{$cancreate{'selfcreate'}} > 0) {
6900: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6901:
6902: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6903: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6904: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6905: }
1.96 raeburn 6906: } elsif (ref($usertypes) eq 'HASH') {
6907: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6908: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6909: } else {
6910: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6911: }
6912: $chgtext .= '<ul>';
6913: foreach my $case (@{$cancreate{$type}}) {
6914: if ($case eq 'default') {
6915: $chgtext .= '<li>'.$othertitle.'</li>';
6916: } else {
6917: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6918: }
6919: }
1.100 raeburn 6920: $chgtext .= '</ul>';
6921: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6922: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6923: }
6924: }
6925: } else {
6926: if (@{$cancreate{$type}} == 0) {
6927: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6928: } else {
6929: $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 6930: }
6931: }
6932: }
1.160.6.5 raeburn 6933: } elsif ($type eq 'captcha') {
6934: if ($cancreate{$type} eq 'notused') {
6935: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6936: } else {
6937: my %captchas = &captcha_phrases();
6938: if ($captchas{$cancreate{$type}}) {
6939: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6940: } else {
6941: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6942: }
6943: }
6944: } elsif ($type eq 'recaptchakeys') {
6945: my ($privkey,$pubkey);
6946: if (ref($cancreate{$type}) eq 'HASH') {
6947: $pubkey = $cancreate{$type}{'public'};
6948: $privkey = $cancreate{$type}{'private'};
6949: }
6950: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6951: if (!$pubkey) {
6952: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6953: } else {
6954: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6955: }
6956: if (!$privkey) {
6957: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6958: } else {
6959: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6960: }
6961: $chgtext .= '</ul>';
1.43 raeburn 6962: } else {
6963: if ($cancreate{$type} eq 'none') {
6964: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6965: } elsif ($cancreate{$type} eq 'any') {
6966: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6967: } elsif ($cancreate{$type} eq 'official') {
6968: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6969: } elsif ($cancreate{$type} eq 'unofficial') {
6970: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6971: }
1.34 raeburn 6972: }
6973: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6974: }
6975: }
6976: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6977: my ($rules,$ruleorder) =
6978: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6979: my $chgtext = '<ul>';
6980: foreach my $type (@username_rule) {
6981: if (ref($rules->{$type}) eq 'HASH') {
6982: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6983: }
6984: }
6985: $chgtext .= '</ul>';
6986: if (@username_rule > 0) {
6987: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6988: } else {
1.28 raeburn 6989: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6990: }
6991: }
1.32 raeburn 6992: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6993: my ($idrules,$idruleorder) =
6994: &Apache::lonnet::inst_userrules($dom,'id');
6995: my $chgtext = '<ul>';
6996: foreach my $type (@id_rule) {
6997: if (ref($idrules->{$type}) eq 'HASH') {
6998: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6999: }
7000: }
7001: $chgtext .= '</ul>';
7002: if (@id_rule > 0) {
7003: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7004: } else {
7005: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7006: }
7007: }
1.43 raeburn 7008: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7009: my ($emailrules,$emailruleorder) =
7010: &Apache::lonnet::inst_userrules($dom,'email');
7011: my $chgtext = '<ul>';
7012: foreach my $type (@email_rule) {
7013: if (ref($emailrules->{$type}) eq 'HASH') {
7014: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7015: }
7016: }
7017: $chgtext .= '</ul>';
7018: if (@email_rule > 0) {
7019: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7020: } else {
7021: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7022: }
7023: }
7024:
1.28 raeburn 7025: my %authname = &authtype_names();
7026: my %context_title = &context_names();
7027: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7028: my $chgtext = '<ul>';
7029: foreach my $type (@{$changes{'authtypes'}}) {
7030: my @allowed;
7031: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7032: foreach my $auth (@authtypes) {
7033: if ($authhash{$type}{$auth}) {
7034: push(@allowed,$authname{$auth});
7035: }
7036: }
1.43 raeburn 7037: if (@allowed > 0) {
7038: $chgtext .= join(', ',@allowed).'</li>';
7039: } else {
7040: $chgtext .= &mt('none').'</li>';
7041: }
1.28 raeburn 7042: }
7043: $chgtext .= '</ul>';
7044: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7045: $resulttext .= '</li>';
7046: }
1.27 raeburn 7047: $resulttext .= '</ul>';
7048: } else {
1.28 raeburn 7049: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7050: }
7051: } else {
7052: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7053: &mt('An error occurred: [_1]',$putresult).'</span>';
7054: }
1.43 raeburn 7055: if ($warningmsg ne '') {
7056: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7057: }
1.23 raeburn 7058: return $resulttext;
7059: }
7060:
1.160.6.5 raeburn 7061: sub process_captcha {
7062: my ($container,$changes,$newsettings,$current) = @_;
7063: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7064: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7065: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7066: $newsettings->{'captcha'} = 'original';
7067: }
7068: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7069: if ($container eq 'cancreate') {
7070: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7071: push(@{$changes->{'cancreate'}},'captcha');
7072: } elsif (!defined($changes->{'cancreate'})) {
7073: $changes->{'cancreate'} = ['captcha'];
7074: }
7075: } else {
7076: $changes->{'captcha'} = 1;
7077: }
7078: }
7079: my ($newpub,$newpriv,$currpub,$currpriv);
7080: if ($newsettings->{'captcha'} eq 'recaptcha') {
7081: $newpub = $env{'form.'.$container.'_recaptchapub'};
7082: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7083: $newpub =~ s/\W//g;
7084: $newpriv =~ s/\W//g;
7085: $newsettings->{'recaptchakeys'} = {
7086: public => $newpub,
7087: private => $newpriv,
7088: };
7089: }
7090: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7091: $currpub = $current->{'recaptchakeys'}{'public'};
7092: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7093: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7094: $newsettings->{'recaptchakeys'} = {
7095: public => '',
7096: private => '',
7097: }
7098: }
1.160.6.5 raeburn 7099: }
7100: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7101: if ($container eq 'cancreate') {
7102: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7103: push(@{$changes->{'cancreate'}},'recaptchakeys');
7104: } elsif (!defined($changes->{'cancreate'})) {
7105: $changes->{'cancreate'} = ['recaptchakeys'];
7106: }
7107: } else {
7108: $changes->{'recaptchakeys'} = 1;
7109: }
7110: }
7111: return;
7112: }
7113:
1.33 raeburn 7114: sub modify_usermodification {
7115: my ($dom,%domconfig) = @_;
7116: my ($resulttext,%curr_usermodification,%changes);
7117: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7118: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7119: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7120: }
7121: }
1.63 raeburn 7122: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7123: my %context_title = (
7124: author => 'In author context',
7125: course => 'In course context',
1.63 raeburn 7126: selfcreate => 'When self creating account',
1.33 raeburn 7127: );
7128: my @fields = ('lastname','firstname','middlename','generation',
7129: 'permanentemail','id');
7130: my %roles = (
7131: author => ['ca','aa'],
7132: course => ['st','ep','ta','in','cr'],
7133: );
1.63 raeburn 7134: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7135: if (ref($types) eq 'ARRAY') {
7136: push(@{$types},'default');
7137: $usertypes->{'default'} = $othertitle;
7138: }
7139: $roles{'selfcreate'} = $types;
1.33 raeburn 7140: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7141: my %modifyhash;
7142: foreach my $context (@contexts) {
7143: foreach my $role (@{$roles{$context}}) {
7144: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7145: foreach my $item (@fields) {
7146: if (grep(/^\Q$item\E$/,@modifiable)) {
7147: $modifyhash{$context}{$role}{$item} = 1;
7148: } else {
7149: $modifyhash{$context}{$role}{$item} = 0;
7150: }
7151: }
7152: }
7153: if (ref($curr_usermodification{$context}) eq 'HASH') {
7154: foreach my $role (@{$roles{$context}}) {
7155: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7156: foreach my $field (@fields) {
7157: if ($modifyhash{$context}{$role}{$field} ne
7158: $curr_usermodification{$context}{$role}{$field}) {
7159: push(@{$changes{$context}},$role);
7160: last;
7161: }
7162: }
7163: }
7164: }
7165: } else {
7166: foreach my $context (@contexts) {
7167: foreach my $role (@{$roles{$context}}) {
7168: push(@{$changes{$context}},$role);
7169: }
7170: }
7171: }
7172: }
7173: my %usermodification_hash = (
7174: usermodification => \%modifyhash,
7175: );
7176: my $putresult = &Apache::lonnet::put_dom('configuration',
7177: \%usermodification_hash,$dom);
7178: if ($putresult eq 'ok') {
7179: if (keys(%changes) > 0) {
7180: $resulttext = &mt('Changes made: ').'<ul>';
7181: foreach my $context (@contexts) {
7182: if (ref($changes{$context}) eq 'ARRAY') {
7183: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7184: if (ref($changes{$context}) eq 'ARRAY') {
7185: foreach my $role (@{$changes{$context}}) {
7186: my $rolename;
1.63 raeburn 7187: if ($context eq 'selfcreate') {
7188: $rolename = $role;
7189: if (ref($usertypes) eq 'HASH') {
7190: if ($usertypes->{$role} ne '') {
7191: $rolename = $usertypes->{$role};
7192: }
7193: }
1.33 raeburn 7194: } else {
1.63 raeburn 7195: if ($role eq 'cr') {
7196: $rolename = &mt('Custom');
7197: } else {
7198: $rolename = &Apache::lonnet::plaintext($role);
7199: }
1.33 raeburn 7200: }
7201: my @modifiable;
1.63 raeburn 7202: if ($context eq 'selfcreate') {
1.126 bisitz 7203: $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 7204: } else {
7205: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7206: }
1.33 raeburn 7207: foreach my $field (@fields) {
7208: if ($modifyhash{$context}{$role}{$field}) {
7209: push(@modifiable,$fieldtitles{$field});
7210: }
7211: }
7212: if (@modifiable > 0) {
7213: $resulttext .= join(', ',@modifiable);
7214: } else {
7215: $resulttext .= &mt('none');
7216: }
7217: $resulttext .= '</li>';
7218: }
7219: $resulttext .= '</ul></li>';
7220: }
7221: }
7222: }
7223: $resulttext .= '</ul>';
7224: } else {
7225: $resulttext = &mt('No changes made to user modification settings');
7226: }
7227: } else {
7228: $resulttext = '<span class="LC_error">'.
7229: &mt('An error occurred: [_1]',$putresult).'</span>';
7230: }
7231: return $resulttext;
7232: }
7233:
1.43 raeburn 7234: sub modify_defaults {
7235: my ($dom,$r) = @_;
7236: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7237: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7238: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7239: my @authtypes = ('internal','krb4','krb5','localauth');
7240: foreach my $item (@items) {
7241: $newvalues{$item} = $env{'form.'.$item};
7242: if ($item eq 'auth_def') {
7243: if ($newvalues{$item} ne '') {
7244: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7245: push(@errors,$item);
7246: }
7247: }
7248: } elsif ($item eq 'lang_def') {
7249: if ($newvalues{$item} ne '') {
7250: if ($newvalues{$item} =~ /^(\w+)/) {
7251: my $langcode = $1;
1.103 raeburn 7252: if ($langcode ne 'x_chef') {
7253: if (code2language($langcode) eq '') {
7254: push(@errors,$item);
7255: }
1.43 raeburn 7256: }
7257: } else {
7258: push(@errors,$item);
7259: }
7260: }
1.54 raeburn 7261: } elsif ($item eq 'timezone_def') {
7262: if ($newvalues{$item} ne '') {
1.62 raeburn 7263: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7264: push(@errors,$item);
7265: }
7266: }
1.68 raeburn 7267: } elsif ($item eq 'datelocale_def') {
7268: if ($newvalues{$item} ne '') {
7269: my @datelocale_ids = DateTime::Locale->ids();
7270: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7271: push(@errors,$item);
7272: }
7273: }
1.141 raeburn 7274: } elsif ($item eq 'portal_def') {
7275: if ($newvalues{$item} ne '') {
7276: 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])\/?$/) {
7277: push(@errors,$item);
7278: }
7279: }
1.43 raeburn 7280: }
7281: if (grep(/^\Q$item\E$/,@errors)) {
7282: $newvalues{$item} = $domdefaults{$item};
7283: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7284: $changes{$item} = 1;
7285: }
1.72 raeburn 7286: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7287: }
7288: my %defaults_hash = (
1.72 raeburn 7289: defaults => \%newvalues,
7290: );
1.43 raeburn 7291: my $title = &defaults_titles();
7292: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7293: $dom);
7294: if ($putresult eq 'ok') {
7295: if (keys(%changes) > 0) {
7296: $resulttext = &mt('Changes made:').'<ul>';
7297: my $version = $r->dir_config('lonVersion');
7298: 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";
7299: foreach my $item (sort(keys(%changes))) {
7300: my $value = $env{'form.'.$item};
7301: if ($value eq '') {
7302: $value = &mt('none');
7303: } elsif ($item eq 'auth_def') {
7304: my %authnames = &authtype_names();
7305: my %shortauth = (
7306: internal => 'int',
7307: krb4 => 'krb4',
7308: krb5 => 'krb5',
7309: localauth => 'loc',
7310: );
7311: $value = $authnames{$shortauth{$value}};
7312: }
7313: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7314: $mailmsgtext .= "$title->{$item} set to $value\n";
7315: }
7316: $resulttext .= '</ul>';
7317: $mailmsgtext .= "\n";
7318: my $cachetime = 24*60*60;
1.72 raeburn 7319: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7320: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7321: my $sysmail = $r->dir_config('lonSysEMail');
7322: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7323: }
1.43 raeburn 7324: } else {
1.54 raeburn 7325: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7326: }
7327: } else {
7328: $resulttext = '<span class="LC_error">'.
7329: &mt('An error occurred: [_1]',$putresult).'</span>';
7330: }
7331: if (@errors > 0) {
7332: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7333: foreach my $item (@errors) {
7334: $resulttext .= ' "'.$title->{$item}.'",';
7335: }
7336: $resulttext =~ s/,$//;
7337: }
7338: return $resulttext;
7339: }
7340:
1.46 raeburn 7341: sub modify_scantron {
1.48 raeburn 7342: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7343: my ($resulttext,%confhash,%changes,$errors);
7344: my $custom = 'custom.tab';
7345: my $default = 'default.tab';
7346: my $servadm = $r->dir_config('lonAdmEMail');
7347: my ($configuserok,$author_ok,$switchserver) =
7348: &config_check($dom,$confname,$servadm);
7349: if ($env{'form.scantronformat.filename'} ne '') {
7350: my $error;
7351: if ($configuserok eq 'ok') {
7352: if ($switchserver) {
1.130 raeburn 7353: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7354: } else {
7355: if ($author_ok eq 'ok') {
7356: my ($result,$scantronurl) =
7357: &publishlogo($r,'upload','scantronformat',$dom,
7358: $confname,'scantron','','',$custom);
7359: if ($result eq 'ok') {
7360: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7361: $changes{'scantronformat'} = 1;
1.46 raeburn 7362: } else {
7363: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7364: }
7365: } else {
7366: $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);
7367: }
7368: }
7369: } else {
7370: $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);
7371: }
7372: if ($error) {
7373: &Apache::lonnet::logthis($error);
7374: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7375: }
7376: }
1.48 raeburn 7377: if (ref($domconfig{'scantron'}) eq 'HASH') {
7378: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7379: if ($env{'form.scantronformat_del'}) {
7380: $confhash{'scantron'}{'scantronformat'} = '';
7381: $changes{'scantronformat'} = 1;
1.46 raeburn 7382: }
7383: }
7384: }
7385: if (keys(%confhash) > 0) {
7386: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7387: $dom);
7388: if ($putresult eq 'ok') {
7389: if (keys(%changes) > 0) {
1.48 raeburn 7390: if (ref($confhash{'scantron'}) eq 'HASH') {
7391: $resulttext = &mt('Changes made:').'<ul>';
7392: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7393: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7394: } else {
1.130 raeburn 7395: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7396: }
1.48 raeburn 7397: $resulttext .= '</ul>';
7398: } else {
1.130 raeburn 7399: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7400: }
7401: $resulttext .= '</ul>';
7402: &Apache::loncommon::devalidate_domconfig_cache($dom);
7403: } else {
1.130 raeburn 7404: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7405: }
7406: } else {
7407: $resulttext = '<span class="LC_error">'.
7408: &mt('An error occurred: [_1]',$putresult).'</span>';
7409: }
7410: } else {
1.130 raeburn 7411: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7412: }
7413: if ($errors) {
7414: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7415: $errors.'</ul>';
7416: }
7417: return $resulttext;
7418: }
7419:
1.48 raeburn 7420: sub modify_coursecategories {
7421: my ($dom,%domconfig) = @_;
1.57 raeburn 7422: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7423: $cathash);
1.48 raeburn 7424: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7425: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7426: $cathash = $domconfig{'coursecategories'}{'cats'};
7427: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7428: $changes{'togglecats'} = 1;
7429: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7430: }
7431: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7432: $changes{'categorize'} = 1;
7433: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7434: }
1.120 raeburn 7435: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7436: $changes{'togglecatscomm'} = 1;
7437: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7438: }
7439: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7440: $changes{'categorizecomm'} = 1;
7441: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7442: }
1.57 raeburn 7443: } else {
7444: $changes{'togglecats'} = 1;
7445: $changes{'categorize'} = 1;
1.124 raeburn 7446: $changes{'togglecatscomm'} = 1;
7447: $changes{'categorizecomm'} = 1;
1.87 raeburn 7448: $domconfig{'coursecategories'} = {
7449: togglecats => $env{'form.togglecats'},
7450: categorize => $env{'form.categorize'},
1.124 raeburn 7451: togglecatscomm => $env{'form.togglecatscomm'},
7452: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7453: };
1.57 raeburn 7454: }
7455: if (ref($cathash) eq 'HASH') {
7456: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7457: push (@deletecategory,'instcode::0');
7458: }
1.120 raeburn 7459: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7460: push(@deletecategory,'communities::0');
7461: }
1.48 raeburn 7462: }
1.57 raeburn 7463: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7464: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7465: if (@deletecategory > 0) {
7466: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7467: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7468: foreach my $item (@deletecategory) {
1.57 raeburn 7469: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7470: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7471: $deletions{$item} = 1;
1.57 raeburn 7472: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7473: }
7474: }
7475: }
1.57 raeburn 7476: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7477: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7478: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7479: $reorderings{$item} = 1;
1.57 raeburn 7480: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7481: }
7482: if ($env{'form.addcategory_name_'.$item} ne '') {
7483: my $newcat = $env{'form.addcategory_name_'.$item};
7484: my $newdepth = $depth+1;
7485: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7486: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7487: $adds{$newitem} = 1;
7488: }
7489: if ($env{'form.subcat_'.$item} ne '') {
7490: my $newcat = $env{'form.subcat_'.$item};
7491: my $newdepth = $depth+1;
7492: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7493: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7494: $adds{$newitem} = 1;
7495: }
7496: }
7497: }
7498: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7499: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7500: my $newitem = 'instcode::0';
1.57 raeburn 7501: if ($cathash->{$newitem} eq '') {
7502: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7503: $adds{$newitem} = 1;
7504: }
7505: } else {
7506: my $newitem = 'instcode::0';
1.57 raeburn 7507: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7508: $adds{$newitem} = 1;
7509: }
7510: }
1.120 raeburn 7511: if ($env{'form.communities'} eq '1') {
7512: if (ref($cathash) eq 'HASH') {
7513: my $newitem = 'communities::0';
7514: if ($cathash->{$newitem} eq '') {
7515: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7516: $adds{$newitem} = 1;
7517: }
7518: } else {
7519: my $newitem = 'communities::0';
7520: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7521: $adds{$newitem} = 1;
7522: }
7523: }
1.48 raeburn 7524: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7525: if (($env{'form.addcategory_name'} ne 'instcode') &&
7526: ($env{'form.addcategory_name'} ne 'communities')) {
7527: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7528: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7529: $adds{$newitem} = 1;
7530: }
1.48 raeburn 7531: }
1.57 raeburn 7532: my $putresult;
1.48 raeburn 7533: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7534: if (keys(%deletions) > 0) {
7535: foreach my $key (keys(%deletions)) {
7536: if ($predelallitems{$key} ne '') {
7537: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7538: }
7539: }
7540: }
7541: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7542: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7543: if (ref($chkcats[0]) eq 'ARRAY') {
7544: my $depth = 0;
7545: my $chg = 0;
7546: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7547: my $name = $chkcats[0][$i];
7548: my $item;
7549: if ($name eq '') {
7550: $chg ++;
7551: } else {
7552: $item = &escape($name).'::0';
7553: if ($chg) {
1.57 raeburn 7554: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7555: }
7556: $depth ++;
1.57 raeburn 7557: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7558: $depth --;
7559: }
7560: }
7561: }
1.57 raeburn 7562: }
7563: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7564: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7565: if ($putresult eq 'ok') {
1.57 raeburn 7566: my %title = (
1.120 raeburn 7567: togglecats => 'Show/Hide a course in catalog',
7568: categorize => 'Assign a category to a course',
7569: togglecatscomm => 'Show/Hide a community in catalog',
7570: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7571: );
7572: my %level = (
1.120 raeburn 7573: dom => 'set in Domain ("Modify Course/Community")',
7574: crs => 'set in Course ("Course Configuration")',
7575: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7576: );
1.48 raeburn 7577: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7578: if ($changes{'togglecats'}) {
7579: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7580: }
7581: if ($changes{'categorize'}) {
7582: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7583: }
1.120 raeburn 7584: if ($changes{'togglecatscomm'}) {
7585: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7586: }
7587: if ($changes{'categorizecomm'}) {
7588: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7589: }
1.57 raeburn 7590: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7591: my $cathash;
7592: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7593: $cathash = $domconfig{'coursecategories'}{'cats'};
7594: } else {
7595: $cathash = {};
7596: }
7597: my (@cats,@trails,%allitems);
7598: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7599: if (keys(%deletions) > 0) {
7600: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7601: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7602: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7603: }
7604: $resulttext .= '</ul></li>';
7605: }
7606: if (keys(%reorderings) > 0) {
7607: my %sort_by_trail;
7608: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7609: foreach my $key (keys(%reorderings)) {
7610: if ($allitems{$key} ne '') {
7611: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7612: }
1.48 raeburn 7613: }
1.57 raeburn 7614: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7615: $resulttext .= '<li>'.$trails[$trail].'</li>';
7616: }
7617: $resulttext .= '</ul></li>';
1.48 raeburn 7618: }
1.57 raeburn 7619: if (keys(%adds) > 0) {
7620: my %sort_by_trail;
7621: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7622: foreach my $key (keys(%adds)) {
7623: if ($allitems{$key} ne '') {
7624: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7625: }
7626: }
7627: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7628: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7629: }
1.57 raeburn 7630: $resulttext .= '</ul></li>';
1.48 raeburn 7631: }
7632: }
7633: $resulttext .= '</ul>';
7634: } else {
7635: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7636: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7637: }
7638: } else {
1.120 raeburn 7639: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7640: }
7641: return $resulttext;
7642: }
7643:
1.69 raeburn 7644: sub modify_serverstatuses {
7645: my ($dom,%domconfig) = @_;
7646: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7647: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7648: %currserverstatus = %{$domconfig{'serverstatuses'}};
7649: }
7650: my @pages = &serverstatus_pages();
7651: foreach my $type (@pages) {
7652: $newserverstatus{$type}{'namedusers'} = '';
7653: $newserverstatus{$type}{'machines'} = '';
7654: if (defined($env{'form.'.$type.'_namedusers'})) {
7655: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7656: my @okusers;
7657: foreach my $user (@users) {
7658: my ($uname,$udom) = split(/:/,$user);
7659: if (($udom =~ /^$match_domain$/) &&
7660: (&Apache::lonnet::domain($udom)) &&
7661: ($uname =~ /^$match_username$/)) {
7662: if (!grep(/^\Q$user\E/,@okusers)) {
7663: push(@okusers,$user);
7664: }
7665: }
7666: }
7667: if (@okusers > 0) {
7668: @okusers = sort(@okusers);
7669: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7670: }
7671: }
7672: if (defined($env{'form.'.$type.'_machines'})) {
7673: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7674: my @okmachines;
7675: foreach my $ip (@machines) {
7676: my @parts = split(/\./,$ip);
7677: next if (@parts < 4);
7678: my $badip = 0;
7679: for (my $i=0; $i<4; $i++) {
7680: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7681: $badip = 1;
7682: last;
7683: }
7684: }
7685: if (!$badip) {
7686: push(@okmachines,$ip);
7687: }
7688: }
7689: @okmachines = sort(@okmachines);
7690: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7691: }
7692: }
7693: my %serverstatushash = (
7694: serverstatuses => \%newserverstatus,
7695: );
7696: foreach my $type (@pages) {
1.83 raeburn 7697: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7698: my (@current,@new);
1.83 raeburn 7699: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7700: if ($currserverstatus{$type}{$setting} ne '') {
7701: @current = split(/,/,$currserverstatus{$type}{$setting});
7702: }
7703: }
7704: if ($newserverstatus{$type}{$setting} ne '') {
7705: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7706: }
7707: if (@current > 0) {
7708: if (@new > 0) {
7709: foreach my $item (@current) {
7710: if (!grep(/^\Q$item\E$/,@new)) {
7711: $changes{$type}{$setting} = 1;
1.82 raeburn 7712: last;
7713: }
7714: }
1.84 raeburn 7715: foreach my $item (@new) {
7716: if (!grep(/^\Q$item\E$/,@current)) {
7717: $changes{$type}{$setting} = 1;
7718: last;
1.82 raeburn 7719: }
7720: }
7721: } else {
1.83 raeburn 7722: $changes{$type}{$setting} = 1;
1.69 raeburn 7723: }
1.83 raeburn 7724: } elsif (@new > 0) {
7725: $changes{$type}{$setting} = 1;
1.69 raeburn 7726: }
7727: }
7728: }
7729: if (keys(%changes) > 0) {
1.81 raeburn 7730: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7731: my $putresult = &Apache::lonnet::put_dom('configuration',
7732: \%serverstatushash,$dom);
7733: if ($putresult eq 'ok') {
7734: $resulttext .= &mt('Changes made:').'<ul>';
7735: foreach my $type (@pages) {
1.84 raeburn 7736: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7737: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7738: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7739: if ($newserverstatus{$type}{'namedusers'} eq '') {
7740: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7741: } else {
7742: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7743: }
1.84 raeburn 7744: }
7745: if ($changes{$type}{'machines'}) {
1.69 raeburn 7746: if ($newserverstatus{$type}{'machines'} eq '') {
7747: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7748: } else {
7749: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7750: }
7751:
7752: }
7753: $resulttext .= '</ul></li>';
7754: }
7755: }
7756: $resulttext .= '</ul>';
7757: } else {
7758: $resulttext = '<span class="LC_error">'.
7759: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7760:
7761: }
7762: } else {
7763: $resulttext = &mt('No changes made to access to server status pages');
7764: }
7765: return $resulttext;
7766: }
7767:
1.118 jms 7768: sub modify_helpsettings {
1.122 jms 7769: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7770: my ($resulttext,$errors,%changes,%helphash);
7771: my %defaultchecked = ('submitbugs' => 'on');
7772: my @offon = ('off','on');
1.118 jms 7773: my @toggles = ('submitbugs');
7774: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7775: foreach my $item (@toggles) {
1.160.6.5 raeburn 7776: if ($defaultchecked{$item} eq 'on') {
7777: if ($domconfig{'helpsettings'}{$item} eq '') {
7778: if ($env{'form.'.$item} eq '0') {
7779: $changes{$item} = 1;
7780: }
7781: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7782: $changes{$item} = 1;
7783: }
7784: } elsif ($defaultchecked{$item} eq 'off') {
7785: if ($domconfig{'helpsettings'}{$item} eq '') {
7786: if ($env{'form.'.$item} eq '1') {
7787: $changes{$item} = 1;
7788: }
7789: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7790: $changes{$item} = 1;
7791: }
7792: }
7793: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7794: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7795: }
7796: }
1.118 jms 7797: }
1.123 jms 7798: my $putresult;
7799: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7800: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7801: if ($putresult eq 'ok') {
7802: $resulttext = &mt('Changes made:').'<ul>';
7803: foreach my $item (sort(keys(%changes))) {
7804: if ($item eq 'submitbugs') {
7805: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7806: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7807: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7808: }
7809: }
7810: $resulttext .= '</ul>';
7811: } else {
7812: $resulttext = &mt('No changes made to help settings');
7813: $errors .= '<li><span class="LC_error">'.
7814: &mt('An error occurred storing the settings: [_1]',
7815: $putresult).'</span></li>';
7816: }
1.118 jms 7817: }
7818: if ($errors) {
1.160.6.5 raeburn 7819: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7820: $errors.'</ul>';
7821: }
7822: return $resulttext;
7823: }
7824:
1.121 raeburn 7825: sub modify_coursedefaults {
7826: my ($dom,%domconfig) = @_;
7827: my ($resulttext,$errors,%changes,%defaultshash);
7828: my %defaultchecked = ('canuse_pdfforms' => 'off');
7829: my @offon = ('off','on');
7830: my @toggles = ('canuse_pdfforms');
7831:
7832: $defaultshash{'coursedefaults'} = {};
7833:
7834: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7835: if ($domconfig{'coursedefaults'} eq '') {
7836: $domconfig{'coursedefaults'} = {};
7837: }
7838: }
7839:
7840: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7841: foreach my $item (@toggles) {
7842: if ($defaultchecked{$item} eq 'on') {
7843: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7844: ($env{'form.'.$item} eq '0')) {
7845: $changes{$item} = 1;
7846: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7847: $changes{$item} = 1;
7848: }
7849: } elsif ($defaultchecked{$item} eq 'off') {
7850: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7851: ($env{'form.'.$item} eq '1')) {
7852: $changes{$item} = 1;
7853: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7854: $changes{$item} = 1;
7855: }
7856: }
7857: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7858: }
1.139 raeburn 7859: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7860: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7861: $newdefresponder =~ s/\D//g;
7862: if ($newdefresponder eq '' || $newdefresponder < 1) {
7863: $newdefresponder = 1;
7864: }
7865: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7866: if ($currdefresponder ne $newdefresponder) {
7867: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7868: $changes{'anonsurvey_threshold'} = 1;
7869: }
7870: }
1.121 raeburn 7871: }
7872: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7873: $dom);
7874: if ($putresult eq 'ok') {
7875: if (keys(%changes) > 0) {
7876: if ($changes{'canuse_pdfforms'}) {
7877: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7878: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7879: my $cachetime = 24*60*60;
7880: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7881: }
7882: $resulttext = &mt('Changes made:').'<ul>';
7883: foreach my $item (sort(keys(%changes))) {
7884: if ($item eq 'canuse_pdfforms') {
7885: if ($env{'form.'.$item} eq '1') {
7886: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7887: } else {
7888: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7889: }
1.139 raeburn 7890: } elsif ($item eq 'anonsurvey_threshold') {
7891: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7892: }
1.121 raeburn 7893: }
7894: $resulttext .= '</ul>';
7895: } else {
7896: $resulttext = &mt('No changes made to course defaults');
7897: }
7898: } else {
7899: $resulttext = '<span class="LC_error">'.
7900: &mt('An error occurred: [_1]',$putresult).'</span>';
7901: }
7902: return $resulttext;
7903: }
7904:
1.137 raeburn 7905: sub modify_usersessions {
7906: my ($dom,%domconfig) = @_;
1.145 raeburn 7907: my @hostingtypes = ('version','excludedomain','includedomain');
7908: my @offloadtypes = ('primary','default');
7909: my %types = (
7910: remote => \@hostingtypes,
7911: hosted => \@hostingtypes,
7912: spares => \@offloadtypes,
7913: );
7914: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7915: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7916: my (%by_ip,%by_location,@intdoms);
7917: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7918: my @locations = sort(keys(%by_location));
1.137 raeburn 7919: my (%defaultshash,%changes);
7920: foreach my $prefix (@prefixes) {
7921: $defaultshash{'usersessions'}{$prefix} = {};
7922: }
7923: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7924: my $resulttext;
1.138 raeburn 7925: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7926: foreach my $prefix (@prefixes) {
1.145 raeburn 7927: next if ($prefix eq 'spares');
7928: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7929: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7930: if ($type eq 'version') {
7931: my $value = $env{'form.'.$prefix.'_'.$type};
7932: my $okvalue;
7933: if ($value ne '') {
7934: if (grep(/^\Q$value\E$/,@lcversions)) {
7935: $okvalue = $value;
7936: }
7937: }
7938: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7939: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7940: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7941: if ($inuse == 0) {
7942: $changes{$prefix}{$type} = 1;
7943: } else {
7944: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7945: $changes{$prefix}{$type} = 1;
7946: }
7947: if ($okvalue ne '') {
7948: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7949: }
7950: }
7951: } else {
7952: if (($inuse == 1) && ($okvalue ne '')) {
7953: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7954: $changes{$prefix}{$type} = 1;
7955: }
7956: }
7957: } else {
7958: if (($inuse == 1) && ($okvalue ne '')) {
7959: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7960: $changes{$prefix}{$type} = 1;
7961: }
7962: }
7963: } else {
7964: if (($inuse == 1) && ($okvalue ne '')) {
7965: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7966: $changes{$prefix}{$type} = 1;
7967: }
7968: }
7969: } else {
7970: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7971: my @okvals;
7972: foreach my $val (@vals) {
1.138 raeburn 7973: if ($val =~ /:/) {
7974: my @items = split(/:/,$val);
7975: foreach my $item (@items) {
7976: if (ref($by_location{$item}) eq 'ARRAY') {
7977: push(@okvals,$item);
7978: }
7979: }
7980: } else {
7981: if (ref($by_location{$val}) eq 'ARRAY') {
7982: push(@okvals,$val);
7983: }
1.137 raeburn 7984: }
7985: }
7986: @okvals = sort(@okvals);
7987: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7988: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7989: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7990: if ($inuse == 0) {
7991: $changes{$prefix}{$type} = 1;
7992: } else {
7993: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7994: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7995: if (@changed > 0) {
7996: $changes{$prefix}{$type} = 1;
7997: }
7998: }
7999: } else {
8000: if ($inuse == 1) {
8001: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8002: $changes{$prefix}{$type} = 1;
8003: }
8004: }
8005: } else {
8006: if ($inuse == 1) {
8007: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8008: $changes{$prefix}{$type} = 1;
8009: }
8010: }
8011: } else {
8012: if ($inuse == 1) {
8013: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8014: $changes{$prefix}{$type} = 1;
8015: }
8016: }
8017: }
8018: }
8019: }
1.145 raeburn 8020:
8021: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8022: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8023: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8024: my $savespares;
8025:
8026: foreach my $lonhost (sort(keys(%servers))) {
8027: my $serverhomeID =
8028: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8029: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8030: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8031: my %spareschg;
8032: foreach my $type (@{$types{'spares'}}) {
8033: my @okspares;
8034: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8035: foreach my $server (@checked) {
1.152 raeburn 8036: if (&Apache::lonnet::hostname($server) ne '') {
8037: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8038: unless (grep(/^\Q$server\E$/,@okspares)) {
8039: push(@okspares,$server);
8040: }
1.145 raeburn 8041: }
8042: }
8043: }
8044: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8045: my $newspare;
1.152 raeburn 8046: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8047: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8048: $newspare = $new;
8049: }
8050: }
1.152 raeburn 8051: my @spares;
8052: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8053: @spares = sort(@okspares,$newspare);
8054: } else {
8055: @spares = sort(@okspares);
8056: }
8057: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8058: if (ref($spareid{$lonhost}) eq 'HASH') {
8059: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8060: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8061: if (@diffs > 0) {
8062: $spareschg{$type} = 1;
8063: }
8064: }
8065: }
8066: }
8067: if (keys(%spareschg) > 0) {
8068: $changes{'spares'}{$lonhost} = \%spareschg;
8069: }
8070: }
8071:
8072: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8073: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8074: if (ref($changes{'spares'}) eq 'HASH') {
8075: if (keys(%{$changes{'spares'}}) > 0) {
8076: $savespares = 1;
8077: }
8078: }
8079: } else {
8080: $savespares = 1;
8081: }
8082: }
8083:
1.147 raeburn 8084: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8085: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8086: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8087: $dom);
8088: if ($putresult eq 'ok') {
8089: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8090: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8091: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8092: }
8093: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8094: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8095: }
8096: }
8097: my $cachetime = 24*60*60;
8098: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8099: if (keys(%changes) > 0) {
8100: my %lt = &usersession_titles();
8101: $resulttext = &mt('Changes made:').'<ul>';
8102: foreach my $prefix (@prefixes) {
8103: if (ref($changes{$prefix}) eq 'HASH') {
8104: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8105: if ($prefix eq 'spares') {
8106: if (ref($changes{$prefix}) eq 'HASH') {
8107: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8108: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8109: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8110: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8111: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8112: foreach my $type (@{$types{$prefix}}) {
8113: if ($changes{$prefix}{$lonhost}{$type}) {
8114: my $offloadto = &mt('None');
8115: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8116: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8117: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8118: }
1.145 raeburn 8119: }
1.147 raeburn 8120: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8121: }
1.137 raeburn 8122: }
8123: }
1.147 raeburn 8124: $resulttext .= '</li>';
1.137 raeburn 8125: }
8126: }
1.147 raeburn 8127: } else {
8128: foreach my $type (@{$types{$prefix}}) {
8129: if (defined($changes{$prefix}{$type})) {
8130: my $newvalue;
8131: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8132: if (ref($defaultshash{'usersessions'}{$prefix})) {
8133: if ($type eq 'version') {
8134: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8135: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8136: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8137: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8138: }
1.145 raeburn 8139: }
8140: }
8141: }
1.147 raeburn 8142: if ($newvalue eq '') {
8143: if ($type eq 'version') {
8144: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8145: } else {
8146: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8147: }
1.145 raeburn 8148: } else {
1.147 raeburn 8149: if ($type eq 'version') {
8150: $newvalue .= ' '.&mt('(or later)');
8151: }
8152: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8153: }
1.137 raeburn 8154: }
8155: }
8156: }
1.147 raeburn 8157: $resulttext .= '</ul>';
1.137 raeburn 8158: }
8159: }
1.147 raeburn 8160: $resulttext .= '</ul>';
8161: } else {
8162: $resulttext = $nochgmsg;
1.137 raeburn 8163: }
8164: } else {
8165: $resulttext = '<span class="LC_error">'.
8166: &mt('An error occurred: [_1]',$putresult).'</span>';
8167: }
8168: } else {
1.147 raeburn 8169: $resulttext = $nochgmsg;
1.137 raeburn 8170: }
8171: return $resulttext;
8172: }
8173:
1.150 raeburn 8174: sub modify_loadbalancing {
8175: my ($dom,%domconfig) = @_;
8176: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8177: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8178: my ($othertitle,$usertypes,$types) =
8179: &Apache::loncommon::sorted_inst_types($dom);
8180: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8181: my @sparestypes = ('primary','default');
8182: my %typetitles = &sparestype_titles();
8183: my $resulttext;
1.160.6.7 raeburn 8184: my (%currbalancer,%currtargets,%currrules,%existing);
8185: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8186: %existing = %{$domconfig{'loadbalancing'}};
8187: }
8188: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8189: \%currtargets,\%currrules);
8190: my ($saveloadbalancing,%defaultshash,%changes);
8191: my ($alltypes,$othertypes,$titles) =
8192: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8193: my %ruletitles = &offloadtype_text();
8194: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8195: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8196: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8197: if ($balancer eq '') {
8198: next;
8199: }
8200: if (!exists($servers{$balancer})) {
8201: if (exists($currbalancer{$balancer})) {
8202: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8203: }
1.160.6.7 raeburn 8204: next;
8205: }
8206: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8207: push(@{$changes{'delete'}},$balancer);
8208: next;
8209: }
8210: if (!exists($currbalancer{$balancer})) {
8211: push(@{$changes{'add'}},$balancer);
8212: }
8213: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8214: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8215: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8216: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8217: $saveloadbalancing = 1;
8218: }
8219: foreach my $sparetype (@sparestypes) {
8220: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8221: my @offloadto;
8222: foreach my $target (@targets) {
8223: if (($servers{$target}) && ($target ne $balancer)) {
8224: if ($sparetype eq 'default') {
8225: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8226: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8227: }
8228: }
1.160.6.7 raeburn 8229: unless(grep(/^\Q$target\E$/,@offloadto)) {
8230: push(@offloadto,$target);
8231: }
1.150 raeburn 8232: }
1.160.6.7 raeburn 8233: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8234: }
8235: }
1.160.6.7 raeburn 8236: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8237: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8238: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8239: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8240: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8241: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8242: }
1.160.6.7 raeburn 8243: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8244: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8245: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8246: }
8247: }
8248: }
8249: } else {
1.160.6.7 raeburn 8250: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8251: foreach my $sparetype (@sparestypes) {
8252: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8253: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8254: $changes{'curr'}{$balancer}{'targets'} = 1;
8255: }
1.150 raeburn 8256: }
8257: }
1.160.6.7 raeburn 8258: }
1.150 raeburn 8259: }
8260: my $ishomedom;
1.160.6.7 raeburn 8261: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8262: $ishomedom = 1;
1.150 raeburn 8263: }
8264: if (ref($alltypes) eq 'ARRAY') {
8265: foreach my $type (@{$alltypes}) {
8266: my $rule;
1.160.6.7 raeburn 8267: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8268: (!$ishomedom)) {
1.160.6.7 raeburn 8269: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8270: }
8271: if ($rule eq 'specific') {
8272: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8273: }
1.160.6.7 raeburn 8274: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8275: if (ref($currrules{$balancer}) eq 'HASH') {
8276: if ($rule ne $currrules{$balancer}{$type}) {
8277: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8278: }
8279: } elsif ($rule ne '') {
1.160.6.7 raeburn 8280: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8281: }
8282: }
8283: }
1.160.6.7 raeburn 8284: }
8285: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8286: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8287: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8288: $defaultshash{'loadbalancing'} = {};
8289: }
8290: my $putresult = &Apache::lonnet::put_dom('configuration',
8291: \%defaultshash,$dom);
8292:
8293: if ($putresult eq 'ok') {
8294: if (keys(%changes) > 0) {
8295: if (ref($changes{'delete'}) eq 'ARRAY') {
8296: foreach my $balancer (sort(@{$changes{'delete'}})) {
8297: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8298: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8299: }
1.160.6.7 raeburn 8300: }
8301: if (ref($changes{'add'}) eq 'ARRAY') {
8302: foreach my $balancer (sort(@{$changes{'add'}})) {
8303: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8304: }
8305: }
8306: if (ref($changes{'curr'}) eq 'HASH') {
8307: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8308: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8309: if ($changes{'curr'}{$balancer}{'targets'}) {
8310: my %offloadstr;
8311: foreach my $sparetype (@sparestypes) {
8312: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8313: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8314: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8315: }
8316: }
1.150 raeburn 8317: }
1.160.6.7 raeburn 8318: if (keys(%offloadstr) == 0) {
8319: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8320: } else {
1.160.6.7 raeburn 8321: my $showoffload;
8322: foreach my $sparetype (@sparestypes) {
8323: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8324: if (defined($offloadstr{$sparetype})) {
8325: $showoffload .= $offloadstr{$sparetype};
8326: } else {
8327: $showoffload .= &mt('None');
8328: }
8329: $showoffload .= (' 'x3);
8330: }
8331: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8332: }
8333: }
8334: }
1.160.6.7 raeburn 8335: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8336: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8337: foreach my $type (@{$alltypes}) {
8338: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8339: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8340: my $balancetext;
8341: if ($rule eq '') {
8342: $balancetext = $ruletitles{'default'};
8343: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8344: $balancetext = $ruletitles{$rule};
8345: } else {
8346: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8347: }
8348: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8349: }
8350: }
8351: }
8352: }
1.160.6.7 raeburn 8353: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8354: }
1.160.6.7 raeburn 8355: }
8356: if ($resulttext ne '') {
8357: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8358: } else {
8359: $resulttext = $nochgmsg;
8360: }
8361: } else {
1.160.6.7 raeburn 8362: $resulttext = $nochgmsg;
1.150 raeburn 8363: }
8364: } else {
1.160.6.7 raeburn 8365: $resulttext = '<span class="LC_error">'.
8366: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8367: }
8368: } else {
1.160.6.7 raeburn 8369: $resulttext = $nochgmsg;
1.150 raeburn 8370: }
8371: return $resulttext;
8372: }
8373:
1.48 raeburn 8374: sub recurse_check {
8375: my ($chkcats,$categories,$depth,$name) = @_;
8376: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8377: my $chg = 0;
8378: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8379: my $category = $chkcats->[$depth]{$name}[$j];
8380: my $item;
8381: if ($category eq '') {
8382: $chg ++;
8383: } else {
8384: my $deeper = $depth + 1;
8385: $item = &escape($category).':'.&escape($name).':'.$depth;
8386: if ($chg) {
8387: $categories->{$item} -= $chg;
8388: }
8389: &recurse_check($chkcats,$categories,$deeper,$category);
8390: $deeper --;
8391: }
8392: }
8393: }
8394: return;
8395: }
8396:
8397: sub recurse_cat_deletes {
8398: my ($item,$coursecategories,$deletions) = @_;
8399: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8400: my $subdepth = $depth + 1;
8401: if (ref($coursecategories) eq 'HASH') {
8402: foreach my $subitem (keys(%{$coursecategories})) {
8403: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8404: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8405: delete($coursecategories->{$subitem});
8406: $deletions->{$subitem} = 1;
8407: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8408: }
8409: }
8410: }
8411: return;
8412: }
8413:
1.125 raeburn 8414: sub get_active_dcs {
8415: my ($dom) = @_;
8416: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8417: my %domcoords;
8418: my $numdcs = 0;
8419: my $now = time;
8420: foreach my $server (keys(%dompersonnel)) {
8421: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8422: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8423: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8424: if (($end eq '') || ($end == 0) || ($end > $now)) {
8425: if ($start <= $now) {
8426: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8427: }
8428: }
8429: }
8430: }
8431: return %domcoords;
8432: }
8433:
8434: sub active_dc_picker {
8435: my ($dom,$curr_dc) = @_;
8436: my %domcoords = &get_active_dcs($dom);
8437: my @dcs = sort(keys(%domcoords));
8438: my $numdcs = scalar(@dcs);
8439: my $datatable;
8440: my $numinrow = 2;
8441: if ($numdcs > 1) {
8442: $datatable = '<table>';
8443: for (my $i=0; $i<@dcs; $i++) {
8444: my $rem = $i%($numinrow);
8445: if ($rem == 0) {
8446: if ($i > 0) {
8447: $datatable .= '</tr>';
8448: }
8449: $datatable .= '<tr>';
8450: }
8451: my $check = ' ';
8452: if ($curr_dc eq '') {
8453: if (!$i) {
8454: $check = ' checked="checked" ';
8455: }
8456: } elsif ($dcs[$i] eq $curr_dc) {
8457: $check = ' checked="checked" ';
8458: }
8459: if ($i == @dcs - 1) {
8460: my $colsleft = $numinrow - $rem;
8461: if ($colsleft > 1) {
8462: $datatable .= '<td colspan="'.$colsleft.'">';
8463: } else {
8464: $datatable .= '<td>';
8465: }
8466: } else {
8467: $datatable .= '<td>';
8468: }
8469: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8470: $datatable .= '<span class="LC_nobreak"><label>'.
8471: '<input type="radio" name="autocreate_xmldc"'.
8472: ' value="'.$dcs[$i].'"'.$check.'/>'.
8473: &Apache::loncommon::plainname($dcname,$dcdom).
1.160.6.13 raeburn 8474: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8475: '</label></span></td>';
8476: }
8477: $datatable .= '</tr></table>';
8478: } elsif (@dcs) {
8479: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8480: $dcs[0].'" />';
8481: }
8482: return ($numdcs,$datatable);
8483: }
8484:
1.137 raeburn 8485: sub usersession_titles {
8486: return &Apache::lonlocal::texthash(
8487: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8488: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8489: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8490: version => 'LON-CAPA version requirement',
1.138 raeburn 8491: excludedomain => 'Allow all, but exclude specific domains',
8492: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8493: primary => 'Primary (checked first)',
1.154 raeburn 8494: default => 'Default',
1.137 raeburn 8495: );
8496: }
8497:
1.152 raeburn 8498: sub id_for_thisdom {
8499: my (%servers) = @_;
8500: my %altids;
8501: foreach my $server (keys(%servers)) {
8502: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8503: if ($serverhome ne $server) {
8504: $altids{$serverhome} = $server;
8505: }
8506: }
8507: return %altids;
8508: }
8509:
1.150 raeburn 8510: sub count_servers {
8511: my ($currbalancer,%servers) = @_;
8512: my (@spares,$numspares);
8513: foreach my $lonhost (sort(keys(%servers))) {
8514: next if ($currbalancer eq $lonhost);
8515: push(@spares,$lonhost);
8516: }
8517: if ($currbalancer) {
8518: $numspares = scalar(@spares);
8519: } else {
8520: $numspares = scalar(@spares) - 1;
8521: }
8522: return ($numspares,@spares);
8523: }
8524:
8525: sub lonbalance_targets_js {
1.160.6.7 raeburn 8526: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8527: my $select = &mt('Select');
8528: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8529: if (ref($servers) eq 'HASH') {
8530: $alltargets = join("','",sort(keys(%{$servers})));
8531: my @homedoms;
8532: foreach my $server (sort(keys(%{$servers}))) {
8533: if (&Apache::lonnet::host_domain($server) eq $dom) {
8534: push(@homedoms,'1');
8535: } else {
8536: push(@homedoms,'0');
8537: }
8538: }
8539: $allishome = join("','",@homedoms);
8540: }
8541: if (ref($types) eq 'ARRAY') {
8542: if (@{$types} > 0) {
8543: @alltypes = @{$types};
8544: }
8545: }
8546: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8547: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8548: my (%currbalancer,%currtargets,%currrules,%existing);
8549: if (ref($settings) eq 'HASH') {
8550: %existing = %{$settings};
8551: }
8552: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8553: \%currtargets,\%currrules);
8554: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8555: return <<"END";
8556:
8557: <script type="text/javascript">
8558: // <![CDATA[
8559:
1.160.6.7 raeburn 8560: currBalancers = new Array('$balancers');
8561:
8562: function toggleTargets(balnum) {
8563: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8564: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8565: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8566: var prevbalancer = prevhostitem.value;
8567: var baltotal = document.getElementById('loadbalancing_total').value;
8568: prevhostitem.value = balancer;
8569: if (prevbalancer != '') {
8570: var prevIdx = currBalancers.indexOf(prevbalancer);
8571: if (prevIdx != -1) {
8572: currBalancers.splice(prevIdx,1);
8573: }
8574: }
1.150 raeburn 8575: if (balancer == '') {
1.160.6.7 raeburn 8576: hideSpares(balnum);
1.150 raeburn 8577: } else {
1.160.6.7 raeburn 8578: var currIdx = currBalancers.indexOf(balancer);
8579: if (currIdx == -1) {
8580: currBalancers.push(balancer);
8581: }
1.150 raeburn 8582: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8583: var ishomedom = homedoms[lonhostitem.selectedIndex];
8584: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8585: }
1.160.6.7 raeburn 8586: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8587: return;
8588: }
8589:
1.160.6.7 raeburn 8590: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8591: var alltargets = new Array('$alltargets');
8592: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8593: var offloadtypes = new Array('primary','default');
8594:
1.160.6.7 raeburn 8595: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8596: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8597:
1.151 raeburn 8598: for (var i=0; i<offloadtypes.length; i++) {
8599: var count = 0;
8600: for (var j=0; j<alltargets.length; j++) {
8601: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8602: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8603: item.value = alltargets[j];
8604: item.style.textAlign='left';
8605: item.style.textFace='normal';
8606: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8607: if (currBalancers.indexOf(alltargets[j]) == -1) {
8608: item.disabled = '';
8609: } else {
8610: item.disabled = 'disabled';
8611: item.checked = false;
8612: }
1.151 raeburn 8613: count ++;
8614: }
1.150 raeburn 8615: }
8616: }
1.151 raeburn 8617: for (var k=0; k<insttypes.length; k++) {
8618: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8619: if (ishomedom == 1) {
1.160.6.7 raeburn 8620: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8621: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8622: } else {
1.160.6.7 raeburn 8623: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8624: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8625:
8626: }
8627: } else {
1.160.6.7 raeburn 8628: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8629: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8630: }
1.151 raeburn 8631: if ((insttypes[k] != '_LC_external') &&
8632: ((insttypes[k] != '_LC_internetdom') ||
8633: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8634: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8635: item.options.length = 0;
8636: item.options[0] = new Option("","",true,true);
8637: var idx = 0;
1.151 raeburn 8638: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8639: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8640: idx ++;
8641: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8642:
1.150 raeburn 8643: }
8644: }
8645: }
8646: }
8647: return;
8648: }
8649:
1.160.6.7 raeburn 8650: function hideSpares(balnum) {
1.150 raeburn 8651: var alltargets = new Array('$alltargets');
8652: var insttypes = new Array('$allinsttypes');
8653: var offloadtypes = new Array('primary','default');
8654:
1.160.6.7 raeburn 8655: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8656: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8657:
8658: var total = alltargets.length - 1;
8659: for (var i=0; i<offloadtypes; i++) {
8660: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8661: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8662: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8663: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8664: }
1.150 raeburn 8665: }
8666: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8667: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8668: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8669: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8670: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8671: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8672: }
8673: }
8674: return;
8675: }
8676:
1.160.6.7 raeburn 8677: function checkOffloads(item,balnum,type) {
1.150 raeburn 8678: var alltargets = new Array('$alltargets');
8679: var offloadtypes = new Array('primary','default');
8680: if (item.checked) {
8681: var total = alltargets.length - 1;
8682: var other;
8683: if (type == offloadtypes[0]) {
1.151 raeburn 8684: other = offloadtypes[1];
1.150 raeburn 8685: } else {
1.151 raeburn 8686: other = offloadtypes[0];
1.150 raeburn 8687: }
8688: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8689: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8690: if (server == item.value) {
1.160.6.7 raeburn 8691: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8692: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8693: }
8694: }
8695: }
8696: }
8697: return;
8698: }
8699:
1.160.6.7 raeburn 8700: function singleServerToggle(balnum,type) {
8701: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8702: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 8703: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8704: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8705:
8706: } else {
1.160.6.7 raeburn 8707: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8708: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8709: }
8710: return;
8711: }
8712:
1.160.6.7 raeburn 8713: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8714: if (type == '_LC_external') {
8715: return;
8716: }
1.160.6.7 raeburn 8717: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8718: for (var i=0; i<typesRules.length; i++) {
8719: if (formname.elements[typesRules[i]].checked) {
8720: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 8721: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8722: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8723: } else {
1.160.6.7 raeburn 8724: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8725: }
8726: }
8727: }
8728: return;
8729: }
8730:
8731: function balancerDeleteChange(balnum) {
8732: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8733: var baltotal = document.getElementById('loadbalancing_total').value;
8734: var addtarget;
8735: var removetarget;
8736: var action = 'delete';
8737: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8738: var lonhost = hostitem.value;
8739: var currIdx = currBalancers.indexOf(lonhost);
8740: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8741: if (currIdx != -1) {
8742: currBalancers.splice(currIdx,1);
8743: }
8744: addtarget = lonhost;
8745: } else {
8746: if (currIdx == -1) {
8747: currBalancers.push(lonhost);
8748: }
8749: removetarget = lonhost;
8750: action = 'undelete';
8751: }
8752: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8753: }
8754: return;
8755: }
8756:
8757: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8758: if (baltotal > 1) {
8759: var offloadtypes = new Array('primary','default');
8760: var alltargets = new Array('$alltargets');
8761: var insttypes = new Array('$allinsttypes');
8762: for (var i=0; i<baltotal; i++) {
8763: if (i != balnum) {
8764: for (var j=0; j<offloadtypes.length; j++) {
8765: var total = alltargets.length - 1;
8766: for (var k=0; k<total; k++) {
8767: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8768: var server = serveritem.value;
8769: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8770: if (server == addtarget) {
8771: serveritem.disabled = '';
8772: }
8773: }
8774: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8775: if (server == removetarget) {
8776: serveritem.disabled = 'disabled';
8777: serveritem.checked = false;
8778: }
8779: }
8780: }
8781: }
8782: for (var j=0; j<insttypes.length; j++) {
8783: if (insttypes[j] != '_LC_external') {
8784: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8785: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8786: var currSel = singleserver.selectedIndex;
8787: var currVal = singleserver.options[currSel].value;
8788: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8789: var numoptions = singleserver.options.length;
8790: var needsnew = 1;
8791: for (var k=0; k<numoptions; k++) {
8792: if (singleserver.options[k] == addtarget) {
8793: needsnew = 0;
8794: break;
8795: }
8796: }
8797: if (needsnew == 1) {
8798: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8799: }
8800: }
8801: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8802: singleserver.options.length = 0;
8803: if ((currVal) && (currVal != removetarget)) {
8804: singleserver.options[0] = new Option("","",false,false);
8805: } else {
8806: singleserver.options[0] = new Option("","",true,true);
8807: }
8808: var idx = 0;
8809: for (var m=0; m<alltargets.length; m++) {
8810: if (currBalancers.indexOf(alltargets[m]) == -1) {
8811: idx ++;
8812: if (currVal == alltargets[m]) {
8813: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8814: } else {
8815: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8816: }
8817: }
8818: }
8819: }
8820: }
8821: }
8822: }
1.150 raeburn 8823: }
8824: }
8825: }
8826: return;
8827: }
8828:
1.152 raeburn 8829: // ]]>
8830: </script>
8831:
8832: END
8833: }
8834:
8835: sub new_spares_js {
8836: my @sparestypes = ('primary','default');
8837: my $types = join("','",@sparestypes);
8838: my $select = &mt('Select');
8839: return <<"END";
8840:
8841: <script type="text/javascript">
8842: // <![CDATA[
8843:
8844: function updateNewSpares(formname,lonhost) {
8845: var types = new Array('$types');
8846: var include = new Array();
8847: var exclude = new Array();
8848: for (var i=0; i<types.length; i++) {
8849: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8850: for (var j=0; j<spareboxes.length; j++) {
8851: if (formname.elements[spareboxes[j]].checked) {
8852: exclude.push(formname.elements[spareboxes[j]].value);
8853: } else {
8854: include.push(formname.elements[spareboxes[j]].value);
8855: }
8856: }
8857: }
8858: for (var i=0; i<types.length; i++) {
8859: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8860: var selIdx = newSpare.selectedIndex;
8861: var currnew = newSpare.options[selIdx].value;
8862: var okSpares = new Array();
8863: for (var j=0; j<newSpare.options.length; j++) {
8864: var possible = newSpare.options[j].value;
8865: if (possible != '') {
8866: if (exclude.indexOf(possible) == -1) {
8867: okSpares.push(possible);
8868: } else {
8869: if (currnew == possible) {
8870: selIdx = 0;
8871: }
8872: }
8873: }
8874: }
8875: for (var k=0; k<include.length; k++) {
8876: if (okSpares.indexOf(include[k]) == -1) {
8877: okSpares.push(include[k]);
8878: }
8879: }
8880: okSpares.sort();
8881: newSpare.options.length = 0;
8882: if (selIdx == 0) {
8883: newSpare.options[0] = new Option("$select","",true,true);
8884: } else {
8885: newSpare.options[0] = new Option("$select","",false,false);
8886: }
8887: for (var m=0; m<okSpares.length; m++) {
8888: var idx = m+1;
8889: var selThis = 0;
8890: if (selIdx != 0) {
8891: if (okSpares[m] == currnew) {
8892: selThis = 1;
8893: }
8894: }
8895: if (selThis == 1) {
8896: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8897: } else {
8898: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8899: }
8900: }
8901: }
8902: return;
8903: }
8904:
8905: function checkNewSpares(lonhost,type) {
8906: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8907: var chosen = newSpare.options[newSpare.selectedIndex].value;
8908: if (chosen != '') {
8909: var othertype;
8910: var othernewSpare;
8911: if (type == 'primary') {
8912: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8913: }
8914: if (type == 'default') {
8915: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8916: }
8917: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8918: othernewSpare.selectedIndex = 0;
8919: }
8920: }
8921: return;
8922: }
8923:
8924: // ]]>
8925: </script>
8926:
8927: END
8928:
8929: }
8930:
8931: sub common_domprefs_js {
8932: return <<"END";
8933:
8934: <script type="text/javascript">
8935: // <![CDATA[
8936:
1.150 raeburn 8937: function getIndicesByName(formname,item) {
1.152 raeburn 8938: var group = new Array();
1.150 raeburn 8939: for (var i=0;i<formname.elements.length;i++) {
8940: if (formname.elements[i].name == item) {
1.152 raeburn 8941: group.push(formname.elements[i].id);
1.150 raeburn 8942: }
8943: }
1.152 raeburn 8944: return group;
1.150 raeburn 8945: }
8946:
8947: // ]]>
8948: </script>
8949:
8950: END
1.152 raeburn 8951:
1.150 raeburn 8952: }
8953:
1.160.6.5 raeburn 8954: sub recaptcha_js {
8955: my %lt = &captcha_phrases();
8956: return <<"END";
8957:
8958: <script type="text/javascript">
8959: // <![CDATA[
8960:
8961: function updateCaptcha(caller,context) {
8962: var privitem;
8963: var pubitem;
8964: var privtext;
8965: var pubtext;
8966: if (document.getElementById(context+'_recaptchapub')) {
8967: pubitem = document.getElementById(context+'_recaptchapub');
8968: } else {
8969: return;
8970: }
8971: if (document.getElementById(context+'_recaptchapriv')) {
8972: privitem = document.getElementById(context+'_recaptchapriv');
8973: } else {
8974: return;
8975: }
8976: if (document.getElementById(context+'_recaptchapubtxt')) {
8977: pubtext = document.getElementById(context+'_recaptchapubtxt');
8978: } else {
8979: return;
8980: }
8981: if (document.getElementById(context+'_recaptchaprivtxt')) {
8982: privtext = document.getElementById(context+'_recaptchaprivtxt');
8983: } else {
8984: return;
8985: }
8986: if (caller.checked) {
8987: if (caller.value == 'recaptcha') {
8988: pubitem.type = 'text';
8989: privitem.type = 'text';
8990: pubitem.size = '40';
8991: privitem.size = '40';
8992: pubtext.innerHTML = "$lt{'pub'}";
8993: privtext.innerHTML = "$lt{'priv'}";
8994: } else {
8995: pubitem.type = 'hidden';
8996: privitem.type = 'hidden';
8997: pubtext.innerHTML = '';
8998: privtext.innerHTML = '';
8999: }
9000: }
9001: return;
9002: }
9003:
9004: // ]]>
9005: </script>
9006:
9007: END
9008:
9009: }
9010:
9011: sub captcha_phrases {
9012: return &Apache::lonlocal::texthash (
9013: priv => 'Private key',
9014: pub => 'Public key',
9015: original => 'original (CAPTCHA)',
9016: recaptcha => 'successor (ReCAPTCHA)',
9017: notused => 'unused',
9018: );
9019: }
9020:
1.3 raeburn 9021: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>