Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.20
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.20! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.19 2013/06/05 13:31:19 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,
1.160.6.20! raeburn 97: used by course owners to request creation of a course, and to display/store
! 98: default quota sizes for authoring spaces.
! 99:
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
107: (official, unofficial and community). In each case the radio buttons allow the
108: selection of one of four values:
109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.69 raeburn 168: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 169: use LONCAPA::Enrollment;
1.81 raeburn 170: use LONCAPA::lonauthcgi();
1.9 raeburn 171: use File::Copy;
1.43 raeburn 172: use Locale::Language;
1.62 raeburn 173: use DateTime::TimeZone;
1.68 raeburn 174: use DateTime::Locale;
1.1 raeburn 175:
1.155 raeburn 176: my $registered_cleanup;
177: my $modified_urls;
178:
1.1 raeburn 179: sub handler {
180: my $r=shift;
181: if ($r->header_only) {
182: &Apache::loncommon::content_type($r,'text/html');
183: $r->send_http_header;
184: return OK;
185: }
186:
1.91 raeburn 187: my $context = 'domain';
1.1 raeburn 188: my $dom = $env{'request.role.domain'};
1.5 albertel 189: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 190: if (&Apache::lonnet::allowed('mau',$dom)) {
191: &Apache::loncommon::content_type($r,'text/html');
192: $r->send_http_header;
193: } else {
194: $env{'user.error.msg'}=
195: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
196: return HTTP_NOT_ACCEPTABLE;
197: }
1.155 raeburn 198:
199: $registered_cleanup=0;
200: @{$modified_urls}=();
201:
1.1 raeburn 202: &Apache::lonhtmlcommon::clear_breadcrumbs();
203: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 204: ['phase','actions']);
1.30 raeburn 205: my $phase = 'pickactions';
1.3 raeburn 206: if ( exists($env{'form.phase'}) ) {
207: $phase = $env{'form.phase'};
208: }
1.150 raeburn 209: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 210: my %domconfig =
1.6 raeburn 211: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 212: 'quotas','autoenroll','autoupdate','autocreate',
213: 'directorysrch','usercreation','usermodification',
214: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 215: 'serverstatuses','requestcourses','coursedefaults',
216: 'usersessions','loadbalancing','requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 219: 'usercreation','usermodification','scantron',
1.160.6.5 raeburn 220: 'requestcourses','requestauthor','coursecategories',
1.160.6.16 raeburn 221: 'serverstatuses','coursedefaults','usersessions');
1.160.6.7 raeburn 222: my %existing;
223: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
224: %existing = %{$domconfig{'loadbalancing'}};
225: }
226: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 227: push(@prefs_order,'loadbalancing');
228: }
1.30 raeburn 229: my %prefs = (
230: 'rolecolors' =>
231: { text => 'Default color schemes',
1.67 raeburn 232: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 233: header => [{col1 => 'Student Settings',
234: col2 => '',},
235: {col1 => 'Coordinator Settings',
236: col2 => '',},
237: {col1 => 'Author Settings',
238: col2 => '',},
239: {col1 => 'Administrator Settings',
240: col2 => '',}],
241: },
1.110 raeburn 242: 'login' =>
1.30 raeburn 243: { text => 'Log-in page options',
1.67 raeburn 244: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 245: header => [{col1 => 'Log-in Page Items',
246: col2 => '',},
247: {col1 => 'Log-in Help',
248: col2 => 'Value'}],
1.30 raeburn 249: },
1.43 raeburn 250: 'defaults' =>
1.141 raeburn 251: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 252: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 253: header => [{col1 => 'Setting',
254: col2 => 'Value'}],
255: },
1.30 raeburn 256: 'quotas' =>
1.160.6.20! raeburn 257: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 258: help => 'Domain_Configuration_Quotas',
1.77 raeburn 259: header => [{col1 => 'User affiliation',
1.72 raeburn 260: col2 => 'Available tools',
1.160.6.20! raeburn 261: col3 => 'Quotas, Mb; (Authoring requires role)',}],
1.30 raeburn 262: },
263: 'autoenroll' =>
264: { text => 'Auto-enrollment settings',
1.67 raeburn 265: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 266: header => [{col1 => 'Configuration setting',
267: col2 => 'Value(s)'}],
268: },
269: 'autoupdate' =>
270: { text => 'Auto-update settings',
1.67 raeburn 271: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 272: header => [{col1 => 'Setting',
273: col2 => 'Value',},
1.131 raeburn 274: {col1 => 'Setting',
275: col2 => 'Affiliation'},
1.43 raeburn 276: {col1 => 'User population',
1.131 raeburn 277: col2 => 'Updateable user data'}],
1.30 raeburn 278: },
1.125 raeburn 279: 'autocreate' =>
280: { text => 'Auto-course creation settings',
281: help => 'Domain_Configuration_Auto_Creation',
282: header => [{col1 => 'Configuration Setting',
283: col2 => 'Value',}],
284: },
1.30 raeburn 285: 'directorysrch' =>
286: { text => 'Institutional directory searches',
1.67 raeburn 287: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 288: header => [{col1 => 'Setting',
289: col2 => 'Value',}],
290: },
291: 'contacts' =>
292: { text => 'Contact Information',
1.67 raeburn 293: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 294: header => [{col1 => 'Setting',
295: col2 => 'Value',}],
296: },
297:
298: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.69 raeburn 308: 'usermodification' =>
1.33 raeburn 309: { text => 'User modification',
1.67 raeburn 310: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 311: header => [{col1 => 'Target user has role',
312: col2 => 'User information updateable in author context'},
313: {col1 => 'Target user has role',
1.63 raeburn 314: col2 => 'User information updateable in course context'},
315: {col1 => "Status of user",
316: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 317: },
1.69 raeburn 318: 'scantron' =>
1.95 www 319: { text => 'Bubblesheet format file',
1.67 raeburn 320: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 321: header => [ {col1 => 'Item',
322: col2 => '',
323: }],
324: },
1.86 raeburn 325: 'requestcourses' =>
326: {text => 'Request creation of courses',
327: help => 'Domain_Configuration_Request_Courses',
328: header => [{col1 => 'User affiliation',
1.102 raeburn 329: col2 => 'Availability/Processing of requests',},
330: {col1 => 'Setting',
331: col2 => 'Value'}],
1.86 raeburn 332: },
1.160.6.5 raeburn 333: 'requestauthor' =>
334: {text => 'Request authoring space',
335: help => 'Domain_Configuration_Request_Author',
336: header => [{col1 => 'User affiliation',
337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
339: col2 => 'Value'}],
340: },
1.69 raeburn 341: 'coursecategories' =>
1.120 raeburn 342: { text => 'Cataloging of courses/communities',
1.67 raeburn 343: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 344: header => [{col1 => 'Category settings',
1.57 raeburn 345: col2 => '',},
346: {col1 => 'Categories',
347: col2 => '',
348: }],
1.69 raeburn 349: },
350: 'serverstatuses' =>
1.77 raeburn 351: {text => 'Access to server status pages',
1.69 raeburn 352: help => 'Domain_Configuration_Server_Status',
353: header => [{col1 => 'Status Page',
354: col2 => 'Other named users',
355: col3 => 'Specific IPs',
356: }],
357: },
1.160.6.16 raeburn 358: 'coursedefaults' =>
359: {text => 'Course/Community defaults',
360: help => 'Domain_Configuration_Course_Defaults',
361: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
362: col2 => 'Value',},],
363: },
1.141 raeburn 364: 'usersessions' =>
1.145 raeburn 365: {text => 'User session hosting/offloading',
1.137 raeburn 366: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 367: header => [{col1 => 'Domain server',
368: col2 => 'Servers to offload sessions to when busy'},
369: {col1 => 'Hosting of users from other domains',
1.137 raeburn 370: col2 => 'Rules'},
371: {col1 => "Hosting domain's own users elsewhere",
372: col2 => 'Rules'}],
373: },
1.150 raeburn 374: 'loadbalancing' =>
1.160.6.7 raeburn 375: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 376: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 377: header => [{col1 => 'Balancers',
1.150 raeburn 378: col2 => 'Default destinations',
1.160.6.13 raeburn 379: col3 => 'User affiliation',
1.150 raeburn 380: col4 => 'Overrides'},
381: ],
382: },
1.3 raeburn 383: );
1.110 raeburn 384: if (keys(%servers) > 1) {
385: $prefs{'login'} = { text => 'Log-in page options',
386: help => 'Domain_Configuration_Login_Page',
387: header => [{col1 => 'Log-in Service',
388: col2 => 'Server Setting',},
389: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 390: col2 => ''},
391: {col1 => 'Log-in Help',
392: col2 => 'Value'}],
1.110 raeburn 393: };
394: }
1.160.6.13 raeburn 395:
1.6 raeburn 396: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 397: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 398: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 399: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 400: text=>"Settings to display/modify"});
1.9 raeburn 401: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 402:
1.3 raeburn 403: if ($phase eq 'process') {
1.91 raeburn 404: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 405: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 406: my $js = &recaptcha_js().
407: &credits_js();
1.160.6.7 raeburn 408: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 409: my ($othertitle,$usertypes,$types) =
410: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 411: $js .= &lonbalance_targets_js($dom,$types,\%servers,
412: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 413: &new_spares_js().
414: &common_domprefs_js().
415: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 416: }
1.150 raeburn 417: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 418: } else {
1.160.6.11 raeburn 419: # check if domconfig user exists for the domain.
420: my $servadm = $r->dir_config('lonAdmEMail');
421: my ($configuserok,$author_ok,$switchserver) =
422: &config_check($dom,$confname,$servadm);
423: unless ($configuserok eq 'ok') {
424: &Apache::lonconfigsettings::print_header($r,$phase,$context);
425: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
426: $confname).
427: '<br />'
428: );
429: if ($switchserver) {
430: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
431: '<br />'.
432: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
433: '<br />'.
434: &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).
435: '<br />'.
436: &mt('To do that now, use the following link: [_1]',$switchserver)
437: );
438: } else {
439: $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.').
440: '<br />'.
441: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
442: );
443: }
444: $r->print(&Apache::loncommon::end_page());
445: return OK;
446: }
1.21 raeburn 447: if (keys(%domconfig) == 0) {
448: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 449: my @ids=&Apache::lonnet::current_machine_ids();
450: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 451: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 452: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 453: my $custom_img_count = 0;
454: foreach my $img (@loginimages) {
455: if ($designhash{$dom.'.login.'.$img} ne '') {
456: $custom_img_count ++;
457: }
458: }
459: foreach my $role (@roles) {
460: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
461: $custom_img_count ++;
462: }
463: }
464: if ($custom_img_count > 0) {
1.94 raeburn 465: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 466: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 467: $r->print(
468: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
469: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
470: &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 />'.
471: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
472: if ($switch_server) {
1.30 raeburn 473: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 474: }
1.91 raeburn 475: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 476: return OK;
477: }
478: }
479: }
1.91 raeburn 480: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 481: }
482: return OK;
483: }
484:
485: sub process_changes {
1.92 raeburn 486: my ($r,$dom,$confname,$action,$roles,$values) = @_;
487: my %domconfig;
488: if (ref($values) eq 'HASH') {
489: %domconfig = %{$values};
490: }
1.3 raeburn 491: my $output;
492: if ($action eq 'login') {
1.9 raeburn 493: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 494: } elsif ($action eq 'rolecolors') {
1.9 raeburn 495: $output = &modify_rolecolors($r,$dom,$confname,$roles,
496: %domconfig);
1.3 raeburn 497: } elsif ($action eq 'quotas') {
1.86 raeburn 498: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 499: } elsif ($action eq 'autoenroll') {
500: $output = &modify_autoenroll($dom,%domconfig);
501: } elsif ($action eq 'autoupdate') {
502: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 503: } elsif ($action eq 'autocreate') {
504: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 505: } elsif ($action eq 'directorysrch') {
506: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 507: } elsif ($action eq 'usercreation') {
1.28 raeburn 508: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 509: } elsif ($action eq 'usermodification') {
510: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 511: } elsif ($action eq 'contacts') {
512: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 513: } elsif ($action eq 'defaults') {
514: $output = &modify_defaults($dom,$r);
1.46 raeburn 515: } elsif ($action eq 'scantron') {
1.48 raeburn 516: $output = &modify_scantron($r,$dom,$confname,%domconfig);
517: } elsif ($action eq 'coursecategories') {
518: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 519: } elsif ($action eq 'serverstatuses') {
520: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 521: } elsif ($action eq 'requestcourses') {
522: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.5 raeburn 523: } elsif ($action eq 'requestauthor') {
524: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.16 raeburn 525: } elsif ($action eq 'coursedefaults') {
526: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 527: } elsif ($action eq 'usersessions') {
528: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 529: } elsif ($action eq 'loadbalancing') {
530: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 531: }
532: return $output;
533: }
534:
535: sub print_config_box {
1.9 raeburn 536: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 537: my $rowtotal = 0;
1.49 raeburn 538: my $output;
539: if ($action eq 'coursecategories') {
540: $output = &coursecategories_javascript($settings);
1.91 raeburn 541: }
1.49 raeburn 542: $output .=
1.30 raeburn 543: '<table class="LC_nested_outer">
1.3 raeburn 544: <tr>
1.66 raeburn 545: <th align="left" valign="middle"><span class="LC_nobreak">'.
546: &mt($item->{text}).' '.
547: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
548: '</tr>';
1.30 raeburn 549: $rowtotal ++;
1.110 raeburn 550: my $numheaders = 1;
551: if (ref($item->{'header'}) eq 'ARRAY') {
552: $numheaders = scalar(@{$item->{'header'}});
553: }
554: if ($numheaders > 1) {
1.64 raeburn 555: my $colspan = '';
1.145 raeburn 556: my $rightcolspan = '';
1.160.6.5 raeburn 557: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
558: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 559: $colspan = ' colspan="2"';
560: }
1.145 raeburn 561: if ($action eq 'usersessions') {
562: $rightcolspan = ' colspan="3"';
563: }
1.30 raeburn 564: $output .= '
1.3 raeburn 565: <tr>
566: <td>
567: <table class="LC_nested">
568: <tr class="LC_info_row">
1.59 bisitz 569: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 570: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 571: </tr>';
1.69 raeburn 572: $rowtotal ++;
1.6 raeburn 573: if ($action eq 'autoupdate') {
1.30 raeburn 574: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 575: } elsif ($action eq 'usercreation') {
1.33 raeburn 576: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
577: } elsif ($action eq 'usermodification') {
578: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 579: } elsif ($action eq 'coursecategories') {
580: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 581: } elsif ($action eq 'login') {
1.160.6.5 raeburn 582: if ($numheaders == 3) {
583: $colspan = ' colspan="2"';
584: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
585: } else {
586: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
587: }
1.102 raeburn 588: } elsif ($action eq 'requestcourses') {
589: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 590: } elsif ($action eq 'requestauthor') {
591: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 592: } elsif ($action eq 'usersessions') {
593: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 594: } elsif ($action eq 'rolecolors') {
1.30 raeburn 595: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 596: }
1.30 raeburn 597: $output .= '
1.6 raeburn 598: </table>
599: </td>
600: </tr>
601: <tr>
602: <td>
603: <table class="LC_nested">
604: <tr class="LC_info_row">
1.59 bisitz 605: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 606: $output .= '
1.59 bisitz 607: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 608: </tr>';
609: $rowtotal ++;
1.6 raeburn 610: if ($action eq 'autoupdate') {
1.131 raeburn 611: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
612: </table>
613: </td>
614: </tr>
615: <tr>
616: <td>
617: <table class="LC_nested">
618: <tr class="LC_info_row">
619: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
620: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
621: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
622: $rowtotal ++;
1.28 raeburn 623: } elsif ($action eq 'usercreation') {
1.34 raeburn 624: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
625: </table>
626: </td>
627: </tr>
628: <tr>
629: <td>
630: <table class="LC_nested">
631: <tr class="LC_info_row">
1.59 bisitz 632: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
633: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 634: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
635: $rowtotal ++;
1.33 raeburn 636: } elsif ($action eq 'usermodification') {
1.63 raeburn 637: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
638: </table>
639: </td>
640: </tr>
641: <tr>
642: <td>
643: <table class="LC_nested">
644: <tr class="LC_info_row">
645: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
646: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
647: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
648: $rowtotal ++;
1.57 raeburn 649: } elsif ($action eq 'coursecategories') {
650: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 651: } elsif ($action eq 'login') {
1.160.6.5 raeburn 652: if ($numheaders == 3) {
653: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
654: </table>
655: </td>
656: </tr>
657: <tr>
658: <td>
659: <table class="LC_nested">
660: <tr class="LC_info_row">
661: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
662: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
663: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
664: $rowtotal ++;
665: } else {
666: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
667: }
1.102 raeburn 668: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 669: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
670: } elsif ($action eq 'requestauthor') {
671: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 672: } elsif ($action eq 'usersessions') {
1.145 raeburn 673: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
674: </table>
675: </td>
676: </tr>
677: <tr>
678: <td>
679: <table class="LC_nested">
680: <tr class="LC_info_row">
681: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
682: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
683: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
684: $rowtotal ++;
1.122 jms 685: } elsif ($action eq 'rolecolors') {
1.30 raeburn 686: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 687: </table>
688: </td>
689: </tr>
690: <tr>
691: <td>
692: <table class="LC_nested">
693: <tr class="LC_info_row">
1.69 raeburn 694: <td class="LC_left_item"'.$colspan.' valign="top">'.
695: &mt($item->{'header'}->[2]->{'col1'}).'</td>
696: <td class="LC_right_item" valign="top">'.
697: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 698: </tr>'.
1.30 raeburn 699: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 700: </table>
701: </td>
702: </tr>
703: <tr>
704: <td>
705: <table class="LC_nested">
706: <tr class="LC_info_row">
1.59 bisitz 707: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
708: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 709: </tr>'.
1.30 raeburn 710: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
711: $rowtotal += 2;
1.6 raeburn 712: }
1.3 raeburn 713: } else {
1.30 raeburn 714: $output .= '
1.3 raeburn 715: <tr>
716: <td>
717: <table class="LC_nested">
1.30 raeburn 718: <tr class="LC_info_row">';
1.24 raeburn 719: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 720: $output .= '
1.59 bisitz 721: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 722: } elsif ($action eq 'serverstatuses') {
723: $output .= '
724: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
725: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
726:
1.6 raeburn 727: } else {
1.30 raeburn 728: $output .= '
1.69 raeburn 729: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
730: }
1.72 raeburn 731: if (defined($item->{'header'}->[0]->{'col3'})) {
732: $output .= '<td class="LC_left_item" valign="top">'.
733: &mt($item->{'header'}->[0]->{'col2'});
734: if ($action eq 'serverstatuses') {
735: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
736: }
1.69 raeburn 737: } else {
738: $output .= '<td class="LC_right_item" valign="top">'.
739: &mt($item->{'header'}->[0]->{'col2'});
740: }
741: $output .= '</td>';
742: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 743: if (defined($item->{'header'}->[0]->{'col4'})) {
744: $output .= '<td class="LC_left_item" valign="top">'.
745: &mt($item->{'header'}->[0]->{'col3'});
746: } else {
747: $output .= '<td class="LC_right_item" valign="top">'.
748: &mt($item->{'header'}->[0]->{'col3'});
749: }
1.69 raeburn 750: if ($action eq 'serverstatuses') {
751: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
752: }
753: $output .= '</td>';
1.6 raeburn 754: }
1.150 raeburn 755: if ($item->{'header'}->[0]->{'col4'}) {
756: $output .= '<td class="LC_right_item" valign="top">'.
757: &mt($item->{'header'}->[0]->{'col4'});
758: }
1.69 raeburn 759: $output .= '</tr>';
1.48 raeburn 760: $rowtotal ++;
1.160.6.5 raeburn 761: if ($action eq 'quotas') {
1.86 raeburn 762: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 763: } elsif ($action eq 'autoenroll') {
1.30 raeburn 764: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 765: } elsif ($action eq 'autocreate') {
766: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 767: } elsif ($action eq 'directorysrch') {
1.30 raeburn 768: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 769: } elsif ($action eq 'contacts') {
1.30 raeburn 770: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 771: } elsif ($action eq 'defaults') {
772: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 773: } elsif ($action eq 'scantron') {
774: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 775: } elsif ($action eq 'serverstatuses') {
776: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 777: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 778: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 779: } elsif ($action eq 'loadbalancing') {
780: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.160.6.16 raeburn 781: } elsif ($action eq 'coursedefaults') {
782: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 783: }
1.3 raeburn 784: }
1.30 raeburn 785: $output .= '
1.3 raeburn 786: </table>
787: </td>
788: </tr>
1.30 raeburn 789: </table><br />';
790: return ($output,$rowtotal);
1.1 raeburn 791: }
792:
1.3 raeburn 793: sub print_login {
1.160.6.5 raeburn 794: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 795: my ($css_class,$datatable);
1.6 raeburn 796: my %choices = &login_choices();
1.110 raeburn 797:
1.160.6.5 raeburn 798: if ($caller eq 'service') {
1.149 raeburn 799: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 800: my $choice = $choices{'disallowlogin'};
801: $css_class = ' class="LC_odd_row"';
1.128 raeburn 802: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 803: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 804: '<th>'.$choices{'server'}.'</th>'.
805: '<th>'.$choices{'serverpath'}.'</th>'.
806: '<th>'.$choices{'custompath'}.'</th>'.
807: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 808: my %disallowed;
809: if (ref($settings) eq 'HASH') {
810: if (ref($settings->{'loginvia'}) eq 'HASH') {
811: %disallowed = %{$settings->{'loginvia'}};
812: }
813: }
814: foreach my $lonhost (sort(keys(%servers))) {
815: my $direct = 'selected="selected"';
1.128 raeburn 816: if (ref($disallowed{$lonhost}) eq 'HASH') {
817: if ($disallowed{$lonhost}{'server'} ne '') {
818: $direct = '';
819: }
1.110 raeburn 820: }
1.115 raeburn 821: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 822: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 823: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
824: '</option>';
1.160.6.13 raeburn 825: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 826: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 827: my $selected = '';
1.128 raeburn 828: if (ref($disallowed{$lonhost}) eq 'HASH') {
829: if ($hostid eq $disallowed{$lonhost}{'server'}) {
830: $selected = 'selected="selected"';
831: }
1.110 raeburn 832: }
833: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
834: $servers{$hostid}.'</option>';
835: }
1.128 raeburn 836: $datatable .= '</select></td>'.
837: '<td><select name="'.$lonhost.'_serverpath">';
838: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
839: my $pathname = $path;
840: if ($path eq 'custom') {
841: $pathname = &mt('Custom Path').' ->';
842: }
843: my $selected = '';
844: if (ref($disallowed{$lonhost}) eq 'HASH') {
845: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
846: $selected = 'selected="selected"';
847: }
848: } elsif ($path eq '') {
849: $selected = 'selected="selected"';
850: }
851: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
852: }
853: $datatable .= '</select></td>';
854: my ($custom,$exempt);
855: if (ref($disallowed{$lonhost}) eq 'HASH') {
856: $custom = $disallowed{$lonhost}{'custompath'};
857: $exempt = $disallowed{$lonhost}{'exempt'};
858: }
859: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
860: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
861: '</tr>';
1.110 raeburn 862: }
863: $datatable .= '</table></td></tr>';
864: return $datatable;
1.160.6.5 raeburn 865: } elsif ($caller eq 'page') {
866: my %defaultchecked = (
867: 'coursecatalog' => 'on',
1.160.6.14 raeburn 868: 'helpdesk' => 'on',
1.160.6.5 raeburn 869: 'adminmail' => 'off',
870: 'newuser' => 'off',
871: );
1.160.6.14 raeburn 872: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 873: my (%checkedon,%checkedoff);
1.42 raeburn 874: foreach my $item (@toggles) {
1.160.6.5 raeburn 875: if ($defaultchecked{$item} eq 'on') {
876: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 877: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 878: } elsif ($defaultchecked{$item} eq 'off') {
879: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 880: $checkedon{$item} = ' ';
881: }
1.1 raeburn 882: }
1.160.6.5 raeburn 883: my @images = ('img','logo','domlogo','login');
884: my @logintext = ('textcol','bgcol');
885: my @bgs = ('pgbg','mainbg','sidebg');
886: my @links = ('link','alink','vlink');
887: my %designhash = &Apache::loncommon::get_domainconf($dom);
888: my %defaultdesign = %Apache::loncommon::defaultdesign;
889: my (%is_custom,%designs);
890: my %defaults = (
891: font => $defaultdesign{'login.font'},
892: );
1.6 raeburn 893: foreach my $item (@images) {
1.160.6.5 raeburn 894: $defaults{$item} = $defaultdesign{'login.'.$item};
895: $defaults{'showlogo'}{$item} = 1;
896: }
897: foreach my $item (@bgs) {
898: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 899: }
1.41 raeburn 900: foreach my $item (@logintext) {
1.160.6.5 raeburn 901: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 902: }
1.160.6.5 raeburn 903: foreach my $item (@links) {
904: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 905: }
1.160.6.5 raeburn 906: if (ref($settings) eq 'HASH') {
907: foreach my $item (@toggles) {
908: if ($settings->{$item} eq '1') {
909: $checkedon{$item} = ' checked="checked" ';
910: $checkedoff{$item} = ' ';
911: } elsif ($settings->{$item} eq '0') {
912: $checkedoff{$item} = ' checked="checked" ';
913: $checkedon{$item} = ' ';
914: }
1.6 raeburn 915: }
1.160.6.5 raeburn 916: foreach my $item (@images) {
917: if (defined($settings->{$item})) {
918: $designs{$item} = $settings->{$item};
919: $is_custom{$item} = 1;
920: }
921: if (defined($settings->{'showlogo'}{$item})) {
922: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
923: }
924: }
925: foreach my $item (@logintext) {
926: if ($settings->{$item} ne '') {
927: $designs{'logintext'}{$item} = $settings->{$item};
928: $is_custom{$item} = 1;
929: }
930: }
931: if ($settings->{'font'} ne '') {
932: $designs{'font'} = $settings->{'font'};
933: $is_custom{'font'} = 1;
934: }
935: foreach my $item (@bgs) {
936: if ($settings->{$item} ne '') {
937: $designs{'bgs'}{$item} = $settings->{$item};
938: $is_custom{$item} = 1;
939: }
940: }
941: foreach my $item (@links) {
942: if ($settings->{$item} ne '') {
943: $designs{'links'}{$item} = $settings->{$item};
944: $is_custom{$item} = 1;
945: }
946: }
947: } else {
948: if ($designhash{$dom.'.login.font'} ne '') {
949: $designs{'font'} = $designhash{$dom.'.login.font'};
950: $is_custom{'font'} = 1;
951: }
952: foreach my $item (@images) {
953: if ($designhash{$dom.'.login.'.$item} ne '') {
954: $designs{$item} = $designhash{$dom.'.login.'.$item};
955: $is_custom{$item} = 1;
956: }
957: }
958: foreach my $item (@bgs) {
959: if ($designhash{$dom.'.login.'.$item} ne '') {
960: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
961: $is_custom{$item} = 1;
962: }
963: }
964: foreach my $item (@links) {
965: if ($designhash{$dom.'.login.'.$item} ne '') {
966: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
967: $is_custom{$item} = 1;
968: }
1.6 raeburn 969: }
970: }
1.160.6.5 raeburn 971: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
972: logo => 'Institution Logo',
973: domlogo => 'Domain Logo',
974: login => 'Login box');
975: my $itemcount = 1;
976: foreach my $item (@toggles) {
977: $css_class = $itemcount%2?' class="LC_odd_row"':'';
978: $datatable .=
979: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
980: '</td><td>'.
981: '<span class="LC_nobreak"><label><input type="radio" name="'.
982: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
983: '</label> <label><input type="radio" name="'.$item.'"'.
984: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
985: '</tr>';
986: $itemcount ++;
1.6 raeburn 987: }
1.160.6.5 raeburn 988: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
989: $datatable .= '</tr></table></td></tr>';
990: } elsif ($caller eq 'help') {
991: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
992: my $switchserver = &check_switchserver($dom,$confname);
993: my $itemcount = 1;
994: $defaulturl = '/adm/loginproblems.html';
995: $defaulttype = 'default';
996: %lt = &Apache::lonlocal::texthash (
997: del => 'Delete?',
998: rep => 'Replace:',
999: upl => 'Upload:',
1000: default => 'Default',
1001: custom => 'Custom',
1002: );
1003: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1004: my @currlangs;
1005: if (ref($settings) eq 'HASH') {
1006: if (ref($settings->{'helpurl'}) eq 'HASH') {
1007: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1008: next if ($settings->{'helpurl'}{$key} eq '');
1009: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1010: $type{$key} = 'custom';
1011: unless ($key eq 'nolang') {
1012: push(@currlangs,$key);
1013: }
1014: }
1015: } elsif ($settings->{'helpurl'} ne '') {
1016: $type{'nolang'} = 'custom';
1017: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1018: }
1019: }
1.160.6.5 raeburn 1020: foreach my $lang ('nolang',sort(@currlangs)) {
1021: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1022: $datatable .= '<tr'.$css_class.'>';
1023: if ($url{$lang} eq '') {
1024: $url{$lang} = $defaulturl;
1025: }
1026: if ($type{$lang} eq '') {
1027: $type{$lang} = $defaulttype;
1028: }
1029: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1030: if ($lang eq 'nolang') {
1031: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1032: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1033: } else {
1034: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1035: $langchoices{$lang},
1036: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1037: }
1038: $datatable .= '</span></td>'."\n".
1039: '<td class="LC_left_item">';
1040: if ($type{$lang} eq 'custom') {
1041: $datatable .= '<span class="LC_nobreak"><label>'.
1042: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1043: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1044: } else {
1045: $datatable .= $lt{'upl'};
1046: }
1047: $datatable .='<br />';
1048: if ($switchserver) {
1049: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1050: } else {
1051: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1052: }
1.160.6.5 raeburn 1053: $datatable .= '</td></tr>';
1054: $itemcount ++;
1.6 raeburn 1055: }
1.160.6.5 raeburn 1056: my @addlangs;
1057: foreach my $lang (sort(keys(%langchoices))) {
1058: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1059: push(@addlangs,$lang);
1060: }
1061: if (@addlangs > 0) {
1062: my %toadd;
1063: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1064: $toadd{''} = &mt('Select');
1065: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1066: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1067: &mt('Add log-in help page for a specific language:').' '.
1068: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1069: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1070: if ($switchserver) {
1071: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1072: } else {
1073: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1074: }
1.160.6.5 raeburn 1075: $datatable .= '</td></tr>';
1076: $itemcount ++;
1.6 raeburn 1077: }
1.160.6.5 raeburn 1078: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1079: }
1.6 raeburn 1080: return $datatable;
1081: }
1082:
1083: sub login_choices {
1084: my %choices =
1085: &Apache::lonlocal::texthash (
1.116 bisitz 1086: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1087: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1088: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1089: disallowlogin => "Login page requests redirected",
1090: hostid => "Server",
1.128 raeburn 1091: server => "Redirect to:",
1092: serverpath => "Path",
1093: custompath => "Custom",
1094: exempt => "Exempt IP(s)",
1.110 raeburn 1095: directlogin => "No redirect",
1096: newuser => "Link to create a user account",
1097: img => "Header",
1098: logo => "Main Logo",
1099: domlogo => "Domain Logo",
1100: login => "Log-in Header",
1101: textcol => "Text color",
1102: bgcol => "Box color",
1103: bgs => "Background colors",
1104: links => "Link colors",
1105: font => "Font color",
1106: pgbg => "Header",
1107: mainbg => "Page",
1108: sidebg => "Login box",
1109: link => "Link",
1110: alink => "Active link",
1111: vlink => "Visited link",
1.6 raeburn 1112: );
1113: return %choices;
1114: }
1115:
1116: sub print_rolecolors {
1.30 raeburn 1117: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1118: my %choices = &color_font_choices();
1119: my @bgs = ('pgbg','tabbg','sidebg');
1120: my @links = ('link','alink','vlink');
1121: my @images = ('img');
1122: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1123: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1124: my %defaultdesign = %Apache::loncommon::defaultdesign;
1125: my (%is_custom,%designs);
1126: my %defaults = (
1127: img => $defaultdesign{$role.'.img'},
1128: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1129: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1130: );
1131: foreach my $item (@bgs) {
1132: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1133: }
1134: foreach my $item (@links) {
1135: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1136: }
1137: if (ref($settings) eq 'HASH') {
1138: if (ref($settings->{$role}) eq 'HASH') {
1139: if ($settings->{$role}->{'img'} ne '') {
1140: $designs{'img'} = $settings->{$role}->{'img'};
1141: $is_custom{'img'} = 1;
1142: }
1143: if ($settings->{$role}->{'font'} ne '') {
1144: $designs{'font'} = $settings->{$role}->{'font'};
1145: $is_custom{'font'} = 1;
1146: }
1.97 tempelho 1147: if ($settings->{$role}->{'fontmenu'} ne '') {
1148: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1149: $is_custom{'fontmenu'} = 1;
1150: }
1.6 raeburn 1151: foreach my $item (@bgs) {
1152: if ($settings->{$role}->{$item} ne '') {
1153: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1154: $is_custom{$item} = 1;
1155: }
1156: }
1157: foreach my $item (@links) {
1158: if ($settings->{$role}->{$item} ne '') {
1159: $designs{'links'}{$item} = $settings->{$role}->{$item};
1160: $is_custom{$item} = 1;
1161: }
1162: }
1163: }
1164: } else {
1165: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1166: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1167: $is_custom{'img'} = 1;
1168: }
1.97 tempelho 1169: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1170: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1171: $is_custom{'fontmenu'} = 1;
1172: }
1.6 raeburn 1173: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1174: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1175: $is_custom{'font'} = 1;
1176: }
1177: foreach my $item (@bgs) {
1178: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1179: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1180: $is_custom{$item} = 1;
1181:
1182: }
1183: }
1184: foreach my $item (@links) {
1185: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1186: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1187: $is_custom{$item} = 1;
1188: }
1189: }
1190: }
1191: my $itemcount = 1;
1.30 raeburn 1192: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1193: $datatable .= '</tr></table></td></tr>';
1194: return $datatable;
1195: }
1196:
1197: sub display_color_options {
1.9 raeburn 1198: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1199: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1200: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1201: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1202: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1203: '<td>'.$choices->{'font'}.'</td>';
1204: if (!$is_custom->{'font'}) {
1.30 raeburn 1205: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1206: } else {
1207: $datatable .= '<td> </td>';
1208: }
1.160.6.9 raeburn 1209: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1210:
1.8 raeburn 1211: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1212: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1213: ' value="'.$current_color.'" /> '.
1214: ' </td></tr>';
1.107 raeburn 1215: unless ($role eq 'login') {
1216: $datatable .= '<tr'.$css_class.'>'.
1217: '<td>'.$choices->{'fontmenu'}.'</td>';
1218: if (!$is_custom->{'fontmenu'}) {
1219: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1220: } else {
1221: $datatable .= '<td> </td>';
1222: }
1.160.6.9 raeburn 1223: $current_color = $designs->{'fontmenu'} ?
1224: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1225: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1226: '<input class="colorchooser" type="text" size="10" name="'
1227: .$role.'_fontmenu"'.
1228: ' value="'.$current_color.'" /> '.
1229: ' </td></tr>';
1.97 tempelho 1230: }
1.9 raeburn 1231: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1232: foreach my $img (@{$images}) {
1.18 albertel 1233: $itemcount ++;
1.6 raeburn 1234: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1235: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1236: '<td>'.$choices->{$img};
1.41 raeburn 1237: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1238: if ($role eq 'login') {
1239: if ($img eq 'login') {
1240: $login_hdr_pick =
1.135 bisitz 1241: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1242: $logincolors =
1243: &login_text_colors($img,$role,$logintext,$phase,$choices,
1244: $designs);
1245: } elsif ($img ne 'domlogo') {
1246: $datatable.= &logo_display_options($img,$defaults,$designs);
1247: }
1248: }
1249: $datatable .= '</td>';
1.6 raeburn 1250: if ($designs->{$img} ne '') {
1251: $imgfile = $designs->{$img};
1.18 albertel 1252: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1253: } else {
1254: $imgfile = $defaults->{$img};
1255: }
1256: if ($imgfile) {
1.9 raeburn 1257: my ($showfile,$fullsize);
1258: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1259: my $urldir = $1;
1260: my $filename = $2;
1261: my @info = &Apache::lonnet::stat_file($designs->{$img});
1262: if (@info) {
1263: my $thumbfile = 'tn-'.$filename;
1264: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1265: if (@thumb) {
1266: $showfile = $urldir.'/'.$thumbfile;
1267: } else {
1268: $showfile = $imgfile;
1269: }
1270: } else {
1271: $showfile = '';
1272: }
1273: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1274: $showfile = $imgfile;
1.6 raeburn 1275: my $imgdir = $1;
1276: my $filename = $2;
1.159 raeburn 1277: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1278: $showfile = "/$imgdir/tn-".$filename;
1279: } else {
1.159 raeburn 1280: my $input = $londocroot.$imgfile;
1281: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1282: if (!-e $output) {
1.9 raeburn 1283: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1284: my ($fullwidth,$fullheight) = &check_dimensions($input);
1285: if ($fullwidth ne '' && $fullheight ne '') {
1286: if ($fullwidth > $width && $fullheight > $height) {
1287: my $size = $width.'x'.$height;
1288: system("convert -sample $size $input $output");
1.159 raeburn 1289: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1290: }
1291: }
1.6 raeburn 1292: }
1293: }
1.16 raeburn 1294: }
1.6 raeburn 1295: if ($showfile) {
1.40 raeburn 1296: if ($showfile =~ m{^/(adm|res)/}) {
1297: if ($showfile =~ m{^/res/}) {
1298: my $local_showfile =
1299: &Apache::lonnet::filelocation('',$showfile);
1300: &Apache::lonnet::repcopy($local_showfile);
1301: }
1302: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1303: }
1304: if ($imgfile) {
1305: if ($imgfile =~ m{^/(adm|res)/}) {
1306: if ($imgfile =~ m{^/res/}) {
1307: my $local_imgfile =
1308: &Apache::lonnet::filelocation('',$imgfile);
1309: &Apache::lonnet::repcopy($local_imgfile);
1310: }
1311: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1312: } else {
1313: $fullsize = $imgfile;
1314: }
1315: }
1.41 raeburn 1316: $datatable .= '<td>';
1317: if ($img eq 'login') {
1.135 bisitz 1318: $datatable .= $login_hdr_pick;
1319: }
1.41 raeburn 1320: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1321: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1322: } else {
1323: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1324: &mt('Upload:');
1325: }
1326: } else {
1327: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1328: &mt('Upload:');
1329: }
1.9 raeburn 1330: if ($switchserver) {
1331: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1332: } else {
1.135 bisitz 1333: if ($img ne 'login') { # suppress file selection for Log-in header
1334: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1335: }
1.9 raeburn 1336: }
1337: $datatable .= '</td></tr>';
1.6 raeburn 1338: }
1339: $itemcount ++;
1340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1341: $datatable .= '<tr'.$css_class.'>'.
1342: '<td>'.$choices->{'bgs'}.'</td>';
1343: my $bgs_def;
1344: foreach my $item (@{$bgs}) {
1345: if (!$is_custom->{$item}) {
1.70 raeburn 1346: $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 1347: }
1348: }
1349: if ($bgs_def) {
1.8 raeburn 1350: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1351: } else {
1352: $datatable .= '<td> </td>';
1353: }
1354: $datatable .= '<td class="LC_right_item">'.
1355: '<table border="0"><tr>';
1.160.6.13 raeburn 1356:
1.6 raeburn 1357: foreach my $item (@{$bgs}) {
1.160.6.9 raeburn 1358: $datatable .= '<td align="center">';
1359: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1360: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1361: $datatable .= ' ';
1.6 raeburn 1362: }
1.160.6.9 raeburn 1363: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1364: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1365: }
1366: $datatable .= '</tr></table></td></tr>';
1367: $itemcount ++;
1368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1369: $datatable .= '<tr'.$css_class.'>'.
1370: '<td>'.$choices->{'links'}.'</td>';
1371: my $links_def;
1372: foreach my $item (@{$links}) {
1373: if (!$is_custom->{$item}) {
1.30 raeburn 1374: $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 1375: }
1376: }
1377: if ($links_def) {
1.8 raeburn 1378: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1379: } else {
1380: $datatable .= '<td> </td>';
1381: }
1382: $datatable .= '<td class="LC_right_item">'.
1383: '<table border="0"><tr>';
1384: foreach my $item (@{$links}) {
1.160.6.9 raeburn 1385: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1386: $datatable .= '<td align="center">'."\n";
1387:
1.6 raeburn 1388: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1389: $datatable.=' ';
1.6 raeburn 1390: }
1.160.6.9 raeburn 1391: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1392: '" /></td>';
1393: }
1.30 raeburn 1394: $$rowtotal += $itemcount;
1.3 raeburn 1395: return $datatable;
1396: }
1397:
1.70 raeburn 1398: sub logo_display_options {
1399: my ($img,$defaults,$designs) = @_;
1400: my $checkedon;
1401: if (ref($defaults) eq 'HASH') {
1402: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1403: if ($defaults->{'showlogo'}{$img}) {
1404: $checkedon = 'checked="checked" ';
1405: }
1406: }
1407: }
1408: if (ref($designs) eq 'HASH') {
1409: if (ref($designs->{'showlogo'}) eq 'HASH') {
1410: if (defined($designs->{'showlogo'}{$img})) {
1411: if ($designs->{'showlogo'}{$img} == 0) {
1412: $checkedon = '';
1413: } elsif ($designs->{'showlogo'}{$img} == 1) {
1414: $checkedon = 'checked="checked" ';
1415: }
1416: }
1417: }
1418: }
1419: return '<br /><label> <input type="checkbox" name="'.
1420: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1421: &mt('show').'</label>'."\n";
1422: }
1423:
1.41 raeburn 1424: sub login_header_options {
1.135 bisitz 1425: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1426: my $output = '';
1.41 raeburn 1427: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1428: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1429: if (!$is_custom->{'textcol'}) {
1430: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1431: ' ';
1432: }
1433: if (!$is_custom->{'bgcol'}) {
1434: $output .= $choices->{'bgcol'}.': '.
1435: '<span id="css_'.$role.'_font" style="background-color: '.
1436: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1437: }
1438: $output .= '<br />';
1439: }
1440: $output .='<br />';
1441: return $output;
1442: }
1443:
1444: sub login_text_colors {
1445: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1446: my $color_menu = '<table border="0"><tr>';
1447: foreach my $item (@{$logintext}) {
1448: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1449: $color_menu .= '<td align="center">'.$link;
1450: if ($designs->{'logintext'}{$item}) {
1451: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1452: }
1453: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1454: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1455: '<td> </td>';
1456: }
1457: $color_menu .= '</tr></table><br />';
1458: return $color_menu;
1459: }
1460:
1461: sub image_changes {
1462: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1463: my $output;
1.135 bisitz 1464: if ($img eq 'login') {
1465: # suppress image for Log-in header
1466: } elsif (!$is_custom) {
1.70 raeburn 1467: if ($img ne 'domlogo') {
1.41 raeburn 1468: $output .= &mt('Default image:').'<br />';
1469: } else {
1470: $output .= &mt('Default in use:').'<br />';
1471: }
1472: }
1.135 bisitz 1473: if ($img eq 'login') { # suppress image for Log-in header
1474: $output .= '<td>'.$logincolors;
1.41 raeburn 1475: } else {
1.135 bisitz 1476: if ($img_import) {
1477: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1478: }
1479: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1480: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1481: if ($is_custom) {
1482: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1483: '<input type="checkbox" name="'.
1484: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1485: '</label> '.&mt('Replace:').'</span><br />';
1486: } else {
1487: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1488: }
1.41 raeburn 1489: }
1490: return $output;
1491: }
1492:
1.6 raeburn 1493: sub color_pick {
1494: my ($phase,$role,$item,$desc,$curcol) = @_;
1495: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1496: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1497: ');">'.$desc.'</a>';
1498: return $link;
1499: }
1500:
1.3 raeburn 1501: sub print_quotas {
1.86 raeburn 1502: my ($dom,$settings,$rowtotal,$action) = @_;
1503: my $context;
1504: if ($action eq 'quotas') {
1505: $context = 'tools';
1506: } else {
1507: $context = $action;
1508: }
1.160.6.20! raeburn 1509: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1510: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1511: my $typecount = 0;
1.101 raeburn 1512: my ($css_class,%titles);
1.86 raeburn 1513: if ($context eq 'requestcourses') {
1.98 raeburn 1514: @usertools = ('official','unofficial','community');
1.106 raeburn 1515: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1516: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1517: %titles = &courserequest_titles();
1.160.6.5 raeburn 1518: } elsif ($context eq 'requestauthor') {
1519: @usertools = ('author');
1520: @options = ('norequest','approval','automatic');
1521: %titles = &authorrequest_titles();
1.86 raeburn 1522: } else {
1.160.6.4 raeburn 1523: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1524: %titles = &tool_titles();
1.86 raeburn 1525: }
1.26 raeburn 1526: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1527: foreach my $type (@{$types}) {
1.160.6.20! raeburn 1528: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1529: unless (($context eq 'requestcourses') ||
1530: ($context eq 'requestauthor')) {
1.86 raeburn 1531: if (ref($settings) eq 'HASH') {
1532: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20! raeburn 1533: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1534: } else {
1535: $currdefquota = $settings->{$type};
1536: }
1.160.6.20! raeburn 1537: if (ref($settings->{authorquota}) eq 'HASH') {
! 1538: $currauthorquota = $settings->{authorquota}->{$type};
! 1539: }
1.78 raeburn 1540: }
1.72 raeburn 1541: }
1.3 raeburn 1542: if (defined($usertypes->{$type})) {
1543: $typecount ++;
1544: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1545: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1546: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1547: '<td class="LC_left_item">';
1.101 raeburn 1548: if ($context eq 'requestcourses') {
1549: $datatable .= '<table><tr>';
1550: }
1551: my %cell;
1.72 raeburn 1552: foreach my $item (@usertools) {
1.101 raeburn 1553: if ($context eq 'requestcourses') {
1554: my ($curroption,$currlimit);
1555: if (ref($settings) eq 'HASH') {
1556: if (ref($settings->{$item}) eq 'HASH') {
1557: $curroption = $settings->{$item}->{$type};
1558: if ($curroption =~ /^autolimit=(\d*)$/) {
1559: $currlimit = $1;
1560: }
1561: }
1562: }
1563: if (!$curroption) {
1564: $curroption = 'norequest';
1565: }
1566: $datatable .= '<th>'.$titles{$item}.'</th>';
1567: foreach my $option (@options) {
1568: my $val = $option;
1569: if ($option eq 'norequest') {
1570: $val = 0;
1571: }
1572: if ($option eq 'validate') {
1573: my $canvalidate = 0;
1574: if (ref($validations{$item}) eq 'HASH') {
1575: if ($validations{$item}{$type}) {
1576: $canvalidate = 1;
1577: }
1578: }
1579: next if (!$canvalidate);
1580: }
1581: my $checked = '';
1582: if ($option eq $curroption) {
1583: $checked = ' checked="checked"';
1584: } elsif ($option eq 'autolimit') {
1585: if ($curroption =~ /^autolimit/) {
1586: $checked = ' checked="checked"';
1587: }
1588: }
1589: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1590: '<input type="radio" name="crsreq_'.$item.
1591: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1592: $titles{$option}.'</label>';
1.101 raeburn 1593: if ($option eq 'autolimit') {
1.127 raeburn 1594: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1595: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1596: 'value="'.$currlimit.'" />';
1.101 raeburn 1597: }
1.127 raeburn 1598: $cell{$item} .= '</span> ';
1.103 raeburn 1599: if ($option eq 'autolimit') {
1.127 raeburn 1600: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1601: }
1.101 raeburn 1602: }
1.160.6.5 raeburn 1603: } elsif ($context eq 'requestauthor') {
1604: my $curroption;
1605: if (ref($settings) eq 'HASH') {
1606: $curroption = $settings->{$type};
1607: }
1608: if (!$curroption) {
1609: $curroption = 'norequest';
1610: }
1611: foreach my $option (@options) {
1612: my $val = $option;
1613: if ($option eq 'norequest') {
1614: $val = 0;
1615: }
1616: my $checked = '';
1617: if ($option eq $curroption) {
1618: $checked = ' checked="checked"';
1619: }
1620: $datatable .= '<span class="LC_nobreak"><label>'.
1621: '<input type="radio" name="authorreq_'.$type.
1622: '" value="'.$val.'"'.$checked.' />'.
1623: $titles{$option}.'</label></span> ';
1624: }
1.101 raeburn 1625: } else {
1626: my $checked = 'checked="checked" ';
1627: if (ref($settings) eq 'HASH') {
1628: if (ref($settings->{$item}) eq 'HASH') {
1629: if ($settings->{$item}->{$type} == 0) {
1630: $checked = '';
1631: } elsif ($settings->{$item}->{$type} == 1) {
1632: $checked = 'checked="checked" ';
1633: }
1.78 raeburn 1634: }
1.72 raeburn 1635: }
1.101 raeburn 1636: $datatable .= '<span class="LC_nobreak"><label>'.
1637: '<input type="checkbox" name="'.$context.'_'.$item.
1638: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1639: '</label></span> ';
1.72 raeburn 1640: }
1.101 raeburn 1641: }
1642: if ($context eq 'requestcourses') {
1643: $datatable .= '</tr><tr>';
1644: foreach my $item (@usertools) {
1.106 raeburn 1645: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1646: }
1647: $datatable .= '</tr></table>';
1.72 raeburn 1648: }
1.86 raeburn 1649: $datatable .= '</td>';
1.160.6.5 raeburn 1650: unless (($context eq 'requestcourses') ||
1651: ($context eq 'requestauthor')) {
1.86 raeburn 1652: $datatable .=
1.160.6.20! raeburn 1653: '<td class="LC_right_item">'.
! 1654: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1655: '<input type="text" name="quota_'.$type.
1.72 raeburn 1656: '" value="'.$currdefquota.
1.160.6.20! raeburn 1657: '" size="5" /></span>'.(' ' x 2).
! 1658: '<span class="LC_nobreak">'.&mt('Authoring').': '.
! 1659: '<input type="text" name="authorquota_'.$type.
! 1660: '" value="'.$currauthorquota.
! 1661: '" size="5" /></span></td>';
1.86 raeburn 1662: }
1663: $datatable .= '</tr>';
1.3 raeburn 1664: }
1665: }
1666: }
1.160.6.5 raeburn 1667: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1668: $defaultquota = '20';
1.160.6.20! raeburn 1669: $authorquota = '500';
1.86 raeburn 1670: if (ref($settings) eq 'HASH') {
1671: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1672: $defaultquota = $settings->{'defaultquota'}->{'default'};
1673: } elsif (defined($settings->{'default'})) {
1674: $defaultquota = $settings->{'default'};
1675: }
1.160.6.20! raeburn 1676: if (ref($settings->{'authorquota'}) eq 'HASH') {
! 1677: $authorquota = $settings->{'authorquota'}->{'default'};
! 1678: }
1.3 raeburn 1679: }
1680: }
1681: $typecount ++;
1682: $css_class = $typecount%2?' class="LC_odd_row"':'';
1683: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1684: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1685: '<td class="LC_left_item">';
1.101 raeburn 1686: if ($context eq 'requestcourses') {
1687: $datatable .= '<table><tr>';
1688: }
1689: my %defcell;
1.72 raeburn 1690: foreach my $item (@usertools) {
1.101 raeburn 1691: if ($context eq 'requestcourses') {
1692: my ($curroption,$currlimit);
1693: if (ref($settings) eq 'HASH') {
1694: if (ref($settings->{$item}) eq 'HASH') {
1695: $curroption = $settings->{$item}->{'default'};
1696: if ($curroption =~ /^autolimit=(\d*)$/) {
1697: $currlimit = $1;
1698: }
1699: }
1700: }
1701: if (!$curroption) {
1702: $curroption = 'norequest';
1703: }
1704: $datatable .= '<th>'.$titles{$item}.'</th>';
1705: foreach my $option (@options) {
1706: my $val = $option;
1707: if ($option eq 'norequest') {
1708: $val = 0;
1709: }
1710: if ($option eq 'validate') {
1711: my $canvalidate = 0;
1712: if (ref($validations{$item}) eq 'HASH') {
1713: if ($validations{$item}{'default'}) {
1714: $canvalidate = 1;
1715: }
1716: }
1717: next if (!$canvalidate);
1718: }
1719: my $checked = '';
1720: if ($option eq $curroption) {
1721: $checked = ' checked="checked"';
1722: } elsif ($option eq 'autolimit') {
1723: if ($curroption =~ /^autolimit/) {
1724: $checked = ' checked="checked"';
1725: }
1726: }
1727: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1728: '<input type="radio" name="crsreq_'.$item.
1729: '_default" value="'.$val.'"'.$checked.' />'.
1730: $titles{$option}.'</label>';
1731: if ($option eq 'autolimit') {
1.127 raeburn 1732: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1733: $item.'_limit_default" size="1" '.
1734: 'value="'.$currlimit.'" />';
1735: }
1.127 raeburn 1736: $defcell{$item} .= '</span> ';
1.104 raeburn 1737: if ($option eq 'autolimit') {
1.127 raeburn 1738: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1739: }
1.101 raeburn 1740: }
1.160.6.5 raeburn 1741: } elsif ($context eq 'requestauthor') {
1742: my $curroption;
1743: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1744: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1745: }
1746: if (!$curroption) {
1747: $curroption = 'norequest';
1748: }
1749: foreach my $option (@options) {
1750: my $val = $option;
1751: if ($option eq 'norequest') {
1752: $val = 0;
1753: }
1754: my $checked = '';
1755: if ($option eq $curroption) {
1756: $checked = ' checked="checked"';
1757: }
1758: $datatable .= '<span class="LC_nobreak"><label>'.
1759: '<input type="radio" name="authorreq_default"'.
1760: ' value="'.$val.'"'.$checked.' />'.
1761: $titles{$option}.'</label></span> ';
1762: }
1.101 raeburn 1763: } else {
1764: my $checked = 'checked="checked" ';
1765: if (ref($settings) eq 'HASH') {
1766: if (ref($settings->{$item}) eq 'HASH') {
1767: if ($settings->{$item}->{'default'} == 0) {
1768: $checked = '';
1769: } elsif ($settings->{$item}->{'default'} == 1) {
1770: $checked = 'checked="checked" ';
1771: }
1.78 raeburn 1772: }
1.72 raeburn 1773: }
1.101 raeburn 1774: $datatable .= '<span class="LC_nobreak"><label>'.
1775: '<input type="checkbox" name="'.$context.'_'.$item.
1776: '" value="default" '.$checked.'/>'.$titles{$item}.
1777: '</label></span> ';
1778: }
1779: }
1780: if ($context eq 'requestcourses') {
1781: $datatable .= '</tr><tr>';
1782: foreach my $item (@usertools) {
1.106 raeburn 1783: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1784: }
1.101 raeburn 1785: $datatable .= '</tr></table>';
1.72 raeburn 1786: }
1.86 raeburn 1787: $datatable .= '</td>';
1.160.6.5 raeburn 1788: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20! raeburn 1789: $datatable .= '<td class="LC_right_item">'.
! 1790: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1791: '<input type="text" name="defaultquota" value="'.
1.160.6.20! raeburn 1792: $defaultquota.'" size="5" /></span>'.(' ' x2).
! 1793: '<span class="LC_nobreak">'.&mt('Authoring').': '.
! 1794: '<input type="text" name="authorquota" value="'.
! 1795: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1796: }
1797: $datatable .= '</tr>';
1.72 raeburn 1798: $typecount ++;
1799: $css_class = $typecount%2?' class="LC_odd_row"':'';
1800: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20! raeburn 1801: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1802: if ($context eq 'requestcourses') {
1.109 raeburn 1803: $datatable .= &mt('(overrides affiliation, if set)').
1804: '</td>'.
1805: '<td class="LC_left_item">'.
1806: '<table><tr>';
1.101 raeburn 1807: } else {
1.109 raeburn 1808: $datatable .= &mt('(overrides affiliation, if checked)').
1809: '</td>'.
1810: '<td class="LC_left_item" colspan="2">'.
1811: '<br />';
1.101 raeburn 1812: }
1813: my %advcell;
1.72 raeburn 1814: foreach my $item (@usertools) {
1.101 raeburn 1815: if ($context eq 'requestcourses') {
1816: my ($curroption,$currlimit);
1817: if (ref($settings) eq 'HASH') {
1818: if (ref($settings->{$item}) eq 'HASH') {
1819: $curroption = $settings->{$item}->{'_LC_adv'};
1820: if ($curroption =~ /^autolimit=(\d*)$/) {
1821: $currlimit = $1;
1822: }
1823: }
1824: }
1825: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1826: my $checked = '';
1827: if ($curroption eq '') {
1828: $checked = ' checked="checked"';
1829: }
1830: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1831: '<input type="radio" name="crsreq_'.$item.
1832: '__LC_adv" value=""'.$checked.' />'.
1833: &mt('No override set').'</label></span> ';
1.101 raeburn 1834: foreach my $option (@options) {
1835: my $val = $option;
1836: if ($option eq 'norequest') {
1837: $val = 0;
1838: }
1839: if ($option eq 'validate') {
1840: my $canvalidate = 0;
1841: if (ref($validations{$item}) eq 'HASH') {
1842: if ($validations{$item}{'_LC_adv'}) {
1843: $canvalidate = 1;
1844: }
1845: }
1846: next if (!$canvalidate);
1847: }
1848: my $checked = '';
1.104 raeburn 1849: if ($val eq $curroption) {
1.101 raeburn 1850: $checked = ' checked="checked"';
1851: } elsif ($option eq 'autolimit') {
1852: if ($curroption =~ /^autolimit/) {
1853: $checked = ' checked="checked"';
1854: }
1855: }
1856: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1857: '<input type="radio" name="crsreq_'.$item.
1858: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1859: $titles{$option}.'</label>';
1860: if ($option eq 'autolimit') {
1.127 raeburn 1861: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1862: $item.'_limit__LC_adv" size="1" '.
1863: 'value="'.$currlimit.'" />';
1864: }
1.127 raeburn 1865: $advcell{$item} .= '</span> ';
1.104 raeburn 1866: if ($option eq 'autolimit') {
1.127 raeburn 1867: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1868: }
1.101 raeburn 1869: }
1.160.6.5 raeburn 1870: } elsif ($context eq 'requestauthor') {
1871: my $curroption;
1872: if (ref($settings) eq 'HASH') {
1873: $curroption = $settings->{'_LC_adv'};
1874: }
1875: my $checked = '';
1876: if ($curroption eq '') {
1877: $checked = ' checked="checked"';
1878: }
1879: $datatable .= '<span class="LC_nobreak"><label>'.
1880: '<input type="radio" name="authorreq__LC_adv"'.
1881: ' value=""'.$checked.' />'.
1882: &mt('No override set').'</label></span> ';
1883: foreach my $option (@options) {
1884: my $val = $option;
1885: if ($option eq 'norequest') {
1886: $val = 0;
1887: }
1888: my $checked = '';
1889: if ($val eq $curroption) {
1890: $checked = ' checked="checked"';
1891: }
1892: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1893: '<input type="radio" name="authorreq__LC_adv"'.
1894: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1895: $titles{$option}.'</label></span> ';
1896: }
1.101 raeburn 1897: } else {
1898: my $checked = 'checked="checked" ';
1899: if (ref($settings) eq 'HASH') {
1900: if (ref($settings->{$item}) eq 'HASH') {
1901: if ($settings->{$item}->{'_LC_adv'} == 0) {
1902: $checked = '';
1903: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1904: $checked = 'checked="checked" ';
1905: }
1.79 raeburn 1906: }
1.72 raeburn 1907: }
1.101 raeburn 1908: $datatable .= '<span class="LC_nobreak"><label>'.
1909: '<input type="checkbox" name="'.$context.'_'.$item.
1910: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1911: '</label></span> ';
1912: }
1913: }
1914: if ($context eq 'requestcourses') {
1915: $datatable .= '</tr><tr>';
1916: foreach my $item (@usertools) {
1.106 raeburn 1917: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1918: }
1.101 raeburn 1919: $datatable .= '</tr></table>';
1.72 raeburn 1920: }
1.98 raeburn 1921: $datatable .= '</td></tr>';
1.30 raeburn 1922: $$rowtotal += $typecount;
1.3 raeburn 1923: return $datatable;
1924: }
1925:
1.160.6.5 raeburn 1926: sub print_requestmail {
1927: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 1928: my ($now,$datatable,%currapp,$rows);
1.102 raeburn 1929: $now = time;
1930: if (ref($settings) eq 'HASH') {
1931: if (ref($settings->{'notify'}) eq 'HASH') {
1932: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.16 raeburn 1933: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1934: }
1935: }
1936: }
1.160.6.16 raeburn 1937: my $numinrow = 2;
1.102 raeburn 1938: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1939: my $text;
1940: if ($action eq 'requestcourses') {
1941: $text = &mt('Receive notification of course requests requiring approval');
1942: } else {
1943: $text = &mt('Receive notification of authoring space requests requiring approval')
1944: }
1945: $datatable = '<tr '.$css_class.'>'.
1946: ' <td>'.$text.'</td>'.
1.102 raeburn 1947: ' <td class="LC_left_item">';
1.160.6.16 raeburn 1948: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1949: 'reqapprovalnotify',%currapp);
1950: if ($numdc > 0) {
1951: $datatable .= $table;
1.102 raeburn 1952: } else {
1953: $datatable .= &mt('There are no active Domain Coordinators');
1954: }
1955: $datatable .='</td></tr>';
1956: $$rowtotal += $rows;
1957: return $datatable;
1958: }
1959:
1.3 raeburn 1960: sub print_autoenroll {
1.30 raeburn 1961: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1962: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1963: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1964: if (ref($settings) eq 'HASH') {
1965: if (exists($settings->{'run'})) {
1966: if ($settings->{'run'} eq '0') {
1967: $runoff = ' checked="checked" ';
1968: $runon = ' ';
1969: } else {
1970: $runon = ' checked="checked" ';
1971: $runoff = ' ';
1972: }
1973: } else {
1974: if ($autorun) {
1975: $runon = ' checked="checked" ';
1976: $runoff = ' ';
1977: } else {
1978: $runoff = ' checked="checked" ';
1979: $runon = ' ';
1980: }
1981: }
1.129 raeburn 1982: if (exists($settings->{'co-owners'})) {
1983: if ($settings->{'co-owners'} eq '0') {
1984: $coownersoff = ' checked="checked" ';
1985: $coownerson = ' ';
1986: } else {
1987: $coownerson = ' checked="checked" ';
1988: $coownersoff = ' ';
1989: }
1990: } else {
1991: $coownersoff = ' checked="checked" ';
1992: $coownerson = ' ';
1993: }
1.3 raeburn 1994: if (exists($settings->{'sender_domain'})) {
1995: $defdom = $settings->{'sender_domain'};
1996: }
1.14 raeburn 1997: } else {
1998: if ($autorun) {
1999: $runon = ' checked="checked" ';
2000: $runoff = ' ';
2001: } else {
2002: $runoff = ' checked="checked" ';
2003: $runon = ' ';
2004: }
1.3 raeburn 2005: }
2006: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2007: my $notif_sender;
2008: if (ref($settings) eq 'HASH') {
2009: $notif_sender = $settings->{'sender_uname'};
2010: }
1.3 raeburn 2011: my $datatable='<tr class="LC_odd_row">'.
2012: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2013: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2014: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2015: $runon.' value="1" />'.&mt('Yes').'</label> '.
2016: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2017: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2018: '</tr><tr>'.
2019: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2020: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2021: &mt('username').': '.
2022: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2023: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2024: ': '.$domform.'</span></td></tr>'.
2025: '<tr class="LC_odd_row">'.
2026: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2027: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2028: '<input type="radio" name="autoassign_coowners"'.
2029: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2030: '<label><input type="radio" name="autoassign_coowners"'.
2031: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2032: '</tr>';
2033: $$rowtotal += 3;
1.3 raeburn 2034: return $datatable;
2035: }
2036:
2037: sub print_autoupdate {
1.30 raeburn 2038: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2039: my $datatable;
2040: if ($position eq 'top') {
2041: my $updateon = ' ';
2042: my $updateoff = ' checked="checked" ';
2043: my $classlistson = ' ';
2044: my $classlistsoff = ' checked="checked" ';
2045: if (ref($settings) eq 'HASH') {
2046: if ($settings->{'run'} eq '1') {
2047: $updateon = $updateoff;
2048: $updateoff = ' ';
2049: }
2050: if ($settings->{'classlists'} eq '1') {
2051: $classlistson = $classlistsoff;
2052: $classlistsoff = ' ';
2053: }
2054: }
2055: my %title = (
2056: run => 'Auto-update active?',
2057: classlists => 'Update information in classlists?',
2058: );
2059: $datatable = '<tr class="LC_odd_row">'.
2060: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2061: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2062: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2063: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2064: '<label><input type="radio" name="autoupdate_run"'.
2065: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2066: '</tr><tr>'.
2067: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2068: '<td class="LC_right_item"><span class="LC_nobreak">'.
2069: '<label><input type="radio" name="classlists"'.
2070: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2071: '<label><input type="radio" name="classlists"'.
2072: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2073: '</tr>';
1.30 raeburn 2074: $$rowtotal += 2;
1.131 raeburn 2075: } elsif ($position eq 'middle') {
2076: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2077: my $numinrow = 3;
2078: my $locknamesettings;
2079: $datatable .= &insttypes_row($settings,$types,$usertypes,
2080: $dom,$numinrow,$othertitle,
2081: 'lockablenames');
2082: $$rowtotal ++;
1.3 raeburn 2083: } else {
1.44 raeburn 2084: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2085: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2086: 'permanentemail','id');
1.33 raeburn 2087: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2088: my $numrows = 0;
1.26 raeburn 2089: if (ref($types) eq 'ARRAY') {
2090: if (@{$types} > 0) {
2091: $datatable =
2092: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2093: \@fields,$types,\$numrows);
1.30 raeburn 2094: $$rowtotal += @{$types};
1.26 raeburn 2095: }
1.3 raeburn 2096: }
2097: $datatable .=
2098: &usertype_update_row($settings,{'default' => $othertitle},
2099: \%fieldtitles,\@fields,['default'],
2100: \$numrows);
1.30 raeburn 2101: $$rowtotal ++;
1.3 raeburn 2102: }
2103: return $datatable;
2104: }
2105:
1.125 raeburn 2106: sub print_autocreate {
2107: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2108: my (%createon,%createoff,%currhash);
1.125 raeburn 2109: my @types = ('xml','req');
2110: if (ref($settings) eq 'HASH') {
2111: foreach my $item (@types) {
2112: $createoff{$item} = ' checked="checked" ';
2113: $createon{$item} = ' ';
2114: if (exists($settings->{$item})) {
2115: if ($settings->{$item}) {
2116: $createon{$item} = ' checked="checked" ';
2117: $createoff{$item} = ' ';
2118: }
2119: }
2120: }
1.160.6.16 raeburn 2121: if ($settings->{'xmldc'} ne '') {
2122: $currhash{$settings->{'xmldc'}} = 1;
2123: }
1.125 raeburn 2124: } else {
2125: foreach my $item (@types) {
2126: $createoff{$item} = ' checked="checked" ';
2127: $createon{$item} = ' ';
2128: }
2129: }
2130: $$rowtotal += 2;
1.160.6.16 raeburn 2131: my $numinrow = 2;
1.125 raeburn 2132: my $datatable='<tr class="LC_odd_row">'.
2133: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2134: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2135: '<input type="radio" name="autocreate_xml"'.
2136: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2137: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2138: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2139: '</td></tr><tr>'.
2140: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2141: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2142: '<input type="radio" name="autocreate_req"'.
2143: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2144: '<label><input type="radio" name="autocreate_req"'.
2145: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2146: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2147: 'autocreate_xmldc',%currhash);
1.125 raeburn 2148: if ($numdc > 1) {
1.143 raeburn 2149: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2150: &mt('Course creation processed as: (choose Dom. Coord.)').
2151: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2152: } else {
1.143 raeburn 2153: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2154: }
1.160.6.16 raeburn 2155: $$rowtotal += $rows;
1.125 raeburn 2156: return $datatable;
2157: }
2158:
1.23 raeburn 2159: sub print_directorysrch {
1.30 raeburn 2160: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2161: my $srchon = ' ';
2162: my $srchoff = ' checked="checked" ';
1.25 raeburn 2163: my ($exacton,$containson,$beginson);
1.24 raeburn 2164: my $localon = ' ';
2165: my $localoff = ' checked="checked" ';
1.23 raeburn 2166: if (ref($settings) eq 'HASH') {
2167: if ($settings->{'available'} eq '1') {
2168: $srchon = $srchoff;
2169: $srchoff = ' ';
2170: }
1.24 raeburn 2171: if ($settings->{'localonly'} eq '1') {
2172: $localon = $localoff;
2173: $localoff = ' ';
2174: }
1.25 raeburn 2175: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2176: foreach my $type (@{$settings->{'searchtypes'}}) {
2177: if ($type eq 'exact') {
2178: $exacton = ' checked="checked" ';
2179: } elsif ($type eq 'contains') {
2180: $containson = ' checked="checked" ';
2181: } elsif ($type eq 'begins') {
2182: $beginson = ' checked="checked" ';
2183: }
2184: }
2185: } else {
2186: if ($settings->{'searchtypes'} eq 'exact') {
2187: $exacton = ' checked="checked" ';
2188: } elsif ($settings->{'searchtypes'} eq 'contains') {
2189: $containson = ' checked="checked" ';
2190: } elsif ($settings->{'searchtypes'} eq 'specify') {
2191: $exacton = ' checked="checked" ';
2192: $containson = ' checked="checked" ';
2193: }
1.23 raeburn 2194: }
2195: }
2196: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2197: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2198:
2199: my $numinrow = 4;
1.26 raeburn 2200: my $cansrchrow = 0;
1.23 raeburn 2201: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2202: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2203: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2204: '<input type="radio" name="dirsrch_available"'.
2205: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2206: '<label><input type="radio" name="dirsrch_available"'.
2207: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2208: '</tr><tr>'.
1.30 raeburn 2209: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2210: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2211: '<input type="radio" name="dirsrch_localonly"'.
2212: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2213: '<label><input type="radio" name="dirsrch_localonly"'.
2214: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2215: '</tr>';
1.30 raeburn 2216: $$rowtotal += 2;
1.26 raeburn 2217: if (ref($usertypes) eq 'HASH') {
2218: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2219: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2220: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2221: $cansrchrow = 1;
2222: }
2223: }
2224: if ($cansrchrow) {
1.30 raeburn 2225: $$rowtotal ++;
1.26 raeburn 2226: $datatable .= '<tr>';
2227: } else {
2228: $datatable .= '<tr class="LC_odd_row">';
2229: }
1.30 raeburn 2230: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2231: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2232: foreach my $title (@{$titleorder}) {
2233: if (defined($searchtitles->{$title})) {
2234: my $check = ' ';
1.93 raeburn 2235: if (ref($settings) eq 'HASH') {
1.39 raeburn 2236: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2237: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2238: $check = ' checked="checked" ';
2239: }
1.25 raeburn 2240: }
2241: }
2242: $datatable .= '<td class="LC_left_item">'.
2243: '<span class="LC_nobreak"><label>'.
2244: '<input type="checkbox" name="searchby" '.
2245: 'value="'.$title.'"'.$check.'/>'.
2246: $searchtitles->{$title}.'</label></span></td>';
2247: }
2248: }
1.26 raeburn 2249: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2250: $$rowtotal ++;
1.26 raeburn 2251: if ($cansrchrow) {
2252: $datatable .= '<tr class="LC_odd_row">';
2253: } else {
2254: $datatable .= '<tr>';
2255: }
1.30 raeburn 2256: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2257: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2258: '<span class="LC_nobreak"><label>'.
2259: '<input type="checkbox" name="searchtypes" '.
2260: $exacton.' value="exact" />'.&mt('Exact match').
2261: '</label> '.
2262: '<label><input type="checkbox" name="searchtypes" '.
2263: $beginson.' value="begins" />'.&mt('Begins with').
2264: '</label> '.
2265: '<label><input type="checkbox" name="searchtypes" '.
2266: $containson.' value="contains" />'.&mt('Contains').
2267: '</label></span></td></tr>';
1.30 raeburn 2268: $$rowtotal ++;
1.25 raeburn 2269: return $datatable;
2270: }
2271:
1.28 raeburn 2272: sub print_contacts {
1.30 raeburn 2273: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2274: my $datatable;
2275: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2276: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2277: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.15 raeburn 2278: 'requestsmail','updatesmail');
1.28 raeburn 2279: foreach my $type (@mailings) {
2280: $otheremails{$type} = '';
2281: }
1.134 raeburn 2282: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2283: if (ref($settings) eq 'HASH') {
2284: foreach my $item (@contacts) {
2285: if (exists($settings->{$item})) {
2286: $to{$item} = $settings->{$item};
2287: }
2288: }
2289: foreach my $type (@mailings) {
2290: if (exists($settings->{$type})) {
2291: if (ref($settings->{$type}) eq 'HASH') {
2292: foreach my $item (@contacts) {
2293: if ($settings->{$type}{$item}) {
2294: $checked{$type}{$item} = ' checked="checked" ';
2295: }
2296: }
2297: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2298: if ($type eq 'helpdeskmail') {
2299: $bccemails{$type} = $settings->{$type}{'bcc'};
2300: }
1.28 raeburn 2301: }
1.89 raeburn 2302: } elsif ($type eq 'lonstatusmail') {
2303: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2304: }
2305: }
2306: } else {
2307: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2308: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2309: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2310: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2311: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2312: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2313: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.15 raeburn 2314: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2315: }
2316: my ($titles,$short_titles) = &contact_titles();
2317: my $rownum = 0;
2318: my $css_class;
2319: foreach my $item (@contacts) {
1.69 raeburn 2320: $rownum ++;
2321: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2322: $datatable .= '<tr'.$css_class.'>'.
2323: '<td><span class="LC_nobreak">'.$titles->{$item}.
2324: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2325: '<input type="text" name="'.$item.'" value="'.
2326: $to{$item}.'" /></td></tr>';
2327: }
2328: foreach my $type (@mailings) {
1.69 raeburn 2329: $rownum ++;
2330: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2331: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2332: '<td><span class="LC_nobreak">'.
2333: $titles->{$type}.': </span></td>'.
1.28 raeburn 2334: '<td class="LC_left_item">'.
2335: '<span class="LC_nobreak">';
2336: foreach my $item (@contacts) {
2337: $datatable .= '<label>'.
2338: '<input type="checkbox" name="'.$type.'"'.
2339: $checked{$type}{$item}.
2340: ' value="'.$item.'" />'.$short_titles->{$item}.
2341: '</label> ';
2342: }
2343: $datatable .= '</span><br />'.&mt('Others').': '.
2344: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2345: 'value="'.$otheremails{$type}.'" />';
2346: if ($type eq 'helpdeskmail') {
1.136 raeburn 2347: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2348: '<input type="text" name="'.$type.'_bcc" '.
2349: 'value="'.$bccemails{$type}.'" />';
2350: }
2351: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2352: }
1.30 raeburn 2353: $$rowtotal += $rownum;
1.28 raeburn 2354: return $datatable;
2355: }
2356:
1.118 jms 2357: sub print_helpsettings {
1.160.6.5 raeburn 2358: my ($dom,$confname,$settings,$rowtotal) = @_;
2359: my ($datatable,$itemcount);
2360: $itemcount = 1;
2361: my (%choices,%defaultchecked,@toggles);
2362: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2363: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2364: &mt('LON-CAPA bug tracker'),600,500));
2365: %defaultchecked = ('submitbugs' => 'on');
2366: @toggles = ('submitbugs',);
1.122 jms 2367:
1.160.6.5 raeburn 2368: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2369: \%choices,$itemcount);
2370: return $datatable;
1.121 raeburn 2371: }
2372:
2373: sub radiobutton_prefs {
1.160.6.16 raeburn 2374: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2375: $additional) = @_;
1.121 raeburn 2376: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2377: (ref($choices) eq 'HASH'));
2378:
2379: my (%checkedon,%checkedoff,$datatable,$css_class);
2380:
2381: foreach my $item (@{$toggles}) {
2382: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2383: $checkedon{$item} = ' checked="checked" ';
2384: $checkedoff{$item} = ' ';
1.121 raeburn 2385: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2386: $checkedoff{$item} = ' checked="checked" ';
2387: $checkedon{$item} = ' ';
2388: }
2389: }
2390: if (ref($settings) eq 'HASH') {
1.121 raeburn 2391: foreach my $item (@{$toggles}) {
1.118 jms 2392: if ($settings->{$item} eq '1') {
2393: $checkedon{$item} = ' checked="checked" ';
2394: $checkedoff{$item} = ' ';
2395: } elsif ($settings->{$item} eq '0') {
2396: $checkedoff{$item} = ' checked="checked" ';
2397: $checkedon{$item} = ' ';
2398: }
2399: }
1.121 raeburn 2400: }
1.160.6.16 raeburn 2401: if ($onclick) {
2402: $onclick = ' onclick="'.$onclick.'"';
2403: }
1.121 raeburn 2404: foreach my $item (@{$toggles}) {
1.118 jms 2405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2406: $datatable .=
1.160.6.16 raeburn 2407: '<tr'.$css_class.'><td valign="top">'.
2408: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2409: '</span></td>'.
2410: '<td class="LC_right_item"><span class="LC_nobreak">'.
2411: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2412: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2413: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2414: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2415: '</span>'.$additional.
2416: '</td>'.
1.118 jms 2417: '</tr>';
2418: $itemcount ++;
1.121 raeburn 2419: }
2420: return ($datatable,$itemcount);
2421: }
2422:
2423: sub print_coursedefaults {
1.139 raeburn 2424: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2425: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2426: my $itemcount = 1;
1.160.6.16 raeburn 2427: my %choices = &Apache::lonlocal::texthash (
2428: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2429: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2430: coursecredits => 'Credits can be specified for courses',
2431: );
1.139 raeburn 2432: if ($position eq 'top') {
2433: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2434: @toggles = ('canuse_pdfforms');
1.139 raeburn 2435: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2436: \%choices,$itemcount);
1.139 raeburn 2437: } else {
2438: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.16 raeburn 2439: my ($currdefresponder,$def_official_credits,$def_unofficial_credits);
2440: my $currusecredits = 0;
1.139 raeburn 2441: if (ref($settings) eq 'HASH') {
2442: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.16 raeburn 2443: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2444: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2445: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2446: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2447: $currusecredits = 1;
2448: }
2449: }
1.139 raeburn 2450: }
2451: if (!$currdefresponder) {
2452: $currdefresponder = 10;
2453: } elsif ($currdefresponder < 1) {
2454: $currdefresponder = 1;
2455: }
2456: $datatable .=
1.160.6.16 raeburn 2457: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2458: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2459: '</span></td>'.
2460: '<td class="LC_right_item"><span class="LC_nobreak">'.
2461: '<input type="text" name="anonsurvey_threshold"'.
2462: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.16 raeburn 2463: '</td></tr>'."\n";
2464: $itemcount ++;
2465: my $onclick = 'toggleCredits(this.form);';
2466: my $display = 'none';
2467: if ($currusecredits) {
2468: $display = 'block';
2469: }
2470: my $additional = '<div id="credits" style="display: '.$display.'">'.
2471: '<span class="LC_nobreak">'.
2472: &mt('Default credits for official courses [_1]',
2473: '<input type="text" name="official_credits" value="'.
2474: $def_official_credits.'" size="3" />').
2475: '</span><br />'.
2476: '<span class="LC_nobreak">'.
2477: &mt('Default credits for unofficial courses [_1]',
2478: '<input type="text" name="unofficial_credits" value="'.
2479: $def_unofficial_credits.'" size="3" />').
2480: '</span></div>'."\n";
2481: %defaultchecked = ('coursecredits' => 'off');
2482: @toggles = ('coursecredits');
2483: my $current = {
2484: 'coursecredits' => $currusecredits,
2485: };
2486: (my $table,$itemcount) =
2487: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2488: \%choices,$itemcount,$onclick,$additional);
2489: $datatable .= $table;
1.139 raeburn 2490: }
1.160.6.16 raeburn 2491: $$rowtotal += $itemcount;
1.121 raeburn 2492: return $datatable;
1.118 jms 2493: }
2494:
1.137 raeburn 2495: sub print_usersessions {
2496: my ($position,$dom,$settings,$rowtotal) = @_;
2497: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2498: my (%by_ip,%by_location,@intdoms);
2499: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2500:
2501: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2502: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2503: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2504: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2505: my $itemcount = 1;
2506: if ($position eq 'top') {
1.152 raeburn 2507: if (keys(%serverhomes) > 1) {
1.145 raeburn 2508: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2509: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2510: } else {
1.140 raeburn 2511: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2512: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2513: }
1.137 raeburn 2514: } else {
1.145 raeburn 2515: if (keys(%by_location) == 0) {
2516: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2517: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2518: } else {
2519: my %lt = &usersession_titles();
2520: my $numinrow = 5;
2521: my $prefix;
2522: my @types;
2523: if ($position eq 'bottom') {
2524: $prefix = 'remote';
2525: @types = ('version','excludedomain','includedomain');
2526: } else {
2527: $prefix = 'hosted';
2528: @types = ('excludedomain','includedomain');
2529: }
2530: my (%current,%checkedon,%checkedoff);
2531: my @lcversions = &Apache::lonnet::all_loncaparevs();
2532: my @locations = sort(keys(%by_location));
2533: foreach my $type (@types) {
2534: $checkedon{$type} = '';
2535: $checkedoff{$type} = ' checked="checked"';
2536: }
2537: if (ref($settings) eq 'HASH') {
2538: if (ref($settings->{$prefix}) eq 'HASH') {
2539: foreach my $key (keys(%{$settings->{$prefix}})) {
2540: $current{$key} = $settings->{$prefix}{$key};
2541: if ($key eq 'version') {
2542: if ($current{$key} ne '') {
2543: $checkedon{$key} = ' checked="checked"';
2544: $checkedoff{$key} = '';
2545: }
2546: } elsif (ref($current{$key}) eq 'ARRAY') {
2547: $checkedon{$key} = ' checked="checked"';
2548: $checkedoff{$key} = '';
2549: }
1.137 raeburn 2550: }
2551: }
2552: }
1.145 raeburn 2553: foreach my $type (@types) {
2554: next if ($type ne 'version' && !@locations);
2555: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2556: $datatable .= '<tr'.$css_class.'>
2557: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2558: <span class="LC_nobreak">
2559: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2560: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2561: if ($type eq 'version') {
2562: my $selector = '<select name="'.$prefix.'_version">';
2563: foreach my $version (@lcversions) {
2564: my $selected = '';
2565: if ($current{'version'} eq $version) {
2566: $selected = ' selected="selected"';
2567: }
2568: $selector .= ' <option value="'.$version.'"'.
2569: $selected.'>'.$version.'</option>';
2570: }
2571: $selector .= '</select> ';
2572: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2573: } else {
2574: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2575: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2576: ' />'.(' 'x2).
2577: '<input type="button" value="'.&mt('uncheck all').'" '.
2578: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2579: "\n".
2580: '</div><div><table>';
2581: my $rem;
2582: for (my $i=0; $i<@locations; $i++) {
2583: my ($showloc,$value,$checkedtype);
2584: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2585: my $ip = $by_location{$locations[$i]}->[0];
2586: if (ref($by_ip{$ip}) eq 'ARRAY') {
2587: $value = join(':',@{$by_ip{$ip}});
2588: $showloc = join(', ',@{$by_ip{$ip}});
2589: if (ref($current{$type}) eq 'ARRAY') {
2590: foreach my $loc (@{$by_ip{$ip}}) {
2591: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2592: $checkedtype = ' checked="checked"';
2593: last;
2594: }
2595: }
1.138 raeburn 2596: }
2597: }
2598: }
1.145 raeburn 2599: $rem = $i%($numinrow);
2600: if ($rem == 0) {
2601: if ($i > 0) {
2602: $datatable .= '</tr>';
2603: }
2604: $datatable .= '<tr>';
2605: }
2606: $datatable .= '<td class="LC_left_item">'.
2607: '<span class="LC_nobreak"><label>'.
2608: '<input type="checkbox" name="'.$prefix.'_'.$type.
2609: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2610: '</label></span></td>';
1.137 raeburn 2611: }
1.145 raeburn 2612: $rem = @locations%($numinrow);
2613: my $colsleft = $numinrow - $rem;
2614: if ($colsleft > 1 ) {
2615: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2616: ' </td>';
2617: } elsif ($colsleft == 1) {
2618: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2619: }
1.145 raeburn 2620: $datatable .= '</tr></table>';
1.137 raeburn 2621: }
1.145 raeburn 2622: $datatable .= '</td></tr>';
2623: $itemcount ++;
1.137 raeburn 2624: }
2625: }
2626: }
2627: $$rowtotal += $itemcount;
2628: return $datatable;
2629: }
2630:
1.138 raeburn 2631: sub build_location_hashes {
2632: my ($intdoms,$by_ip,$by_location) = @_;
2633: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2634: (ref($by_location) eq 'HASH'));
2635: my %iphost = &Apache::lonnet::get_iphost();
2636: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2637: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2638: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2639: foreach my $id (@{$iphost{$primary_ip}}) {
2640: my $intdom = &Apache::lonnet::internet_dom($id);
2641: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2642: push(@{$intdoms},$intdom);
2643: }
2644: }
2645: }
2646: foreach my $ip (keys(%iphost)) {
2647: if (ref($iphost{$ip}) eq 'ARRAY') {
2648: foreach my $id (@{$iphost{$ip}}) {
2649: my $location = &Apache::lonnet::internet_dom($id);
2650: if ($location) {
2651: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2652: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2653: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2654: push(@{$by_ip->{$ip}},$location);
2655: }
2656: } else {
2657: $by_ip->{$ip} = [$location];
2658: }
2659: }
2660: }
2661: }
2662: }
2663: foreach my $ip (sort(keys(%{$by_ip}))) {
2664: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2665: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2666: my $first = $by_ip->{$ip}->[0];
2667: if (ref($by_location->{$first}) eq 'ARRAY') {
2668: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2669: push(@{$by_location->{$first}},$ip);
2670: }
2671: } else {
2672: $by_location->{$first} = [$ip];
2673: }
2674: }
2675: }
2676: return;
2677: }
2678:
1.145 raeburn 2679: sub current_offloads_to {
2680: my ($dom,$settings,$servers) = @_;
2681: my (%spareid,%otherdomconfigs);
1.152 raeburn 2682: if (ref($servers) eq 'HASH') {
1.145 raeburn 2683: foreach my $lonhost (sort(keys(%{$servers}))) {
2684: my $gotspares;
1.152 raeburn 2685: if (ref($settings) eq 'HASH') {
2686: if (ref($settings->{'spares'}) eq 'HASH') {
2687: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2688: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2689: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2690: $gotspares = 1;
2691: }
1.145 raeburn 2692: }
2693: }
2694: unless ($gotspares) {
2695: my $gotspares;
2696: my $serverhomeID =
2697: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2698: my $serverhomedom =
2699: &Apache::lonnet::host_domain($serverhomeID);
2700: if ($serverhomedom ne $dom) {
2701: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2702: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2703: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2704: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2705: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2706: $gotspares = 1;
2707: }
2708: }
2709: } else {
2710: $otherdomconfigs{$serverhomedom} =
2711: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2712: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2713: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2714: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2715: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2716: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2717: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2718: $gotspares = 1;
2719: }
2720: }
2721: }
2722: }
2723: }
2724: }
2725: }
2726: unless ($gotspares) {
2727: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2728: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2729: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2730: } else {
2731: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2732: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2733: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2734: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2735: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2736: } else {
1.150 raeburn 2737: my %what = (
2738: spareid => 1,
2739: );
2740: my ($result,$returnhash) =
2741: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2742: if ($result eq 'ok') {
2743: if (ref($returnhash) eq 'HASH') {
2744: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2745: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2746: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2747: }
2748: }
1.145 raeburn 2749: }
2750: }
2751: }
2752: }
2753: }
2754: }
2755: return %spareid;
2756: }
2757:
2758: sub spares_row {
1.152 raeburn 2759: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2760: my $css_class;
2761: my $numinrow = 4;
2762: my $itemcount = 1;
2763: my $datatable;
1.152 raeburn 2764: my %typetitles = &sparestype_titles();
2765: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2766: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2767: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2768: my ($othercontrol,$serverdom);
2769: if ($serverhome ne $server) {
2770: $serverdom = &Apache::lonnet::host_domain($serverhome);
2771: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2772: } else {
2773: $serverdom = &Apache::lonnet::host_domain($server);
2774: if ($serverdom ne $dom) {
2775: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2776: }
2777: }
2778: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2779: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2780: $datatable .= '<tr'.$css_class.'>
2781: <td rowspan="2">
1.160.6.13 raeburn 2782: <span class="LC_nobreak">'.
2783: &mt('[_1] when busy, offloads to:'
2784: ,'<b>'.$server.'</b>').
2785: "\n";
1.145 raeburn 2786: my (%current,%canselect);
1.152 raeburn 2787: my @choices =
2788: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2789: foreach my $type ('primary','default') {
2790: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2791: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2792: my @spares = @{$spareid->{$server}{$type}};
2793: if (@spares > 0) {
1.152 raeburn 2794: if ($othercontrol) {
2795: $current{$type} = join(', ',@spares);
2796: } else {
2797: $current{$type} .= '<table>';
2798: my $numspares = scalar(@spares);
2799: for (my $i=0; $i<@spares; $i++) {
2800: my $rem = $i%($numinrow);
2801: if ($rem == 0) {
2802: if ($i > 0) {
2803: $current{$type} .= '</tr>';
2804: }
2805: $current{$type} .= '<tr>';
1.145 raeburn 2806: }
1.152 raeburn 2807: $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'".');" /> '.
2808: $spareid->{$server}{$type}[$i].
2809: '</label></td>'."\n";
2810: }
2811: my $rem = @spares%($numinrow);
2812: my $colsleft = $numinrow - $rem;
2813: if ($colsleft > 1 ) {
2814: $current{$type} .= '<td colspan="'.$colsleft.
2815: '" class="LC_left_item">'.
2816: ' </td>';
2817: } elsif ($colsleft == 1) {
2818: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2819: }
1.152 raeburn 2820: $current{$type} .= '</tr></table>';
1.150 raeburn 2821: }
1.145 raeburn 2822: }
2823: }
2824: if ($current{$type} eq '') {
2825: $current{$type} = &mt('None specified');
2826: }
1.152 raeburn 2827: if ($othercontrol) {
2828: if ($type eq 'primary') {
2829: $canselect{$type} = $othercontrol;
2830: }
2831: } else {
2832: $canselect{$type} =
2833: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2834: '<select name="newspare_'.$type.'_'.$server.'" '.
2835: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2836: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2837: if (@choices > 0) {
2838: foreach my $lonhost (@choices) {
2839: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2840: }
2841: }
2842: $canselect{$type} .= '</select>'."\n";
2843: }
2844: } else {
2845: $current{$type} = &mt('Could not be determined');
2846: if ($type eq 'primary') {
2847: $canselect{$type} = $othercontrol;
2848: }
1.145 raeburn 2849: }
1.152 raeburn 2850: if ($type eq 'default') {
2851: $datatable .= '<tr'.$css_class.'>';
2852: }
2853: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2854: '<td>'.$current{$type}.'</td>'."\n".
2855: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2856: }
2857: $itemcount ++;
2858: }
2859: }
2860: $$rowtotal += $itemcount;
2861: return $datatable;
2862: }
2863:
1.152 raeburn 2864: sub possible_newspares {
2865: my ($server,$currspares,$serverhomes,$altids) = @_;
2866: my $serverhostname = &Apache::lonnet::hostname($server);
2867: my %excluded;
2868: if ($serverhostname ne '') {
2869: %excluded = (
2870: $serverhostname => 1,
2871: );
2872: }
2873: if (ref($currspares) eq 'HASH') {
2874: foreach my $type (keys(%{$currspares})) {
2875: if (ref($currspares->{$type}) eq 'ARRAY') {
2876: if (@{$currspares->{$type}} > 0) {
2877: foreach my $curr (@{$currspares->{$type}}) {
2878: my $hostname = &Apache::lonnet::hostname($curr);
2879: $excluded{$hostname} = 1;
2880: }
2881: }
2882: }
2883: }
2884: }
2885: my @choices;
2886: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2887: if (keys(%{$serverhomes}) > 1) {
2888: foreach my $name (sort(keys(%{$serverhomes}))) {
2889: unless ($excluded{$name}) {
2890: if (exists($altids->{$serverhomes->{$name}})) {
2891: push(@choices,$altids->{$serverhomes->{$name}});
2892: } else {
2893: push(@choices,$serverhomes->{$name});
1.145 raeburn 2894: }
2895: }
2896: }
2897: }
2898: }
1.152 raeburn 2899: return sort(@choices);
1.145 raeburn 2900: }
2901:
1.150 raeburn 2902: sub print_loadbalancing {
2903: my ($dom,$settings,$rowtotal) = @_;
2904: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2905: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2906: my $numinrow = 1;
2907: my $datatable;
2908: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2909: my (%currbalancer,%currtargets,%currrules,%existing);
2910: if (ref($settings) eq 'HASH') {
2911: %existing = %{$settings};
2912: }
2913: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2914: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2915: \%currtargets,\%currrules);
1.150 raeburn 2916: } else {
2917: return;
2918: }
2919: my ($othertitle,$usertypes,$types) =
2920: &Apache::loncommon::sorted_inst_types($dom);
2921: my $rownum = 6;
2922: if (ref($types) eq 'ARRAY') {
2923: $rownum += scalar(@{$types});
2924: }
1.160.6.7 raeburn 2925: my @css_class = ('LC_odd_row','LC_even_row');
2926: my $balnum = 0;
2927: my $islast;
2928: my (@toshow,$disabledtext);
2929: if (keys(%currbalancer) > 0) {
2930: @toshow = sort(keys(%currbalancer));
2931: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2932: push(@toshow,'');
2933: }
2934: } else {
2935: @toshow = ('');
2936: $disabledtext = &mt('No existing load balancer');
2937: }
2938: foreach my $lonhost (@toshow) {
2939: if ($balnum == scalar(@toshow)-1) {
2940: $islast = 1;
2941: } else {
2942: $islast = 0;
2943: }
2944: my $cssidx = $balnum%2;
2945: my $targets_div_style = 'display: none';
2946: my $disabled_div_style = 'display: block';
2947: my $homedom_div_style = 'display: none';
2948: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2949: '<td rowspan="'.$rownum.'" valign="top">'.
2950: '<p>';
2951: if ($lonhost eq '') {
2952: $datatable .= '<span class="LC_nobreak">';
2953: if (keys(%currbalancer) > 0) {
2954: $datatable .= &mt('Add balancer:');
2955: } else {
2956: $datatable .= &mt('Enable balancer:');
2957: }
2958: $datatable .= ' '.
2959: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2960: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2961: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2962: '<option value="" selected="selected">'.&mt('None').
2963: '</option>'."\n";
2964: foreach my $server (sort(keys(%servers))) {
2965: next if ($currbalancer{$server});
2966: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2967: }
2968: $datatable .=
2969: '</select>'."\n".
2970: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2971: } else {
2972: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2973: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2974: &mt('Stop balancing').'</label>'.
2975: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2976: $targets_div_style = 'display: block';
2977: $disabled_div_style = 'display: none';
2978: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2979: $homedom_div_style = 'display: block';
2980: }
2981: }
2982: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2983: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2984: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2985: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2986: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2987: my @sparestypes = ('primary','default');
2988: my %typetitles = &sparestype_titles();
2989: foreach my $sparetype (@sparestypes) {
2990: my $targettable;
2991: for (my $i=0; $i<$numspares; $i++) {
2992: my $checked;
2993: if (ref($currtargets{$lonhost}) eq 'HASH') {
2994: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
2995: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
2996: $checked = ' checked="checked"';
2997: }
2998: }
2999: }
3000: my ($chkboxval,$disabled);
3001: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3002: $chkboxval = $spares[$i];
3003: }
3004: if (exists($currbalancer{$spares[$i]})) {
3005: $disabled = ' disabled="disabled"';
3006: }
3007: $targettable .=
3008: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3009: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3010: '</span></label></td>';
3011: my $rem = $i%($numinrow);
3012: if ($rem == 0) {
3013: if (($i > 0) && ($i < $numspares-1)) {
3014: $targettable .= '</tr>';
3015: }
3016: if ($i < $numspares-1) {
3017: $targettable .= '<tr>';
1.150 raeburn 3018: }
3019: }
3020: }
1.160.6.7 raeburn 3021: if ($targettable ne '') {
3022: my $rem = $numspares%($numinrow);
3023: my $colsleft = $numinrow - $rem;
3024: if ($colsleft > 1 ) {
3025: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3026: ' </td>';
3027: } elsif ($colsleft == 1) {
3028: $targettable .= '<td class="LC_left_item"> </td>';
3029: }
3030: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3031: '<table><tr>'.$targettable.'</tr></table><br />';
3032: }
3033: }
3034: $datatable .= '</div></td></tr>'.
3035: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3036: $othertitle,$usertypes,$types,\%servers,
3037: \%currbalancer,$lonhost,
3038: $targets_div_style,$homedom_div_style,
3039: $css_class[$cssidx],$balnum,$islast);
3040: $$rowtotal += $rownum;
3041: $balnum ++;
3042: }
3043: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3044: return $datatable;
3045: }
3046:
3047: sub get_loadbalancers_config {
3048: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3049: return unless ((ref($servers) eq 'HASH') &&
3050: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3051: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3052: if (keys(%{$existing}) > 0) {
3053: my $oldlonhost;
3054: foreach my $key (sort(keys(%{$existing}))) {
3055: if ($key eq 'lonhost') {
3056: $oldlonhost = $existing->{'lonhost'};
3057: $currbalancer->{$oldlonhost} = 1;
3058: } elsif ($key eq 'targets') {
3059: if ($oldlonhost) {
3060: $currtargets->{$oldlonhost} = $existing->{'targets'};
3061: }
3062: } elsif ($key eq 'rules') {
3063: if ($oldlonhost) {
3064: $currrules->{$oldlonhost} = $existing->{'rules'};
3065: }
3066: } elsif (ref($existing->{$key}) eq 'HASH') {
3067: $currbalancer->{$key} = 1;
3068: $currtargets->{$key} = $existing->{$key}{'targets'};
3069: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3070: }
3071: }
1.160.6.7 raeburn 3072: } else {
3073: my ($balancerref,$targetsref) =
3074: &Apache::lonnet::get_lonbalancer_config($servers);
3075: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3076: foreach my $server (sort(keys(%{$balancerref}))) {
3077: $currbalancer->{$server} = 1;
3078: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3079: }
3080: }
3081: }
1.160.6.7 raeburn 3082: return;
1.150 raeburn 3083: }
3084:
3085: sub loadbalancing_rules {
3086: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3087: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3088: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3089: my $output;
1.160.6.7 raeburn 3090: my $num = 0;
3091: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3092: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3093: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3094: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3095: $num ++;
1.150 raeburn 3096: my $current;
3097: if (ref($currrules) eq 'HASH') {
3098: $current = $currrules->{$type};
3099: }
3100: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3101: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3102: $current = '';
3103: }
3104: }
3105: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3106: $servers,$currbalancer,$lonhost,$dom,
3107: $targets_div_style,$homedom_div_style,
3108: $css_class,$balnum,$num,$islast);
1.150 raeburn 3109: }
3110: }
3111: return $output;
3112: }
3113:
3114: sub loadbalancing_titles {
3115: my ($dom,$intdom,$usertypes,$types) = @_;
3116: my %othertypes = (
3117: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3118: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3119: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3120: '_LC_external' => &mt('Users not from [_1]',$intdom),
3121: );
3122: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3123: if (ref($types) eq 'ARRAY') {
3124: unshift(@alltypes,@{$types},'default');
3125: }
3126: my %titles;
3127: foreach my $type (@alltypes) {
3128: if ($type =~ /^_LC_/) {
3129: $titles{$type} = $othertypes{$type};
3130: } elsif ($type eq 'default') {
3131: $titles{$type} = &mt('All users from [_1]',$dom);
3132: if (ref($types) eq 'ARRAY') {
3133: if (@{$types} > 0) {
3134: $titles{$type} = &mt('Other users from [_1]',$dom);
3135: }
3136: }
3137: } elsif (ref($usertypes) eq 'HASH') {
3138: $titles{$type} = $usertypes->{$type};
3139: }
3140: }
3141: return (\@alltypes,\%othertypes,\%titles);
3142: }
3143:
3144: sub loadbalance_rule_row {
1.160.6.7 raeburn 3145: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3146: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3147: my @rulenames = ('default','homeserver');
3148: my %ruletitles = &offloadtype_text();
3149: if ($type eq '_LC_external') {
3150: push(@rulenames,'externalbalancer');
3151: } else {
3152: push(@rulenames,'specific');
3153: }
1.160.6.3 raeburn 3154: push(@rulenames,'none');
1.150 raeburn 3155: my $style = $targets_div_style;
3156: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3157: $style = $homedom_div_style;
3158: }
1.160.6.7 raeburn 3159: my $space;
3160: if ($islast && $num == 1) {
3161: $space = '<div display="inline-block"> </div>';
3162: }
3163: my $output =
3164: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3165: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3166: '<td valaign="top">'.$space.
3167: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3168: for (my $i=0; $i<@rulenames; $i++) {
3169: my $rule = $rulenames[$i];
3170: my ($checked,$extra);
3171: if ($rulenames[$i] eq 'default') {
3172: $rule = '';
3173: }
3174: if ($rulenames[$i] eq 'specific') {
3175: if (ref($servers) eq 'HASH') {
3176: my $default;
3177: if (($current ne '') && (exists($servers->{$current}))) {
3178: $checked = ' checked="checked"';
3179: }
3180: unless ($checked) {
3181: $default = ' selected="selected"';
3182: }
1.160.6.7 raeburn 3183: $extra =
3184: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3185: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3186: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3187: '<option value=""'.$default.'></option>'."\n";
3188: foreach my $server (sort(keys(%{$servers}))) {
3189: if (ref($currbalancer) eq 'HASH') {
3190: next if (exists($currbalancer->{$server}));
3191: }
1.150 raeburn 3192: my $selected;
1.160.6.7 raeburn 3193: if ($server eq $current) {
1.150 raeburn 3194: $selected = ' selected="selected"';
3195: }
1.160.6.7 raeburn 3196: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3197: }
3198: $extra .= '</select>';
3199: }
3200: } elsif ($rule eq $current) {
3201: $checked = ' checked="checked"';
3202: }
3203: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3204: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3205: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3206: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3207: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3208: '</label>'.$extra.'</span><br />'."\n";
3209: }
3210: $output .= '</div></td></tr>'."\n";
3211: return $output;
3212: }
3213:
3214: sub offloadtype_text {
3215: my %ruletitles = &Apache::lonlocal::texthash (
3216: 'default' => 'Offloads to default destinations',
3217: 'homeserver' => "Offloads to user's home server",
3218: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3219: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3220: 'none' => 'No offload',
1.150 raeburn 3221: );
3222: return %ruletitles;
3223: }
3224:
3225: sub sparestype_titles {
3226: my %typestitles = &Apache::lonlocal::texthash (
3227: 'primary' => 'primary',
3228: 'default' => 'default',
3229: );
3230: return %typestitles;
3231: }
3232:
1.28 raeburn 3233: sub contact_titles {
3234: my %titles = &Apache::lonlocal::texthash (
3235: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3236: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3237: 'errormail' => 'Error reports to be e-mailed to',
3238: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3239: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3240: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3241: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3242: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.28 raeburn 3243: );
3244: my %short_titles = &Apache::lonlocal::texthash (
3245: adminemail => 'Admin E-mail address',
3246: supportemail => 'Support E-mail',
3247: );
3248: return (\%titles,\%short_titles);
3249: }
3250:
1.72 raeburn 3251: sub tool_titles {
3252: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3253: aboutme => 'Personal web page',
1.86 raeburn 3254: blog => 'Blog',
1.160.6.4 raeburn 3255: webdav => 'WebDAV',
1.86 raeburn 3256: portfolio => 'Portfolio',
1.88 bisitz 3257: official => 'Official courses (with institutional codes)',
3258: unofficial => 'Unofficial courses',
1.98 raeburn 3259: community => 'Communities',
1.86 raeburn 3260: );
1.72 raeburn 3261: return %titles;
3262: }
3263:
1.101 raeburn 3264: sub courserequest_titles {
3265: my %titles = &Apache::lonlocal::texthash (
3266: official => 'Official',
3267: unofficial => 'Unofficial',
3268: community => 'Communities',
3269: norequest => 'Not allowed',
1.104 raeburn 3270: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3271: validate => 'With validation',
3272: autolimit => 'Numerical limit',
1.103 raeburn 3273: unlimited => '(blank for unlimited)',
1.101 raeburn 3274: );
3275: return %titles;
3276: }
3277:
1.160.6.5 raeburn 3278: sub authorrequest_titles {
3279: my %titles = &Apache::lonlocal::texthash (
3280: norequest => 'Not allowed',
3281: approval => 'Approval by Dom. Coord.',
3282: automatic => 'Automatic approval',
3283: );
3284: return %titles;
3285: }
3286:
1.101 raeburn 3287: sub courserequest_conditions {
3288: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3289: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3290: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3291: );
3292: return %conditions;
3293: }
3294:
3295:
1.27 raeburn 3296: sub print_usercreation {
1.30 raeburn 3297: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3298: my $numinrow = 4;
1.28 raeburn 3299: my $datatable;
3300: if ($position eq 'top') {
1.30 raeburn 3301: $$rowtotal ++;
1.34 raeburn 3302: my $rowcount = 0;
1.32 raeburn 3303: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3304: if (ref($rules) eq 'HASH') {
3305: if (keys(%{$rules}) > 0) {
1.32 raeburn 3306: $datatable .= &user_formats_row('username',$settings,$rules,
3307: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3308: $$rowtotal ++;
1.32 raeburn 3309: $rowcount ++;
3310: }
3311: }
3312: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3313: if (ref($idrules) eq 'HASH') {
3314: if (keys(%{$idrules}) > 0) {
3315: $datatable .= &user_formats_row('id',$settings,$idrules,
3316: $idruleorder,$numinrow,$rowcount);
3317: $$rowtotal ++;
3318: $rowcount ++;
1.28 raeburn 3319: }
3320: }
1.43 raeburn 3321: my ($emailrules,$emailruleorder) =
3322: &Apache::lonnet::inst_userrules($dom,'email');
3323: if (ref($emailrules) eq 'HASH') {
3324: if (keys(%{$emailrules}) > 0) {
3325: $datatable .= &user_formats_row('email',$settings,$emailrules,
3326: $emailruleorder,$numinrow,$rowcount);
3327: $$rowtotal ++;
3328: $rowcount ++;
3329: }
3330: }
1.39 raeburn 3331: if ($rowcount == 0) {
3332: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3333: $$rowtotal ++;
3334: $rowcount ++;
3335: }
1.34 raeburn 3336: } elsif ($position eq 'middle') {
1.100 raeburn 3337: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3338: my ($rules,$ruleorder) =
3339: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3340: my %lt = &usercreation_types();
3341: my %checked;
1.50 raeburn 3342: my @selfcreate;
1.34 raeburn 3343: if (ref($settings) eq 'HASH') {
3344: if (ref($settings->{'cancreate'}) eq 'HASH') {
3345: foreach my $item (@creators) {
3346: $checked{$item} = $settings->{'cancreate'}{$item};
3347: }
1.50 raeburn 3348: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3349: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3350: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3351: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3352: @selfcreate = ('email','login','sso');
3353: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3354: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3355: }
3356: }
1.34 raeburn 3357: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3358: foreach my $item (@creators) {
3359: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3360: $checked{$item} = 'none';
3361: }
3362: }
3363: }
3364: }
3365: my $rownum = 0;
3366: foreach my $item (@creators) {
3367: $rownum ++;
1.50 raeburn 3368: if ($item ne 'selfcreate') {
3369: if ($checked{$item} eq '') {
1.43 raeburn 3370: $checked{$item} = 'any';
3371: }
1.34 raeburn 3372: }
3373: my $css_class;
3374: if ($rownum%2) {
3375: $css_class = '';
3376: } else {
3377: $css_class = ' class="LC_odd_row" ';
3378: }
3379: $datatable .= '<tr'.$css_class.'>'.
3380: '<td><span class="LC_nobreak">'.$lt{$item}.
3381: '</span></td><td align="right">';
1.50 raeburn 3382: my @options;
1.45 raeburn 3383: if ($item eq 'selfcreate') {
1.43 raeburn 3384: push(@options,('email','login','sso'));
3385: } else {
1.50 raeburn 3386: @options = ('any');
1.43 raeburn 3387: if (ref($rules) eq 'HASH') {
3388: if (keys(%{$rules}) > 0) {
3389: push(@options,('official','unofficial'));
3390: }
1.37 raeburn 3391: }
1.50 raeburn 3392: push(@options,'none');
1.37 raeburn 3393: }
3394: foreach my $option (@options) {
1.50 raeburn 3395: my $type = 'radio';
1.34 raeburn 3396: my $check = ' ';
1.50 raeburn 3397: if ($item eq 'selfcreate') {
3398: $type = 'checkbox';
3399: if (grep(/^\Q$option\E$/,@selfcreate)) {
3400: $check = ' checked="checked" ';
3401: }
3402: } else {
3403: if ($checked{$item} eq $option) {
3404: $check = ' checked="checked" ';
3405: }
1.34 raeburn 3406: }
3407: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3408: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3409: $item.'" value="'.$option.'"'.$check.'/> '.
3410: $lt{$option}.'</label> </span>';
3411: }
3412: $datatable .= '</td></tr>';
3413: }
1.93 raeburn 3414: my ($othertitle,$usertypes,$types) =
3415: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3416: my $createsettings;
3417: if (ref($settings) eq 'HASH') {
3418: $createsettings = $settings->{cancreate};
3419: }
1.93 raeburn 3420: if (ref($usertypes) eq 'HASH') {
3421: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3422: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3423: $dom,$numinrow,$othertitle,
3424: 'statustocreate');
3425: $$rowtotal ++;
1.160.6.5 raeburn 3426: $rownum ++;
1.93 raeburn 3427: }
3428: }
1.160.6.5 raeburn 3429: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3430: } else {
3431: my @contexts = ('author','course','domain');
3432: my @authtypes = ('int','krb4','krb5','loc');
3433: my %checked;
3434: if (ref($settings) eq 'HASH') {
3435: if (ref($settings->{'authtypes'}) eq 'HASH') {
3436: foreach my $item (@contexts) {
3437: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3438: foreach my $auth (@authtypes) {
3439: if ($settings->{'authtypes'}{$item}{$auth}) {
3440: $checked{$item}{$auth} = ' checked="checked" ';
3441: }
3442: }
3443: }
3444: }
1.27 raeburn 3445: }
1.35 raeburn 3446: } else {
3447: foreach my $item (@contexts) {
1.36 raeburn 3448: foreach my $auth (@authtypes) {
1.35 raeburn 3449: $checked{$item}{$auth} = ' checked="checked" ';
3450: }
3451: }
1.27 raeburn 3452: }
1.28 raeburn 3453: my %title = &context_names();
3454: my %authname = &authtype_names();
3455: my $rownum = 0;
3456: my $css_class;
3457: foreach my $item (@contexts) {
3458: if ($rownum%2) {
3459: $css_class = '';
3460: } else {
3461: $css_class = ' class="LC_odd_row" ';
3462: }
1.30 raeburn 3463: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3464: '<td>'.$title{$item}.
3465: '</td><td class="LC_left_item">'.
3466: '<span class="LC_nobreak">';
3467: foreach my $auth (@authtypes) {
3468: $datatable .= '<label>'.
3469: '<input type="checkbox" name="'.$item.'_auth" '.
3470: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3471: $authname{$auth}.'</label> ';
3472: }
3473: $datatable .= '</span></td></tr>';
3474: $rownum ++;
1.27 raeburn 3475: }
1.30 raeburn 3476: $$rowtotal += $rownum;
1.27 raeburn 3477: }
3478: return $datatable;
3479: }
3480:
1.160.6.5 raeburn 3481: sub captcha_choice {
3482: my ($context,$settings,$itemcount) = @_;
3483: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3484: my %lt = &captcha_phrases();
3485: $keyentry = 'hidden';
3486: if ($context eq 'cancreate') {
3487: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3488: } elsif ($context eq 'login') {
3489: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3490: }
3491: if (ref($settings) eq 'HASH') {
3492: if ($settings->{'captcha'}) {
3493: $checked{$settings->{'captcha'}} = ' checked="checked"';
3494: } else {
3495: $checked{'original'} = ' checked="checked"';
3496: }
3497: if ($settings->{'captcha'} eq 'recaptcha') {
3498: $pubtext = $lt{'pub'};
3499: $privtext = $lt{'priv'};
3500: $keyentry = 'text';
3501: }
3502: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3503: $currpub = $settings->{'recaptchakeys'}{'public'};
3504: $currpriv = $settings->{'recaptchakeys'}{'private'};
3505: }
3506: } else {
3507: $checked{'original'} = ' checked="checked"';
3508: }
3509: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3510: my $output = '<tr'.$css_class.'>'.
3511: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3512: '<table><tr><td>'."\n";
3513: foreach my $option ('original','recaptcha','notused') {
3514: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3515: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3516: $lt{$option}.'</label></span>';
3517: unless ($option eq 'notused') {
3518: $output .= (' 'x2)."\n";
3519: }
3520: }
3521: #
3522: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3523: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3524: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3525: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3526: #
3527: $output .= '</td></tr>'."\n".
3528: '<tr><td>'."\n".
3529: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3530: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3531: $currpub.'" size="40" /></span><br />'."\n".
3532: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3533: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3534: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3535: '</td></tr>';
3536: return $output;
3537: }
3538:
1.32 raeburn 3539: sub user_formats_row {
3540: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3541: my $output;
3542: my %text = (
3543: 'username' => 'new usernames',
3544: 'id' => 'IDs',
1.45 raeburn 3545: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3546: );
3547: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3548: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3549: '<td><span class="LC_nobreak">';
3550: if ($type eq 'email') {
3551: $output .= &mt("Formats disallowed for $text{$type}: ");
3552: } else {
3553: $output .= &mt("Format rules to check for $text{$type}: ");
3554: }
3555: $output .= '</span></td>'.
3556: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3557: my $rem;
3558: if (ref($ruleorder) eq 'ARRAY') {
3559: for (my $i=0; $i<@{$ruleorder}; $i++) {
3560: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3561: my $rem = $i%($numinrow);
3562: if ($rem == 0) {
3563: if ($i > 0) {
3564: $output .= '</tr>';
3565: }
3566: $output .= '<tr>';
3567: }
3568: my $check = ' ';
1.39 raeburn 3569: if (ref($settings) eq 'HASH') {
3570: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3571: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3572: $check = ' checked="checked" ';
3573: }
1.27 raeburn 3574: }
3575: }
3576: $output .= '<td class="LC_left_item">'.
3577: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3578: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3579: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3580: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3581: }
3582: }
3583: $rem = @{$ruleorder}%($numinrow);
3584: }
3585: my $colsleft = $numinrow - $rem;
3586: if ($colsleft > 1 ) {
3587: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3588: ' </td>';
3589: } elsif ($colsleft == 1) {
3590: $output .= '<td class="LC_left_item"> </td>';
3591: }
3592: $output .= '</tr></table></td></tr>';
3593: return $output;
3594: }
3595:
1.34 raeburn 3596: sub usercreation_types {
3597: my %lt = &Apache::lonlocal::texthash (
3598: author => 'When adding a co-author',
3599: course => 'When adding a user to a course',
1.100 raeburn 3600: requestcrs => 'When requesting a course',
1.45 raeburn 3601: selfcreate => 'User creates own account',
1.34 raeburn 3602: any => 'Any',
3603: official => 'Institutional only ',
3604: unofficial => 'Non-institutional only',
1.85 schafran 3605: email => 'E-mail address',
1.43 raeburn 3606: login => 'Institutional Login',
3607: sso => 'SSO',
1.34 raeburn 3608: none => 'None',
3609: );
3610: return %lt;
1.48 raeburn 3611: }
1.34 raeburn 3612:
1.28 raeburn 3613: sub authtype_names {
3614: my %lt = &Apache::lonlocal::texthash(
3615: int => 'Internal',
3616: krb4 => 'Kerberos 4',
3617: krb5 => 'Kerberos 5',
3618: loc => 'Local',
3619: );
3620: return %lt;
3621: }
3622:
3623: sub context_names {
3624: my %context_title = &Apache::lonlocal::texthash(
3625: author => 'Creating users when an Author',
3626: course => 'Creating users when in a course',
3627: domain => 'Creating users when a Domain Coordinator',
3628: );
3629: return %context_title;
3630: }
3631:
1.33 raeburn 3632: sub print_usermodification {
3633: my ($position,$dom,$settings,$rowtotal) = @_;
3634: my $numinrow = 4;
3635: my ($context,$datatable,$rowcount);
3636: if ($position eq 'top') {
3637: $rowcount = 0;
3638: $context = 'author';
3639: foreach my $role ('ca','aa') {
3640: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3641: $numinrow,$rowcount);
3642: $$rowtotal ++;
3643: $rowcount ++;
3644: }
1.63 raeburn 3645: } elsif ($position eq 'middle') {
1.33 raeburn 3646: $context = 'course';
3647: $rowcount = 0;
3648: foreach my $role ('st','ep','ta','in','cr') {
3649: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3650: $numinrow,$rowcount);
3651: $$rowtotal ++;
3652: $rowcount ++;
3653: }
1.63 raeburn 3654: } elsif ($position eq 'bottom') {
3655: $context = 'selfcreate';
3656: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3657: $usertypes->{'default'} = $othertitle;
3658: if (ref($types) eq 'ARRAY') {
3659: push(@{$types},'default');
3660: $usertypes->{'default'} = $othertitle;
3661: foreach my $status (@{$types}) {
3662: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3663: $numinrow,$rowcount,$usertypes);
3664: $$rowtotal ++;
3665: $rowcount ++;
3666: }
3667: }
1.33 raeburn 3668: }
3669: return $datatable;
3670: }
3671:
1.43 raeburn 3672: sub print_defaults {
3673: my ($dom,$rowtotal) = @_;
1.68 raeburn 3674: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3675: 'datelocale_def','portal_def');
1.43 raeburn 3676: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3677: my $titles = &defaults_titles($dom);
1.43 raeburn 3678: my $rownum = 0;
3679: my ($datatable,$css_class);
3680: foreach my $item (@items) {
3681: if ($rownum%2) {
3682: $css_class = '';
3683: } else {
3684: $css_class = ' class="LC_odd_row" ';
3685: }
3686: $datatable .= '<tr'.$css_class.'>'.
3687: '<td><span class="LC_nobreak">'.$titles->{$item}.
3688: '</span></td><td class="LC_right_item">';
3689: if ($item eq 'auth_def') {
3690: my @authtypes = ('internal','krb4','krb5','localauth');
3691: my %shortauth = (
3692: internal => 'int',
3693: krb4 => 'krb4',
3694: krb5 => 'krb5',
3695: localauth => 'loc'
3696: );
3697: my %authnames = &authtype_names();
3698: foreach my $auth (@authtypes) {
3699: my $checked = ' ';
3700: if ($domdefaults{$item} eq $auth) {
3701: $checked = ' checked="checked" ';
3702: }
3703: $datatable .= '<label><input type="radio" name="'.$item.
3704: '" value="'.$auth.'"'.$checked.'/>'.
3705: $authnames{$shortauth{$auth}}.'</label> ';
3706: }
1.54 raeburn 3707: } elsif ($item eq 'timezone_def') {
3708: my $includeempty = 1;
3709: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3710: } elsif ($item eq 'datelocale_def') {
3711: my $includeempty = 1;
3712: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3713: } elsif ($item eq 'lang_def') {
3714: my %langchoices = &get_languages_hash();
3715: $langchoices{''} = 'No language preference';
3716: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3717: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3718: \%langchoices);
1.43 raeburn 3719: } else {
1.141 raeburn 3720: my $size;
3721: if ($item eq 'portal_def') {
3722: $size = ' size="25"';
3723: }
1.43 raeburn 3724: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3725: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3726: }
3727: $datatable .= '</td></tr>';
3728: $rownum ++;
3729: }
3730: $$rowtotal += $rownum;
3731: return $datatable;
3732: }
3733:
1.160.6.5 raeburn 3734: sub get_languages_hash {
3735: my %langchoices;
3736: foreach my $id (&Apache::loncommon::languageids()) {
3737: my $code = &Apache::loncommon::supportedlanguagecode($id);
3738: if ($code ne '') {
3739: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3740: }
3741: }
3742: return %langchoices;
3743: }
3744:
1.43 raeburn 3745: sub defaults_titles {
1.141 raeburn 3746: my ($dom) = @_;
1.43 raeburn 3747: my %titles = &Apache::lonlocal::texthash (
3748: 'auth_def' => 'Default authentication type',
3749: 'auth_arg_def' => 'Default authentication argument',
3750: 'lang_def' => 'Default language',
1.54 raeburn 3751: 'timezone_def' => 'Default timezone',
1.68 raeburn 3752: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3753: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3754: );
1.141 raeburn 3755: if ($dom) {
3756: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3757: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3758: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3759: $protocol = 'http' if ($protocol ne 'https');
3760: if ($uint_dom) {
3761: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3762: $uint_dom);
3763: }
3764: }
1.43 raeburn 3765: return (\%titles);
3766: }
3767:
1.46 raeburn 3768: sub print_scantronformat {
3769: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3770: my $itemcount = 1;
1.60 raeburn 3771: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3772: %confhash);
1.46 raeburn 3773: my $switchserver = &check_switchserver($dom,$confname);
3774: my %lt = &Apache::lonlocal::texthash (
1.95 www 3775: default => 'Default bubblesheet format file error',
3776: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3777: );
3778: my %scantronfiles = (
3779: default => 'default.tab',
3780: custom => 'custom.tab',
3781: );
3782: foreach my $key (keys(%scantronfiles)) {
3783: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3784: .$scantronfiles{$key};
3785: }
3786: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3787: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3788: if (!$switchserver) {
3789: my $servadm = $r->dir_config('lonAdmEMail');
3790: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3791: if ($configuserok eq 'ok') {
3792: if ($author_ok eq 'ok') {
3793: my %legacyfile = (
3794: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3795: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3796: );
3797: my %md5chk;
3798: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3799: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3800: chomp($md5chk{$type});
1.46 raeburn 3801: }
3802: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3803: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3804: ($scantronurls{$type},my $error) =
1.46 raeburn 3805: &legacy_scantronformat($r,$dom,$confname,
3806: $type,$legacyfile{$type},
3807: $scantronurls{$type},
3808: $scantronfiles{$type});
1.60 raeburn 3809: if ($error ne '') {
3810: $error{$type} = $error;
3811: }
3812: }
3813: if (keys(%error) == 0) {
3814: $is_custom = 1;
3815: $confhash{'scantron'}{'scantronformat'} =
3816: $scantronurls{'custom'};
3817: my $putresult =
3818: &Apache::lonnet::put_dom('configuration',
3819: \%confhash,$dom);
3820: if ($putresult ne 'ok') {
3821: $error{'custom'} =
3822: '<span class="LC_error">'.
3823: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3824: }
1.46 raeburn 3825: }
3826: } else {
1.60 raeburn 3827: ($scantronurls{'default'},my $error) =
1.46 raeburn 3828: &legacy_scantronformat($r,$dom,$confname,
3829: 'default',$legacyfile{'default'},
3830: $scantronurls{'default'},
3831: $scantronfiles{'default'});
1.60 raeburn 3832: if ($error eq '') {
3833: $confhash{'scantron'}{'scantronformat'} = '';
3834: my $putresult =
3835: &Apache::lonnet::put_dom('configuration',
3836: \%confhash,$dom);
3837: if ($putresult ne 'ok') {
3838: $error{'default'} =
3839: '<span class="LC_error">'.
3840: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3841: }
3842: } else {
3843: $error{'default'} = $error;
3844: }
1.46 raeburn 3845: }
3846: }
3847: }
3848: } else {
1.95 www 3849: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3850: }
3851: }
3852: if (ref($settings) eq 'HASH') {
3853: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3854: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3855: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3856: $scantronurl = '';
3857: } else {
3858: $scantronurl = $settings->{'scantronformat'};
3859: }
3860: $is_custom = 1;
3861: } else {
3862: $scantronurl = $scantronurls{'default'};
3863: }
3864: } else {
1.60 raeburn 3865: if ($is_custom) {
3866: $scantronurl = $scantronurls{'custom'};
3867: } else {
3868: $scantronurl = $scantronurls{'default'};
3869: }
1.46 raeburn 3870: }
3871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3872: $datatable .= '<tr'.$css_class.'>';
3873: if (!$is_custom) {
1.65 raeburn 3874: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3875: '<span class="LC_nobreak">';
1.46 raeburn 3876: if ($scantronurl) {
3877: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3878: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3879: } else {
3880: $datatable = &mt('File unavailable for display');
3881: }
1.65 raeburn 3882: $datatable .= '</span></td>';
1.60 raeburn 3883: if (keys(%error) == 0) {
3884: $datatable .= '<td valign="bottom">';
3885: if (!$switchserver) {
3886: $datatable .= &mt('Upload:').'<br />';
3887: }
3888: } else {
3889: my $errorstr;
3890: foreach my $key (sort(keys(%error))) {
3891: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3892: }
3893: $datatable .= '<td>'.$errorstr;
3894: }
1.46 raeburn 3895: } else {
3896: if (keys(%error) > 0) {
3897: my $errorstr;
3898: foreach my $key (sort(keys(%error))) {
3899: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3900: }
1.60 raeburn 3901: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3902: } elsif ($scantronurl) {
1.65 raeburn 3903: $datatable .= '<td><span class="LC_nobreak">'.
3904: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3905: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3906: '<input type="checkbox" name="scantronformat_del"'.
3907: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3908: '<td><span class="LC_nobreak"> '.
3909: &mt('Replace:').'</span><br />';
1.46 raeburn 3910: }
3911: }
3912: if (keys(%error) == 0) {
3913: if ($switchserver) {
3914: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3915: } else {
1.65 raeburn 3916: $datatable .='<span class="LC_nobreak"> '.
3917: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3918: }
3919: }
3920: $datatable .= '</td></tr>';
3921: $$rowtotal ++;
3922: return $datatable;
3923: }
3924:
3925: sub legacy_scantronformat {
3926: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3927: my ($url,$error);
3928: my @statinfo = &Apache::lonnet::stat_file($newurl);
3929: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3930: (my $result,$url) =
3931: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3932: '','',$newfile);
3933: if ($result ne 'ok') {
1.130 raeburn 3934: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3935: }
3936: }
3937: return ($url,$error);
3938: }
1.43 raeburn 3939:
1.49 raeburn 3940: sub print_coursecategories {
1.57 raeburn 3941: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3942: my $datatable;
3943: if ($position eq 'top') {
3944: my $toggle_cats_crs = ' ';
3945: my $toggle_cats_dom = ' checked="checked" ';
3946: my $can_cat_crs = ' ';
3947: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3948: my $toggle_catscomm_comm = ' ';
3949: my $toggle_catscomm_dom = ' checked="checked" ';
3950: my $can_catcomm_comm = ' ';
3951: my $can_catcomm_dom = ' checked="checked" ';
3952:
1.57 raeburn 3953: if (ref($settings) eq 'HASH') {
3954: if ($settings->{'togglecats'} eq 'crs') {
3955: $toggle_cats_crs = $toggle_cats_dom;
3956: $toggle_cats_dom = ' ';
3957: }
3958: if ($settings->{'categorize'} eq 'crs') {
3959: $can_cat_crs = $can_cat_dom;
3960: $can_cat_dom = ' ';
3961: }
1.120 raeburn 3962: if ($settings->{'togglecatscomm'} eq 'comm') {
3963: $toggle_catscomm_comm = $toggle_catscomm_dom;
3964: $toggle_catscomm_dom = ' ';
3965: }
3966: if ($settings->{'categorizecomm'} eq 'comm') {
3967: $can_catcomm_comm = $can_catcomm_dom;
3968: $can_catcomm_dom = ' ';
3969: }
1.57 raeburn 3970: }
3971: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3972: togglecats => 'Show/Hide a course in catalog',
3973: togglecatscomm => 'Show/Hide a community in catalog',
3974: categorize => 'Assign a category to a course',
3975: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3976: );
3977: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3978: dom => 'Set in Domain',
3979: crs => 'Set in Course',
3980: comm => 'Set in Community',
1.57 raeburn 3981: );
3982: $datatable = '<tr class="LC_odd_row">'.
3983: '<td>'.$title{'togglecats'}.'</td>'.
3984: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3985: '<input type="radio" name="togglecats"'.
3986: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3987: '<label><input type="radio" name="togglecats"'.
3988: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3989: '</tr><tr>'.
3990: '<td>'.$title{'categorize'}.'</td>'.
3991: '<td class="LC_right_item"><span class="LC_nobreak">'.
3992: '<label><input type="radio" name="categorize"'.
3993: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3994: '<label><input type="radio" name="categorize"'.
3995: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3996: '</tr><tr class="LC_odd_row">'.
3997: '<td>'.$title{'togglecatscomm'}.'</td>'.
3998: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3999: '<input type="radio" name="togglecatscomm"'.
4000: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4001: '<label><input type="radio" name="togglecatscomm"'.
4002: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4003: '</tr><tr>'.
4004: '<td>'.$title{'categorizecomm'}.'</td>'.
4005: '<td class="LC_right_item"><span class="LC_nobreak">'.
4006: '<label><input type="radio" name="categorizecomm"'.
4007: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4008: '<label><input type="radio" name="categorizecomm"'.
4009: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4010: '</tr>';
1.120 raeburn 4011: $$rowtotal += 4;
1.57 raeburn 4012: } else {
4013: my $css_class;
4014: my $itemcount = 1;
4015: my $cathash;
4016: if (ref($settings) eq 'HASH') {
4017: $cathash = $settings->{'cats'};
4018: }
4019: if (ref($cathash) eq 'HASH') {
4020: my (@cats,@trails,%allitems,%idx,@jsarray);
4021: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4022: \%allitems,\%idx,\@jsarray);
4023: my $maxdepth = scalar(@cats);
4024: my $colattrib = '';
4025: if ($maxdepth > 2) {
4026: $colattrib = ' colspan="2" ';
4027: }
4028: my @path;
4029: if (@cats > 0) {
4030: if (ref($cats[0]) eq 'ARRAY') {
4031: my $numtop = @{$cats[0]};
4032: my $maxnum = $numtop;
1.120 raeburn 4033: my %default_names = (
4034: instcode => &mt('Official courses'),
4035: communities => &mt('Communities'),
4036: );
4037:
4038: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4039: ($cathash->{'instcode::0'} eq '') ||
4040: (!grep(/^communities$/,@{$cats[0]})) ||
4041: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4042: $maxnum ++;
4043: }
4044: my $lastidx;
4045: for (my $i=0; $i<$numtop; $i++) {
4046: my $parent = $cats[0][$i];
4047: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4048: my $item = &escape($parent).'::0';
4049: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4050: $lastidx = $idx{$item};
4051: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4052: .'<select name="'.$item.'"'.$chgstr.'>';
4053: for (my $k=0; $k<=$maxnum; $k++) {
4054: my $vpos = $k+1;
4055: my $selstr;
4056: if ($k == $i) {
4057: $selstr = ' selected="selected" ';
4058: }
4059: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4060: }
4061: $datatable .= '</select></td><td>';
1.120 raeburn 4062: if ($parent eq 'instcode' || $parent eq 'communities') {
4063: $datatable .= '<span class="LC_nobreak">'
4064: .$default_names{$parent}.'</span>';
4065: if ($parent eq 'instcode') {
4066: $datatable .= '<br /><span class="LC_nobreak">('
4067: .&mt('with institutional codes')
4068: .')</span></td><td'.$colattrib.'>';
4069: } else {
4070: $datatable .= '<table><tr><td>';
4071: }
4072: $datatable .= '<span class="LC_nobreak">'
4073: .'<label><input type="radio" name="'
4074: .$parent.'" value="1" checked="checked" />'
4075: .&mt('Display').'</label>';
4076: if ($parent eq 'instcode') {
4077: $datatable .= ' ';
4078: } else {
4079: $datatable .= '</span></td></tr><tr><td>'
4080: .'<span class="LC_nobreak">';
4081: }
4082: $datatable .= '<label><input type="radio" name="'
4083: .$parent.'" value="0" />'
4084: .&mt('Do not display').'</label></span>';
4085: if ($parent eq 'communities') {
4086: $datatable .= '</td></tr></table>';
4087: }
4088: $datatable .= '</td>';
1.57 raeburn 4089: } else {
4090: $datatable .= $parent
4091: .' <label><input type="checkbox" name="deletecategory" '
4092: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4093: }
4094: my $depth = 1;
4095: push(@path,$parent);
4096: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4097: pop(@path);
4098: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4099: $itemcount ++;
4100: }
1.48 raeburn 4101: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4102: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4103: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4104: for (my $k=0; $k<=$maxnum; $k++) {
4105: my $vpos = $k+1;
4106: my $selstr;
1.57 raeburn 4107: if ($k == $numtop) {
1.48 raeburn 4108: $selstr = ' selected="selected" ';
4109: }
4110: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4111: }
1.59 bisitz 4112: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4113: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4114: .'</tr>'."\n";
1.48 raeburn 4115: $itemcount ++;
1.120 raeburn 4116: foreach my $default ('instcode','communities') {
4117: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4118: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4119: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4120: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4121: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4122: for (my $k=0; $k<=$maxnum; $k++) {
4123: my $vpos = $k+1;
4124: my $selstr;
4125: if ($k == $maxnum) {
4126: $selstr = ' selected="selected" ';
4127: }
4128: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4129: }
1.120 raeburn 4130: $datatable .= '</select></span></td>'.
4131: '<td><span class="LC_nobreak">'.
4132: $default_names{$default}.'</span>';
4133: if ($default eq 'instcode') {
4134: $datatable .= '<br /><span class="LC_nobreak">('
4135: .&mt('with institutional codes').')</span>';
4136: }
4137: $datatable .= '</td>'
4138: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4139: .&mt('Display').'</label> '
4140: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4141: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4142: }
4143: }
4144: }
1.57 raeburn 4145: } else {
4146: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4147: }
4148: } else {
1.57 raeburn 4149: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4150: .&initialize_categories($itemcount);
1.48 raeburn 4151: }
1.57 raeburn 4152: $$rowtotal += $itemcount;
1.48 raeburn 4153: }
4154: return $datatable;
4155: }
4156:
1.69 raeburn 4157: sub print_serverstatuses {
4158: my ($dom,$settings,$rowtotal) = @_;
4159: my $datatable;
4160: my @pages = &serverstatus_pages();
4161: my (%namedaccess,%machineaccess);
4162: foreach my $type (@pages) {
4163: $namedaccess{$type} = '';
4164: $machineaccess{$type}= '';
4165: }
4166: if (ref($settings) eq 'HASH') {
4167: foreach my $type (@pages) {
4168: if (exists($settings->{$type})) {
4169: if (ref($settings->{$type}) eq 'HASH') {
4170: foreach my $key (keys(%{$settings->{$type}})) {
4171: if ($key eq 'namedusers') {
4172: $namedaccess{$type} = $settings->{$type}->{$key};
4173: } elsif ($key eq 'machines') {
4174: $machineaccess{$type} = $settings->{$type}->{$key};
4175: }
4176: }
4177: }
4178: }
4179: }
4180: }
1.81 raeburn 4181: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4182: my $rownum = 0;
4183: my $css_class;
4184: foreach my $type (@pages) {
4185: $rownum ++;
4186: $css_class = $rownum%2?' class="LC_odd_row"':'';
4187: $datatable .= '<tr'.$css_class.'>'.
4188: '<td><span class="LC_nobreak">'.
4189: $titles->{$type}.'</span></td>'.
4190: '<td class="LC_left_item">'.
4191: '<input type="text" name="'.$type.'_namedusers" '.
4192: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4193: '<td class="LC_right_item">'.
4194: '<span class="LC_nobreak">'.
4195: '<input type="text" name="'.$type.'_machines" '.
4196: 'value="'.$machineaccess{$type}.'" size="10" />'.
4197: '</td></tr>'."\n";
4198: }
4199: $$rowtotal += $rownum;
4200: return $datatable;
4201: }
4202:
4203: sub serverstatus_pages {
4204: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4205: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4206: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4207: }
4208:
1.49 raeburn 4209: sub coursecategories_javascript {
4210: my ($settings) = @_;
1.57 raeburn 4211: my ($output,$jstext,$cathash);
1.49 raeburn 4212: if (ref($settings) eq 'HASH') {
1.57 raeburn 4213: $cathash = $settings->{'cats'};
4214: }
4215: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4216: my (@cats,@jsarray,%idx);
1.57 raeburn 4217: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4218: if (@jsarray > 0) {
4219: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4220: for (my $i=0; $i<@jsarray; $i++) {
4221: if (ref($jsarray[$i]) eq 'ARRAY') {
4222: my $catstr = join('","',@{$jsarray[$i]});
4223: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4224: }
4225: }
4226: }
4227: } else {
4228: $jstext = ' var categories = Array(1);'."\n".
4229: ' categories[0] = Array("instcode_pos");'."\n";
4230: }
1.120 raeburn 4231: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4232: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4233: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4234: $output = <<"ENDSCRIPT";
4235: <script type="text/javascript">
1.109 raeburn 4236: // <![CDATA[
1.49 raeburn 4237: function reorderCats(form,parent,item,idx) {
4238: var changedVal;
4239: $jstext
4240: var newpos = 'addcategory_pos';
4241: var current = new Array;
4242: if (parent == '') {
4243: var has_instcode = 0;
4244: var maxtop = categories[idx].length;
4245: for (var j=0; j<maxtop; j++) {
4246: if (categories[idx][j] == 'instcode::0') {
4247: has_instcode == 1;
4248: }
4249: }
4250: if (has_instcode == 0) {
4251: categories[idx][maxtop] = 'instcode_pos';
4252: }
4253: } else {
4254: newpos += '_'+parent;
4255: }
4256: var maxh = 1 + categories[idx].length;
4257: var current = new Array;
4258: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4259: if (item == newpos) {
4260: changedVal = newitemVal;
4261: } else {
4262: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4263: current[newitemVal] = newpos;
4264: }
4265: for (var i=0; i<categories[idx].length; i++) {
4266: var elementName = categories[idx][i];
4267: if (elementName != item) {
4268: if (form.elements[elementName]) {
4269: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4270: current[currVal] = elementName;
4271: }
4272: }
4273: }
4274: var oldVal;
4275: for (var j=0; j<maxh; j++) {
4276: if (current[j] == undefined) {
4277: oldVal = j;
4278: }
4279: }
4280: if (oldVal < changedVal) {
4281: for (var k=oldVal+1; k<=changedVal ; k++) {
4282: var elementName = current[k];
4283: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4284: }
4285: } else {
4286: for (var k=changedVal; k<oldVal; k++) {
4287: var elementName = current[k];
4288: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4289: }
4290: }
4291: return;
4292: }
1.120 raeburn 4293:
4294: function categoryCheck(form) {
4295: if (form.elements['addcategory_name'].value == 'instcode') {
4296: alert('$instcode_reserved\\n$choose_again');
4297: return false;
4298: }
4299: if (form.elements['addcategory_name'].value == 'communities') {
4300: alert('$communities_reserved\\n$choose_again');
4301: return false;
4302: }
4303: return true;
4304: }
4305:
1.109 raeburn 4306: // ]]>
1.49 raeburn 4307: </script>
4308:
4309: ENDSCRIPT
4310: return $output;
4311: }
4312:
1.48 raeburn 4313: sub initialize_categories {
4314: my ($itemcount) = @_;
1.120 raeburn 4315: my ($datatable,$css_class,$chgstr);
4316: my %default_names = (
4317: instcode => 'Official courses (with institutional codes)',
4318: communities => 'Communities',
4319: );
4320: my $select0 = ' selected="selected"';
4321: my $select1 = '';
4322: foreach my $default ('instcode','communities') {
4323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4324: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4325: if ($default eq 'communities') {
4326: $select1 = $select0;
4327: $select0 = '';
4328: }
4329: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4330: .'<select name="'.$default.'_pos">'
4331: .'<option value="0"'.$select0.'>1</option>'
4332: .'<option value="1"'.$select1.'>2</option>'
4333: .'<option value="2">3</option></select> '
4334: .$default_names{$default}
4335: .'</span></td><td><span class="LC_nobreak">'
4336: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4337: .&mt('Display').'</label> <label>'
4338: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4339: .'</label></span></td></tr>';
1.120 raeburn 4340: $itemcount ++;
4341: }
1.48 raeburn 4342: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4343: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4344: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4345: .'<select name="addcategory_pos"'.$chgstr.'>'
4346: .'<option value="0">1</option>'
4347: .'<option value="1">2</option>'
4348: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4349: .&mt('Add category').'</td><td>'.&mt('Name:')
4350: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4351: return $datatable;
4352: }
4353:
4354: sub build_category_rows {
1.49 raeburn 4355: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4356: my ($text,$name,$item,$chgstr);
1.48 raeburn 4357: if (ref($cats) eq 'ARRAY') {
4358: my $maxdepth = scalar(@{$cats});
4359: if (ref($cats->[$depth]) eq 'HASH') {
4360: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4361: my $numchildren = @{$cats->[$depth]{$parent}};
4362: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4363: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4364: my ($idxnum,$parent_name,$parent_item);
4365: my $higher = $depth - 1;
4366: if ($higher == 0) {
4367: $parent_name = &escape($parent).'::'.$higher;
4368: } else {
4369: if (ref($path) eq 'ARRAY') {
4370: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4371: }
4372: }
4373: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4374: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4375: if ($j < $numchildren) {
1.48 raeburn 4376: $name = $cats->[$depth]{$parent}[$j];
4377: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4378: $idxnum = $idx->{$item};
4379: } else {
4380: $name = $parent_name;
4381: $item = $parent_item;
1.48 raeburn 4382: }
1.49 raeburn 4383: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4384: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4385: for (my $i=0; $i<=$numchildren; $i++) {
4386: my $vpos = $i+1;
4387: my $selstr;
4388: if ($j == $i) {
4389: $selstr = ' selected="selected" ';
4390: }
4391: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4392: }
4393: $text .= '</select> ';
4394: if ($j < $numchildren) {
4395: my $deeper = $depth+1;
4396: $text .= $name.' '
4397: .'<label><input type="checkbox" name="deletecategory" value="'
4398: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4399: if(ref($path) eq 'ARRAY') {
4400: push(@{$path},$name);
1.49 raeburn 4401: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4402: pop(@{$path});
4403: }
4404: } else {
1.59 bisitz 4405: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4406: if ($j == $numchildren) {
4407: $text .= $name;
4408: } else {
4409: $text .= $item;
4410: }
4411: $text .= '" value="" />';
4412: }
4413: $text .= '</td></tr>';
4414: }
4415: $text .= '</table></td>';
4416: } else {
4417: my $higher = $depth-1;
4418: if ($higher == 0) {
4419: $name = &escape($parent).'::'.$higher;
4420: } else {
4421: if (ref($path) eq 'ARRAY') {
4422: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4423: }
4424: }
4425: my $colspan;
4426: if ($parent ne 'instcode') {
4427: $colspan = $maxdepth - $depth - 1;
4428: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4429: }
4430: }
4431: }
4432: }
4433: return $text;
4434: }
4435:
1.33 raeburn 4436: sub modifiable_userdata_row {
1.63 raeburn 4437: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4438: my $rolename;
1.63 raeburn 4439: if ($context eq 'selfcreate') {
4440: if (ref($usertypes) eq 'HASH') {
4441: $rolename = $usertypes->{$role};
4442: } else {
4443: $rolename = $role;
4444: }
1.33 raeburn 4445: } else {
1.63 raeburn 4446: if ($role eq 'cr') {
4447: $rolename = &mt('Custom role');
4448: } else {
4449: $rolename = &Apache::lonnet::plaintext($role);
4450: }
1.33 raeburn 4451: }
4452: my @fields = ('lastname','firstname','middlename','generation',
4453: 'permanentemail','id');
4454: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4455: my $output;
4456: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4457: $output = '<tr '.$css_class.'>'.
4458: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4459: '<td class="LC_left_item" colspan="2"><table>';
4460: my $rem;
4461: my %checks;
4462: if (ref($settings) eq 'HASH') {
4463: if (ref($settings->{$context}) eq 'HASH') {
4464: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4465: foreach my $field (@fields) {
4466: if ($settings->{$context}->{$role}->{$field}) {
4467: $checks{$field} = ' checked="checked" ';
4468: }
4469: }
4470: }
4471: }
4472: }
4473: for (my $i=0; $i<@fields; $i++) {
4474: my $rem = $i%($numinrow);
4475: if ($rem == 0) {
4476: if ($i > 0) {
4477: $output .= '</tr>';
4478: }
4479: $output .= '<tr>';
4480: }
4481: my $check = ' ';
4482: if (exists($checks{$fields[$i]})) {
4483: $check = $checks{$fields[$i]}
4484: } else {
4485: if ($role eq 'st') {
4486: if (ref($settings) ne 'HASH') {
4487: $check = ' checked="checked" ';
4488: }
4489: }
4490: }
4491: $output .= '<td class="LC_left_item">'.
4492: '<span class="LC_nobreak"><label>'.
4493: '<input type="checkbox" name="canmodify_'.$role.'" '.
4494: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4495: '</label></span></td>';
4496: $rem = @fields%($numinrow);
4497: }
4498: my $colsleft = $numinrow - $rem;
4499: if ($colsleft > 1 ) {
4500: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4501: ' </td>';
4502: } elsif ($colsleft == 1) {
4503: $output .= '<td class="LC_left_item"> </td>';
4504: }
4505: $output .= '</tr></table></td></tr>';
4506: return $output;
4507: }
1.28 raeburn 4508:
1.93 raeburn 4509: sub insttypes_row {
4510: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4511: my %lt = &Apache::lonlocal::texthash (
4512: cansearch => 'Users allowed to search',
4513: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4514: lockablenames => 'User preference to lock name',
1.93 raeburn 4515: );
4516: my $showdom;
4517: if ($context eq 'cansearch') {
4518: $showdom = ' ('.$dom.')';
4519: }
1.160.6.5 raeburn 4520: my $class = 'LC_left_item';
4521: if ($context eq 'statustocreate') {
4522: $class = 'LC_right_item';
4523: }
1.25 raeburn 4524: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4525: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4526: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4527: my $rem;
4528: if (ref($types) eq 'ARRAY') {
4529: for (my $i=0; $i<@{$types}; $i++) {
4530: if (defined($usertypes->{$types->[$i]})) {
4531: my $rem = $i%($numinrow);
4532: if ($rem == 0) {
4533: if ($i > 0) {
4534: $output .= '</tr>';
4535: }
4536: $output .= '<tr>';
1.23 raeburn 4537: }
1.26 raeburn 4538: my $check = ' ';
1.99 raeburn 4539: if (ref($settings) eq 'HASH') {
4540: if (ref($settings->{$context}) eq 'ARRAY') {
4541: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4542: $check = ' checked="checked" ';
4543: }
4544: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4545: $check = ' checked="checked" ';
4546: }
1.23 raeburn 4547: }
1.26 raeburn 4548: $output .= '<td class="LC_left_item">'.
4549: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4550: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4551: 'value="'.$types->[$i].'"'.$check.'/>'.
4552: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4553: }
4554: }
1.26 raeburn 4555: $rem = @{$types}%($numinrow);
1.23 raeburn 4556: }
4557: my $colsleft = $numinrow - $rem;
1.131 raeburn 4558: if (($rem == 0) && (@{$types} > 0)) {
4559: $output .= '<tr>';
4560: }
1.23 raeburn 4561: if ($colsleft > 1) {
1.25 raeburn 4562: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4563: } else {
1.25 raeburn 4564: $output .= '<td class="LC_left_item">';
1.23 raeburn 4565: }
4566: my $defcheck = ' ';
1.99 raeburn 4567: if (ref($settings) eq 'HASH') {
4568: if (ref($settings->{$context}) eq 'ARRAY') {
4569: if (grep(/^default$/,@{$settings->{$context}})) {
4570: $defcheck = ' checked="checked" ';
4571: }
4572: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4573: $defcheck = ' checked="checked" ';
4574: }
1.23 raeburn 4575: }
1.25 raeburn 4576: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4577: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4578: 'value="default"'.$defcheck.'/>'.
4579: $othertitle.'</label></span></td>'.
4580: '</tr></table></td></tr>';
4581: return $output;
1.23 raeburn 4582: }
4583:
4584: sub sorted_searchtitles {
4585: my %searchtitles = &Apache::lonlocal::texthash(
4586: 'uname' => 'username',
4587: 'lastname' => 'last name',
4588: 'lastfirst' => 'last name, first name',
4589: );
4590: my @titleorder = ('uname','lastname','lastfirst');
4591: return (\%searchtitles,\@titleorder);
4592: }
4593:
1.25 raeburn 4594: sub sorted_searchtypes {
4595: my %srchtypes_desc = (
4596: exact => 'is exact match',
4597: contains => 'contains ..',
4598: begins => 'begins with ..',
4599: );
4600: my @srchtypeorder = ('exact','begins','contains');
4601: return (\%srchtypes_desc,\@srchtypeorder);
4602: }
4603:
1.3 raeburn 4604: sub usertype_update_row {
4605: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4606: my $datatable;
4607: my $numinrow = 4;
4608: foreach my $type (@{$types}) {
4609: if (defined($usertypes->{$type})) {
4610: $$rownums ++;
4611: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4612: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4613: '</td><td class="LC_left_item"><table>';
4614: for (my $i=0; $i<@{$fields}; $i++) {
4615: my $rem = $i%($numinrow);
4616: if ($rem == 0) {
4617: if ($i > 0) {
4618: $datatable .= '</tr>';
4619: }
4620: $datatable .= '<tr>';
4621: }
4622: my $check = ' ';
1.39 raeburn 4623: if (ref($settings) eq 'HASH') {
4624: if (ref($settings->{'fields'}) eq 'HASH') {
4625: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4626: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4627: $check = ' checked="checked" ';
4628: }
1.3 raeburn 4629: }
4630: }
4631: }
4632:
4633: if ($i == @{$fields}-1) {
4634: my $colsleft = $numinrow - $rem;
4635: if ($colsleft > 1) {
4636: $datatable .= '<td colspan="'.$colsleft.'">';
4637: } else {
4638: $datatable .= '<td>';
4639: }
4640: } else {
4641: $datatable .= '<td>';
4642: }
1.8 raeburn 4643: $datatable .= '<span class="LC_nobreak"><label>'.
4644: '<input type="checkbox" name="updateable_'.$type.
4645: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4646: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4647: }
4648: $datatable .= '</tr></table></td></tr>';
4649: }
4650: }
4651: return $datatable;
1.1 raeburn 4652: }
4653:
4654: sub modify_login {
1.9 raeburn 4655: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4656: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4657: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4658: %title = ( coursecatalog => 'Display course catalog',
4659: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 4660: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4661: newuser => 'Link for visitors to create a user account',
4662: loginheader => 'Log-in box header');
4663: @offon = ('off','on');
1.112 raeburn 4664: if (ref($domconfig{login}) eq 'HASH') {
4665: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4666: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4667: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4668: }
4669: }
4670: }
1.9 raeburn 4671: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4672: \%domconfig,\%loginhash);
1.160.6.14 raeburn 4673: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4674: foreach my $item (@toggles) {
4675: $loginhash{login}{$item} = $env{'form.'.$item};
4676: }
1.41 raeburn 4677: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4678: if (ref($colchanges{'login'}) eq 'HASH') {
4679: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4680: \%loginhash);
4681: }
1.110 raeburn 4682:
1.149 raeburn 4683: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4684: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4685: if (keys(%servers) > 1) {
4686: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4687: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4688: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4689: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4690: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4691: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4692: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4693: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4694: $changes{'loginvia'}{$lonhost} = 1;
4695: } else {
4696: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4697: $changes{'loginvia'}{$lonhost} = 1;
4698: }
4699: } else {
4700: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4701: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4702: $changes{'loginvia'}{$lonhost} = 1;
4703: }
4704: }
4705: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4706: foreach my $item (@loginvia_attribs) {
4707: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4708: }
4709: } else {
4710: foreach my $item (@loginvia_attribs) {
4711: my $new = $env{'form.'.$lonhost.'_'.$item};
4712: if (($item eq 'serverpath') && ($new eq 'custom')) {
4713: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4714: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4715: $new = '/';
4716: }
4717: }
4718: if (($item eq 'custompath') &&
4719: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4720: $new = '';
4721: }
4722: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4723: $changes{'loginvia'}{$lonhost} = 1;
4724: }
4725: if ($item eq 'exempt') {
4726: $new =~ s/^\s+//;
4727: $new =~ s/\s+$//;
4728: my @poss_ips = split(/\s*[,:]\s*/,$new);
4729: my @okips;
4730: foreach my $ip (@poss_ips) {
4731: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4732: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4733: push(@okips,$ip);
4734: }
4735: }
4736: }
4737: if (@okips > 0) {
4738: $new = join(',',@okips);
4739: } else {
4740: $new = '';
4741: }
4742: }
4743: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4744: }
4745: }
1.112 raeburn 4746: } else {
1.128 raeburn 4747: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4748: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4749: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4750: foreach my $item (@loginvia_attribs) {
4751: my $new = $env{'form.'.$lonhost.'_'.$item};
4752: if (($item eq 'serverpath') && ($new eq 'custom')) {
4753: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4754: $new = '/';
4755: }
4756: }
4757: if (($item eq 'custompath') &&
4758: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4759: $new = '';
4760: }
4761: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4762: }
1.110 raeburn 4763: }
4764: }
4765: }
4766: }
1.119 raeburn 4767:
1.160.6.5 raeburn 4768: my $servadm = $r->dir_config('lonAdmEMail');
4769: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4770: if (ref($domconfig{'login'}) eq 'HASH') {
4771: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4772: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4773: if ($lang eq 'nolang') {
4774: push(@currlangs,$lang);
4775: } elsif (defined($langchoices{$lang})) {
4776: push(@currlangs,$lang);
4777: } else {
4778: next;
4779: }
4780: }
4781: }
4782: }
4783: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4784: if (@currlangs > 0) {
4785: foreach my $lang (@currlangs) {
4786: if (grep(/^\Q$lang\E$/,@delurls)) {
4787: $changes{'helpurl'}{$lang} = 1;
4788: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4789: $changes{'helpurl'}{$lang} = 1;
4790: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4791: push(@newlangs,$lang);
4792: } else {
4793: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4794: }
4795: }
4796: }
4797: unless (grep(/^nolang$/,@currlangs)) {
4798: if ($env{'form.loginhelpurl_nolang.filename'}) {
4799: $changes{'helpurl'}{'nolang'} = 1;
4800: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4801: push(@newlangs,'nolang');
4802: }
4803: }
4804: if ($env{'form.loginhelpurl_add_lang'}) {
4805: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4806: ($env{'form.loginhelpurl_add_file.filename'})) {
4807: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4808: $addedfile = $env{'form.loginhelpurl_add_lang'};
4809: }
4810: }
4811: if ((@newlangs > 0) || ($addedfile)) {
4812: my $error;
4813: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4814: if ($configuserok eq 'ok') {
4815: if ($switchserver) {
4816: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4817: } elsif ($author_ok eq 'ok') {
4818: my @allnew = @newlangs;
4819: if ($addedfile ne '') {
4820: push(@allnew,$addedfile);
4821: }
4822: foreach my $lang (@allnew) {
4823: my $formelem = 'loginhelpurl_'.$lang;
4824: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4825: $formelem = 'loginhelpurl_add_file';
4826: }
4827: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4828: "help/$lang",'','',$newfile{$lang});
4829: if ($result eq 'ok') {
4830: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4831: $changes{'helpurl'}{$lang} = 1;
4832: } else {
4833: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4834: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4835: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4836: (!grep(/^\Q$lang\E$/,@delurls))) {
4837:
4838: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4839: }
4840: }
4841: }
4842: } else {
4843: $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);
4844: }
4845: } else {
4846: $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);
4847: }
4848: if ($error) {
4849: &Apache::lonnet::logthis($error);
4850: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4851: }
4852: }
4853: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4854:
4855: my $defaulthelpfile = '/adm/loginproblems.html';
4856: my $defaulttext = &mt('Default in use');
4857:
1.1 raeburn 4858: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4859: $dom);
4860: if ($putresult eq 'ok') {
1.160.6.14 raeburn 4861: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4862: my %defaultchecked = (
4863: 'coursecatalog' => 'on',
1.160.6.14 raeburn 4864: 'helpdesk' => 'on',
1.42 raeburn 4865: 'adminmail' => 'off',
1.43 raeburn 4866: 'newuser' => 'off',
1.42 raeburn 4867: );
1.55 raeburn 4868: if (ref($domconfig{'login'}) eq 'HASH') {
4869: foreach my $item (@toggles) {
4870: if ($defaultchecked{$item} eq 'on') {
4871: if (($domconfig{'login'}{$item} eq '0') &&
4872: ($env{'form.'.$item} eq '1')) {
4873: $changes{$item} = 1;
4874: } elsif (($domconfig{'login'}{$item} eq '' ||
4875: $domconfig{'login'}{$item} eq '1') &&
4876: ($env{'form.'.$item} eq '0')) {
4877: $changes{$item} = 1;
4878: }
4879: } elsif ($defaultchecked{$item} eq 'off') {
4880: if (($domconfig{'login'}{$item} eq '1') &&
4881: ($env{'form.'.$item} eq '0')) {
4882: $changes{$item} = 1;
4883: } elsif (($domconfig{'login'}{$item} eq '' ||
4884: $domconfig{'login'}{$item} eq '0') &&
4885: ($env{'form.'.$item} eq '1')) {
4886: $changes{$item} = 1;
4887: }
1.42 raeburn 4888: }
4889: }
1.41 raeburn 4890: }
1.6 raeburn 4891: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4892: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4893: $resulttext = &mt('Changes made:').'<ul>';
4894: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4895: if ($item eq 'loginvia') {
1.112 raeburn 4896: if (ref($changes{$item}) eq 'HASH') {
4897: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4898: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4899: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4900: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4901: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4902: $protocol = 'http' if ($protocol ne 'https');
4903: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4904:
4905: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4906: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4907: } else {
4908: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4909: }
4910: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4911: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4912: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4913: }
4914: $resulttext .= '</li>';
4915: } else {
4916: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4917: }
1.112 raeburn 4918: } else {
1.128 raeburn 4919: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4920: }
4921: }
1.128 raeburn 4922: $resulttext .= '</ul></li>';
1.112 raeburn 4923: }
1.160.6.5 raeburn 4924: } elsif ($item eq 'helpurl') {
4925: if (ref($changes{$item}) eq 'HASH') {
4926: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4927: if (grep(/^\Q$lang\E$/,@delurls)) {
4928: my ($chg,$link);
4929: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4930: if ($lang eq 'nolang') {
4931: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4932: } else {
4933: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4934: }
4935: $resulttext .= '<li>'.$chg.'</li>';
4936: } else {
4937: my $chg;
4938: if ($lang eq 'nolang') {
4939: $chg = &mt('custom log-in help file for no preferred language');
4940: } else {
4941: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4942: }
4943: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4944: $loginhash{'login'}{'helpurl'}{$lang}.
4945: '?inhibitmenu=yes',$chg,600,500).
4946: '</li>';
4947: }
4948: }
4949: }
4950: } elsif ($item eq 'captcha') {
4951: if (ref($loginhash{'login'}) eq 'HASH') {
4952: my $chgtxt;
4953: if ($loginhash{'login'}{$item} eq 'notused') {
4954: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4955: } else {
4956: my %captchas = &captcha_phrases();
4957: if ($captchas{$loginhash{'login'}{$item}}) {
4958: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4959: } else {
4960: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4961: }
4962: }
4963: $resulttext .= '<li>'.$chgtxt.'</li>';
4964: }
4965: } elsif ($item eq 'recaptchakeys') {
4966: if (ref($loginhash{'login'}) eq 'HASH') {
4967: my ($privkey,$pubkey);
4968: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4969: $pubkey = $loginhash{'login'}{$item}{'public'};
4970: $privkey = $loginhash{'login'}{$item}{'private'};
4971: }
4972: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4973: if (!$pubkey) {
4974: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4975: } else {
4976: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4977: }
4978: if (!$privkey) {
4979: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4980: } else {
4981: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4982: }
4983: $chgtxt .= '</ul>';
4984: $resulttext .= '<li>'.$chgtxt.'</li>';
4985: }
1.41 raeburn 4986: } else {
4987: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4988: }
1.1 raeburn 4989: }
1.6 raeburn 4990: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4991: } else {
4992: $resulttext = &mt('No changes made to log-in page settings');
4993: }
4994: } else {
1.11 albertel 4995: $resulttext = '<span class="LC_error">'.
4996: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4997: }
1.6 raeburn 4998: if ($errors) {
1.9 raeburn 4999: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5000: $errors.'</ul>';
5001: }
5002: return $resulttext;
5003: }
5004:
5005: sub color_font_choices {
5006: my %choices =
5007: &Apache::lonlocal::texthash (
5008: img => "Header",
5009: bgs => "Background colors",
5010: links => "Link colors",
1.55 raeburn 5011: images => "Images",
1.6 raeburn 5012: font => "Font color",
1.97 tempelho 5013: fontmenu => "Font Menu",
1.76 raeburn 5014: pgbg => "Page",
1.6 raeburn 5015: tabbg => "Header",
5016: sidebg => "Border",
5017: link => "Link",
5018: alink => "Active link",
5019: vlink => "Visited link",
5020: );
5021: return %choices;
5022: }
5023:
5024: sub modify_rolecolors {
1.9 raeburn 5025: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5026: my ($resulttext,%rolehash);
5027: $rolehash{'rolecolors'} = {};
1.55 raeburn 5028: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5029: if ($domconfig{'rolecolors'} eq '') {
5030: $domconfig{'rolecolors'} = {};
5031: }
5032: }
1.9 raeburn 5033: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5034: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5035: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5036: $dom);
5037: if ($putresult eq 'ok') {
5038: if (keys(%changes) > 0) {
1.41 raeburn 5039: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5040: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5041: $rolehash{'rolecolors'});
5042: } else {
5043: $resulttext = &mt('No changes made to default color schemes');
5044: }
5045: } else {
1.11 albertel 5046: $resulttext = '<span class="LC_error">'.
5047: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5048: }
5049: if ($errors) {
5050: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5051: $errors.'</ul>';
5052: }
5053: return $resulttext;
5054: }
5055:
5056: sub modify_colors {
1.9 raeburn 5057: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5058: my (%changes,%choices);
1.51 raeburn 5059: my @bgs;
1.6 raeburn 5060: my @links = ('link','alink','vlink');
1.41 raeburn 5061: my @logintext;
1.6 raeburn 5062: my @images;
5063: my $servadm = $r->dir_config('lonAdmEMail');
5064: my $errors;
5065: foreach my $role (@{$roles}) {
5066: if ($role eq 'login') {
1.12 raeburn 5067: %choices = &login_choices();
1.41 raeburn 5068: @logintext = ('textcol','bgcol');
1.12 raeburn 5069: } else {
5070: %choices = &color_font_choices();
1.107 raeburn 5071: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5072: }
5073: if ($role eq 'login') {
1.41 raeburn 5074: @images = ('img','logo','domlogo','login');
1.51 raeburn 5075: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5076: } else {
5077: @images = ('img');
1.51 raeburn 5078: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5079: }
5080: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5081: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5082: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5083: }
1.46 raeburn 5084: my ($configuserok,$author_ok,$switchserver) =
5085: &config_check($dom,$confname,$servadm);
1.9 raeburn 5086: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5087: if (ref($domconfig->{$role}) ne 'HASH') {
5088: $domconfig->{$role} = {};
5089: }
1.8 raeburn 5090: foreach my $img (@images) {
1.70 raeburn 5091: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5092: if (defined($env{'form.login_showlogo_'.$img})) {
5093: $confhash->{$role}{'showlogo'}{$img} = 1;
5094: } else {
5095: $confhash->{$role}{'showlogo'}{$img} = 0;
5096: }
5097: }
1.18 albertel 5098: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5099: && !defined($domconfig->{$role}{$img})
5100: && !$env{'form.'.$role.'_del_'.$img}
5101: && $env{'form.'.$role.'_import_'.$img}) {
5102: # import the old configured image from the .tab setting
5103: # if they haven't provided a new one
5104: $domconfig->{$role}{$img} =
5105: $env{'form.'.$role.'_import_'.$img};
5106: }
1.6 raeburn 5107: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5108: my $error;
1.6 raeburn 5109: if ($configuserok eq 'ok') {
1.9 raeburn 5110: if ($switchserver) {
1.12 raeburn 5111: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5112: } else {
5113: if ($author_ok eq 'ok') {
5114: my ($result,$logourl) =
5115: &publishlogo($r,'upload',$role.'_'.$img,
5116: $dom,$confname,$img,$width,$height);
5117: if ($result eq 'ok') {
5118: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5119: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5120: } else {
1.12 raeburn 5121: $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 5122: }
5123: } else {
1.46 raeburn 5124: $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 5125: }
5126: }
5127: } else {
1.46 raeburn 5128: $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 5129: }
5130: if ($error) {
1.8 raeburn 5131: &Apache::lonnet::logthis($error);
1.11 albertel 5132: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5133: }
5134: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5135: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5136: my $error;
5137: if ($configuserok eq 'ok') {
5138: # is confname an author?
5139: if ($switchserver eq '') {
5140: if ($author_ok eq 'ok') {
5141: my ($result,$logourl) =
5142: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5143: $dom,$confname,$img,$width,$height);
5144: if ($result eq 'ok') {
5145: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5146: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5147: }
5148: }
5149: }
5150: }
1.6 raeburn 5151: }
5152: }
5153: }
5154: if (ref($domconfig) eq 'HASH') {
5155: if (ref($domconfig->{$role}) eq 'HASH') {
5156: foreach my $img (@images) {
5157: if ($domconfig->{$role}{$img} ne '') {
5158: if ($env{'form.'.$role.'_del_'.$img}) {
5159: $confhash->{$role}{$img} = '';
1.12 raeburn 5160: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5161: } else {
1.9 raeburn 5162: if ($confhash->{$role}{$img} eq '') {
5163: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5164: }
1.6 raeburn 5165: }
5166: } else {
5167: if ($env{'form.'.$role.'_del_'.$img}) {
5168: $confhash->{$role}{$img} = '';
1.12 raeburn 5169: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5170: }
5171: }
1.70 raeburn 5172: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5173: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5174: if ($confhash->{$role}{'showlogo'}{$img} ne
5175: $domconfig->{$role}{'showlogo'}{$img}) {
5176: $changes{$role}{'showlogo'}{$img} = 1;
5177: }
5178: } else {
5179: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5180: $changes{$role}{'showlogo'}{$img} = 1;
5181: }
5182: }
5183: }
5184: }
1.6 raeburn 5185: if ($domconfig->{$role}{'font'} ne '') {
5186: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5187: $changes{$role}{'font'} = 1;
5188: }
5189: } else {
5190: if ($confhash->{$role}{'font'}) {
5191: $changes{$role}{'font'} = 1;
5192: }
5193: }
1.107 raeburn 5194: if ($role ne 'login') {
5195: if ($domconfig->{$role}{'fontmenu'} ne '') {
5196: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5197: $changes{$role}{'fontmenu'} = 1;
5198: }
5199: } else {
5200: if ($confhash->{$role}{'fontmenu'}) {
5201: $changes{$role}{'fontmenu'} = 1;
5202: }
1.97 tempelho 5203: }
5204: }
1.6 raeburn 5205: foreach my $item (@bgs) {
5206: if ($domconfig->{$role}{$item} ne '') {
5207: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5208: $changes{$role}{'bgs'}{$item} = 1;
5209: }
5210: } else {
5211: if ($confhash->{$role}{$item}) {
5212: $changes{$role}{'bgs'}{$item} = 1;
5213: }
5214: }
5215: }
5216: foreach my $item (@links) {
5217: if ($domconfig->{$role}{$item} ne '') {
5218: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5219: $changes{$role}{'links'}{$item} = 1;
5220: }
5221: } else {
5222: if ($confhash->{$role}{$item}) {
5223: $changes{$role}{'links'}{$item} = 1;
5224: }
5225: }
5226: }
1.41 raeburn 5227: foreach my $item (@logintext) {
5228: if ($domconfig->{$role}{$item} ne '') {
5229: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5230: $changes{$role}{'logintext'}{$item} = 1;
5231: }
5232: } else {
5233: if ($confhash->{$role}{$item}) {
5234: $changes{$role}{'logintext'}{$item} = 1;
5235: }
5236: }
5237: }
1.6 raeburn 5238: } else {
5239: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5240: \@logintext,$confhash,\%changes);
1.6 raeburn 5241: }
5242: } else {
5243: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5244: \@logintext,$confhash,\%changes);
1.6 raeburn 5245: }
5246: }
5247: return ($errors,%changes);
5248: }
5249:
1.46 raeburn 5250: sub config_check {
5251: my ($dom,$confname,$servadm) = @_;
5252: my ($configuserok,$author_ok,$switchserver,%currroles);
5253: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5254: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5255: $confname,$servadm);
5256: if ($configuserok eq 'ok') {
5257: $switchserver = &check_switchserver($dom,$confname);
5258: if ($switchserver eq '') {
5259: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5260: }
5261: }
5262: return ($configuserok,$author_ok,$switchserver);
5263: }
5264:
1.6 raeburn 5265: sub default_change_checker {
1.41 raeburn 5266: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5267: foreach my $item (@{$links}) {
5268: if ($confhash->{$role}{$item}) {
5269: $changes->{$role}{'links'}{$item} = 1;
5270: }
5271: }
5272: foreach my $item (@{$bgs}) {
5273: if ($confhash->{$role}{$item}) {
5274: $changes->{$role}{'bgs'}{$item} = 1;
5275: }
5276: }
1.41 raeburn 5277: foreach my $item (@{$logintext}) {
5278: if ($confhash->{$role}{$item}) {
5279: $changes->{$role}{'logintext'}{$item} = 1;
5280: }
5281: }
1.6 raeburn 5282: foreach my $img (@{$images}) {
5283: if ($env{'form.'.$role.'_del_'.$img}) {
5284: $confhash->{$role}{$img} = '';
1.12 raeburn 5285: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5286: }
1.70 raeburn 5287: if ($role eq 'login') {
5288: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5289: $changes->{$role}{'showlogo'}{$img} = 1;
5290: }
5291: }
1.6 raeburn 5292: }
5293: if ($confhash->{$role}{'font'}) {
5294: $changes->{$role}{'font'} = 1;
5295: }
1.48 raeburn 5296: }
1.6 raeburn 5297:
5298: sub display_colorchgs {
5299: my ($dom,$changes,$roles,$confhash) = @_;
5300: my (%choices,$resulttext);
5301: if (!grep(/^login$/,@{$roles})) {
5302: $resulttext = &mt('Changes made:').'<br />';
5303: }
5304: foreach my $role (@{$roles}) {
5305: if ($role eq 'login') {
5306: %choices = &login_choices();
5307: } else {
5308: %choices = &color_font_choices();
5309: }
5310: if (ref($changes->{$role}) eq 'HASH') {
5311: if ($role ne 'login') {
5312: $resulttext .= '<h4>'.&mt($role).'</h4>';
5313: }
5314: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5315: if ($role ne 'login') {
5316: $resulttext .= '<ul>';
5317: }
5318: if (ref($changes->{$role}{$key}) eq 'HASH') {
5319: if ($role ne 'login') {
5320: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5321: }
5322: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5323: if (($role eq 'login') && ($key eq 'showlogo')) {
5324: if ($confhash->{$role}{$key}{$item}) {
5325: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5326: } else {
5327: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5328: }
5329: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5330: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5331: } else {
1.12 raeburn 5332: my $newitem = $confhash->{$role}{$item};
5333: if ($key eq 'images') {
5334: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5335: }
5336: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5337: }
5338: }
5339: if ($role ne 'login') {
5340: $resulttext .= '</ul></li>';
5341: }
5342: } else {
5343: if ($confhash->{$role}{$key} eq '') {
5344: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5345: } else {
5346: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5347: }
5348: }
5349: if ($role ne 'login') {
5350: $resulttext .= '</ul>';
5351: }
5352: }
5353: }
5354: }
1.3 raeburn 5355: return $resulttext;
1.1 raeburn 5356: }
5357:
1.9 raeburn 5358: sub thumb_dimensions {
5359: return ('200','50');
5360: }
5361:
1.16 raeburn 5362: sub check_dimensions {
5363: my ($inputfile) = @_;
5364: my ($fullwidth,$fullheight);
5365: if ($inputfile =~ m|^[/\w.\-]+$|) {
5366: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5367: my $imageinfo = <PIPE>;
5368: if (!close(PIPE)) {
5369: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5370: }
5371: chomp($imageinfo);
5372: my ($fullsize) =
1.21 raeburn 5373: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5374: if ($fullsize) {
5375: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5376: }
5377: }
5378: }
5379: return ($fullwidth,$fullheight);
5380: }
5381:
1.9 raeburn 5382: sub check_configuser {
5383: my ($uhome,$dom,$confname,$servadm) = @_;
5384: my ($configuserok,%currroles);
5385: if ($uhome eq 'no_host') {
5386: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5387: my $configpass = &LONCAPA::Enrollment::create_password();
5388: $configuserok =
5389: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5390: $configpass,'','','','','',undef,$servadm);
5391: } else {
5392: $configuserok = 'ok';
5393: %currroles =
5394: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5395: }
5396: return ($configuserok,%currroles);
5397: }
5398:
5399: sub check_authorstatus {
5400: my ($dom,$confname,%currroles) = @_;
5401: my $author_ok;
1.40 raeburn 5402: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5403: my $start = time;
5404: my $end = 0;
5405: $author_ok =
5406: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5407: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5408: } else {
5409: $author_ok = 'ok';
5410: }
5411: return $author_ok;
5412: }
5413:
5414: sub publishlogo {
1.46 raeburn 5415: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5416: my ($output,$fname,$logourl);
5417: if ($action eq 'upload') {
5418: $fname=$env{'form.'.$formname.'.filename'};
5419: chop($env{'form.'.$formname});
5420: } else {
5421: ($fname) = ($formname =~ /([^\/]+)$/);
5422: }
1.46 raeburn 5423: if ($savefileas ne '') {
5424: $fname = $savefileas;
5425: }
1.9 raeburn 5426: $fname=&Apache::lonnet::clean_filename($fname);
5427: # See if there is anything left
5428: unless ($fname) { return ('error: no uploaded file'); }
5429: $fname="$subdir/$fname";
1.160.6.5 raeburn 5430: my $docroot=$r->dir_config('lonDocRoot');
5431: my $filepath="$docroot/priv";
5432: my $relpath = "$dom/$confname";
1.9 raeburn 5433: my ($fnamepath,$file,$fetchthumb);
5434: $file=$fname;
5435: if ($fname=~m|/|) {
5436: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5437: }
1.160.6.5 raeburn 5438: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5439: my $count;
1.160.6.5 raeburn 5440: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5441: $filepath.="/$parts[$count]";
5442: if ((-e $filepath)!=1) {
5443: mkdir($filepath,02770);
5444: }
5445: }
5446: # Check for bad extension and disallow upload
5447: if ($file=~/\.(\w+)$/ &&
5448: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5449: $output =
5450: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5451: } elsif ($file=~/\.(\w+)$/ &&
5452: !defined(&Apache::loncommon::fileembstyle($1))) {
5453: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5454: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 5455: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 5456: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 5457: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5458: } else {
5459: my $source = $filepath.'/'.$file;
5460: my $logfile;
5461: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 5462: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5463: }
5464: print $logfile
5465: "\n================= Publish ".localtime()." ================\n".
5466: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5467: # Save the file
5468: if (!open(FH,'>'.$source)) {
5469: &Apache::lonnet::logthis('Failed to create '.$source);
5470: return (&mt('Failed to create file'));
5471: }
5472: if ($action eq 'upload') {
5473: if (!print FH ($env{'form.'.$formname})) {
5474: &Apache::lonnet::logthis('Failed to write to '.$source);
5475: return (&mt('Failed to write file'));
5476: }
5477: } else {
5478: my $original = &Apache::lonnet::filelocation('',$formname);
5479: if(!copy($original,$source)) {
5480: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5481: return (&mt('Failed to write file'));
5482: }
5483: }
5484: close(FH);
5485: chmod(0660, $source); # Permissions to rw-rw---.
5486:
5487: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5488: my $copyfile=$targetdir.'/'.$file;
5489:
5490: my @parts=split(/\//,$targetdir);
5491: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5492: for (my $count=5;$count<=$#parts;$count++) {
5493: $path.="/$parts[$count]";
5494: if (!-e $path) {
5495: print $logfile "\nCreating directory ".$path;
5496: mkdir($path,02770);
5497: }
5498: }
5499: my $versionresult;
5500: if (-e $copyfile) {
5501: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5502: } else {
5503: $versionresult = 'ok';
5504: }
5505: if ($versionresult eq 'ok') {
5506: if (copy($source,$copyfile)) {
5507: print $logfile "\nCopied original source to ".$copyfile."\n";
5508: $output = 'ok';
5509: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5510: push(@{$modified_urls},[$copyfile,$source]);
5511: my $metaoutput =
5512: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5513: unless ($registered_cleanup) {
5514: my $handlers = $r->get_handlers('PerlCleanupHandler');
5515: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5516: $registered_cleanup=1;
5517: }
1.9 raeburn 5518: } else {
5519: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5520: $output = &mt('Failed to copy file to RES space').", $!";
5521: }
5522: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5523: my $inputfile = $filepath.'/'.$file;
5524: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5525: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5526: if ($fullwidth ne '' && $fullheight ne '') {
5527: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5528: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5529: system("convert -sample $thumbsize $inputfile $outfile");
5530: chmod(0660, $filepath.'/tn-'.$file);
5531: if (-e $outfile) {
5532: my $copyfile=$targetdir.'/tn-'.$file;
5533: if (copy($outfile,$copyfile)) {
5534: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5535: my $thumb_metaoutput =
5536: &write_metadata($dom,$confname,$formname,
5537: $targetdir,'tn-'.$file,$logfile);
5538: push(@{$modified_urls},[$copyfile,$outfile]);
5539: unless ($registered_cleanup) {
5540: my $handlers = $r->get_handlers('PerlCleanupHandler');
5541: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5542: $registered_cleanup=1;
5543: }
1.16 raeburn 5544: } else {
5545: print $logfile "\nUnable to write ".$copyfile.
5546: ':'.$!."\n";
5547: }
5548: }
1.9 raeburn 5549: }
5550: }
5551: }
5552: } else {
5553: $output = $versionresult;
5554: }
5555: }
5556: return ($output,$logourl);
5557: }
5558:
5559: sub logo_versioning {
5560: my ($targetdir,$file,$logfile) = @_;
5561: my $target = $targetdir.'/'.$file;
5562: my ($maxversion,$fn,$extn,$output);
5563: $maxversion = 0;
5564: if ($file =~ /^(.+)\.(\w+)$/) {
5565: $fn=$1;
5566: $extn=$2;
5567: }
5568: opendir(DIR,$targetdir);
5569: while (my $filename=readdir(DIR)) {
5570: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5571: $maxversion=($1>$maxversion)?$1:$maxversion;
5572: }
5573: }
5574: $maxversion++;
5575: print $logfile "\nCreating old version ".$maxversion."\n";
5576: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5577: if (copy($target,$copyfile)) {
5578: print $logfile "Copied old target to ".$copyfile."\n";
5579: $copyfile=$copyfile.'.meta';
5580: if (copy($target.'.meta',$copyfile)) {
5581: print $logfile "Copied old target metadata to ".$copyfile."\n";
5582: $output = 'ok';
5583: } else {
5584: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5585: $output = &mt('Failed to copy old meta').", $!, ";
5586: }
5587: } else {
5588: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5589: $output = &mt('Failed to copy old target').", $!, ";
5590: }
5591: return $output;
5592: }
5593:
5594: sub write_metadata {
5595: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5596: my (%metadatafields,%metadatakeys,$output);
5597: $metadatafields{'title'}=$formname;
5598: $metadatafields{'creationdate'}=time;
5599: $metadatafields{'lastrevisiondate'}=time;
5600: $metadatafields{'copyright'}='public';
5601: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5602: $env{'user.domain'};
5603: $metadatafields{'authorspace'}=$confname.':'.$dom;
5604: $metadatafields{'domain'}=$dom;
5605: {
5606: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5607: my $mfh;
1.155 raeburn 5608: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5609: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5610: unless ($_=~/\./) {
5611: my $unikey=$_;
5612: $unikey=~/^([A-Za-z]+)/;
5613: my $tag=$1;
5614: $tag=~tr/A-Z/a-z/;
5615: print $mfh "\n\<$tag";
5616: foreach (split(/\,/,$metadatakeys{$unikey})) {
5617: my $value=$metadatafields{$unikey.'.'.$_};
5618: $value=~s/\"/\'\'/g;
5619: print $mfh ' '.$_.'="'.$value.'"';
5620: }
5621: print $mfh '>'.
5622: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5623: .'</'.$tag.'>';
5624: }
5625: }
5626: $output = 'ok';
5627: print $logfile "\nWrote metadata";
5628: close($mfh);
5629: } else {
5630: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5631: $output = &mt('Could not write metadata');
5632: }
5633: }
1.155 raeburn 5634: return $output;
5635: }
5636:
5637: sub notifysubscribed {
5638: foreach my $targetsource (@{$modified_urls}){
5639: next unless (ref($targetsource) eq 'ARRAY');
5640: my ($target,$source)=@{$targetsource};
5641: if ($source ne '') {
5642: if (open(my $logfh,'>>'.$source.'.log')) {
5643: print $logfh "\nCleanup phase: Notifications\n";
5644: my @subscribed=&subscribed_hosts($target);
5645: foreach my $subhost (@subscribed) {
5646: print $logfh "\nNotifying host ".$subhost.':';
5647: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5648: print $logfh $reply;
5649: }
5650: my @subscribedmeta=&subscribed_hosts("$target.meta");
5651: foreach my $subhost (@subscribedmeta) {
5652: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5653: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5654: $subhost);
5655: print $logfh $reply;
5656: }
5657: print $logfh "\n============ Done ============\n";
1.160 raeburn 5658: close($logfh);
1.155 raeburn 5659: }
5660: }
5661: }
5662: return OK;
5663: }
5664:
5665: sub subscribed_hosts {
5666: my ($target) = @_;
5667: my @subscribed;
5668: if (open(my $fh,"<$target.subscription")) {
5669: while (my $subline=<$fh>) {
5670: if ($subline =~ /^($match_lonid):/) {
5671: my $host = $1;
5672: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5673: unless (grep(/^\Q$host\E$/,@subscribed)) {
5674: push(@subscribed,$host);
5675: }
5676: }
5677: }
5678: }
5679: }
5680: return @subscribed;
1.9 raeburn 5681: }
5682:
5683: sub check_switchserver {
5684: my ($dom,$confname) = @_;
5685: my ($allowed,$switchserver);
5686: my $home = &Apache::lonnet::homeserver($confname,$dom);
5687: if ($home eq 'no_host') {
5688: $home = &Apache::lonnet::domain($dom,'primary');
5689: }
5690: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5691: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5692: if (!$allowed) {
1.160.6.11 raeburn 5693: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5694: }
5695: return $switchserver;
5696: }
5697:
1.1 raeburn 5698: sub modify_quotas {
1.86 raeburn 5699: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5700: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5701: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5702: if ($action eq 'quotas') {
5703: $context = 'tools';
5704: } else {
5705: $context = $action;
5706: }
5707: if ($context eq 'requestcourses') {
1.98 raeburn 5708: @usertools = ('official','unofficial','community');
1.106 raeburn 5709: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5710: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5711: %titles = &courserequest_titles();
5712: $toolregexp = join('|',@usertools);
5713: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5714: } elsif ($context eq 'requestauthor') {
5715: @usertools = ('author');
5716: %titles = &authorrequest_titles();
1.86 raeburn 5717: } else {
1.160.6.4 raeburn 5718: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5719: %titles = &tool_titles();
1.86 raeburn 5720: }
1.72 raeburn 5721: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5722: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5723: foreach my $key (keys(%env)) {
1.101 raeburn 5724: if ($context eq 'requestcourses') {
5725: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5726: my $item = $1;
5727: my $type = $2;
5728: if ($type =~ /^limit_(.+)/) {
5729: $limithash{$item}{$1} = $env{$key};
5730: } else {
5731: $confhash{$item}{$type} = $env{$key};
5732: }
5733: }
1.160.6.5 raeburn 5734: } elsif ($context eq 'requestauthor') {
5735: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5736: $confhash{$1} = $env{$key};
5737: }
1.101 raeburn 5738: } else {
1.86 raeburn 5739: if ($key =~ /^form\.quota_(.+)$/) {
5740: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20! raeburn 5741: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
! 5742: $confhash{'authorquota'}{$1} = $env{$key};
! 5743: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5744: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5745: }
1.72 raeburn 5746: }
5747: }
1.160.6.5 raeburn 5748: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5749: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5750: @approvalnotify = sort(@approvalnotify);
5751: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5752: if (ref($domconfig{$action}) eq 'HASH') {
5753: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5754: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5755: $changes{'notify'}{'approval'} = 1;
5756: }
5757: } else {
1.144 raeburn 5758: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5759: $changes{'notify'}{'approval'} = 1;
5760: }
5761: }
5762: } else {
1.144 raeburn 5763: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5764: $changes{'notify'}{'approval'} = 1;
5765: }
5766: }
5767: } else {
1.86 raeburn 5768: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20! raeburn 5769: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5770: }
1.72 raeburn 5771: foreach my $item (@usertools) {
5772: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5773: my $unset;
1.101 raeburn 5774: if ($context eq 'requestcourses') {
1.104 raeburn 5775: $unset = '0';
5776: if ($type eq '_LC_adv') {
5777: $unset = '';
5778: }
1.101 raeburn 5779: if ($confhash{$item}{$type} eq 'autolimit') {
5780: $confhash{$item}{$type} .= '=';
5781: unless ($limithash{$item}{$type} =~ /\D/) {
5782: $confhash{$item}{$type} .= $limithash{$item}{$type};
5783: }
5784: }
1.160.6.5 raeburn 5785: } elsif ($context eq 'requestauthor') {
5786: $unset = '0';
5787: if ($type eq '_LC_adv') {
5788: $unset = '';
5789: }
1.72 raeburn 5790: } else {
1.101 raeburn 5791: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5792: $confhash{$item}{$type} = 1;
5793: } else {
5794: $confhash{$item}{$type} = 0;
5795: }
1.72 raeburn 5796: }
1.86 raeburn 5797: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5798: if ($action eq 'requestauthor') {
5799: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5800: $changes{$type} = 1;
5801: }
5802: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5803: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5804: $changes{$item}{$type} = 1;
5805: }
5806: } else {
5807: if ($context eq 'requestcourses') {
1.104 raeburn 5808: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5809: $changes{$item}{$type} = 1;
5810: }
5811: } else {
5812: if (!$confhash{$item}{$type}) {
5813: $changes{$item}{$type} = 1;
5814: }
5815: }
5816: }
5817: } else {
5818: if ($context eq 'requestcourses') {
1.104 raeburn 5819: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5820: $changes{$item}{$type} = 1;
5821: }
1.160.6.5 raeburn 5822: } elsif ($context eq 'requestauthor') {
5823: if ($confhash{$type} ne $unset) {
5824: $changes{$type} = 1;
5825: }
1.72 raeburn 5826: } else {
5827: if (!$confhash{$item}{$type}) {
5828: $changes{$item}{$type} = 1;
5829: }
5830: }
5831: }
1.1 raeburn 5832: }
5833: }
1.160.6.5 raeburn 5834: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5835: if (ref($domconfig{'quotas'}) eq 'HASH') {
5836: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5837: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5838: if (exists($confhash{'defaultquota'}{$key})) {
5839: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5840: $changes{'defaultquota'}{$key} = 1;
5841: }
5842: } else {
5843: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5844: }
5845: }
1.86 raeburn 5846: } else {
5847: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5848: if (exists($confhash{'defaultquota'}{$key})) {
5849: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5850: $changes{'defaultquota'}{$key} = 1;
5851: }
5852: } else {
5853: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5854: }
1.1 raeburn 5855: }
5856: }
1.160.6.20! raeburn 5857: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
! 5858: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
! 5859: if (exists($confhash{'authorquota'}{$key})) {
! 5860: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
! 5861: $changes{'authorquota'}{$key} = 1;
! 5862: }
! 5863: } else {
! 5864: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
! 5865: }
! 5866: }
! 5867: }
1.1 raeburn 5868: }
1.86 raeburn 5869: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5870: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5871: if (ref($domconfig{'quotas'}) eq 'HASH') {
5872: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5873: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5874: $changes{'defaultquota'}{$key} = 1;
5875: }
5876: } else {
5877: if (!exists($domconfig{'quotas'}{$key})) {
5878: $changes{'defaultquota'}{$key} = 1;
5879: }
1.72 raeburn 5880: }
5881: } else {
1.86 raeburn 5882: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5883: }
1.1 raeburn 5884: }
5885: }
1.160.6.20! raeburn 5886: if (ref($confhash{'authorquota'}) eq 'HASH') {
! 5887: foreach my $key (keys(%{$confhash{'authorquota'}})) {
! 5888: if (ref($domconfig{'quotas'}) eq 'HASH') {
! 5889: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
! 5890: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
! 5891: $changes{'authorquota'}{$key} = 1;
! 5892: }
! 5893: } else {
! 5894: $changes{'authorquota'}{$key} = 1;
! 5895: }
! 5896: } else {
! 5897: $changes{'authorquota'}{$key} = 1;
! 5898: }
! 5899: }
! 5900: }
1.1 raeburn 5901: }
1.72 raeburn 5902:
1.160.6.5 raeburn 5903: if ($context eq 'requestauthor') {
5904: $domdefaults{'requestauthor'} = \%confhash;
5905: } else {
5906: foreach my $key (keys(%confhash)) {
5907: $domdefaults{$key} = $confhash{$key};
5908: }
1.72 raeburn 5909: }
1.160.6.5 raeburn 5910:
1.1 raeburn 5911: my %quotahash = (
1.86 raeburn 5912: $action => { %confhash }
1.1 raeburn 5913: );
5914: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5915: $dom);
5916: if ($putresult eq 'ok') {
5917: if (keys(%changes) > 0) {
1.72 raeburn 5918: my $cachetime = 24*60*60;
5919: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5920:
1.1 raeburn 5921: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 5922: unless (($context eq 'requestcourses') ||
5923: ($context eq 'requestauthor')) {
1.86 raeburn 5924: if (ref($changes{'defaultquota'}) eq 'HASH') {
5925: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5926: foreach my $type (@{$types},'default') {
5927: if (defined($changes{'defaultquota'}{$type})) {
5928: my $typetitle = $usertypes->{$type};
5929: if ($type eq 'default') {
5930: $typetitle = $othertitle;
5931: }
5932: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5933: }
5934: }
1.86 raeburn 5935: $resulttext .= '</ul></li>';
1.72 raeburn 5936: }
1.160.6.20! raeburn 5937: if (ref($changes{'authorquota'}) eq 'HASH') {
! 5938: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
! 5939: foreach my $type (@{$types},'default') {
! 5940: if (defined($changes{'authorquota'}{$type})) {
! 5941: my $typetitle = $usertypes->{$type};
! 5942: if ($type eq 'default') {
! 5943: $typetitle = $othertitle;
! 5944: }
! 5945: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
! 5946: }
! 5947: }
! 5948: $resulttext .= '</ul></li>';
! 5949: }
1.72 raeburn 5950: }
1.80 raeburn 5951: my %newenv;
1.72 raeburn 5952: foreach my $item (@usertools) {
1.160.6.5 raeburn 5953: my (%haschgs,%inconf);
5954: if ($context eq 'requestauthor') {
5955: %haschgs = %changes;
5956: %inconf = %confhash;
5957: } else {
5958: if (ref($changes{$item}) eq 'HASH') {
5959: %haschgs = %{$changes{$item}};
5960: }
5961: if (ref($confhash{$item}) eq 'HASH') {
5962: %inconf = %{$confhash{$item}};
5963: }
5964: }
5965: if (keys(%haschgs) > 0) {
1.80 raeburn 5966: my $newacc =
5967: &Apache::lonnet::usertools_access($env{'user.name'},
5968: $env{'user.domain'},
1.86 raeburn 5969: $item,'reload',$context);
1.160.6.5 raeburn 5970: if (($context eq 'requestcourses') ||
5971: ($context eq 'requestauthor')) {
1.108 raeburn 5972: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5973: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5974: }
5975: } else {
5976: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5977: $newenv{'environment.availabletools.'.$item} = $newacc;
5978: }
1.80 raeburn 5979: }
1.160.6.5 raeburn 5980: unless ($context eq 'requestauthor') {
5981: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5982: }
1.72 raeburn 5983: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 5984: if ($haschgs{$type}) {
1.72 raeburn 5985: my $typetitle = $usertypes->{$type};
5986: if ($type eq 'default') {
5987: $typetitle = $othertitle;
5988: } elsif ($type eq '_LC_adv') {
5989: $typetitle = 'LON-CAPA Advanced Users';
5990: }
1.160.6.5 raeburn 5991: if ($inconf{$type}) {
1.101 raeburn 5992: if ($context eq 'requestcourses') {
5993: my $cond;
1.160.6.5 raeburn 5994: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5995: if ($1 eq '') {
5996: $cond = &mt('(Automatic processing of any request).');
5997: } else {
5998: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5999: }
6000: } else {
1.160.6.5 raeburn 6001: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6002: }
6003: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 6004: } elsif ($context eq 'requestauthor') {
6005: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6006: $titles{$inconf{$type}},$typetitle);
6007:
1.101 raeburn 6008: } else {
6009: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6010: }
1.72 raeburn 6011: } else {
1.104 raeburn 6012: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 6013: if ($inconf{$type} eq '0') {
1.104 raeburn 6014: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6015: } else {
6016: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6017: }
6018: } else {
6019: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6020: }
1.72 raeburn 6021: }
6022: }
1.26 raeburn 6023: }
1.160.6.5 raeburn 6024: unless ($context eq 'requestauthor') {
6025: $resulttext .= '</ul></li>';
6026: }
1.26 raeburn 6027: }
1.1 raeburn 6028: }
1.160.6.5 raeburn 6029: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6030: if (ref($changes{'notify'}) eq 'HASH') {
6031: if ($changes{'notify'}{'approval'}) {
6032: if (ref($confhash{'notify'}) eq 'HASH') {
6033: if ($confhash{'notify'}{'approval'}) {
6034: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6035: } else {
1.160.6.5 raeburn 6036: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6037: }
6038: }
6039: }
6040: }
6041: }
1.1 raeburn 6042: $resulttext .= '</ul>';
1.80 raeburn 6043: if (keys(%newenv)) {
6044: &Apache::lonnet::appenv(\%newenv);
6045: }
1.1 raeburn 6046: } else {
1.86 raeburn 6047: if ($context eq 'requestcourses') {
6048: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 6049: } elsif ($context eq 'requestauthor') {
6050: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6051: } else {
1.90 weissno 6052: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6053: }
1.1 raeburn 6054: }
6055: } else {
1.11 albertel 6056: $resulttext = '<span class="LC_error">'.
6057: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6058: }
1.3 raeburn 6059: return $resulttext;
1.1 raeburn 6060: }
6061:
1.3 raeburn 6062: sub modify_autoenroll {
6063: my ($dom,%domconfig) = @_;
1.1 raeburn 6064: my ($resulttext,%changes);
6065: my %currautoenroll;
6066: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6067: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6068: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6069: }
6070: }
6071: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6072: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6073: sender => 'Sender for notification messages',
6074: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6075: my @offon = ('off','on');
1.17 raeburn 6076: my $sender_uname = $env{'form.sender_uname'};
6077: my $sender_domain = $env{'form.sender_domain'};
6078: if ($sender_domain eq '') {
6079: $sender_uname = '';
6080: } elsif ($sender_uname eq '') {
6081: $sender_domain = '';
6082: }
1.129 raeburn 6083: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6084: my %autoenrollhash = (
1.129 raeburn 6085: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6086: 'sender_uname' => $sender_uname,
6087: 'sender_domain' => $sender_domain,
6088: 'co-owners' => $coowners,
1.1 raeburn 6089: }
6090: );
1.4 raeburn 6091: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6092: $dom);
1.1 raeburn 6093: if ($putresult eq 'ok') {
6094: if (exists($currautoenroll{'run'})) {
6095: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6096: $changes{'run'} = 1;
6097: }
6098: } elsif ($autorun) {
6099: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6100: $changes{'run'} = 1;
1.1 raeburn 6101: }
6102: }
1.17 raeburn 6103: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6104: $changes{'sender'} = 1;
6105: }
1.17 raeburn 6106: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6107: $changes{'sender'} = 1;
6108: }
1.129 raeburn 6109: if ($currautoenroll{'co-owners'} ne '') {
6110: if ($currautoenroll{'co-owners'} ne $coowners) {
6111: $changes{'coowners'} = 1;
6112: }
6113: } elsif ($coowners) {
6114: $changes{'coowners'} = 1;
6115: }
1.1 raeburn 6116: if (keys(%changes) > 0) {
6117: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6118: if ($changes{'run'}) {
1.1 raeburn 6119: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6120: }
6121: if ($changes{'sender'}) {
1.17 raeburn 6122: if ($sender_uname eq '' || $sender_domain eq '') {
6123: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6124: } else {
6125: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6126: }
1.1 raeburn 6127: }
1.129 raeburn 6128: if ($changes{'coowners'}) {
6129: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6130: &Apache::loncommon::devalidate_domconfig_cache($dom);
6131: }
1.1 raeburn 6132: $resulttext .= '</ul>';
6133: } else {
6134: $resulttext = &mt('No changes made to auto-enrollment settings');
6135: }
6136: } else {
1.11 albertel 6137: $resulttext = '<span class="LC_error">'.
6138: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6139: }
1.3 raeburn 6140: return $resulttext;
1.1 raeburn 6141: }
6142:
6143: sub modify_autoupdate {
1.3 raeburn 6144: my ($dom,%domconfig) = @_;
1.1 raeburn 6145: my ($resulttext,%currautoupdate,%fields,%changes);
6146: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6147: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6148: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6149: }
6150: }
6151: my @offon = ('off','on');
6152: my %title = &Apache::lonlocal::texthash (
6153: run => 'Auto-update:',
6154: classlists => 'Updates to user information in classlists?'
6155: );
1.44 raeburn 6156: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6157: my %fieldtitles = &Apache::lonlocal::texthash (
6158: id => 'Student/Employee ID',
1.20 raeburn 6159: permanentemail => 'E-mail address',
1.1 raeburn 6160: lastname => 'Last Name',
6161: firstname => 'First Name',
6162: middlename => 'Middle Name',
1.132 raeburn 6163: generation => 'Generation',
1.1 raeburn 6164: );
1.142 raeburn 6165: $othertitle = &mt('All users');
1.1 raeburn 6166: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6167: $othertitle = &mt('Other users');
1.1 raeburn 6168: }
6169: foreach my $key (keys(%env)) {
6170: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6171: my ($usertype,$item) = ($1,$2);
6172: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6173: if ($usertype eq 'default') {
6174: push(@{$fields{$1}},$2);
6175: } elsif (ref($types) eq 'ARRAY') {
6176: if (grep(/^\Q$usertype\E$/,@{$types})) {
6177: push(@{$fields{$1}},$2);
6178: }
6179: }
6180: }
1.1 raeburn 6181: }
6182: }
1.131 raeburn 6183: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6184: @lockablenames = sort(@lockablenames);
6185: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6186: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6187: if (@changed) {
6188: $changes{'lockablenames'} = 1;
6189: }
6190: } else {
6191: if (@lockablenames) {
6192: $changes{'lockablenames'} = 1;
6193: }
6194: }
1.1 raeburn 6195: my %updatehash = (
6196: autoupdate => { run => $env{'form.autoupdate_run'},
6197: classlists => $env{'form.classlists'},
6198: fields => {%fields},
1.131 raeburn 6199: lockablenames => \@lockablenames,
1.1 raeburn 6200: }
6201: );
6202: foreach my $key (keys(%currautoupdate)) {
6203: if (($key eq 'run') || ($key eq 'classlists')) {
6204: if (exists($updatehash{autoupdate}{$key})) {
6205: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6206: $changes{$key} = 1;
6207: }
6208: }
6209: } elsif ($key eq 'fields') {
6210: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6211: foreach my $item (@{$types},'default') {
1.1 raeburn 6212: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6213: my $change = 0;
6214: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6215: if (!exists($fields{$item})) {
6216: $change = 1;
1.132 raeburn 6217: last;
1.1 raeburn 6218: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6219: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6220: $change = 1;
1.132 raeburn 6221: last;
1.1 raeburn 6222: }
6223: }
6224: }
6225: if ($change) {
6226: push(@{$changes{$key}},$item);
6227: }
1.26 raeburn 6228: }
1.1 raeburn 6229: }
6230: }
1.131 raeburn 6231: } elsif ($key eq 'lockablenames') {
6232: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6233: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6234: if (@changed) {
6235: $changes{'lockablenames'} = 1;
6236: }
6237: } else {
6238: if (@lockablenames) {
6239: $changes{'lockablenames'} = 1;
6240: }
6241: }
6242: }
6243: }
6244: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6245: if (@lockablenames) {
6246: $changes{'lockablenames'} = 1;
1.1 raeburn 6247: }
6248: }
1.26 raeburn 6249: foreach my $item (@{$types},'default') {
6250: if (defined($fields{$item})) {
6251: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6252: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6253: my $change = 0;
6254: if (ref($fields{$item}) eq 'ARRAY') {
6255: foreach my $type (@{$fields{$item}}) {
6256: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6257: $change = 1;
6258: last;
6259: }
6260: }
6261: }
6262: if ($change) {
6263: push(@{$changes{'fields'}},$item);
6264: }
6265: } else {
1.26 raeburn 6266: push(@{$changes{'fields'}},$item);
6267: }
6268: } else {
6269: push(@{$changes{'fields'}},$item);
1.1 raeburn 6270: }
6271: }
6272: }
6273: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6274: $dom);
6275: if ($putresult eq 'ok') {
6276: if (keys(%changes) > 0) {
6277: $resulttext = &mt('Changes made:').'<ul>';
6278: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6279: if ($key eq 'lockablenames') {
6280: $resulttext .= '<li>';
6281: if (@lockablenames) {
6282: $usertypes->{'default'} = $othertitle;
6283: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6284: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6285: } else {
6286: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6287: }
6288: $resulttext .= '</li>';
6289: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6290: foreach my $item (@{$changes{$key}}) {
6291: my @newvalues;
6292: foreach my $type (@{$fields{$item}}) {
6293: push(@newvalues,$fieldtitles{$type});
6294: }
1.3 raeburn 6295: my $newvaluestr;
6296: if (@newvalues > 0) {
6297: $newvaluestr = join(', ',@newvalues);
6298: } else {
6299: $newvaluestr = &mt('none');
1.6 raeburn 6300: }
1.1 raeburn 6301: if ($item eq 'default') {
1.26 raeburn 6302: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6303: } else {
1.26 raeburn 6304: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6305: }
6306: }
6307: } else {
6308: my $newvalue;
6309: if ($key eq 'run') {
6310: $newvalue = $offon[$env{'form.autoupdate_run'}];
6311: } else {
6312: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6313: }
1.1 raeburn 6314: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6315: }
6316: }
6317: $resulttext .= '</ul>';
6318: } else {
1.3 raeburn 6319: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6320: }
6321: } else {
1.11 albertel 6322: $resulttext = '<span class="LC_error">'.
6323: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6324: }
1.3 raeburn 6325: return $resulttext;
1.1 raeburn 6326: }
6327:
1.125 raeburn 6328: sub modify_autocreate {
6329: my ($dom,%domconfig) = @_;
6330: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6331: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6332: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6333: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6334: }
6335: }
6336: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6337: req => 'Auto-creation of validated requests for official courses',
6338: xmldc => 'Identity of course creator of courses from XML files',
6339: );
6340: my @types = ('xml','req');
6341: foreach my $item (@types) {
6342: $newvals{$item} = $env{'form.autocreate_'.$item};
6343: $newvals{$item} =~ s/\D//g;
6344: $newvals{$item} = 0 if ($newvals{$item} eq '');
6345: }
6346: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6347: my %domcoords = &get_active_dcs($dom);
6348: unless (exists($domcoords{$newvals{'xmldc'}})) {
6349: $newvals{'xmldc'} = '';
6350: }
6351: %autocreatehash = (
6352: autocreate => { xml => $newvals{'xml'},
6353: req => $newvals{'req'},
6354: }
6355: );
6356: if ($newvals{'xmldc'} ne '') {
6357: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6358: }
6359: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6360: $dom);
6361: if ($putresult eq 'ok') {
6362: my @items = @types;
6363: if ($newvals{'xml'}) {
6364: push(@items,'xmldc');
6365: }
6366: foreach my $item (@items) {
6367: if (exists($currautocreate{$item})) {
6368: if ($currautocreate{$item} ne $newvals{$item}) {
6369: $changes{$item} = 1;
6370: }
6371: } elsif ($newvals{$item}) {
6372: $changes{$item} = 1;
6373: }
6374: }
6375: if (keys(%changes) > 0) {
6376: my @offon = ('off','on');
6377: $resulttext = &mt('Changes made:').'<ul>';
6378: foreach my $item (@types) {
6379: if ($changes{$item}) {
6380: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6381: $resulttext .= '<li>'.
6382: &mt("$title{$item} set to [_1]$newtxt [_2]",
6383: '<b>','</b>').
6384: '</li>';
1.125 raeburn 6385: }
6386: }
6387: if ($changes{'xmldc'}) {
6388: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6389: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6390: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6391: }
6392: $resulttext .= '</ul>';
6393: } else {
6394: $resulttext = &mt('No changes made to auto-creation settings');
6395: }
6396: } else {
6397: $resulttext = '<span class="LC_error">'.
6398: &mt('An error occurred: [_1]',$putresult).'</span>';
6399: }
6400: return $resulttext;
6401: }
6402:
1.23 raeburn 6403: sub modify_directorysrch {
6404: my ($dom,%domconfig) = @_;
6405: my ($resulttext,%changes);
6406: my %currdirsrch;
6407: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6408: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6409: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6410: }
6411: }
6412: my %title = ( available => 'Directory search available',
1.24 raeburn 6413: localonly => 'Other domains can search',
1.23 raeburn 6414: searchby => 'Search types',
6415: searchtypes => 'Search latitude');
6416: my @offon = ('off','on');
1.24 raeburn 6417: my @otherdoms = ('Yes','No');
1.23 raeburn 6418:
1.25 raeburn 6419: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6420: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6421: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6422:
1.44 raeburn 6423: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6424: if (keys(%{$usertypes}) == 0) {
6425: @cansearch = ('default');
6426: } else {
6427: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6428: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6429: if (!grep(/^\Q$type\E$/,@cansearch)) {
6430: push(@{$changes{'cansearch'}},$type);
6431: }
1.23 raeburn 6432: }
1.26 raeburn 6433: foreach my $type (@cansearch) {
6434: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6435: push(@{$changes{'cansearch'}},$type);
6436: }
1.23 raeburn 6437: }
1.26 raeburn 6438: } else {
6439: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6440: }
6441: }
6442:
6443: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6444: foreach my $by (@{$currdirsrch{'searchby'}}) {
6445: if (!grep(/^\Q$by\E$/,@searchby)) {
6446: push(@{$changes{'searchby'}},$by);
6447: }
6448: }
6449: foreach my $by (@searchby) {
6450: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6451: push(@{$changes{'searchby'}},$by);
6452: }
6453: }
6454: } else {
6455: push(@{$changes{'searchby'}},@searchby);
6456: }
1.25 raeburn 6457:
6458: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6459: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6460: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6461: push(@{$changes{'searchtypes'}},$type);
6462: }
6463: }
6464: foreach my $type (@searchtypes) {
6465: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6466: push(@{$changes{'searchtypes'}},$type);
6467: }
6468: }
6469: } else {
6470: if (exists($currdirsrch{'searchtypes'})) {
6471: foreach my $type (@searchtypes) {
6472: if ($type ne $currdirsrch{'searchtypes'}) {
6473: push(@{$changes{'searchtypes'}},$type);
6474: }
6475: }
6476: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6477: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6478: }
6479: } else {
6480: push(@{$changes{'searchtypes'}},@searchtypes);
6481: }
6482: }
6483:
1.23 raeburn 6484: my %dirsrch_hash = (
6485: directorysrch => { available => $env{'form.dirsrch_available'},
6486: cansearch => \@cansearch,
1.24 raeburn 6487: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6488: searchby => \@searchby,
1.25 raeburn 6489: searchtypes => \@searchtypes,
1.23 raeburn 6490: }
6491: );
6492: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6493: $dom);
6494: if ($putresult eq 'ok') {
6495: if (exists($currdirsrch{'available'})) {
6496: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6497: $changes{'available'} = 1;
6498: }
6499: } else {
6500: if ($env{'form.dirsrch_available'} eq '1') {
6501: $changes{'available'} = 1;
6502: }
6503: }
1.24 raeburn 6504: if (exists($currdirsrch{'localonly'})) {
6505: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6506: $changes{'localonly'} = 1;
6507: }
6508: } else {
6509: if ($env{'form.dirsrch_localonly'} eq '1') {
6510: $changes{'localonly'} = 1;
6511: }
6512: }
1.23 raeburn 6513: if (keys(%changes) > 0) {
6514: $resulttext = &mt('Changes made:').'<ul>';
6515: if ($changes{'available'}) {
6516: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6517: }
1.24 raeburn 6518: if ($changes{'localonly'}) {
6519: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6520: }
6521:
1.23 raeburn 6522: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6523: my $chgtext;
1.26 raeburn 6524: if (ref($usertypes) eq 'HASH') {
6525: if (keys(%{$usertypes}) > 0) {
6526: foreach my $type (@{$types}) {
6527: if (grep(/^\Q$type\E$/,@cansearch)) {
6528: $chgtext .= $usertypes->{$type}.'; ';
6529: }
6530: }
6531: if (grep(/^default$/,@cansearch)) {
6532: $chgtext .= $othertitle;
6533: } else {
6534: $chgtext =~ s/\; $//;
6535: }
1.160.6.13 raeburn 6536: $resulttext .=
6537: '<li>'.
6538: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6539: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6540: '</li>';
1.23 raeburn 6541: }
6542: }
6543: }
6544: if (ref($changes{'searchby'}) eq 'ARRAY') {
6545: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6546: my $chgtext;
6547: foreach my $type (@{$titleorder}) {
6548: if (grep(/^\Q$type\E$/,@searchby)) {
6549: if (defined($searchtitles->{$type})) {
6550: $chgtext .= $searchtitles->{$type}.'; ';
6551: }
6552: }
6553: }
6554: $chgtext =~ s/\; $//;
6555: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6556: }
1.25 raeburn 6557: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6558: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6559: my $chgtext;
6560: foreach my $type (@{$srchtypeorder}) {
6561: if (grep(/^\Q$type\E$/,@searchtypes)) {
6562: if (defined($srchtypes_desc->{$type})) {
6563: $chgtext .= $srchtypes_desc->{$type}.'; ';
6564: }
6565: }
6566: }
6567: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 6568: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6569: }
6570: $resulttext .= '</ul>';
6571: } else {
6572: $resulttext = &mt('No changes made to institution directory search settings');
6573: }
6574: } else {
6575: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6576: &mt('An error occurred: [_1]',$putresult).'</span>';
6577: }
6578: return $resulttext;
6579: }
6580:
1.28 raeburn 6581: sub modify_contacts {
6582: my ($dom,%domconfig) = @_;
6583: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6584: if (ref($domconfig{'contacts'}) eq 'HASH') {
6585: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6586: $currsetting{$key} = $domconfig{'contacts'}{$key};
6587: }
6588: }
1.134 raeburn 6589: my (%others,%to,%bcc);
1.28 raeburn 6590: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6591: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.15 raeburn 6592: 'requestsmail','updatesmail');
1.28 raeburn 6593: foreach my $type (@mailings) {
6594: @{$newsetting{$type}} =
6595: &Apache::loncommon::get_env_multiple('form.'.$type);
6596: foreach my $item (@contacts) {
6597: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6598: $contacts_hash{contacts}{$type}{$item} = 1;
6599: } else {
6600: $contacts_hash{contacts}{$type}{$item} = 0;
6601: }
6602: }
6603: $others{$type} = $env{'form.'.$type.'_others'};
6604: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6605: if ($type eq 'helpdeskmail') {
6606: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6607: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6608: }
1.28 raeburn 6609: }
6610: foreach my $item (@contacts) {
6611: $to{$item} = $env{'form.'.$item};
6612: $contacts_hash{'contacts'}{$item} = $to{$item};
6613: }
6614: if (keys(%currsetting) > 0) {
6615: foreach my $item (@contacts) {
6616: if ($to{$item} ne $currsetting{$item}) {
6617: $changes{$item} = 1;
6618: }
6619: }
6620: foreach my $type (@mailings) {
6621: foreach my $item (@contacts) {
6622: if (ref($currsetting{$type}) eq 'HASH') {
6623: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6624: push(@{$changes{$type}},$item);
6625: }
6626: } else {
6627: push(@{$changes{$type}},@{$newsetting{$type}});
6628: }
6629: }
6630: if ($others{$type} ne $currsetting{$type}{'others'}) {
6631: push(@{$changes{$type}},'others');
6632: }
1.134 raeburn 6633: if ($type eq 'helpdeskmail') {
6634: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6635: push(@{$changes{$type}},'bcc');
6636: }
6637: }
1.28 raeburn 6638: }
6639: } else {
6640: my %default;
6641: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6642: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6643: $default{'errormail'} = 'adminemail';
6644: $default{'packagesmail'} = 'adminemail';
6645: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6646: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6647: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 6648: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6649: foreach my $item (@contacts) {
6650: if ($to{$item} ne $default{$item}) {
6651: $changes{$item} = 1;
6652: }
6653: }
6654: foreach my $type (@mailings) {
6655: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6656:
6657: push(@{$changes{$type}},@{$newsetting{$type}});
6658: }
6659: if ($others{$type} ne '') {
6660: push(@{$changes{$type}},'others');
1.134 raeburn 6661: }
6662: if ($type eq 'helpdeskmail') {
6663: if ($bcc{$type} ne '') {
6664: push(@{$changes{$type}},'bcc');
6665: }
6666: }
1.28 raeburn 6667: }
6668: }
6669: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6670: $dom);
6671: if ($putresult eq 'ok') {
6672: if (keys(%changes) > 0) {
6673: my ($titles,$short_titles) = &contact_titles();
6674: $resulttext = &mt('Changes made:').'<ul>';
6675: foreach my $item (@contacts) {
6676: if ($changes{$item}) {
6677: $resulttext .= '<li>'.$titles->{$item}.
6678: &mt(' set to: ').
6679: '<span class="LC_cusr_emph">'.
6680: $to{$item}.'</span></li>';
6681: }
6682: }
6683: foreach my $type (@mailings) {
6684: if (ref($changes{$type}) eq 'ARRAY') {
6685: $resulttext .= '<li>'.$titles->{$type}.': ';
6686: my @text;
6687: foreach my $item (@{$newsetting{$type}}) {
6688: push(@text,$short_titles->{$item});
6689: }
6690: if ($others{$type} ne '') {
6691: push(@text,$others{$type});
6692: }
6693: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6694: join(', ',@text).'</span>';
6695: if ($type eq 'helpdeskmail') {
6696: if ($bcc{$type} ne '') {
6697: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6698: }
6699: }
6700: $resulttext .= '</li>';
1.28 raeburn 6701: }
6702: }
6703: $resulttext .= '</ul>';
6704: } else {
1.34 raeburn 6705: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6706: }
6707: } else {
6708: $resulttext = '<span class="LC_error">'.
6709: &mt('An error occurred: [_1].',$putresult).'</span>';
6710: }
6711: return $resulttext;
6712: }
6713:
6714: sub modify_usercreation {
1.27 raeburn 6715: my ($dom,%domconfig) = @_;
1.34 raeburn 6716: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6717: my $warningmsg;
1.27 raeburn 6718: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6719: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6720: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6721: }
6722: }
6723: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6724: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6725: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6726: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6727: foreach my $item(@contexts) {
1.45 raeburn 6728: if ($item eq 'selfcreate') {
1.50 raeburn 6729: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6730: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6731: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6732: if (ref($cancreate{$item}) eq 'ARRAY') {
6733: if (grep(/^login$/,@{$cancreate{$item}})) {
6734: $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.');
6735: }
1.43 raeburn 6736: }
6737: }
1.50 raeburn 6738: } else {
6739: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6740: }
1.34 raeburn 6741: }
1.93 raeburn 6742: my ($othertitle,$usertypes,$types) =
6743: &Apache::loncommon::sorted_inst_types($dom);
6744: if (ref($types) eq 'ARRAY') {
6745: if (@{$types} > 0) {
6746: @{$cancreate{'statustocreate'}} =
6747: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6748: } else {
6749: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6750: }
6751: push(@contexts,'statustocreate');
6752: }
1.160.6.5 raeburn 6753: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6754: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6755: foreach my $item (@contexts) {
1.93 raeburn 6756: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6757: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6758: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6759: if (ref($cancreate{$item}) eq 'ARRAY') {
6760: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6761: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6762: push(@{$changes{'cancreate'}},$item);
6763: }
1.50 raeburn 6764: }
6765: }
6766: }
6767: } else {
6768: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6769: if (@{$cancreate{$item}} > 0) {
6770: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6771: push(@{$changes{'cancreate'}},$item);
6772: }
6773: }
6774: } else {
6775: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6776: if (@{$cancreate{$item}} < 3) {
6777: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6778: push(@{$changes{'cancreate'}},$item);
6779: }
6780: }
6781: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6782: if (@{$cancreate{$item}} > 0) {
6783: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6784: push(@{$changes{'cancreate'}},$item);
6785: }
6786: }
6787: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6788: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6789: push(@{$changes{'cancreate'}},$item);
6790: }
6791: }
6792: }
6793: }
6794: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6795: foreach my $type (@{$cancreate{$item}}) {
6796: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6797: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6798: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6799: push(@{$changes{'cancreate'}},$item);
6800: }
6801: }
6802: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6803: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6804: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6805: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6806: push(@{$changes{'cancreate'}},$item);
6807: }
6808: }
6809: }
6810: }
6811: }
6812: } else {
6813: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6814: push(@{$changes{'cancreate'}},$item);
6815: }
6816: }
1.27 raeburn 6817: }
1.34 raeburn 6818: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6819: foreach my $item (@contexts) {
1.43 raeburn 6820: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6821: if ($cancreate{$item} ne 'any') {
6822: push(@{$changes{'cancreate'}},$item);
6823: }
6824: } else {
6825: if ($cancreate{$item} ne 'none') {
6826: push(@{$changes{'cancreate'}},$item);
6827: }
1.27 raeburn 6828: }
6829: }
6830: } else {
1.43 raeburn 6831: foreach my $item (@contexts) {
1.34 raeburn 6832: push(@{$changes{'cancreate'}},$item);
6833: }
1.27 raeburn 6834: }
1.34 raeburn 6835:
1.27 raeburn 6836: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6837: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6838: if (!grep(/^\Q$type\E$/,@username_rule)) {
6839: push(@{$changes{'username_rule'}},$type);
6840: }
6841: }
6842: foreach my $type (@username_rule) {
6843: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6844: push(@{$changes{'username_rule'}},$type);
6845: }
6846: }
6847: } else {
6848: push(@{$changes{'username_rule'}},@username_rule);
6849: }
6850:
1.32 raeburn 6851: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6852: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6853: if (!grep(/^\Q$type\E$/,@id_rule)) {
6854: push(@{$changes{'id_rule'}},$type);
6855: }
6856: }
6857: foreach my $type (@id_rule) {
6858: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6859: push(@{$changes{'id_rule'}},$type);
6860: }
6861: }
6862: } else {
6863: push(@{$changes{'id_rule'}},@id_rule);
6864: }
6865:
1.43 raeburn 6866: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6867: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6868: if (!grep(/^\Q$type\E$/,@email_rule)) {
6869: push(@{$changes{'email_rule'}},$type);
6870: }
6871: }
6872: foreach my $type (@email_rule) {
6873: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6874: push(@{$changes{'email_rule'}},$type);
6875: }
6876: }
6877: } else {
6878: push(@{$changes{'email_rule'}},@email_rule);
6879: }
6880:
6881: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6882: my @authtypes = ('int','krb4','krb5','loc');
6883: my %authhash;
1.43 raeburn 6884: foreach my $item (@authen_contexts) {
1.28 raeburn 6885: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6886: foreach my $auth (@authtypes) {
6887: if (grep(/^\Q$auth\E$/,@authallowed)) {
6888: $authhash{$item}{$auth} = 1;
6889: } else {
6890: $authhash{$item}{$auth} = 0;
6891: }
6892: }
6893: }
6894: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6895: foreach my $item (@authen_contexts) {
1.28 raeburn 6896: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6897: foreach my $auth (@authtypes) {
6898: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6899: push(@{$changes{'authtypes'}},$item);
6900: last;
6901: }
6902: }
6903: }
6904: }
6905: } else {
1.43 raeburn 6906: foreach my $item (@authen_contexts) {
1.28 raeburn 6907: push(@{$changes{'authtypes'}},$item);
6908: }
6909: }
6910:
1.27 raeburn 6911: my %usercreation_hash = (
1.28 raeburn 6912: usercreation => {
1.34 raeburn 6913: cancreate => \%cancreate,
1.27 raeburn 6914: username_rule => \@username_rule,
1.32 raeburn 6915: id_rule => \@id_rule,
1.43 raeburn 6916: email_rule => \@email_rule,
1.32 raeburn 6917: authtypes => \%authhash,
1.27 raeburn 6918: }
6919: );
6920:
6921: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6922: $dom);
1.50 raeburn 6923:
6924: my %selfcreatetypes = (
6925: sso => 'users authenticated by institutional single sign on',
6926: login => 'users authenticated by institutional log-in',
6927: email => 'users who provide a valid e-mail address for use as the username',
6928: );
1.27 raeburn 6929: if ($putresult eq 'ok') {
6930: if (keys(%changes) > 0) {
6931: $resulttext = &mt('Changes made:').'<ul>';
6932: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6933: my %lt = &usercreation_types();
6934: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6935: my $chgtext;
1.160.6.5 raeburn 6936: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6937: $chgtext = $lt{$type}.', ';
6938: }
1.45 raeburn 6939: if ($type eq 'selfcreate') {
1.50 raeburn 6940: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6941: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6942: } else {
1.100 raeburn 6943: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6944: foreach my $case (@{$cancreate{$type}}) {
6945: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6946: }
6947: $chgtext .= '</ul>';
1.100 raeburn 6948: if (ref($cancreate{$type}) eq 'ARRAY') {
6949: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6950: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6951: if (@{$cancreate{'statustocreate'}} == 0) {
6952: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6953: }
6954: }
6955: }
6956: }
1.43 raeburn 6957: }
1.93 raeburn 6958: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6959: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6960: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6961: if (@{$cancreate{'selfcreate'}} > 0) {
6962: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6963:
6964: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6965: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6966: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6967: }
1.96 raeburn 6968: } elsif (ref($usertypes) eq 'HASH') {
6969: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6970: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6971: } else {
6972: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6973: }
6974: $chgtext .= '<ul>';
6975: foreach my $case (@{$cancreate{$type}}) {
6976: if ($case eq 'default') {
6977: $chgtext .= '<li>'.$othertitle.'</li>';
6978: } else {
6979: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6980: }
6981: }
1.100 raeburn 6982: $chgtext .= '</ul>';
6983: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6984: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6985: }
6986: }
6987: } else {
6988: if (@{$cancreate{$type}} == 0) {
6989: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6990: } else {
6991: $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 6992: }
6993: }
6994: }
1.160.6.5 raeburn 6995: } elsif ($type eq 'captcha') {
6996: if ($cancreate{$type} eq 'notused') {
6997: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6998: } else {
6999: my %captchas = &captcha_phrases();
7000: if ($captchas{$cancreate{$type}}) {
7001: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7002: } else {
7003: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7004: }
7005: }
7006: } elsif ($type eq 'recaptchakeys') {
7007: my ($privkey,$pubkey);
7008: if (ref($cancreate{$type}) eq 'HASH') {
7009: $pubkey = $cancreate{$type}{'public'};
7010: $privkey = $cancreate{$type}{'private'};
7011: }
7012: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7013: if (!$pubkey) {
7014: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7015: } else {
7016: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7017: }
7018: if (!$privkey) {
7019: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7020: } else {
7021: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7022: }
7023: $chgtext .= '</ul>';
1.43 raeburn 7024: } else {
7025: if ($cancreate{$type} eq 'none') {
7026: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7027: } elsif ($cancreate{$type} eq 'any') {
7028: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7029: } elsif ($cancreate{$type} eq 'official') {
7030: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7031: } elsif ($cancreate{$type} eq 'unofficial') {
7032: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7033: }
1.34 raeburn 7034: }
7035: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7036: }
7037: }
7038: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7039: my ($rules,$ruleorder) =
7040: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7041: my $chgtext = '<ul>';
7042: foreach my $type (@username_rule) {
7043: if (ref($rules->{$type}) eq 'HASH') {
7044: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7045: }
7046: }
7047: $chgtext .= '</ul>';
7048: if (@username_rule > 0) {
7049: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7050: } else {
1.28 raeburn 7051: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7052: }
7053: }
1.32 raeburn 7054: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7055: my ($idrules,$idruleorder) =
7056: &Apache::lonnet::inst_userrules($dom,'id');
7057: my $chgtext = '<ul>';
7058: foreach my $type (@id_rule) {
7059: if (ref($idrules->{$type}) eq 'HASH') {
7060: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7061: }
7062: }
7063: $chgtext .= '</ul>';
7064: if (@id_rule > 0) {
7065: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7066: } else {
7067: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7068: }
7069: }
1.43 raeburn 7070: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7071: my ($emailrules,$emailruleorder) =
7072: &Apache::lonnet::inst_userrules($dom,'email');
7073: my $chgtext = '<ul>';
7074: foreach my $type (@email_rule) {
7075: if (ref($emailrules->{$type}) eq 'HASH') {
7076: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7077: }
7078: }
7079: $chgtext .= '</ul>';
7080: if (@email_rule > 0) {
7081: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7082: } else {
7083: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7084: }
7085: }
7086:
1.28 raeburn 7087: my %authname = &authtype_names();
7088: my %context_title = &context_names();
7089: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7090: my $chgtext = '<ul>';
7091: foreach my $type (@{$changes{'authtypes'}}) {
7092: my @allowed;
7093: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7094: foreach my $auth (@authtypes) {
7095: if ($authhash{$type}{$auth}) {
7096: push(@allowed,$authname{$auth});
7097: }
7098: }
1.43 raeburn 7099: if (@allowed > 0) {
7100: $chgtext .= join(', ',@allowed).'</li>';
7101: } else {
7102: $chgtext .= &mt('none').'</li>';
7103: }
1.28 raeburn 7104: }
7105: $chgtext .= '</ul>';
7106: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7107: $resulttext .= '</li>';
7108: }
1.27 raeburn 7109: $resulttext .= '</ul>';
7110: } else {
1.28 raeburn 7111: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7112: }
7113: } else {
7114: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7115: &mt('An error occurred: [_1]',$putresult).'</span>';
7116: }
1.43 raeburn 7117: if ($warningmsg ne '') {
7118: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7119: }
1.23 raeburn 7120: return $resulttext;
7121: }
7122:
1.160.6.5 raeburn 7123: sub process_captcha {
7124: my ($container,$changes,$newsettings,$current) = @_;
7125: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7126: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7127: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7128: $newsettings->{'captcha'} = 'original';
7129: }
7130: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7131: if ($container eq 'cancreate') {
7132: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7133: push(@{$changes->{'cancreate'}},'captcha');
7134: } elsif (!defined($changes->{'cancreate'})) {
7135: $changes->{'cancreate'} = ['captcha'];
7136: }
7137: } else {
7138: $changes->{'captcha'} = 1;
7139: }
7140: }
7141: my ($newpub,$newpriv,$currpub,$currpriv);
7142: if ($newsettings->{'captcha'} eq 'recaptcha') {
7143: $newpub = $env{'form.'.$container.'_recaptchapub'};
7144: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7145: $newpub =~ s/\W//g;
7146: $newpriv =~ s/\W//g;
7147: $newsettings->{'recaptchakeys'} = {
7148: public => $newpub,
7149: private => $newpriv,
7150: };
7151: }
7152: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7153: $currpub = $current->{'recaptchakeys'}{'public'};
7154: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7155: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7156: $newsettings->{'recaptchakeys'} = {
7157: public => '',
7158: private => '',
7159: }
7160: }
1.160.6.5 raeburn 7161: }
7162: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7163: if ($container eq 'cancreate') {
7164: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7165: push(@{$changes->{'cancreate'}},'recaptchakeys');
7166: } elsif (!defined($changes->{'cancreate'})) {
7167: $changes->{'cancreate'} = ['recaptchakeys'];
7168: }
7169: } else {
7170: $changes->{'recaptchakeys'} = 1;
7171: }
7172: }
7173: return;
7174: }
7175:
1.33 raeburn 7176: sub modify_usermodification {
7177: my ($dom,%domconfig) = @_;
7178: my ($resulttext,%curr_usermodification,%changes);
7179: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7180: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7181: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7182: }
7183: }
1.63 raeburn 7184: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7185: my %context_title = (
7186: author => 'In author context',
7187: course => 'In course context',
1.63 raeburn 7188: selfcreate => 'When self creating account',
1.33 raeburn 7189: );
7190: my @fields = ('lastname','firstname','middlename','generation',
7191: 'permanentemail','id');
7192: my %roles = (
7193: author => ['ca','aa'],
7194: course => ['st','ep','ta','in','cr'],
7195: );
1.63 raeburn 7196: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7197: if (ref($types) eq 'ARRAY') {
7198: push(@{$types},'default');
7199: $usertypes->{'default'} = $othertitle;
7200: }
7201: $roles{'selfcreate'} = $types;
1.33 raeburn 7202: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7203: my %modifyhash;
7204: foreach my $context (@contexts) {
7205: foreach my $role (@{$roles{$context}}) {
7206: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7207: foreach my $item (@fields) {
7208: if (grep(/^\Q$item\E$/,@modifiable)) {
7209: $modifyhash{$context}{$role}{$item} = 1;
7210: } else {
7211: $modifyhash{$context}{$role}{$item} = 0;
7212: }
7213: }
7214: }
7215: if (ref($curr_usermodification{$context}) eq 'HASH') {
7216: foreach my $role (@{$roles{$context}}) {
7217: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7218: foreach my $field (@fields) {
7219: if ($modifyhash{$context}{$role}{$field} ne
7220: $curr_usermodification{$context}{$role}{$field}) {
7221: push(@{$changes{$context}},$role);
7222: last;
7223: }
7224: }
7225: }
7226: }
7227: } else {
7228: foreach my $context (@contexts) {
7229: foreach my $role (@{$roles{$context}}) {
7230: push(@{$changes{$context}},$role);
7231: }
7232: }
7233: }
7234: }
7235: my %usermodification_hash = (
7236: usermodification => \%modifyhash,
7237: );
7238: my $putresult = &Apache::lonnet::put_dom('configuration',
7239: \%usermodification_hash,$dom);
7240: if ($putresult eq 'ok') {
7241: if (keys(%changes) > 0) {
7242: $resulttext = &mt('Changes made: ').'<ul>';
7243: foreach my $context (@contexts) {
7244: if (ref($changes{$context}) eq 'ARRAY') {
7245: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7246: if (ref($changes{$context}) eq 'ARRAY') {
7247: foreach my $role (@{$changes{$context}}) {
7248: my $rolename;
1.63 raeburn 7249: if ($context eq 'selfcreate') {
7250: $rolename = $role;
7251: if (ref($usertypes) eq 'HASH') {
7252: if ($usertypes->{$role} ne '') {
7253: $rolename = $usertypes->{$role};
7254: }
7255: }
1.33 raeburn 7256: } else {
1.63 raeburn 7257: if ($role eq 'cr') {
7258: $rolename = &mt('Custom');
7259: } else {
7260: $rolename = &Apache::lonnet::plaintext($role);
7261: }
1.33 raeburn 7262: }
7263: my @modifiable;
1.63 raeburn 7264: if ($context eq 'selfcreate') {
1.126 bisitz 7265: $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 7266: } else {
7267: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7268: }
1.33 raeburn 7269: foreach my $field (@fields) {
7270: if ($modifyhash{$context}{$role}{$field}) {
7271: push(@modifiable,$fieldtitles{$field});
7272: }
7273: }
7274: if (@modifiable > 0) {
7275: $resulttext .= join(', ',@modifiable);
7276: } else {
7277: $resulttext .= &mt('none');
7278: }
7279: $resulttext .= '</li>';
7280: }
7281: $resulttext .= '</ul></li>';
7282: }
7283: }
7284: }
7285: $resulttext .= '</ul>';
7286: } else {
7287: $resulttext = &mt('No changes made to user modification settings');
7288: }
7289: } else {
7290: $resulttext = '<span class="LC_error">'.
7291: &mt('An error occurred: [_1]',$putresult).'</span>';
7292: }
7293: return $resulttext;
7294: }
7295:
1.43 raeburn 7296: sub modify_defaults {
7297: my ($dom,$r) = @_;
7298: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7299: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7300: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7301: my @authtypes = ('internal','krb4','krb5','localauth');
7302: foreach my $item (@items) {
7303: $newvalues{$item} = $env{'form.'.$item};
7304: if ($item eq 'auth_def') {
7305: if ($newvalues{$item} ne '') {
7306: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7307: push(@errors,$item);
7308: }
7309: }
7310: } elsif ($item eq 'lang_def') {
7311: if ($newvalues{$item} ne '') {
7312: if ($newvalues{$item} =~ /^(\w+)/) {
7313: my $langcode = $1;
1.103 raeburn 7314: if ($langcode ne 'x_chef') {
7315: if (code2language($langcode) eq '') {
7316: push(@errors,$item);
7317: }
1.43 raeburn 7318: }
7319: } else {
7320: push(@errors,$item);
7321: }
7322: }
1.54 raeburn 7323: } elsif ($item eq 'timezone_def') {
7324: if ($newvalues{$item} ne '') {
1.62 raeburn 7325: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7326: push(@errors,$item);
7327: }
7328: }
1.68 raeburn 7329: } elsif ($item eq 'datelocale_def') {
7330: if ($newvalues{$item} ne '') {
7331: my @datelocale_ids = DateTime::Locale->ids();
7332: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7333: push(@errors,$item);
7334: }
7335: }
1.141 raeburn 7336: } elsif ($item eq 'portal_def') {
7337: if ($newvalues{$item} ne '') {
7338: 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])\/?$/) {
7339: push(@errors,$item);
7340: }
7341: }
1.43 raeburn 7342: }
7343: if (grep(/^\Q$item\E$/,@errors)) {
7344: $newvalues{$item} = $domdefaults{$item};
7345: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7346: $changes{$item} = 1;
7347: }
1.72 raeburn 7348: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7349: }
7350: my %defaults_hash = (
1.72 raeburn 7351: defaults => \%newvalues,
7352: );
1.43 raeburn 7353: my $title = &defaults_titles();
7354: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7355: $dom);
7356: if ($putresult eq 'ok') {
7357: if (keys(%changes) > 0) {
7358: $resulttext = &mt('Changes made:').'<ul>';
7359: my $version = $r->dir_config('lonVersion');
7360: 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";
7361: foreach my $item (sort(keys(%changes))) {
7362: my $value = $env{'form.'.$item};
7363: if ($value eq '') {
7364: $value = &mt('none');
7365: } elsif ($item eq 'auth_def') {
7366: my %authnames = &authtype_names();
7367: my %shortauth = (
7368: internal => 'int',
7369: krb4 => 'krb4',
7370: krb5 => 'krb5',
7371: localauth => 'loc',
7372: );
7373: $value = $authnames{$shortauth{$value}};
7374: }
7375: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7376: $mailmsgtext .= "$title->{$item} set to $value\n";
7377: }
7378: $resulttext .= '</ul>';
7379: $mailmsgtext .= "\n";
7380: my $cachetime = 24*60*60;
1.72 raeburn 7381: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7382: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7383: my $sysmail = $r->dir_config('lonSysEMail');
7384: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7385: }
1.43 raeburn 7386: } else {
1.54 raeburn 7387: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7388: }
7389: } else {
7390: $resulttext = '<span class="LC_error">'.
7391: &mt('An error occurred: [_1]',$putresult).'</span>';
7392: }
7393: if (@errors > 0) {
7394: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7395: foreach my $item (@errors) {
7396: $resulttext .= ' "'.$title->{$item}.'",';
7397: }
7398: $resulttext =~ s/,$//;
7399: }
7400: return $resulttext;
7401: }
7402:
1.46 raeburn 7403: sub modify_scantron {
1.48 raeburn 7404: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7405: my ($resulttext,%confhash,%changes,$errors);
7406: my $custom = 'custom.tab';
7407: my $default = 'default.tab';
7408: my $servadm = $r->dir_config('lonAdmEMail');
7409: my ($configuserok,$author_ok,$switchserver) =
7410: &config_check($dom,$confname,$servadm);
7411: if ($env{'form.scantronformat.filename'} ne '') {
7412: my $error;
7413: if ($configuserok eq 'ok') {
7414: if ($switchserver) {
1.130 raeburn 7415: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7416: } else {
7417: if ($author_ok eq 'ok') {
7418: my ($result,$scantronurl) =
7419: &publishlogo($r,'upload','scantronformat',$dom,
7420: $confname,'scantron','','',$custom);
7421: if ($result eq 'ok') {
7422: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7423: $changes{'scantronformat'} = 1;
1.46 raeburn 7424: } else {
7425: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7426: }
7427: } else {
7428: $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);
7429: }
7430: }
7431: } else {
7432: $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);
7433: }
7434: if ($error) {
7435: &Apache::lonnet::logthis($error);
7436: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7437: }
7438: }
1.48 raeburn 7439: if (ref($domconfig{'scantron'}) eq 'HASH') {
7440: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7441: if ($env{'form.scantronformat_del'}) {
7442: $confhash{'scantron'}{'scantronformat'} = '';
7443: $changes{'scantronformat'} = 1;
1.46 raeburn 7444: }
7445: }
7446: }
7447: if (keys(%confhash) > 0) {
7448: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7449: $dom);
7450: if ($putresult eq 'ok') {
7451: if (keys(%changes) > 0) {
1.48 raeburn 7452: if (ref($confhash{'scantron'}) eq 'HASH') {
7453: $resulttext = &mt('Changes made:').'<ul>';
7454: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7455: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7456: } else {
1.130 raeburn 7457: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7458: }
1.48 raeburn 7459: $resulttext .= '</ul>';
7460: } else {
1.130 raeburn 7461: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7462: }
7463: $resulttext .= '</ul>';
7464: &Apache::loncommon::devalidate_domconfig_cache($dom);
7465: } else {
1.130 raeburn 7466: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7467: }
7468: } else {
7469: $resulttext = '<span class="LC_error">'.
7470: &mt('An error occurred: [_1]',$putresult).'</span>';
7471: }
7472: } else {
1.130 raeburn 7473: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7474: }
7475: if ($errors) {
7476: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7477: $errors.'</ul>';
7478: }
7479: return $resulttext;
7480: }
7481:
1.48 raeburn 7482: sub modify_coursecategories {
7483: my ($dom,%domconfig) = @_;
1.57 raeburn 7484: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7485: $cathash);
1.48 raeburn 7486: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7487: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7488: $cathash = $domconfig{'coursecategories'}{'cats'};
7489: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7490: $changes{'togglecats'} = 1;
7491: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7492: }
7493: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7494: $changes{'categorize'} = 1;
7495: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7496: }
1.120 raeburn 7497: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7498: $changes{'togglecatscomm'} = 1;
7499: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7500: }
7501: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7502: $changes{'categorizecomm'} = 1;
7503: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7504: }
1.57 raeburn 7505: } else {
7506: $changes{'togglecats'} = 1;
7507: $changes{'categorize'} = 1;
1.124 raeburn 7508: $changes{'togglecatscomm'} = 1;
7509: $changes{'categorizecomm'} = 1;
1.87 raeburn 7510: $domconfig{'coursecategories'} = {
7511: togglecats => $env{'form.togglecats'},
7512: categorize => $env{'form.categorize'},
1.124 raeburn 7513: togglecatscomm => $env{'form.togglecatscomm'},
7514: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7515: };
1.57 raeburn 7516: }
7517: if (ref($cathash) eq 'HASH') {
7518: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7519: push (@deletecategory,'instcode::0');
7520: }
1.120 raeburn 7521: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7522: push(@deletecategory,'communities::0');
7523: }
1.48 raeburn 7524: }
1.57 raeburn 7525: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7526: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7527: if (@deletecategory > 0) {
7528: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7529: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7530: foreach my $item (@deletecategory) {
1.57 raeburn 7531: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7532: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7533: $deletions{$item} = 1;
1.57 raeburn 7534: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7535: }
7536: }
7537: }
1.57 raeburn 7538: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7539: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7540: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7541: $reorderings{$item} = 1;
1.57 raeburn 7542: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7543: }
7544: if ($env{'form.addcategory_name_'.$item} ne '') {
7545: my $newcat = $env{'form.addcategory_name_'.$item};
7546: my $newdepth = $depth+1;
7547: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7548: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7549: $adds{$newitem} = 1;
7550: }
7551: if ($env{'form.subcat_'.$item} ne '') {
7552: my $newcat = $env{'form.subcat_'.$item};
7553: my $newdepth = $depth+1;
7554: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7555: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7556: $adds{$newitem} = 1;
7557: }
7558: }
7559: }
7560: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7561: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7562: my $newitem = 'instcode::0';
1.57 raeburn 7563: if ($cathash->{$newitem} eq '') {
7564: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7565: $adds{$newitem} = 1;
7566: }
7567: } else {
7568: my $newitem = 'instcode::0';
1.57 raeburn 7569: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7570: $adds{$newitem} = 1;
7571: }
7572: }
1.120 raeburn 7573: if ($env{'form.communities'} eq '1') {
7574: if (ref($cathash) eq 'HASH') {
7575: my $newitem = 'communities::0';
7576: if ($cathash->{$newitem} eq '') {
7577: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7578: $adds{$newitem} = 1;
7579: }
7580: } else {
7581: my $newitem = 'communities::0';
7582: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7583: $adds{$newitem} = 1;
7584: }
7585: }
1.48 raeburn 7586: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7587: if (($env{'form.addcategory_name'} ne 'instcode') &&
7588: ($env{'form.addcategory_name'} ne 'communities')) {
7589: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7590: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7591: $adds{$newitem} = 1;
7592: }
1.48 raeburn 7593: }
1.57 raeburn 7594: my $putresult;
1.48 raeburn 7595: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7596: if (keys(%deletions) > 0) {
7597: foreach my $key (keys(%deletions)) {
7598: if ($predelallitems{$key} ne '') {
7599: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7600: }
7601: }
7602: }
7603: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7604: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7605: if (ref($chkcats[0]) eq 'ARRAY') {
7606: my $depth = 0;
7607: my $chg = 0;
7608: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7609: my $name = $chkcats[0][$i];
7610: my $item;
7611: if ($name eq '') {
7612: $chg ++;
7613: } else {
7614: $item = &escape($name).'::0';
7615: if ($chg) {
1.57 raeburn 7616: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7617: }
7618: $depth ++;
1.57 raeburn 7619: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7620: $depth --;
7621: }
7622: }
7623: }
1.57 raeburn 7624: }
7625: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7626: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7627: if ($putresult eq 'ok') {
1.57 raeburn 7628: my %title = (
1.120 raeburn 7629: togglecats => 'Show/Hide a course in catalog',
7630: categorize => 'Assign a category to a course',
7631: togglecatscomm => 'Show/Hide a community in catalog',
7632: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7633: );
7634: my %level = (
1.120 raeburn 7635: dom => 'set in Domain ("Modify Course/Community")',
7636: crs => 'set in Course ("Course Configuration")',
7637: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7638: );
1.48 raeburn 7639: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7640: if ($changes{'togglecats'}) {
7641: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7642: }
7643: if ($changes{'categorize'}) {
7644: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7645: }
1.120 raeburn 7646: if ($changes{'togglecatscomm'}) {
7647: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7648: }
7649: if ($changes{'categorizecomm'}) {
7650: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7651: }
1.57 raeburn 7652: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7653: my $cathash;
7654: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7655: $cathash = $domconfig{'coursecategories'}{'cats'};
7656: } else {
7657: $cathash = {};
7658: }
7659: my (@cats,@trails,%allitems);
7660: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7661: if (keys(%deletions) > 0) {
7662: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7663: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7664: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7665: }
7666: $resulttext .= '</ul></li>';
7667: }
7668: if (keys(%reorderings) > 0) {
7669: my %sort_by_trail;
7670: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7671: foreach my $key (keys(%reorderings)) {
7672: if ($allitems{$key} ne '') {
7673: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7674: }
1.48 raeburn 7675: }
1.57 raeburn 7676: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7677: $resulttext .= '<li>'.$trails[$trail].'</li>';
7678: }
7679: $resulttext .= '</ul></li>';
1.48 raeburn 7680: }
1.57 raeburn 7681: if (keys(%adds) > 0) {
7682: my %sort_by_trail;
7683: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7684: foreach my $key (keys(%adds)) {
7685: if ($allitems{$key} ne '') {
7686: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7687: }
7688: }
7689: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7690: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7691: }
1.57 raeburn 7692: $resulttext .= '</ul></li>';
1.48 raeburn 7693: }
7694: }
7695: $resulttext .= '</ul>';
7696: } else {
7697: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7698: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7699: }
7700: } else {
1.120 raeburn 7701: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7702: }
7703: return $resulttext;
7704: }
7705:
1.69 raeburn 7706: sub modify_serverstatuses {
7707: my ($dom,%domconfig) = @_;
7708: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7709: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7710: %currserverstatus = %{$domconfig{'serverstatuses'}};
7711: }
7712: my @pages = &serverstatus_pages();
7713: foreach my $type (@pages) {
7714: $newserverstatus{$type}{'namedusers'} = '';
7715: $newserverstatus{$type}{'machines'} = '';
7716: if (defined($env{'form.'.$type.'_namedusers'})) {
7717: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7718: my @okusers;
7719: foreach my $user (@users) {
7720: my ($uname,$udom) = split(/:/,$user);
7721: if (($udom =~ /^$match_domain$/) &&
7722: (&Apache::lonnet::domain($udom)) &&
7723: ($uname =~ /^$match_username$/)) {
7724: if (!grep(/^\Q$user\E/,@okusers)) {
7725: push(@okusers,$user);
7726: }
7727: }
7728: }
7729: if (@okusers > 0) {
7730: @okusers = sort(@okusers);
7731: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7732: }
7733: }
7734: if (defined($env{'form.'.$type.'_machines'})) {
7735: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7736: my @okmachines;
7737: foreach my $ip (@machines) {
7738: my @parts = split(/\./,$ip);
7739: next if (@parts < 4);
7740: my $badip = 0;
7741: for (my $i=0; $i<4; $i++) {
7742: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7743: $badip = 1;
7744: last;
7745: }
7746: }
7747: if (!$badip) {
7748: push(@okmachines,$ip);
7749: }
7750: }
7751: @okmachines = sort(@okmachines);
7752: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7753: }
7754: }
7755: my %serverstatushash = (
7756: serverstatuses => \%newserverstatus,
7757: );
7758: foreach my $type (@pages) {
1.83 raeburn 7759: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7760: my (@current,@new);
1.83 raeburn 7761: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7762: if ($currserverstatus{$type}{$setting} ne '') {
7763: @current = split(/,/,$currserverstatus{$type}{$setting});
7764: }
7765: }
7766: if ($newserverstatus{$type}{$setting} ne '') {
7767: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7768: }
7769: if (@current > 0) {
7770: if (@new > 0) {
7771: foreach my $item (@current) {
7772: if (!grep(/^\Q$item\E$/,@new)) {
7773: $changes{$type}{$setting} = 1;
1.82 raeburn 7774: last;
7775: }
7776: }
1.84 raeburn 7777: foreach my $item (@new) {
7778: if (!grep(/^\Q$item\E$/,@current)) {
7779: $changes{$type}{$setting} = 1;
7780: last;
1.82 raeburn 7781: }
7782: }
7783: } else {
1.83 raeburn 7784: $changes{$type}{$setting} = 1;
1.69 raeburn 7785: }
1.83 raeburn 7786: } elsif (@new > 0) {
7787: $changes{$type}{$setting} = 1;
1.69 raeburn 7788: }
7789: }
7790: }
7791: if (keys(%changes) > 0) {
1.81 raeburn 7792: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7793: my $putresult = &Apache::lonnet::put_dom('configuration',
7794: \%serverstatushash,$dom);
7795: if ($putresult eq 'ok') {
7796: $resulttext .= &mt('Changes made:').'<ul>';
7797: foreach my $type (@pages) {
1.84 raeburn 7798: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7799: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7800: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7801: if ($newserverstatus{$type}{'namedusers'} eq '') {
7802: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7803: } else {
7804: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7805: }
1.84 raeburn 7806: }
7807: if ($changes{$type}{'machines'}) {
1.69 raeburn 7808: if ($newserverstatus{$type}{'machines'} eq '') {
7809: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7810: } else {
7811: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7812: }
7813:
7814: }
7815: $resulttext .= '</ul></li>';
7816: }
7817: }
7818: $resulttext .= '</ul>';
7819: } else {
7820: $resulttext = '<span class="LC_error">'.
7821: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7822:
7823: }
7824: } else {
7825: $resulttext = &mt('No changes made to access to server status pages');
7826: }
7827: return $resulttext;
7828: }
7829:
1.118 jms 7830: sub modify_helpsettings {
1.122 jms 7831: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7832: my ($resulttext,$errors,%changes,%helphash);
7833: my %defaultchecked = ('submitbugs' => 'on');
7834: my @offon = ('off','on');
1.118 jms 7835: my @toggles = ('submitbugs');
7836: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7837: foreach my $item (@toggles) {
1.160.6.5 raeburn 7838: if ($defaultchecked{$item} eq 'on') {
7839: if ($domconfig{'helpsettings'}{$item} eq '') {
7840: if ($env{'form.'.$item} eq '0') {
7841: $changes{$item} = 1;
7842: }
7843: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7844: $changes{$item} = 1;
7845: }
7846: } elsif ($defaultchecked{$item} eq 'off') {
7847: if ($domconfig{'helpsettings'}{$item} eq '') {
7848: if ($env{'form.'.$item} eq '1') {
7849: $changes{$item} = 1;
7850: }
7851: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7852: $changes{$item} = 1;
7853: }
7854: }
7855: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7856: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7857: }
7858: }
1.118 jms 7859: }
1.123 jms 7860: my $putresult;
7861: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7862: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7863: if ($putresult eq 'ok') {
7864: $resulttext = &mt('Changes made:').'<ul>';
7865: foreach my $item (sort(keys(%changes))) {
7866: if ($item eq 'submitbugs') {
7867: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7868: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7869: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7870: }
7871: }
7872: $resulttext .= '</ul>';
7873: } else {
7874: $resulttext = &mt('No changes made to help settings');
7875: $errors .= '<li><span class="LC_error">'.
7876: &mt('An error occurred storing the settings: [_1]',
7877: $putresult).'</span></li>';
7878: }
1.118 jms 7879: }
7880: if ($errors) {
1.160.6.5 raeburn 7881: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7882: $errors.'</ul>';
7883: }
7884: return $resulttext;
7885: }
7886:
1.121 raeburn 7887: sub modify_coursedefaults {
7888: my ($dom,%domconfig) = @_;
7889: my ($resulttext,$errors,%changes,%defaultshash);
7890: my %defaultchecked = ('canuse_pdfforms' => 'off');
7891: my @toggles = ('canuse_pdfforms');
7892:
7893: $defaultshash{'coursedefaults'} = {};
7894:
7895: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7896: if ($domconfig{'coursedefaults'} eq '') {
7897: $domconfig{'coursedefaults'} = {};
7898: }
7899: }
7900:
7901: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7902: foreach my $item (@toggles) {
7903: if ($defaultchecked{$item} eq 'on') {
7904: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7905: ($env{'form.'.$item} eq '0')) {
7906: $changes{$item} = 1;
1.160.6.16 raeburn 7907: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 7908: $changes{$item} = 1;
7909: }
7910: } elsif ($defaultchecked{$item} eq 'off') {
7911: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7912: ($env{'form.'.$item} eq '1')) {
7913: $changes{$item} = 1;
7914: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7915: $changes{$item} = 1;
7916: }
7917: }
7918: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7919: }
1.139 raeburn 7920: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7921: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7922: $newdefresponder =~ s/\D//g;
7923: if ($newdefresponder eq '' || $newdefresponder < 1) {
7924: $newdefresponder = 1;
7925: }
7926: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7927: if ($currdefresponder ne $newdefresponder) {
7928: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7929: $changes{'anonsurvey_threshold'} = 1;
7930: }
7931: }
1.160.6.16 raeburn 7932: my $officialcreds = $env{'form.official_credits'};
7933: $officialcreds =~ s/^[^\d\.]//g;
7934: my $unofficialcreds = $env{'form.unofficial_credits'};
7935: $unofficialcreds =~ s/^[^\d\.]//g;
7936: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
7937: ($env{'form.coursecredits'} eq '1')) {
7938: $changes{'coursecredits'} = 1;
7939: } else {
7940: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
7941: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
7942: $changes{'coursecredits'} = 1;
7943: }
7944: }
7945: $defaultshash{'coursedefaults'}{'coursecredits'} = {
7946: official => $officialcreds,
7947: unofficial => $unofficialcreds,
7948: }
1.121 raeburn 7949: }
7950: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7951: $dom);
7952: if ($putresult eq 'ok') {
1.160.6.16 raeburn 7953: my %domdefaults;
1.121 raeburn 7954: if (keys(%changes) > 0) {
1.160.6.16 raeburn 7955: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'})) {
7956: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7957: if ($changes{'canuse_pdfforms'}) {
7958: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7959: }
7960: if ($changes{'coursecredits'}) {
7961: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
7962: $domdefaults{'officialcredits'} =
7963: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
7964: $domdefaults{'unofficialcredits'} =
7965: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
7966: }
7967: }
1.121 raeburn 7968: my $cachetime = 24*60*60;
7969: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7970: }
7971: $resulttext = &mt('Changes made:').'<ul>';
7972: foreach my $item (sort(keys(%changes))) {
7973: if ($item eq 'canuse_pdfforms') {
7974: if ($env{'form.'.$item} eq '1') {
7975: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7976: } else {
7977: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7978: }
1.139 raeburn 7979: } elsif ($item eq 'anonsurvey_threshold') {
7980: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.16 raeburn 7981: } elsif ($item eq 'coursecredits') {
7982: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
7983: if (($domdefaults{'officialcredits'} eq '') &&
7984: ($domdefaults{'unofficialcredits'} eq '')) {
7985: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
7986: } else {
7987: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
7988: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
7989: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
7990: '</ul>'.
7991: '</li>';
7992: }
7993: } else {
7994: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
7995: }
1.140 raeburn 7996: }
1.121 raeburn 7997: }
7998: $resulttext .= '</ul>';
7999: } else {
8000: $resulttext = &mt('No changes made to course defaults');
8001: }
8002: } else {
8003: $resulttext = '<span class="LC_error">'.
8004: &mt('An error occurred: [_1]',$putresult).'</span>';
8005: }
8006: return $resulttext;
8007: }
8008:
1.137 raeburn 8009: sub modify_usersessions {
8010: my ($dom,%domconfig) = @_;
1.145 raeburn 8011: my @hostingtypes = ('version','excludedomain','includedomain');
8012: my @offloadtypes = ('primary','default');
8013: my %types = (
8014: remote => \@hostingtypes,
8015: hosted => \@hostingtypes,
8016: spares => \@offloadtypes,
8017: );
8018: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8019: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8020: my (%by_ip,%by_location,@intdoms);
8021: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8022: my @locations = sort(keys(%by_location));
1.137 raeburn 8023: my (%defaultshash,%changes);
8024: foreach my $prefix (@prefixes) {
8025: $defaultshash{'usersessions'}{$prefix} = {};
8026: }
8027: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8028: my $resulttext;
1.138 raeburn 8029: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8030: foreach my $prefix (@prefixes) {
1.145 raeburn 8031: next if ($prefix eq 'spares');
8032: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8033: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8034: if ($type eq 'version') {
8035: my $value = $env{'form.'.$prefix.'_'.$type};
8036: my $okvalue;
8037: if ($value ne '') {
8038: if (grep(/^\Q$value\E$/,@lcversions)) {
8039: $okvalue = $value;
8040: }
8041: }
8042: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8043: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8044: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8045: if ($inuse == 0) {
8046: $changes{$prefix}{$type} = 1;
8047: } else {
8048: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8049: $changes{$prefix}{$type} = 1;
8050: }
8051: if ($okvalue ne '') {
8052: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8053: }
8054: }
8055: } else {
8056: if (($inuse == 1) && ($okvalue ne '')) {
8057: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8058: $changes{$prefix}{$type} = 1;
8059: }
8060: }
8061: } else {
8062: if (($inuse == 1) && ($okvalue ne '')) {
8063: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8064: $changes{$prefix}{$type} = 1;
8065: }
8066: }
8067: } else {
8068: if (($inuse == 1) && ($okvalue ne '')) {
8069: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8070: $changes{$prefix}{$type} = 1;
8071: }
8072: }
8073: } else {
8074: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8075: my @okvals;
8076: foreach my $val (@vals) {
1.138 raeburn 8077: if ($val =~ /:/) {
8078: my @items = split(/:/,$val);
8079: foreach my $item (@items) {
8080: if (ref($by_location{$item}) eq 'ARRAY') {
8081: push(@okvals,$item);
8082: }
8083: }
8084: } else {
8085: if (ref($by_location{$val}) eq 'ARRAY') {
8086: push(@okvals,$val);
8087: }
1.137 raeburn 8088: }
8089: }
8090: @okvals = sort(@okvals);
8091: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8092: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8093: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8094: if ($inuse == 0) {
8095: $changes{$prefix}{$type} = 1;
8096: } else {
8097: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8098: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8099: if (@changed > 0) {
8100: $changes{$prefix}{$type} = 1;
8101: }
8102: }
8103: } else {
8104: if ($inuse == 1) {
8105: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8106: $changes{$prefix}{$type} = 1;
8107: }
8108: }
8109: } else {
8110: if ($inuse == 1) {
8111: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8112: $changes{$prefix}{$type} = 1;
8113: }
8114: }
8115: } else {
8116: if ($inuse == 1) {
8117: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8118: $changes{$prefix}{$type} = 1;
8119: }
8120: }
8121: }
8122: }
8123: }
1.145 raeburn 8124:
8125: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8126: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8127: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8128: my $savespares;
8129:
8130: foreach my $lonhost (sort(keys(%servers))) {
8131: my $serverhomeID =
8132: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8133: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8134: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8135: my %spareschg;
8136: foreach my $type (@{$types{'spares'}}) {
8137: my @okspares;
8138: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8139: foreach my $server (@checked) {
1.152 raeburn 8140: if (&Apache::lonnet::hostname($server) ne '') {
8141: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8142: unless (grep(/^\Q$server\E$/,@okspares)) {
8143: push(@okspares,$server);
8144: }
1.145 raeburn 8145: }
8146: }
8147: }
8148: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8149: my $newspare;
1.152 raeburn 8150: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8151: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8152: $newspare = $new;
8153: }
8154: }
1.152 raeburn 8155: my @spares;
8156: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8157: @spares = sort(@okspares,$newspare);
8158: } else {
8159: @spares = sort(@okspares);
8160: }
8161: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8162: if (ref($spareid{$lonhost}) eq 'HASH') {
8163: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8164: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8165: if (@diffs > 0) {
8166: $spareschg{$type} = 1;
8167: }
8168: }
8169: }
8170: }
8171: if (keys(%spareschg) > 0) {
8172: $changes{'spares'}{$lonhost} = \%spareschg;
8173: }
8174: }
8175:
8176: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8177: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8178: if (ref($changes{'spares'}) eq 'HASH') {
8179: if (keys(%{$changes{'spares'}}) > 0) {
8180: $savespares = 1;
8181: }
8182: }
8183: } else {
8184: $savespares = 1;
8185: }
8186: }
8187:
1.147 raeburn 8188: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8189: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8190: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8191: $dom);
8192: if ($putresult eq 'ok') {
8193: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8194: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8195: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8196: }
8197: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8198: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8199: }
8200: }
8201: my $cachetime = 24*60*60;
8202: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8203: if (keys(%changes) > 0) {
8204: my %lt = &usersession_titles();
8205: $resulttext = &mt('Changes made:').'<ul>';
8206: foreach my $prefix (@prefixes) {
8207: if (ref($changes{$prefix}) eq 'HASH') {
8208: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8209: if ($prefix eq 'spares') {
8210: if (ref($changes{$prefix}) eq 'HASH') {
8211: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8212: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8213: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8214: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8215: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8216: foreach my $type (@{$types{$prefix}}) {
8217: if ($changes{$prefix}{$lonhost}{$type}) {
8218: my $offloadto = &mt('None');
8219: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8220: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8221: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8222: }
1.145 raeburn 8223: }
1.147 raeburn 8224: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8225: }
1.137 raeburn 8226: }
8227: }
1.147 raeburn 8228: $resulttext .= '</li>';
1.137 raeburn 8229: }
8230: }
1.147 raeburn 8231: } else {
8232: foreach my $type (@{$types{$prefix}}) {
8233: if (defined($changes{$prefix}{$type})) {
8234: my $newvalue;
8235: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8236: if (ref($defaultshash{'usersessions'}{$prefix})) {
8237: if ($type eq 'version') {
8238: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8239: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8240: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8241: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8242: }
1.145 raeburn 8243: }
8244: }
8245: }
1.147 raeburn 8246: if ($newvalue eq '') {
8247: if ($type eq 'version') {
8248: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8249: } else {
8250: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8251: }
1.145 raeburn 8252: } else {
1.147 raeburn 8253: if ($type eq 'version') {
8254: $newvalue .= ' '.&mt('(or later)');
8255: }
8256: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8257: }
1.137 raeburn 8258: }
8259: }
8260: }
1.147 raeburn 8261: $resulttext .= '</ul>';
1.137 raeburn 8262: }
8263: }
1.147 raeburn 8264: $resulttext .= '</ul>';
8265: } else {
8266: $resulttext = $nochgmsg;
1.137 raeburn 8267: }
8268: } else {
8269: $resulttext = '<span class="LC_error">'.
8270: &mt('An error occurred: [_1]',$putresult).'</span>';
8271: }
8272: } else {
1.147 raeburn 8273: $resulttext = $nochgmsg;
1.137 raeburn 8274: }
8275: return $resulttext;
8276: }
8277:
1.150 raeburn 8278: sub modify_loadbalancing {
8279: my ($dom,%domconfig) = @_;
8280: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8281: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8282: my ($othertitle,$usertypes,$types) =
8283: &Apache::loncommon::sorted_inst_types($dom);
8284: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8285: my @sparestypes = ('primary','default');
8286: my %typetitles = &sparestype_titles();
8287: my $resulttext;
1.160.6.7 raeburn 8288: my (%currbalancer,%currtargets,%currrules,%existing);
8289: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8290: %existing = %{$domconfig{'loadbalancing'}};
8291: }
8292: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8293: \%currtargets,\%currrules);
8294: my ($saveloadbalancing,%defaultshash,%changes);
8295: my ($alltypes,$othertypes,$titles) =
8296: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8297: my %ruletitles = &offloadtype_text();
8298: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8299: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8300: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8301: if ($balancer eq '') {
8302: next;
8303: }
8304: if (!exists($servers{$balancer})) {
8305: if (exists($currbalancer{$balancer})) {
8306: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8307: }
1.160.6.7 raeburn 8308: next;
8309: }
8310: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8311: push(@{$changes{'delete'}},$balancer);
8312: next;
8313: }
8314: if (!exists($currbalancer{$balancer})) {
8315: push(@{$changes{'add'}},$balancer);
8316: }
8317: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8318: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8319: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8320: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8321: $saveloadbalancing = 1;
8322: }
8323: foreach my $sparetype (@sparestypes) {
8324: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8325: my @offloadto;
8326: foreach my $target (@targets) {
8327: if (($servers{$target}) && ($target ne $balancer)) {
8328: if ($sparetype eq 'default') {
8329: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8330: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8331: }
8332: }
1.160.6.7 raeburn 8333: unless(grep(/^\Q$target\E$/,@offloadto)) {
8334: push(@offloadto,$target);
8335: }
1.150 raeburn 8336: }
1.160.6.7 raeburn 8337: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8338: }
8339: }
1.160.6.7 raeburn 8340: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8341: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8342: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8343: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8344: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8345: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8346: }
1.160.6.7 raeburn 8347: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8348: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8349: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8350: }
8351: }
8352: }
8353: } else {
1.160.6.7 raeburn 8354: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8355: foreach my $sparetype (@sparestypes) {
8356: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8357: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8358: $changes{'curr'}{$balancer}{'targets'} = 1;
8359: }
1.150 raeburn 8360: }
8361: }
1.160.6.7 raeburn 8362: }
1.150 raeburn 8363: }
8364: my $ishomedom;
1.160.6.7 raeburn 8365: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8366: $ishomedom = 1;
1.150 raeburn 8367: }
8368: if (ref($alltypes) eq 'ARRAY') {
8369: foreach my $type (@{$alltypes}) {
8370: my $rule;
1.160.6.7 raeburn 8371: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8372: (!$ishomedom)) {
1.160.6.7 raeburn 8373: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8374: }
8375: if ($rule eq 'specific') {
8376: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8377: }
1.160.6.7 raeburn 8378: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8379: if (ref($currrules{$balancer}) eq 'HASH') {
8380: if ($rule ne $currrules{$balancer}{$type}) {
8381: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8382: }
8383: } elsif ($rule ne '') {
1.160.6.7 raeburn 8384: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8385: }
8386: }
8387: }
1.160.6.7 raeburn 8388: }
8389: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8390: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8391: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8392: $defaultshash{'loadbalancing'} = {};
8393: }
8394: my $putresult = &Apache::lonnet::put_dom('configuration',
8395: \%defaultshash,$dom);
8396:
8397: if ($putresult eq 'ok') {
8398: if (keys(%changes) > 0) {
8399: if (ref($changes{'delete'}) eq 'ARRAY') {
8400: foreach my $balancer (sort(@{$changes{'delete'}})) {
8401: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8402: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8403: }
1.160.6.7 raeburn 8404: }
8405: if (ref($changes{'add'}) eq 'ARRAY') {
8406: foreach my $balancer (sort(@{$changes{'add'}})) {
8407: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8408: }
8409: }
8410: if (ref($changes{'curr'}) eq 'HASH') {
8411: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8412: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8413: if ($changes{'curr'}{$balancer}{'targets'}) {
8414: my %offloadstr;
8415: foreach my $sparetype (@sparestypes) {
8416: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8417: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8418: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8419: }
8420: }
1.150 raeburn 8421: }
1.160.6.7 raeburn 8422: if (keys(%offloadstr) == 0) {
8423: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8424: } else {
1.160.6.7 raeburn 8425: my $showoffload;
8426: foreach my $sparetype (@sparestypes) {
8427: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8428: if (defined($offloadstr{$sparetype})) {
8429: $showoffload .= $offloadstr{$sparetype};
8430: } else {
8431: $showoffload .= &mt('None');
8432: }
8433: $showoffload .= (' 'x3);
8434: }
8435: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8436: }
8437: }
8438: }
1.160.6.7 raeburn 8439: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8440: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8441: foreach my $type (@{$alltypes}) {
8442: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8443: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8444: my $balancetext;
8445: if ($rule eq '') {
8446: $balancetext = $ruletitles{'default'};
8447: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8448: $balancetext = $ruletitles{$rule};
8449: } else {
8450: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8451: }
8452: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8453: }
8454: }
8455: }
8456: }
1.160.6.7 raeburn 8457: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8458: }
1.160.6.7 raeburn 8459: }
8460: if ($resulttext ne '') {
8461: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8462: } else {
8463: $resulttext = $nochgmsg;
8464: }
8465: } else {
1.160.6.7 raeburn 8466: $resulttext = $nochgmsg;
1.150 raeburn 8467: }
8468: } else {
1.160.6.7 raeburn 8469: $resulttext = '<span class="LC_error">'.
8470: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8471: }
8472: } else {
1.160.6.7 raeburn 8473: $resulttext = $nochgmsg;
1.150 raeburn 8474: }
8475: return $resulttext;
8476: }
8477:
1.48 raeburn 8478: sub recurse_check {
8479: my ($chkcats,$categories,$depth,$name) = @_;
8480: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8481: my $chg = 0;
8482: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8483: my $category = $chkcats->[$depth]{$name}[$j];
8484: my $item;
8485: if ($category eq '') {
8486: $chg ++;
8487: } else {
8488: my $deeper = $depth + 1;
8489: $item = &escape($category).':'.&escape($name).':'.$depth;
8490: if ($chg) {
8491: $categories->{$item} -= $chg;
8492: }
8493: &recurse_check($chkcats,$categories,$deeper,$category);
8494: $deeper --;
8495: }
8496: }
8497: }
8498: return;
8499: }
8500:
8501: sub recurse_cat_deletes {
8502: my ($item,$coursecategories,$deletions) = @_;
8503: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8504: my $subdepth = $depth + 1;
8505: if (ref($coursecategories) eq 'HASH') {
8506: foreach my $subitem (keys(%{$coursecategories})) {
8507: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8508: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8509: delete($coursecategories->{$subitem});
8510: $deletions->{$subitem} = 1;
8511: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8512: }
8513: }
8514: }
8515: return;
8516: }
8517:
1.125 raeburn 8518: sub get_active_dcs {
8519: my ($dom) = @_;
1.160.6.16 raeburn 8520: my $now = time;
8521: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8522: my %domcoords;
8523: my $numdcs = 0;
8524: foreach my $server (keys(%dompersonnel)) {
8525: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8526: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 8527: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8528: }
8529: }
8530: return %domcoords;
8531: }
8532:
8533: sub active_dc_picker {
1.160.6.16 raeburn 8534: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8535: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 8536: my @domcoord = keys(%domcoords);
8537: if (keys(%currhash)) {
8538: foreach my $dc (keys(%currhash)) {
8539: unless (exists($domcoords{$dc})) {
8540: push(@domcoord,$dc);
8541: }
8542: }
8543: }
8544: @domcoord = sort(@domcoord);
8545: my $numdcs = scalar(@domcoord);
8546: my $rows = 0;
8547: my $table;
1.125 raeburn 8548: if ($numdcs > 1) {
1.160.6.16 raeburn 8549: $table = '<table>';
8550: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8551: my $rem = $i%($numinrow);
8552: if ($rem == 0) {
8553: if ($i > 0) {
1.160.6.16 raeburn 8554: $table .= '</tr>';
1.125 raeburn 8555: }
1.160.6.16 raeburn 8556: $table .= '<tr>';
8557: $rows ++;
1.125 raeburn 8558: }
1.160.6.16 raeburn 8559: my $check = '';
8560: if ($inputtype eq 'radio') {
8561: if (keys(%currhash) == 0) {
8562: if (!$i) {
8563: $check = ' checked="checked"';
8564: }
8565: } elsif (exists($currhash{$domcoord[$i]})) {
8566: $check = ' checked="checked"';
8567: }
8568: } else {
8569: if (exists($currhash{$domcoord[$i]})) {
8570: $check = ' checked="checked"';
1.125 raeburn 8571: }
8572: }
1.160.6.16 raeburn 8573: if ($i == @domcoord - 1) {
1.125 raeburn 8574: my $colsleft = $numinrow - $rem;
8575: if ($colsleft > 1) {
1.160.6.16 raeburn 8576: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8577: } else {
1.160.6.16 raeburn 8578: $table .= '<td class="LC_left_item">';
1.125 raeburn 8579: }
8580: } else {
1.160.6.16 raeburn 8581: $table .= '<td class="LC_left_item">';
8582: }
8583: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8584: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8585: $table .= '<span class="LC_nobreak"><label>'.
8586: '<input type="'.$inputtype.'" name="'.$name.'"'.
8587: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8588: if ($user ne $dcname.':'.$dcdom) {
8589: $table .= ' ('.$dcname.':'.$dcdom.')'.
8590: '</label></span></td>';
1.125 raeburn 8591: }
8592: }
1.160.6.16 raeburn 8593: $table .= '</tr></table>';
8594: } elsif ($numdcs == 1) {
8595: if ($inputtype eq 'radio') {
8596: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8597: } else {
8598: my $check;
8599: if (exists($currhash{$domcoord[0]})) {
8600: $check = ' checked="checked"';
8601: }
8602: $table .= '<input type="checkbox" name="'.$name.'" '.
8603: 'value="'.$domcoord[0].'"'.$check.' />';
8604: $rows ++;
8605: }
1.125 raeburn 8606: }
1.160.6.16 raeburn 8607: return ($numdcs,$table,$rows);
1.125 raeburn 8608: }
8609:
1.137 raeburn 8610: sub usersession_titles {
8611: return &Apache::lonlocal::texthash(
8612: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8613: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8614: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8615: version => 'LON-CAPA version requirement',
1.138 raeburn 8616: excludedomain => 'Allow all, but exclude specific domains',
8617: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8618: primary => 'Primary (checked first)',
1.154 raeburn 8619: default => 'Default',
1.137 raeburn 8620: );
8621: }
8622:
1.152 raeburn 8623: sub id_for_thisdom {
8624: my (%servers) = @_;
8625: my %altids;
8626: foreach my $server (keys(%servers)) {
8627: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8628: if ($serverhome ne $server) {
8629: $altids{$serverhome} = $server;
8630: }
8631: }
8632: return %altids;
8633: }
8634:
1.150 raeburn 8635: sub count_servers {
8636: my ($currbalancer,%servers) = @_;
8637: my (@spares,$numspares);
8638: foreach my $lonhost (sort(keys(%servers))) {
8639: next if ($currbalancer eq $lonhost);
8640: push(@spares,$lonhost);
8641: }
8642: if ($currbalancer) {
8643: $numspares = scalar(@spares);
8644: } else {
8645: $numspares = scalar(@spares) - 1;
8646: }
8647: return ($numspares,@spares);
8648: }
8649:
8650: sub lonbalance_targets_js {
1.160.6.7 raeburn 8651: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8652: my $select = &mt('Select');
8653: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8654: if (ref($servers) eq 'HASH') {
8655: $alltargets = join("','",sort(keys(%{$servers})));
8656: my @homedoms;
8657: foreach my $server (sort(keys(%{$servers}))) {
8658: if (&Apache::lonnet::host_domain($server) eq $dom) {
8659: push(@homedoms,'1');
8660: } else {
8661: push(@homedoms,'0');
8662: }
8663: }
8664: $allishome = join("','",@homedoms);
8665: }
8666: if (ref($types) eq 'ARRAY') {
8667: if (@{$types} > 0) {
8668: @alltypes = @{$types};
8669: }
8670: }
8671: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8672: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8673: my (%currbalancer,%currtargets,%currrules,%existing);
8674: if (ref($settings) eq 'HASH') {
8675: %existing = %{$settings};
8676: }
8677: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8678: \%currtargets,\%currrules);
8679: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8680: return <<"END";
8681:
8682: <script type="text/javascript">
8683: // <![CDATA[
8684:
1.160.6.7 raeburn 8685: currBalancers = new Array('$balancers');
8686:
8687: function toggleTargets(balnum) {
8688: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8689: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8690: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8691: var prevbalancer = prevhostitem.value;
8692: var baltotal = document.getElementById('loadbalancing_total').value;
8693: prevhostitem.value = balancer;
8694: if (prevbalancer != '') {
8695: var prevIdx = currBalancers.indexOf(prevbalancer);
8696: if (prevIdx != -1) {
8697: currBalancers.splice(prevIdx,1);
8698: }
8699: }
1.150 raeburn 8700: if (balancer == '') {
1.160.6.7 raeburn 8701: hideSpares(balnum);
1.150 raeburn 8702: } else {
1.160.6.7 raeburn 8703: var currIdx = currBalancers.indexOf(balancer);
8704: if (currIdx == -1) {
8705: currBalancers.push(balancer);
8706: }
1.150 raeburn 8707: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8708: var ishomedom = homedoms[lonhostitem.selectedIndex];
8709: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8710: }
1.160.6.7 raeburn 8711: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8712: return;
8713: }
8714:
1.160.6.7 raeburn 8715: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8716: var alltargets = new Array('$alltargets');
8717: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8718: var offloadtypes = new Array('primary','default');
8719:
1.160.6.7 raeburn 8720: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8721: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8722:
1.151 raeburn 8723: for (var i=0; i<offloadtypes.length; i++) {
8724: var count = 0;
8725: for (var j=0; j<alltargets.length; j++) {
8726: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8727: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8728: item.value = alltargets[j];
8729: item.style.textAlign='left';
8730: item.style.textFace='normal';
8731: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8732: if (currBalancers.indexOf(alltargets[j]) == -1) {
8733: item.disabled = '';
8734: } else {
8735: item.disabled = 'disabled';
8736: item.checked = false;
8737: }
1.151 raeburn 8738: count ++;
8739: }
1.150 raeburn 8740: }
8741: }
1.151 raeburn 8742: for (var k=0; k<insttypes.length; k++) {
8743: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8744: if (ishomedom == 1) {
1.160.6.7 raeburn 8745: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8746: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8747: } else {
1.160.6.7 raeburn 8748: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8749: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8750:
8751: }
8752: } else {
1.160.6.7 raeburn 8753: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8754: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8755: }
1.151 raeburn 8756: if ((insttypes[k] != '_LC_external') &&
8757: ((insttypes[k] != '_LC_internetdom') ||
8758: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8759: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8760: item.options.length = 0;
8761: item.options[0] = new Option("","",true,true);
8762: var idx = 0;
1.151 raeburn 8763: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8764: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8765: idx ++;
8766: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8767:
1.150 raeburn 8768: }
8769: }
8770: }
8771: }
8772: return;
8773: }
8774:
1.160.6.7 raeburn 8775: function hideSpares(balnum) {
1.150 raeburn 8776: var alltargets = new Array('$alltargets');
8777: var insttypes = new Array('$allinsttypes');
8778: var offloadtypes = new Array('primary','default');
8779:
1.160.6.7 raeburn 8780: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8781: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8782:
8783: var total = alltargets.length - 1;
8784: for (var i=0; i<offloadtypes; i++) {
8785: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8786: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8787: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8788: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8789: }
1.150 raeburn 8790: }
8791: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8792: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8793: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8794: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8795: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8796: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8797: }
8798: }
8799: return;
8800: }
8801:
1.160.6.7 raeburn 8802: function checkOffloads(item,balnum,type) {
1.150 raeburn 8803: var alltargets = new Array('$alltargets');
8804: var offloadtypes = new Array('primary','default');
8805: if (item.checked) {
8806: var total = alltargets.length - 1;
8807: var other;
8808: if (type == offloadtypes[0]) {
1.151 raeburn 8809: other = offloadtypes[1];
1.150 raeburn 8810: } else {
1.151 raeburn 8811: other = offloadtypes[0];
1.150 raeburn 8812: }
8813: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8814: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8815: if (server == item.value) {
1.160.6.7 raeburn 8816: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8817: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8818: }
8819: }
8820: }
8821: }
8822: return;
8823: }
8824:
1.160.6.7 raeburn 8825: function singleServerToggle(balnum,type) {
8826: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8827: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 8828: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8829: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8830:
8831: } else {
1.160.6.7 raeburn 8832: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8833: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8834: }
8835: return;
8836: }
8837:
1.160.6.7 raeburn 8838: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8839: if (type == '_LC_external') {
8840: return;
8841: }
1.160.6.7 raeburn 8842: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8843: for (var i=0; i<typesRules.length; i++) {
8844: if (formname.elements[typesRules[i]].checked) {
8845: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 8846: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8847: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8848: } else {
1.160.6.7 raeburn 8849: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8850: }
8851: }
8852: }
8853: return;
8854: }
8855:
8856: function balancerDeleteChange(balnum) {
8857: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8858: var baltotal = document.getElementById('loadbalancing_total').value;
8859: var addtarget;
8860: var removetarget;
8861: var action = 'delete';
8862: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8863: var lonhost = hostitem.value;
8864: var currIdx = currBalancers.indexOf(lonhost);
8865: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8866: if (currIdx != -1) {
8867: currBalancers.splice(currIdx,1);
8868: }
8869: addtarget = lonhost;
8870: } else {
8871: if (currIdx == -1) {
8872: currBalancers.push(lonhost);
8873: }
8874: removetarget = lonhost;
8875: action = 'undelete';
8876: }
8877: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8878: }
8879: return;
8880: }
8881:
8882: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8883: if (baltotal > 1) {
8884: var offloadtypes = new Array('primary','default');
8885: var alltargets = new Array('$alltargets');
8886: var insttypes = new Array('$allinsttypes');
8887: for (var i=0; i<baltotal; i++) {
8888: if (i != balnum) {
8889: for (var j=0; j<offloadtypes.length; j++) {
8890: var total = alltargets.length - 1;
8891: for (var k=0; k<total; k++) {
8892: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8893: var server = serveritem.value;
8894: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8895: if (server == addtarget) {
8896: serveritem.disabled = '';
8897: }
8898: }
8899: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8900: if (server == removetarget) {
8901: serveritem.disabled = 'disabled';
8902: serveritem.checked = false;
8903: }
8904: }
8905: }
8906: }
8907: for (var j=0; j<insttypes.length; j++) {
8908: if (insttypes[j] != '_LC_external') {
8909: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8910: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8911: var currSel = singleserver.selectedIndex;
8912: var currVal = singleserver.options[currSel].value;
8913: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8914: var numoptions = singleserver.options.length;
8915: var needsnew = 1;
8916: for (var k=0; k<numoptions; k++) {
8917: if (singleserver.options[k] == addtarget) {
8918: needsnew = 0;
8919: break;
8920: }
8921: }
8922: if (needsnew == 1) {
8923: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8924: }
8925: }
8926: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8927: singleserver.options.length = 0;
8928: if ((currVal) && (currVal != removetarget)) {
8929: singleserver.options[0] = new Option("","",false,false);
8930: } else {
8931: singleserver.options[0] = new Option("","",true,true);
8932: }
8933: var idx = 0;
8934: for (var m=0; m<alltargets.length; m++) {
8935: if (currBalancers.indexOf(alltargets[m]) == -1) {
8936: idx ++;
8937: if (currVal == alltargets[m]) {
8938: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8939: } else {
8940: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8941: }
8942: }
8943: }
8944: }
8945: }
8946: }
8947: }
1.150 raeburn 8948: }
8949: }
8950: }
8951: return;
8952: }
8953:
1.152 raeburn 8954: // ]]>
8955: </script>
8956:
8957: END
8958: }
8959:
8960: sub new_spares_js {
8961: my @sparestypes = ('primary','default');
8962: my $types = join("','",@sparestypes);
8963: my $select = &mt('Select');
8964: return <<"END";
8965:
8966: <script type="text/javascript">
8967: // <![CDATA[
8968:
8969: function updateNewSpares(formname,lonhost) {
8970: var types = new Array('$types');
8971: var include = new Array();
8972: var exclude = new Array();
8973: for (var i=0; i<types.length; i++) {
8974: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8975: for (var j=0; j<spareboxes.length; j++) {
8976: if (formname.elements[spareboxes[j]].checked) {
8977: exclude.push(formname.elements[spareboxes[j]].value);
8978: } else {
8979: include.push(formname.elements[spareboxes[j]].value);
8980: }
8981: }
8982: }
8983: for (var i=0; i<types.length; i++) {
8984: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8985: var selIdx = newSpare.selectedIndex;
8986: var currnew = newSpare.options[selIdx].value;
8987: var okSpares = new Array();
8988: for (var j=0; j<newSpare.options.length; j++) {
8989: var possible = newSpare.options[j].value;
8990: if (possible != '') {
8991: if (exclude.indexOf(possible) == -1) {
8992: okSpares.push(possible);
8993: } else {
8994: if (currnew == possible) {
8995: selIdx = 0;
8996: }
8997: }
8998: }
8999: }
9000: for (var k=0; k<include.length; k++) {
9001: if (okSpares.indexOf(include[k]) == -1) {
9002: okSpares.push(include[k]);
9003: }
9004: }
9005: okSpares.sort();
9006: newSpare.options.length = 0;
9007: if (selIdx == 0) {
9008: newSpare.options[0] = new Option("$select","",true,true);
9009: } else {
9010: newSpare.options[0] = new Option("$select","",false,false);
9011: }
9012: for (var m=0; m<okSpares.length; m++) {
9013: var idx = m+1;
9014: var selThis = 0;
9015: if (selIdx != 0) {
9016: if (okSpares[m] == currnew) {
9017: selThis = 1;
9018: }
9019: }
9020: if (selThis == 1) {
9021: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9022: } else {
9023: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9024: }
9025: }
9026: }
9027: return;
9028: }
9029:
9030: function checkNewSpares(lonhost,type) {
9031: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9032: var chosen = newSpare.options[newSpare.selectedIndex].value;
9033: if (chosen != '') {
9034: var othertype;
9035: var othernewSpare;
9036: if (type == 'primary') {
9037: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9038: }
9039: if (type == 'default') {
9040: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9041: }
9042: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9043: othernewSpare.selectedIndex = 0;
9044: }
9045: }
9046: return;
9047: }
9048:
9049: // ]]>
9050: </script>
9051:
9052: END
9053:
9054: }
9055:
9056: sub common_domprefs_js {
9057: return <<"END";
9058:
9059: <script type="text/javascript">
9060: // <![CDATA[
9061:
1.150 raeburn 9062: function getIndicesByName(formname,item) {
1.152 raeburn 9063: var group = new Array();
1.150 raeburn 9064: for (var i=0;i<formname.elements.length;i++) {
9065: if (formname.elements[i].name == item) {
1.152 raeburn 9066: group.push(formname.elements[i].id);
1.150 raeburn 9067: }
9068: }
1.152 raeburn 9069: return group;
1.150 raeburn 9070: }
9071:
9072: // ]]>
9073: </script>
9074:
9075: END
1.152 raeburn 9076:
1.150 raeburn 9077: }
9078:
1.160.6.5 raeburn 9079: sub recaptcha_js {
9080: my %lt = &captcha_phrases();
9081: return <<"END";
9082:
9083: <script type="text/javascript">
9084: // <![CDATA[
9085:
9086: function updateCaptcha(caller,context) {
9087: var privitem;
9088: var pubitem;
9089: var privtext;
9090: var pubtext;
9091: if (document.getElementById(context+'_recaptchapub')) {
9092: pubitem = document.getElementById(context+'_recaptchapub');
9093: } else {
9094: return;
9095: }
9096: if (document.getElementById(context+'_recaptchapriv')) {
9097: privitem = document.getElementById(context+'_recaptchapriv');
9098: } else {
9099: return;
9100: }
9101: if (document.getElementById(context+'_recaptchapubtxt')) {
9102: pubtext = document.getElementById(context+'_recaptchapubtxt');
9103: } else {
9104: return;
9105: }
9106: if (document.getElementById(context+'_recaptchaprivtxt')) {
9107: privtext = document.getElementById(context+'_recaptchaprivtxt');
9108: } else {
9109: return;
9110: }
9111: if (caller.checked) {
9112: if (caller.value == 'recaptcha') {
9113: pubitem.type = 'text';
9114: privitem.type = 'text';
9115: pubitem.size = '40';
9116: privitem.size = '40';
9117: pubtext.innerHTML = "$lt{'pub'}";
9118: privtext.innerHTML = "$lt{'priv'}";
9119: } else {
9120: pubitem.type = 'hidden';
9121: privitem.type = 'hidden';
9122: pubtext.innerHTML = '';
9123: privtext.innerHTML = '';
9124: }
9125: }
9126: return;
9127: }
9128:
9129: // ]]>
9130: </script>
9131:
9132: END
9133:
9134: }
9135:
1.160.6.16 raeburn 9136: sub credits_js {
9137: return <<"END";
9138:
9139: <script type="text/javascript">
9140: // <![CDATA[
9141:
9142: function toggleCredits(domForm) {
9143: if (document.getElementById('credits')) {
9144: creditsitem = document.getElementById('credits');
9145: var creditsLength = domForm.coursecredits.length;
9146: if (creditsLength) {
9147: var currval;
9148: for (var i=0; i<creditsLength; i++) {
9149: if (domForm.coursecredits[i].checked) {
9150: currval = domForm.coursecredits[i].value;
9151: }
9152: }
9153: if (currval == 1) {
9154: creditsitem.style.display = 'block';
9155: } else {
9156: creditsitem.style.display = 'none';
9157: }
9158: }
9159: }
9160: return;
9161: }
9162:
9163: // ]]>
9164: </script>
9165:
9166: END
9167:
9168: }
9169:
1.160.6.5 raeburn 9170: sub captcha_phrases {
9171: return &Apache::lonlocal::texthash (
9172: priv => 'Private key',
9173: pub => 'Public key',
9174: original => 'original (CAPTCHA)',
9175: recaptcha => 'successor (ReCAPTCHA)',
9176: notused => 'unused',
9177: );
9178: }
9179:
1.3 raeburn 9180: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>