Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.15
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.15! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.14 2013/01/11 17:55:36 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',
1.160.6.15! raeburn 2297: 'requestsmail','updatesmail');
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.160.6.15! raeburn 2333: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2334: }
2335: my ($titles,$short_titles) = &contact_titles();
2336: my $rownum = 0;
2337: my $css_class;
2338: foreach my $item (@contacts) {
1.69 raeburn 2339: $rownum ++;
2340: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2341: $datatable .= '<tr'.$css_class.'>'.
2342: '<td><span class="LC_nobreak">'.$titles->{$item}.
2343: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2344: '<input type="text" name="'.$item.'" value="'.
2345: $to{$item}.'" /></td></tr>';
2346: }
2347: foreach my $type (@mailings) {
1.69 raeburn 2348: $rownum ++;
2349: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2350: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2351: '<td><span class="LC_nobreak">'.
2352: $titles->{$type}.': </span></td>'.
1.28 raeburn 2353: '<td class="LC_left_item">'.
2354: '<span class="LC_nobreak">';
2355: foreach my $item (@contacts) {
2356: $datatable .= '<label>'.
2357: '<input type="checkbox" name="'.$type.'"'.
2358: $checked{$type}{$item}.
2359: ' value="'.$item.'" />'.$short_titles->{$item}.
2360: '</label> ';
2361: }
2362: $datatable .= '</span><br />'.&mt('Others').': '.
2363: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2364: 'value="'.$otheremails{$type}.'" />';
2365: if ($type eq 'helpdeskmail') {
1.136 raeburn 2366: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2367: '<input type="text" name="'.$type.'_bcc" '.
2368: 'value="'.$bccemails{$type}.'" />';
2369: }
2370: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2371: }
1.30 raeburn 2372: $$rowtotal += $rownum;
1.28 raeburn 2373: return $datatable;
2374: }
2375:
1.118 jms 2376: sub print_helpsettings {
1.160.6.5 raeburn 2377: my ($dom,$confname,$settings,$rowtotal) = @_;
2378: my ($datatable,$itemcount);
2379: $itemcount = 1;
2380: my (%choices,%defaultchecked,@toggles);
2381: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2382: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2383: &mt('LON-CAPA bug tracker'),600,500));
2384: %defaultchecked = ('submitbugs' => 'on');
2385: @toggles = ('submitbugs',);
1.122 jms 2386:
1.160.6.5 raeburn 2387: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2388: \%choices,$itemcount);
2389: return $datatable;
1.121 raeburn 2390: }
2391:
2392: sub radiobutton_prefs {
2393: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2394: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2395: (ref($choices) eq 'HASH'));
2396:
2397: my (%checkedon,%checkedoff,$datatable,$css_class);
2398:
2399: foreach my $item (@{$toggles}) {
2400: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2401: $checkedon{$item} = ' checked="checked" ';
2402: $checkedoff{$item} = ' ';
1.121 raeburn 2403: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2404: $checkedoff{$item} = ' checked="checked" ';
2405: $checkedon{$item} = ' ';
2406: }
2407: }
2408: if (ref($settings) eq 'HASH') {
1.121 raeburn 2409: foreach my $item (@{$toggles}) {
1.118 jms 2410: if ($settings->{$item} eq '1') {
2411: $checkedon{$item} = ' checked="checked" ';
2412: $checkedoff{$item} = ' ';
2413: } elsif ($settings->{$item} eq '0') {
2414: $checkedoff{$item} = ' checked="checked" ';
2415: $checkedon{$item} = ' ';
2416: }
2417: }
1.121 raeburn 2418: }
2419: foreach my $item (@{$toggles}) {
1.118 jms 2420: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2421: $datatable .=
2422: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2423: '</span></td>'.
2424: '<td class="LC_right_item"><span class="LC_nobreak">'.
2425: '<label><input type="radio" name="'.
2426: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2427: '</label> <label><input type="radio" name="'.$item.'" '.
2428: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2429: '</span></td>'.
2430: '</tr>';
2431: $itemcount ++;
1.121 raeburn 2432: }
2433: return ($datatable,$itemcount);
2434: }
2435:
2436: sub print_coursedefaults {
1.139 raeburn 2437: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2438: my ($css_class,$datatable);
2439: my $itemcount = 1;
1.139 raeburn 2440: if ($position eq 'top') {
2441: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2442: %choices =
2443: &Apache::lonlocal::texthash (
2444: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2445: );
2446: %defaultchecked = ('canuse_pdfforms' => 'off');
2447: @toggles = ('canuse_pdfforms',);
2448: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2449: \%choices,$itemcount);
1.139 raeburn 2450: $$rowtotal += $itemcount;
2451: } else {
2452: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2453: my %choices =
2454: &Apache::lonlocal::texthash (
2455: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2456: );
2457: my $currdefresponder;
2458: if (ref($settings) eq 'HASH') {
2459: $currdefresponder = $settings->{'anonsurvey_threshold'};
2460: }
2461: if (!$currdefresponder) {
2462: $currdefresponder = 10;
2463: } elsif ($currdefresponder < 1) {
2464: $currdefresponder = 1;
2465: }
2466: $datatable .=
2467: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2468: '</span></td>'.
2469: '<td class="LC_right_item"><span class="LC_nobreak">'.
2470: '<input type="text" name="anonsurvey_threshold"'.
2471: ' value="'.$currdefresponder.'" size="5" /></span>'.
2472: '</td></tr>';
2473: }
1.121 raeburn 2474: return $datatable;
1.118 jms 2475: }
2476:
1.137 raeburn 2477: sub print_usersessions {
2478: my ($position,$dom,$settings,$rowtotal) = @_;
2479: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2480: my (%by_ip,%by_location,@intdoms);
2481: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2482:
2483: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2484: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2485: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2486: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2487: my $itemcount = 1;
2488: if ($position eq 'top') {
1.152 raeburn 2489: if (keys(%serverhomes) > 1) {
1.145 raeburn 2490: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2491: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2492: } else {
1.140 raeburn 2493: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2494: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2495: }
1.137 raeburn 2496: } else {
1.145 raeburn 2497: if (keys(%by_location) == 0) {
2498: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2499: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2500: } else {
2501: my %lt = &usersession_titles();
2502: my $numinrow = 5;
2503: my $prefix;
2504: my @types;
2505: if ($position eq 'bottom') {
2506: $prefix = 'remote';
2507: @types = ('version','excludedomain','includedomain');
2508: } else {
2509: $prefix = 'hosted';
2510: @types = ('excludedomain','includedomain');
2511: }
2512: my (%current,%checkedon,%checkedoff);
2513: my @lcversions = &Apache::lonnet::all_loncaparevs();
2514: my @locations = sort(keys(%by_location));
2515: foreach my $type (@types) {
2516: $checkedon{$type} = '';
2517: $checkedoff{$type} = ' checked="checked"';
2518: }
2519: if (ref($settings) eq 'HASH') {
2520: if (ref($settings->{$prefix}) eq 'HASH') {
2521: foreach my $key (keys(%{$settings->{$prefix}})) {
2522: $current{$key} = $settings->{$prefix}{$key};
2523: if ($key eq 'version') {
2524: if ($current{$key} ne '') {
2525: $checkedon{$key} = ' checked="checked"';
2526: $checkedoff{$key} = '';
2527: }
2528: } elsif (ref($current{$key}) eq 'ARRAY') {
2529: $checkedon{$key} = ' checked="checked"';
2530: $checkedoff{$key} = '';
2531: }
1.137 raeburn 2532: }
2533: }
2534: }
1.145 raeburn 2535: foreach my $type (@types) {
2536: next if ($type ne 'version' && !@locations);
2537: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2538: $datatable .= '<tr'.$css_class.'>
2539: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2540: <span class="LC_nobreak">
2541: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2542: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2543: if ($type eq 'version') {
2544: my $selector = '<select name="'.$prefix.'_version">';
2545: foreach my $version (@lcversions) {
2546: my $selected = '';
2547: if ($current{'version'} eq $version) {
2548: $selected = ' selected="selected"';
2549: }
2550: $selector .= ' <option value="'.$version.'"'.
2551: $selected.'>'.$version.'</option>';
2552: }
2553: $selector .= '</select> ';
2554: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2555: } else {
2556: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2557: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2558: ' />'.(' 'x2).
2559: '<input type="button" value="'.&mt('uncheck all').'" '.
2560: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2561: "\n".
2562: '</div><div><table>';
2563: my $rem;
2564: for (my $i=0; $i<@locations; $i++) {
2565: my ($showloc,$value,$checkedtype);
2566: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2567: my $ip = $by_location{$locations[$i]}->[0];
2568: if (ref($by_ip{$ip}) eq 'ARRAY') {
2569: $value = join(':',@{$by_ip{$ip}});
2570: $showloc = join(', ',@{$by_ip{$ip}});
2571: if (ref($current{$type}) eq 'ARRAY') {
2572: foreach my $loc (@{$by_ip{$ip}}) {
2573: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2574: $checkedtype = ' checked="checked"';
2575: last;
2576: }
2577: }
1.138 raeburn 2578: }
2579: }
2580: }
1.145 raeburn 2581: $rem = $i%($numinrow);
2582: if ($rem == 0) {
2583: if ($i > 0) {
2584: $datatable .= '</tr>';
2585: }
2586: $datatable .= '<tr>';
2587: }
2588: $datatable .= '<td class="LC_left_item">'.
2589: '<span class="LC_nobreak"><label>'.
2590: '<input type="checkbox" name="'.$prefix.'_'.$type.
2591: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2592: '</label></span></td>';
1.137 raeburn 2593: }
1.145 raeburn 2594: $rem = @locations%($numinrow);
2595: my $colsleft = $numinrow - $rem;
2596: if ($colsleft > 1 ) {
2597: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2598: ' </td>';
2599: } elsif ($colsleft == 1) {
2600: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2601: }
1.145 raeburn 2602: $datatable .= '</tr></table>';
1.137 raeburn 2603: }
1.145 raeburn 2604: $datatable .= '</td></tr>';
2605: $itemcount ++;
1.137 raeburn 2606: }
2607: }
2608: }
2609: $$rowtotal += $itemcount;
2610: return $datatable;
2611: }
2612:
1.138 raeburn 2613: sub build_location_hashes {
2614: my ($intdoms,$by_ip,$by_location) = @_;
2615: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2616: (ref($by_location) eq 'HASH'));
2617: my %iphost = &Apache::lonnet::get_iphost();
2618: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2619: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2620: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2621: foreach my $id (@{$iphost{$primary_ip}}) {
2622: my $intdom = &Apache::lonnet::internet_dom($id);
2623: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2624: push(@{$intdoms},$intdom);
2625: }
2626: }
2627: }
2628: foreach my $ip (keys(%iphost)) {
2629: if (ref($iphost{$ip}) eq 'ARRAY') {
2630: foreach my $id (@{$iphost{$ip}}) {
2631: my $location = &Apache::lonnet::internet_dom($id);
2632: if ($location) {
2633: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2634: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2635: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2636: push(@{$by_ip->{$ip}},$location);
2637: }
2638: } else {
2639: $by_ip->{$ip} = [$location];
2640: }
2641: }
2642: }
2643: }
2644: }
2645: foreach my $ip (sort(keys(%{$by_ip}))) {
2646: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2647: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2648: my $first = $by_ip->{$ip}->[0];
2649: if (ref($by_location->{$first}) eq 'ARRAY') {
2650: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2651: push(@{$by_location->{$first}},$ip);
2652: }
2653: } else {
2654: $by_location->{$first} = [$ip];
2655: }
2656: }
2657: }
2658: return;
2659: }
2660:
1.145 raeburn 2661: sub current_offloads_to {
2662: my ($dom,$settings,$servers) = @_;
2663: my (%spareid,%otherdomconfigs);
1.152 raeburn 2664: if (ref($servers) eq 'HASH') {
1.145 raeburn 2665: foreach my $lonhost (sort(keys(%{$servers}))) {
2666: my $gotspares;
1.152 raeburn 2667: if (ref($settings) eq 'HASH') {
2668: if (ref($settings->{'spares'}) eq 'HASH') {
2669: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2670: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2671: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2672: $gotspares = 1;
2673: }
1.145 raeburn 2674: }
2675: }
2676: unless ($gotspares) {
2677: my $gotspares;
2678: my $serverhomeID =
2679: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2680: my $serverhomedom =
2681: &Apache::lonnet::host_domain($serverhomeID);
2682: if ($serverhomedom ne $dom) {
2683: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2684: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2685: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2686: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2687: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2688: $gotspares = 1;
2689: }
2690: }
2691: } else {
2692: $otherdomconfigs{$serverhomedom} =
2693: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2694: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2695: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2696: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2697: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2698: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2699: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2700: $gotspares = 1;
2701: }
2702: }
2703: }
2704: }
2705: }
2706: }
2707: }
2708: unless ($gotspares) {
2709: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2710: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2711: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2712: } else {
2713: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2714: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2715: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2716: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2717: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2718: } else {
1.150 raeburn 2719: my %what = (
2720: spareid => 1,
2721: );
2722: my ($result,$returnhash) =
2723: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2724: if ($result eq 'ok') {
2725: if (ref($returnhash) eq 'HASH') {
2726: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2727: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2728: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2729: }
2730: }
1.145 raeburn 2731: }
2732: }
2733: }
2734: }
2735: }
2736: }
2737: return %spareid;
2738: }
2739:
2740: sub spares_row {
1.152 raeburn 2741: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2742: my $css_class;
2743: my $numinrow = 4;
2744: my $itemcount = 1;
2745: my $datatable;
1.152 raeburn 2746: my %typetitles = &sparestype_titles();
2747: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2748: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2749: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2750: my ($othercontrol,$serverdom);
2751: if ($serverhome ne $server) {
2752: $serverdom = &Apache::lonnet::host_domain($serverhome);
2753: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2754: } else {
2755: $serverdom = &Apache::lonnet::host_domain($server);
2756: if ($serverdom ne $dom) {
2757: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2758: }
2759: }
2760: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2761: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2762: $datatable .= '<tr'.$css_class.'>
2763: <td rowspan="2">
1.160.6.13 raeburn 2764: <span class="LC_nobreak">'.
2765: &mt('[_1] when busy, offloads to:'
2766: ,'<b>'.$server.'</b>').
2767: "\n";
1.145 raeburn 2768: my (%current,%canselect);
1.152 raeburn 2769: my @choices =
2770: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2771: foreach my $type ('primary','default') {
2772: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2773: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2774: my @spares = @{$spareid->{$server}{$type}};
2775: if (@spares > 0) {
1.152 raeburn 2776: if ($othercontrol) {
2777: $current{$type} = join(', ',@spares);
2778: } else {
2779: $current{$type} .= '<table>';
2780: my $numspares = scalar(@spares);
2781: for (my $i=0; $i<@spares; $i++) {
2782: my $rem = $i%($numinrow);
2783: if ($rem == 0) {
2784: if ($i > 0) {
2785: $current{$type} .= '</tr>';
2786: }
2787: $current{$type} .= '<tr>';
1.145 raeburn 2788: }
1.152 raeburn 2789: $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'".');" /> '.
2790: $spareid->{$server}{$type}[$i].
2791: '</label></td>'."\n";
2792: }
2793: my $rem = @spares%($numinrow);
2794: my $colsleft = $numinrow - $rem;
2795: if ($colsleft > 1 ) {
2796: $current{$type} .= '<td colspan="'.$colsleft.
2797: '" class="LC_left_item">'.
2798: ' </td>';
2799: } elsif ($colsleft == 1) {
2800: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2801: }
1.152 raeburn 2802: $current{$type} .= '</tr></table>';
1.150 raeburn 2803: }
1.145 raeburn 2804: }
2805: }
2806: if ($current{$type} eq '') {
2807: $current{$type} = &mt('None specified');
2808: }
1.152 raeburn 2809: if ($othercontrol) {
2810: if ($type eq 'primary') {
2811: $canselect{$type} = $othercontrol;
2812: }
2813: } else {
2814: $canselect{$type} =
2815: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2816: '<select name="newspare_'.$type.'_'.$server.'" '.
2817: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2818: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2819: if (@choices > 0) {
2820: foreach my $lonhost (@choices) {
2821: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2822: }
2823: }
2824: $canselect{$type} .= '</select>'."\n";
2825: }
2826: } else {
2827: $current{$type} = &mt('Could not be determined');
2828: if ($type eq 'primary') {
2829: $canselect{$type} = $othercontrol;
2830: }
1.145 raeburn 2831: }
1.152 raeburn 2832: if ($type eq 'default') {
2833: $datatable .= '<tr'.$css_class.'>';
2834: }
2835: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2836: '<td>'.$current{$type}.'</td>'."\n".
2837: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2838: }
2839: $itemcount ++;
2840: }
2841: }
2842: $$rowtotal += $itemcount;
2843: return $datatable;
2844: }
2845:
1.152 raeburn 2846: sub possible_newspares {
2847: my ($server,$currspares,$serverhomes,$altids) = @_;
2848: my $serverhostname = &Apache::lonnet::hostname($server);
2849: my %excluded;
2850: if ($serverhostname ne '') {
2851: %excluded = (
2852: $serverhostname => 1,
2853: );
2854: }
2855: if (ref($currspares) eq 'HASH') {
2856: foreach my $type (keys(%{$currspares})) {
2857: if (ref($currspares->{$type}) eq 'ARRAY') {
2858: if (@{$currspares->{$type}} > 0) {
2859: foreach my $curr (@{$currspares->{$type}}) {
2860: my $hostname = &Apache::lonnet::hostname($curr);
2861: $excluded{$hostname} = 1;
2862: }
2863: }
2864: }
2865: }
2866: }
2867: my @choices;
2868: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2869: if (keys(%{$serverhomes}) > 1) {
2870: foreach my $name (sort(keys(%{$serverhomes}))) {
2871: unless ($excluded{$name}) {
2872: if (exists($altids->{$serverhomes->{$name}})) {
2873: push(@choices,$altids->{$serverhomes->{$name}});
2874: } else {
2875: push(@choices,$serverhomes->{$name});
1.145 raeburn 2876: }
2877: }
2878: }
2879: }
2880: }
1.152 raeburn 2881: return sort(@choices);
1.145 raeburn 2882: }
2883:
1.150 raeburn 2884: sub print_loadbalancing {
2885: my ($dom,$settings,$rowtotal) = @_;
2886: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2887: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2888: my $numinrow = 1;
2889: my $datatable;
2890: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2891: my (%currbalancer,%currtargets,%currrules,%existing);
2892: if (ref($settings) eq 'HASH') {
2893: %existing = %{$settings};
2894: }
2895: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2896: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2897: \%currtargets,\%currrules);
1.150 raeburn 2898: } else {
2899: return;
2900: }
2901: my ($othertitle,$usertypes,$types) =
2902: &Apache::loncommon::sorted_inst_types($dom);
2903: my $rownum = 6;
2904: if (ref($types) eq 'ARRAY') {
2905: $rownum += scalar(@{$types});
2906: }
1.160.6.7 raeburn 2907: my @css_class = ('LC_odd_row','LC_even_row');
2908: my $balnum = 0;
2909: my $islast;
2910: my (@toshow,$disabledtext);
2911: if (keys(%currbalancer) > 0) {
2912: @toshow = sort(keys(%currbalancer));
2913: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2914: push(@toshow,'');
2915: }
2916: } else {
2917: @toshow = ('');
2918: $disabledtext = &mt('No existing load balancer');
2919: }
2920: foreach my $lonhost (@toshow) {
2921: if ($balnum == scalar(@toshow)-1) {
2922: $islast = 1;
2923: } else {
2924: $islast = 0;
2925: }
2926: my $cssidx = $balnum%2;
2927: my $targets_div_style = 'display: none';
2928: my $disabled_div_style = 'display: block';
2929: my $homedom_div_style = 'display: none';
2930: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2931: '<td rowspan="'.$rownum.'" valign="top">'.
2932: '<p>';
2933: if ($lonhost eq '') {
2934: $datatable .= '<span class="LC_nobreak">';
2935: if (keys(%currbalancer) > 0) {
2936: $datatable .= &mt('Add balancer:');
2937: } else {
2938: $datatable .= &mt('Enable balancer:');
2939: }
2940: $datatable .= ' '.
2941: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2942: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2943: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2944: '<option value="" selected="selected">'.&mt('None').
2945: '</option>'."\n";
2946: foreach my $server (sort(keys(%servers))) {
2947: next if ($currbalancer{$server});
2948: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2949: }
2950: $datatable .=
2951: '</select>'."\n".
2952: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2953: } else {
2954: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2955: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2956: &mt('Stop balancing').'</label>'.
2957: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2958: $targets_div_style = 'display: block';
2959: $disabled_div_style = 'display: none';
2960: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2961: $homedom_div_style = 'display: block';
2962: }
2963: }
2964: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2965: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2966: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2967: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2968: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2969: my @sparestypes = ('primary','default');
2970: my %typetitles = &sparestype_titles();
2971: foreach my $sparetype (@sparestypes) {
2972: my $targettable;
2973: for (my $i=0; $i<$numspares; $i++) {
2974: my $checked;
2975: if (ref($currtargets{$lonhost}) eq 'HASH') {
2976: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
2977: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
2978: $checked = ' checked="checked"';
2979: }
2980: }
2981: }
2982: my ($chkboxval,$disabled);
2983: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
2984: $chkboxval = $spares[$i];
2985: }
2986: if (exists($currbalancer{$spares[$i]})) {
2987: $disabled = ' disabled="disabled"';
2988: }
2989: $targettable .=
2990: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
2991: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2992: '</span></label></td>';
2993: my $rem = $i%($numinrow);
2994: if ($rem == 0) {
2995: if (($i > 0) && ($i < $numspares-1)) {
2996: $targettable .= '</tr>';
2997: }
2998: if ($i < $numspares-1) {
2999: $targettable .= '<tr>';
1.150 raeburn 3000: }
3001: }
3002: }
1.160.6.7 raeburn 3003: if ($targettable ne '') {
3004: my $rem = $numspares%($numinrow);
3005: my $colsleft = $numinrow - $rem;
3006: if ($colsleft > 1 ) {
3007: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3008: ' </td>';
3009: } elsif ($colsleft == 1) {
3010: $targettable .= '<td class="LC_left_item"> </td>';
3011: }
3012: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3013: '<table><tr>'.$targettable.'</tr></table><br />';
3014: }
3015: }
3016: $datatable .= '</div></td></tr>'.
3017: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3018: $othertitle,$usertypes,$types,\%servers,
3019: \%currbalancer,$lonhost,
3020: $targets_div_style,$homedom_div_style,
3021: $css_class[$cssidx],$balnum,$islast);
3022: $$rowtotal += $rownum;
3023: $balnum ++;
3024: }
3025: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3026: return $datatable;
3027: }
3028:
3029: sub get_loadbalancers_config {
3030: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3031: return unless ((ref($servers) eq 'HASH') &&
3032: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3033: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3034: if (keys(%{$existing}) > 0) {
3035: my $oldlonhost;
3036: foreach my $key (sort(keys(%{$existing}))) {
3037: if ($key eq 'lonhost') {
3038: $oldlonhost = $existing->{'lonhost'};
3039: $currbalancer->{$oldlonhost} = 1;
3040: } elsif ($key eq 'targets') {
3041: if ($oldlonhost) {
3042: $currtargets->{$oldlonhost} = $existing->{'targets'};
3043: }
3044: } elsif ($key eq 'rules') {
3045: if ($oldlonhost) {
3046: $currrules->{$oldlonhost} = $existing->{'rules'};
3047: }
3048: } elsif (ref($existing->{$key}) eq 'HASH') {
3049: $currbalancer->{$key} = 1;
3050: $currtargets->{$key} = $existing->{$key}{'targets'};
3051: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3052: }
3053: }
1.160.6.7 raeburn 3054: } else {
3055: my ($balancerref,$targetsref) =
3056: &Apache::lonnet::get_lonbalancer_config($servers);
3057: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3058: foreach my $server (sort(keys(%{$balancerref}))) {
3059: $currbalancer->{$server} = 1;
3060: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3061: }
3062: }
3063: }
1.160.6.7 raeburn 3064: return;
1.150 raeburn 3065: }
3066:
3067: sub loadbalancing_rules {
3068: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3069: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3070: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3071: my $output;
1.160.6.7 raeburn 3072: my $num = 0;
3073: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3074: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3075: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3076: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3077: $num ++;
1.150 raeburn 3078: my $current;
3079: if (ref($currrules) eq 'HASH') {
3080: $current = $currrules->{$type};
3081: }
3082: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3083: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3084: $current = '';
3085: }
3086: }
3087: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3088: $servers,$currbalancer,$lonhost,$dom,
3089: $targets_div_style,$homedom_div_style,
3090: $css_class,$balnum,$num,$islast);
1.150 raeburn 3091: }
3092: }
3093: return $output;
3094: }
3095:
3096: sub loadbalancing_titles {
3097: my ($dom,$intdom,$usertypes,$types) = @_;
3098: my %othertypes = (
3099: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3100: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3101: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3102: '_LC_external' => &mt('Users not from [_1]',$intdom),
3103: );
3104: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3105: if (ref($types) eq 'ARRAY') {
3106: unshift(@alltypes,@{$types},'default');
3107: }
3108: my %titles;
3109: foreach my $type (@alltypes) {
3110: if ($type =~ /^_LC_/) {
3111: $titles{$type} = $othertypes{$type};
3112: } elsif ($type eq 'default') {
3113: $titles{$type} = &mt('All users from [_1]',$dom);
3114: if (ref($types) eq 'ARRAY') {
3115: if (@{$types} > 0) {
3116: $titles{$type} = &mt('Other users from [_1]',$dom);
3117: }
3118: }
3119: } elsif (ref($usertypes) eq 'HASH') {
3120: $titles{$type} = $usertypes->{$type};
3121: }
3122: }
3123: return (\@alltypes,\%othertypes,\%titles);
3124: }
3125:
3126: sub loadbalance_rule_row {
1.160.6.7 raeburn 3127: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3128: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3129: my @rulenames = ('default','homeserver');
3130: my %ruletitles = &offloadtype_text();
3131: if ($type eq '_LC_external') {
3132: push(@rulenames,'externalbalancer');
3133: } else {
3134: push(@rulenames,'specific');
3135: }
1.160.6.3 raeburn 3136: push(@rulenames,'none');
1.150 raeburn 3137: my $style = $targets_div_style;
3138: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3139: $style = $homedom_div_style;
3140: }
1.160.6.7 raeburn 3141: my $space;
3142: if ($islast && $num == 1) {
3143: $space = '<div display="inline-block"> </div>';
3144: }
3145: my $output =
3146: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3147: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3148: '<td valaign="top">'.$space.
3149: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3150: for (my $i=0; $i<@rulenames; $i++) {
3151: my $rule = $rulenames[$i];
3152: my ($checked,$extra);
3153: if ($rulenames[$i] eq 'default') {
3154: $rule = '';
3155: }
3156: if ($rulenames[$i] eq 'specific') {
3157: if (ref($servers) eq 'HASH') {
3158: my $default;
3159: if (($current ne '') && (exists($servers->{$current}))) {
3160: $checked = ' checked="checked"';
3161: }
3162: unless ($checked) {
3163: $default = ' selected="selected"';
3164: }
1.160.6.7 raeburn 3165: $extra =
3166: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3167: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3168: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3169: '<option value=""'.$default.'></option>'."\n";
3170: foreach my $server (sort(keys(%{$servers}))) {
3171: if (ref($currbalancer) eq 'HASH') {
3172: next if (exists($currbalancer->{$server}));
3173: }
1.150 raeburn 3174: my $selected;
1.160.6.7 raeburn 3175: if ($server eq $current) {
1.150 raeburn 3176: $selected = ' selected="selected"';
3177: }
1.160.6.7 raeburn 3178: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3179: }
3180: $extra .= '</select>';
3181: }
3182: } elsif ($rule eq $current) {
3183: $checked = ' checked="checked"';
3184: }
3185: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3186: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3187: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3188: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3189: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3190: '</label>'.$extra.'</span><br />'."\n";
3191: }
3192: $output .= '</div></td></tr>'."\n";
3193: return $output;
3194: }
3195:
3196: sub offloadtype_text {
3197: my %ruletitles = &Apache::lonlocal::texthash (
3198: 'default' => 'Offloads to default destinations',
3199: 'homeserver' => "Offloads to user's home server",
3200: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3201: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3202: 'none' => 'No offload',
1.150 raeburn 3203: );
3204: return %ruletitles;
3205: }
3206:
3207: sub sparestype_titles {
3208: my %typestitles = &Apache::lonlocal::texthash (
3209: 'primary' => 'primary',
3210: 'default' => 'default',
3211: );
3212: return %typestitles;
3213: }
3214:
1.28 raeburn 3215: sub contact_titles {
3216: my %titles = &Apache::lonlocal::texthash (
3217: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3218: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3219: 'errormail' => 'Error reports to be e-mailed to',
3220: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3221: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3222: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3223: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15! raeburn 3224: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.28 raeburn 3225: );
3226: my %short_titles = &Apache::lonlocal::texthash (
3227: adminemail => 'Admin E-mail address',
3228: supportemail => 'Support E-mail',
3229: );
3230: return (\%titles,\%short_titles);
3231: }
3232:
1.72 raeburn 3233: sub tool_titles {
3234: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3235: aboutme => 'Personal web page',
1.86 raeburn 3236: blog => 'Blog',
1.160.6.4 raeburn 3237: webdav => 'WebDAV',
1.86 raeburn 3238: portfolio => 'Portfolio',
1.88 bisitz 3239: official => 'Official courses (with institutional codes)',
3240: unofficial => 'Unofficial courses',
1.98 raeburn 3241: community => 'Communities',
1.86 raeburn 3242: );
1.72 raeburn 3243: return %titles;
3244: }
3245:
1.101 raeburn 3246: sub courserequest_titles {
3247: my %titles = &Apache::lonlocal::texthash (
3248: official => 'Official',
3249: unofficial => 'Unofficial',
3250: community => 'Communities',
3251: norequest => 'Not allowed',
1.104 raeburn 3252: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3253: validate => 'With validation',
3254: autolimit => 'Numerical limit',
1.103 raeburn 3255: unlimited => '(blank for unlimited)',
1.101 raeburn 3256: );
3257: return %titles;
3258: }
3259:
1.160.6.5 raeburn 3260: sub authorrequest_titles {
3261: my %titles = &Apache::lonlocal::texthash (
3262: norequest => 'Not allowed',
3263: approval => 'Approval by Dom. Coord.',
3264: automatic => 'Automatic approval',
3265: );
3266: return %titles;
3267: }
3268:
1.101 raeburn 3269: sub courserequest_conditions {
3270: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3271: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3272: validate => '(Processing of request subject to instittutional validation).',
3273: );
3274: return %conditions;
3275: }
3276:
3277:
1.27 raeburn 3278: sub print_usercreation {
1.30 raeburn 3279: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3280: my $numinrow = 4;
1.28 raeburn 3281: my $datatable;
3282: if ($position eq 'top') {
1.30 raeburn 3283: $$rowtotal ++;
1.34 raeburn 3284: my $rowcount = 0;
1.32 raeburn 3285: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3286: if (ref($rules) eq 'HASH') {
3287: if (keys(%{$rules}) > 0) {
1.32 raeburn 3288: $datatable .= &user_formats_row('username',$settings,$rules,
3289: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3290: $$rowtotal ++;
1.32 raeburn 3291: $rowcount ++;
3292: }
3293: }
3294: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3295: if (ref($idrules) eq 'HASH') {
3296: if (keys(%{$idrules}) > 0) {
3297: $datatable .= &user_formats_row('id',$settings,$idrules,
3298: $idruleorder,$numinrow,$rowcount);
3299: $$rowtotal ++;
3300: $rowcount ++;
1.28 raeburn 3301: }
3302: }
1.43 raeburn 3303: my ($emailrules,$emailruleorder) =
3304: &Apache::lonnet::inst_userrules($dom,'email');
3305: if (ref($emailrules) eq 'HASH') {
3306: if (keys(%{$emailrules}) > 0) {
3307: $datatable .= &user_formats_row('email',$settings,$emailrules,
3308: $emailruleorder,$numinrow,$rowcount);
3309: $$rowtotal ++;
3310: $rowcount ++;
3311: }
3312: }
1.39 raeburn 3313: if ($rowcount == 0) {
3314: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3315: $$rowtotal ++;
3316: $rowcount ++;
3317: }
1.34 raeburn 3318: } elsif ($position eq 'middle') {
1.100 raeburn 3319: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3320: my ($rules,$ruleorder) =
3321: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3322: my %lt = &usercreation_types();
3323: my %checked;
1.50 raeburn 3324: my @selfcreate;
1.34 raeburn 3325: if (ref($settings) eq 'HASH') {
3326: if (ref($settings->{'cancreate'}) eq 'HASH') {
3327: foreach my $item (@creators) {
3328: $checked{$item} = $settings->{'cancreate'}{$item};
3329: }
1.50 raeburn 3330: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3331: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3332: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3333: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3334: @selfcreate = ('email','login','sso');
3335: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3336: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3337: }
3338: }
1.34 raeburn 3339: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3340: foreach my $item (@creators) {
3341: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3342: $checked{$item} = 'none';
3343: }
3344: }
3345: }
3346: }
3347: my $rownum = 0;
3348: foreach my $item (@creators) {
3349: $rownum ++;
1.50 raeburn 3350: if ($item ne 'selfcreate') {
3351: if ($checked{$item} eq '') {
1.43 raeburn 3352: $checked{$item} = 'any';
3353: }
1.34 raeburn 3354: }
3355: my $css_class;
3356: if ($rownum%2) {
3357: $css_class = '';
3358: } else {
3359: $css_class = ' class="LC_odd_row" ';
3360: }
3361: $datatable .= '<tr'.$css_class.'>'.
3362: '<td><span class="LC_nobreak">'.$lt{$item}.
3363: '</span></td><td align="right">';
1.50 raeburn 3364: my @options;
1.45 raeburn 3365: if ($item eq 'selfcreate') {
1.43 raeburn 3366: push(@options,('email','login','sso'));
3367: } else {
1.50 raeburn 3368: @options = ('any');
1.43 raeburn 3369: if (ref($rules) eq 'HASH') {
3370: if (keys(%{$rules}) > 0) {
3371: push(@options,('official','unofficial'));
3372: }
1.37 raeburn 3373: }
1.50 raeburn 3374: push(@options,'none');
1.37 raeburn 3375: }
3376: foreach my $option (@options) {
1.50 raeburn 3377: my $type = 'radio';
1.34 raeburn 3378: my $check = ' ';
1.50 raeburn 3379: if ($item eq 'selfcreate') {
3380: $type = 'checkbox';
3381: if (grep(/^\Q$option\E$/,@selfcreate)) {
3382: $check = ' checked="checked" ';
3383: }
3384: } else {
3385: if ($checked{$item} eq $option) {
3386: $check = ' checked="checked" ';
3387: }
1.34 raeburn 3388: }
3389: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3390: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3391: $item.'" value="'.$option.'"'.$check.'/> '.
3392: $lt{$option}.'</label> </span>';
3393: }
3394: $datatable .= '</td></tr>';
3395: }
1.93 raeburn 3396: my ($othertitle,$usertypes,$types) =
3397: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3398: my $createsettings;
3399: if (ref($settings) eq 'HASH') {
3400: $createsettings = $settings->{cancreate};
3401: }
1.93 raeburn 3402: if (ref($usertypes) eq 'HASH') {
3403: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3404: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3405: $dom,$numinrow,$othertitle,
3406: 'statustocreate');
3407: $$rowtotal ++;
1.160.6.5 raeburn 3408: $rownum ++;
1.93 raeburn 3409: }
3410: }
1.160.6.5 raeburn 3411: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3412: } else {
3413: my @contexts = ('author','course','domain');
3414: my @authtypes = ('int','krb4','krb5','loc');
3415: my %checked;
3416: if (ref($settings) eq 'HASH') {
3417: if (ref($settings->{'authtypes'}) eq 'HASH') {
3418: foreach my $item (@contexts) {
3419: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3420: foreach my $auth (@authtypes) {
3421: if ($settings->{'authtypes'}{$item}{$auth}) {
3422: $checked{$item}{$auth} = ' checked="checked" ';
3423: }
3424: }
3425: }
3426: }
1.27 raeburn 3427: }
1.35 raeburn 3428: } else {
3429: foreach my $item (@contexts) {
1.36 raeburn 3430: foreach my $auth (@authtypes) {
1.35 raeburn 3431: $checked{$item}{$auth} = ' checked="checked" ';
3432: }
3433: }
1.27 raeburn 3434: }
1.28 raeburn 3435: my %title = &context_names();
3436: my %authname = &authtype_names();
3437: my $rownum = 0;
3438: my $css_class;
3439: foreach my $item (@contexts) {
3440: if ($rownum%2) {
3441: $css_class = '';
3442: } else {
3443: $css_class = ' class="LC_odd_row" ';
3444: }
1.30 raeburn 3445: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3446: '<td>'.$title{$item}.
3447: '</td><td class="LC_left_item">'.
3448: '<span class="LC_nobreak">';
3449: foreach my $auth (@authtypes) {
3450: $datatable .= '<label>'.
3451: '<input type="checkbox" name="'.$item.'_auth" '.
3452: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3453: $authname{$auth}.'</label> ';
3454: }
3455: $datatable .= '</span></td></tr>';
3456: $rownum ++;
1.27 raeburn 3457: }
1.30 raeburn 3458: $$rowtotal += $rownum;
1.27 raeburn 3459: }
3460: return $datatable;
3461: }
3462:
1.160.6.5 raeburn 3463: sub captcha_choice {
3464: my ($context,$settings,$itemcount) = @_;
3465: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3466: my %lt = &captcha_phrases();
3467: $keyentry = 'hidden';
3468: if ($context eq 'cancreate') {
3469: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3470: } elsif ($context eq 'login') {
3471: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3472: }
3473: if (ref($settings) eq 'HASH') {
3474: if ($settings->{'captcha'}) {
3475: $checked{$settings->{'captcha'}} = ' checked="checked"';
3476: } else {
3477: $checked{'original'} = ' checked="checked"';
3478: }
3479: if ($settings->{'captcha'} eq 'recaptcha') {
3480: $pubtext = $lt{'pub'};
3481: $privtext = $lt{'priv'};
3482: $keyentry = 'text';
3483: }
3484: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3485: $currpub = $settings->{'recaptchakeys'}{'public'};
3486: $currpriv = $settings->{'recaptchakeys'}{'private'};
3487: }
3488: } else {
3489: $checked{'original'} = ' checked="checked"';
3490: }
3491: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3492: my $output = '<tr'.$css_class.'>'.
3493: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3494: '<table><tr><td>'."\n";
3495: foreach my $option ('original','recaptcha','notused') {
3496: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3497: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3498: $lt{$option}.'</label></span>';
3499: unless ($option eq 'notused') {
3500: $output .= (' 'x2)."\n";
3501: }
3502: }
3503: #
3504: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3505: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3506: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3507: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3508: #
3509: $output .= '</td></tr>'."\n".
3510: '<tr><td>'."\n".
3511: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3512: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3513: $currpub.'" size="40" /></span><br />'."\n".
3514: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3515: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3516: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3517: '</td></tr>';
3518: return $output;
3519: }
3520:
1.32 raeburn 3521: sub user_formats_row {
3522: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3523: my $output;
3524: my %text = (
3525: 'username' => 'new usernames',
3526: 'id' => 'IDs',
1.45 raeburn 3527: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3528: );
3529: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3530: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3531: '<td><span class="LC_nobreak">';
3532: if ($type eq 'email') {
3533: $output .= &mt("Formats disallowed for $text{$type}: ");
3534: } else {
3535: $output .= &mt("Format rules to check for $text{$type}: ");
3536: }
3537: $output .= '</span></td>'.
3538: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3539: my $rem;
3540: if (ref($ruleorder) eq 'ARRAY') {
3541: for (my $i=0; $i<@{$ruleorder}; $i++) {
3542: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3543: my $rem = $i%($numinrow);
3544: if ($rem == 0) {
3545: if ($i > 0) {
3546: $output .= '</tr>';
3547: }
3548: $output .= '<tr>';
3549: }
3550: my $check = ' ';
1.39 raeburn 3551: if (ref($settings) eq 'HASH') {
3552: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3553: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3554: $check = ' checked="checked" ';
3555: }
1.27 raeburn 3556: }
3557: }
3558: $output .= '<td class="LC_left_item">'.
3559: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3560: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3561: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3562: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3563: }
3564: }
3565: $rem = @{$ruleorder}%($numinrow);
3566: }
3567: my $colsleft = $numinrow - $rem;
3568: if ($colsleft > 1 ) {
3569: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3570: ' </td>';
3571: } elsif ($colsleft == 1) {
3572: $output .= '<td class="LC_left_item"> </td>';
3573: }
3574: $output .= '</tr></table></td></tr>';
3575: return $output;
3576: }
3577:
1.34 raeburn 3578: sub usercreation_types {
3579: my %lt = &Apache::lonlocal::texthash (
3580: author => 'When adding a co-author',
3581: course => 'When adding a user to a course',
1.100 raeburn 3582: requestcrs => 'When requesting a course',
1.45 raeburn 3583: selfcreate => 'User creates own account',
1.34 raeburn 3584: any => 'Any',
3585: official => 'Institutional only ',
3586: unofficial => 'Non-institutional only',
1.85 schafran 3587: email => 'E-mail address',
1.43 raeburn 3588: login => 'Institutional Login',
3589: sso => 'SSO',
1.34 raeburn 3590: none => 'None',
3591: );
3592: return %lt;
1.48 raeburn 3593: }
1.34 raeburn 3594:
1.28 raeburn 3595: sub authtype_names {
3596: my %lt = &Apache::lonlocal::texthash(
3597: int => 'Internal',
3598: krb4 => 'Kerberos 4',
3599: krb5 => 'Kerberos 5',
3600: loc => 'Local',
3601: );
3602: return %lt;
3603: }
3604:
3605: sub context_names {
3606: my %context_title = &Apache::lonlocal::texthash(
3607: author => 'Creating users when an Author',
3608: course => 'Creating users when in a course',
3609: domain => 'Creating users when a Domain Coordinator',
3610: );
3611: return %context_title;
3612: }
3613:
1.33 raeburn 3614: sub print_usermodification {
3615: my ($position,$dom,$settings,$rowtotal) = @_;
3616: my $numinrow = 4;
3617: my ($context,$datatable,$rowcount);
3618: if ($position eq 'top') {
3619: $rowcount = 0;
3620: $context = 'author';
3621: foreach my $role ('ca','aa') {
3622: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3623: $numinrow,$rowcount);
3624: $$rowtotal ++;
3625: $rowcount ++;
3626: }
1.63 raeburn 3627: } elsif ($position eq 'middle') {
1.33 raeburn 3628: $context = 'course';
3629: $rowcount = 0;
3630: foreach my $role ('st','ep','ta','in','cr') {
3631: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3632: $numinrow,$rowcount);
3633: $$rowtotal ++;
3634: $rowcount ++;
3635: }
1.63 raeburn 3636: } elsif ($position eq 'bottom') {
3637: $context = 'selfcreate';
3638: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3639: $usertypes->{'default'} = $othertitle;
3640: if (ref($types) eq 'ARRAY') {
3641: push(@{$types},'default');
3642: $usertypes->{'default'} = $othertitle;
3643: foreach my $status (@{$types}) {
3644: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3645: $numinrow,$rowcount,$usertypes);
3646: $$rowtotal ++;
3647: $rowcount ++;
3648: }
3649: }
1.33 raeburn 3650: }
3651: return $datatable;
3652: }
3653:
1.43 raeburn 3654: sub print_defaults {
3655: my ($dom,$rowtotal) = @_;
1.68 raeburn 3656: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3657: 'datelocale_def','portal_def');
1.43 raeburn 3658: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3659: my $titles = &defaults_titles($dom);
1.43 raeburn 3660: my $rownum = 0;
3661: my ($datatable,$css_class);
3662: foreach my $item (@items) {
3663: if ($rownum%2) {
3664: $css_class = '';
3665: } else {
3666: $css_class = ' class="LC_odd_row" ';
3667: }
3668: $datatable .= '<tr'.$css_class.'>'.
3669: '<td><span class="LC_nobreak">'.$titles->{$item}.
3670: '</span></td><td class="LC_right_item">';
3671: if ($item eq 'auth_def') {
3672: my @authtypes = ('internal','krb4','krb5','localauth');
3673: my %shortauth = (
3674: internal => 'int',
3675: krb4 => 'krb4',
3676: krb5 => 'krb5',
3677: localauth => 'loc'
3678: );
3679: my %authnames = &authtype_names();
3680: foreach my $auth (@authtypes) {
3681: my $checked = ' ';
3682: if ($domdefaults{$item} eq $auth) {
3683: $checked = ' checked="checked" ';
3684: }
3685: $datatable .= '<label><input type="radio" name="'.$item.
3686: '" value="'.$auth.'"'.$checked.'/>'.
3687: $authnames{$shortauth{$auth}}.'</label> ';
3688: }
1.54 raeburn 3689: } elsif ($item eq 'timezone_def') {
3690: my $includeempty = 1;
3691: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3692: } elsif ($item eq 'datelocale_def') {
3693: my $includeempty = 1;
3694: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3695: } elsif ($item eq 'lang_def') {
3696: my %langchoices = &get_languages_hash();
3697: $langchoices{''} = 'No language preference';
3698: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3699: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3700: \%langchoices);
1.43 raeburn 3701: } else {
1.141 raeburn 3702: my $size;
3703: if ($item eq 'portal_def') {
3704: $size = ' size="25"';
3705: }
1.43 raeburn 3706: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3707: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3708: }
3709: $datatable .= '</td></tr>';
3710: $rownum ++;
3711: }
3712: $$rowtotal += $rownum;
3713: return $datatable;
3714: }
3715:
1.160.6.5 raeburn 3716: sub get_languages_hash {
3717: my %langchoices;
3718: foreach my $id (&Apache::loncommon::languageids()) {
3719: my $code = &Apache::loncommon::supportedlanguagecode($id);
3720: if ($code ne '') {
3721: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3722: }
3723: }
3724: return %langchoices;
3725: }
3726:
1.43 raeburn 3727: sub defaults_titles {
1.141 raeburn 3728: my ($dom) = @_;
1.43 raeburn 3729: my %titles = &Apache::lonlocal::texthash (
3730: 'auth_def' => 'Default authentication type',
3731: 'auth_arg_def' => 'Default authentication argument',
3732: 'lang_def' => 'Default language',
1.54 raeburn 3733: 'timezone_def' => 'Default timezone',
1.68 raeburn 3734: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3735: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3736: );
1.141 raeburn 3737: if ($dom) {
3738: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3739: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3740: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3741: $protocol = 'http' if ($protocol ne 'https');
3742: if ($uint_dom) {
3743: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3744: $uint_dom);
3745: }
3746: }
1.43 raeburn 3747: return (\%titles);
3748: }
3749:
1.46 raeburn 3750: sub print_scantronformat {
3751: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3752: my $itemcount = 1;
1.60 raeburn 3753: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3754: %confhash);
1.46 raeburn 3755: my $switchserver = &check_switchserver($dom,$confname);
3756: my %lt = &Apache::lonlocal::texthash (
1.95 www 3757: default => 'Default bubblesheet format file error',
3758: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3759: );
3760: my %scantronfiles = (
3761: default => 'default.tab',
3762: custom => 'custom.tab',
3763: );
3764: foreach my $key (keys(%scantronfiles)) {
3765: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3766: .$scantronfiles{$key};
3767: }
3768: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3769: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3770: if (!$switchserver) {
3771: my $servadm = $r->dir_config('lonAdmEMail');
3772: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3773: if ($configuserok eq 'ok') {
3774: if ($author_ok eq 'ok') {
3775: my %legacyfile = (
3776: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3777: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3778: );
3779: my %md5chk;
3780: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3781: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3782: chomp($md5chk{$type});
1.46 raeburn 3783: }
3784: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3785: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3786: ($scantronurls{$type},my $error) =
1.46 raeburn 3787: &legacy_scantronformat($r,$dom,$confname,
3788: $type,$legacyfile{$type},
3789: $scantronurls{$type},
3790: $scantronfiles{$type});
1.60 raeburn 3791: if ($error ne '') {
3792: $error{$type} = $error;
3793: }
3794: }
3795: if (keys(%error) == 0) {
3796: $is_custom = 1;
3797: $confhash{'scantron'}{'scantronformat'} =
3798: $scantronurls{'custom'};
3799: my $putresult =
3800: &Apache::lonnet::put_dom('configuration',
3801: \%confhash,$dom);
3802: if ($putresult ne 'ok') {
3803: $error{'custom'} =
3804: '<span class="LC_error">'.
3805: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3806: }
1.46 raeburn 3807: }
3808: } else {
1.60 raeburn 3809: ($scantronurls{'default'},my $error) =
1.46 raeburn 3810: &legacy_scantronformat($r,$dom,$confname,
3811: 'default',$legacyfile{'default'},
3812: $scantronurls{'default'},
3813: $scantronfiles{'default'});
1.60 raeburn 3814: if ($error eq '') {
3815: $confhash{'scantron'}{'scantronformat'} = '';
3816: my $putresult =
3817: &Apache::lonnet::put_dom('configuration',
3818: \%confhash,$dom);
3819: if ($putresult ne 'ok') {
3820: $error{'default'} =
3821: '<span class="LC_error">'.
3822: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3823: }
3824: } else {
3825: $error{'default'} = $error;
3826: }
1.46 raeburn 3827: }
3828: }
3829: }
3830: } else {
1.95 www 3831: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3832: }
3833: }
3834: if (ref($settings) eq 'HASH') {
3835: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3836: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3837: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3838: $scantronurl = '';
3839: } else {
3840: $scantronurl = $settings->{'scantronformat'};
3841: }
3842: $is_custom = 1;
3843: } else {
3844: $scantronurl = $scantronurls{'default'};
3845: }
3846: } else {
1.60 raeburn 3847: if ($is_custom) {
3848: $scantronurl = $scantronurls{'custom'};
3849: } else {
3850: $scantronurl = $scantronurls{'default'};
3851: }
1.46 raeburn 3852: }
3853: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3854: $datatable .= '<tr'.$css_class.'>';
3855: if (!$is_custom) {
1.65 raeburn 3856: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3857: '<span class="LC_nobreak">';
1.46 raeburn 3858: if ($scantronurl) {
3859: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3860: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3861: } else {
3862: $datatable = &mt('File unavailable for display');
3863: }
1.65 raeburn 3864: $datatable .= '</span></td>';
1.60 raeburn 3865: if (keys(%error) == 0) {
3866: $datatable .= '<td valign="bottom">';
3867: if (!$switchserver) {
3868: $datatable .= &mt('Upload:').'<br />';
3869: }
3870: } else {
3871: my $errorstr;
3872: foreach my $key (sort(keys(%error))) {
3873: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3874: }
3875: $datatable .= '<td>'.$errorstr;
3876: }
1.46 raeburn 3877: } else {
3878: if (keys(%error) > 0) {
3879: my $errorstr;
3880: foreach my $key (sort(keys(%error))) {
3881: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3882: }
1.60 raeburn 3883: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3884: } elsif ($scantronurl) {
1.65 raeburn 3885: $datatable .= '<td><span class="LC_nobreak">'.
3886: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3887: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3888: '<input type="checkbox" name="scantronformat_del"'.
3889: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3890: '<td><span class="LC_nobreak"> '.
3891: &mt('Replace:').'</span><br />';
1.46 raeburn 3892: }
3893: }
3894: if (keys(%error) == 0) {
3895: if ($switchserver) {
3896: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3897: } else {
1.65 raeburn 3898: $datatable .='<span class="LC_nobreak"> '.
3899: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3900: }
3901: }
3902: $datatable .= '</td></tr>';
3903: $$rowtotal ++;
3904: return $datatable;
3905: }
3906:
3907: sub legacy_scantronformat {
3908: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3909: my ($url,$error);
3910: my @statinfo = &Apache::lonnet::stat_file($newurl);
3911: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3912: (my $result,$url) =
3913: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3914: '','',$newfile);
3915: if ($result ne 'ok') {
1.130 raeburn 3916: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3917: }
3918: }
3919: return ($url,$error);
3920: }
1.43 raeburn 3921:
1.49 raeburn 3922: sub print_coursecategories {
1.57 raeburn 3923: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3924: my $datatable;
3925: if ($position eq 'top') {
3926: my $toggle_cats_crs = ' ';
3927: my $toggle_cats_dom = ' checked="checked" ';
3928: my $can_cat_crs = ' ';
3929: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3930: my $toggle_catscomm_comm = ' ';
3931: my $toggle_catscomm_dom = ' checked="checked" ';
3932: my $can_catcomm_comm = ' ';
3933: my $can_catcomm_dom = ' checked="checked" ';
3934:
1.57 raeburn 3935: if (ref($settings) eq 'HASH') {
3936: if ($settings->{'togglecats'} eq 'crs') {
3937: $toggle_cats_crs = $toggle_cats_dom;
3938: $toggle_cats_dom = ' ';
3939: }
3940: if ($settings->{'categorize'} eq 'crs') {
3941: $can_cat_crs = $can_cat_dom;
3942: $can_cat_dom = ' ';
3943: }
1.120 raeburn 3944: if ($settings->{'togglecatscomm'} eq 'comm') {
3945: $toggle_catscomm_comm = $toggle_catscomm_dom;
3946: $toggle_catscomm_dom = ' ';
3947: }
3948: if ($settings->{'categorizecomm'} eq 'comm') {
3949: $can_catcomm_comm = $can_catcomm_dom;
3950: $can_catcomm_dom = ' ';
3951: }
1.57 raeburn 3952: }
3953: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3954: togglecats => 'Show/Hide a course in catalog',
3955: togglecatscomm => 'Show/Hide a community in catalog',
3956: categorize => 'Assign a category to a course',
3957: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3958: );
3959: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3960: dom => 'Set in Domain',
3961: crs => 'Set in Course',
3962: comm => 'Set in Community',
1.57 raeburn 3963: );
3964: $datatable = '<tr class="LC_odd_row">'.
3965: '<td>'.$title{'togglecats'}.'</td>'.
3966: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3967: '<input type="radio" name="togglecats"'.
3968: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3969: '<label><input type="radio" name="togglecats"'.
3970: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3971: '</tr><tr>'.
3972: '<td>'.$title{'categorize'}.'</td>'.
3973: '<td class="LC_right_item"><span class="LC_nobreak">'.
3974: '<label><input type="radio" name="categorize"'.
3975: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3976: '<label><input type="radio" name="categorize"'.
3977: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3978: '</tr><tr class="LC_odd_row">'.
3979: '<td>'.$title{'togglecatscomm'}.'</td>'.
3980: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3981: '<input type="radio" name="togglecatscomm"'.
3982: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3983: '<label><input type="radio" name="togglecatscomm"'.
3984: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3985: '</tr><tr>'.
3986: '<td>'.$title{'categorizecomm'}.'</td>'.
3987: '<td class="LC_right_item"><span class="LC_nobreak">'.
3988: '<label><input type="radio" name="categorizecomm"'.
3989: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3990: '<label><input type="radio" name="categorizecomm"'.
3991: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3992: '</tr>';
1.120 raeburn 3993: $$rowtotal += 4;
1.57 raeburn 3994: } else {
3995: my $css_class;
3996: my $itemcount = 1;
3997: my $cathash;
3998: if (ref($settings) eq 'HASH') {
3999: $cathash = $settings->{'cats'};
4000: }
4001: if (ref($cathash) eq 'HASH') {
4002: my (@cats,@trails,%allitems,%idx,@jsarray);
4003: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4004: \%allitems,\%idx,\@jsarray);
4005: my $maxdepth = scalar(@cats);
4006: my $colattrib = '';
4007: if ($maxdepth > 2) {
4008: $colattrib = ' colspan="2" ';
4009: }
4010: my @path;
4011: if (@cats > 0) {
4012: if (ref($cats[0]) eq 'ARRAY') {
4013: my $numtop = @{$cats[0]};
4014: my $maxnum = $numtop;
1.120 raeburn 4015: my %default_names = (
4016: instcode => &mt('Official courses'),
4017: communities => &mt('Communities'),
4018: );
4019:
4020: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4021: ($cathash->{'instcode::0'} eq '') ||
4022: (!grep(/^communities$/,@{$cats[0]})) ||
4023: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4024: $maxnum ++;
4025: }
4026: my $lastidx;
4027: for (my $i=0; $i<$numtop; $i++) {
4028: my $parent = $cats[0][$i];
4029: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4030: my $item = &escape($parent).'::0';
4031: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4032: $lastidx = $idx{$item};
4033: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4034: .'<select name="'.$item.'"'.$chgstr.'>';
4035: for (my $k=0; $k<=$maxnum; $k++) {
4036: my $vpos = $k+1;
4037: my $selstr;
4038: if ($k == $i) {
4039: $selstr = ' selected="selected" ';
4040: }
4041: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4042: }
4043: $datatable .= '</select></td><td>';
1.120 raeburn 4044: if ($parent eq 'instcode' || $parent eq 'communities') {
4045: $datatable .= '<span class="LC_nobreak">'
4046: .$default_names{$parent}.'</span>';
4047: if ($parent eq 'instcode') {
4048: $datatable .= '<br /><span class="LC_nobreak">('
4049: .&mt('with institutional codes')
4050: .')</span></td><td'.$colattrib.'>';
4051: } else {
4052: $datatable .= '<table><tr><td>';
4053: }
4054: $datatable .= '<span class="LC_nobreak">'
4055: .'<label><input type="radio" name="'
4056: .$parent.'" value="1" checked="checked" />'
4057: .&mt('Display').'</label>';
4058: if ($parent eq 'instcode') {
4059: $datatable .= ' ';
4060: } else {
4061: $datatable .= '</span></td></tr><tr><td>'
4062: .'<span class="LC_nobreak">';
4063: }
4064: $datatable .= '<label><input type="radio" name="'
4065: .$parent.'" value="0" />'
4066: .&mt('Do not display').'</label></span>';
4067: if ($parent eq 'communities') {
4068: $datatable .= '</td></tr></table>';
4069: }
4070: $datatable .= '</td>';
1.57 raeburn 4071: } else {
4072: $datatable .= $parent
4073: .' <label><input type="checkbox" name="deletecategory" '
4074: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4075: }
4076: my $depth = 1;
4077: push(@path,$parent);
4078: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4079: pop(@path);
4080: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4081: $itemcount ++;
4082: }
1.48 raeburn 4083: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4084: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4085: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4086: for (my $k=0; $k<=$maxnum; $k++) {
4087: my $vpos = $k+1;
4088: my $selstr;
1.57 raeburn 4089: if ($k == $numtop) {
1.48 raeburn 4090: $selstr = ' selected="selected" ';
4091: }
4092: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4093: }
1.59 bisitz 4094: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4095: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4096: .'</tr>'."\n";
1.48 raeburn 4097: $itemcount ++;
1.120 raeburn 4098: foreach my $default ('instcode','communities') {
4099: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4100: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4101: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4102: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4103: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4104: for (my $k=0; $k<=$maxnum; $k++) {
4105: my $vpos = $k+1;
4106: my $selstr;
4107: if ($k == $maxnum) {
4108: $selstr = ' selected="selected" ';
4109: }
4110: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4111: }
1.120 raeburn 4112: $datatable .= '</select></span></td>'.
4113: '<td><span class="LC_nobreak">'.
4114: $default_names{$default}.'</span>';
4115: if ($default eq 'instcode') {
4116: $datatable .= '<br /><span class="LC_nobreak">('
4117: .&mt('with institutional codes').')</span>';
4118: }
4119: $datatable .= '</td>'
4120: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4121: .&mt('Display').'</label> '
4122: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4123: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4124: }
4125: }
4126: }
1.57 raeburn 4127: } else {
4128: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4129: }
4130: } else {
1.57 raeburn 4131: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4132: .&initialize_categories($itemcount);
1.48 raeburn 4133: }
1.57 raeburn 4134: $$rowtotal += $itemcount;
1.48 raeburn 4135: }
4136: return $datatable;
4137: }
4138:
1.69 raeburn 4139: sub print_serverstatuses {
4140: my ($dom,$settings,$rowtotal) = @_;
4141: my $datatable;
4142: my @pages = &serverstatus_pages();
4143: my (%namedaccess,%machineaccess);
4144: foreach my $type (@pages) {
4145: $namedaccess{$type} = '';
4146: $machineaccess{$type}= '';
4147: }
4148: if (ref($settings) eq 'HASH') {
4149: foreach my $type (@pages) {
4150: if (exists($settings->{$type})) {
4151: if (ref($settings->{$type}) eq 'HASH') {
4152: foreach my $key (keys(%{$settings->{$type}})) {
4153: if ($key eq 'namedusers') {
4154: $namedaccess{$type} = $settings->{$type}->{$key};
4155: } elsif ($key eq 'machines') {
4156: $machineaccess{$type} = $settings->{$type}->{$key};
4157: }
4158: }
4159: }
4160: }
4161: }
4162: }
1.81 raeburn 4163: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4164: my $rownum = 0;
4165: my $css_class;
4166: foreach my $type (@pages) {
4167: $rownum ++;
4168: $css_class = $rownum%2?' class="LC_odd_row"':'';
4169: $datatable .= '<tr'.$css_class.'>'.
4170: '<td><span class="LC_nobreak">'.
4171: $titles->{$type}.'</span></td>'.
4172: '<td class="LC_left_item">'.
4173: '<input type="text" name="'.$type.'_namedusers" '.
4174: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4175: '<td class="LC_right_item">'.
4176: '<span class="LC_nobreak">'.
4177: '<input type="text" name="'.$type.'_machines" '.
4178: 'value="'.$machineaccess{$type}.'" size="10" />'.
4179: '</td></tr>'."\n";
4180: }
4181: $$rowtotal += $rownum;
4182: return $datatable;
4183: }
4184:
4185: sub serverstatus_pages {
4186: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15! raeburn 4187: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4188: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4189: }
4190:
1.49 raeburn 4191: sub coursecategories_javascript {
4192: my ($settings) = @_;
1.57 raeburn 4193: my ($output,$jstext,$cathash);
1.49 raeburn 4194: if (ref($settings) eq 'HASH') {
1.57 raeburn 4195: $cathash = $settings->{'cats'};
4196: }
4197: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4198: my (@cats,@jsarray,%idx);
1.57 raeburn 4199: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4200: if (@jsarray > 0) {
4201: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4202: for (my $i=0; $i<@jsarray; $i++) {
4203: if (ref($jsarray[$i]) eq 'ARRAY') {
4204: my $catstr = join('","',@{$jsarray[$i]});
4205: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4206: }
4207: }
4208: }
4209: } else {
4210: $jstext = ' var categories = Array(1);'."\n".
4211: ' categories[0] = Array("instcode_pos");'."\n";
4212: }
1.120 raeburn 4213: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4214: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4215: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4216: $output = <<"ENDSCRIPT";
4217: <script type="text/javascript">
1.109 raeburn 4218: // <![CDATA[
1.49 raeburn 4219: function reorderCats(form,parent,item,idx) {
4220: var changedVal;
4221: $jstext
4222: var newpos = 'addcategory_pos';
4223: var current = new Array;
4224: if (parent == '') {
4225: var has_instcode = 0;
4226: var maxtop = categories[idx].length;
4227: for (var j=0; j<maxtop; j++) {
4228: if (categories[idx][j] == 'instcode::0') {
4229: has_instcode == 1;
4230: }
4231: }
4232: if (has_instcode == 0) {
4233: categories[idx][maxtop] = 'instcode_pos';
4234: }
4235: } else {
4236: newpos += '_'+parent;
4237: }
4238: var maxh = 1 + categories[idx].length;
4239: var current = new Array;
4240: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4241: if (item == newpos) {
4242: changedVal = newitemVal;
4243: } else {
4244: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4245: current[newitemVal] = newpos;
4246: }
4247: for (var i=0; i<categories[idx].length; i++) {
4248: var elementName = categories[idx][i];
4249: if (elementName != item) {
4250: if (form.elements[elementName]) {
4251: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4252: current[currVal] = elementName;
4253: }
4254: }
4255: }
4256: var oldVal;
4257: for (var j=0; j<maxh; j++) {
4258: if (current[j] == undefined) {
4259: oldVal = j;
4260: }
4261: }
4262: if (oldVal < changedVal) {
4263: for (var k=oldVal+1; k<=changedVal ; k++) {
4264: var elementName = current[k];
4265: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4266: }
4267: } else {
4268: for (var k=changedVal; k<oldVal; k++) {
4269: var elementName = current[k];
4270: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4271: }
4272: }
4273: return;
4274: }
1.120 raeburn 4275:
4276: function categoryCheck(form) {
4277: if (form.elements['addcategory_name'].value == 'instcode') {
4278: alert('$instcode_reserved\\n$choose_again');
4279: return false;
4280: }
4281: if (form.elements['addcategory_name'].value == 'communities') {
4282: alert('$communities_reserved\\n$choose_again');
4283: return false;
4284: }
4285: return true;
4286: }
4287:
1.109 raeburn 4288: // ]]>
1.49 raeburn 4289: </script>
4290:
4291: ENDSCRIPT
4292: return $output;
4293: }
4294:
1.48 raeburn 4295: sub initialize_categories {
4296: my ($itemcount) = @_;
1.120 raeburn 4297: my ($datatable,$css_class,$chgstr);
4298: my %default_names = (
4299: instcode => 'Official courses (with institutional codes)',
4300: communities => 'Communities',
4301: );
4302: my $select0 = ' selected="selected"';
4303: my $select1 = '';
4304: foreach my $default ('instcode','communities') {
4305: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4306: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4307: if ($default eq 'communities') {
4308: $select1 = $select0;
4309: $select0 = '';
4310: }
4311: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4312: .'<select name="'.$default.'_pos">'
4313: .'<option value="0"'.$select0.'>1</option>'
4314: .'<option value="1"'.$select1.'>2</option>'
4315: .'<option value="2">3</option></select> '
4316: .$default_names{$default}
4317: .'</span></td><td><span class="LC_nobreak">'
4318: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4319: .&mt('Display').'</label> <label>'
4320: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4321: .'</label></span></td></tr>';
1.120 raeburn 4322: $itemcount ++;
4323: }
1.48 raeburn 4324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4325: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4326: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4327: .'<select name="addcategory_pos"'.$chgstr.'>'
4328: .'<option value="0">1</option>'
4329: .'<option value="1">2</option>'
4330: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4331: .&mt('Add category').'</td><td>'.&mt('Name:')
4332: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4333: return $datatable;
4334: }
4335:
4336: sub build_category_rows {
1.49 raeburn 4337: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4338: my ($text,$name,$item,$chgstr);
1.48 raeburn 4339: if (ref($cats) eq 'ARRAY') {
4340: my $maxdepth = scalar(@{$cats});
4341: if (ref($cats->[$depth]) eq 'HASH') {
4342: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4343: my $numchildren = @{$cats->[$depth]{$parent}};
4344: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4345: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4346: my ($idxnum,$parent_name,$parent_item);
4347: my $higher = $depth - 1;
4348: if ($higher == 0) {
4349: $parent_name = &escape($parent).'::'.$higher;
4350: } else {
4351: if (ref($path) eq 'ARRAY') {
4352: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4353: }
4354: }
4355: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4356: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4357: if ($j < $numchildren) {
1.48 raeburn 4358: $name = $cats->[$depth]{$parent}[$j];
4359: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4360: $idxnum = $idx->{$item};
4361: } else {
4362: $name = $parent_name;
4363: $item = $parent_item;
1.48 raeburn 4364: }
1.49 raeburn 4365: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4366: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4367: for (my $i=0; $i<=$numchildren; $i++) {
4368: my $vpos = $i+1;
4369: my $selstr;
4370: if ($j == $i) {
4371: $selstr = ' selected="selected" ';
4372: }
4373: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4374: }
4375: $text .= '</select> ';
4376: if ($j < $numchildren) {
4377: my $deeper = $depth+1;
4378: $text .= $name.' '
4379: .'<label><input type="checkbox" name="deletecategory" value="'
4380: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4381: if(ref($path) eq 'ARRAY') {
4382: push(@{$path},$name);
1.49 raeburn 4383: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4384: pop(@{$path});
4385: }
4386: } else {
1.59 bisitz 4387: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4388: if ($j == $numchildren) {
4389: $text .= $name;
4390: } else {
4391: $text .= $item;
4392: }
4393: $text .= '" value="" />';
4394: }
4395: $text .= '</td></tr>';
4396: }
4397: $text .= '</table></td>';
4398: } else {
4399: my $higher = $depth-1;
4400: if ($higher == 0) {
4401: $name = &escape($parent).'::'.$higher;
4402: } else {
4403: if (ref($path) eq 'ARRAY') {
4404: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4405: }
4406: }
4407: my $colspan;
4408: if ($parent ne 'instcode') {
4409: $colspan = $maxdepth - $depth - 1;
4410: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4411: }
4412: }
4413: }
4414: }
4415: return $text;
4416: }
4417:
1.33 raeburn 4418: sub modifiable_userdata_row {
1.63 raeburn 4419: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4420: my $rolename;
1.63 raeburn 4421: if ($context eq 'selfcreate') {
4422: if (ref($usertypes) eq 'HASH') {
4423: $rolename = $usertypes->{$role};
4424: } else {
4425: $rolename = $role;
4426: }
1.33 raeburn 4427: } else {
1.63 raeburn 4428: if ($role eq 'cr') {
4429: $rolename = &mt('Custom role');
4430: } else {
4431: $rolename = &Apache::lonnet::plaintext($role);
4432: }
1.33 raeburn 4433: }
4434: my @fields = ('lastname','firstname','middlename','generation',
4435: 'permanentemail','id');
4436: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4437: my $output;
4438: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4439: $output = '<tr '.$css_class.'>'.
4440: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4441: '<td class="LC_left_item" colspan="2"><table>';
4442: my $rem;
4443: my %checks;
4444: if (ref($settings) eq 'HASH') {
4445: if (ref($settings->{$context}) eq 'HASH') {
4446: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4447: foreach my $field (@fields) {
4448: if ($settings->{$context}->{$role}->{$field}) {
4449: $checks{$field} = ' checked="checked" ';
4450: }
4451: }
4452: }
4453: }
4454: }
4455: for (my $i=0; $i<@fields; $i++) {
4456: my $rem = $i%($numinrow);
4457: if ($rem == 0) {
4458: if ($i > 0) {
4459: $output .= '</tr>';
4460: }
4461: $output .= '<tr>';
4462: }
4463: my $check = ' ';
4464: if (exists($checks{$fields[$i]})) {
4465: $check = $checks{$fields[$i]}
4466: } else {
4467: if ($role eq 'st') {
4468: if (ref($settings) ne 'HASH') {
4469: $check = ' checked="checked" ';
4470: }
4471: }
4472: }
4473: $output .= '<td class="LC_left_item">'.
4474: '<span class="LC_nobreak"><label>'.
4475: '<input type="checkbox" name="canmodify_'.$role.'" '.
4476: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4477: '</label></span></td>';
4478: $rem = @fields%($numinrow);
4479: }
4480: my $colsleft = $numinrow - $rem;
4481: if ($colsleft > 1 ) {
4482: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4483: ' </td>';
4484: } elsif ($colsleft == 1) {
4485: $output .= '<td class="LC_left_item"> </td>';
4486: }
4487: $output .= '</tr></table></td></tr>';
4488: return $output;
4489: }
1.28 raeburn 4490:
1.93 raeburn 4491: sub insttypes_row {
4492: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4493: my %lt = &Apache::lonlocal::texthash (
4494: cansearch => 'Users allowed to search',
4495: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4496: lockablenames => 'User preference to lock name',
1.93 raeburn 4497: );
4498: my $showdom;
4499: if ($context eq 'cansearch') {
4500: $showdom = ' ('.$dom.')';
4501: }
1.160.6.5 raeburn 4502: my $class = 'LC_left_item';
4503: if ($context eq 'statustocreate') {
4504: $class = 'LC_right_item';
4505: }
1.25 raeburn 4506: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4507: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4508: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4509: my $rem;
4510: if (ref($types) eq 'ARRAY') {
4511: for (my $i=0; $i<@{$types}; $i++) {
4512: if (defined($usertypes->{$types->[$i]})) {
4513: my $rem = $i%($numinrow);
4514: if ($rem == 0) {
4515: if ($i > 0) {
4516: $output .= '</tr>';
4517: }
4518: $output .= '<tr>';
1.23 raeburn 4519: }
1.26 raeburn 4520: my $check = ' ';
1.99 raeburn 4521: if (ref($settings) eq 'HASH') {
4522: if (ref($settings->{$context}) eq 'ARRAY') {
4523: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4524: $check = ' checked="checked" ';
4525: }
4526: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4527: $check = ' checked="checked" ';
4528: }
1.23 raeburn 4529: }
1.26 raeburn 4530: $output .= '<td class="LC_left_item">'.
4531: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4532: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4533: 'value="'.$types->[$i].'"'.$check.'/>'.
4534: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4535: }
4536: }
1.26 raeburn 4537: $rem = @{$types}%($numinrow);
1.23 raeburn 4538: }
4539: my $colsleft = $numinrow - $rem;
1.131 raeburn 4540: if (($rem == 0) && (@{$types} > 0)) {
4541: $output .= '<tr>';
4542: }
1.23 raeburn 4543: if ($colsleft > 1) {
1.25 raeburn 4544: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4545: } else {
1.25 raeburn 4546: $output .= '<td class="LC_left_item">';
1.23 raeburn 4547: }
4548: my $defcheck = ' ';
1.99 raeburn 4549: if (ref($settings) eq 'HASH') {
4550: if (ref($settings->{$context}) eq 'ARRAY') {
4551: if (grep(/^default$/,@{$settings->{$context}})) {
4552: $defcheck = ' checked="checked" ';
4553: }
4554: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4555: $defcheck = ' checked="checked" ';
4556: }
1.23 raeburn 4557: }
1.25 raeburn 4558: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4559: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4560: 'value="default"'.$defcheck.'/>'.
4561: $othertitle.'</label></span></td>'.
4562: '</tr></table></td></tr>';
4563: return $output;
1.23 raeburn 4564: }
4565:
4566: sub sorted_searchtitles {
4567: my %searchtitles = &Apache::lonlocal::texthash(
4568: 'uname' => 'username',
4569: 'lastname' => 'last name',
4570: 'lastfirst' => 'last name, first name',
4571: );
4572: my @titleorder = ('uname','lastname','lastfirst');
4573: return (\%searchtitles,\@titleorder);
4574: }
4575:
1.25 raeburn 4576: sub sorted_searchtypes {
4577: my %srchtypes_desc = (
4578: exact => 'is exact match',
4579: contains => 'contains ..',
4580: begins => 'begins with ..',
4581: );
4582: my @srchtypeorder = ('exact','begins','contains');
4583: return (\%srchtypes_desc,\@srchtypeorder);
4584: }
4585:
1.3 raeburn 4586: sub usertype_update_row {
4587: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4588: my $datatable;
4589: my $numinrow = 4;
4590: foreach my $type (@{$types}) {
4591: if (defined($usertypes->{$type})) {
4592: $$rownums ++;
4593: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4594: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4595: '</td><td class="LC_left_item"><table>';
4596: for (my $i=0; $i<@{$fields}; $i++) {
4597: my $rem = $i%($numinrow);
4598: if ($rem == 0) {
4599: if ($i > 0) {
4600: $datatable .= '</tr>';
4601: }
4602: $datatable .= '<tr>';
4603: }
4604: my $check = ' ';
1.39 raeburn 4605: if (ref($settings) eq 'HASH') {
4606: if (ref($settings->{'fields'}) eq 'HASH') {
4607: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4608: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4609: $check = ' checked="checked" ';
4610: }
1.3 raeburn 4611: }
4612: }
4613: }
4614:
4615: if ($i == @{$fields}-1) {
4616: my $colsleft = $numinrow - $rem;
4617: if ($colsleft > 1) {
4618: $datatable .= '<td colspan="'.$colsleft.'">';
4619: } else {
4620: $datatable .= '<td>';
4621: }
4622: } else {
4623: $datatable .= '<td>';
4624: }
1.8 raeburn 4625: $datatable .= '<span class="LC_nobreak"><label>'.
4626: '<input type="checkbox" name="updateable_'.$type.
4627: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4628: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4629: }
4630: $datatable .= '</tr></table></td></tr>';
4631: }
4632: }
4633: return $datatable;
1.1 raeburn 4634: }
4635:
4636: sub modify_login {
1.9 raeburn 4637: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4638: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4639: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4640: %title = ( coursecatalog => 'Display course catalog',
4641: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 4642: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4643: newuser => 'Link for visitors to create a user account',
4644: loginheader => 'Log-in box header');
4645: @offon = ('off','on');
1.112 raeburn 4646: if (ref($domconfig{login}) eq 'HASH') {
4647: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4648: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4649: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4650: }
4651: }
4652: }
1.9 raeburn 4653: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4654: \%domconfig,\%loginhash);
1.160.6.14 raeburn 4655: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4656: foreach my $item (@toggles) {
4657: $loginhash{login}{$item} = $env{'form.'.$item};
4658: }
1.41 raeburn 4659: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4660: if (ref($colchanges{'login'}) eq 'HASH') {
4661: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4662: \%loginhash);
4663: }
1.110 raeburn 4664:
1.149 raeburn 4665: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4666: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4667: if (keys(%servers) > 1) {
4668: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4669: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4670: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4671: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4672: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4673: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4674: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4675: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4676: $changes{'loginvia'}{$lonhost} = 1;
4677: } else {
4678: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4679: $changes{'loginvia'}{$lonhost} = 1;
4680: }
4681: } else {
4682: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4683: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4684: $changes{'loginvia'}{$lonhost} = 1;
4685: }
4686: }
4687: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4688: foreach my $item (@loginvia_attribs) {
4689: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4690: }
4691: } else {
4692: foreach my $item (@loginvia_attribs) {
4693: my $new = $env{'form.'.$lonhost.'_'.$item};
4694: if (($item eq 'serverpath') && ($new eq 'custom')) {
4695: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4696: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4697: $new = '/';
4698: }
4699: }
4700: if (($item eq 'custompath') &&
4701: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4702: $new = '';
4703: }
4704: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4705: $changes{'loginvia'}{$lonhost} = 1;
4706: }
4707: if ($item eq 'exempt') {
4708: $new =~ s/^\s+//;
4709: $new =~ s/\s+$//;
4710: my @poss_ips = split(/\s*[,:]\s*/,$new);
4711: my @okips;
4712: foreach my $ip (@poss_ips) {
4713: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4714: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4715: push(@okips,$ip);
4716: }
4717: }
4718: }
4719: if (@okips > 0) {
4720: $new = join(',',@okips);
4721: } else {
4722: $new = '';
4723: }
4724: }
4725: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4726: }
4727: }
1.112 raeburn 4728: } else {
1.128 raeburn 4729: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4730: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4731: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4732: foreach my $item (@loginvia_attribs) {
4733: my $new = $env{'form.'.$lonhost.'_'.$item};
4734: if (($item eq 'serverpath') && ($new eq 'custom')) {
4735: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4736: $new = '/';
4737: }
4738: }
4739: if (($item eq 'custompath') &&
4740: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4741: $new = '';
4742: }
4743: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4744: }
1.110 raeburn 4745: }
4746: }
4747: }
4748: }
1.119 raeburn 4749:
1.160.6.5 raeburn 4750: my $servadm = $r->dir_config('lonAdmEMail');
4751: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4752: if (ref($domconfig{'login'}) eq 'HASH') {
4753: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4754: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4755: if ($lang eq 'nolang') {
4756: push(@currlangs,$lang);
4757: } elsif (defined($langchoices{$lang})) {
4758: push(@currlangs,$lang);
4759: } else {
4760: next;
4761: }
4762: }
4763: }
4764: }
4765: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4766: if (@currlangs > 0) {
4767: foreach my $lang (@currlangs) {
4768: if (grep(/^\Q$lang\E$/,@delurls)) {
4769: $changes{'helpurl'}{$lang} = 1;
4770: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4771: $changes{'helpurl'}{$lang} = 1;
4772: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4773: push(@newlangs,$lang);
4774: } else {
4775: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4776: }
4777: }
4778: }
4779: unless (grep(/^nolang$/,@currlangs)) {
4780: if ($env{'form.loginhelpurl_nolang.filename'}) {
4781: $changes{'helpurl'}{'nolang'} = 1;
4782: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4783: push(@newlangs,'nolang');
4784: }
4785: }
4786: if ($env{'form.loginhelpurl_add_lang'}) {
4787: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4788: ($env{'form.loginhelpurl_add_file.filename'})) {
4789: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4790: $addedfile = $env{'form.loginhelpurl_add_lang'};
4791: }
4792: }
4793: if ((@newlangs > 0) || ($addedfile)) {
4794: my $error;
4795: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4796: if ($configuserok eq 'ok') {
4797: if ($switchserver) {
4798: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4799: } elsif ($author_ok eq 'ok') {
4800: my @allnew = @newlangs;
4801: if ($addedfile ne '') {
4802: push(@allnew,$addedfile);
4803: }
4804: foreach my $lang (@allnew) {
4805: my $formelem = 'loginhelpurl_'.$lang;
4806: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4807: $formelem = 'loginhelpurl_add_file';
4808: }
4809: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4810: "help/$lang",'','',$newfile{$lang});
4811: if ($result eq 'ok') {
4812: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4813: $changes{'helpurl'}{$lang} = 1;
4814: } else {
4815: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4816: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4817: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4818: (!grep(/^\Q$lang\E$/,@delurls))) {
4819:
4820: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4821: }
4822: }
4823: }
4824: } else {
4825: $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);
4826: }
4827: } else {
4828: $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);
4829: }
4830: if ($error) {
4831: &Apache::lonnet::logthis($error);
4832: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4833: }
4834: }
4835: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4836:
4837: my $defaulthelpfile = '/adm/loginproblems.html';
4838: my $defaulttext = &mt('Default in use');
4839:
1.1 raeburn 4840: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4841: $dom);
4842: if ($putresult eq 'ok') {
1.160.6.14 raeburn 4843: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4844: my %defaultchecked = (
4845: 'coursecatalog' => 'on',
1.160.6.14 raeburn 4846: 'helpdesk' => 'on',
1.42 raeburn 4847: 'adminmail' => 'off',
1.43 raeburn 4848: 'newuser' => 'off',
1.42 raeburn 4849: );
1.55 raeburn 4850: if (ref($domconfig{'login'}) eq 'HASH') {
4851: foreach my $item (@toggles) {
4852: if ($defaultchecked{$item} eq 'on') {
4853: if (($domconfig{'login'}{$item} eq '0') &&
4854: ($env{'form.'.$item} eq '1')) {
4855: $changes{$item} = 1;
4856: } elsif (($domconfig{'login'}{$item} eq '' ||
4857: $domconfig{'login'}{$item} eq '1') &&
4858: ($env{'form.'.$item} eq '0')) {
4859: $changes{$item} = 1;
4860: }
4861: } elsif ($defaultchecked{$item} eq 'off') {
4862: if (($domconfig{'login'}{$item} eq '1') &&
4863: ($env{'form.'.$item} eq '0')) {
4864: $changes{$item} = 1;
4865: } elsif (($domconfig{'login'}{$item} eq '' ||
4866: $domconfig{'login'}{$item} eq '0') &&
4867: ($env{'form.'.$item} eq '1')) {
4868: $changes{$item} = 1;
4869: }
1.42 raeburn 4870: }
4871: }
1.41 raeburn 4872: }
1.6 raeburn 4873: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4874: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4875: $resulttext = &mt('Changes made:').'<ul>';
4876: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4877: if ($item eq 'loginvia') {
1.112 raeburn 4878: if (ref($changes{$item}) eq 'HASH') {
4879: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4880: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4881: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4882: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4883: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4884: $protocol = 'http' if ($protocol ne 'https');
4885: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4886:
4887: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4888: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4889: } else {
4890: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4891: }
4892: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4893: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4894: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4895: }
4896: $resulttext .= '</li>';
4897: } else {
4898: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4899: }
1.112 raeburn 4900: } else {
1.128 raeburn 4901: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4902: }
4903: }
1.128 raeburn 4904: $resulttext .= '</ul></li>';
1.112 raeburn 4905: }
1.160.6.5 raeburn 4906: } elsif ($item eq 'helpurl') {
4907: if (ref($changes{$item}) eq 'HASH') {
4908: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4909: if (grep(/^\Q$lang\E$/,@delurls)) {
4910: my ($chg,$link);
4911: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4912: if ($lang eq 'nolang') {
4913: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4914: } else {
4915: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4916: }
4917: $resulttext .= '<li>'.$chg.'</li>';
4918: } else {
4919: my $chg;
4920: if ($lang eq 'nolang') {
4921: $chg = &mt('custom log-in help file for no preferred language');
4922: } else {
4923: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4924: }
4925: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4926: $loginhash{'login'}{'helpurl'}{$lang}.
4927: '?inhibitmenu=yes',$chg,600,500).
4928: '</li>';
4929: }
4930: }
4931: }
4932: } elsif ($item eq 'captcha') {
4933: if (ref($loginhash{'login'}) eq 'HASH') {
4934: my $chgtxt;
4935: if ($loginhash{'login'}{$item} eq 'notused') {
4936: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4937: } else {
4938: my %captchas = &captcha_phrases();
4939: if ($captchas{$loginhash{'login'}{$item}}) {
4940: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4941: } else {
4942: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4943: }
4944: }
4945: $resulttext .= '<li>'.$chgtxt.'</li>';
4946: }
4947: } elsif ($item eq 'recaptchakeys') {
4948: if (ref($loginhash{'login'}) eq 'HASH') {
4949: my ($privkey,$pubkey);
4950: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4951: $pubkey = $loginhash{'login'}{$item}{'public'};
4952: $privkey = $loginhash{'login'}{$item}{'private'};
4953: }
4954: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4955: if (!$pubkey) {
4956: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4957: } else {
4958: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4959: }
4960: if (!$privkey) {
4961: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4962: } else {
4963: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4964: }
4965: $chgtxt .= '</ul>';
4966: $resulttext .= '<li>'.$chgtxt.'</li>';
4967: }
1.41 raeburn 4968: } else {
4969: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4970: }
1.1 raeburn 4971: }
1.6 raeburn 4972: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4973: } else {
4974: $resulttext = &mt('No changes made to log-in page settings');
4975: }
4976: } else {
1.11 albertel 4977: $resulttext = '<span class="LC_error">'.
4978: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4979: }
1.6 raeburn 4980: if ($errors) {
1.9 raeburn 4981: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4982: $errors.'</ul>';
4983: }
4984: return $resulttext;
4985: }
4986:
4987: sub color_font_choices {
4988: my %choices =
4989: &Apache::lonlocal::texthash (
4990: img => "Header",
4991: bgs => "Background colors",
4992: links => "Link colors",
1.55 raeburn 4993: images => "Images",
1.6 raeburn 4994: font => "Font color",
1.97 tempelho 4995: fontmenu => "Font Menu",
1.76 raeburn 4996: pgbg => "Page",
1.6 raeburn 4997: tabbg => "Header",
4998: sidebg => "Border",
4999: link => "Link",
5000: alink => "Active link",
5001: vlink => "Visited link",
5002: );
5003: return %choices;
5004: }
5005:
5006: sub modify_rolecolors {
1.9 raeburn 5007: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5008: my ($resulttext,%rolehash);
5009: $rolehash{'rolecolors'} = {};
1.55 raeburn 5010: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5011: if ($domconfig{'rolecolors'} eq '') {
5012: $domconfig{'rolecolors'} = {};
5013: }
5014: }
1.9 raeburn 5015: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5016: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5017: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5018: $dom);
5019: if ($putresult eq 'ok') {
5020: if (keys(%changes) > 0) {
1.41 raeburn 5021: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5022: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5023: $rolehash{'rolecolors'});
5024: } else {
5025: $resulttext = &mt('No changes made to default color schemes');
5026: }
5027: } else {
1.11 albertel 5028: $resulttext = '<span class="LC_error">'.
5029: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5030: }
5031: if ($errors) {
5032: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5033: $errors.'</ul>';
5034: }
5035: return $resulttext;
5036: }
5037:
5038: sub modify_colors {
1.9 raeburn 5039: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5040: my (%changes,%choices);
1.51 raeburn 5041: my @bgs;
1.6 raeburn 5042: my @links = ('link','alink','vlink');
1.41 raeburn 5043: my @logintext;
1.6 raeburn 5044: my @images;
5045: my $servadm = $r->dir_config('lonAdmEMail');
5046: my $errors;
5047: foreach my $role (@{$roles}) {
5048: if ($role eq 'login') {
1.12 raeburn 5049: %choices = &login_choices();
1.41 raeburn 5050: @logintext = ('textcol','bgcol');
1.12 raeburn 5051: } else {
5052: %choices = &color_font_choices();
1.107 raeburn 5053: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5054: }
5055: if ($role eq 'login') {
1.41 raeburn 5056: @images = ('img','logo','domlogo','login');
1.51 raeburn 5057: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5058: } else {
5059: @images = ('img');
1.51 raeburn 5060: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5061: }
5062: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5063: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5064: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5065: }
1.46 raeburn 5066: my ($configuserok,$author_ok,$switchserver) =
5067: &config_check($dom,$confname,$servadm);
1.9 raeburn 5068: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5069: if (ref($domconfig->{$role}) ne 'HASH') {
5070: $domconfig->{$role} = {};
5071: }
1.8 raeburn 5072: foreach my $img (@images) {
1.70 raeburn 5073: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5074: if (defined($env{'form.login_showlogo_'.$img})) {
5075: $confhash->{$role}{'showlogo'}{$img} = 1;
5076: } else {
5077: $confhash->{$role}{'showlogo'}{$img} = 0;
5078: }
5079: }
1.18 albertel 5080: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5081: && !defined($domconfig->{$role}{$img})
5082: && !$env{'form.'.$role.'_del_'.$img}
5083: && $env{'form.'.$role.'_import_'.$img}) {
5084: # import the old configured image from the .tab setting
5085: # if they haven't provided a new one
5086: $domconfig->{$role}{$img} =
5087: $env{'form.'.$role.'_import_'.$img};
5088: }
1.6 raeburn 5089: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5090: my $error;
1.6 raeburn 5091: if ($configuserok eq 'ok') {
1.9 raeburn 5092: if ($switchserver) {
1.12 raeburn 5093: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5094: } else {
5095: if ($author_ok eq 'ok') {
5096: my ($result,$logourl) =
5097: &publishlogo($r,'upload',$role.'_'.$img,
5098: $dom,$confname,$img,$width,$height);
5099: if ($result eq 'ok') {
5100: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5101: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5102: } else {
1.12 raeburn 5103: $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 5104: }
5105: } else {
1.46 raeburn 5106: $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 5107: }
5108: }
5109: } else {
1.46 raeburn 5110: $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 5111: }
5112: if ($error) {
1.8 raeburn 5113: &Apache::lonnet::logthis($error);
1.11 albertel 5114: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5115: }
5116: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5117: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5118: my $error;
5119: if ($configuserok eq 'ok') {
5120: # is confname an author?
5121: if ($switchserver eq '') {
5122: if ($author_ok eq 'ok') {
5123: my ($result,$logourl) =
5124: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5125: $dom,$confname,$img,$width,$height);
5126: if ($result eq 'ok') {
5127: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5128: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5129: }
5130: }
5131: }
5132: }
1.6 raeburn 5133: }
5134: }
5135: }
5136: if (ref($domconfig) eq 'HASH') {
5137: if (ref($domconfig->{$role}) eq 'HASH') {
5138: foreach my $img (@images) {
5139: if ($domconfig->{$role}{$img} ne '') {
5140: if ($env{'form.'.$role.'_del_'.$img}) {
5141: $confhash->{$role}{$img} = '';
1.12 raeburn 5142: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5143: } else {
1.9 raeburn 5144: if ($confhash->{$role}{$img} eq '') {
5145: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5146: }
1.6 raeburn 5147: }
5148: } else {
5149: if ($env{'form.'.$role.'_del_'.$img}) {
5150: $confhash->{$role}{$img} = '';
1.12 raeburn 5151: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5152: }
5153: }
1.70 raeburn 5154: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5155: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5156: if ($confhash->{$role}{'showlogo'}{$img} ne
5157: $domconfig->{$role}{'showlogo'}{$img}) {
5158: $changes{$role}{'showlogo'}{$img} = 1;
5159: }
5160: } else {
5161: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5162: $changes{$role}{'showlogo'}{$img} = 1;
5163: }
5164: }
5165: }
5166: }
1.6 raeburn 5167: if ($domconfig->{$role}{'font'} ne '') {
5168: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5169: $changes{$role}{'font'} = 1;
5170: }
5171: } else {
5172: if ($confhash->{$role}{'font'}) {
5173: $changes{$role}{'font'} = 1;
5174: }
5175: }
1.107 raeburn 5176: if ($role ne 'login') {
5177: if ($domconfig->{$role}{'fontmenu'} ne '') {
5178: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5179: $changes{$role}{'fontmenu'} = 1;
5180: }
5181: } else {
5182: if ($confhash->{$role}{'fontmenu'}) {
5183: $changes{$role}{'fontmenu'} = 1;
5184: }
1.97 tempelho 5185: }
5186: }
1.6 raeburn 5187: foreach my $item (@bgs) {
5188: if ($domconfig->{$role}{$item} ne '') {
5189: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5190: $changes{$role}{'bgs'}{$item} = 1;
5191: }
5192: } else {
5193: if ($confhash->{$role}{$item}) {
5194: $changes{$role}{'bgs'}{$item} = 1;
5195: }
5196: }
5197: }
5198: foreach my $item (@links) {
5199: if ($domconfig->{$role}{$item} ne '') {
5200: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5201: $changes{$role}{'links'}{$item} = 1;
5202: }
5203: } else {
5204: if ($confhash->{$role}{$item}) {
5205: $changes{$role}{'links'}{$item} = 1;
5206: }
5207: }
5208: }
1.41 raeburn 5209: foreach my $item (@logintext) {
5210: if ($domconfig->{$role}{$item} ne '') {
5211: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5212: $changes{$role}{'logintext'}{$item} = 1;
5213: }
5214: } else {
5215: if ($confhash->{$role}{$item}) {
5216: $changes{$role}{'logintext'}{$item} = 1;
5217: }
5218: }
5219: }
1.6 raeburn 5220: } else {
5221: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5222: \@logintext,$confhash,\%changes);
1.6 raeburn 5223: }
5224: } else {
5225: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5226: \@logintext,$confhash,\%changes);
1.6 raeburn 5227: }
5228: }
5229: return ($errors,%changes);
5230: }
5231:
1.46 raeburn 5232: sub config_check {
5233: my ($dom,$confname,$servadm) = @_;
5234: my ($configuserok,$author_ok,$switchserver,%currroles);
5235: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5236: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5237: $confname,$servadm);
5238: if ($configuserok eq 'ok') {
5239: $switchserver = &check_switchserver($dom,$confname);
5240: if ($switchserver eq '') {
5241: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5242: }
5243: }
5244: return ($configuserok,$author_ok,$switchserver);
5245: }
5246:
1.6 raeburn 5247: sub default_change_checker {
1.41 raeburn 5248: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5249: foreach my $item (@{$links}) {
5250: if ($confhash->{$role}{$item}) {
5251: $changes->{$role}{'links'}{$item} = 1;
5252: }
5253: }
5254: foreach my $item (@{$bgs}) {
5255: if ($confhash->{$role}{$item}) {
5256: $changes->{$role}{'bgs'}{$item} = 1;
5257: }
5258: }
1.41 raeburn 5259: foreach my $item (@{$logintext}) {
5260: if ($confhash->{$role}{$item}) {
5261: $changes->{$role}{'logintext'}{$item} = 1;
5262: }
5263: }
1.6 raeburn 5264: foreach my $img (@{$images}) {
5265: if ($env{'form.'.$role.'_del_'.$img}) {
5266: $confhash->{$role}{$img} = '';
1.12 raeburn 5267: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5268: }
1.70 raeburn 5269: if ($role eq 'login') {
5270: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5271: $changes->{$role}{'showlogo'}{$img} = 1;
5272: }
5273: }
1.6 raeburn 5274: }
5275: if ($confhash->{$role}{'font'}) {
5276: $changes->{$role}{'font'} = 1;
5277: }
1.48 raeburn 5278: }
1.6 raeburn 5279:
5280: sub display_colorchgs {
5281: my ($dom,$changes,$roles,$confhash) = @_;
5282: my (%choices,$resulttext);
5283: if (!grep(/^login$/,@{$roles})) {
5284: $resulttext = &mt('Changes made:').'<br />';
5285: }
5286: foreach my $role (@{$roles}) {
5287: if ($role eq 'login') {
5288: %choices = &login_choices();
5289: } else {
5290: %choices = &color_font_choices();
5291: }
5292: if (ref($changes->{$role}) eq 'HASH') {
5293: if ($role ne 'login') {
5294: $resulttext .= '<h4>'.&mt($role).'</h4>';
5295: }
5296: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5297: if ($role ne 'login') {
5298: $resulttext .= '<ul>';
5299: }
5300: if (ref($changes->{$role}{$key}) eq 'HASH') {
5301: if ($role ne 'login') {
5302: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5303: }
5304: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5305: if (($role eq 'login') && ($key eq 'showlogo')) {
5306: if ($confhash->{$role}{$key}{$item}) {
5307: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5308: } else {
5309: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5310: }
5311: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5312: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5313: } else {
1.12 raeburn 5314: my $newitem = $confhash->{$role}{$item};
5315: if ($key eq 'images') {
5316: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5317: }
5318: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5319: }
5320: }
5321: if ($role ne 'login') {
5322: $resulttext .= '</ul></li>';
5323: }
5324: } else {
5325: if ($confhash->{$role}{$key} eq '') {
5326: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5327: } else {
5328: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5329: }
5330: }
5331: if ($role ne 'login') {
5332: $resulttext .= '</ul>';
5333: }
5334: }
5335: }
5336: }
1.3 raeburn 5337: return $resulttext;
1.1 raeburn 5338: }
5339:
1.9 raeburn 5340: sub thumb_dimensions {
5341: return ('200','50');
5342: }
5343:
1.16 raeburn 5344: sub check_dimensions {
5345: my ($inputfile) = @_;
5346: my ($fullwidth,$fullheight);
5347: if ($inputfile =~ m|^[/\w.\-]+$|) {
5348: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5349: my $imageinfo = <PIPE>;
5350: if (!close(PIPE)) {
5351: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5352: }
5353: chomp($imageinfo);
5354: my ($fullsize) =
1.21 raeburn 5355: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5356: if ($fullsize) {
5357: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5358: }
5359: }
5360: }
5361: return ($fullwidth,$fullheight);
5362: }
5363:
1.9 raeburn 5364: sub check_configuser {
5365: my ($uhome,$dom,$confname,$servadm) = @_;
5366: my ($configuserok,%currroles);
5367: if ($uhome eq 'no_host') {
5368: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5369: my $configpass = &LONCAPA::Enrollment::create_password();
5370: $configuserok =
5371: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5372: $configpass,'','','','','',undef,$servadm);
5373: } else {
5374: $configuserok = 'ok';
5375: %currroles =
5376: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5377: }
5378: return ($configuserok,%currroles);
5379: }
5380:
5381: sub check_authorstatus {
5382: my ($dom,$confname,%currroles) = @_;
5383: my $author_ok;
1.40 raeburn 5384: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5385: my $start = time;
5386: my $end = 0;
5387: $author_ok =
5388: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5389: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5390: } else {
5391: $author_ok = 'ok';
5392: }
5393: return $author_ok;
5394: }
5395:
5396: sub publishlogo {
1.46 raeburn 5397: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5398: my ($output,$fname,$logourl);
5399: if ($action eq 'upload') {
5400: $fname=$env{'form.'.$formname.'.filename'};
5401: chop($env{'form.'.$formname});
5402: } else {
5403: ($fname) = ($formname =~ /([^\/]+)$/);
5404: }
1.46 raeburn 5405: if ($savefileas ne '') {
5406: $fname = $savefileas;
5407: }
1.9 raeburn 5408: $fname=&Apache::lonnet::clean_filename($fname);
5409: # See if there is anything left
5410: unless ($fname) { return ('error: no uploaded file'); }
5411: $fname="$subdir/$fname";
1.160.6.5 raeburn 5412: my $docroot=$r->dir_config('lonDocRoot');
5413: my $filepath="$docroot/priv";
5414: my $relpath = "$dom/$confname";
1.9 raeburn 5415: my ($fnamepath,$file,$fetchthumb);
5416: $file=$fname;
5417: if ($fname=~m|/|) {
5418: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5419: }
1.160.6.5 raeburn 5420: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5421: my $count;
1.160.6.5 raeburn 5422: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5423: $filepath.="/$parts[$count]";
5424: if ((-e $filepath)!=1) {
5425: mkdir($filepath,02770);
5426: }
5427: }
5428: # Check for bad extension and disallow upload
5429: if ($file=~/\.(\w+)$/ &&
5430: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5431: $output =
5432: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5433: } elsif ($file=~/\.(\w+)$/ &&
5434: !defined(&Apache::loncommon::fileembstyle($1))) {
5435: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5436: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5437: $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 5438: } elsif (-d "$filepath/$file") {
5439: $output = &mt('File name is a directory name - rename the file and re-upload');
5440: } else {
5441: my $source = $filepath.'/'.$file;
5442: my $logfile;
5443: if (!open($logfile,">>$source".'.log')) {
5444: return (&mt('No write permission to Construction Space'));
5445: }
5446: print $logfile
5447: "\n================= Publish ".localtime()." ================\n".
5448: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5449: # Save the file
5450: if (!open(FH,'>'.$source)) {
5451: &Apache::lonnet::logthis('Failed to create '.$source);
5452: return (&mt('Failed to create file'));
5453: }
5454: if ($action eq 'upload') {
5455: if (!print FH ($env{'form.'.$formname})) {
5456: &Apache::lonnet::logthis('Failed to write to '.$source);
5457: return (&mt('Failed to write file'));
5458: }
5459: } else {
5460: my $original = &Apache::lonnet::filelocation('',$formname);
5461: if(!copy($original,$source)) {
5462: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5463: return (&mt('Failed to write file'));
5464: }
5465: }
5466: close(FH);
5467: chmod(0660, $source); # Permissions to rw-rw---.
5468:
5469: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5470: my $copyfile=$targetdir.'/'.$file;
5471:
5472: my @parts=split(/\//,$targetdir);
5473: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5474: for (my $count=5;$count<=$#parts;$count++) {
5475: $path.="/$parts[$count]";
5476: if (!-e $path) {
5477: print $logfile "\nCreating directory ".$path;
5478: mkdir($path,02770);
5479: }
5480: }
5481: my $versionresult;
5482: if (-e $copyfile) {
5483: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5484: } else {
5485: $versionresult = 'ok';
5486: }
5487: if ($versionresult eq 'ok') {
5488: if (copy($source,$copyfile)) {
5489: print $logfile "\nCopied original source to ".$copyfile."\n";
5490: $output = 'ok';
5491: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5492: push(@{$modified_urls},[$copyfile,$source]);
5493: my $metaoutput =
5494: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5495: unless ($registered_cleanup) {
5496: my $handlers = $r->get_handlers('PerlCleanupHandler');
5497: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5498: $registered_cleanup=1;
5499: }
1.9 raeburn 5500: } else {
5501: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5502: $output = &mt('Failed to copy file to RES space').", $!";
5503: }
5504: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5505: my $inputfile = $filepath.'/'.$file;
5506: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5507: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5508: if ($fullwidth ne '' && $fullheight ne '') {
5509: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5510: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5511: system("convert -sample $thumbsize $inputfile $outfile");
5512: chmod(0660, $filepath.'/tn-'.$file);
5513: if (-e $outfile) {
5514: my $copyfile=$targetdir.'/tn-'.$file;
5515: if (copy($outfile,$copyfile)) {
5516: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5517: my $thumb_metaoutput =
5518: &write_metadata($dom,$confname,$formname,
5519: $targetdir,'tn-'.$file,$logfile);
5520: push(@{$modified_urls},[$copyfile,$outfile]);
5521: unless ($registered_cleanup) {
5522: my $handlers = $r->get_handlers('PerlCleanupHandler');
5523: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5524: $registered_cleanup=1;
5525: }
1.16 raeburn 5526: } else {
5527: print $logfile "\nUnable to write ".$copyfile.
5528: ':'.$!."\n";
5529: }
5530: }
1.9 raeburn 5531: }
5532: }
5533: }
5534: } else {
5535: $output = $versionresult;
5536: }
5537: }
5538: return ($output,$logourl);
5539: }
5540:
5541: sub logo_versioning {
5542: my ($targetdir,$file,$logfile) = @_;
5543: my $target = $targetdir.'/'.$file;
5544: my ($maxversion,$fn,$extn,$output);
5545: $maxversion = 0;
5546: if ($file =~ /^(.+)\.(\w+)$/) {
5547: $fn=$1;
5548: $extn=$2;
5549: }
5550: opendir(DIR,$targetdir);
5551: while (my $filename=readdir(DIR)) {
5552: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5553: $maxversion=($1>$maxversion)?$1:$maxversion;
5554: }
5555: }
5556: $maxversion++;
5557: print $logfile "\nCreating old version ".$maxversion."\n";
5558: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5559: if (copy($target,$copyfile)) {
5560: print $logfile "Copied old target to ".$copyfile."\n";
5561: $copyfile=$copyfile.'.meta';
5562: if (copy($target.'.meta',$copyfile)) {
5563: print $logfile "Copied old target metadata to ".$copyfile."\n";
5564: $output = 'ok';
5565: } else {
5566: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5567: $output = &mt('Failed to copy old meta').", $!, ";
5568: }
5569: } else {
5570: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5571: $output = &mt('Failed to copy old target').", $!, ";
5572: }
5573: return $output;
5574: }
5575:
5576: sub write_metadata {
5577: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5578: my (%metadatafields,%metadatakeys,$output);
5579: $metadatafields{'title'}=$formname;
5580: $metadatafields{'creationdate'}=time;
5581: $metadatafields{'lastrevisiondate'}=time;
5582: $metadatafields{'copyright'}='public';
5583: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5584: $env{'user.domain'};
5585: $metadatafields{'authorspace'}=$confname.':'.$dom;
5586: $metadatafields{'domain'}=$dom;
5587: {
5588: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5589: my $mfh;
1.155 raeburn 5590: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5591: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5592: unless ($_=~/\./) {
5593: my $unikey=$_;
5594: $unikey=~/^([A-Za-z]+)/;
5595: my $tag=$1;
5596: $tag=~tr/A-Z/a-z/;
5597: print $mfh "\n\<$tag";
5598: foreach (split(/\,/,$metadatakeys{$unikey})) {
5599: my $value=$metadatafields{$unikey.'.'.$_};
5600: $value=~s/\"/\'\'/g;
5601: print $mfh ' '.$_.'="'.$value.'"';
5602: }
5603: print $mfh '>'.
5604: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5605: .'</'.$tag.'>';
5606: }
5607: }
5608: $output = 'ok';
5609: print $logfile "\nWrote metadata";
5610: close($mfh);
5611: } else {
5612: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5613: $output = &mt('Could not write metadata');
5614: }
5615: }
1.155 raeburn 5616: return $output;
5617: }
5618:
5619: sub notifysubscribed {
5620: foreach my $targetsource (@{$modified_urls}){
5621: next unless (ref($targetsource) eq 'ARRAY');
5622: my ($target,$source)=@{$targetsource};
5623: if ($source ne '') {
5624: if (open(my $logfh,'>>'.$source.'.log')) {
5625: print $logfh "\nCleanup phase: Notifications\n";
5626: my @subscribed=&subscribed_hosts($target);
5627: foreach my $subhost (@subscribed) {
5628: print $logfh "\nNotifying host ".$subhost.':';
5629: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5630: print $logfh $reply;
5631: }
5632: my @subscribedmeta=&subscribed_hosts("$target.meta");
5633: foreach my $subhost (@subscribedmeta) {
5634: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5635: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5636: $subhost);
5637: print $logfh $reply;
5638: }
5639: print $logfh "\n============ Done ============\n";
1.160 raeburn 5640: close($logfh);
1.155 raeburn 5641: }
5642: }
5643: }
5644: return OK;
5645: }
5646:
5647: sub subscribed_hosts {
5648: my ($target) = @_;
5649: my @subscribed;
5650: if (open(my $fh,"<$target.subscription")) {
5651: while (my $subline=<$fh>) {
5652: if ($subline =~ /^($match_lonid):/) {
5653: my $host = $1;
5654: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5655: unless (grep(/^\Q$host\E$/,@subscribed)) {
5656: push(@subscribed,$host);
5657: }
5658: }
5659: }
5660: }
5661: }
5662: return @subscribed;
1.9 raeburn 5663: }
5664:
5665: sub check_switchserver {
5666: my ($dom,$confname) = @_;
5667: my ($allowed,$switchserver);
5668: my $home = &Apache::lonnet::homeserver($confname,$dom);
5669: if ($home eq 'no_host') {
5670: $home = &Apache::lonnet::domain($dom,'primary');
5671: }
5672: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5673: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5674: if (!$allowed) {
1.160.6.11 raeburn 5675: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5676: }
5677: return $switchserver;
5678: }
5679:
1.1 raeburn 5680: sub modify_quotas {
1.86 raeburn 5681: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5682: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5683: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5684: if ($action eq 'quotas') {
5685: $context = 'tools';
5686: } else {
5687: $context = $action;
5688: }
5689: if ($context eq 'requestcourses') {
1.98 raeburn 5690: @usertools = ('official','unofficial','community');
1.106 raeburn 5691: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5692: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5693: %titles = &courserequest_titles();
5694: $toolregexp = join('|',@usertools);
5695: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5696: } elsif ($context eq 'requestauthor') {
5697: @usertools = ('author');
5698: %titles = &authorrequest_titles();
1.86 raeburn 5699: } else {
1.160.6.4 raeburn 5700: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5701: %titles = &tool_titles();
1.86 raeburn 5702: }
1.72 raeburn 5703: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5704: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5705: foreach my $key (keys(%env)) {
1.101 raeburn 5706: if ($context eq 'requestcourses') {
5707: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5708: my $item = $1;
5709: my $type = $2;
5710: if ($type =~ /^limit_(.+)/) {
5711: $limithash{$item}{$1} = $env{$key};
5712: } else {
5713: $confhash{$item}{$type} = $env{$key};
5714: }
5715: }
1.160.6.5 raeburn 5716: } elsif ($context eq 'requestauthor') {
5717: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5718: $confhash{$1} = $env{$key};
5719: }
1.101 raeburn 5720: } else {
1.86 raeburn 5721: if ($key =~ /^form\.quota_(.+)$/) {
5722: $confhash{'defaultquota'}{$1} = $env{$key};
5723: }
1.101 raeburn 5724: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5725: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5726: }
1.72 raeburn 5727: }
5728: }
1.160.6.5 raeburn 5729: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5730: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5731: @approvalnotify = sort(@approvalnotify);
5732: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5733: if (ref($domconfig{$action}) eq 'HASH') {
5734: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5735: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5736: $changes{'notify'}{'approval'} = 1;
5737: }
5738: } else {
1.144 raeburn 5739: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5740: $changes{'notify'}{'approval'} = 1;
5741: }
5742: }
5743: } else {
1.144 raeburn 5744: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5745: $changes{'notify'}{'approval'} = 1;
5746: }
5747: }
5748: } else {
1.86 raeburn 5749: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5750: }
1.72 raeburn 5751: foreach my $item (@usertools) {
5752: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5753: my $unset;
1.101 raeburn 5754: if ($context eq 'requestcourses') {
1.104 raeburn 5755: $unset = '0';
5756: if ($type eq '_LC_adv') {
5757: $unset = '';
5758: }
1.101 raeburn 5759: if ($confhash{$item}{$type} eq 'autolimit') {
5760: $confhash{$item}{$type} .= '=';
5761: unless ($limithash{$item}{$type} =~ /\D/) {
5762: $confhash{$item}{$type} .= $limithash{$item}{$type};
5763: }
5764: }
1.160.6.5 raeburn 5765: } elsif ($context eq 'requestauthor') {
5766: $unset = '0';
5767: if ($type eq '_LC_adv') {
5768: $unset = '';
5769: }
1.72 raeburn 5770: } else {
1.101 raeburn 5771: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5772: $confhash{$item}{$type} = 1;
5773: } else {
5774: $confhash{$item}{$type} = 0;
5775: }
1.72 raeburn 5776: }
1.86 raeburn 5777: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5778: if ($action eq 'requestauthor') {
5779: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5780: $changes{$type} = 1;
5781: }
5782: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5783: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5784: $changes{$item}{$type} = 1;
5785: }
5786: } else {
5787: if ($context eq 'requestcourses') {
1.104 raeburn 5788: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5789: $changes{$item}{$type} = 1;
5790: }
5791: } else {
5792: if (!$confhash{$item}{$type}) {
5793: $changes{$item}{$type} = 1;
5794: }
5795: }
5796: }
5797: } else {
5798: if ($context eq 'requestcourses') {
1.104 raeburn 5799: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5800: $changes{$item}{$type} = 1;
5801: }
1.160.6.5 raeburn 5802: } elsif ($context eq 'requestauthor') {
5803: if ($confhash{$type} ne $unset) {
5804: $changes{$type} = 1;
5805: }
1.72 raeburn 5806: } else {
5807: if (!$confhash{$item}{$type}) {
5808: $changes{$item}{$type} = 1;
5809: }
5810: }
5811: }
1.1 raeburn 5812: }
5813: }
1.160.6.5 raeburn 5814: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5815: if (ref($domconfig{'quotas'}) eq 'HASH') {
5816: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5817: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5818: if (exists($confhash{'defaultquota'}{$key})) {
5819: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5820: $changes{'defaultquota'}{$key} = 1;
5821: }
5822: } else {
5823: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5824: }
5825: }
1.86 raeburn 5826: } else {
5827: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5828: if (exists($confhash{'defaultquota'}{$key})) {
5829: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5830: $changes{'defaultquota'}{$key} = 1;
5831: }
5832: } else {
5833: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5834: }
1.1 raeburn 5835: }
5836: }
5837: }
1.86 raeburn 5838: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5839: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5840: if (ref($domconfig{'quotas'}) eq 'HASH') {
5841: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5842: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5843: $changes{'defaultquota'}{$key} = 1;
5844: }
5845: } else {
5846: if (!exists($domconfig{'quotas'}{$key})) {
5847: $changes{'defaultquota'}{$key} = 1;
5848: }
1.72 raeburn 5849: }
5850: } else {
1.86 raeburn 5851: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5852: }
1.1 raeburn 5853: }
5854: }
5855: }
1.72 raeburn 5856:
1.160.6.5 raeburn 5857: if ($context eq 'requestauthor') {
5858: $domdefaults{'requestauthor'} = \%confhash;
5859: } else {
5860: foreach my $key (keys(%confhash)) {
5861: $domdefaults{$key} = $confhash{$key};
5862: }
1.72 raeburn 5863: }
1.160.6.5 raeburn 5864:
1.1 raeburn 5865: my %quotahash = (
1.86 raeburn 5866: $action => { %confhash }
1.1 raeburn 5867: );
5868: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5869: $dom);
5870: if ($putresult eq 'ok') {
5871: if (keys(%changes) > 0) {
1.72 raeburn 5872: my $cachetime = 24*60*60;
5873: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5874:
1.1 raeburn 5875: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 5876: unless (($context eq 'requestcourses') ||
5877: ($context eq 'requestauthor')) {
1.86 raeburn 5878: if (ref($changes{'defaultquota'}) eq 'HASH') {
5879: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5880: foreach my $type (@{$types},'default') {
5881: if (defined($changes{'defaultquota'}{$type})) {
5882: my $typetitle = $usertypes->{$type};
5883: if ($type eq 'default') {
5884: $typetitle = $othertitle;
5885: }
5886: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5887: }
5888: }
1.86 raeburn 5889: $resulttext .= '</ul></li>';
1.72 raeburn 5890: }
5891: }
1.80 raeburn 5892: my %newenv;
1.72 raeburn 5893: foreach my $item (@usertools) {
1.160.6.5 raeburn 5894: my (%haschgs,%inconf);
5895: if ($context eq 'requestauthor') {
5896: %haschgs = %changes;
5897: %inconf = %confhash;
5898: } else {
5899: if (ref($changes{$item}) eq 'HASH') {
5900: %haschgs = %{$changes{$item}};
5901: }
5902: if (ref($confhash{$item}) eq 'HASH') {
5903: %inconf = %{$confhash{$item}};
5904: }
5905: }
5906: if (keys(%haschgs) > 0) {
1.80 raeburn 5907: my $newacc =
5908: &Apache::lonnet::usertools_access($env{'user.name'},
5909: $env{'user.domain'},
1.86 raeburn 5910: $item,'reload',$context);
1.160.6.5 raeburn 5911: if (($context eq 'requestcourses') ||
5912: ($context eq 'requestauthor')) {
1.108 raeburn 5913: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5914: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5915: }
5916: } else {
5917: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5918: $newenv{'environment.availabletools.'.$item} = $newacc;
5919: }
1.80 raeburn 5920: }
1.160.6.5 raeburn 5921: unless ($context eq 'requestauthor') {
5922: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5923: }
1.72 raeburn 5924: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 5925: if ($haschgs{$type}) {
1.72 raeburn 5926: my $typetitle = $usertypes->{$type};
5927: if ($type eq 'default') {
5928: $typetitle = $othertitle;
5929: } elsif ($type eq '_LC_adv') {
5930: $typetitle = 'LON-CAPA Advanced Users';
5931: }
1.160.6.5 raeburn 5932: if ($inconf{$type}) {
1.101 raeburn 5933: if ($context eq 'requestcourses') {
5934: my $cond;
1.160.6.5 raeburn 5935: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5936: if ($1 eq '') {
5937: $cond = &mt('(Automatic processing of any request).');
5938: } else {
5939: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5940: }
5941: } else {
1.160.6.5 raeburn 5942: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5943: }
5944: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 5945: } elsif ($context eq 'requestauthor') {
5946: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5947: $titles{$inconf{$type}},$typetitle);
5948:
1.101 raeburn 5949: } else {
5950: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5951: }
1.72 raeburn 5952: } else {
1.104 raeburn 5953: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 5954: if ($inconf{$type} eq '0') {
1.104 raeburn 5955: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5956: } else {
5957: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5958: }
5959: } else {
5960: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5961: }
1.72 raeburn 5962: }
5963: }
1.26 raeburn 5964: }
1.160.6.5 raeburn 5965: unless ($context eq 'requestauthor') {
5966: $resulttext .= '</ul></li>';
5967: }
1.26 raeburn 5968: }
1.1 raeburn 5969: }
1.160.6.5 raeburn 5970: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5971: if (ref($changes{'notify'}) eq 'HASH') {
5972: if ($changes{'notify'}{'approval'}) {
5973: if (ref($confhash{'notify'}) eq 'HASH') {
5974: if ($confhash{'notify'}{'approval'}) {
5975: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5976: } else {
1.160.6.5 raeburn 5977: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5978: }
5979: }
5980: }
5981: }
5982: }
1.1 raeburn 5983: $resulttext .= '</ul>';
1.80 raeburn 5984: if (keys(%newenv)) {
5985: &Apache::lonnet::appenv(\%newenv);
5986: }
1.1 raeburn 5987: } else {
1.86 raeburn 5988: if ($context eq 'requestcourses') {
5989: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 5990: } elsif ($context eq 'requestauthor') {
5991: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5992: } else {
1.90 weissno 5993: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5994: }
1.1 raeburn 5995: }
5996: } else {
1.11 albertel 5997: $resulttext = '<span class="LC_error">'.
5998: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5999: }
1.3 raeburn 6000: return $resulttext;
1.1 raeburn 6001: }
6002:
1.3 raeburn 6003: sub modify_autoenroll {
6004: my ($dom,%domconfig) = @_;
1.1 raeburn 6005: my ($resulttext,%changes);
6006: my %currautoenroll;
6007: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6008: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6009: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6010: }
6011: }
6012: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6013: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6014: sender => 'Sender for notification messages',
6015: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6016: my @offon = ('off','on');
1.17 raeburn 6017: my $sender_uname = $env{'form.sender_uname'};
6018: my $sender_domain = $env{'form.sender_domain'};
6019: if ($sender_domain eq '') {
6020: $sender_uname = '';
6021: } elsif ($sender_uname eq '') {
6022: $sender_domain = '';
6023: }
1.129 raeburn 6024: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6025: my %autoenrollhash = (
1.129 raeburn 6026: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6027: 'sender_uname' => $sender_uname,
6028: 'sender_domain' => $sender_domain,
6029: 'co-owners' => $coowners,
1.1 raeburn 6030: }
6031: );
1.4 raeburn 6032: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6033: $dom);
1.1 raeburn 6034: if ($putresult eq 'ok') {
6035: if (exists($currautoenroll{'run'})) {
6036: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6037: $changes{'run'} = 1;
6038: }
6039: } elsif ($autorun) {
6040: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6041: $changes{'run'} = 1;
1.1 raeburn 6042: }
6043: }
1.17 raeburn 6044: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6045: $changes{'sender'} = 1;
6046: }
1.17 raeburn 6047: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6048: $changes{'sender'} = 1;
6049: }
1.129 raeburn 6050: if ($currautoenroll{'co-owners'} ne '') {
6051: if ($currautoenroll{'co-owners'} ne $coowners) {
6052: $changes{'coowners'} = 1;
6053: }
6054: } elsif ($coowners) {
6055: $changes{'coowners'} = 1;
6056: }
1.1 raeburn 6057: if (keys(%changes) > 0) {
6058: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6059: if ($changes{'run'}) {
1.1 raeburn 6060: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6061: }
6062: if ($changes{'sender'}) {
1.17 raeburn 6063: if ($sender_uname eq '' || $sender_domain eq '') {
6064: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6065: } else {
6066: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6067: }
1.1 raeburn 6068: }
1.129 raeburn 6069: if ($changes{'coowners'}) {
6070: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6071: &Apache::loncommon::devalidate_domconfig_cache($dom);
6072: }
1.1 raeburn 6073: $resulttext .= '</ul>';
6074: } else {
6075: $resulttext = &mt('No changes made to auto-enrollment settings');
6076: }
6077: } else {
1.11 albertel 6078: $resulttext = '<span class="LC_error">'.
6079: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6080: }
1.3 raeburn 6081: return $resulttext;
1.1 raeburn 6082: }
6083:
6084: sub modify_autoupdate {
1.3 raeburn 6085: my ($dom,%domconfig) = @_;
1.1 raeburn 6086: my ($resulttext,%currautoupdate,%fields,%changes);
6087: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6088: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6089: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6090: }
6091: }
6092: my @offon = ('off','on');
6093: my %title = &Apache::lonlocal::texthash (
6094: run => 'Auto-update:',
6095: classlists => 'Updates to user information in classlists?'
6096: );
1.44 raeburn 6097: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6098: my %fieldtitles = &Apache::lonlocal::texthash (
6099: id => 'Student/Employee ID',
1.20 raeburn 6100: permanentemail => 'E-mail address',
1.1 raeburn 6101: lastname => 'Last Name',
6102: firstname => 'First Name',
6103: middlename => 'Middle Name',
1.132 raeburn 6104: generation => 'Generation',
1.1 raeburn 6105: );
1.142 raeburn 6106: $othertitle = &mt('All users');
1.1 raeburn 6107: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6108: $othertitle = &mt('Other users');
1.1 raeburn 6109: }
6110: foreach my $key (keys(%env)) {
6111: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6112: my ($usertype,$item) = ($1,$2);
6113: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6114: if ($usertype eq 'default') {
6115: push(@{$fields{$1}},$2);
6116: } elsif (ref($types) eq 'ARRAY') {
6117: if (grep(/^\Q$usertype\E$/,@{$types})) {
6118: push(@{$fields{$1}},$2);
6119: }
6120: }
6121: }
1.1 raeburn 6122: }
6123: }
1.131 raeburn 6124: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6125: @lockablenames = sort(@lockablenames);
6126: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6127: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6128: if (@changed) {
6129: $changes{'lockablenames'} = 1;
6130: }
6131: } else {
6132: if (@lockablenames) {
6133: $changes{'lockablenames'} = 1;
6134: }
6135: }
1.1 raeburn 6136: my %updatehash = (
6137: autoupdate => { run => $env{'form.autoupdate_run'},
6138: classlists => $env{'form.classlists'},
6139: fields => {%fields},
1.131 raeburn 6140: lockablenames => \@lockablenames,
1.1 raeburn 6141: }
6142: );
6143: foreach my $key (keys(%currautoupdate)) {
6144: if (($key eq 'run') || ($key eq 'classlists')) {
6145: if (exists($updatehash{autoupdate}{$key})) {
6146: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6147: $changes{$key} = 1;
6148: }
6149: }
6150: } elsif ($key eq 'fields') {
6151: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6152: foreach my $item (@{$types},'default') {
1.1 raeburn 6153: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6154: my $change = 0;
6155: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6156: if (!exists($fields{$item})) {
6157: $change = 1;
1.132 raeburn 6158: last;
1.1 raeburn 6159: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6160: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6161: $change = 1;
1.132 raeburn 6162: last;
1.1 raeburn 6163: }
6164: }
6165: }
6166: if ($change) {
6167: push(@{$changes{$key}},$item);
6168: }
1.26 raeburn 6169: }
1.1 raeburn 6170: }
6171: }
1.131 raeburn 6172: } elsif ($key eq 'lockablenames') {
6173: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6174: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6175: if (@changed) {
6176: $changes{'lockablenames'} = 1;
6177: }
6178: } else {
6179: if (@lockablenames) {
6180: $changes{'lockablenames'} = 1;
6181: }
6182: }
6183: }
6184: }
6185: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6186: if (@lockablenames) {
6187: $changes{'lockablenames'} = 1;
1.1 raeburn 6188: }
6189: }
1.26 raeburn 6190: foreach my $item (@{$types},'default') {
6191: if (defined($fields{$item})) {
6192: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6193: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6194: my $change = 0;
6195: if (ref($fields{$item}) eq 'ARRAY') {
6196: foreach my $type (@{$fields{$item}}) {
6197: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6198: $change = 1;
6199: last;
6200: }
6201: }
6202: }
6203: if ($change) {
6204: push(@{$changes{'fields'}},$item);
6205: }
6206: } else {
1.26 raeburn 6207: push(@{$changes{'fields'}},$item);
6208: }
6209: } else {
6210: push(@{$changes{'fields'}},$item);
1.1 raeburn 6211: }
6212: }
6213: }
6214: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6215: $dom);
6216: if ($putresult eq 'ok') {
6217: if (keys(%changes) > 0) {
6218: $resulttext = &mt('Changes made:').'<ul>';
6219: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6220: if ($key eq 'lockablenames') {
6221: $resulttext .= '<li>';
6222: if (@lockablenames) {
6223: $usertypes->{'default'} = $othertitle;
6224: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6225: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6226: } else {
6227: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6228: }
6229: $resulttext .= '</li>';
6230: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6231: foreach my $item (@{$changes{$key}}) {
6232: my @newvalues;
6233: foreach my $type (@{$fields{$item}}) {
6234: push(@newvalues,$fieldtitles{$type});
6235: }
1.3 raeburn 6236: my $newvaluestr;
6237: if (@newvalues > 0) {
6238: $newvaluestr = join(', ',@newvalues);
6239: } else {
6240: $newvaluestr = &mt('none');
1.6 raeburn 6241: }
1.1 raeburn 6242: if ($item eq 'default') {
1.26 raeburn 6243: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6244: } else {
1.26 raeburn 6245: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6246: }
6247: }
6248: } else {
6249: my $newvalue;
6250: if ($key eq 'run') {
6251: $newvalue = $offon[$env{'form.autoupdate_run'}];
6252: } else {
6253: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6254: }
1.1 raeburn 6255: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6256: }
6257: }
6258: $resulttext .= '</ul>';
6259: } else {
1.3 raeburn 6260: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6261: }
6262: } else {
1.11 albertel 6263: $resulttext = '<span class="LC_error">'.
6264: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6265: }
1.3 raeburn 6266: return $resulttext;
1.1 raeburn 6267: }
6268:
1.125 raeburn 6269: sub modify_autocreate {
6270: my ($dom,%domconfig) = @_;
6271: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6272: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6273: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6274: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6275: }
6276: }
6277: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6278: req => 'Auto-creation of validated requests for official courses',
6279: xmldc => 'Identity of course creator of courses from XML files',
6280: );
6281: my @types = ('xml','req');
6282: foreach my $item (@types) {
6283: $newvals{$item} = $env{'form.autocreate_'.$item};
6284: $newvals{$item} =~ s/\D//g;
6285: $newvals{$item} = 0 if ($newvals{$item} eq '');
6286: }
6287: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6288: my %domcoords = &get_active_dcs($dom);
6289: unless (exists($domcoords{$newvals{'xmldc'}})) {
6290: $newvals{'xmldc'} = '';
6291: }
6292: %autocreatehash = (
6293: autocreate => { xml => $newvals{'xml'},
6294: req => $newvals{'req'},
6295: }
6296: );
6297: if ($newvals{'xmldc'} ne '') {
6298: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6299: }
6300: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6301: $dom);
6302: if ($putresult eq 'ok') {
6303: my @items = @types;
6304: if ($newvals{'xml'}) {
6305: push(@items,'xmldc');
6306: }
6307: foreach my $item (@items) {
6308: if (exists($currautocreate{$item})) {
6309: if ($currautocreate{$item} ne $newvals{$item}) {
6310: $changes{$item} = 1;
6311: }
6312: } elsif ($newvals{$item}) {
6313: $changes{$item} = 1;
6314: }
6315: }
6316: if (keys(%changes) > 0) {
6317: my @offon = ('off','on');
6318: $resulttext = &mt('Changes made:').'<ul>';
6319: foreach my $item (@types) {
6320: if ($changes{$item}) {
6321: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6322: $resulttext .= '<li>'.
6323: &mt("$title{$item} set to [_1]$newtxt [_2]",
6324: '<b>','</b>').
6325: '</li>';
1.125 raeburn 6326: }
6327: }
6328: if ($changes{'xmldc'}) {
6329: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6330: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6331: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6332: }
6333: $resulttext .= '</ul>';
6334: } else {
6335: $resulttext = &mt('No changes made to auto-creation settings');
6336: }
6337: } else {
6338: $resulttext = '<span class="LC_error">'.
6339: &mt('An error occurred: [_1]',$putresult).'</span>';
6340: }
6341: return $resulttext;
6342: }
6343:
1.23 raeburn 6344: sub modify_directorysrch {
6345: my ($dom,%domconfig) = @_;
6346: my ($resulttext,%changes);
6347: my %currdirsrch;
6348: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6349: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6350: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6351: }
6352: }
6353: my %title = ( available => 'Directory search available',
1.24 raeburn 6354: localonly => 'Other domains can search',
1.23 raeburn 6355: searchby => 'Search types',
6356: searchtypes => 'Search latitude');
6357: my @offon = ('off','on');
1.24 raeburn 6358: my @otherdoms = ('Yes','No');
1.23 raeburn 6359:
1.25 raeburn 6360: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6361: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6362: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6363:
1.44 raeburn 6364: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6365: if (keys(%{$usertypes}) == 0) {
6366: @cansearch = ('default');
6367: } else {
6368: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6369: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6370: if (!grep(/^\Q$type\E$/,@cansearch)) {
6371: push(@{$changes{'cansearch'}},$type);
6372: }
1.23 raeburn 6373: }
1.26 raeburn 6374: foreach my $type (@cansearch) {
6375: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6376: push(@{$changes{'cansearch'}},$type);
6377: }
1.23 raeburn 6378: }
1.26 raeburn 6379: } else {
6380: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6381: }
6382: }
6383:
6384: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6385: foreach my $by (@{$currdirsrch{'searchby'}}) {
6386: if (!grep(/^\Q$by\E$/,@searchby)) {
6387: push(@{$changes{'searchby'}},$by);
6388: }
6389: }
6390: foreach my $by (@searchby) {
6391: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6392: push(@{$changes{'searchby'}},$by);
6393: }
6394: }
6395: } else {
6396: push(@{$changes{'searchby'}},@searchby);
6397: }
1.25 raeburn 6398:
6399: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6400: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6401: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6402: push(@{$changes{'searchtypes'}},$type);
6403: }
6404: }
6405: foreach my $type (@searchtypes) {
6406: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6407: push(@{$changes{'searchtypes'}},$type);
6408: }
6409: }
6410: } else {
6411: if (exists($currdirsrch{'searchtypes'})) {
6412: foreach my $type (@searchtypes) {
6413: if ($type ne $currdirsrch{'searchtypes'}) {
6414: push(@{$changes{'searchtypes'}},$type);
6415: }
6416: }
6417: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6418: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6419: }
6420: } else {
6421: push(@{$changes{'searchtypes'}},@searchtypes);
6422: }
6423: }
6424:
1.23 raeburn 6425: my %dirsrch_hash = (
6426: directorysrch => { available => $env{'form.dirsrch_available'},
6427: cansearch => \@cansearch,
1.24 raeburn 6428: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6429: searchby => \@searchby,
1.25 raeburn 6430: searchtypes => \@searchtypes,
1.23 raeburn 6431: }
6432: );
6433: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6434: $dom);
6435: if ($putresult eq 'ok') {
6436: if (exists($currdirsrch{'available'})) {
6437: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6438: $changes{'available'} = 1;
6439: }
6440: } else {
6441: if ($env{'form.dirsrch_available'} eq '1') {
6442: $changes{'available'} = 1;
6443: }
6444: }
1.24 raeburn 6445: if (exists($currdirsrch{'localonly'})) {
6446: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6447: $changes{'localonly'} = 1;
6448: }
6449: } else {
6450: if ($env{'form.dirsrch_localonly'} eq '1') {
6451: $changes{'localonly'} = 1;
6452: }
6453: }
1.23 raeburn 6454: if (keys(%changes) > 0) {
6455: $resulttext = &mt('Changes made:').'<ul>';
6456: if ($changes{'available'}) {
6457: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6458: }
1.24 raeburn 6459: if ($changes{'localonly'}) {
6460: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6461: }
6462:
1.23 raeburn 6463: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6464: my $chgtext;
1.26 raeburn 6465: if (ref($usertypes) eq 'HASH') {
6466: if (keys(%{$usertypes}) > 0) {
6467: foreach my $type (@{$types}) {
6468: if (grep(/^\Q$type\E$/,@cansearch)) {
6469: $chgtext .= $usertypes->{$type}.'; ';
6470: }
6471: }
6472: if (grep(/^default$/,@cansearch)) {
6473: $chgtext .= $othertitle;
6474: } else {
6475: $chgtext =~ s/\; $//;
6476: }
1.160.6.13 raeburn 6477: $resulttext .=
6478: '<li>'.
6479: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6480: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6481: '</li>';
1.23 raeburn 6482: }
6483: }
6484: }
6485: if (ref($changes{'searchby'}) eq 'ARRAY') {
6486: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6487: my $chgtext;
6488: foreach my $type (@{$titleorder}) {
6489: if (grep(/^\Q$type\E$/,@searchby)) {
6490: if (defined($searchtitles->{$type})) {
6491: $chgtext .= $searchtitles->{$type}.'; ';
6492: }
6493: }
6494: }
6495: $chgtext =~ s/\; $//;
6496: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6497: }
1.25 raeburn 6498: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6499: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6500: my $chgtext;
6501: foreach my $type (@{$srchtypeorder}) {
6502: if (grep(/^\Q$type\E$/,@searchtypes)) {
6503: if (defined($srchtypes_desc->{$type})) {
6504: $chgtext .= $srchtypes_desc->{$type}.'; ';
6505: }
6506: }
6507: }
6508: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 6509: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6510: }
6511: $resulttext .= '</ul>';
6512: } else {
6513: $resulttext = &mt('No changes made to institution directory search settings');
6514: }
6515: } else {
6516: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6517: &mt('An error occurred: [_1]',$putresult).'</span>';
6518: }
6519: return $resulttext;
6520: }
6521:
1.28 raeburn 6522: sub modify_contacts {
6523: my ($dom,%domconfig) = @_;
6524: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6525: if (ref($domconfig{'contacts'}) eq 'HASH') {
6526: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6527: $currsetting{$key} = $domconfig{'contacts'}{$key};
6528: }
6529: }
1.134 raeburn 6530: my (%others,%to,%bcc);
1.28 raeburn 6531: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6532: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.15! raeburn 6533: 'requestsmail','updatesmail');
1.28 raeburn 6534: foreach my $type (@mailings) {
6535: @{$newsetting{$type}} =
6536: &Apache::loncommon::get_env_multiple('form.'.$type);
6537: foreach my $item (@contacts) {
6538: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6539: $contacts_hash{contacts}{$type}{$item} = 1;
6540: } else {
6541: $contacts_hash{contacts}{$type}{$item} = 0;
6542: }
6543: }
6544: $others{$type} = $env{'form.'.$type.'_others'};
6545: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6546: if ($type eq 'helpdeskmail') {
6547: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6548: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6549: }
1.28 raeburn 6550: }
6551: foreach my $item (@contacts) {
6552: $to{$item} = $env{'form.'.$item};
6553: $contacts_hash{'contacts'}{$item} = $to{$item};
6554: }
6555: if (keys(%currsetting) > 0) {
6556: foreach my $item (@contacts) {
6557: if ($to{$item} ne $currsetting{$item}) {
6558: $changes{$item} = 1;
6559: }
6560: }
6561: foreach my $type (@mailings) {
6562: foreach my $item (@contacts) {
6563: if (ref($currsetting{$type}) eq 'HASH') {
6564: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6565: push(@{$changes{$type}},$item);
6566: }
6567: } else {
6568: push(@{$changes{$type}},@{$newsetting{$type}});
6569: }
6570: }
6571: if ($others{$type} ne $currsetting{$type}{'others'}) {
6572: push(@{$changes{$type}},'others');
6573: }
1.134 raeburn 6574: if ($type eq 'helpdeskmail') {
6575: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6576: push(@{$changes{$type}},'bcc');
6577: }
6578: }
1.28 raeburn 6579: }
6580: } else {
6581: my %default;
6582: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6583: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6584: $default{'errormail'} = 'adminemail';
6585: $default{'packagesmail'} = 'adminemail';
6586: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6587: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6588: $default{'requestsmail'} = 'adminemail';
1.160.6.15! raeburn 6589: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6590: foreach my $item (@contacts) {
6591: if ($to{$item} ne $default{$item}) {
6592: $changes{$item} = 1;
6593: }
6594: }
6595: foreach my $type (@mailings) {
6596: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6597:
6598: push(@{$changes{$type}},@{$newsetting{$type}});
6599: }
6600: if ($others{$type} ne '') {
6601: push(@{$changes{$type}},'others');
1.134 raeburn 6602: }
6603: if ($type eq 'helpdeskmail') {
6604: if ($bcc{$type} ne '') {
6605: push(@{$changes{$type}},'bcc');
6606: }
6607: }
1.28 raeburn 6608: }
6609: }
6610: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6611: $dom);
6612: if ($putresult eq 'ok') {
6613: if (keys(%changes) > 0) {
6614: my ($titles,$short_titles) = &contact_titles();
6615: $resulttext = &mt('Changes made:').'<ul>';
6616: foreach my $item (@contacts) {
6617: if ($changes{$item}) {
6618: $resulttext .= '<li>'.$titles->{$item}.
6619: &mt(' set to: ').
6620: '<span class="LC_cusr_emph">'.
6621: $to{$item}.'</span></li>';
6622: }
6623: }
6624: foreach my $type (@mailings) {
6625: if (ref($changes{$type}) eq 'ARRAY') {
6626: $resulttext .= '<li>'.$titles->{$type}.': ';
6627: my @text;
6628: foreach my $item (@{$newsetting{$type}}) {
6629: push(@text,$short_titles->{$item});
6630: }
6631: if ($others{$type} ne '') {
6632: push(@text,$others{$type});
6633: }
6634: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6635: join(', ',@text).'</span>';
6636: if ($type eq 'helpdeskmail') {
6637: if ($bcc{$type} ne '') {
6638: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6639: }
6640: }
6641: $resulttext .= '</li>';
1.28 raeburn 6642: }
6643: }
6644: $resulttext .= '</ul>';
6645: } else {
1.34 raeburn 6646: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6647: }
6648: } else {
6649: $resulttext = '<span class="LC_error">'.
6650: &mt('An error occurred: [_1].',$putresult).'</span>';
6651: }
6652: return $resulttext;
6653: }
6654:
6655: sub modify_usercreation {
1.27 raeburn 6656: my ($dom,%domconfig) = @_;
1.34 raeburn 6657: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6658: my $warningmsg;
1.27 raeburn 6659: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6660: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6661: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6662: }
6663: }
6664: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6665: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6666: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6667: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6668: foreach my $item(@contexts) {
1.45 raeburn 6669: if ($item eq 'selfcreate') {
1.50 raeburn 6670: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6671: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6672: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6673: if (ref($cancreate{$item}) eq 'ARRAY') {
6674: if (grep(/^login$/,@{$cancreate{$item}})) {
6675: $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.');
6676: }
1.43 raeburn 6677: }
6678: }
1.50 raeburn 6679: } else {
6680: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6681: }
1.34 raeburn 6682: }
1.93 raeburn 6683: my ($othertitle,$usertypes,$types) =
6684: &Apache::loncommon::sorted_inst_types($dom);
6685: if (ref($types) eq 'ARRAY') {
6686: if (@{$types} > 0) {
6687: @{$cancreate{'statustocreate'}} =
6688: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6689: } else {
6690: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6691: }
6692: push(@contexts,'statustocreate');
6693: }
1.160.6.5 raeburn 6694: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6695: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6696: foreach my $item (@contexts) {
1.93 raeburn 6697: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6698: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6699: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6700: if (ref($cancreate{$item}) eq 'ARRAY') {
6701: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6702: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6703: push(@{$changes{'cancreate'}},$item);
6704: }
1.50 raeburn 6705: }
6706: }
6707: }
6708: } else {
6709: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6710: if (@{$cancreate{$item}} > 0) {
6711: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6712: push(@{$changes{'cancreate'}},$item);
6713: }
6714: }
6715: } else {
6716: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6717: if (@{$cancreate{$item}} < 3) {
6718: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6719: push(@{$changes{'cancreate'}},$item);
6720: }
6721: }
6722: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6723: if (@{$cancreate{$item}} > 0) {
6724: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6725: push(@{$changes{'cancreate'}},$item);
6726: }
6727: }
6728: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6729: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6730: push(@{$changes{'cancreate'}},$item);
6731: }
6732: }
6733: }
6734: }
6735: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6736: foreach my $type (@{$cancreate{$item}}) {
6737: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6738: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6739: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6740: push(@{$changes{'cancreate'}},$item);
6741: }
6742: }
6743: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6744: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6745: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6746: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6747: push(@{$changes{'cancreate'}},$item);
6748: }
6749: }
6750: }
6751: }
6752: }
6753: } else {
6754: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6755: push(@{$changes{'cancreate'}},$item);
6756: }
6757: }
1.27 raeburn 6758: }
1.34 raeburn 6759: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6760: foreach my $item (@contexts) {
1.43 raeburn 6761: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6762: if ($cancreate{$item} ne 'any') {
6763: push(@{$changes{'cancreate'}},$item);
6764: }
6765: } else {
6766: if ($cancreate{$item} ne 'none') {
6767: push(@{$changes{'cancreate'}},$item);
6768: }
1.27 raeburn 6769: }
6770: }
6771: } else {
1.43 raeburn 6772: foreach my $item (@contexts) {
1.34 raeburn 6773: push(@{$changes{'cancreate'}},$item);
6774: }
1.27 raeburn 6775: }
1.34 raeburn 6776:
1.27 raeburn 6777: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6778: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6779: if (!grep(/^\Q$type\E$/,@username_rule)) {
6780: push(@{$changes{'username_rule'}},$type);
6781: }
6782: }
6783: foreach my $type (@username_rule) {
6784: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6785: push(@{$changes{'username_rule'}},$type);
6786: }
6787: }
6788: } else {
6789: push(@{$changes{'username_rule'}},@username_rule);
6790: }
6791:
1.32 raeburn 6792: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6793: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6794: if (!grep(/^\Q$type\E$/,@id_rule)) {
6795: push(@{$changes{'id_rule'}},$type);
6796: }
6797: }
6798: foreach my $type (@id_rule) {
6799: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6800: push(@{$changes{'id_rule'}},$type);
6801: }
6802: }
6803: } else {
6804: push(@{$changes{'id_rule'}},@id_rule);
6805: }
6806:
1.43 raeburn 6807: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6808: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6809: if (!grep(/^\Q$type\E$/,@email_rule)) {
6810: push(@{$changes{'email_rule'}},$type);
6811: }
6812: }
6813: foreach my $type (@email_rule) {
6814: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6815: push(@{$changes{'email_rule'}},$type);
6816: }
6817: }
6818: } else {
6819: push(@{$changes{'email_rule'}},@email_rule);
6820: }
6821:
6822: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6823: my @authtypes = ('int','krb4','krb5','loc');
6824: my %authhash;
1.43 raeburn 6825: foreach my $item (@authen_contexts) {
1.28 raeburn 6826: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6827: foreach my $auth (@authtypes) {
6828: if (grep(/^\Q$auth\E$/,@authallowed)) {
6829: $authhash{$item}{$auth} = 1;
6830: } else {
6831: $authhash{$item}{$auth} = 0;
6832: }
6833: }
6834: }
6835: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6836: foreach my $item (@authen_contexts) {
1.28 raeburn 6837: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6838: foreach my $auth (@authtypes) {
6839: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6840: push(@{$changes{'authtypes'}},$item);
6841: last;
6842: }
6843: }
6844: }
6845: }
6846: } else {
1.43 raeburn 6847: foreach my $item (@authen_contexts) {
1.28 raeburn 6848: push(@{$changes{'authtypes'}},$item);
6849: }
6850: }
6851:
1.27 raeburn 6852: my %usercreation_hash = (
1.28 raeburn 6853: usercreation => {
1.34 raeburn 6854: cancreate => \%cancreate,
1.27 raeburn 6855: username_rule => \@username_rule,
1.32 raeburn 6856: id_rule => \@id_rule,
1.43 raeburn 6857: email_rule => \@email_rule,
1.32 raeburn 6858: authtypes => \%authhash,
1.27 raeburn 6859: }
6860: );
6861:
6862: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6863: $dom);
1.50 raeburn 6864:
6865: my %selfcreatetypes = (
6866: sso => 'users authenticated by institutional single sign on',
6867: login => 'users authenticated by institutional log-in',
6868: email => 'users who provide a valid e-mail address for use as the username',
6869: );
1.27 raeburn 6870: if ($putresult eq 'ok') {
6871: if (keys(%changes) > 0) {
6872: $resulttext = &mt('Changes made:').'<ul>';
6873: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6874: my %lt = &usercreation_types();
6875: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6876: my $chgtext;
1.160.6.5 raeburn 6877: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6878: $chgtext = $lt{$type}.', ';
6879: }
1.45 raeburn 6880: if ($type eq 'selfcreate') {
1.50 raeburn 6881: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6882: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6883: } else {
1.100 raeburn 6884: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6885: foreach my $case (@{$cancreate{$type}}) {
6886: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6887: }
6888: $chgtext .= '</ul>';
1.100 raeburn 6889: if (ref($cancreate{$type}) eq 'ARRAY') {
6890: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6891: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6892: if (@{$cancreate{'statustocreate'}} == 0) {
6893: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6894: }
6895: }
6896: }
6897: }
1.43 raeburn 6898: }
1.93 raeburn 6899: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6900: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6901: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6902: if (@{$cancreate{'selfcreate'}} > 0) {
6903: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6904:
6905: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6906: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6907: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6908: }
1.96 raeburn 6909: } elsif (ref($usertypes) eq 'HASH') {
6910: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6911: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6912: } else {
6913: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6914: }
6915: $chgtext .= '<ul>';
6916: foreach my $case (@{$cancreate{$type}}) {
6917: if ($case eq 'default') {
6918: $chgtext .= '<li>'.$othertitle.'</li>';
6919: } else {
6920: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6921: }
6922: }
1.100 raeburn 6923: $chgtext .= '</ul>';
6924: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6925: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6926: }
6927: }
6928: } else {
6929: if (@{$cancreate{$type}} == 0) {
6930: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6931: } else {
6932: $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 6933: }
6934: }
6935: }
1.160.6.5 raeburn 6936: } elsif ($type eq 'captcha') {
6937: if ($cancreate{$type} eq 'notused') {
6938: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6939: } else {
6940: my %captchas = &captcha_phrases();
6941: if ($captchas{$cancreate{$type}}) {
6942: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6943: } else {
6944: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6945: }
6946: }
6947: } elsif ($type eq 'recaptchakeys') {
6948: my ($privkey,$pubkey);
6949: if (ref($cancreate{$type}) eq 'HASH') {
6950: $pubkey = $cancreate{$type}{'public'};
6951: $privkey = $cancreate{$type}{'private'};
6952: }
6953: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6954: if (!$pubkey) {
6955: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6956: } else {
6957: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6958: }
6959: if (!$privkey) {
6960: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6961: } else {
6962: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6963: }
6964: $chgtext .= '</ul>';
1.43 raeburn 6965: } else {
6966: if ($cancreate{$type} eq 'none') {
6967: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6968: } elsif ($cancreate{$type} eq 'any') {
6969: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6970: } elsif ($cancreate{$type} eq 'official') {
6971: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6972: } elsif ($cancreate{$type} eq 'unofficial') {
6973: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6974: }
1.34 raeburn 6975: }
6976: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6977: }
6978: }
6979: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6980: my ($rules,$ruleorder) =
6981: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6982: my $chgtext = '<ul>';
6983: foreach my $type (@username_rule) {
6984: if (ref($rules->{$type}) eq 'HASH') {
6985: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6986: }
6987: }
6988: $chgtext .= '</ul>';
6989: if (@username_rule > 0) {
6990: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6991: } else {
1.28 raeburn 6992: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6993: }
6994: }
1.32 raeburn 6995: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6996: my ($idrules,$idruleorder) =
6997: &Apache::lonnet::inst_userrules($dom,'id');
6998: my $chgtext = '<ul>';
6999: foreach my $type (@id_rule) {
7000: if (ref($idrules->{$type}) eq 'HASH') {
7001: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7002: }
7003: }
7004: $chgtext .= '</ul>';
7005: if (@id_rule > 0) {
7006: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7007: } else {
7008: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7009: }
7010: }
1.43 raeburn 7011: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7012: my ($emailrules,$emailruleorder) =
7013: &Apache::lonnet::inst_userrules($dom,'email');
7014: my $chgtext = '<ul>';
7015: foreach my $type (@email_rule) {
7016: if (ref($emailrules->{$type}) eq 'HASH') {
7017: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7018: }
7019: }
7020: $chgtext .= '</ul>';
7021: if (@email_rule > 0) {
7022: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7023: } else {
7024: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7025: }
7026: }
7027:
1.28 raeburn 7028: my %authname = &authtype_names();
7029: my %context_title = &context_names();
7030: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7031: my $chgtext = '<ul>';
7032: foreach my $type (@{$changes{'authtypes'}}) {
7033: my @allowed;
7034: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7035: foreach my $auth (@authtypes) {
7036: if ($authhash{$type}{$auth}) {
7037: push(@allowed,$authname{$auth});
7038: }
7039: }
1.43 raeburn 7040: if (@allowed > 0) {
7041: $chgtext .= join(', ',@allowed).'</li>';
7042: } else {
7043: $chgtext .= &mt('none').'</li>';
7044: }
1.28 raeburn 7045: }
7046: $chgtext .= '</ul>';
7047: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7048: $resulttext .= '</li>';
7049: }
1.27 raeburn 7050: $resulttext .= '</ul>';
7051: } else {
1.28 raeburn 7052: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7053: }
7054: } else {
7055: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7056: &mt('An error occurred: [_1]',$putresult).'</span>';
7057: }
1.43 raeburn 7058: if ($warningmsg ne '') {
7059: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7060: }
1.23 raeburn 7061: return $resulttext;
7062: }
7063:
1.160.6.5 raeburn 7064: sub process_captcha {
7065: my ($container,$changes,$newsettings,$current) = @_;
7066: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7067: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7068: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7069: $newsettings->{'captcha'} = 'original';
7070: }
7071: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7072: if ($container eq 'cancreate') {
7073: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7074: push(@{$changes->{'cancreate'}},'captcha');
7075: } elsif (!defined($changes->{'cancreate'})) {
7076: $changes->{'cancreate'} = ['captcha'];
7077: }
7078: } else {
7079: $changes->{'captcha'} = 1;
7080: }
7081: }
7082: my ($newpub,$newpriv,$currpub,$currpriv);
7083: if ($newsettings->{'captcha'} eq 'recaptcha') {
7084: $newpub = $env{'form.'.$container.'_recaptchapub'};
7085: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7086: $newpub =~ s/\W//g;
7087: $newpriv =~ s/\W//g;
7088: $newsettings->{'recaptchakeys'} = {
7089: public => $newpub,
7090: private => $newpriv,
7091: };
7092: }
7093: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7094: $currpub = $current->{'recaptchakeys'}{'public'};
7095: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7096: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7097: $newsettings->{'recaptchakeys'} = {
7098: public => '',
7099: private => '',
7100: }
7101: }
1.160.6.5 raeburn 7102: }
7103: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7104: if ($container eq 'cancreate') {
7105: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7106: push(@{$changes->{'cancreate'}},'recaptchakeys');
7107: } elsif (!defined($changes->{'cancreate'})) {
7108: $changes->{'cancreate'} = ['recaptchakeys'];
7109: }
7110: } else {
7111: $changes->{'recaptchakeys'} = 1;
7112: }
7113: }
7114: return;
7115: }
7116:
1.33 raeburn 7117: sub modify_usermodification {
7118: my ($dom,%domconfig) = @_;
7119: my ($resulttext,%curr_usermodification,%changes);
7120: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7121: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7122: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7123: }
7124: }
1.63 raeburn 7125: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7126: my %context_title = (
7127: author => 'In author context',
7128: course => 'In course context',
1.63 raeburn 7129: selfcreate => 'When self creating account',
1.33 raeburn 7130: );
7131: my @fields = ('lastname','firstname','middlename','generation',
7132: 'permanentemail','id');
7133: my %roles = (
7134: author => ['ca','aa'],
7135: course => ['st','ep','ta','in','cr'],
7136: );
1.63 raeburn 7137: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7138: if (ref($types) eq 'ARRAY') {
7139: push(@{$types},'default');
7140: $usertypes->{'default'} = $othertitle;
7141: }
7142: $roles{'selfcreate'} = $types;
1.33 raeburn 7143: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7144: my %modifyhash;
7145: foreach my $context (@contexts) {
7146: foreach my $role (@{$roles{$context}}) {
7147: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7148: foreach my $item (@fields) {
7149: if (grep(/^\Q$item\E$/,@modifiable)) {
7150: $modifyhash{$context}{$role}{$item} = 1;
7151: } else {
7152: $modifyhash{$context}{$role}{$item} = 0;
7153: }
7154: }
7155: }
7156: if (ref($curr_usermodification{$context}) eq 'HASH') {
7157: foreach my $role (@{$roles{$context}}) {
7158: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7159: foreach my $field (@fields) {
7160: if ($modifyhash{$context}{$role}{$field} ne
7161: $curr_usermodification{$context}{$role}{$field}) {
7162: push(@{$changes{$context}},$role);
7163: last;
7164: }
7165: }
7166: }
7167: }
7168: } else {
7169: foreach my $context (@contexts) {
7170: foreach my $role (@{$roles{$context}}) {
7171: push(@{$changes{$context}},$role);
7172: }
7173: }
7174: }
7175: }
7176: my %usermodification_hash = (
7177: usermodification => \%modifyhash,
7178: );
7179: my $putresult = &Apache::lonnet::put_dom('configuration',
7180: \%usermodification_hash,$dom);
7181: if ($putresult eq 'ok') {
7182: if (keys(%changes) > 0) {
7183: $resulttext = &mt('Changes made: ').'<ul>';
7184: foreach my $context (@contexts) {
7185: if (ref($changes{$context}) eq 'ARRAY') {
7186: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7187: if (ref($changes{$context}) eq 'ARRAY') {
7188: foreach my $role (@{$changes{$context}}) {
7189: my $rolename;
1.63 raeburn 7190: if ($context eq 'selfcreate') {
7191: $rolename = $role;
7192: if (ref($usertypes) eq 'HASH') {
7193: if ($usertypes->{$role} ne '') {
7194: $rolename = $usertypes->{$role};
7195: }
7196: }
1.33 raeburn 7197: } else {
1.63 raeburn 7198: if ($role eq 'cr') {
7199: $rolename = &mt('Custom');
7200: } else {
7201: $rolename = &Apache::lonnet::plaintext($role);
7202: }
1.33 raeburn 7203: }
7204: my @modifiable;
1.63 raeburn 7205: if ($context eq 'selfcreate') {
1.126 bisitz 7206: $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 7207: } else {
7208: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7209: }
1.33 raeburn 7210: foreach my $field (@fields) {
7211: if ($modifyhash{$context}{$role}{$field}) {
7212: push(@modifiable,$fieldtitles{$field});
7213: }
7214: }
7215: if (@modifiable > 0) {
7216: $resulttext .= join(', ',@modifiable);
7217: } else {
7218: $resulttext .= &mt('none');
7219: }
7220: $resulttext .= '</li>';
7221: }
7222: $resulttext .= '</ul></li>';
7223: }
7224: }
7225: }
7226: $resulttext .= '</ul>';
7227: } else {
7228: $resulttext = &mt('No changes made to user modification settings');
7229: }
7230: } else {
7231: $resulttext = '<span class="LC_error">'.
7232: &mt('An error occurred: [_1]',$putresult).'</span>';
7233: }
7234: return $resulttext;
7235: }
7236:
1.43 raeburn 7237: sub modify_defaults {
7238: my ($dom,$r) = @_;
7239: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7240: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7241: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7242: my @authtypes = ('internal','krb4','krb5','localauth');
7243: foreach my $item (@items) {
7244: $newvalues{$item} = $env{'form.'.$item};
7245: if ($item eq 'auth_def') {
7246: if ($newvalues{$item} ne '') {
7247: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7248: push(@errors,$item);
7249: }
7250: }
7251: } elsif ($item eq 'lang_def') {
7252: if ($newvalues{$item} ne '') {
7253: if ($newvalues{$item} =~ /^(\w+)/) {
7254: my $langcode = $1;
1.103 raeburn 7255: if ($langcode ne 'x_chef') {
7256: if (code2language($langcode) eq '') {
7257: push(@errors,$item);
7258: }
1.43 raeburn 7259: }
7260: } else {
7261: push(@errors,$item);
7262: }
7263: }
1.54 raeburn 7264: } elsif ($item eq 'timezone_def') {
7265: if ($newvalues{$item} ne '') {
1.62 raeburn 7266: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7267: push(@errors,$item);
7268: }
7269: }
1.68 raeburn 7270: } elsif ($item eq 'datelocale_def') {
7271: if ($newvalues{$item} ne '') {
7272: my @datelocale_ids = DateTime::Locale->ids();
7273: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7274: push(@errors,$item);
7275: }
7276: }
1.141 raeburn 7277: } elsif ($item eq 'portal_def') {
7278: if ($newvalues{$item} ne '') {
7279: 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])\/?$/) {
7280: push(@errors,$item);
7281: }
7282: }
1.43 raeburn 7283: }
7284: if (grep(/^\Q$item\E$/,@errors)) {
7285: $newvalues{$item} = $domdefaults{$item};
7286: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7287: $changes{$item} = 1;
7288: }
1.72 raeburn 7289: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7290: }
7291: my %defaults_hash = (
1.72 raeburn 7292: defaults => \%newvalues,
7293: );
1.43 raeburn 7294: my $title = &defaults_titles();
7295: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7296: $dom);
7297: if ($putresult eq 'ok') {
7298: if (keys(%changes) > 0) {
7299: $resulttext = &mt('Changes made:').'<ul>';
7300: my $version = $r->dir_config('lonVersion');
7301: 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";
7302: foreach my $item (sort(keys(%changes))) {
7303: my $value = $env{'form.'.$item};
7304: if ($value eq '') {
7305: $value = &mt('none');
7306: } elsif ($item eq 'auth_def') {
7307: my %authnames = &authtype_names();
7308: my %shortauth = (
7309: internal => 'int',
7310: krb4 => 'krb4',
7311: krb5 => 'krb5',
7312: localauth => 'loc',
7313: );
7314: $value = $authnames{$shortauth{$value}};
7315: }
7316: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7317: $mailmsgtext .= "$title->{$item} set to $value\n";
7318: }
7319: $resulttext .= '</ul>';
7320: $mailmsgtext .= "\n";
7321: my $cachetime = 24*60*60;
1.72 raeburn 7322: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7323: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7324: my $sysmail = $r->dir_config('lonSysEMail');
7325: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7326: }
1.43 raeburn 7327: } else {
1.54 raeburn 7328: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7329: }
7330: } else {
7331: $resulttext = '<span class="LC_error">'.
7332: &mt('An error occurred: [_1]',$putresult).'</span>';
7333: }
7334: if (@errors > 0) {
7335: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7336: foreach my $item (@errors) {
7337: $resulttext .= ' "'.$title->{$item}.'",';
7338: }
7339: $resulttext =~ s/,$//;
7340: }
7341: return $resulttext;
7342: }
7343:
1.46 raeburn 7344: sub modify_scantron {
1.48 raeburn 7345: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7346: my ($resulttext,%confhash,%changes,$errors);
7347: my $custom = 'custom.tab';
7348: my $default = 'default.tab';
7349: my $servadm = $r->dir_config('lonAdmEMail');
7350: my ($configuserok,$author_ok,$switchserver) =
7351: &config_check($dom,$confname,$servadm);
7352: if ($env{'form.scantronformat.filename'} ne '') {
7353: my $error;
7354: if ($configuserok eq 'ok') {
7355: if ($switchserver) {
1.130 raeburn 7356: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7357: } else {
7358: if ($author_ok eq 'ok') {
7359: my ($result,$scantronurl) =
7360: &publishlogo($r,'upload','scantronformat',$dom,
7361: $confname,'scantron','','',$custom);
7362: if ($result eq 'ok') {
7363: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7364: $changes{'scantronformat'} = 1;
1.46 raeburn 7365: } else {
7366: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7367: }
7368: } else {
7369: $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);
7370: }
7371: }
7372: } else {
7373: $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);
7374: }
7375: if ($error) {
7376: &Apache::lonnet::logthis($error);
7377: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7378: }
7379: }
1.48 raeburn 7380: if (ref($domconfig{'scantron'}) eq 'HASH') {
7381: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7382: if ($env{'form.scantronformat_del'}) {
7383: $confhash{'scantron'}{'scantronformat'} = '';
7384: $changes{'scantronformat'} = 1;
1.46 raeburn 7385: }
7386: }
7387: }
7388: if (keys(%confhash) > 0) {
7389: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7390: $dom);
7391: if ($putresult eq 'ok') {
7392: if (keys(%changes) > 0) {
1.48 raeburn 7393: if (ref($confhash{'scantron'}) eq 'HASH') {
7394: $resulttext = &mt('Changes made:').'<ul>';
7395: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7396: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7397: } else {
1.130 raeburn 7398: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7399: }
1.48 raeburn 7400: $resulttext .= '</ul>';
7401: } else {
1.130 raeburn 7402: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7403: }
7404: $resulttext .= '</ul>';
7405: &Apache::loncommon::devalidate_domconfig_cache($dom);
7406: } else {
1.130 raeburn 7407: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7408: }
7409: } else {
7410: $resulttext = '<span class="LC_error">'.
7411: &mt('An error occurred: [_1]',$putresult).'</span>';
7412: }
7413: } else {
1.130 raeburn 7414: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7415: }
7416: if ($errors) {
7417: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7418: $errors.'</ul>';
7419: }
7420: return $resulttext;
7421: }
7422:
1.48 raeburn 7423: sub modify_coursecategories {
7424: my ($dom,%domconfig) = @_;
1.57 raeburn 7425: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7426: $cathash);
1.48 raeburn 7427: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7428: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7429: $cathash = $domconfig{'coursecategories'}{'cats'};
7430: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7431: $changes{'togglecats'} = 1;
7432: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7433: }
7434: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7435: $changes{'categorize'} = 1;
7436: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7437: }
1.120 raeburn 7438: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7439: $changes{'togglecatscomm'} = 1;
7440: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7441: }
7442: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7443: $changes{'categorizecomm'} = 1;
7444: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7445: }
1.57 raeburn 7446: } else {
7447: $changes{'togglecats'} = 1;
7448: $changes{'categorize'} = 1;
1.124 raeburn 7449: $changes{'togglecatscomm'} = 1;
7450: $changes{'categorizecomm'} = 1;
1.87 raeburn 7451: $domconfig{'coursecategories'} = {
7452: togglecats => $env{'form.togglecats'},
7453: categorize => $env{'form.categorize'},
1.124 raeburn 7454: togglecatscomm => $env{'form.togglecatscomm'},
7455: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7456: };
1.57 raeburn 7457: }
7458: if (ref($cathash) eq 'HASH') {
7459: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7460: push (@deletecategory,'instcode::0');
7461: }
1.120 raeburn 7462: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7463: push(@deletecategory,'communities::0');
7464: }
1.48 raeburn 7465: }
1.57 raeburn 7466: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7467: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7468: if (@deletecategory > 0) {
7469: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7470: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7471: foreach my $item (@deletecategory) {
1.57 raeburn 7472: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7473: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7474: $deletions{$item} = 1;
1.57 raeburn 7475: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7476: }
7477: }
7478: }
1.57 raeburn 7479: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7480: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7481: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7482: $reorderings{$item} = 1;
1.57 raeburn 7483: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7484: }
7485: if ($env{'form.addcategory_name_'.$item} ne '') {
7486: my $newcat = $env{'form.addcategory_name_'.$item};
7487: my $newdepth = $depth+1;
7488: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7489: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7490: $adds{$newitem} = 1;
7491: }
7492: if ($env{'form.subcat_'.$item} ne '') {
7493: my $newcat = $env{'form.subcat_'.$item};
7494: my $newdepth = $depth+1;
7495: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7496: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7497: $adds{$newitem} = 1;
7498: }
7499: }
7500: }
7501: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7502: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7503: my $newitem = 'instcode::0';
1.57 raeburn 7504: if ($cathash->{$newitem} eq '') {
7505: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7506: $adds{$newitem} = 1;
7507: }
7508: } else {
7509: my $newitem = 'instcode::0';
1.57 raeburn 7510: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7511: $adds{$newitem} = 1;
7512: }
7513: }
1.120 raeburn 7514: if ($env{'form.communities'} eq '1') {
7515: if (ref($cathash) eq 'HASH') {
7516: my $newitem = 'communities::0';
7517: if ($cathash->{$newitem} eq '') {
7518: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7519: $adds{$newitem} = 1;
7520: }
7521: } else {
7522: my $newitem = 'communities::0';
7523: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7524: $adds{$newitem} = 1;
7525: }
7526: }
1.48 raeburn 7527: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7528: if (($env{'form.addcategory_name'} ne 'instcode') &&
7529: ($env{'form.addcategory_name'} ne 'communities')) {
7530: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7531: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7532: $adds{$newitem} = 1;
7533: }
1.48 raeburn 7534: }
1.57 raeburn 7535: my $putresult;
1.48 raeburn 7536: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7537: if (keys(%deletions) > 0) {
7538: foreach my $key (keys(%deletions)) {
7539: if ($predelallitems{$key} ne '') {
7540: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7541: }
7542: }
7543: }
7544: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7545: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7546: if (ref($chkcats[0]) eq 'ARRAY') {
7547: my $depth = 0;
7548: my $chg = 0;
7549: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7550: my $name = $chkcats[0][$i];
7551: my $item;
7552: if ($name eq '') {
7553: $chg ++;
7554: } else {
7555: $item = &escape($name).'::0';
7556: if ($chg) {
1.57 raeburn 7557: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7558: }
7559: $depth ++;
1.57 raeburn 7560: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7561: $depth --;
7562: }
7563: }
7564: }
1.57 raeburn 7565: }
7566: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7567: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7568: if ($putresult eq 'ok') {
1.57 raeburn 7569: my %title = (
1.120 raeburn 7570: togglecats => 'Show/Hide a course in catalog',
7571: categorize => 'Assign a category to a course',
7572: togglecatscomm => 'Show/Hide a community in catalog',
7573: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7574: );
7575: my %level = (
1.120 raeburn 7576: dom => 'set in Domain ("Modify Course/Community")',
7577: crs => 'set in Course ("Course Configuration")',
7578: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7579: );
1.48 raeburn 7580: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7581: if ($changes{'togglecats'}) {
7582: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7583: }
7584: if ($changes{'categorize'}) {
7585: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7586: }
1.120 raeburn 7587: if ($changes{'togglecatscomm'}) {
7588: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7589: }
7590: if ($changes{'categorizecomm'}) {
7591: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7592: }
1.57 raeburn 7593: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7594: my $cathash;
7595: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7596: $cathash = $domconfig{'coursecategories'}{'cats'};
7597: } else {
7598: $cathash = {};
7599: }
7600: my (@cats,@trails,%allitems);
7601: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7602: if (keys(%deletions) > 0) {
7603: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7604: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7605: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7606: }
7607: $resulttext .= '</ul></li>';
7608: }
7609: if (keys(%reorderings) > 0) {
7610: my %sort_by_trail;
7611: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7612: foreach my $key (keys(%reorderings)) {
7613: if ($allitems{$key} ne '') {
7614: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7615: }
1.48 raeburn 7616: }
1.57 raeburn 7617: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7618: $resulttext .= '<li>'.$trails[$trail].'</li>';
7619: }
7620: $resulttext .= '</ul></li>';
1.48 raeburn 7621: }
1.57 raeburn 7622: if (keys(%adds) > 0) {
7623: my %sort_by_trail;
7624: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7625: foreach my $key (keys(%adds)) {
7626: if ($allitems{$key} ne '') {
7627: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7628: }
7629: }
7630: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7631: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7632: }
1.57 raeburn 7633: $resulttext .= '</ul></li>';
1.48 raeburn 7634: }
7635: }
7636: $resulttext .= '</ul>';
7637: } else {
7638: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7639: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7640: }
7641: } else {
1.120 raeburn 7642: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7643: }
7644: return $resulttext;
7645: }
7646:
1.69 raeburn 7647: sub modify_serverstatuses {
7648: my ($dom,%domconfig) = @_;
7649: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7650: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7651: %currserverstatus = %{$domconfig{'serverstatuses'}};
7652: }
7653: my @pages = &serverstatus_pages();
7654: foreach my $type (@pages) {
7655: $newserverstatus{$type}{'namedusers'} = '';
7656: $newserverstatus{$type}{'machines'} = '';
7657: if (defined($env{'form.'.$type.'_namedusers'})) {
7658: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7659: my @okusers;
7660: foreach my $user (@users) {
7661: my ($uname,$udom) = split(/:/,$user);
7662: if (($udom =~ /^$match_domain$/) &&
7663: (&Apache::lonnet::domain($udom)) &&
7664: ($uname =~ /^$match_username$/)) {
7665: if (!grep(/^\Q$user\E/,@okusers)) {
7666: push(@okusers,$user);
7667: }
7668: }
7669: }
7670: if (@okusers > 0) {
7671: @okusers = sort(@okusers);
7672: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7673: }
7674: }
7675: if (defined($env{'form.'.$type.'_machines'})) {
7676: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7677: my @okmachines;
7678: foreach my $ip (@machines) {
7679: my @parts = split(/\./,$ip);
7680: next if (@parts < 4);
7681: my $badip = 0;
7682: for (my $i=0; $i<4; $i++) {
7683: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7684: $badip = 1;
7685: last;
7686: }
7687: }
7688: if (!$badip) {
7689: push(@okmachines,$ip);
7690: }
7691: }
7692: @okmachines = sort(@okmachines);
7693: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7694: }
7695: }
7696: my %serverstatushash = (
7697: serverstatuses => \%newserverstatus,
7698: );
7699: foreach my $type (@pages) {
1.83 raeburn 7700: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7701: my (@current,@new);
1.83 raeburn 7702: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7703: if ($currserverstatus{$type}{$setting} ne '') {
7704: @current = split(/,/,$currserverstatus{$type}{$setting});
7705: }
7706: }
7707: if ($newserverstatus{$type}{$setting} ne '') {
7708: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7709: }
7710: if (@current > 0) {
7711: if (@new > 0) {
7712: foreach my $item (@current) {
7713: if (!grep(/^\Q$item\E$/,@new)) {
7714: $changes{$type}{$setting} = 1;
1.82 raeburn 7715: last;
7716: }
7717: }
1.84 raeburn 7718: foreach my $item (@new) {
7719: if (!grep(/^\Q$item\E$/,@current)) {
7720: $changes{$type}{$setting} = 1;
7721: last;
1.82 raeburn 7722: }
7723: }
7724: } else {
1.83 raeburn 7725: $changes{$type}{$setting} = 1;
1.69 raeburn 7726: }
1.83 raeburn 7727: } elsif (@new > 0) {
7728: $changes{$type}{$setting} = 1;
1.69 raeburn 7729: }
7730: }
7731: }
7732: if (keys(%changes) > 0) {
1.81 raeburn 7733: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7734: my $putresult = &Apache::lonnet::put_dom('configuration',
7735: \%serverstatushash,$dom);
7736: if ($putresult eq 'ok') {
7737: $resulttext .= &mt('Changes made:').'<ul>';
7738: foreach my $type (@pages) {
1.84 raeburn 7739: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7740: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7741: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7742: if ($newserverstatus{$type}{'namedusers'} eq '') {
7743: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7744: } else {
7745: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7746: }
1.84 raeburn 7747: }
7748: if ($changes{$type}{'machines'}) {
1.69 raeburn 7749: if ($newserverstatus{$type}{'machines'} eq '') {
7750: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7751: } else {
7752: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7753: }
7754:
7755: }
7756: $resulttext .= '</ul></li>';
7757: }
7758: }
7759: $resulttext .= '</ul>';
7760: } else {
7761: $resulttext = '<span class="LC_error">'.
7762: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7763:
7764: }
7765: } else {
7766: $resulttext = &mt('No changes made to access to server status pages');
7767: }
7768: return $resulttext;
7769: }
7770:
1.118 jms 7771: sub modify_helpsettings {
1.122 jms 7772: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7773: my ($resulttext,$errors,%changes,%helphash);
7774: my %defaultchecked = ('submitbugs' => 'on');
7775: my @offon = ('off','on');
1.118 jms 7776: my @toggles = ('submitbugs');
7777: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7778: foreach my $item (@toggles) {
1.160.6.5 raeburn 7779: if ($defaultchecked{$item} eq 'on') {
7780: if ($domconfig{'helpsettings'}{$item} eq '') {
7781: if ($env{'form.'.$item} eq '0') {
7782: $changes{$item} = 1;
7783: }
7784: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7785: $changes{$item} = 1;
7786: }
7787: } elsif ($defaultchecked{$item} eq 'off') {
7788: if ($domconfig{'helpsettings'}{$item} eq '') {
7789: if ($env{'form.'.$item} eq '1') {
7790: $changes{$item} = 1;
7791: }
7792: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7793: $changes{$item} = 1;
7794: }
7795: }
7796: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7797: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7798: }
7799: }
1.118 jms 7800: }
1.123 jms 7801: my $putresult;
7802: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7803: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7804: if ($putresult eq 'ok') {
7805: $resulttext = &mt('Changes made:').'<ul>';
7806: foreach my $item (sort(keys(%changes))) {
7807: if ($item eq 'submitbugs') {
7808: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7809: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7810: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7811: }
7812: }
7813: $resulttext .= '</ul>';
7814: } else {
7815: $resulttext = &mt('No changes made to help settings');
7816: $errors .= '<li><span class="LC_error">'.
7817: &mt('An error occurred storing the settings: [_1]',
7818: $putresult).'</span></li>';
7819: }
1.118 jms 7820: }
7821: if ($errors) {
1.160.6.5 raeburn 7822: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7823: $errors.'</ul>';
7824: }
7825: return $resulttext;
7826: }
7827:
1.121 raeburn 7828: sub modify_coursedefaults {
7829: my ($dom,%domconfig) = @_;
7830: my ($resulttext,$errors,%changes,%defaultshash);
7831: my %defaultchecked = ('canuse_pdfforms' => 'off');
7832: my @offon = ('off','on');
7833: my @toggles = ('canuse_pdfforms');
7834:
7835: $defaultshash{'coursedefaults'} = {};
7836:
7837: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7838: if ($domconfig{'coursedefaults'} eq '') {
7839: $domconfig{'coursedefaults'} = {};
7840: }
7841: }
7842:
7843: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7844: foreach my $item (@toggles) {
7845: if ($defaultchecked{$item} eq 'on') {
7846: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7847: ($env{'form.'.$item} eq '0')) {
7848: $changes{$item} = 1;
7849: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7850: $changes{$item} = 1;
7851: }
7852: } elsif ($defaultchecked{$item} eq 'off') {
7853: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7854: ($env{'form.'.$item} eq '1')) {
7855: $changes{$item} = 1;
7856: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7857: $changes{$item} = 1;
7858: }
7859: }
7860: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7861: }
1.139 raeburn 7862: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7863: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7864: $newdefresponder =~ s/\D//g;
7865: if ($newdefresponder eq '' || $newdefresponder < 1) {
7866: $newdefresponder = 1;
7867: }
7868: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7869: if ($currdefresponder ne $newdefresponder) {
7870: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7871: $changes{'anonsurvey_threshold'} = 1;
7872: }
7873: }
1.121 raeburn 7874: }
7875: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7876: $dom);
7877: if ($putresult eq 'ok') {
7878: if (keys(%changes) > 0) {
7879: if ($changes{'canuse_pdfforms'}) {
7880: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7881: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7882: my $cachetime = 24*60*60;
7883: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7884: }
7885: $resulttext = &mt('Changes made:').'<ul>';
7886: foreach my $item (sort(keys(%changes))) {
7887: if ($item eq 'canuse_pdfforms') {
7888: if ($env{'form.'.$item} eq '1') {
7889: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7890: } else {
7891: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7892: }
1.139 raeburn 7893: } elsif ($item eq 'anonsurvey_threshold') {
7894: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7895: }
1.121 raeburn 7896: }
7897: $resulttext .= '</ul>';
7898: } else {
7899: $resulttext = &mt('No changes made to course defaults');
7900: }
7901: } else {
7902: $resulttext = '<span class="LC_error">'.
7903: &mt('An error occurred: [_1]',$putresult).'</span>';
7904: }
7905: return $resulttext;
7906: }
7907:
1.137 raeburn 7908: sub modify_usersessions {
7909: my ($dom,%domconfig) = @_;
1.145 raeburn 7910: my @hostingtypes = ('version','excludedomain','includedomain');
7911: my @offloadtypes = ('primary','default');
7912: my %types = (
7913: remote => \@hostingtypes,
7914: hosted => \@hostingtypes,
7915: spares => \@offloadtypes,
7916: );
7917: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7918: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7919: my (%by_ip,%by_location,@intdoms);
7920: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7921: my @locations = sort(keys(%by_location));
1.137 raeburn 7922: my (%defaultshash,%changes);
7923: foreach my $prefix (@prefixes) {
7924: $defaultshash{'usersessions'}{$prefix} = {};
7925: }
7926: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7927: my $resulttext;
1.138 raeburn 7928: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7929: foreach my $prefix (@prefixes) {
1.145 raeburn 7930: next if ($prefix eq 'spares');
7931: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7932: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7933: if ($type eq 'version') {
7934: my $value = $env{'form.'.$prefix.'_'.$type};
7935: my $okvalue;
7936: if ($value ne '') {
7937: if (grep(/^\Q$value\E$/,@lcversions)) {
7938: $okvalue = $value;
7939: }
7940: }
7941: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7942: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7943: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7944: if ($inuse == 0) {
7945: $changes{$prefix}{$type} = 1;
7946: } else {
7947: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7948: $changes{$prefix}{$type} = 1;
7949: }
7950: if ($okvalue ne '') {
7951: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7952: }
7953: }
7954: } else {
7955: if (($inuse == 1) && ($okvalue ne '')) {
7956: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7957: $changes{$prefix}{$type} = 1;
7958: }
7959: }
7960: } else {
7961: if (($inuse == 1) && ($okvalue ne '')) {
7962: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7963: $changes{$prefix}{$type} = 1;
7964: }
7965: }
7966: } else {
7967: if (($inuse == 1) && ($okvalue ne '')) {
7968: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7969: $changes{$prefix}{$type} = 1;
7970: }
7971: }
7972: } else {
7973: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7974: my @okvals;
7975: foreach my $val (@vals) {
1.138 raeburn 7976: if ($val =~ /:/) {
7977: my @items = split(/:/,$val);
7978: foreach my $item (@items) {
7979: if (ref($by_location{$item}) eq 'ARRAY') {
7980: push(@okvals,$item);
7981: }
7982: }
7983: } else {
7984: if (ref($by_location{$val}) eq 'ARRAY') {
7985: push(@okvals,$val);
7986: }
1.137 raeburn 7987: }
7988: }
7989: @okvals = sort(@okvals);
7990: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7991: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7992: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7993: if ($inuse == 0) {
7994: $changes{$prefix}{$type} = 1;
7995: } else {
7996: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7997: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7998: if (@changed > 0) {
7999: $changes{$prefix}{$type} = 1;
8000: }
8001: }
8002: } else {
8003: if ($inuse == 1) {
8004: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8005: $changes{$prefix}{$type} = 1;
8006: }
8007: }
8008: } else {
8009: if ($inuse == 1) {
8010: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8011: $changes{$prefix}{$type} = 1;
8012: }
8013: }
8014: } else {
8015: if ($inuse == 1) {
8016: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8017: $changes{$prefix}{$type} = 1;
8018: }
8019: }
8020: }
8021: }
8022: }
1.145 raeburn 8023:
8024: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8025: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8026: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8027: my $savespares;
8028:
8029: foreach my $lonhost (sort(keys(%servers))) {
8030: my $serverhomeID =
8031: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8032: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8033: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8034: my %spareschg;
8035: foreach my $type (@{$types{'spares'}}) {
8036: my @okspares;
8037: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8038: foreach my $server (@checked) {
1.152 raeburn 8039: if (&Apache::lonnet::hostname($server) ne '') {
8040: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8041: unless (grep(/^\Q$server\E$/,@okspares)) {
8042: push(@okspares,$server);
8043: }
1.145 raeburn 8044: }
8045: }
8046: }
8047: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8048: my $newspare;
1.152 raeburn 8049: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8050: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8051: $newspare = $new;
8052: }
8053: }
1.152 raeburn 8054: my @spares;
8055: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8056: @spares = sort(@okspares,$newspare);
8057: } else {
8058: @spares = sort(@okspares);
8059: }
8060: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8061: if (ref($spareid{$lonhost}) eq 'HASH') {
8062: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8063: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8064: if (@diffs > 0) {
8065: $spareschg{$type} = 1;
8066: }
8067: }
8068: }
8069: }
8070: if (keys(%spareschg) > 0) {
8071: $changes{'spares'}{$lonhost} = \%spareschg;
8072: }
8073: }
8074:
8075: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8076: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8077: if (ref($changes{'spares'}) eq 'HASH') {
8078: if (keys(%{$changes{'spares'}}) > 0) {
8079: $savespares = 1;
8080: }
8081: }
8082: } else {
8083: $savespares = 1;
8084: }
8085: }
8086:
1.147 raeburn 8087: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8088: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8089: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8090: $dom);
8091: if ($putresult eq 'ok') {
8092: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8093: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8094: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8095: }
8096: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8097: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8098: }
8099: }
8100: my $cachetime = 24*60*60;
8101: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8102: if (keys(%changes) > 0) {
8103: my %lt = &usersession_titles();
8104: $resulttext = &mt('Changes made:').'<ul>';
8105: foreach my $prefix (@prefixes) {
8106: if (ref($changes{$prefix}) eq 'HASH') {
8107: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8108: if ($prefix eq 'spares') {
8109: if (ref($changes{$prefix}) eq 'HASH') {
8110: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8111: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8112: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8113: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8114: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8115: foreach my $type (@{$types{$prefix}}) {
8116: if ($changes{$prefix}{$lonhost}{$type}) {
8117: my $offloadto = &mt('None');
8118: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8119: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8120: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8121: }
1.145 raeburn 8122: }
1.147 raeburn 8123: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8124: }
1.137 raeburn 8125: }
8126: }
1.147 raeburn 8127: $resulttext .= '</li>';
1.137 raeburn 8128: }
8129: }
1.147 raeburn 8130: } else {
8131: foreach my $type (@{$types{$prefix}}) {
8132: if (defined($changes{$prefix}{$type})) {
8133: my $newvalue;
8134: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8135: if (ref($defaultshash{'usersessions'}{$prefix})) {
8136: if ($type eq 'version') {
8137: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8138: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8139: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8140: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8141: }
1.145 raeburn 8142: }
8143: }
8144: }
1.147 raeburn 8145: if ($newvalue eq '') {
8146: if ($type eq 'version') {
8147: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8148: } else {
8149: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8150: }
1.145 raeburn 8151: } else {
1.147 raeburn 8152: if ($type eq 'version') {
8153: $newvalue .= ' '.&mt('(or later)');
8154: }
8155: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8156: }
1.137 raeburn 8157: }
8158: }
8159: }
1.147 raeburn 8160: $resulttext .= '</ul>';
1.137 raeburn 8161: }
8162: }
1.147 raeburn 8163: $resulttext .= '</ul>';
8164: } else {
8165: $resulttext = $nochgmsg;
1.137 raeburn 8166: }
8167: } else {
8168: $resulttext = '<span class="LC_error">'.
8169: &mt('An error occurred: [_1]',$putresult).'</span>';
8170: }
8171: } else {
1.147 raeburn 8172: $resulttext = $nochgmsg;
1.137 raeburn 8173: }
8174: return $resulttext;
8175: }
8176:
1.150 raeburn 8177: sub modify_loadbalancing {
8178: my ($dom,%domconfig) = @_;
8179: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8180: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8181: my ($othertitle,$usertypes,$types) =
8182: &Apache::loncommon::sorted_inst_types($dom);
8183: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8184: my @sparestypes = ('primary','default');
8185: my %typetitles = &sparestype_titles();
8186: my $resulttext;
1.160.6.7 raeburn 8187: my (%currbalancer,%currtargets,%currrules,%existing);
8188: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8189: %existing = %{$domconfig{'loadbalancing'}};
8190: }
8191: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8192: \%currtargets,\%currrules);
8193: my ($saveloadbalancing,%defaultshash,%changes);
8194: my ($alltypes,$othertypes,$titles) =
8195: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8196: my %ruletitles = &offloadtype_text();
8197: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8198: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8199: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8200: if ($balancer eq '') {
8201: next;
8202: }
8203: if (!exists($servers{$balancer})) {
8204: if (exists($currbalancer{$balancer})) {
8205: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8206: }
1.160.6.7 raeburn 8207: next;
8208: }
8209: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8210: push(@{$changes{'delete'}},$balancer);
8211: next;
8212: }
8213: if (!exists($currbalancer{$balancer})) {
8214: push(@{$changes{'add'}},$balancer);
8215: }
8216: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8217: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8218: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8219: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8220: $saveloadbalancing = 1;
8221: }
8222: foreach my $sparetype (@sparestypes) {
8223: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8224: my @offloadto;
8225: foreach my $target (@targets) {
8226: if (($servers{$target}) && ($target ne $balancer)) {
8227: if ($sparetype eq 'default') {
8228: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8229: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8230: }
8231: }
1.160.6.7 raeburn 8232: unless(grep(/^\Q$target\E$/,@offloadto)) {
8233: push(@offloadto,$target);
8234: }
1.150 raeburn 8235: }
1.160.6.7 raeburn 8236: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8237: }
8238: }
1.160.6.7 raeburn 8239: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8240: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8241: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8242: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8243: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8244: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8245: }
1.160.6.7 raeburn 8246: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8247: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8248: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8249: }
8250: }
8251: }
8252: } else {
1.160.6.7 raeburn 8253: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8254: foreach my $sparetype (@sparestypes) {
8255: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8256: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8257: $changes{'curr'}{$balancer}{'targets'} = 1;
8258: }
1.150 raeburn 8259: }
8260: }
1.160.6.7 raeburn 8261: }
1.150 raeburn 8262: }
8263: my $ishomedom;
1.160.6.7 raeburn 8264: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8265: $ishomedom = 1;
1.150 raeburn 8266: }
8267: if (ref($alltypes) eq 'ARRAY') {
8268: foreach my $type (@{$alltypes}) {
8269: my $rule;
1.160.6.7 raeburn 8270: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8271: (!$ishomedom)) {
1.160.6.7 raeburn 8272: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8273: }
8274: if ($rule eq 'specific') {
8275: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8276: }
1.160.6.7 raeburn 8277: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8278: if (ref($currrules{$balancer}) eq 'HASH') {
8279: if ($rule ne $currrules{$balancer}{$type}) {
8280: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8281: }
8282: } elsif ($rule ne '') {
1.160.6.7 raeburn 8283: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8284: }
8285: }
8286: }
1.160.6.7 raeburn 8287: }
8288: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8289: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8290: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8291: $defaultshash{'loadbalancing'} = {};
8292: }
8293: my $putresult = &Apache::lonnet::put_dom('configuration',
8294: \%defaultshash,$dom);
8295:
8296: if ($putresult eq 'ok') {
8297: if (keys(%changes) > 0) {
8298: if (ref($changes{'delete'}) eq 'ARRAY') {
8299: foreach my $balancer (sort(@{$changes{'delete'}})) {
8300: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8301: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8302: }
1.160.6.7 raeburn 8303: }
8304: if (ref($changes{'add'}) eq 'ARRAY') {
8305: foreach my $balancer (sort(@{$changes{'add'}})) {
8306: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8307: }
8308: }
8309: if (ref($changes{'curr'}) eq 'HASH') {
8310: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8311: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8312: if ($changes{'curr'}{$balancer}{'targets'}) {
8313: my %offloadstr;
8314: foreach my $sparetype (@sparestypes) {
8315: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8316: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8317: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8318: }
8319: }
1.150 raeburn 8320: }
1.160.6.7 raeburn 8321: if (keys(%offloadstr) == 0) {
8322: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8323: } else {
1.160.6.7 raeburn 8324: my $showoffload;
8325: foreach my $sparetype (@sparestypes) {
8326: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8327: if (defined($offloadstr{$sparetype})) {
8328: $showoffload .= $offloadstr{$sparetype};
8329: } else {
8330: $showoffload .= &mt('None');
8331: }
8332: $showoffload .= (' 'x3);
8333: }
8334: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8335: }
8336: }
8337: }
1.160.6.7 raeburn 8338: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8339: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8340: foreach my $type (@{$alltypes}) {
8341: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8342: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8343: my $balancetext;
8344: if ($rule eq '') {
8345: $balancetext = $ruletitles{'default'};
8346: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8347: $balancetext = $ruletitles{$rule};
8348: } else {
8349: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8350: }
8351: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8352: }
8353: }
8354: }
8355: }
1.160.6.7 raeburn 8356: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8357: }
1.160.6.7 raeburn 8358: }
8359: if ($resulttext ne '') {
8360: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8361: } else {
8362: $resulttext = $nochgmsg;
8363: }
8364: } else {
1.160.6.7 raeburn 8365: $resulttext = $nochgmsg;
1.150 raeburn 8366: }
8367: } else {
1.160.6.7 raeburn 8368: $resulttext = '<span class="LC_error">'.
8369: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8370: }
8371: } else {
1.160.6.7 raeburn 8372: $resulttext = $nochgmsg;
1.150 raeburn 8373: }
8374: return $resulttext;
8375: }
8376:
1.48 raeburn 8377: sub recurse_check {
8378: my ($chkcats,$categories,$depth,$name) = @_;
8379: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8380: my $chg = 0;
8381: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8382: my $category = $chkcats->[$depth]{$name}[$j];
8383: my $item;
8384: if ($category eq '') {
8385: $chg ++;
8386: } else {
8387: my $deeper = $depth + 1;
8388: $item = &escape($category).':'.&escape($name).':'.$depth;
8389: if ($chg) {
8390: $categories->{$item} -= $chg;
8391: }
8392: &recurse_check($chkcats,$categories,$deeper,$category);
8393: $deeper --;
8394: }
8395: }
8396: }
8397: return;
8398: }
8399:
8400: sub recurse_cat_deletes {
8401: my ($item,$coursecategories,$deletions) = @_;
8402: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8403: my $subdepth = $depth + 1;
8404: if (ref($coursecategories) eq 'HASH') {
8405: foreach my $subitem (keys(%{$coursecategories})) {
8406: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8407: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8408: delete($coursecategories->{$subitem});
8409: $deletions->{$subitem} = 1;
8410: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8411: }
8412: }
8413: }
8414: return;
8415: }
8416:
1.125 raeburn 8417: sub get_active_dcs {
8418: my ($dom) = @_;
8419: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8420: my %domcoords;
8421: my $numdcs = 0;
8422: my $now = time;
8423: foreach my $server (keys(%dompersonnel)) {
8424: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8425: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8426: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8427: if (($end eq '') || ($end == 0) || ($end > $now)) {
8428: if ($start <= $now) {
8429: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8430: }
8431: }
8432: }
8433: }
8434: return %domcoords;
8435: }
8436:
8437: sub active_dc_picker {
8438: my ($dom,$curr_dc) = @_;
8439: my %domcoords = &get_active_dcs($dom);
8440: my @dcs = sort(keys(%domcoords));
8441: my $numdcs = scalar(@dcs);
8442: my $datatable;
8443: my $numinrow = 2;
8444: if ($numdcs > 1) {
8445: $datatable = '<table>';
8446: for (my $i=0; $i<@dcs; $i++) {
8447: my $rem = $i%($numinrow);
8448: if ($rem == 0) {
8449: if ($i > 0) {
8450: $datatable .= '</tr>';
8451: }
8452: $datatable .= '<tr>';
8453: }
8454: my $check = ' ';
8455: if ($curr_dc eq '') {
8456: if (!$i) {
8457: $check = ' checked="checked" ';
8458: }
8459: } elsif ($dcs[$i] eq $curr_dc) {
8460: $check = ' checked="checked" ';
8461: }
8462: if ($i == @dcs - 1) {
8463: my $colsleft = $numinrow - $rem;
8464: if ($colsleft > 1) {
8465: $datatable .= '<td colspan="'.$colsleft.'">';
8466: } else {
8467: $datatable .= '<td>';
8468: }
8469: } else {
8470: $datatable .= '<td>';
8471: }
8472: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8473: $datatable .= '<span class="LC_nobreak"><label>'.
8474: '<input type="radio" name="autocreate_xmldc"'.
8475: ' value="'.$dcs[$i].'"'.$check.'/>'.
8476: &Apache::loncommon::plainname($dcname,$dcdom).
1.160.6.13 raeburn 8477: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8478: '</label></span></td>';
8479: }
8480: $datatable .= '</tr></table>';
8481: } elsif (@dcs) {
8482: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8483: $dcs[0].'" />';
8484: }
8485: return ($numdcs,$datatable);
8486: }
8487:
1.137 raeburn 8488: sub usersession_titles {
8489: return &Apache::lonlocal::texthash(
8490: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8491: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8492: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8493: version => 'LON-CAPA version requirement',
1.138 raeburn 8494: excludedomain => 'Allow all, but exclude specific domains',
8495: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8496: primary => 'Primary (checked first)',
1.154 raeburn 8497: default => 'Default',
1.137 raeburn 8498: );
8499: }
8500:
1.152 raeburn 8501: sub id_for_thisdom {
8502: my (%servers) = @_;
8503: my %altids;
8504: foreach my $server (keys(%servers)) {
8505: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8506: if ($serverhome ne $server) {
8507: $altids{$serverhome} = $server;
8508: }
8509: }
8510: return %altids;
8511: }
8512:
1.150 raeburn 8513: sub count_servers {
8514: my ($currbalancer,%servers) = @_;
8515: my (@spares,$numspares);
8516: foreach my $lonhost (sort(keys(%servers))) {
8517: next if ($currbalancer eq $lonhost);
8518: push(@spares,$lonhost);
8519: }
8520: if ($currbalancer) {
8521: $numspares = scalar(@spares);
8522: } else {
8523: $numspares = scalar(@spares) - 1;
8524: }
8525: return ($numspares,@spares);
8526: }
8527:
8528: sub lonbalance_targets_js {
1.160.6.7 raeburn 8529: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8530: my $select = &mt('Select');
8531: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8532: if (ref($servers) eq 'HASH') {
8533: $alltargets = join("','",sort(keys(%{$servers})));
8534: my @homedoms;
8535: foreach my $server (sort(keys(%{$servers}))) {
8536: if (&Apache::lonnet::host_domain($server) eq $dom) {
8537: push(@homedoms,'1');
8538: } else {
8539: push(@homedoms,'0');
8540: }
8541: }
8542: $allishome = join("','",@homedoms);
8543: }
8544: if (ref($types) eq 'ARRAY') {
8545: if (@{$types} > 0) {
8546: @alltypes = @{$types};
8547: }
8548: }
8549: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8550: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8551: my (%currbalancer,%currtargets,%currrules,%existing);
8552: if (ref($settings) eq 'HASH') {
8553: %existing = %{$settings};
8554: }
8555: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8556: \%currtargets,\%currrules);
8557: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8558: return <<"END";
8559:
8560: <script type="text/javascript">
8561: // <![CDATA[
8562:
1.160.6.7 raeburn 8563: currBalancers = new Array('$balancers');
8564:
8565: function toggleTargets(balnum) {
8566: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8567: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8568: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8569: var prevbalancer = prevhostitem.value;
8570: var baltotal = document.getElementById('loadbalancing_total').value;
8571: prevhostitem.value = balancer;
8572: if (prevbalancer != '') {
8573: var prevIdx = currBalancers.indexOf(prevbalancer);
8574: if (prevIdx != -1) {
8575: currBalancers.splice(prevIdx,1);
8576: }
8577: }
1.150 raeburn 8578: if (balancer == '') {
1.160.6.7 raeburn 8579: hideSpares(balnum);
1.150 raeburn 8580: } else {
1.160.6.7 raeburn 8581: var currIdx = currBalancers.indexOf(balancer);
8582: if (currIdx == -1) {
8583: currBalancers.push(balancer);
8584: }
1.150 raeburn 8585: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8586: var ishomedom = homedoms[lonhostitem.selectedIndex];
8587: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8588: }
1.160.6.7 raeburn 8589: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8590: return;
8591: }
8592:
1.160.6.7 raeburn 8593: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8594: var alltargets = new Array('$alltargets');
8595: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8596: var offloadtypes = new Array('primary','default');
8597:
1.160.6.7 raeburn 8598: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8599: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8600:
1.151 raeburn 8601: for (var i=0; i<offloadtypes.length; i++) {
8602: var count = 0;
8603: for (var j=0; j<alltargets.length; j++) {
8604: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8605: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8606: item.value = alltargets[j];
8607: item.style.textAlign='left';
8608: item.style.textFace='normal';
8609: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8610: if (currBalancers.indexOf(alltargets[j]) == -1) {
8611: item.disabled = '';
8612: } else {
8613: item.disabled = 'disabled';
8614: item.checked = false;
8615: }
1.151 raeburn 8616: count ++;
8617: }
1.150 raeburn 8618: }
8619: }
1.151 raeburn 8620: for (var k=0; k<insttypes.length; k++) {
8621: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8622: if (ishomedom == 1) {
1.160.6.7 raeburn 8623: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8624: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8625: } else {
1.160.6.7 raeburn 8626: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8627: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8628:
8629: }
8630: } else {
1.160.6.7 raeburn 8631: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8632: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8633: }
1.151 raeburn 8634: if ((insttypes[k] != '_LC_external') &&
8635: ((insttypes[k] != '_LC_internetdom') ||
8636: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8637: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8638: item.options.length = 0;
8639: item.options[0] = new Option("","",true,true);
8640: var idx = 0;
1.151 raeburn 8641: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8642: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8643: idx ++;
8644: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8645:
1.150 raeburn 8646: }
8647: }
8648: }
8649: }
8650: return;
8651: }
8652:
1.160.6.7 raeburn 8653: function hideSpares(balnum) {
1.150 raeburn 8654: var alltargets = new Array('$alltargets');
8655: var insttypes = new Array('$allinsttypes');
8656: var offloadtypes = new Array('primary','default');
8657:
1.160.6.7 raeburn 8658: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8659: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8660:
8661: var total = alltargets.length - 1;
8662: for (var i=0; i<offloadtypes; i++) {
8663: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8664: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8665: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8666: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8667: }
1.150 raeburn 8668: }
8669: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8670: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8671: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8672: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8673: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8674: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8675: }
8676: }
8677: return;
8678: }
8679:
1.160.6.7 raeburn 8680: function checkOffloads(item,balnum,type) {
1.150 raeburn 8681: var alltargets = new Array('$alltargets');
8682: var offloadtypes = new Array('primary','default');
8683: if (item.checked) {
8684: var total = alltargets.length - 1;
8685: var other;
8686: if (type == offloadtypes[0]) {
1.151 raeburn 8687: other = offloadtypes[1];
1.150 raeburn 8688: } else {
1.151 raeburn 8689: other = offloadtypes[0];
1.150 raeburn 8690: }
8691: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8692: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8693: if (server == item.value) {
1.160.6.7 raeburn 8694: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8695: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8696: }
8697: }
8698: }
8699: }
8700: return;
8701: }
8702:
1.160.6.7 raeburn 8703: function singleServerToggle(balnum,type) {
8704: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8705: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 8706: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8707: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8708:
8709: } else {
1.160.6.7 raeburn 8710: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8711: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8712: }
8713: return;
8714: }
8715:
1.160.6.7 raeburn 8716: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8717: if (type == '_LC_external') {
8718: return;
8719: }
1.160.6.7 raeburn 8720: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8721: for (var i=0; i<typesRules.length; i++) {
8722: if (formname.elements[typesRules[i]].checked) {
8723: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 8724: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8725: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8726: } else {
1.160.6.7 raeburn 8727: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8728: }
8729: }
8730: }
8731: return;
8732: }
8733:
8734: function balancerDeleteChange(balnum) {
8735: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8736: var baltotal = document.getElementById('loadbalancing_total').value;
8737: var addtarget;
8738: var removetarget;
8739: var action = 'delete';
8740: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8741: var lonhost = hostitem.value;
8742: var currIdx = currBalancers.indexOf(lonhost);
8743: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8744: if (currIdx != -1) {
8745: currBalancers.splice(currIdx,1);
8746: }
8747: addtarget = lonhost;
8748: } else {
8749: if (currIdx == -1) {
8750: currBalancers.push(lonhost);
8751: }
8752: removetarget = lonhost;
8753: action = 'undelete';
8754: }
8755: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8756: }
8757: return;
8758: }
8759:
8760: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8761: if (baltotal > 1) {
8762: var offloadtypes = new Array('primary','default');
8763: var alltargets = new Array('$alltargets');
8764: var insttypes = new Array('$allinsttypes');
8765: for (var i=0; i<baltotal; i++) {
8766: if (i != balnum) {
8767: for (var j=0; j<offloadtypes.length; j++) {
8768: var total = alltargets.length - 1;
8769: for (var k=0; k<total; k++) {
8770: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8771: var server = serveritem.value;
8772: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8773: if (server == addtarget) {
8774: serveritem.disabled = '';
8775: }
8776: }
8777: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8778: if (server == removetarget) {
8779: serveritem.disabled = 'disabled';
8780: serveritem.checked = false;
8781: }
8782: }
8783: }
8784: }
8785: for (var j=0; j<insttypes.length; j++) {
8786: if (insttypes[j] != '_LC_external') {
8787: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8788: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8789: var currSel = singleserver.selectedIndex;
8790: var currVal = singleserver.options[currSel].value;
8791: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8792: var numoptions = singleserver.options.length;
8793: var needsnew = 1;
8794: for (var k=0; k<numoptions; k++) {
8795: if (singleserver.options[k] == addtarget) {
8796: needsnew = 0;
8797: break;
8798: }
8799: }
8800: if (needsnew == 1) {
8801: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8802: }
8803: }
8804: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8805: singleserver.options.length = 0;
8806: if ((currVal) && (currVal != removetarget)) {
8807: singleserver.options[0] = new Option("","",false,false);
8808: } else {
8809: singleserver.options[0] = new Option("","",true,true);
8810: }
8811: var idx = 0;
8812: for (var m=0; m<alltargets.length; m++) {
8813: if (currBalancers.indexOf(alltargets[m]) == -1) {
8814: idx ++;
8815: if (currVal == alltargets[m]) {
8816: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8817: } else {
8818: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8819: }
8820: }
8821: }
8822: }
8823: }
8824: }
8825: }
1.150 raeburn 8826: }
8827: }
8828: }
8829: return;
8830: }
8831:
1.152 raeburn 8832: // ]]>
8833: </script>
8834:
8835: END
8836: }
8837:
8838: sub new_spares_js {
8839: my @sparestypes = ('primary','default');
8840: my $types = join("','",@sparestypes);
8841: my $select = &mt('Select');
8842: return <<"END";
8843:
8844: <script type="text/javascript">
8845: // <![CDATA[
8846:
8847: function updateNewSpares(formname,lonhost) {
8848: var types = new Array('$types');
8849: var include = new Array();
8850: var exclude = new Array();
8851: for (var i=0; i<types.length; i++) {
8852: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8853: for (var j=0; j<spareboxes.length; j++) {
8854: if (formname.elements[spareboxes[j]].checked) {
8855: exclude.push(formname.elements[spareboxes[j]].value);
8856: } else {
8857: include.push(formname.elements[spareboxes[j]].value);
8858: }
8859: }
8860: }
8861: for (var i=0; i<types.length; i++) {
8862: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8863: var selIdx = newSpare.selectedIndex;
8864: var currnew = newSpare.options[selIdx].value;
8865: var okSpares = new Array();
8866: for (var j=0; j<newSpare.options.length; j++) {
8867: var possible = newSpare.options[j].value;
8868: if (possible != '') {
8869: if (exclude.indexOf(possible) == -1) {
8870: okSpares.push(possible);
8871: } else {
8872: if (currnew == possible) {
8873: selIdx = 0;
8874: }
8875: }
8876: }
8877: }
8878: for (var k=0; k<include.length; k++) {
8879: if (okSpares.indexOf(include[k]) == -1) {
8880: okSpares.push(include[k]);
8881: }
8882: }
8883: okSpares.sort();
8884: newSpare.options.length = 0;
8885: if (selIdx == 0) {
8886: newSpare.options[0] = new Option("$select","",true,true);
8887: } else {
8888: newSpare.options[0] = new Option("$select","",false,false);
8889: }
8890: for (var m=0; m<okSpares.length; m++) {
8891: var idx = m+1;
8892: var selThis = 0;
8893: if (selIdx != 0) {
8894: if (okSpares[m] == currnew) {
8895: selThis = 1;
8896: }
8897: }
8898: if (selThis == 1) {
8899: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8900: } else {
8901: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8902: }
8903: }
8904: }
8905: return;
8906: }
8907:
8908: function checkNewSpares(lonhost,type) {
8909: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8910: var chosen = newSpare.options[newSpare.selectedIndex].value;
8911: if (chosen != '') {
8912: var othertype;
8913: var othernewSpare;
8914: if (type == 'primary') {
8915: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8916: }
8917: if (type == 'default') {
8918: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8919: }
8920: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8921: othernewSpare.selectedIndex = 0;
8922: }
8923: }
8924: return;
8925: }
8926:
8927: // ]]>
8928: </script>
8929:
8930: END
8931:
8932: }
8933:
8934: sub common_domprefs_js {
8935: return <<"END";
8936:
8937: <script type="text/javascript">
8938: // <![CDATA[
8939:
1.150 raeburn 8940: function getIndicesByName(formname,item) {
1.152 raeburn 8941: var group = new Array();
1.150 raeburn 8942: for (var i=0;i<formname.elements.length;i++) {
8943: if (formname.elements[i].name == item) {
1.152 raeburn 8944: group.push(formname.elements[i].id);
1.150 raeburn 8945: }
8946: }
1.152 raeburn 8947: return group;
1.150 raeburn 8948: }
8949:
8950: // ]]>
8951: </script>
8952:
8953: END
1.152 raeburn 8954:
1.150 raeburn 8955: }
8956:
1.160.6.5 raeburn 8957: sub recaptcha_js {
8958: my %lt = &captcha_phrases();
8959: return <<"END";
8960:
8961: <script type="text/javascript">
8962: // <![CDATA[
8963:
8964: function updateCaptcha(caller,context) {
8965: var privitem;
8966: var pubitem;
8967: var privtext;
8968: var pubtext;
8969: if (document.getElementById(context+'_recaptchapub')) {
8970: pubitem = document.getElementById(context+'_recaptchapub');
8971: } else {
8972: return;
8973: }
8974: if (document.getElementById(context+'_recaptchapriv')) {
8975: privitem = document.getElementById(context+'_recaptchapriv');
8976: } else {
8977: return;
8978: }
8979: if (document.getElementById(context+'_recaptchapubtxt')) {
8980: pubtext = document.getElementById(context+'_recaptchapubtxt');
8981: } else {
8982: return;
8983: }
8984: if (document.getElementById(context+'_recaptchaprivtxt')) {
8985: privtext = document.getElementById(context+'_recaptchaprivtxt');
8986: } else {
8987: return;
8988: }
8989: if (caller.checked) {
8990: if (caller.value == 'recaptcha') {
8991: pubitem.type = 'text';
8992: privitem.type = 'text';
8993: pubitem.size = '40';
8994: privitem.size = '40';
8995: pubtext.innerHTML = "$lt{'pub'}";
8996: privtext.innerHTML = "$lt{'priv'}";
8997: } else {
8998: pubitem.type = 'hidden';
8999: privitem.type = 'hidden';
9000: pubtext.innerHTML = '';
9001: privtext.innerHTML = '';
9002: }
9003: }
9004: return;
9005: }
9006:
9007: // ]]>
9008: </script>
9009:
9010: END
9011:
9012: }
9013:
9014: sub captcha_phrases {
9015: return &Apache::lonlocal::texthash (
9016: priv => 'Private key',
9017: pub => 'Public key',
9018: original => 'original (CAPTCHA)',
9019: recaptcha => 'successor (ReCAPTCHA)',
9020: notused => 'unused',
9021: );
9022: }
9023:
1.3 raeburn 9024: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>