Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.25
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.25! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.24 2013/09/10 01:52:35 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.160.6.24 raeburn 404: if (&Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
405: \%prefs,\%domconfig,$confname,\@roles) eq 'update') {
406: $r->rflush();
407: &devalidate_remote_domconfs($dom);
408: }
1.30 raeburn 409: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 410: my $js = &recaptcha_js().
411: &credits_js();
1.160.6.7 raeburn 412: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 413: my ($othertitle,$usertypes,$types) =
414: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 415: $js .= &lonbalance_targets_js($dom,$types,\%servers,
416: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 417: &new_spares_js().
418: &common_domprefs_js().
419: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 420: }
1.150 raeburn 421: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 422: } else {
1.160.6.11 raeburn 423: # check if domconfig user exists for the domain.
424: my $servadm = $r->dir_config('lonAdmEMail');
425: my ($configuserok,$author_ok,$switchserver) =
426: &config_check($dom,$confname,$servadm);
427: unless ($configuserok eq 'ok') {
428: &Apache::lonconfigsettings::print_header($r,$phase,$context);
429: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
430: $confname).
431: '<br />'
432: );
433: if ($switchserver) {
434: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
435: '<br />'.
436: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
437: '<br />'.
438: &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).
439: '<br />'.
440: &mt('To do that now, use the following link: [_1]',$switchserver)
441: );
442: } else {
443: $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.').
444: '<br />'.
445: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
446: );
447: }
448: $r->print(&Apache::loncommon::end_page());
449: return OK;
450: }
1.21 raeburn 451: if (keys(%domconfig) == 0) {
452: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 453: my @ids=&Apache::lonnet::current_machine_ids();
454: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 455: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 456: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 457: my $custom_img_count = 0;
458: foreach my $img (@loginimages) {
459: if ($designhash{$dom.'.login.'.$img} ne '') {
460: $custom_img_count ++;
461: }
462: }
463: foreach my $role (@roles) {
464: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
465: $custom_img_count ++;
466: }
467: }
468: if ($custom_img_count > 0) {
1.94 raeburn 469: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 470: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 471: $r->print(
472: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
473: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
474: &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 />'.
475: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
476: if ($switch_server) {
1.30 raeburn 477: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 478: }
1.91 raeburn 479: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 480: return OK;
481: }
482: }
483: }
1.91 raeburn 484: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 485: }
486: return OK;
487: }
488:
489: sub process_changes {
1.160.6.24 raeburn 490: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 491: my %domconfig;
492: if (ref($values) eq 'HASH') {
493: %domconfig = %{$values};
494: }
1.3 raeburn 495: my $output;
496: if ($action eq 'login') {
1.160.6.24 raeburn 497: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 498: } elsif ($action eq 'rolecolors') {
1.9 raeburn 499: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 500: $lastactref,%domconfig);
1.3 raeburn 501: } elsif ($action eq 'quotas') {
1.86 raeburn 502: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 503: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 504: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 505: } elsif ($action eq 'autoupdate') {
506: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 507: } elsif ($action eq 'autocreate') {
508: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 509: } elsif ($action eq 'directorysrch') {
510: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 511: } elsif ($action eq 'usercreation') {
1.28 raeburn 512: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 513: } elsif ($action eq 'usermodification') {
514: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 515: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 516: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 517: } elsif ($action eq 'defaults') {
1.160.6.23 raeburn 518: $output = &modify_defaults($dom,$r,%domconfig);
1.46 raeburn 519: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 520: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 521: } elsif ($action eq 'coursecategories') {
522: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 523: } elsif ($action eq 'serverstatuses') {
524: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 525: } elsif ($action eq 'requestcourses') {
526: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.5 raeburn 527: } elsif ($action eq 'requestauthor') {
528: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.16 raeburn 529: } elsif ($action eq 'coursedefaults') {
530: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 531: } elsif ($action eq 'usersessions') {
532: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 533: } elsif ($action eq 'loadbalancing') {
534: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 535: }
536: return $output;
537: }
538:
539: sub print_config_box {
1.9 raeburn 540: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 541: my $rowtotal = 0;
1.49 raeburn 542: my $output;
543: if ($action eq 'coursecategories') {
544: $output = &coursecategories_javascript($settings);
1.91 raeburn 545: }
1.49 raeburn 546: $output .=
1.30 raeburn 547: '<table class="LC_nested_outer">
1.3 raeburn 548: <tr>
1.66 raeburn 549: <th align="left" valign="middle"><span class="LC_nobreak">'.
550: &mt($item->{text}).' '.
551: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
552: '</tr>';
1.30 raeburn 553: $rowtotal ++;
1.110 raeburn 554: my $numheaders = 1;
555: if (ref($item->{'header'}) eq 'ARRAY') {
556: $numheaders = scalar(@{$item->{'header'}});
557: }
558: if ($numheaders > 1) {
1.64 raeburn 559: my $colspan = '';
1.145 raeburn 560: my $rightcolspan = '';
1.160.6.5 raeburn 561: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
562: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 563: $colspan = ' colspan="2"';
564: }
1.145 raeburn 565: if ($action eq 'usersessions') {
566: $rightcolspan = ' colspan="3"';
567: }
1.30 raeburn 568: $output .= '
1.3 raeburn 569: <tr>
570: <td>
571: <table class="LC_nested">
572: <tr class="LC_info_row">
1.59 bisitz 573: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 574: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 575: </tr>';
1.69 raeburn 576: $rowtotal ++;
1.6 raeburn 577: if ($action eq 'autoupdate') {
1.30 raeburn 578: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 579: } elsif ($action eq 'usercreation') {
1.33 raeburn 580: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
581: } elsif ($action eq 'usermodification') {
582: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 583: } elsif ($action eq 'coursecategories') {
584: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 585: } elsif ($action eq 'login') {
1.160.6.5 raeburn 586: if ($numheaders == 3) {
587: $colspan = ' colspan="2"';
588: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
589: } else {
590: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
591: }
1.102 raeburn 592: } elsif ($action eq 'requestcourses') {
593: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 594: } elsif ($action eq 'requestauthor') {
595: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 596: } elsif ($action eq 'usersessions') {
597: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 598: } elsif ($action eq 'rolecolors') {
1.30 raeburn 599: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 600: }
1.30 raeburn 601: $output .= '
1.6 raeburn 602: </table>
603: </td>
604: </tr>
605: <tr>
606: <td>
607: <table class="LC_nested">
608: <tr class="LC_info_row">
1.59 bisitz 609: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 610: $output .= '
1.59 bisitz 611: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 612: </tr>';
613: $rowtotal ++;
1.6 raeburn 614: if ($action eq 'autoupdate') {
1.131 raeburn 615: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
616: </table>
617: </td>
618: </tr>
619: <tr>
620: <td>
621: <table class="LC_nested">
622: <tr class="LC_info_row">
623: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
624: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
625: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
626: $rowtotal ++;
1.28 raeburn 627: } elsif ($action eq 'usercreation') {
1.34 raeburn 628: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
629: </table>
630: </td>
631: </tr>
632: <tr>
633: <td>
634: <table class="LC_nested">
635: <tr class="LC_info_row">
1.59 bisitz 636: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
637: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 638: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
639: $rowtotal ++;
1.33 raeburn 640: } elsif ($action eq 'usermodification') {
1.63 raeburn 641: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
642: </table>
643: </td>
644: </tr>
645: <tr>
646: <td>
647: <table class="LC_nested">
648: <tr class="LC_info_row">
649: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
650: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
651: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
652: $rowtotal ++;
1.57 raeburn 653: } elsif ($action eq 'coursecategories') {
654: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 655: } elsif ($action eq 'login') {
1.160.6.5 raeburn 656: if ($numheaders == 3) {
657: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
658: </table>
659: </td>
660: </tr>
661: <tr>
662: <td>
663: <table class="LC_nested">
664: <tr class="LC_info_row">
665: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
666: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
667: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
668: $rowtotal ++;
669: } else {
670: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
671: }
1.102 raeburn 672: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 673: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
674: } elsif ($action eq 'requestauthor') {
675: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 676: } elsif ($action eq 'usersessions') {
1.145 raeburn 677: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
678: </table>
679: </td>
680: </tr>
681: <tr>
682: <td>
683: <table class="LC_nested">
684: <tr class="LC_info_row">
685: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
686: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
687: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
688: $rowtotal ++;
1.122 jms 689: } elsif ($action eq 'rolecolors') {
1.30 raeburn 690: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 691: </table>
692: </td>
693: </tr>
694: <tr>
695: <td>
696: <table class="LC_nested">
697: <tr class="LC_info_row">
1.69 raeburn 698: <td class="LC_left_item"'.$colspan.' valign="top">'.
699: &mt($item->{'header'}->[2]->{'col1'}).'</td>
700: <td class="LC_right_item" valign="top">'.
701: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 702: </tr>'.
1.30 raeburn 703: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 704: </table>
705: </td>
706: </tr>
707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
1.59 bisitz 711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
712: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 713: </tr>'.
1.30 raeburn 714: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
715: $rowtotal += 2;
1.6 raeburn 716: }
1.3 raeburn 717: } else {
1.30 raeburn 718: $output .= '
1.3 raeburn 719: <tr>
720: <td>
721: <table class="LC_nested">
1.30 raeburn 722: <tr class="LC_info_row">';
1.24 raeburn 723: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 724: $output .= '
1.59 bisitz 725: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 726: } elsif ($action eq 'serverstatuses') {
727: $output .= '
728: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
729: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
730:
1.6 raeburn 731: } else {
1.30 raeburn 732: $output .= '
1.69 raeburn 733: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
734: }
1.72 raeburn 735: if (defined($item->{'header'}->[0]->{'col3'})) {
736: $output .= '<td class="LC_left_item" valign="top">'.
737: &mt($item->{'header'}->[0]->{'col2'});
738: if ($action eq 'serverstatuses') {
739: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
740: }
1.69 raeburn 741: } else {
742: $output .= '<td class="LC_right_item" valign="top">'.
743: &mt($item->{'header'}->[0]->{'col2'});
744: }
745: $output .= '</td>';
746: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 747: if (defined($item->{'header'}->[0]->{'col4'})) {
748: $output .= '<td class="LC_left_item" valign="top">'.
749: &mt($item->{'header'}->[0]->{'col3'});
750: } else {
751: $output .= '<td class="LC_right_item" valign="top">'.
752: &mt($item->{'header'}->[0]->{'col3'});
753: }
1.69 raeburn 754: if ($action eq 'serverstatuses') {
755: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
756: }
757: $output .= '</td>';
1.6 raeburn 758: }
1.150 raeburn 759: if ($item->{'header'}->[0]->{'col4'}) {
760: $output .= '<td class="LC_right_item" valign="top">'.
761: &mt($item->{'header'}->[0]->{'col4'});
762: }
1.69 raeburn 763: $output .= '</tr>';
1.48 raeburn 764: $rowtotal ++;
1.160.6.5 raeburn 765: if ($action eq 'quotas') {
1.86 raeburn 766: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 767: } elsif ($action eq 'autoenroll') {
1.30 raeburn 768: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 769: } elsif ($action eq 'autocreate') {
770: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 771: } elsif ($action eq 'directorysrch') {
1.30 raeburn 772: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 773: } elsif ($action eq 'contacts') {
1.30 raeburn 774: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 775: } elsif ($action eq 'defaults') {
776: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 777: } elsif ($action eq 'scantron') {
778: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 779: } elsif ($action eq 'serverstatuses') {
780: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 781: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 782: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 783: } elsif ($action eq 'loadbalancing') {
784: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.160.6.16 raeburn 785: } elsif ($action eq 'coursedefaults') {
786: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 787: }
1.3 raeburn 788: }
1.30 raeburn 789: $output .= '
1.3 raeburn 790: </table>
791: </td>
792: </tr>
1.30 raeburn 793: </table><br />';
794: return ($output,$rowtotal);
1.1 raeburn 795: }
796:
1.3 raeburn 797: sub print_login {
1.160.6.5 raeburn 798: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 799: my ($css_class,$datatable);
1.6 raeburn 800: my %choices = &login_choices();
1.110 raeburn 801:
1.160.6.5 raeburn 802: if ($caller eq 'service') {
1.149 raeburn 803: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 804: my $choice = $choices{'disallowlogin'};
805: $css_class = ' class="LC_odd_row"';
1.128 raeburn 806: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 807: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 808: '<th>'.$choices{'server'}.'</th>'.
809: '<th>'.$choices{'serverpath'}.'</th>'.
810: '<th>'.$choices{'custompath'}.'</th>'.
811: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 812: my %disallowed;
813: if (ref($settings) eq 'HASH') {
814: if (ref($settings->{'loginvia'}) eq 'HASH') {
815: %disallowed = %{$settings->{'loginvia'}};
816: }
817: }
818: foreach my $lonhost (sort(keys(%servers))) {
819: my $direct = 'selected="selected"';
1.128 raeburn 820: if (ref($disallowed{$lonhost}) eq 'HASH') {
821: if ($disallowed{$lonhost}{'server'} ne '') {
822: $direct = '';
823: }
1.110 raeburn 824: }
1.115 raeburn 825: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 826: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 827: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
828: '</option>';
1.160.6.13 raeburn 829: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 830: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 831: my $selected = '';
1.128 raeburn 832: if (ref($disallowed{$lonhost}) eq 'HASH') {
833: if ($hostid eq $disallowed{$lonhost}{'server'}) {
834: $selected = 'selected="selected"';
835: }
1.110 raeburn 836: }
837: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
838: $servers{$hostid}.'</option>';
839: }
1.128 raeburn 840: $datatable .= '</select></td>'.
841: '<td><select name="'.$lonhost.'_serverpath">';
842: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
843: my $pathname = $path;
844: if ($path eq 'custom') {
845: $pathname = &mt('Custom Path').' ->';
846: }
847: my $selected = '';
848: if (ref($disallowed{$lonhost}) eq 'HASH') {
849: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
850: $selected = 'selected="selected"';
851: }
852: } elsif ($path eq '') {
853: $selected = 'selected="selected"';
854: }
855: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
856: }
857: $datatable .= '</select></td>';
858: my ($custom,$exempt);
859: if (ref($disallowed{$lonhost}) eq 'HASH') {
860: $custom = $disallowed{$lonhost}{'custompath'};
861: $exempt = $disallowed{$lonhost}{'exempt'};
862: }
863: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
864: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
865: '</tr>';
1.110 raeburn 866: }
867: $datatable .= '</table></td></tr>';
868: return $datatable;
1.160.6.5 raeburn 869: } elsif ($caller eq 'page') {
870: my %defaultchecked = (
871: 'coursecatalog' => 'on',
1.160.6.14 raeburn 872: 'helpdesk' => 'on',
1.160.6.5 raeburn 873: 'adminmail' => 'off',
874: 'newuser' => 'off',
875: );
1.160.6.14 raeburn 876: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 877: my (%checkedon,%checkedoff);
1.42 raeburn 878: foreach my $item (@toggles) {
1.160.6.5 raeburn 879: if ($defaultchecked{$item} eq 'on') {
880: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 881: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 882: } elsif ($defaultchecked{$item} eq 'off') {
883: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 884: $checkedon{$item} = ' ';
885: }
1.1 raeburn 886: }
1.160.6.5 raeburn 887: my @images = ('img','logo','domlogo','login');
888: my @logintext = ('textcol','bgcol');
889: my @bgs = ('pgbg','mainbg','sidebg');
890: my @links = ('link','alink','vlink');
891: my %designhash = &Apache::loncommon::get_domainconf($dom);
892: my %defaultdesign = %Apache::loncommon::defaultdesign;
893: my (%is_custom,%designs);
894: my %defaults = (
895: font => $defaultdesign{'login.font'},
896: );
1.6 raeburn 897: foreach my $item (@images) {
1.160.6.5 raeburn 898: $defaults{$item} = $defaultdesign{'login.'.$item};
899: $defaults{'showlogo'}{$item} = 1;
900: }
901: foreach my $item (@bgs) {
902: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 903: }
1.41 raeburn 904: foreach my $item (@logintext) {
1.160.6.5 raeburn 905: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 906: }
1.160.6.5 raeburn 907: foreach my $item (@links) {
908: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 909: }
1.160.6.5 raeburn 910: if (ref($settings) eq 'HASH') {
911: foreach my $item (@toggles) {
912: if ($settings->{$item} eq '1') {
913: $checkedon{$item} = ' checked="checked" ';
914: $checkedoff{$item} = ' ';
915: } elsif ($settings->{$item} eq '0') {
916: $checkedoff{$item} = ' checked="checked" ';
917: $checkedon{$item} = ' ';
918: }
1.6 raeburn 919: }
1.160.6.5 raeburn 920: foreach my $item (@images) {
921: if (defined($settings->{$item})) {
922: $designs{$item} = $settings->{$item};
923: $is_custom{$item} = 1;
924: }
925: if (defined($settings->{'showlogo'}{$item})) {
926: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
927: }
928: }
929: foreach my $item (@logintext) {
930: if ($settings->{$item} ne '') {
931: $designs{'logintext'}{$item} = $settings->{$item};
932: $is_custom{$item} = 1;
933: }
934: }
935: if ($settings->{'font'} ne '') {
936: $designs{'font'} = $settings->{'font'};
937: $is_custom{'font'} = 1;
938: }
939: foreach my $item (@bgs) {
940: if ($settings->{$item} ne '') {
941: $designs{'bgs'}{$item} = $settings->{$item};
942: $is_custom{$item} = 1;
943: }
944: }
945: foreach my $item (@links) {
946: if ($settings->{$item} ne '') {
947: $designs{'links'}{$item} = $settings->{$item};
948: $is_custom{$item} = 1;
949: }
950: }
951: } else {
952: if ($designhash{$dom.'.login.font'} ne '') {
953: $designs{'font'} = $designhash{$dom.'.login.font'};
954: $is_custom{'font'} = 1;
955: }
956: foreach my $item (@images) {
957: if ($designhash{$dom.'.login.'.$item} ne '') {
958: $designs{$item} = $designhash{$dom.'.login.'.$item};
959: $is_custom{$item} = 1;
960: }
961: }
962: foreach my $item (@bgs) {
963: if ($designhash{$dom.'.login.'.$item} ne '') {
964: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
965: $is_custom{$item} = 1;
966: }
967: }
968: foreach my $item (@links) {
969: if ($designhash{$dom.'.login.'.$item} ne '') {
970: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
971: $is_custom{$item} = 1;
972: }
1.6 raeburn 973: }
974: }
1.160.6.5 raeburn 975: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
976: logo => 'Institution Logo',
977: domlogo => 'Domain Logo',
978: login => 'Login box');
979: my $itemcount = 1;
980: foreach my $item (@toggles) {
981: $css_class = $itemcount%2?' class="LC_odd_row"':'';
982: $datatable .=
983: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
984: '</td><td>'.
985: '<span class="LC_nobreak"><label><input type="radio" name="'.
986: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
987: '</label> <label><input type="radio" name="'.$item.'"'.
988: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
989: '</tr>';
990: $itemcount ++;
1.6 raeburn 991: }
1.160.6.5 raeburn 992: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
993: $datatable .= '</tr></table></td></tr>';
994: } elsif ($caller eq 'help') {
995: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
996: my $switchserver = &check_switchserver($dom,$confname);
997: my $itemcount = 1;
998: $defaulturl = '/adm/loginproblems.html';
999: $defaulttype = 'default';
1000: %lt = &Apache::lonlocal::texthash (
1001: del => 'Delete?',
1002: rep => 'Replace:',
1003: upl => 'Upload:',
1004: default => 'Default',
1005: custom => 'Custom',
1006: );
1007: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1008: my @currlangs;
1009: if (ref($settings) eq 'HASH') {
1010: if (ref($settings->{'helpurl'}) eq 'HASH') {
1011: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1012: next if ($settings->{'helpurl'}{$key} eq '');
1013: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1014: $type{$key} = 'custom';
1015: unless ($key eq 'nolang') {
1016: push(@currlangs,$key);
1017: }
1018: }
1019: } elsif ($settings->{'helpurl'} ne '') {
1020: $type{'nolang'} = 'custom';
1021: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1022: }
1023: }
1.160.6.5 raeburn 1024: foreach my $lang ('nolang',sort(@currlangs)) {
1025: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1026: $datatable .= '<tr'.$css_class.'>';
1027: if ($url{$lang} eq '') {
1028: $url{$lang} = $defaulturl;
1029: }
1030: if ($type{$lang} eq '') {
1031: $type{$lang} = $defaulttype;
1032: }
1033: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1034: if ($lang eq 'nolang') {
1035: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1036: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1037: } else {
1038: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1039: $langchoices{$lang},
1040: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1041: }
1042: $datatable .= '</span></td>'."\n".
1043: '<td class="LC_left_item">';
1044: if ($type{$lang} eq 'custom') {
1045: $datatable .= '<span class="LC_nobreak"><label>'.
1046: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1047: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1048: } else {
1049: $datatable .= $lt{'upl'};
1050: }
1051: $datatable .='<br />';
1052: if ($switchserver) {
1053: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1054: } else {
1055: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1056: }
1.160.6.5 raeburn 1057: $datatable .= '</td></tr>';
1058: $itemcount ++;
1.6 raeburn 1059: }
1.160.6.5 raeburn 1060: my @addlangs;
1061: foreach my $lang (sort(keys(%langchoices))) {
1062: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1063: push(@addlangs,$lang);
1064: }
1065: if (@addlangs > 0) {
1066: my %toadd;
1067: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1068: $toadd{''} = &mt('Select');
1069: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1070: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1071: &mt('Add log-in help page for a specific language:').' '.
1072: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1073: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1074: if ($switchserver) {
1075: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1076: } else {
1077: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1078: }
1.160.6.5 raeburn 1079: $datatable .= '</td></tr>';
1080: $itemcount ++;
1.6 raeburn 1081: }
1.160.6.5 raeburn 1082: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1083: }
1.6 raeburn 1084: return $datatable;
1085: }
1086:
1087: sub login_choices {
1088: my %choices =
1089: &Apache::lonlocal::texthash (
1.116 bisitz 1090: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1091: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1092: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1093: disallowlogin => "Login page requests redirected",
1094: hostid => "Server",
1.128 raeburn 1095: server => "Redirect to:",
1096: serverpath => "Path",
1097: custompath => "Custom",
1098: exempt => "Exempt IP(s)",
1.110 raeburn 1099: directlogin => "No redirect",
1100: newuser => "Link to create a user account",
1101: img => "Header",
1102: logo => "Main Logo",
1103: domlogo => "Domain Logo",
1104: login => "Log-in Header",
1105: textcol => "Text color",
1106: bgcol => "Box color",
1107: bgs => "Background colors",
1108: links => "Link colors",
1109: font => "Font color",
1110: pgbg => "Header",
1111: mainbg => "Page",
1112: sidebg => "Login box",
1113: link => "Link",
1114: alink => "Active link",
1115: vlink => "Visited link",
1.6 raeburn 1116: );
1117: return %choices;
1118: }
1119:
1120: sub print_rolecolors {
1.30 raeburn 1121: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1122: my %choices = &color_font_choices();
1123: my @bgs = ('pgbg','tabbg','sidebg');
1124: my @links = ('link','alink','vlink');
1125: my @images = ('img');
1126: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1127: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1128: my %defaultdesign = %Apache::loncommon::defaultdesign;
1129: my (%is_custom,%designs);
1.160.6.22 raeburn 1130: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1131: if (ref($settings) eq 'HASH') {
1132: if (ref($settings->{$role}) eq 'HASH') {
1133: if ($settings->{$role}->{'img'} ne '') {
1134: $designs{'img'} = $settings->{$role}->{'img'};
1135: $is_custom{'img'} = 1;
1136: }
1137: if ($settings->{$role}->{'font'} ne '') {
1138: $designs{'font'} = $settings->{$role}->{'font'};
1139: $is_custom{'font'} = 1;
1140: }
1.97 tempelho 1141: if ($settings->{$role}->{'fontmenu'} ne '') {
1142: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1143: $is_custom{'fontmenu'} = 1;
1144: }
1.6 raeburn 1145: foreach my $item (@bgs) {
1146: if ($settings->{$role}->{$item} ne '') {
1147: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1148: $is_custom{$item} = 1;
1149: }
1150: }
1151: foreach my $item (@links) {
1152: if ($settings->{$role}->{$item} ne '') {
1153: $designs{'links'}{$item} = $settings->{$role}->{$item};
1154: $is_custom{$item} = 1;
1155: }
1156: }
1157: }
1158: } else {
1159: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1160: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1161: $is_custom{'img'} = 1;
1162: }
1.97 tempelho 1163: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1164: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1165: $is_custom{'fontmenu'} = 1;
1166: }
1.6 raeburn 1167: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1168: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1169: $is_custom{'font'} = 1;
1170: }
1171: foreach my $item (@bgs) {
1172: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1173: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1174: $is_custom{$item} = 1;
1175:
1176: }
1177: }
1178: foreach my $item (@links) {
1179: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1180: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1181: $is_custom{$item} = 1;
1182: }
1183: }
1184: }
1185: my $itemcount = 1;
1.30 raeburn 1186: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1187: $datatable .= '</tr></table></td></tr>';
1188: return $datatable;
1189: }
1190:
1.160.6.22 raeburn 1191: sub role_defaults {
1192: my ($role,$bgs,$links,$images,$logintext) = @_;
1193: my %defaults;
1194: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1195: return %defaults;
1196: }
1197: my %defaultdesign = %Apache::loncommon::defaultdesign;
1198: if ($role eq 'login') {
1199: %defaults = (
1200: font => $defaultdesign{$role.'.font'},
1201: );
1202: if (ref($logintext) eq 'ARRAY') {
1203: foreach my $item (@{$logintext}) {
1204: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1205: }
1206: }
1207: foreach my $item (@{$images}) {
1208: $defaults{'showlogo'}{$item} = 1;
1209: }
1210: } else {
1211: %defaults = (
1212: img => $defaultdesign{$role.'.img'},
1213: font => $defaultdesign{$role.'.font'},
1214: fontmenu => $defaultdesign{$role.'.fontmenu'},
1215: );
1216: }
1217: foreach my $item (@{$bgs}) {
1218: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1219: }
1220: foreach my $item (@{$links}) {
1221: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1222: }
1223: foreach my $item (@{$images}) {
1224: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1225: }
1226: return %defaults;
1227: }
1228:
1.6 raeburn 1229: sub display_color_options {
1.9 raeburn 1230: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1231: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1232: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1233: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1234: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1235: '<td>'.$choices->{'font'}.'</td>';
1236: if (!$is_custom->{'font'}) {
1.30 raeburn 1237: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1238: } else {
1239: $datatable .= '<td> </td>';
1240: }
1.160.6.9 raeburn 1241: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1242:
1.8 raeburn 1243: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1244: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1245: ' value="'.$current_color.'" /> '.
1246: ' </td></tr>';
1.107 raeburn 1247: unless ($role eq 'login') {
1248: $datatable .= '<tr'.$css_class.'>'.
1249: '<td>'.$choices->{'fontmenu'}.'</td>';
1250: if (!$is_custom->{'fontmenu'}) {
1251: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1252: } else {
1253: $datatable .= '<td> </td>';
1254: }
1.160.6.22 raeburn 1255: $current_color = $designs->{'fontmenu'} ?
1256: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1257: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1258: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1259: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1260: ' value="'.$current_color.'" /> '.
1261: ' </td></tr>';
1.97 tempelho 1262: }
1.9 raeburn 1263: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1264: foreach my $img (@{$images}) {
1.18 albertel 1265: $itemcount ++;
1.6 raeburn 1266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1267: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1268: '<td>'.$choices->{$img};
1.41 raeburn 1269: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1270: if ($role eq 'login') {
1271: if ($img eq 'login') {
1272: $login_hdr_pick =
1.135 bisitz 1273: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1274: $logincolors =
1275: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1276: $designs,$defaults);
1.70 raeburn 1277: } elsif ($img ne 'domlogo') {
1278: $datatable.= &logo_display_options($img,$defaults,$designs);
1279: }
1280: }
1281: $datatable .= '</td>';
1.6 raeburn 1282: if ($designs->{$img} ne '') {
1283: $imgfile = $designs->{$img};
1.18 albertel 1284: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1285: } else {
1286: $imgfile = $defaults->{$img};
1287: }
1288: if ($imgfile) {
1.9 raeburn 1289: my ($showfile,$fullsize);
1290: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1291: my $urldir = $1;
1292: my $filename = $2;
1293: my @info = &Apache::lonnet::stat_file($designs->{$img});
1294: if (@info) {
1295: my $thumbfile = 'tn-'.$filename;
1296: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1297: if (@thumb) {
1298: $showfile = $urldir.'/'.$thumbfile;
1299: } else {
1300: $showfile = $imgfile;
1301: }
1302: } else {
1303: $showfile = '';
1304: }
1305: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1306: $showfile = $imgfile;
1.6 raeburn 1307: my $imgdir = $1;
1308: my $filename = $2;
1.159 raeburn 1309: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1310: $showfile = "/$imgdir/tn-".$filename;
1311: } else {
1.159 raeburn 1312: my $input = $londocroot.$imgfile;
1313: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1314: if (!-e $output) {
1.9 raeburn 1315: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1316: my ($fullwidth,$fullheight) = &check_dimensions($input);
1317: if ($fullwidth ne '' && $fullheight ne '') {
1318: if ($fullwidth > $width && $fullheight > $height) {
1319: my $size = $width.'x'.$height;
1320: system("convert -sample $size $input $output");
1.159 raeburn 1321: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1322: }
1323: }
1.6 raeburn 1324: }
1325: }
1.16 raeburn 1326: }
1.6 raeburn 1327: if ($showfile) {
1.40 raeburn 1328: if ($showfile =~ m{^/(adm|res)/}) {
1329: if ($showfile =~ m{^/res/}) {
1330: my $local_showfile =
1331: &Apache::lonnet::filelocation('',$showfile);
1332: &Apache::lonnet::repcopy($local_showfile);
1333: }
1334: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1335: }
1336: if ($imgfile) {
1337: if ($imgfile =~ m{^/(adm|res)/}) {
1338: if ($imgfile =~ m{^/res/}) {
1339: my $local_imgfile =
1340: &Apache::lonnet::filelocation('',$imgfile);
1341: &Apache::lonnet::repcopy($local_imgfile);
1342: }
1343: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1344: } else {
1345: $fullsize = $imgfile;
1346: }
1347: }
1.41 raeburn 1348: $datatable .= '<td>';
1349: if ($img eq 'login') {
1.135 bisitz 1350: $datatable .= $login_hdr_pick;
1351: }
1.41 raeburn 1352: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1353: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1354: } else {
1.160.6.22 raeburn 1355: $datatable .= '<td> </td><td class="LC_left_item">'.
1356: &mt('Upload:').'<br />';
1.6 raeburn 1357: }
1358: } else {
1.160.6.22 raeburn 1359: $datatable .= '<td> </td><td class="LC_left_item">'.
1360: &mt('Upload:').'<br />';
1.6 raeburn 1361: }
1.9 raeburn 1362: if ($switchserver) {
1363: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1364: } else {
1.135 bisitz 1365: if ($img ne 'login') { # suppress file selection for Log-in header
1366: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1367: }
1.9 raeburn 1368: }
1369: $datatable .= '</td></tr>';
1.6 raeburn 1370: }
1371: $itemcount ++;
1372: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1373: $datatable .= '<tr'.$css_class.'>'.
1374: '<td>'.$choices->{'bgs'}.'</td>';
1375: my $bgs_def;
1376: foreach my $item (@{$bgs}) {
1377: if (!$is_custom->{$item}) {
1.70 raeburn 1378: $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 1379: }
1380: }
1381: if ($bgs_def) {
1.8 raeburn 1382: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1383: } else {
1384: $datatable .= '<td> </td>';
1385: }
1386: $datatable .= '<td class="LC_right_item">'.
1387: '<table border="0"><tr>';
1.160.6.13 raeburn 1388:
1.6 raeburn 1389: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1390: $datatable .= '<td align="center">'.$choices->{$item};
1391: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1392: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1393: $datatable .= ' ';
1.6 raeburn 1394: }
1.160.6.9 raeburn 1395: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1396: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1397: }
1398: $datatable .= '</tr></table></td></tr>';
1399: $itemcount ++;
1400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1401: $datatable .= '<tr'.$css_class.'>'.
1402: '<td>'.$choices->{'links'}.'</td>';
1403: my $links_def;
1404: foreach my $item (@{$links}) {
1405: if (!$is_custom->{$item}) {
1.30 raeburn 1406: $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 1407: }
1408: }
1409: if ($links_def) {
1.8 raeburn 1410: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1411: } else {
1412: $datatable .= '<td> </td>';
1413: }
1414: $datatable .= '<td class="LC_right_item">'.
1415: '<table border="0"><tr>';
1416: foreach my $item (@{$links}) {
1.160.6.22 raeburn 1417: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1418: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1419: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1420: $datatable.=' ';
1.6 raeburn 1421: }
1.160.6.9 raeburn 1422: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1423: '" /></td>';
1424: }
1.30 raeburn 1425: $$rowtotal += $itemcount;
1.3 raeburn 1426: return $datatable;
1427: }
1428:
1.70 raeburn 1429: sub logo_display_options {
1430: my ($img,$defaults,$designs) = @_;
1431: my $checkedon;
1432: if (ref($defaults) eq 'HASH') {
1433: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1434: if ($defaults->{'showlogo'}{$img}) {
1435: $checkedon = 'checked="checked" ';
1436: }
1437: }
1438: }
1439: if (ref($designs) eq 'HASH') {
1440: if (ref($designs->{'showlogo'}) eq 'HASH') {
1441: if (defined($designs->{'showlogo'}{$img})) {
1442: if ($designs->{'showlogo'}{$img} == 0) {
1443: $checkedon = '';
1444: } elsif ($designs->{'showlogo'}{$img} == 1) {
1445: $checkedon = 'checked="checked" ';
1446: }
1447: }
1448: }
1449: }
1450: return '<br /><label> <input type="checkbox" name="'.
1451: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1452: &mt('show').'</label>'."\n";
1453: }
1454:
1.41 raeburn 1455: sub login_header_options {
1.135 bisitz 1456: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1457: my $output = '';
1.41 raeburn 1458: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1459: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1460: if (!$is_custom->{'textcol'}) {
1461: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1462: ' ';
1463: }
1464: if (!$is_custom->{'bgcol'}) {
1465: $output .= $choices->{'bgcol'}.': '.
1466: '<span id="css_'.$role.'_font" style="background-color: '.
1467: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1468: }
1469: $output .= '<br />';
1470: }
1471: $output .='<br />';
1472: return $output;
1473: }
1474:
1475: sub login_text_colors {
1.160.6.22 raeburn 1476: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1477: my $color_menu = '<table border="0"><tr>';
1478: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1479: $color_menu .= '<td align="center">'.$choices->{$item};
1480: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1481: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1482: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1483: }
1484: $color_menu .= '</tr></table><br />';
1485: return $color_menu;
1486: }
1487:
1488: sub image_changes {
1489: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1490: my $output;
1.135 bisitz 1491: if ($img eq 'login') {
1492: # suppress image for Log-in header
1493: } elsif (!$is_custom) {
1.70 raeburn 1494: if ($img ne 'domlogo') {
1.41 raeburn 1495: $output .= &mt('Default image:').'<br />';
1496: } else {
1497: $output .= &mt('Default in use:').'<br />';
1498: }
1499: }
1.135 bisitz 1500: if ($img eq 'login') { # suppress image for Log-in header
1501: $output .= '<td>'.$logincolors;
1.41 raeburn 1502: } else {
1.135 bisitz 1503: if ($img_import) {
1504: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1505: }
1506: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1507: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1508: if ($is_custom) {
1509: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1510: '<input type="checkbox" name="'.
1511: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1512: '</label> '.&mt('Replace:').'</span><br />';
1513: } else {
1.160.6.22 raeburn 1514: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1515: }
1.41 raeburn 1516: }
1517: return $output;
1518: }
1519:
1.3 raeburn 1520: sub print_quotas {
1.86 raeburn 1521: my ($dom,$settings,$rowtotal,$action) = @_;
1522: my $context;
1523: if ($action eq 'quotas') {
1524: $context = 'tools';
1525: } else {
1526: $context = $action;
1527: }
1.160.6.20 raeburn 1528: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1529: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1530: my $typecount = 0;
1.101 raeburn 1531: my ($css_class,%titles);
1.86 raeburn 1532: if ($context eq 'requestcourses') {
1.98 raeburn 1533: @usertools = ('official','unofficial','community');
1.106 raeburn 1534: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1535: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1536: %titles = &courserequest_titles();
1.160.6.5 raeburn 1537: } elsif ($context eq 'requestauthor') {
1538: @usertools = ('author');
1539: @options = ('norequest','approval','automatic');
1540: %titles = &authorrequest_titles();
1.86 raeburn 1541: } else {
1.160.6.4 raeburn 1542: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1543: %titles = &tool_titles();
1.86 raeburn 1544: }
1.26 raeburn 1545: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1546: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1547: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1548: unless (($context eq 'requestcourses') ||
1549: ($context eq 'requestauthor')) {
1.86 raeburn 1550: if (ref($settings) eq 'HASH') {
1551: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1552: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1553: } else {
1554: $currdefquota = $settings->{$type};
1555: }
1.160.6.20 raeburn 1556: if (ref($settings->{authorquota}) eq 'HASH') {
1557: $currauthorquota = $settings->{authorquota}->{$type};
1558: }
1.78 raeburn 1559: }
1.72 raeburn 1560: }
1.3 raeburn 1561: if (defined($usertypes->{$type})) {
1562: $typecount ++;
1563: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1564: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1565: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1566: '<td class="LC_left_item">';
1.101 raeburn 1567: if ($context eq 'requestcourses') {
1568: $datatable .= '<table><tr>';
1569: }
1570: my %cell;
1.72 raeburn 1571: foreach my $item (@usertools) {
1.101 raeburn 1572: if ($context eq 'requestcourses') {
1573: my ($curroption,$currlimit);
1574: if (ref($settings) eq 'HASH') {
1575: if (ref($settings->{$item}) eq 'HASH') {
1576: $curroption = $settings->{$item}->{$type};
1577: if ($curroption =~ /^autolimit=(\d*)$/) {
1578: $currlimit = $1;
1579: }
1580: }
1581: }
1582: if (!$curroption) {
1583: $curroption = 'norequest';
1584: }
1585: $datatable .= '<th>'.$titles{$item}.'</th>';
1586: foreach my $option (@options) {
1587: my $val = $option;
1588: if ($option eq 'norequest') {
1589: $val = 0;
1590: }
1591: if ($option eq 'validate') {
1592: my $canvalidate = 0;
1593: if (ref($validations{$item}) eq 'HASH') {
1594: if ($validations{$item}{$type}) {
1595: $canvalidate = 1;
1596: }
1597: }
1598: next if (!$canvalidate);
1599: }
1600: my $checked = '';
1601: if ($option eq $curroption) {
1602: $checked = ' checked="checked"';
1603: } elsif ($option eq 'autolimit') {
1604: if ($curroption =~ /^autolimit/) {
1605: $checked = ' checked="checked"';
1606: }
1607: }
1608: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1609: '<input type="radio" name="crsreq_'.$item.
1610: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1611: $titles{$option}.'</label>';
1.101 raeburn 1612: if ($option eq 'autolimit') {
1.127 raeburn 1613: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1614: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1615: 'value="'.$currlimit.'" />';
1.101 raeburn 1616: }
1.127 raeburn 1617: $cell{$item} .= '</span> ';
1.103 raeburn 1618: if ($option eq 'autolimit') {
1.127 raeburn 1619: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1620: }
1.101 raeburn 1621: }
1.160.6.5 raeburn 1622: } elsif ($context eq 'requestauthor') {
1623: my $curroption;
1624: if (ref($settings) eq 'HASH') {
1625: $curroption = $settings->{$type};
1626: }
1627: if (!$curroption) {
1628: $curroption = 'norequest';
1629: }
1630: foreach my $option (@options) {
1631: my $val = $option;
1632: if ($option eq 'norequest') {
1633: $val = 0;
1634: }
1635: my $checked = '';
1636: if ($option eq $curroption) {
1637: $checked = ' checked="checked"';
1638: }
1639: $datatable .= '<span class="LC_nobreak"><label>'.
1640: '<input type="radio" name="authorreq_'.$type.
1641: '" value="'.$val.'"'.$checked.' />'.
1642: $titles{$option}.'</label></span> ';
1643: }
1.101 raeburn 1644: } else {
1645: my $checked = 'checked="checked" ';
1646: if (ref($settings) eq 'HASH') {
1647: if (ref($settings->{$item}) eq 'HASH') {
1648: if ($settings->{$item}->{$type} == 0) {
1649: $checked = '';
1650: } elsif ($settings->{$item}->{$type} == 1) {
1651: $checked = 'checked="checked" ';
1652: }
1.78 raeburn 1653: }
1.72 raeburn 1654: }
1.101 raeburn 1655: $datatable .= '<span class="LC_nobreak"><label>'.
1656: '<input type="checkbox" name="'.$context.'_'.$item.
1657: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1658: '</label></span> ';
1.72 raeburn 1659: }
1.101 raeburn 1660: }
1661: if ($context eq 'requestcourses') {
1662: $datatable .= '</tr><tr>';
1663: foreach my $item (@usertools) {
1.106 raeburn 1664: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1665: }
1666: $datatable .= '</tr></table>';
1.72 raeburn 1667: }
1.86 raeburn 1668: $datatable .= '</td>';
1.160.6.5 raeburn 1669: unless (($context eq 'requestcourses') ||
1670: ($context eq 'requestauthor')) {
1.86 raeburn 1671: $datatable .=
1.160.6.20 raeburn 1672: '<td class="LC_right_item">'.
1673: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1674: '<input type="text" name="quota_'.$type.
1.72 raeburn 1675: '" value="'.$currdefquota.
1.160.6.20 raeburn 1676: '" size="5" /></span>'.(' ' x 2).
1677: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1678: '<input type="text" name="authorquota_'.$type.
1679: '" value="'.$currauthorquota.
1680: '" size="5" /></span></td>';
1.86 raeburn 1681: }
1682: $datatable .= '</tr>';
1.3 raeburn 1683: }
1684: }
1685: }
1.160.6.5 raeburn 1686: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1687: $defaultquota = '20';
1.160.6.20 raeburn 1688: $authorquota = '500';
1.86 raeburn 1689: if (ref($settings) eq 'HASH') {
1690: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1691: $defaultquota = $settings->{'defaultquota'}->{'default'};
1692: } elsif (defined($settings->{'default'})) {
1693: $defaultquota = $settings->{'default'};
1694: }
1.160.6.20 raeburn 1695: if (ref($settings->{'authorquota'}) eq 'HASH') {
1696: $authorquota = $settings->{'authorquota'}->{'default'};
1697: }
1.3 raeburn 1698: }
1699: }
1700: $typecount ++;
1701: $css_class = $typecount%2?' class="LC_odd_row"':'';
1702: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1703: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1704: '<td class="LC_left_item">';
1.101 raeburn 1705: if ($context eq 'requestcourses') {
1706: $datatable .= '<table><tr>';
1707: }
1708: my %defcell;
1.72 raeburn 1709: foreach my $item (@usertools) {
1.101 raeburn 1710: if ($context eq 'requestcourses') {
1711: my ($curroption,$currlimit);
1712: if (ref($settings) eq 'HASH') {
1713: if (ref($settings->{$item}) eq 'HASH') {
1714: $curroption = $settings->{$item}->{'default'};
1715: if ($curroption =~ /^autolimit=(\d*)$/) {
1716: $currlimit = $1;
1717: }
1718: }
1719: }
1720: if (!$curroption) {
1721: $curroption = 'norequest';
1722: }
1723: $datatable .= '<th>'.$titles{$item}.'</th>';
1724: foreach my $option (@options) {
1725: my $val = $option;
1726: if ($option eq 'norequest') {
1727: $val = 0;
1728: }
1729: if ($option eq 'validate') {
1730: my $canvalidate = 0;
1731: if (ref($validations{$item}) eq 'HASH') {
1732: if ($validations{$item}{'default'}) {
1733: $canvalidate = 1;
1734: }
1735: }
1736: next if (!$canvalidate);
1737: }
1738: my $checked = '';
1739: if ($option eq $curroption) {
1740: $checked = ' checked="checked"';
1741: } elsif ($option eq 'autolimit') {
1742: if ($curroption =~ /^autolimit/) {
1743: $checked = ' checked="checked"';
1744: }
1745: }
1746: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1747: '<input type="radio" name="crsreq_'.$item.
1748: '_default" value="'.$val.'"'.$checked.' />'.
1749: $titles{$option}.'</label>';
1750: if ($option eq 'autolimit') {
1.127 raeburn 1751: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1752: $item.'_limit_default" size="1" '.
1753: 'value="'.$currlimit.'" />';
1754: }
1.127 raeburn 1755: $defcell{$item} .= '</span> ';
1.104 raeburn 1756: if ($option eq 'autolimit') {
1.127 raeburn 1757: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1758: }
1.101 raeburn 1759: }
1.160.6.5 raeburn 1760: } elsif ($context eq 'requestauthor') {
1761: my $curroption;
1762: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1763: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1764: }
1765: if (!$curroption) {
1766: $curroption = 'norequest';
1767: }
1768: foreach my $option (@options) {
1769: my $val = $option;
1770: if ($option eq 'norequest') {
1771: $val = 0;
1772: }
1773: my $checked = '';
1774: if ($option eq $curroption) {
1775: $checked = ' checked="checked"';
1776: }
1777: $datatable .= '<span class="LC_nobreak"><label>'.
1778: '<input type="radio" name="authorreq_default"'.
1779: ' value="'.$val.'"'.$checked.' />'.
1780: $titles{$option}.'</label></span> ';
1781: }
1.101 raeburn 1782: } else {
1783: my $checked = 'checked="checked" ';
1784: if (ref($settings) eq 'HASH') {
1785: if (ref($settings->{$item}) eq 'HASH') {
1786: if ($settings->{$item}->{'default'} == 0) {
1787: $checked = '';
1788: } elsif ($settings->{$item}->{'default'} == 1) {
1789: $checked = 'checked="checked" ';
1790: }
1.78 raeburn 1791: }
1.72 raeburn 1792: }
1.101 raeburn 1793: $datatable .= '<span class="LC_nobreak"><label>'.
1794: '<input type="checkbox" name="'.$context.'_'.$item.
1795: '" value="default" '.$checked.'/>'.$titles{$item}.
1796: '</label></span> ';
1797: }
1798: }
1799: if ($context eq 'requestcourses') {
1800: $datatable .= '</tr><tr>';
1801: foreach my $item (@usertools) {
1.106 raeburn 1802: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1803: }
1.101 raeburn 1804: $datatable .= '</tr></table>';
1.72 raeburn 1805: }
1.86 raeburn 1806: $datatable .= '</td>';
1.160.6.5 raeburn 1807: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1808: $datatable .= '<td class="LC_right_item">'.
1809: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1810: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1811: $defaultquota.'" size="5" /></span>'.(' ' x2).
1812: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1813: '<input type="text" name="authorquota" value="'.
1814: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1815: }
1816: $datatable .= '</tr>';
1.72 raeburn 1817: $typecount ++;
1818: $css_class = $typecount%2?' class="LC_odd_row"':'';
1819: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1820: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1821: if ($context eq 'requestcourses') {
1.109 raeburn 1822: $datatable .= &mt('(overrides affiliation, if set)').
1823: '</td>'.
1824: '<td class="LC_left_item">'.
1825: '<table><tr>';
1.101 raeburn 1826: } else {
1.109 raeburn 1827: $datatable .= &mt('(overrides affiliation, if checked)').
1828: '</td>'.
1829: '<td class="LC_left_item" colspan="2">'.
1830: '<br />';
1.101 raeburn 1831: }
1832: my %advcell;
1.72 raeburn 1833: foreach my $item (@usertools) {
1.101 raeburn 1834: if ($context eq 'requestcourses') {
1835: my ($curroption,$currlimit);
1836: if (ref($settings) eq 'HASH') {
1837: if (ref($settings->{$item}) eq 'HASH') {
1838: $curroption = $settings->{$item}->{'_LC_adv'};
1839: if ($curroption =~ /^autolimit=(\d*)$/) {
1840: $currlimit = $1;
1841: }
1842: }
1843: }
1844: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1845: my $checked = '';
1846: if ($curroption eq '') {
1847: $checked = ' checked="checked"';
1848: }
1849: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1850: '<input type="radio" name="crsreq_'.$item.
1851: '__LC_adv" value=""'.$checked.' />'.
1852: &mt('No override set').'</label></span> ';
1.101 raeburn 1853: foreach my $option (@options) {
1854: my $val = $option;
1855: if ($option eq 'norequest') {
1856: $val = 0;
1857: }
1858: if ($option eq 'validate') {
1859: my $canvalidate = 0;
1860: if (ref($validations{$item}) eq 'HASH') {
1861: if ($validations{$item}{'_LC_adv'}) {
1862: $canvalidate = 1;
1863: }
1864: }
1865: next if (!$canvalidate);
1866: }
1867: my $checked = '';
1.104 raeburn 1868: if ($val eq $curroption) {
1.101 raeburn 1869: $checked = ' checked="checked"';
1870: } elsif ($option eq 'autolimit') {
1871: if ($curroption =~ /^autolimit/) {
1872: $checked = ' checked="checked"';
1873: }
1874: }
1875: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1876: '<input type="radio" name="crsreq_'.$item.
1877: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1878: $titles{$option}.'</label>';
1879: if ($option eq 'autolimit') {
1.127 raeburn 1880: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1881: $item.'_limit__LC_adv" size="1" '.
1882: 'value="'.$currlimit.'" />';
1883: }
1.127 raeburn 1884: $advcell{$item} .= '</span> ';
1.104 raeburn 1885: if ($option eq 'autolimit') {
1.127 raeburn 1886: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1887: }
1.101 raeburn 1888: }
1.160.6.5 raeburn 1889: } elsif ($context eq 'requestauthor') {
1890: my $curroption;
1891: if (ref($settings) eq 'HASH') {
1892: $curroption = $settings->{'_LC_adv'};
1893: }
1894: my $checked = '';
1895: if ($curroption eq '') {
1896: $checked = ' checked="checked"';
1897: }
1898: $datatable .= '<span class="LC_nobreak"><label>'.
1899: '<input type="radio" name="authorreq__LC_adv"'.
1900: ' value=""'.$checked.' />'.
1901: &mt('No override set').'</label></span> ';
1902: foreach my $option (@options) {
1903: my $val = $option;
1904: if ($option eq 'norequest') {
1905: $val = 0;
1906: }
1907: my $checked = '';
1908: if ($val eq $curroption) {
1909: $checked = ' checked="checked"';
1910: }
1911: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1912: '<input type="radio" name="authorreq__LC_adv"'.
1913: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1914: $titles{$option}.'</label></span> ';
1915: }
1.101 raeburn 1916: } else {
1917: my $checked = 'checked="checked" ';
1918: if (ref($settings) eq 'HASH') {
1919: if (ref($settings->{$item}) eq 'HASH') {
1920: if ($settings->{$item}->{'_LC_adv'} == 0) {
1921: $checked = '';
1922: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1923: $checked = 'checked="checked" ';
1924: }
1.79 raeburn 1925: }
1.72 raeburn 1926: }
1.101 raeburn 1927: $datatable .= '<span class="LC_nobreak"><label>'.
1928: '<input type="checkbox" name="'.$context.'_'.$item.
1929: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1930: '</label></span> ';
1931: }
1932: }
1933: if ($context eq 'requestcourses') {
1934: $datatable .= '</tr><tr>';
1935: foreach my $item (@usertools) {
1.106 raeburn 1936: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1937: }
1.101 raeburn 1938: $datatable .= '</tr></table>';
1.72 raeburn 1939: }
1.98 raeburn 1940: $datatable .= '</td></tr>';
1.30 raeburn 1941: $$rowtotal += $typecount;
1.3 raeburn 1942: return $datatable;
1943: }
1944:
1.160.6.5 raeburn 1945: sub print_requestmail {
1946: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25! raeburn 1947: my ($now,$datatable,%currapp);
1.102 raeburn 1948: $now = time;
1949: if (ref($settings) eq 'HASH') {
1950: if (ref($settings->{'notify'}) eq 'HASH') {
1951: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.16 raeburn 1952: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1953: }
1954: }
1955: }
1.160.6.16 raeburn 1956: my $numinrow = 2;
1.102 raeburn 1957: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1958: my $text;
1959: if ($action eq 'requestcourses') {
1960: $text = &mt('Receive notification of course requests requiring approval');
1961: } else {
1962: $text = &mt('Receive notification of authoring space requests requiring approval')
1963: }
1964: $datatable = '<tr '.$css_class.'>'.
1965: ' <td>'.$text.'</td>'.
1.102 raeburn 1966: ' <td class="LC_left_item">';
1.160.6.16 raeburn 1967: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1968: 'reqapprovalnotify',%currapp);
1969: if ($numdc > 0) {
1970: $datatable .= $table;
1.102 raeburn 1971: } else {
1972: $datatable .= &mt('There are no active Domain Coordinators');
1973: }
1974: $datatable .='</td></tr>';
1975: $$rowtotal += $rows;
1976: return $datatable;
1977: }
1978:
1.3 raeburn 1979: sub print_autoenroll {
1.30 raeburn 1980: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1981: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1982: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1983: if (ref($settings) eq 'HASH') {
1984: if (exists($settings->{'run'})) {
1985: if ($settings->{'run'} eq '0') {
1986: $runoff = ' checked="checked" ';
1987: $runon = ' ';
1988: } else {
1989: $runon = ' checked="checked" ';
1990: $runoff = ' ';
1991: }
1992: } else {
1993: if ($autorun) {
1994: $runon = ' checked="checked" ';
1995: $runoff = ' ';
1996: } else {
1997: $runoff = ' checked="checked" ';
1998: $runon = ' ';
1999: }
2000: }
1.129 raeburn 2001: if (exists($settings->{'co-owners'})) {
2002: if ($settings->{'co-owners'} eq '0') {
2003: $coownersoff = ' checked="checked" ';
2004: $coownerson = ' ';
2005: } else {
2006: $coownerson = ' checked="checked" ';
2007: $coownersoff = ' ';
2008: }
2009: } else {
2010: $coownersoff = ' checked="checked" ';
2011: $coownerson = ' ';
2012: }
1.3 raeburn 2013: if (exists($settings->{'sender_domain'})) {
2014: $defdom = $settings->{'sender_domain'};
2015: }
1.14 raeburn 2016: } else {
2017: if ($autorun) {
2018: $runon = ' checked="checked" ';
2019: $runoff = ' ';
2020: } else {
2021: $runoff = ' checked="checked" ';
2022: $runon = ' ';
2023: }
1.3 raeburn 2024: }
2025: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2026: my $notif_sender;
2027: if (ref($settings) eq 'HASH') {
2028: $notif_sender = $settings->{'sender_uname'};
2029: }
1.3 raeburn 2030: my $datatable='<tr class="LC_odd_row">'.
2031: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2032: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2033: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2034: $runon.' value="1" />'.&mt('Yes').'</label> '.
2035: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2036: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2037: '</tr><tr>'.
2038: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2039: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2040: &mt('username').': '.
2041: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2042: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2043: ': '.$domform.'</span></td></tr>'.
2044: '<tr class="LC_odd_row">'.
2045: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2046: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2047: '<input type="radio" name="autoassign_coowners"'.
2048: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2049: '<label><input type="radio" name="autoassign_coowners"'.
2050: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2051: '</tr>';
2052: $$rowtotal += 3;
1.3 raeburn 2053: return $datatable;
2054: }
2055:
2056: sub print_autoupdate {
1.30 raeburn 2057: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2058: my $datatable;
2059: if ($position eq 'top') {
2060: my $updateon = ' ';
2061: my $updateoff = ' checked="checked" ';
2062: my $classlistson = ' ';
2063: my $classlistsoff = ' checked="checked" ';
2064: if (ref($settings) eq 'HASH') {
2065: if ($settings->{'run'} eq '1') {
2066: $updateon = $updateoff;
2067: $updateoff = ' ';
2068: }
2069: if ($settings->{'classlists'} eq '1') {
2070: $classlistson = $classlistsoff;
2071: $classlistsoff = ' ';
2072: }
2073: }
2074: my %title = (
2075: run => 'Auto-update active?',
2076: classlists => 'Update information in classlists?',
2077: );
2078: $datatable = '<tr class="LC_odd_row">'.
2079: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2080: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2081: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2082: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2083: '<label><input type="radio" name="autoupdate_run"'.
2084: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2085: '</tr><tr>'.
2086: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2087: '<td class="LC_right_item"><span class="LC_nobreak">'.
2088: '<label><input type="radio" name="classlists"'.
2089: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2090: '<label><input type="radio" name="classlists"'.
2091: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2092: '</tr>';
1.30 raeburn 2093: $$rowtotal += 2;
1.131 raeburn 2094: } elsif ($position eq 'middle') {
2095: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2096: my $numinrow = 3;
2097: my $locknamesettings;
2098: $datatable .= &insttypes_row($settings,$types,$usertypes,
2099: $dom,$numinrow,$othertitle,
2100: 'lockablenames');
2101: $$rowtotal ++;
1.3 raeburn 2102: } else {
1.44 raeburn 2103: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2104: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2105: 'permanentemail','id');
1.33 raeburn 2106: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2107: my $numrows = 0;
1.26 raeburn 2108: if (ref($types) eq 'ARRAY') {
2109: if (@{$types} > 0) {
2110: $datatable =
2111: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2112: \@fields,$types,\$numrows);
1.30 raeburn 2113: $$rowtotal += @{$types};
1.26 raeburn 2114: }
1.3 raeburn 2115: }
2116: $datatable .=
2117: &usertype_update_row($settings,{'default' => $othertitle},
2118: \%fieldtitles,\@fields,['default'],
2119: \$numrows);
1.30 raeburn 2120: $$rowtotal ++;
1.3 raeburn 2121: }
2122: return $datatable;
2123: }
2124:
1.125 raeburn 2125: sub print_autocreate {
2126: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2127: my (%createon,%createoff,%currhash);
1.125 raeburn 2128: my @types = ('xml','req');
2129: if (ref($settings) eq 'HASH') {
2130: foreach my $item (@types) {
2131: $createoff{$item} = ' checked="checked" ';
2132: $createon{$item} = ' ';
2133: if (exists($settings->{$item})) {
2134: if ($settings->{$item}) {
2135: $createon{$item} = ' checked="checked" ';
2136: $createoff{$item} = ' ';
2137: }
2138: }
2139: }
1.160.6.16 raeburn 2140: if ($settings->{'xmldc'} ne '') {
2141: $currhash{$settings->{'xmldc'}} = 1;
2142: }
1.125 raeburn 2143: } else {
2144: foreach my $item (@types) {
2145: $createoff{$item} = ' checked="checked" ';
2146: $createon{$item} = ' ';
2147: }
2148: }
2149: $$rowtotal += 2;
1.160.6.16 raeburn 2150: my $numinrow = 2;
1.125 raeburn 2151: my $datatable='<tr class="LC_odd_row">'.
2152: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2153: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2154: '<input type="radio" name="autocreate_xml"'.
2155: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2156: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2157: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2158: '</td></tr><tr>'.
2159: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2160: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2161: '<input type="radio" name="autocreate_req"'.
2162: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2163: '<label><input type="radio" name="autocreate_req"'.
2164: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2165: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2166: 'autocreate_xmldc',%currhash);
1.125 raeburn 2167: if ($numdc > 1) {
1.143 raeburn 2168: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2169: &mt('Course creation processed as: (choose Dom. Coord.)').
2170: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2171: } else {
1.143 raeburn 2172: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2173: }
1.160.6.16 raeburn 2174: $$rowtotal += $rows;
1.125 raeburn 2175: return $datatable;
2176: }
2177:
1.23 raeburn 2178: sub print_directorysrch {
1.30 raeburn 2179: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2180: my $srchon = ' ';
2181: my $srchoff = ' checked="checked" ';
1.25 raeburn 2182: my ($exacton,$containson,$beginson);
1.24 raeburn 2183: my $localon = ' ';
2184: my $localoff = ' checked="checked" ';
1.23 raeburn 2185: if (ref($settings) eq 'HASH') {
2186: if ($settings->{'available'} eq '1') {
2187: $srchon = $srchoff;
2188: $srchoff = ' ';
2189: }
1.24 raeburn 2190: if ($settings->{'localonly'} eq '1') {
2191: $localon = $localoff;
2192: $localoff = ' ';
2193: }
1.25 raeburn 2194: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2195: foreach my $type (@{$settings->{'searchtypes'}}) {
2196: if ($type eq 'exact') {
2197: $exacton = ' checked="checked" ';
2198: } elsif ($type eq 'contains') {
2199: $containson = ' checked="checked" ';
2200: } elsif ($type eq 'begins') {
2201: $beginson = ' checked="checked" ';
2202: }
2203: }
2204: } else {
2205: if ($settings->{'searchtypes'} eq 'exact') {
2206: $exacton = ' checked="checked" ';
2207: } elsif ($settings->{'searchtypes'} eq 'contains') {
2208: $containson = ' checked="checked" ';
2209: } elsif ($settings->{'searchtypes'} eq 'specify') {
2210: $exacton = ' checked="checked" ';
2211: $containson = ' checked="checked" ';
2212: }
1.23 raeburn 2213: }
2214: }
2215: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2217:
2218: my $numinrow = 4;
1.26 raeburn 2219: my $cansrchrow = 0;
1.23 raeburn 2220: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2221: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2222: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2223: '<input type="radio" name="dirsrch_available"'.
2224: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2225: '<label><input type="radio" name="dirsrch_available"'.
2226: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2227: '</tr><tr>'.
1.30 raeburn 2228: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2229: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2230: '<input type="radio" name="dirsrch_localonly"'.
2231: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2232: '<label><input type="radio" name="dirsrch_localonly"'.
2233: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2234: '</tr>';
1.30 raeburn 2235: $$rowtotal += 2;
1.26 raeburn 2236: if (ref($usertypes) eq 'HASH') {
2237: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2238: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2239: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2240: $cansrchrow = 1;
2241: }
2242: }
2243: if ($cansrchrow) {
1.30 raeburn 2244: $$rowtotal ++;
1.26 raeburn 2245: $datatable .= '<tr>';
2246: } else {
2247: $datatable .= '<tr class="LC_odd_row">';
2248: }
1.30 raeburn 2249: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2250: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2251: foreach my $title (@{$titleorder}) {
2252: if (defined($searchtitles->{$title})) {
2253: my $check = ' ';
1.93 raeburn 2254: if (ref($settings) eq 'HASH') {
1.39 raeburn 2255: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2256: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2257: $check = ' checked="checked" ';
2258: }
1.25 raeburn 2259: }
2260: }
2261: $datatable .= '<td class="LC_left_item">'.
2262: '<span class="LC_nobreak"><label>'.
2263: '<input type="checkbox" name="searchby" '.
2264: 'value="'.$title.'"'.$check.'/>'.
2265: $searchtitles->{$title}.'</label></span></td>';
2266: }
2267: }
1.26 raeburn 2268: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2269: $$rowtotal ++;
1.26 raeburn 2270: if ($cansrchrow) {
2271: $datatable .= '<tr class="LC_odd_row">';
2272: } else {
2273: $datatable .= '<tr>';
2274: }
1.30 raeburn 2275: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2276: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2277: '<span class="LC_nobreak"><label>'.
2278: '<input type="checkbox" name="searchtypes" '.
2279: $exacton.' value="exact" />'.&mt('Exact match').
2280: '</label> '.
2281: '<label><input type="checkbox" name="searchtypes" '.
2282: $beginson.' value="begins" />'.&mt('Begins with').
2283: '</label> '.
2284: '<label><input type="checkbox" name="searchtypes" '.
2285: $containson.' value="contains" />'.&mt('Contains').
2286: '</label></span></td></tr>';
1.30 raeburn 2287: $$rowtotal ++;
1.25 raeburn 2288: return $datatable;
2289: }
2290:
1.28 raeburn 2291: sub print_contacts {
1.30 raeburn 2292: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2293: my $datatable;
2294: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2295: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2296: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2297: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2298: foreach my $type (@mailings) {
2299: $otheremails{$type} = '';
2300: }
1.134 raeburn 2301: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2302: if (ref($settings) eq 'HASH') {
2303: foreach my $item (@contacts) {
2304: if (exists($settings->{$item})) {
2305: $to{$item} = $settings->{$item};
2306: }
2307: }
2308: foreach my $type (@mailings) {
2309: if (exists($settings->{$type})) {
2310: if (ref($settings->{$type}) eq 'HASH') {
2311: foreach my $item (@contacts) {
2312: if ($settings->{$type}{$item}) {
2313: $checked{$type}{$item} = ' checked="checked" ';
2314: }
2315: }
2316: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2317: if ($type eq 'helpdeskmail') {
2318: $bccemails{$type} = $settings->{$type}{'bcc'};
2319: }
1.28 raeburn 2320: }
1.89 raeburn 2321: } elsif ($type eq 'lonstatusmail') {
2322: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2323: }
2324: }
2325: } else {
2326: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2327: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2328: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2329: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2330: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2331: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2332: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2333: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2334: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2335: }
2336: my ($titles,$short_titles) = &contact_titles();
2337: my $rownum = 0;
2338: my $css_class;
2339: foreach my $item (@contacts) {
1.69 raeburn 2340: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2341: $datatable .= '<tr'.$css_class.'>'.
2342: '<td><span class="LC_nobreak">'.$titles->{$item}.
2343: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2344: '<input type="text" name="'.$item.'" value="'.
2345: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2346: $rownum ++;
1.28 raeburn 2347: }
2348: foreach my $type (@mailings) {
1.69 raeburn 2349: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2350: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2351: '<td><span class="LC_nobreak">'.
2352: $titles->{$type}.': </span></td>'.
1.28 raeburn 2353: '<td class="LC_left_item">'.
2354: '<span class="LC_nobreak">';
2355: foreach my $item (@contacts) {
2356: $datatable .= '<label>'.
2357: '<input type="checkbox" name="'.$type.'"'.
2358: $checked{$type}{$item}.
2359: ' value="'.$item.'" />'.$short_titles->{$item}.
2360: '</label> ';
2361: }
2362: $datatable .= '</span><br />'.&mt('Others').': '.
2363: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2364: 'value="'.$otheremails{$type}.'" />';
2365: if ($type eq 'helpdeskmail') {
1.136 raeburn 2366: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2367: '<input type="text" name="'.$type.'_bcc" '.
2368: 'value="'.$bccemails{$type}.'" />';
2369: }
2370: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2371: $rownum ++;
1.28 raeburn 2372: }
1.160.6.23 raeburn 2373: my %choices;
2374: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2375: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2376: &mt('LON-CAPA core group - MSU'),600,500));
2377: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2378: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2379: &mt('LON-CAPA core group - MSU'),600,500));
2380: my @toggles = ('reporterrors','reportupdates');
2381: my %defaultchecked = ('reporterrors' => 'on',
2382: 'reportupdates' => 'on');
2383: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2384: \%choices,$rownum);
2385: $datatable .= $reports;
1.30 raeburn 2386: $$rowtotal += $rownum;
1.28 raeburn 2387: return $datatable;
2388: }
2389:
1.118 jms 2390: sub print_helpsettings {
1.160.6.5 raeburn 2391: my ($dom,$confname,$settings,$rowtotal) = @_;
2392: my ($datatable,$itemcount);
2393: $itemcount = 1;
2394: my (%choices,%defaultchecked,@toggles);
2395: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2396: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2397: &mt('LON-CAPA bug tracker'),600,500));
2398: %defaultchecked = ('submitbugs' => 'on');
2399: @toggles = ('submitbugs',);
1.122 jms 2400:
1.160.6.5 raeburn 2401: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2402: \%choices,$itemcount);
2403: return $datatable;
1.121 raeburn 2404: }
2405:
2406: sub radiobutton_prefs {
1.160.6.16 raeburn 2407: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2408: $additional) = @_;
1.121 raeburn 2409: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2410: (ref($choices) eq 'HASH'));
2411:
2412: my (%checkedon,%checkedoff,$datatable,$css_class);
2413:
2414: foreach my $item (@{$toggles}) {
2415: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2416: $checkedon{$item} = ' checked="checked" ';
2417: $checkedoff{$item} = ' ';
1.121 raeburn 2418: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2419: $checkedoff{$item} = ' checked="checked" ';
2420: $checkedon{$item} = ' ';
2421: }
2422: }
2423: if (ref($settings) eq 'HASH') {
1.121 raeburn 2424: foreach my $item (@{$toggles}) {
1.118 jms 2425: if ($settings->{$item} eq '1') {
2426: $checkedon{$item} = ' checked="checked" ';
2427: $checkedoff{$item} = ' ';
2428: } elsif ($settings->{$item} eq '0') {
2429: $checkedoff{$item} = ' checked="checked" ';
2430: $checkedon{$item} = ' ';
2431: }
2432: }
1.121 raeburn 2433: }
1.160.6.16 raeburn 2434: if ($onclick) {
2435: $onclick = ' onclick="'.$onclick.'"';
2436: }
1.121 raeburn 2437: foreach my $item (@{$toggles}) {
1.118 jms 2438: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2439: $datatable .=
1.160.6.16 raeburn 2440: '<tr'.$css_class.'><td valign="top">'.
2441: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2442: '</span></td>'.
2443: '<td class="LC_right_item"><span class="LC_nobreak">'.
2444: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2445: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2446: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2447: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2448: '</span>'.$additional.
2449: '</td>'.
1.118 jms 2450: '</tr>';
2451: $itemcount ++;
1.121 raeburn 2452: }
2453: return ($datatable,$itemcount);
2454: }
2455:
2456: sub print_coursedefaults {
1.139 raeburn 2457: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2458: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2459: my $itemcount = 1;
1.160.6.16 raeburn 2460: my %choices = &Apache::lonlocal::texthash (
2461: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2462: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2463: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2464: coursecredits => 'Credits can be specified for courses',
2465: );
1.160.6.21 raeburn 2466: my %staticdefaults = (
2467: anonsurvey_threshold => 10,
2468: uploadquota => 500,
2469: );
1.139 raeburn 2470: if ($position eq 'top') {
2471: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2472: @toggles = ('canuse_pdfforms');
1.139 raeburn 2473: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2474: \%choices,$itemcount);
1.139 raeburn 2475: } else {
2476: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.21 raeburn 2477: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.160.6.16 raeburn 2478: my $currusecredits = 0;
1.160.6.21 raeburn 2479: my @types = ('official','unofficial','community');
1.139 raeburn 2480: if (ref($settings) eq 'HASH') {
2481: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2482: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2483: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2484: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2485: }
2486: }
1.160.6.16 raeburn 2487: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2488: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2489: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2490: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2491: $currusecredits = 1;
2492: }
2493: }
1.139 raeburn 2494: }
2495: if (!$currdefresponder) {
1.160.6.21 raeburn 2496: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2497: } elsif ($currdefresponder < 1) {
2498: $currdefresponder = 1;
2499: }
1.160.6.21 raeburn 2500: foreach my $type (@types) {
2501: if ($curruploadquota{$type} eq '') {
2502: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2503: }
2504: }
1.139 raeburn 2505: $datatable .=
1.160.6.16 raeburn 2506: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2507: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2508: '</span></td>'.
2509: '<td class="LC_right_item"><span class="LC_nobreak">'.
2510: '<input type="text" name="anonsurvey_threshold"'.
2511: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.21 raeburn 2512: '</td></tr>'."\n".
2513: '<tr><td><span class="LC_nobreak">'.
2514: $choices{'uploadquota'}.
2515: '</span></td>'.
2516: '<td align="right" class="LC_right_item">'.
2517: '<table><tr>';
2518: foreach my $type (@types) {
2519: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2520: '<input type="text" name="uploadquota_'.$type.'"'.
2521: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2522: }
2523: $datatable .= '</tr></table></td></tr>'."\n";
2524: $itemcount += 2;
1.160.6.16 raeburn 2525: my $onclick = 'toggleCredits(this.form);';
2526: my $display = 'none';
2527: if ($currusecredits) {
2528: $display = 'block';
2529: }
2530: my $additional = '<div id="credits" style="display: '.$display.'">'.
2531: '<span class="LC_nobreak">'.
2532: &mt('Default credits for official courses [_1]',
2533: '<input type="text" name="official_credits" value="'.
2534: $def_official_credits.'" size="3" />').
2535: '</span><br />'.
2536: '<span class="LC_nobreak">'.
2537: &mt('Default credits for unofficial courses [_1]',
2538: '<input type="text" name="unofficial_credits" value="'.
2539: $def_unofficial_credits.'" size="3" />').
2540: '</span></div>'."\n";
2541: %defaultchecked = ('coursecredits' => 'off');
2542: @toggles = ('coursecredits');
2543: my $current = {
2544: 'coursecredits' => $currusecredits,
2545: };
2546: (my $table,$itemcount) =
2547: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2548: \%choices,$itemcount,$onclick,$additional);
2549: $datatable .= $table;
1.139 raeburn 2550: }
1.160.6.16 raeburn 2551: $$rowtotal += $itemcount;
1.121 raeburn 2552: return $datatable;
1.118 jms 2553: }
2554:
1.137 raeburn 2555: sub print_usersessions {
2556: my ($position,$dom,$settings,$rowtotal) = @_;
2557: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2558: my (%by_ip,%by_location,@intdoms);
2559: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2560:
2561: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2562: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2563: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2564: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2565: my $itemcount = 1;
2566: if ($position eq 'top') {
1.152 raeburn 2567: if (keys(%serverhomes) > 1) {
1.145 raeburn 2568: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2569: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2570: } else {
1.140 raeburn 2571: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2572: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2573: }
1.137 raeburn 2574: } else {
1.145 raeburn 2575: if (keys(%by_location) == 0) {
2576: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2577: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2578: } else {
2579: my %lt = &usersession_titles();
2580: my $numinrow = 5;
2581: my $prefix;
2582: my @types;
2583: if ($position eq 'bottom') {
2584: $prefix = 'remote';
2585: @types = ('version','excludedomain','includedomain');
2586: } else {
2587: $prefix = 'hosted';
2588: @types = ('excludedomain','includedomain');
2589: }
2590: my (%current,%checkedon,%checkedoff);
2591: my @lcversions = &Apache::lonnet::all_loncaparevs();
2592: my @locations = sort(keys(%by_location));
2593: foreach my $type (@types) {
2594: $checkedon{$type} = '';
2595: $checkedoff{$type} = ' checked="checked"';
2596: }
2597: if (ref($settings) eq 'HASH') {
2598: if (ref($settings->{$prefix}) eq 'HASH') {
2599: foreach my $key (keys(%{$settings->{$prefix}})) {
2600: $current{$key} = $settings->{$prefix}{$key};
2601: if ($key eq 'version') {
2602: if ($current{$key} ne '') {
2603: $checkedon{$key} = ' checked="checked"';
2604: $checkedoff{$key} = '';
2605: }
2606: } elsif (ref($current{$key}) eq 'ARRAY') {
2607: $checkedon{$key} = ' checked="checked"';
2608: $checkedoff{$key} = '';
2609: }
1.137 raeburn 2610: }
2611: }
2612: }
1.145 raeburn 2613: foreach my $type (@types) {
2614: next if ($type ne 'version' && !@locations);
2615: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2616: $datatable .= '<tr'.$css_class.'>
2617: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2618: <span class="LC_nobreak">
2619: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2620: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2621: if ($type eq 'version') {
2622: my $selector = '<select name="'.$prefix.'_version">';
2623: foreach my $version (@lcversions) {
2624: my $selected = '';
2625: if ($current{'version'} eq $version) {
2626: $selected = ' selected="selected"';
2627: }
2628: $selector .= ' <option value="'.$version.'"'.
2629: $selected.'>'.$version.'</option>';
2630: }
2631: $selector .= '</select> ';
2632: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2633: } else {
2634: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2635: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2636: ' />'.(' 'x2).
2637: '<input type="button" value="'.&mt('uncheck all').'" '.
2638: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2639: "\n".
2640: '</div><div><table>';
2641: my $rem;
2642: for (my $i=0; $i<@locations; $i++) {
2643: my ($showloc,$value,$checkedtype);
2644: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2645: my $ip = $by_location{$locations[$i]}->[0];
2646: if (ref($by_ip{$ip}) eq 'ARRAY') {
2647: $value = join(':',@{$by_ip{$ip}});
2648: $showloc = join(', ',@{$by_ip{$ip}});
2649: if (ref($current{$type}) eq 'ARRAY') {
2650: foreach my $loc (@{$by_ip{$ip}}) {
2651: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2652: $checkedtype = ' checked="checked"';
2653: last;
2654: }
2655: }
1.138 raeburn 2656: }
2657: }
2658: }
1.145 raeburn 2659: $rem = $i%($numinrow);
2660: if ($rem == 0) {
2661: if ($i > 0) {
2662: $datatable .= '</tr>';
2663: }
2664: $datatable .= '<tr>';
2665: }
2666: $datatable .= '<td class="LC_left_item">'.
2667: '<span class="LC_nobreak"><label>'.
2668: '<input type="checkbox" name="'.$prefix.'_'.$type.
2669: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2670: '</label></span></td>';
1.137 raeburn 2671: }
1.145 raeburn 2672: $rem = @locations%($numinrow);
2673: my $colsleft = $numinrow - $rem;
2674: if ($colsleft > 1 ) {
2675: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2676: ' </td>';
2677: } elsif ($colsleft == 1) {
2678: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2679: }
1.145 raeburn 2680: $datatable .= '</tr></table>';
1.137 raeburn 2681: }
1.145 raeburn 2682: $datatable .= '</td></tr>';
2683: $itemcount ++;
1.137 raeburn 2684: }
2685: }
2686: }
2687: $$rowtotal += $itemcount;
2688: return $datatable;
2689: }
2690:
1.138 raeburn 2691: sub build_location_hashes {
2692: my ($intdoms,$by_ip,$by_location) = @_;
2693: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2694: (ref($by_location) eq 'HASH'));
2695: my %iphost = &Apache::lonnet::get_iphost();
2696: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2697: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2698: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2699: foreach my $id (@{$iphost{$primary_ip}}) {
2700: my $intdom = &Apache::lonnet::internet_dom($id);
2701: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2702: push(@{$intdoms},$intdom);
2703: }
2704: }
2705: }
2706: foreach my $ip (keys(%iphost)) {
2707: if (ref($iphost{$ip}) eq 'ARRAY') {
2708: foreach my $id (@{$iphost{$ip}}) {
2709: my $location = &Apache::lonnet::internet_dom($id);
2710: if ($location) {
2711: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2712: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2713: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2714: push(@{$by_ip->{$ip}},$location);
2715: }
2716: } else {
2717: $by_ip->{$ip} = [$location];
2718: }
2719: }
2720: }
2721: }
2722: }
2723: foreach my $ip (sort(keys(%{$by_ip}))) {
2724: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2725: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2726: my $first = $by_ip->{$ip}->[0];
2727: if (ref($by_location->{$first}) eq 'ARRAY') {
2728: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2729: push(@{$by_location->{$first}},$ip);
2730: }
2731: } else {
2732: $by_location->{$first} = [$ip];
2733: }
2734: }
2735: }
2736: return;
2737: }
2738:
1.145 raeburn 2739: sub current_offloads_to {
2740: my ($dom,$settings,$servers) = @_;
2741: my (%spareid,%otherdomconfigs);
1.152 raeburn 2742: if (ref($servers) eq 'HASH') {
1.145 raeburn 2743: foreach my $lonhost (sort(keys(%{$servers}))) {
2744: my $gotspares;
1.152 raeburn 2745: if (ref($settings) eq 'HASH') {
2746: if (ref($settings->{'spares'}) eq 'HASH') {
2747: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2748: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2749: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2750: $gotspares = 1;
2751: }
1.145 raeburn 2752: }
2753: }
2754: unless ($gotspares) {
2755: my $gotspares;
2756: my $serverhomeID =
2757: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2758: my $serverhomedom =
2759: &Apache::lonnet::host_domain($serverhomeID);
2760: if ($serverhomedom ne $dom) {
2761: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2762: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2763: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2764: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2765: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2766: $gotspares = 1;
2767: }
2768: }
2769: } else {
2770: $otherdomconfigs{$serverhomedom} =
2771: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2772: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2773: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2774: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2775: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2776: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2777: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2778: $gotspares = 1;
2779: }
2780: }
2781: }
2782: }
2783: }
2784: }
2785: }
2786: unless ($gotspares) {
2787: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2788: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2789: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2790: } else {
2791: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2792: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2793: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2794: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2795: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2796: } else {
1.150 raeburn 2797: my %what = (
2798: spareid => 1,
2799: );
2800: my ($result,$returnhash) =
2801: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2802: if ($result eq 'ok') {
2803: if (ref($returnhash) eq 'HASH') {
2804: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2805: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2806: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2807: }
2808: }
1.145 raeburn 2809: }
2810: }
2811: }
2812: }
2813: }
2814: }
2815: return %spareid;
2816: }
2817:
2818: sub spares_row {
1.152 raeburn 2819: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2820: my $css_class;
2821: my $numinrow = 4;
2822: my $itemcount = 1;
2823: my $datatable;
1.152 raeburn 2824: my %typetitles = &sparestype_titles();
2825: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2826: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2827: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2828: my ($othercontrol,$serverdom);
2829: if ($serverhome ne $server) {
2830: $serverdom = &Apache::lonnet::host_domain($serverhome);
2831: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2832: } else {
2833: $serverdom = &Apache::lonnet::host_domain($server);
2834: if ($serverdom ne $dom) {
2835: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2836: }
2837: }
2838: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2839: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2840: $datatable .= '<tr'.$css_class.'>
2841: <td rowspan="2">
1.160.6.13 raeburn 2842: <span class="LC_nobreak">'.
2843: &mt('[_1] when busy, offloads to:'
2844: ,'<b>'.$server.'</b>').
2845: "\n";
1.145 raeburn 2846: my (%current,%canselect);
1.152 raeburn 2847: my @choices =
2848: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2849: foreach my $type ('primary','default') {
2850: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2851: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2852: my @spares = @{$spareid->{$server}{$type}};
2853: if (@spares > 0) {
1.152 raeburn 2854: if ($othercontrol) {
2855: $current{$type} = join(', ',@spares);
2856: } else {
2857: $current{$type} .= '<table>';
2858: my $numspares = scalar(@spares);
2859: for (my $i=0; $i<@spares; $i++) {
2860: my $rem = $i%($numinrow);
2861: if ($rem == 0) {
2862: if ($i > 0) {
2863: $current{$type} .= '</tr>';
2864: }
2865: $current{$type} .= '<tr>';
1.145 raeburn 2866: }
1.152 raeburn 2867: $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'".');" /> '.
2868: $spareid->{$server}{$type}[$i].
2869: '</label></td>'."\n";
2870: }
2871: my $rem = @spares%($numinrow);
2872: my $colsleft = $numinrow - $rem;
2873: if ($colsleft > 1 ) {
2874: $current{$type} .= '<td colspan="'.$colsleft.
2875: '" class="LC_left_item">'.
2876: ' </td>';
2877: } elsif ($colsleft == 1) {
2878: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2879: }
1.152 raeburn 2880: $current{$type} .= '</tr></table>';
1.150 raeburn 2881: }
1.145 raeburn 2882: }
2883: }
2884: if ($current{$type} eq '') {
2885: $current{$type} = &mt('None specified');
2886: }
1.152 raeburn 2887: if ($othercontrol) {
2888: if ($type eq 'primary') {
2889: $canselect{$type} = $othercontrol;
2890: }
2891: } else {
2892: $canselect{$type} =
2893: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2894: '<select name="newspare_'.$type.'_'.$server.'" '.
2895: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2896: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2897: if (@choices > 0) {
2898: foreach my $lonhost (@choices) {
2899: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2900: }
2901: }
2902: $canselect{$type} .= '</select>'."\n";
2903: }
2904: } else {
2905: $current{$type} = &mt('Could not be determined');
2906: if ($type eq 'primary') {
2907: $canselect{$type} = $othercontrol;
2908: }
1.145 raeburn 2909: }
1.152 raeburn 2910: if ($type eq 'default') {
2911: $datatable .= '<tr'.$css_class.'>';
2912: }
2913: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2914: '<td>'.$current{$type}.'</td>'."\n".
2915: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2916: }
2917: $itemcount ++;
2918: }
2919: }
2920: $$rowtotal += $itemcount;
2921: return $datatable;
2922: }
2923:
1.152 raeburn 2924: sub possible_newspares {
2925: my ($server,$currspares,$serverhomes,$altids) = @_;
2926: my $serverhostname = &Apache::lonnet::hostname($server);
2927: my %excluded;
2928: if ($serverhostname ne '') {
2929: %excluded = (
2930: $serverhostname => 1,
2931: );
2932: }
2933: if (ref($currspares) eq 'HASH') {
2934: foreach my $type (keys(%{$currspares})) {
2935: if (ref($currspares->{$type}) eq 'ARRAY') {
2936: if (@{$currspares->{$type}} > 0) {
2937: foreach my $curr (@{$currspares->{$type}}) {
2938: my $hostname = &Apache::lonnet::hostname($curr);
2939: $excluded{$hostname} = 1;
2940: }
2941: }
2942: }
2943: }
2944: }
2945: my @choices;
2946: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2947: if (keys(%{$serverhomes}) > 1) {
2948: foreach my $name (sort(keys(%{$serverhomes}))) {
2949: unless ($excluded{$name}) {
2950: if (exists($altids->{$serverhomes->{$name}})) {
2951: push(@choices,$altids->{$serverhomes->{$name}});
2952: } else {
2953: push(@choices,$serverhomes->{$name});
1.145 raeburn 2954: }
2955: }
2956: }
2957: }
2958: }
1.152 raeburn 2959: return sort(@choices);
1.145 raeburn 2960: }
2961:
1.150 raeburn 2962: sub print_loadbalancing {
2963: my ($dom,$settings,$rowtotal) = @_;
2964: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2965: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2966: my $numinrow = 1;
2967: my $datatable;
2968: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2969: my (%currbalancer,%currtargets,%currrules,%existing);
2970: if (ref($settings) eq 'HASH') {
2971: %existing = %{$settings};
2972: }
2973: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2974: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2975: \%currtargets,\%currrules);
1.150 raeburn 2976: } else {
2977: return;
2978: }
2979: my ($othertitle,$usertypes,$types) =
2980: &Apache::loncommon::sorted_inst_types($dom);
2981: my $rownum = 6;
2982: if (ref($types) eq 'ARRAY') {
2983: $rownum += scalar(@{$types});
2984: }
1.160.6.7 raeburn 2985: my @css_class = ('LC_odd_row','LC_even_row');
2986: my $balnum = 0;
2987: my $islast;
2988: my (@toshow,$disabledtext);
2989: if (keys(%currbalancer) > 0) {
2990: @toshow = sort(keys(%currbalancer));
2991: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2992: push(@toshow,'');
2993: }
2994: } else {
2995: @toshow = ('');
2996: $disabledtext = &mt('No existing load balancer');
2997: }
2998: foreach my $lonhost (@toshow) {
2999: if ($balnum == scalar(@toshow)-1) {
3000: $islast = 1;
3001: } else {
3002: $islast = 0;
3003: }
3004: my $cssidx = $balnum%2;
3005: my $targets_div_style = 'display: none';
3006: my $disabled_div_style = 'display: block';
3007: my $homedom_div_style = 'display: none';
3008: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3009: '<td rowspan="'.$rownum.'" valign="top">'.
3010: '<p>';
3011: if ($lonhost eq '') {
3012: $datatable .= '<span class="LC_nobreak">';
3013: if (keys(%currbalancer) > 0) {
3014: $datatable .= &mt('Add balancer:');
3015: } else {
3016: $datatable .= &mt('Enable balancer:');
3017: }
3018: $datatable .= ' '.
3019: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3020: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3021: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3022: '<option value="" selected="selected">'.&mt('None').
3023: '</option>'."\n";
3024: foreach my $server (sort(keys(%servers))) {
3025: next if ($currbalancer{$server});
3026: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3027: }
3028: $datatable .=
3029: '</select>'."\n".
3030: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3031: } else {
3032: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3033: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3034: &mt('Stop balancing').'</label>'.
3035: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3036: $targets_div_style = 'display: block';
3037: $disabled_div_style = 'display: none';
3038: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3039: $homedom_div_style = 'display: block';
3040: }
3041: }
3042: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3043: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3044: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3045: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3046: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3047: my @sparestypes = ('primary','default');
3048: my %typetitles = &sparestype_titles();
3049: foreach my $sparetype (@sparestypes) {
3050: my $targettable;
3051: for (my $i=0; $i<$numspares; $i++) {
3052: my $checked;
3053: if (ref($currtargets{$lonhost}) eq 'HASH') {
3054: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3055: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3056: $checked = ' checked="checked"';
3057: }
3058: }
3059: }
3060: my ($chkboxval,$disabled);
3061: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3062: $chkboxval = $spares[$i];
3063: }
3064: if (exists($currbalancer{$spares[$i]})) {
3065: $disabled = ' disabled="disabled"';
3066: }
3067: $targettable .=
3068: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3069: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3070: '</span></label></td>';
3071: my $rem = $i%($numinrow);
3072: if ($rem == 0) {
3073: if (($i > 0) && ($i < $numspares-1)) {
3074: $targettable .= '</tr>';
3075: }
3076: if ($i < $numspares-1) {
3077: $targettable .= '<tr>';
1.150 raeburn 3078: }
3079: }
3080: }
1.160.6.7 raeburn 3081: if ($targettable ne '') {
3082: my $rem = $numspares%($numinrow);
3083: my $colsleft = $numinrow - $rem;
3084: if ($colsleft > 1 ) {
3085: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3086: ' </td>';
3087: } elsif ($colsleft == 1) {
3088: $targettable .= '<td class="LC_left_item"> </td>';
3089: }
3090: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3091: '<table><tr>'.$targettable.'</tr></table><br />';
3092: }
3093: }
3094: $datatable .= '</div></td></tr>'.
3095: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3096: $othertitle,$usertypes,$types,\%servers,
3097: \%currbalancer,$lonhost,
3098: $targets_div_style,$homedom_div_style,
3099: $css_class[$cssidx],$balnum,$islast);
3100: $$rowtotal += $rownum;
3101: $balnum ++;
3102: }
3103: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3104: return $datatable;
3105: }
3106:
3107: sub get_loadbalancers_config {
3108: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3109: return unless ((ref($servers) eq 'HASH') &&
3110: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3111: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3112: if (keys(%{$existing}) > 0) {
3113: my $oldlonhost;
3114: foreach my $key (sort(keys(%{$existing}))) {
3115: if ($key eq 'lonhost') {
3116: $oldlonhost = $existing->{'lonhost'};
3117: $currbalancer->{$oldlonhost} = 1;
3118: } elsif ($key eq 'targets') {
3119: if ($oldlonhost) {
3120: $currtargets->{$oldlonhost} = $existing->{'targets'};
3121: }
3122: } elsif ($key eq 'rules') {
3123: if ($oldlonhost) {
3124: $currrules->{$oldlonhost} = $existing->{'rules'};
3125: }
3126: } elsif (ref($existing->{$key}) eq 'HASH') {
3127: $currbalancer->{$key} = 1;
3128: $currtargets->{$key} = $existing->{$key}{'targets'};
3129: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3130: }
3131: }
1.160.6.7 raeburn 3132: } else {
3133: my ($balancerref,$targetsref) =
3134: &Apache::lonnet::get_lonbalancer_config($servers);
3135: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3136: foreach my $server (sort(keys(%{$balancerref}))) {
3137: $currbalancer->{$server} = 1;
3138: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3139: }
3140: }
3141: }
1.160.6.7 raeburn 3142: return;
1.150 raeburn 3143: }
3144:
3145: sub loadbalancing_rules {
3146: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3147: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3148: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3149: my $output;
1.160.6.7 raeburn 3150: my $num = 0;
3151: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3152: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3153: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3154: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3155: $num ++;
1.150 raeburn 3156: my $current;
3157: if (ref($currrules) eq 'HASH') {
3158: $current = $currrules->{$type};
3159: }
3160: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3161: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3162: $current = '';
3163: }
3164: }
3165: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3166: $servers,$currbalancer,$lonhost,$dom,
3167: $targets_div_style,$homedom_div_style,
3168: $css_class,$balnum,$num,$islast);
1.150 raeburn 3169: }
3170: }
3171: return $output;
3172: }
3173:
3174: sub loadbalancing_titles {
3175: my ($dom,$intdom,$usertypes,$types) = @_;
3176: my %othertypes = (
3177: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3178: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3179: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3180: '_LC_external' => &mt('Users not from [_1]',$intdom),
3181: );
3182: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3183: if (ref($types) eq 'ARRAY') {
3184: unshift(@alltypes,@{$types},'default');
3185: }
3186: my %titles;
3187: foreach my $type (@alltypes) {
3188: if ($type =~ /^_LC_/) {
3189: $titles{$type} = $othertypes{$type};
3190: } elsif ($type eq 'default') {
3191: $titles{$type} = &mt('All users from [_1]',$dom);
3192: if (ref($types) eq 'ARRAY') {
3193: if (@{$types} > 0) {
3194: $titles{$type} = &mt('Other users from [_1]',$dom);
3195: }
3196: }
3197: } elsif (ref($usertypes) eq 'HASH') {
3198: $titles{$type} = $usertypes->{$type};
3199: }
3200: }
3201: return (\@alltypes,\%othertypes,\%titles);
3202: }
3203:
3204: sub loadbalance_rule_row {
1.160.6.7 raeburn 3205: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3206: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3207: my @rulenames = ('default','homeserver');
3208: my %ruletitles = &offloadtype_text();
3209: if ($type eq '_LC_external') {
3210: push(@rulenames,'externalbalancer');
3211: } else {
3212: push(@rulenames,'specific');
3213: }
1.160.6.3 raeburn 3214: push(@rulenames,'none');
1.150 raeburn 3215: my $style = $targets_div_style;
3216: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3217: $style = $homedom_div_style;
3218: }
1.160.6.7 raeburn 3219: my $space;
3220: if ($islast && $num == 1) {
3221: $space = '<div display="inline-block"> </div>';
3222: }
3223: my $output =
3224: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3225: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3226: '<td valaign="top">'.$space.
3227: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3228: for (my $i=0; $i<@rulenames; $i++) {
3229: my $rule = $rulenames[$i];
3230: my ($checked,$extra);
3231: if ($rulenames[$i] eq 'default') {
3232: $rule = '';
3233: }
3234: if ($rulenames[$i] eq 'specific') {
3235: if (ref($servers) eq 'HASH') {
3236: my $default;
3237: if (($current ne '') && (exists($servers->{$current}))) {
3238: $checked = ' checked="checked"';
3239: }
3240: unless ($checked) {
3241: $default = ' selected="selected"';
3242: }
1.160.6.7 raeburn 3243: $extra =
3244: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3245: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3246: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3247: '<option value=""'.$default.'></option>'."\n";
3248: foreach my $server (sort(keys(%{$servers}))) {
3249: if (ref($currbalancer) eq 'HASH') {
3250: next if (exists($currbalancer->{$server}));
3251: }
1.150 raeburn 3252: my $selected;
1.160.6.7 raeburn 3253: if ($server eq $current) {
1.150 raeburn 3254: $selected = ' selected="selected"';
3255: }
1.160.6.7 raeburn 3256: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3257: }
3258: $extra .= '</select>';
3259: }
3260: } elsif ($rule eq $current) {
3261: $checked = ' checked="checked"';
3262: }
3263: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3264: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3265: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3266: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3267: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3268: '</label>'.$extra.'</span><br />'."\n";
3269: }
3270: $output .= '</div></td></tr>'."\n";
3271: return $output;
3272: }
3273:
3274: sub offloadtype_text {
3275: my %ruletitles = &Apache::lonlocal::texthash (
3276: 'default' => 'Offloads to default destinations',
3277: 'homeserver' => "Offloads to user's home server",
3278: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3279: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3280: 'none' => 'No offload',
1.150 raeburn 3281: );
3282: return %ruletitles;
3283: }
3284:
3285: sub sparestype_titles {
3286: my %typestitles = &Apache::lonlocal::texthash (
3287: 'primary' => 'primary',
3288: 'default' => 'default',
3289: );
3290: return %typestitles;
3291: }
3292:
1.28 raeburn 3293: sub contact_titles {
3294: my %titles = &Apache::lonlocal::texthash (
3295: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3296: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3297: 'errormail' => 'Error reports to be e-mailed to',
3298: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3299: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3300: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3301: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3302: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3303: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3304: );
3305: my %short_titles = &Apache::lonlocal::texthash (
3306: adminemail => 'Admin E-mail address',
3307: supportemail => 'Support E-mail',
3308: );
3309: return (\%titles,\%short_titles);
3310: }
3311:
1.72 raeburn 3312: sub tool_titles {
3313: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3314: aboutme => 'Personal web page',
1.86 raeburn 3315: blog => 'Blog',
1.160.6.4 raeburn 3316: webdav => 'WebDAV',
1.86 raeburn 3317: portfolio => 'Portfolio',
1.88 bisitz 3318: official => 'Official courses (with institutional codes)',
3319: unofficial => 'Unofficial courses',
1.98 raeburn 3320: community => 'Communities',
1.86 raeburn 3321: );
1.72 raeburn 3322: return %titles;
3323: }
3324:
1.101 raeburn 3325: sub courserequest_titles {
3326: my %titles = &Apache::lonlocal::texthash (
3327: official => 'Official',
3328: unofficial => 'Unofficial',
3329: community => 'Communities',
3330: norequest => 'Not allowed',
1.104 raeburn 3331: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3332: validate => 'With validation',
3333: autolimit => 'Numerical limit',
1.103 raeburn 3334: unlimited => '(blank for unlimited)',
1.101 raeburn 3335: );
3336: return %titles;
3337: }
3338:
1.160.6.5 raeburn 3339: sub authorrequest_titles {
3340: my %titles = &Apache::lonlocal::texthash (
3341: norequest => 'Not allowed',
3342: approval => 'Approval by Dom. Coord.',
3343: automatic => 'Automatic approval',
3344: );
3345: return %titles;
3346: }
3347:
1.101 raeburn 3348: sub courserequest_conditions {
3349: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3350: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3351: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3352: );
3353: return %conditions;
3354: }
3355:
3356:
1.27 raeburn 3357: sub print_usercreation {
1.30 raeburn 3358: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3359: my $numinrow = 4;
1.28 raeburn 3360: my $datatable;
3361: if ($position eq 'top') {
1.30 raeburn 3362: $$rowtotal ++;
1.34 raeburn 3363: my $rowcount = 0;
1.32 raeburn 3364: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3365: if (ref($rules) eq 'HASH') {
3366: if (keys(%{$rules}) > 0) {
1.32 raeburn 3367: $datatable .= &user_formats_row('username',$settings,$rules,
3368: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3369: $$rowtotal ++;
1.32 raeburn 3370: $rowcount ++;
3371: }
3372: }
3373: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3374: if (ref($idrules) eq 'HASH') {
3375: if (keys(%{$idrules}) > 0) {
3376: $datatable .= &user_formats_row('id',$settings,$idrules,
3377: $idruleorder,$numinrow,$rowcount);
3378: $$rowtotal ++;
3379: $rowcount ++;
1.28 raeburn 3380: }
3381: }
1.43 raeburn 3382: my ($emailrules,$emailruleorder) =
3383: &Apache::lonnet::inst_userrules($dom,'email');
3384: if (ref($emailrules) eq 'HASH') {
3385: if (keys(%{$emailrules}) > 0) {
3386: $datatable .= &user_formats_row('email',$settings,$emailrules,
3387: $emailruleorder,$numinrow,$rowcount);
3388: $$rowtotal ++;
3389: $rowcount ++;
3390: }
3391: }
1.39 raeburn 3392: if ($rowcount == 0) {
3393: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3394: $$rowtotal ++;
3395: $rowcount ++;
3396: }
1.34 raeburn 3397: } elsif ($position eq 'middle') {
1.100 raeburn 3398: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3399: my ($rules,$ruleorder) =
3400: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3401: my %lt = &usercreation_types();
3402: my %checked;
1.50 raeburn 3403: my @selfcreate;
1.34 raeburn 3404: if (ref($settings) eq 'HASH') {
3405: if (ref($settings->{'cancreate'}) eq 'HASH') {
3406: foreach my $item (@creators) {
3407: $checked{$item} = $settings->{'cancreate'}{$item};
3408: }
1.50 raeburn 3409: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3410: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3411: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3412: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3413: @selfcreate = ('email','login','sso');
3414: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3415: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3416: }
3417: }
1.34 raeburn 3418: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3419: foreach my $item (@creators) {
3420: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3421: $checked{$item} = 'none';
3422: }
3423: }
3424: }
3425: }
3426: my $rownum = 0;
3427: foreach my $item (@creators) {
3428: $rownum ++;
1.50 raeburn 3429: if ($item ne 'selfcreate') {
3430: if ($checked{$item} eq '') {
1.43 raeburn 3431: $checked{$item} = 'any';
3432: }
1.34 raeburn 3433: }
3434: my $css_class;
3435: if ($rownum%2) {
3436: $css_class = '';
3437: } else {
3438: $css_class = ' class="LC_odd_row" ';
3439: }
3440: $datatable .= '<tr'.$css_class.'>'.
3441: '<td><span class="LC_nobreak">'.$lt{$item}.
3442: '</span></td><td align="right">';
1.50 raeburn 3443: my @options;
1.45 raeburn 3444: if ($item eq 'selfcreate') {
1.43 raeburn 3445: push(@options,('email','login','sso'));
3446: } else {
1.50 raeburn 3447: @options = ('any');
1.43 raeburn 3448: if (ref($rules) eq 'HASH') {
3449: if (keys(%{$rules}) > 0) {
3450: push(@options,('official','unofficial'));
3451: }
1.37 raeburn 3452: }
1.50 raeburn 3453: push(@options,'none');
1.37 raeburn 3454: }
3455: foreach my $option (@options) {
1.50 raeburn 3456: my $type = 'radio';
1.34 raeburn 3457: my $check = ' ';
1.50 raeburn 3458: if ($item eq 'selfcreate') {
3459: $type = 'checkbox';
3460: if (grep(/^\Q$option\E$/,@selfcreate)) {
3461: $check = ' checked="checked" ';
3462: }
3463: } else {
3464: if ($checked{$item} eq $option) {
3465: $check = ' checked="checked" ';
3466: }
1.34 raeburn 3467: }
3468: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3469: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3470: $item.'" value="'.$option.'"'.$check.'/> '.
3471: $lt{$option}.'</label> </span>';
3472: }
3473: $datatable .= '</td></tr>';
3474: }
1.93 raeburn 3475: my ($othertitle,$usertypes,$types) =
3476: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3477: my $createsettings;
3478: if (ref($settings) eq 'HASH') {
3479: $createsettings = $settings->{cancreate};
3480: }
1.93 raeburn 3481: if (ref($usertypes) eq 'HASH') {
3482: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3483: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3484: $dom,$numinrow,$othertitle,
3485: 'statustocreate');
3486: $$rowtotal ++;
1.160.6.5 raeburn 3487: $rownum ++;
1.93 raeburn 3488: }
3489: }
1.160.6.5 raeburn 3490: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3491: } else {
3492: my @contexts = ('author','course','domain');
3493: my @authtypes = ('int','krb4','krb5','loc');
3494: my %checked;
3495: if (ref($settings) eq 'HASH') {
3496: if (ref($settings->{'authtypes'}) eq 'HASH') {
3497: foreach my $item (@contexts) {
3498: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3499: foreach my $auth (@authtypes) {
3500: if ($settings->{'authtypes'}{$item}{$auth}) {
3501: $checked{$item}{$auth} = ' checked="checked" ';
3502: }
3503: }
3504: }
3505: }
1.27 raeburn 3506: }
1.35 raeburn 3507: } else {
3508: foreach my $item (@contexts) {
1.36 raeburn 3509: foreach my $auth (@authtypes) {
1.35 raeburn 3510: $checked{$item}{$auth} = ' checked="checked" ';
3511: }
3512: }
1.27 raeburn 3513: }
1.28 raeburn 3514: my %title = &context_names();
3515: my %authname = &authtype_names();
3516: my $rownum = 0;
3517: my $css_class;
3518: foreach my $item (@contexts) {
3519: if ($rownum%2) {
3520: $css_class = '';
3521: } else {
3522: $css_class = ' class="LC_odd_row" ';
3523: }
1.30 raeburn 3524: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3525: '<td>'.$title{$item}.
3526: '</td><td class="LC_left_item">'.
3527: '<span class="LC_nobreak">';
3528: foreach my $auth (@authtypes) {
3529: $datatable .= '<label>'.
3530: '<input type="checkbox" name="'.$item.'_auth" '.
3531: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3532: $authname{$auth}.'</label> ';
3533: }
3534: $datatable .= '</span></td></tr>';
3535: $rownum ++;
1.27 raeburn 3536: }
1.30 raeburn 3537: $$rowtotal += $rownum;
1.27 raeburn 3538: }
3539: return $datatable;
3540: }
3541:
1.160.6.5 raeburn 3542: sub captcha_choice {
3543: my ($context,$settings,$itemcount) = @_;
3544: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3545: my %lt = &captcha_phrases();
3546: $keyentry = 'hidden';
3547: if ($context eq 'cancreate') {
3548: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3549: } elsif ($context eq 'login') {
3550: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3551: }
3552: if (ref($settings) eq 'HASH') {
3553: if ($settings->{'captcha'}) {
3554: $checked{$settings->{'captcha'}} = ' checked="checked"';
3555: } else {
3556: $checked{'original'} = ' checked="checked"';
3557: }
3558: if ($settings->{'captcha'} eq 'recaptcha') {
3559: $pubtext = $lt{'pub'};
3560: $privtext = $lt{'priv'};
3561: $keyentry = 'text';
3562: }
3563: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3564: $currpub = $settings->{'recaptchakeys'}{'public'};
3565: $currpriv = $settings->{'recaptchakeys'}{'private'};
3566: }
3567: } else {
3568: $checked{'original'} = ' checked="checked"';
3569: }
3570: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3571: my $output = '<tr'.$css_class.'>'.
3572: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3573: '<table><tr><td>'."\n";
3574: foreach my $option ('original','recaptcha','notused') {
3575: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3576: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3577: $lt{$option}.'</label></span>';
3578: unless ($option eq 'notused') {
3579: $output .= (' 'x2)."\n";
3580: }
3581: }
3582: #
3583: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3584: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3585: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3586: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3587: #
3588: $output .= '</td></tr>'."\n".
3589: '<tr><td>'."\n".
3590: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3591: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3592: $currpub.'" size="40" /></span><br />'."\n".
3593: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3594: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3595: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3596: '</td></tr>';
3597: return $output;
3598: }
3599:
1.32 raeburn 3600: sub user_formats_row {
3601: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3602: my $output;
3603: my %text = (
3604: 'username' => 'new usernames',
3605: 'id' => 'IDs',
1.45 raeburn 3606: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3607: );
3608: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3609: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3610: '<td><span class="LC_nobreak">';
3611: if ($type eq 'email') {
3612: $output .= &mt("Formats disallowed for $text{$type}: ");
3613: } else {
3614: $output .= &mt("Format rules to check for $text{$type}: ");
3615: }
3616: $output .= '</span></td>'.
3617: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3618: my $rem;
3619: if (ref($ruleorder) eq 'ARRAY') {
3620: for (my $i=0; $i<@{$ruleorder}; $i++) {
3621: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3622: my $rem = $i%($numinrow);
3623: if ($rem == 0) {
3624: if ($i > 0) {
3625: $output .= '</tr>';
3626: }
3627: $output .= '<tr>';
3628: }
3629: my $check = ' ';
1.39 raeburn 3630: if (ref($settings) eq 'HASH') {
3631: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3632: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3633: $check = ' checked="checked" ';
3634: }
1.27 raeburn 3635: }
3636: }
3637: $output .= '<td class="LC_left_item">'.
3638: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3639: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3640: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3641: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3642: }
3643: }
3644: $rem = @{$ruleorder}%($numinrow);
3645: }
3646: my $colsleft = $numinrow - $rem;
3647: if ($colsleft > 1 ) {
3648: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3649: ' </td>';
3650: } elsif ($colsleft == 1) {
3651: $output .= '<td class="LC_left_item"> </td>';
3652: }
3653: $output .= '</tr></table></td></tr>';
3654: return $output;
3655: }
3656:
1.34 raeburn 3657: sub usercreation_types {
3658: my %lt = &Apache::lonlocal::texthash (
3659: author => 'When adding a co-author',
3660: course => 'When adding a user to a course',
1.100 raeburn 3661: requestcrs => 'When requesting a course',
1.45 raeburn 3662: selfcreate => 'User creates own account',
1.34 raeburn 3663: any => 'Any',
3664: official => 'Institutional only ',
3665: unofficial => 'Non-institutional only',
1.85 schafran 3666: email => 'E-mail address',
1.43 raeburn 3667: login => 'Institutional Login',
3668: sso => 'SSO',
1.34 raeburn 3669: none => 'None',
3670: );
3671: return %lt;
1.48 raeburn 3672: }
1.34 raeburn 3673:
1.28 raeburn 3674: sub authtype_names {
3675: my %lt = &Apache::lonlocal::texthash(
3676: int => 'Internal',
3677: krb4 => 'Kerberos 4',
3678: krb5 => 'Kerberos 5',
3679: loc => 'Local',
3680: );
3681: return %lt;
3682: }
3683:
3684: sub context_names {
3685: my %context_title = &Apache::lonlocal::texthash(
3686: author => 'Creating users when an Author',
3687: course => 'Creating users when in a course',
3688: domain => 'Creating users when a Domain Coordinator',
3689: );
3690: return %context_title;
3691: }
3692:
1.33 raeburn 3693: sub print_usermodification {
3694: my ($position,$dom,$settings,$rowtotal) = @_;
3695: my $numinrow = 4;
3696: my ($context,$datatable,$rowcount);
3697: if ($position eq 'top') {
3698: $rowcount = 0;
3699: $context = 'author';
3700: foreach my $role ('ca','aa') {
3701: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3702: $numinrow,$rowcount);
3703: $$rowtotal ++;
3704: $rowcount ++;
3705: }
1.63 raeburn 3706: } elsif ($position eq 'middle') {
1.33 raeburn 3707: $context = 'course';
3708: $rowcount = 0;
3709: foreach my $role ('st','ep','ta','in','cr') {
3710: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3711: $numinrow,$rowcount);
3712: $$rowtotal ++;
3713: $rowcount ++;
3714: }
1.63 raeburn 3715: } elsif ($position eq 'bottom') {
3716: $context = 'selfcreate';
3717: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3718: $usertypes->{'default'} = $othertitle;
3719: if (ref($types) eq 'ARRAY') {
3720: push(@{$types},'default');
3721: $usertypes->{'default'} = $othertitle;
3722: foreach my $status (@{$types}) {
3723: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3724: $numinrow,$rowcount,$usertypes);
3725: $$rowtotal ++;
3726: $rowcount ++;
3727: }
3728: }
1.33 raeburn 3729: }
3730: return $datatable;
3731: }
3732:
1.43 raeburn 3733: sub print_defaults {
3734: my ($dom,$rowtotal) = @_;
1.68 raeburn 3735: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3736: 'datelocale_def','portal_def');
1.43 raeburn 3737: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3738: my $titles = &defaults_titles($dom);
1.43 raeburn 3739: my $rownum = 0;
3740: my ($datatable,$css_class);
3741: foreach my $item (@items) {
3742: if ($rownum%2) {
3743: $css_class = '';
3744: } else {
3745: $css_class = ' class="LC_odd_row" ';
3746: }
3747: $datatable .= '<tr'.$css_class.'>'.
3748: '<td><span class="LC_nobreak">'.$titles->{$item}.
3749: '</span></td><td class="LC_right_item">';
3750: if ($item eq 'auth_def') {
3751: my @authtypes = ('internal','krb4','krb5','localauth');
3752: my %shortauth = (
3753: internal => 'int',
3754: krb4 => 'krb4',
3755: krb5 => 'krb5',
3756: localauth => 'loc'
3757: );
3758: my %authnames = &authtype_names();
3759: foreach my $auth (@authtypes) {
3760: my $checked = ' ';
3761: if ($domdefaults{$item} eq $auth) {
3762: $checked = ' checked="checked" ';
3763: }
3764: $datatable .= '<label><input type="radio" name="'.$item.
3765: '" value="'.$auth.'"'.$checked.'/>'.
3766: $authnames{$shortauth{$auth}}.'</label> ';
3767: }
1.54 raeburn 3768: } elsif ($item eq 'timezone_def') {
3769: my $includeempty = 1;
3770: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3771: } elsif ($item eq 'datelocale_def') {
3772: my $includeempty = 1;
3773: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3774: } elsif ($item eq 'lang_def') {
3775: my %langchoices = &get_languages_hash();
3776: $langchoices{''} = 'No language preference';
3777: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3778: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3779: \%langchoices);
1.43 raeburn 3780: } else {
1.141 raeburn 3781: my $size;
3782: if ($item eq 'portal_def') {
3783: $size = ' size="25"';
3784: }
1.43 raeburn 3785: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3786: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3787: }
3788: $datatable .= '</td></tr>';
3789: $rownum ++;
3790: }
3791: $$rowtotal += $rownum;
3792: return $datatable;
3793: }
3794:
1.160.6.5 raeburn 3795: sub get_languages_hash {
3796: my %langchoices;
3797: foreach my $id (&Apache::loncommon::languageids()) {
3798: my $code = &Apache::loncommon::supportedlanguagecode($id);
3799: if ($code ne '') {
3800: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3801: }
3802: }
3803: return %langchoices;
3804: }
3805:
1.43 raeburn 3806: sub defaults_titles {
1.141 raeburn 3807: my ($dom) = @_;
1.43 raeburn 3808: my %titles = &Apache::lonlocal::texthash (
3809: 'auth_def' => 'Default authentication type',
3810: 'auth_arg_def' => 'Default authentication argument',
3811: 'lang_def' => 'Default language',
1.54 raeburn 3812: 'timezone_def' => 'Default timezone',
1.68 raeburn 3813: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3814: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3815: );
1.141 raeburn 3816: if ($dom) {
3817: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3818: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3819: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3820: $protocol = 'http' if ($protocol ne 'https');
3821: if ($uint_dom) {
3822: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3823: $uint_dom);
3824: }
3825: }
1.43 raeburn 3826: return (\%titles);
3827: }
3828:
1.46 raeburn 3829: sub print_scantronformat {
3830: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3831: my $itemcount = 1;
1.60 raeburn 3832: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3833: %confhash);
1.46 raeburn 3834: my $switchserver = &check_switchserver($dom,$confname);
3835: my %lt = &Apache::lonlocal::texthash (
1.95 www 3836: default => 'Default bubblesheet format file error',
3837: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3838: );
3839: my %scantronfiles = (
3840: default => 'default.tab',
3841: custom => 'custom.tab',
3842: );
3843: foreach my $key (keys(%scantronfiles)) {
3844: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3845: .$scantronfiles{$key};
3846: }
3847: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3848: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3849: if (!$switchserver) {
3850: my $servadm = $r->dir_config('lonAdmEMail');
3851: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3852: if ($configuserok eq 'ok') {
3853: if ($author_ok eq 'ok') {
3854: my %legacyfile = (
3855: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3856: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3857: );
3858: my %md5chk;
3859: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3860: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3861: chomp($md5chk{$type});
1.46 raeburn 3862: }
3863: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3864: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3865: ($scantronurls{$type},my $error) =
1.46 raeburn 3866: &legacy_scantronformat($r,$dom,$confname,
3867: $type,$legacyfile{$type},
3868: $scantronurls{$type},
3869: $scantronfiles{$type});
1.60 raeburn 3870: if ($error ne '') {
3871: $error{$type} = $error;
3872: }
3873: }
3874: if (keys(%error) == 0) {
3875: $is_custom = 1;
3876: $confhash{'scantron'}{'scantronformat'} =
3877: $scantronurls{'custom'};
3878: my $putresult =
3879: &Apache::lonnet::put_dom('configuration',
3880: \%confhash,$dom);
3881: if ($putresult ne 'ok') {
3882: $error{'custom'} =
3883: '<span class="LC_error">'.
3884: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3885: }
1.46 raeburn 3886: }
3887: } else {
1.60 raeburn 3888: ($scantronurls{'default'},my $error) =
1.46 raeburn 3889: &legacy_scantronformat($r,$dom,$confname,
3890: 'default',$legacyfile{'default'},
3891: $scantronurls{'default'},
3892: $scantronfiles{'default'});
1.60 raeburn 3893: if ($error eq '') {
3894: $confhash{'scantron'}{'scantronformat'} = '';
3895: my $putresult =
3896: &Apache::lonnet::put_dom('configuration',
3897: \%confhash,$dom);
3898: if ($putresult ne 'ok') {
3899: $error{'default'} =
3900: '<span class="LC_error">'.
3901: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3902: }
3903: } else {
3904: $error{'default'} = $error;
3905: }
1.46 raeburn 3906: }
3907: }
3908: }
3909: } else {
1.95 www 3910: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3911: }
3912: }
3913: if (ref($settings) eq 'HASH') {
3914: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3915: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3916: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3917: $scantronurl = '';
3918: } else {
3919: $scantronurl = $settings->{'scantronformat'};
3920: }
3921: $is_custom = 1;
3922: } else {
3923: $scantronurl = $scantronurls{'default'};
3924: }
3925: } else {
1.60 raeburn 3926: if ($is_custom) {
3927: $scantronurl = $scantronurls{'custom'};
3928: } else {
3929: $scantronurl = $scantronurls{'default'};
3930: }
1.46 raeburn 3931: }
3932: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3933: $datatable .= '<tr'.$css_class.'>';
3934: if (!$is_custom) {
1.65 raeburn 3935: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3936: '<span class="LC_nobreak">';
1.46 raeburn 3937: if ($scantronurl) {
1.160.6.21 raeburn 3938: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
3939: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 3940: } else {
3941: $datatable = &mt('File unavailable for display');
3942: }
1.65 raeburn 3943: $datatable .= '</span></td>';
1.60 raeburn 3944: if (keys(%error) == 0) {
3945: $datatable .= '<td valign="bottom">';
3946: if (!$switchserver) {
3947: $datatable .= &mt('Upload:').'<br />';
3948: }
3949: } else {
3950: my $errorstr;
3951: foreach my $key (sort(keys(%error))) {
3952: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3953: }
3954: $datatable .= '<td>'.$errorstr;
3955: }
1.46 raeburn 3956: } else {
3957: if (keys(%error) > 0) {
3958: my $errorstr;
3959: foreach my $key (sort(keys(%error))) {
3960: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3961: }
1.60 raeburn 3962: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3963: } elsif ($scantronurl) {
1.160.6.21 raeburn 3964: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
3965: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 3966: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 3967: $link.
3968: '<label><input type="checkbox" name="scantronformat_del"'.
3969: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 3970: '<td><span class="LC_nobreak"> '.
3971: &mt('Replace:').'</span><br />';
1.46 raeburn 3972: }
3973: }
3974: if (keys(%error) == 0) {
3975: if ($switchserver) {
3976: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3977: } else {
1.65 raeburn 3978: $datatable .='<span class="LC_nobreak"> '.
3979: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3980: }
3981: }
3982: $datatable .= '</td></tr>';
3983: $$rowtotal ++;
3984: return $datatable;
3985: }
3986:
3987: sub legacy_scantronformat {
3988: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3989: my ($url,$error);
3990: my @statinfo = &Apache::lonnet::stat_file($newurl);
3991: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3992: (my $result,$url) =
3993: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3994: '','',$newfile);
3995: if ($result ne 'ok') {
1.130 raeburn 3996: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3997: }
3998: }
3999: return ($url,$error);
4000: }
1.43 raeburn 4001:
1.49 raeburn 4002: sub print_coursecategories {
1.57 raeburn 4003: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4004: my $datatable;
4005: if ($position eq 'top') {
4006: my $toggle_cats_crs = ' ';
4007: my $toggle_cats_dom = ' checked="checked" ';
4008: my $can_cat_crs = ' ';
4009: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4010: my $toggle_catscomm_comm = ' ';
4011: my $toggle_catscomm_dom = ' checked="checked" ';
4012: my $can_catcomm_comm = ' ';
4013: my $can_catcomm_dom = ' checked="checked" ';
4014:
1.57 raeburn 4015: if (ref($settings) eq 'HASH') {
4016: if ($settings->{'togglecats'} eq 'crs') {
4017: $toggle_cats_crs = $toggle_cats_dom;
4018: $toggle_cats_dom = ' ';
4019: }
4020: if ($settings->{'categorize'} eq 'crs') {
4021: $can_cat_crs = $can_cat_dom;
4022: $can_cat_dom = ' ';
4023: }
1.120 raeburn 4024: if ($settings->{'togglecatscomm'} eq 'comm') {
4025: $toggle_catscomm_comm = $toggle_catscomm_dom;
4026: $toggle_catscomm_dom = ' ';
4027: }
4028: if ($settings->{'categorizecomm'} eq 'comm') {
4029: $can_catcomm_comm = $can_catcomm_dom;
4030: $can_catcomm_dom = ' ';
4031: }
1.57 raeburn 4032: }
4033: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4034: togglecats => 'Show/Hide a course in catalog',
4035: togglecatscomm => 'Show/Hide a community in catalog',
4036: categorize => 'Assign a category to a course',
4037: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4038: );
4039: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4040: dom => 'Set in Domain',
4041: crs => 'Set in Course',
4042: comm => 'Set in Community',
1.57 raeburn 4043: );
4044: $datatable = '<tr class="LC_odd_row">'.
4045: '<td>'.$title{'togglecats'}.'</td>'.
4046: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4047: '<input type="radio" name="togglecats"'.
4048: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4049: '<label><input type="radio" name="togglecats"'.
4050: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4051: '</tr><tr>'.
4052: '<td>'.$title{'categorize'}.'</td>'.
4053: '<td class="LC_right_item"><span class="LC_nobreak">'.
4054: '<label><input type="radio" name="categorize"'.
4055: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4056: '<label><input type="radio" name="categorize"'.
4057: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4058: '</tr><tr class="LC_odd_row">'.
4059: '<td>'.$title{'togglecatscomm'}.'</td>'.
4060: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4061: '<input type="radio" name="togglecatscomm"'.
4062: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4063: '<label><input type="radio" name="togglecatscomm"'.
4064: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4065: '</tr><tr>'.
4066: '<td>'.$title{'categorizecomm'}.'</td>'.
4067: '<td class="LC_right_item"><span class="LC_nobreak">'.
4068: '<label><input type="radio" name="categorizecomm"'.
4069: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4070: '<label><input type="radio" name="categorizecomm"'.
4071: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4072: '</tr>';
1.120 raeburn 4073: $$rowtotal += 4;
1.57 raeburn 4074: } else {
4075: my $css_class;
4076: my $itemcount = 1;
4077: my $cathash;
4078: if (ref($settings) eq 'HASH') {
4079: $cathash = $settings->{'cats'};
4080: }
4081: if (ref($cathash) eq 'HASH') {
4082: my (@cats,@trails,%allitems,%idx,@jsarray);
4083: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4084: \%allitems,\%idx,\@jsarray);
4085: my $maxdepth = scalar(@cats);
4086: my $colattrib = '';
4087: if ($maxdepth > 2) {
4088: $colattrib = ' colspan="2" ';
4089: }
4090: my @path;
4091: if (@cats > 0) {
4092: if (ref($cats[0]) eq 'ARRAY') {
4093: my $numtop = @{$cats[0]};
4094: my $maxnum = $numtop;
1.120 raeburn 4095: my %default_names = (
4096: instcode => &mt('Official courses'),
4097: communities => &mt('Communities'),
4098: );
4099:
4100: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4101: ($cathash->{'instcode::0'} eq '') ||
4102: (!grep(/^communities$/,@{$cats[0]})) ||
4103: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4104: $maxnum ++;
4105: }
4106: my $lastidx;
4107: for (my $i=0; $i<$numtop; $i++) {
4108: my $parent = $cats[0][$i];
4109: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4110: my $item = &escape($parent).'::0';
4111: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4112: $lastidx = $idx{$item};
4113: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4114: .'<select name="'.$item.'"'.$chgstr.'>';
4115: for (my $k=0; $k<=$maxnum; $k++) {
4116: my $vpos = $k+1;
4117: my $selstr;
4118: if ($k == $i) {
4119: $selstr = ' selected="selected" ';
4120: }
4121: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4122: }
4123: $datatable .= '</select></td><td>';
1.120 raeburn 4124: if ($parent eq 'instcode' || $parent eq 'communities') {
4125: $datatable .= '<span class="LC_nobreak">'
4126: .$default_names{$parent}.'</span>';
4127: if ($parent eq 'instcode') {
4128: $datatable .= '<br /><span class="LC_nobreak">('
4129: .&mt('with institutional codes')
4130: .')</span></td><td'.$colattrib.'>';
4131: } else {
4132: $datatable .= '<table><tr><td>';
4133: }
4134: $datatable .= '<span class="LC_nobreak">'
4135: .'<label><input type="radio" name="'
4136: .$parent.'" value="1" checked="checked" />'
4137: .&mt('Display').'</label>';
4138: if ($parent eq 'instcode') {
4139: $datatable .= ' ';
4140: } else {
4141: $datatable .= '</span></td></tr><tr><td>'
4142: .'<span class="LC_nobreak">';
4143: }
4144: $datatable .= '<label><input type="radio" name="'
4145: .$parent.'" value="0" />'
4146: .&mt('Do not display').'</label></span>';
4147: if ($parent eq 'communities') {
4148: $datatable .= '</td></tr></table>';
4149: }
4150: $datatable .= '</td>';
1.57 raeburn 4151: } else {
4152: $datatable .= $parent
4153: .' <label><input type="checkbox" name="deletecategory" '
4154: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4155: }
4156: my $depth = 1;
4157: push(@path,$parent);
4158: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4159: pop(@path);
4160: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4161: $itemcount ++;
4162: }
1.48 raeburn 4163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4164: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4165: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4166: for (my $k=0; $k<=$maxnum; $k++) {
4167: my $vpos = $k+1;
4168: my $selstr;
1.57 raeburn 4169: if ($k == $numtop) {
1.48 raeburn 4170: $selstr = ' selected="selected" ';
4171: }
4172: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4173: }
1.59 bisitz 4174: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4175: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4176: .'</tr>'."\n";
1.48 raeburn 4177: $itemcount ++;
1.120 raeburn 4178: foreach my $default ('instcode','communities') {
4179: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4181: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4182: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4183: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4184: for (my $k=0; $k<=$maxnum; $k++) {
4185: my $vpos = $k+1;
4186: my $selstr;
4187: if ($k == $maxnum) {
4188: $selstr = ' selected="selected" ';
4189: }
4190: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4191: }
1.120 raeburn 4192: $datatable .= '</select></span></td>'.
4193: '<td><span class="LC_nobreak">'.
4194: $default_names{$default}.'</span>';
4195: if ($default eq 'instcode') {
4196: $datatable .= '<br /><span class="LC_nobreak">('
4197: .&mt('with institutional codes').')</span>';
4198: }
4199: $datatable .= '</td>'
4200: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4201: .&mt('Display').'</label> '
4202: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4203: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4204: }
4205: }
4206: }
1.57 raeburn 4207: } else {
4208: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4209: }
4210: } else {
1.57 raeburn 4211: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4212: .&initialize_categories($itemcount);
1.48 raeburn 4213: }
1.57 raeburn 4214: $$rowtotal += $itemcount;
1.48 raeburn 4215: }
4216: return $datatable;
4217: }
4218:
1.69 raeburn 4219: sub print_serverstatuses {
4220: my ($dom,$settings,$rowtotal) = @_;
4221: my $datatable;
4222: my @pages = &serverstatus_pages();
4223: my (%namedaccess,%machineaccess);
4224: foreach my $type (@pages) {
4225: $namedaccess{$type} = '';
4226: $machineaccess{$type}= '';
4227: }
4228: if (ref($settings) eq 'HASH') {
4229: foreach my $type (@pages) {
4230: if (exists($settings->{$type})) {
4231: if (ref($settings->{$type}) eq 'HASH') {
4232: foreach my $key (keys(%{$settings->{$type}})) {
4233: if ($key eq 'namedusers') {
4234: $namedaccess{$type} = $settings->{$type}->{$key};
4235: } elsif ($key eq 'machines') {
4236: $machineaccess{$type} = $settings->{$type}->{$key};
4237: }
4238: }
4239: }
4240: }
4241: }
4242: }
1.81 raeburn 4243: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4244: my $rownum = 0;
4245: my $css_class;
4246: foreach my $type (@pages) {
4247: $rownum ++;
4248: $css_class = $rownum%2?' class="LC_odd_row"':'';
4249: $datatable .= '<tr'.$css_class.'>'.
4250: '<td><span class="LC_nobreak">'.
4251: $titles->{$type}.'</span></td>'.
4252: '<td class="LC_left_item">'.
4253: '<input type="text" name="'.$type.'_namedusers" '.
4254: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4255: '<td class="LC_right_item">'.
4256: '<span class="LC_nobreak">'.
4257: '<input type="text" name="'.$type.'_machines" '.
4258: 'value="'.$machineaccess{$type}.'" size="10" />'.
4259: '</td></tr>'."\n";
4260: }
4261: $$rowtotal += $rownum;
4262: return $datatable;
4263: }
4264:
4265: sub serverstatus_pages {
4266: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4267: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4268: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4269: }
4270:
1.49 raeburn 4271: sub coursecategories_javascript {
4272: my ($settings) = @_;
1.57 raeburn 4273: my ($output,$jstext,$cathash);
1.49 raeburn 4274: if (ref($settings) eq 'HASH') {
1.57 raeburn 4275: $cathash = $settings->{'cats'};
4276: }
4277: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4278: my (@cats,@jsarray,%idx);
1.57 raeburn 4279: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4280: if (@jsarray > 0) {
4281: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4282: for (my $i=0; $i<@jsarray; $i++) {
4283: if (ref($jsarray[$i]) eq 'ARRAY') {
4284: my $catstr = join('","',@{$jsarray[$i]});
4285: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4286: }
4287: }
4288: }
4289: } else {
4290: $jstext = ' var categories = Array(1);'."\n".
4291: ' categories[0] = Array("instcode_pos");'."\n";
4292: }
1.120 raeburn 4293: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4294: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4295: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4296: $output = <<"ENDSCRIPT";
4297: <script type="text/javascript">
1.109 raeburn 4298: // <![CDATA[
1.49 raeburn 4299: function reorderCats(form,parent,item,idx) {
4300: var changedVal;
4301: $jstext
4302: var newpos = 'addcategory_pos';
4303: var current = new Array;
4304: if (parent == '') {
4305: var has_instcode = 0;
4306: var maxtop = categories[idx].length;
4307: for (var j=0; j<maxtop; j++) {
4308: if (categories[idx][j] == 'instcode::0') {
4309: has_instcode == 1;
4310: }
4311: }
4312: if (has_instcode == 0) {
4313: categories[idx][maxtop] = 'instcode_pos';
4314: }
4315: } else {
4316: newpos += '_'+parent;
4317: }
4318: var maxh = 1 + categories[idx].length;
4319: var current = new Array;
4320: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4321: if (item == newpos) {
4322: changedVal = newitemVal;
4323: } else {
4324: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4325: current[newitemVal] = newpos;
4326: }
4327: for (var i=0; i<categories[idx].length; i++) {
4328: var elementName = categories[idx][i];
4329: if (elementName != item) {
4330: if (form.elements[elementName]) {
4331: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4332: current[currVal] = elementName;
4333: }
4334: }
4335: }
4336: var oldVal;
4337: for (var j=0; j<maxh; j++) {
4338: if (current[j] == undefined) {
4339: oldVal = j;
4340: }
4341: }
4342: if (oldVal < changedVal) {
4343: for (var k=oldVal+1; k<=changedVal ; k++) {
4344: var elementName = current[k];
4345: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4346: }
4347: } else {
4348: for (var k=changedVal; k<oldVal; k++) {
4349: var elementName = current[k];
4350: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4351: }
4352: }
4353: return;
4354: }
1.120 raeburn 4355:
4356: function categoryCheck(form) {
4357: if (form.elements['addcategory_name'].value == 'instcode') {
4358: alert('$instcode_reserved\\n$choose_again');
4359: return false;
4360: }
4361: if (form.elements['addcategory_name'].value == 'communities') {
4362: alert('$communities_reserved\\n$choose_again');
4363: return false;
4364: }
4365: return true;
4366: }
4367:
1.109 raeburn 4368: // ]]>
1.49 raeburn 4369: </script>
4370:
4371: ENDSCRIPT
4372: return $output;
4373: }
4374:
1.48 raeburn 4375: sub initialize_categories {
4376: my ($itemcount) = @_;
1.120 raeburn 4377: my ($datatable,$css_class,$chgstr);
4378: my %default_names = (
4379: instcode => 'Official courses (with institutional codes)',
4380: communities => 'Communities',
4381: );
4382: my $select0 = ' selected="selected"';
4383: my $select1 = '';
4384: foreach my $default ('instcode','communities') {
4385: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4386: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4387: if ($default eq 'communities') {
4388: $select1 = $select0;
4389: $select0 = '';
4390: }
4391: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4392: .'<select name="'.$default.'_pos">'
4393: .'<option value="0"'.$select0.'>1</option>'
4394: .'<option value="1"'.$select1.'>2</option>'
4395: .'<option value="2">3</option></select> '
4396: .$default_names{$default}
4397: .'</span></td><td><span class="LC_nobreak">'
4398: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4399: .&mt('Display').'</label> <label>'
4400: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4401: .'</label></span></td></tr>';
1.120 raeburn 4402: $itemcount ++;
4403: }
1.48 raeburn 4404: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4405: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4406: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4407: .'<select name="addcategory_pos"'.$chgstr.'>'
4408: .'<option value="0">1</option>'
4409: .'<option value="1">2</option>'
4410: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4411: .&mt('Add category').'</td><td>'.&mt('Name:')
4412: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4413: return $datatable;
4414: }
4415:
4416: sub build_category_rows {
1.49 raeburn 4417: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4418: my ($text,$name,$item,$chgstr);
1.48 raeburn 4419: if (ref($cats) eq 'ARRAY') {
4420: my $maxdepth = scalar(@{$cats});
4421: if (ref($cats->[$depth]) eq 'HASH') {
4422: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4423: my $numchildren = @{$cats->[$depth]{$parent}};
4424: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 4425: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4426: my ($idxnum,$parent_name,$parent_item);
4427: my $higher = $depth - 1;
4428: if ($higher == 0) {
4429: $parent_name = &escape($parent).'::'.$higher;
4430: } else {
4431: if (ref($path) eq 'ARRAY') {
4432: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4433: }
4434: }
4435: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4436: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4437: if ($j < $numchildren) {
1.48 raeburn 4438: $name = $cats->[$depth]{$parent}[$j];
4439: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4440: $idxnum = $idx->{$item};
4441: } else {
4442: $name = $parent_name;
4443: $item = $parent_item;
1.48 raeburn 4444: }
1.49 raeburn 4445: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4446: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4447: for (my $i=0; $i<=$numchildren; $i++) {
4448: my $vpos = $i+1;
4449: my $selstr;
4450: if ($j == $i) {
4451: $selstr = ' selected="selected" ';
4452: }
4453: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4454: }
4455: $text .= '</select> ';
4456: if ($j < $numchildren) {
4457: my $deeper = $depth+1;
4458: $text .= $name.' '
4459: .'<label><input type="checkbox" name="deletecategory" value="'
4460: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4461: if(ref($path) eq 'ARRAY') {
4462: push(@{$path},$name);
1.49 raeburn 4463: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4464: pop(@{$path});
4465: }
4466: } else {
1.59 bisitz 4467: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4468: if ($j == $numchildren) {
4469: $text .= $name;
4470: } else {
4471: $text .= $item;
4472: }
4473: $text .= '" value="" />';
4474: }
4475: $text .= '</td></tr>';
4476: }
4477: $text .= '</table></td>';
4478: } else {
4479: my $higher = $depth-1;
4480: if ($higher == 0) {
4481: $name = &escape($parent).'::'.$higher;
4482: } else {
4483: if (ref($path) eq 'ARRAY') {
4484: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4485: }
4486: }
4487: my $colspan;
4488: if ($parent ne 'instcode') {
4489: $colspan = $maxdepth - $depth - 1;
4490: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4491: }
4492: }
4493: }
4494: }
4495: return $text;
4496: }
4497:
1.33 raeburn 4498: sub modifiable_userdata_row {
1.63 raeburn 4499: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4500: my $rolename;
1.63 raeburn 4501: if ($context eq 'selfcreate') {
4502: if (ref($usertypes) eq 'HASH') {
4503: $rolename = $usertypes->{$role};
4504: } else {
4505: $rolename = $role;
4506: }
1.33 raeburn 4507: } else {
1.63 raeburn 4508: if ($role eq 'cr') {
4509: $rolename = &mt('Custom role');
4510: } else {
4511: $rolename = &Apache::lonnet::plaintext($role);
4512: }
1.33 raeburn 4513: }
4514: my @fields = ('lastname','firstname','middlename','generation',
4515: 'permanentemail','id');
4516: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4517: my $output;
4518: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4519: $output = '<tr '.$css_class.'>'.
4520: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4521: '<td class="LC_left_item" colspan="2"><table>';
4522: my $rem;
4523: my %checks;
4524: if (ref($settings) eq 'HASH') {
4525: if (ref($settings->{$context}) eq 'HASH') {
4526: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4527: foreach my $field (@fields) {
4528: if ($settings->{$context}->{$role}->{$field}) {
4529: $checks{$field} = ' checked="checked" ';
4530: }
4531: }
4532: }
4533: }
4534: }
4535: for (my $i=0; $i<@fields; $i++) {
4536: my $rem = $i%($numinrow);
4537: if ($rem == 0) {
4538: if ($i > 0) {
4539: $output .= '</tr>';
4540: }
4541: $output .= '<tr>';
4542: }
4543: my $check = ' ';
4544: if (exists($checks{$fields[$i]})) {
4545: $check = $checks{$fields[$i]}
4546: } else {
4547: if ($role eq 'st') {
4548: if (ref($settings) ne 'HASH') {
4549: $check = ' checked="checked" ';
4550: }
4551: }
4552: }
4553: $output .= '<td class="LC_left_item">'.
4554: '<span class="LC_nobreak"><label>'.
4555: '<input type="checkbox" name="canmodify_'.$role.'" '.
4556: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4557: '</label></span></td>';
4558: $rem = @fields%($numinrow);
4559: }
4560: my $colsleft = $numinrow - $rem;
4561: if ($colsleft > 1 ) {
4562: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4563: ' </td>';
4564: } elsif ($colsleft == 1) {
4565: $output .= '<td class="LC_left_item"> </td>';
4566: }
4567: $output .= '</tr></table></td></tr>';
4568: return $output;
4569: }
1.28 raeburn 4570:
1.93 raeburn 4571: sub insttypes_row {
4572: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4573: my %lt = &Apache::lonlocal::texthash (
4574: cansearch => 'Users allowed to search',
4575: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4576: lockablenames => 'User preference to lock name',
1.93 raeburn 4577: );
4578: my $showdom;
4579: if ($context eq 'cansearch') {
4580: $showdom = ' ('.$dom.')';
4581: }
1.160.6.5 raeburn 4582: my $class = 'LC_left_item';
4583: if ($context eq 'statustocreate') {
4584: $class = 'LC_right_item';
4585: }
1.25 raeburn 4586: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4587: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4588: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4589: my $rem;
4590: if (ref($types) eq 'ARRAY') {
4591: for (my $i=0; $i<@{$types}; $i++) {
4592: if (defined($usertypes->{$types->[$i]})) {
4593: my $rem = $i%($numinrow);
4594: if ($rem == 0) {
4595: if ($i > 0) {
4596: $output .= '</tr>';
4597: }
4598: $output .= '<tr>';
1.23 raeburn 4599: }
1.26 raeburn 4600: my $check = ' ';
1.99 raeburn 4601: if (ref($settings) eq 'HASH') {
4602: if (ref($settings->{$context}) eq 'ARRAY') {
4603: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4604: $check = ' checked="checked" ';
4605: }
4606: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4607: $check = ' checked="checked" ';
4608: }
1.23 raeburn 4609: }
1.26 raeburn 4610: $output .= '<td class="LC_left_item">'.
4611: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4612: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4613: 'value="'.$types->[$i].'"'.$check.'/>'.
4614: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4615: }
4616: }
1.26 raeburn 4617: $rem = @{$types}%($numinrow);
1.23 raeburn 4618: }
4619: my $colsleft = $numinrow - $rem;
1.131 raeburn 4620: if (($rem == 0) && (@{$types} > 0)) {
4621: $output .= '<tr>';
4622: }
1.23 raeburn 4623: if ($colsleft > 1) {
1.25 raeburn 4624: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4625: } else {
1.25 raeburn 4626: $output .= '<td class="LC_left_item">';
1.23 raeburn 4627: }
4628: my $defcheck = ' ';
1.99 raeburn 4629: if (ref($settings) eq 'HASH') {
4630: if (ref($settings->{$context}) eq 'ARRAY') {
4631: if (grep(/^default$/,@{$settings->{$context}})) {
4632: $defcheck = ' checked="checked" ';
4633: }
4634: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4635: $defcheck = ' checked="checked" ';
4636: }
1.23 raeburn 4637: }
1.25 raeburn 4638: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4639: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4640: 'value="default"'.$defcheck.'/>'.
4641: $othertitle.'</label></span></td>'.
4642: '</tr></table></td></tr>';
4643: return $output;
1.23 raeburn 4644: }
4645:
4646: sub sorted_searchtitles {
4647: my %searchtitles = &Apache::lonlocal::texthash(
4648: 'uname' => 'username',
4649: 'lastname' => 'last name',
4650: 'lastfirst' => 'last name, first name',
4651: );
4652: my @titleorder = ('uname','lastname','lastfirst');
4653: return (\%searchtitles,\@titleorder);
4654: }
4655:
1.25 raeburn 4656: sub sorted_searchtypes {
4657: my %srchtypes_desc = (
4658: exact => 'is exact match',
4659: contains => 'contains ..',
4660: begins => 'begins with ..',
4661: );
4662: my @srchtypeorder = ('exact','begins','contains');
4663: return (\%srchtypes_desc,\@srchtypeorder);
4664: }
4665:
1.3 raeburn 4666: sub usertype_update_row {
4667: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4668: my $datatable;
4669: my $numinrow = 4;
4670: foreach my $type (@{$types}) {
4671: if (defined($usertypes->{$type})) {
4672: $$rownums ++;
4673: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4674: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4675: '</td><td class="LC_left_item"><table>';
4676: for (my $i=0; $i<@{$fields}; $i++) {
4677: my $rem = $i%($numinrow);
4678: if ($rem == 0) {
4679: if ($i > 0) {
4680: $datatable .= '</tr>';
4681: }
4682: $datatable .= '<tr>';
4683: }
4684: my $check = ' ';
1.39 raeburn 4685: if (ref($settings) eq 'HASH') {
4686: if (ref($settings->{'fields'}) eq 'HASH') {
4687: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4688: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4689: $check = ' checked="checked" ';
4690: }
1.3 raeburn 4691: }
4692: }
4693: }
4694:
4695: if ($i == @{$fields}-1) {
4696: my $colsleft = $numinrow - $rem;
4697: if ($colsleft > 1) {
4698: $datatable .= '<td colspan="'.$colsleft.'">';
4699: } else {
4700: $datatable .= '<td>';
4701: }
4702: } else {
4703: $datatable .= '<td>';
4704: }
1.8 raeburn 4705: $datatable .= '<span class="LC_nobreak"><label>'.
4706: '<input type="checkbox" name="updateable_'.$type.
4707: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4708: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4709: }
4710: $datatable .= '</tr></table></td></tr>';
4711: }
4712: }
4713: return $datatable;
1.1 raeburn 4714: }
4715:
4716: sub modify_login {
1.160.6.24 raeburn 4717: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 4718: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4719: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4720: %title = ( coursecatalog => 'Display course catalog',
4721: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 4722: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4723: newuser => 'Link for visitors to create a user account',
4724: loginheader => 'Log-in box header');
4725: @offon = ('off','on');
1.112 raeburn 4726: if (ref($domconfig{login}) eq 'HASH') {
4727: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4728: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4729: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4730: }
4731: }
4732: }
1.9 raeburn 4733: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4734: \%domconfig,\%loginhash);
1.160.6.14 raeburn 4735: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4736: foreach my $item (@toggles) {
4737: $loginhash{login}{$item} = $env{'form.'.$item};
4738: }
1.41 raeburn 4739: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4740: if (ref($colchanges{'login'}) eq 'HASH') {
4741: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4742: \%loginhash);
4743: }
1.110 raeburn 4744:
1.149 raeburn 4745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4746: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4747: if (keys(%servers) > 1) {
4748: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4749: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4750: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4751: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4752: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4753: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4754: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4755: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4756: $changes{'loginvia'}{$lonhost} = 1;
4757: } else {
4758: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4759: $changes{'loginvia'}{$lonhost} = 1;
4760: }
4761: } else {
4762: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4763: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4764: $changes{'loginvia'}{$lonhost} = 1;
4765: }
4766: }
4767: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4768: foreach my $item (@loginvia_attribs) {
4769: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4770: }
4771: } else {
4772: foreach my $item (@loginvia_attribs) {
4773: my $new = $env{'form.'.$lonhost.'_'.$item};
4774: if (($item eq 'serverpath') && ($new eq 'custom')) {
4775: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4776: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4777: $new = '/';
4778: }
4779: }
4780: if (($item eq 'custompath') &&
4781: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4782: $new = '';
4783: }
4784: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4785: $changes{'loginvia'}{$lonhost} = 1;
4786: }
4787: if ($item eq 'exempt') {
4788: $new =~ s/^\s+//;
4789: $new =~ s/\s+$//;
4790: my @poss_ips = split(/\s*[,:]\s*/,$new);
4791: my @okips;
4792: foreach my $ip (@poss_ips) {
4793: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4794: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4795: push(@okips,$ip);
4796: }
4797: }
4798: }
4799: if (@okips > 0) {
4800: $new = join(',',@okips);
4801: } else {
4802: $new = '';
4803: }
4804: }
4805: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4806: }
4807: }
1.112 raeburn 4808: } else {
1.128 raeburn 4809: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4810: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4811: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4812: foreach my $item (@loginvia_attribs) {
4813: my $new = $env{'form.'.$lonhost.'_'.$item};
4814: if (($item eq 'serverpath') && ($new eq 'custom')) {
4815: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4816: $new = '/';
4817: }
4818: }
4819: if (($item eq 'custompath') &&
4820: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4821: $new = '';
4822: }
4823: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4824: }
1.110 raeburn 4825: }
4826: }
4827: }
4828: }
1.119 raeburn 4829:
1.160.6.5 raeburn 4830: my $servadm = $r->dir_config('lonAdmEMail');
4831: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4832: if (ref($domconfig{'login'}) eq 'HASH') {
4833: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4834: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4835: if ($lang eq 'nolang') {
4836: push(@currlangs,$lang);
4837: } elsif (defined($langchoices{$lang})) {
4838: push(@currlangs,$lang);
4839: } else {
4840: next;
4841: }
4842: }
4843: }
4844: }
4845: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4846: if (@currlangs > 0) {
4847: foreach my $lang (@currlangs) {
4848: if (grep(/^\Q$lang\E$/,@delurls)) {
4849: $changes{'helpurl'}{$lang} = 1;
4850: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4851: $changes{'helpurl'}{$lang} = 1;
4852: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4853: push(@newlangs,$lang);
4854: } else {
4855: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4856: }
4857: }
4858: }
4859: unless (grep(/^nolang$/,@currlangs)) {
4860: if ($env{'form.loginhelpurl_nolang.filename'}) {
4861: $changes{'helpurl'}{'nolang'} = 1;
4862: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4863: push(@newlangs,'nolang');
4864: }
4865: }
4866: if ($env{'form.loginhelpurl_add_lang'}) {
4867: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4868: ($env{'form.loginhelpurl_add_file.filename'})) {
4869: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4870: $addedfile = $env{'form.loginhelpurl_add_lang'};
4871: }
4872: }
4873: if ((@newlangs > 0) || ($addedfile)) {
4874: my $error;
4875: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4876: if ($configuserok eq 'ok') {
4877: if ($switchserver) {
4878: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4879: } elsif ($author_ok eq 'ok') {
4880: my @allnew = @newlangs;
4881: if ($addedfile ne '') {
4882: push(@allnew,$addedfile);
4883: }
4884: foreach my $lang (@allnew) {
4885: my $formelem = 'loginhelpurl_'.$lang;
4886: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4887: $formelem = 'loginhelpurl_add_file';
4888: }
4889: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4890: "help/$lang",'','',$newfile{$lang});
4891: if ($result eq 'ok') {
4892: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4893: $changes{'helpurl'}{$lang} = 1;
4894: } else {
4895: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4896: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4897: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4898: (!grep(/^\Q$lang\E$/,@delurls))) {
4899:
4900: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4901: }
4902: }
4903: }
4904: } else {
4905: $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);
4906: }
4907: } else {
4908: $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);
4909: }
4910: if ($error) {
4911: &Apache::lonnet::logthis($error);
4912: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4913: }
4914: }
4915: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4916:
4917: my $defaulthelpfile = '/adm/loginproblems.html';
4918: my $defaulttext = &mt('Default in use');
4919:
1.1 raeburn 4920: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4921: $dom);
4922: if ($putresult eq 'ok') {
1.160.6.14 raeburn 4923: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4924: my %defaultchecked = (
4925: 'coursecatalog' => 'on',
1.160.6.14 raeburn 4926: 'helpdesk' => 'on',
1.42 raeburn 4927: 'adminmail' => 'off',
1.43 raeburn 4928: 'newuser' => 'off',
1.42 raeburn 4929: );
1.55 raeburn 4930: if (ref($domconfig{'login'}) eq 'HASH') {
4931: foreach my $item (@toggles) {
4932: if ($defaultchecked{$item} eq 'on') {
4933: if (($domconfig{'login'}{$item} eq '0') &&
4934: ($env{'form.'.$item} eq '1')) {
4935: $changes{$item} = 1;
4936: } elsif (($domconfig{'login'}{$item} eq '' ||
4937: $domconfig{'login'}{$item} eq '1') &&
4938: ($env{'form.'.$item} eq '0')) {
4939: $changes{$item} = 1;
4940: }
4941: } elsif ($defaultchecked{$item} eq 'off') {
4942: if (($domconfig{'login'}{$item} eq '1') &&
4943: ($env{'form.'.$item} eq '0')) {
4944: $changes{$item} = 1;
4945: } elsif (($domconfig{'login'}{$item} eq '' ||
4946: $domconfig{'login'}{$item} eq '0') &&
4947: ($env{'form.'.$item} eq '1')) {
4948: $changes{$item} = 1;
4949: }
1.42 raeburn 4950: }
4951: }
1.41 raeburn 4952: }
1.6 raeburn 4953: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4954: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.24 raeburn 4955: $$lastactref = 'update';
1.1 raeburn 4956: $resulttext = &mt('Changes made:').'<ul>';
4957: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4958: if ($item eq 'loginvia') {
1.112 raeburn 4959: if (ref($changes{$item}) eq 'HASH') {
4960: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4961: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4962: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4963: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4964: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4965: $protocol = 'http' if ($protocol ne 'https');
4966: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4967:
4968: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4969: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4970: } else {
4971: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4972: }
4973: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4974: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4975: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4976: }
4977: $resulttext .= '</li>';
4978: } else {
4979: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4980: }
1.112 raeburn 4981: } else {
1.128 raeburn 4982: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4983: }
4984: }
1.128 raeburn 4985: $resulttext .= '</ul></li>';
1.112 raeburn 4986: }
1.160.6.5 raeburn 4987: } elsif ($item eq 'helpurl') {
4988: if (ref($changes{$item}) eq 'HASH') {
4989: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4990: if (grep(/^\Q$lang\E$/,@delurls)) {
4991: my ($chg,$link);
4992: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4993: if ($lang eq 'nolang') {
4994: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4995: } else {
4996: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4997: }
4998: $resulttext .= '<li>'.$chg.'</li>';
4999: } else {
5000: my $chg;
5001: if ($lang eq 'nolang') {
5002: $chg = &mt('custom log-in help file for no preferred language');
5003: } else {
5004: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5005: }
5006: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5007: $loginhash{'login'}{'helpurl'}{$lang}.
5008: '?inhibitmenu=yes',$chg,600,500).
5009: '</li>';
5010: }
5011: }
5012: }
5013: } elsif ($item eq 'captcha') {
5014: if (ref($loginhash{'login'}) eq 'HASH') {
5015: my $chgtxt;
5016: if ($loginhash{'login'}{$item} eq 'notused') {
5017: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5018: } else {
5019: my %captchas = &captcha_phrases();
5020: if ($captchas{$loginhash{'login'}{$item}}) {
5021: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5022: } else {
5023: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5024: }
5025: }
5026: $resulttext .= '<li>'.$chgtxt.'</li>';
5027: }
5028: } elsif ($item eq 'recaptchakeys') {
5029: if (ref($loginhash{'login'}) eq 'HASH') {
5030: my ($privkey,$pubkey);
5031: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5032: $pubkey = $loginhash{'login'}{$item}{'public'};
5033: $privkey = $loginhash{'login'}{$item}{'private'};
5034: }
5035: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5036: if (!$pubkey) {
5037: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5038: } else {
5039: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5040: }
5041: if (!$privkey) {
5042: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5043: } else {
5044: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5045: }
5046: $chgtxt .= '</ul>';
5047: $resulttext .= '<li>'.$chgtxt.'</li>';
5048: }
1.41 raeburn 5049: } else {
5050: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5051: }
1.1 raeburn 5052: }
1.6 raeburn 5053: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5054: } else {
5055: $resulttext = &mt('No changes made to log-in page settings');
5056: }
5057: } else {
1.11 albertel 5058: $resulttext = '<span class="LC_error">'.
5059: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5060: }
1.6 raeburn 5061: if ($errors) {
1.9 raeburn 5062: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5063: $errors.'</ul>';
5064: }
5065: return $resulttext;
5066: }
5067:
5068: sub color_font_choices {
5069: my %choices =
5070: &Apache::lonlocal::texthash (
5071: img => "Header",
5072: bgs => "Background colors",
5073: links => "Link colors",
1.55 raeburn 5074: images => "Images",
1.6 raeburn 5075: font => "Font color",
1.160.6.22 raeburn 5076: fontmenu => "Font menu",
1.76 raeburn 5077: pgbg => "Page",
1.6 raeburn 5078: tabbg => "Header",
5079: sidebg => "Border",
5080: link => "Link",
5081: alink => "Active link",
5082: vlink => "Visited link",
5083: );
5084: return %choices;
5085: }
5086:
5087: sub modify_rolecolors {
1.160.6.24 raeburn 5088: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5089: my ($resulttext,%rolehash);
5090: $rolehash{'rolecolors'} = {};
1.55 raeburn 5091: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5092: if ($domconfig{'rolecolors'} eq '') {
5093: $domconfig{'rolecolors'} = {};
5094: }
5095: }
1.9 raeburn 5096: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5097: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5098: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5099: $dom);
5100: if ($putresult eq 'ok') {
5101: if (keys(%changes) > 0) {
1.41 raeburn 5102: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.24 raeburn 5103: $$lastactref = 'update';
1.6 raeburn 5104: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5105: $rolehash{'rolecolors'});
5106: } else {
5107: $resulttext = &mt('No changes made to default color schemes');
5108: }
5109: } else {
1.11 albertel 5110: $resulttext = '<span class="LC_error">'.
5111: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5112: }
5113: if ($errors) {
5114: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5115: $errors.'</ul>';
5116: }
5117: return $resulttext;
5118: }
5119:
5120: sub modify_colors {
1.9 raeburn 5121: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5122: my (%changes,%choices);
1.51 raeburn 5123: my @bgs;
1.6 raeburn 5124: my @links = ('link','alink','vlink');
1.41 raeburn 5125: my @logintext;
1.6 raeburn 5126: my @images;
5127: my $servadm = $r->dir_config('lonAdmEMail');
5128: my $errors;
1.160.6.22 raeburn 5129: my %defaults;
1.6 raeburn 5130: foreach my $role (@{$roles}) {
5131: if ($role eq 'login') {
1.12 raeburn 5132: %choices = &login_choices();
1.41 raeburn 5133: @logintext = ('textcol','bgcol');
1.12 raeburn 5134: } else {
5135: %choices = &color_font_choices();
5136: }
5137: if ($role eq 'login') {
1.41 raeburn 5138: @images = ('img','logo','domlogo','login');
1.51 raeburn 5139: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5140: } else {
5141: @images = ('img');
1.160.6.22 raeburn 5142: @bgs = ('pgbg','tabbg','sidebg');
5143: }
5144: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5145: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5146: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5147: }
5148: if ($role eq 'login') {
5149: foreach my $item (@logintext) {
5150: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5151: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5152: }
5153: }
5154: } else {
5155: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5156: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5157: }
1.6 raeburn 5158: }
1.160.6.22 raeburn 5159: foreach my $item (@bgs) {
5160: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5161: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5162: }
5163: }
5164: foreach my $item (@links) {
5165: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5166: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5167: }
1.6 raeburn 5168: }
1.46 raeburn 5169: my ($configuserok,$author_ok,$switchserver) =
5170: &config_check($dom,$confname,$servadm);
1.9 raeburn 5171: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5172: if (ref($domconfig->{$role}) ne 'HASH') {
5173: $domconfig->{$role} = {};
5174: }
1.8 raeburn 5175: foreach my $img (@images) {
1.70 raeburn 5176: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5177: if (defined($env{'form.login_showlogo_'.$img})) {
5178: $confhash->{$role}{'showlogo'}{$img} = 1;
5179: } else {
5180: $confhash->{$role}{'showlogo'}{$img} = 0;
5181: }
5182: }
1.18 albertel 5183: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5184: && !defined($domconfig->{$role}{$img})
5185: && !$env{'form.'.$role.'_del_'.$img}
5186: && $env{'form.'.$role.'_import_'.$img}) {
5187: # import the old configured image from the .tab setting
5188: # if they haven't provided a new one
5189: $domconfig->{$role}{$img} =
5190: $env{'form.'.$role.'_import_'.$img};
5191: }
1.6 raeburn 5192: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5193: my $error;
1.6 raeburn 5194: if ($configuserok eq 'ok') {
1.9 raeburn 5195: if ($switchserver) {
1.12 raeburn 5196: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5197: } else {
5198: if ($author_ok eq 'ok') {
5199: my ($result,$logourl) =
5200: &publishlogo($r,'upload',$role.'_'.$img,
5201: $dom,$confname,$img,$width,$height);
5202: if ($result eq 'ok') {
5203: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5204: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5205: } else {
1.12 raeburn 5206: $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 5207: }
5208: } else {
1.46 raeburn 5209: $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 5210: }
5211: }
5212: } else {
1.46 raeburn 5213: $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 5214: }
5215: if ($error) {
1.8 raeburn 5216: &Apache::lonnet::logthis($error);
1.11 albertel 5217: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5218: }
5219: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5220: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5221: my $error;
5222: if ($configuserok eq 'ok') {
5223: # is confname an author?
5224: if ($switchserver eq '') {
5225: if ($author_ok eq 'ok') {
5226: my ($result,$logourl) =
5227: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5228: $dom,$confname,$img,$width,$height);
5229: if ($result eq 'ok') {
5230: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5231: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5232: }
5233: }
5234: }
5235: }
1.6 raeburn 5236: }
5237: }
5238: }
5239: if (ref($domconfig) eq 'HASH') {
5240: if (ref($domconfig->{$role}) eq 'HASH') {
5241: foreach my $img (@images) {
5242: if ($domconfig->{$role}{$img} ne '') {
5243: if ($env{'form.'.$role.'_del_'.$img}) {
5244: $confhash->{$role}{$img} = '';
1.12 raeburn 5245: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5246: } else {
1.9 raeburn 5247: if ($confhash->{$role}{$img} eq '') {
5248: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5249: }
1.6 raeburn 5250: }
5251: } else {
5252: if ($env{'form.'.$role.'_del_'.$img}) {
5253: $confhash->{$role}{$img} = '';
1.12 raeburn 5254: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5255: }
5256: }
1.70 raeburn 5257: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5258: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5259: if ($confhash->{$role}{'showlogo'}{$img} ne
5260: $domconfig->{$role}{'showlogo'}{$img}) {
5261: $changes{$role}{'showlogo'}{$img} = 1;
5262: }
5263: } else {
5264: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5265: $changes{$role}{'showlogo'}{$img} = 1;
5266: }
5267: }
5268: }
5269: }
1.6 raeburn 5270: if ($domconfig->{$role}{'font'} ne '') {
5271: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5272: $changes{$role}{'font'} = 1;
5273: }
5274: } else {
5275: if ($confhash->{$role}{'font'}) {
5276: $changes{$role}{'font'} = 1;
5277: }
5278: }
1.107 raeburn 5279: if ($role ne 'login') {
5280: if ($domconfig->{$role}{'fontmenu'} ne '') {
5281: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5282: $changes{$role}{'fontmenu'} = 1;
5283: }
5284: } else {
5285: if ($confhash->{$role}{'fontmenu'}) {
5286: $changes{$role}{'fontmenu'} = 1;
5287: }
1.97 tempelho 5288: }
5289: }
1.6 raeburn 5290: foreach my $item (@bgs) {
5291: if ($domconfig->{$role}{$item} ne '') {
5292: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5293: $changes{$role}{'bgs'}{$item} = 1;
5294: }
5295: } else {
5296: if ($confhash->{$role}{$item}) {
5297: $changes{$role}{'bgs'}{$item} = 1;
5298: }
5299: }
5300: }
5301: foreach my $item (@links) {
5302: if ($domconfig->{$role}{$item} ne '') {
5303: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5304: $changes{$role}{'links'}{$item} = 1;
5305: }
5306: } else {
5307: if ($confhash->{$role}{$item}) {
5308: $changes{$role}{'links'}{$item} = 1;
5309: }
5310: }
5311: }
1.41 raeburn 5312: foreach my $item (@logintext) {
5313: if ($domconfig->{$role}{$item} ne '') {
5314: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5315: $changes{$role}{'logintext'}{$item} = 1;
5316: }
5317: } else {
5318: if ($confhash->{$role}{$item}) {
5319: $changes{$role}{'logintext'}{$item} = 1;
5320: }
5321: }
5322: }
1.6 raeburn 5323: } else {
5324: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5325: \@logintext,$confhash,\%changes);
1.6 raeburn 5326: }
5327: } else {
5328: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5329: \@logintext,$confhash,\%changes);
1.6 raeburn 5330: }
5331: }
5332: return ($errors,%changes);
5333: }
5334:
1.46 raeburn 5335: sub config_check {
5336: my ($dom,$confname,$servadm) = @_;
5337: my ($configuserok,$author_ok,$switchserver,%currroles);
5338: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5339: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5340: $confname,$servadm);
5341: if ($configuserok eq 'ok') {
5342: $switchserver = &check_switchserver($dom,$confname);
5343: if ($switchserver eq '') {
5344: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5345: }
5346: }
5347: return ($configuserok,$author_ok,$switchserver);
5348: }
5349:
1.6 raeburn 5350: sub default_change_checker {
1.41 raeburn 5351: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5352: foreach my $item (@{$links}) {
5353: if ($confhash->{$role}{$item}) {
5354: $changes->{$role}{'links'}{$item} = 1;
5355: }
5356: }
5357: foreach my $item (@{$bgs}) {
5358: if ($confhash->{$role}{$item}) {
5359: $changes->{$role}{'bgs'}{$item} = 1;
5360: }
5361: }
1.41 raeburn 5362: foreach my $item (@{$logintext}) {
5363: if ($confhash->{$role}{$item}) {
5364: $changes->{$role}{'logintext'}{$item} = 1;
5365: }
5366: }
1.6 raeburn 5367: foreach my $img (@{$images}) {
5368: if ($env{'form.'.$role.'_del_'.$img}) {
5369: $confhash->{$role}{$img} = '';
1.12 raeburn 5370: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5371: }
1.70 raeburn 5372: if ($role eq 'login') {
5373: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5374: $changes->{$role}{'showlogo'}{$img} = 1;
5375: }
5376: }
1.6 raeburn 5377: }
5378: if ($confhash->{$role}{'font'}) {
5379: $changes->{$role}{'font'} = 1;
5380: }
1.48 raeburn 5381: }
1.6 raeburn 5382:
5383: sub display_colorchgs {
5384: my ($dom,$changes,$roles,$confhash) = @_;
5385: my (%choices,$resulttext);
5386: if (!grep(/^login$/,@{$roles})) {
5387: $resulttext = &mt('Changes made:').'<br />';
5388: }
5389: foreach my $role (@{$roles}) {
5390: if ($role eq 'login') {
5391: %choices = &login_choices();
5392: } else {
5393: %choices = &color_font_choices();
5394: }
5395: if (ref($changes->{$role}) eq 'HASH') {
5396: if ($role ne 'login') {
5397: $resulttext .= '<h4>'.&mt($role).'</h4>';
5398: }
5399: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5400: if ($role ne 'login') {
5401: $resulttext .= '<ul>';
5402: }
5403: if (ref($changes->{$role}{$key}) eq 'HASH') {
5404: if ($role ne 'login') {
5405: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5406: }
5407: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5408: if (($role eq 'login') && ($key eq 'showlogo')) {
5409: if ($confhash->{$role}{$key}{$item}) {
5410: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5411: } else {
5412: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5413: }
5414: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5415: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5416: } else {
1.12 raeburn 5417: my $newitem = $confhash->{$role}{$item};
5418: if ($key eq 'images') {
5419: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5420: }
5421: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5422: }
5423: }
5424: if ($role ne 'login') {
5425: $resulttext .= '</ul></li>';
5426: }
5427: } else {
5428: if ($confhash->{$role}{$key} eq '') {
5429: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5430: } else {
5431: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5432: }
5433: }
5434: if ($role ne 'login') {
5435: $resulttext .= '</ul>';
5436: }
5437: }
5438: }
5439: }
1.3 raeburn 5440: return $resulttext;
1.1 raeburn 5441: }
5442:
1.9 raeburn 5443: sub thumb_dimensions {
5444: return ('200','50');
5445: }
5446:
1.16 raeburn 5447: sub check_dimensions {
5448: my ($inputfile) = @_;
5449: my ($fullwidth,$fullheight);
5450: if ($inputfile =~ m|^[/\w.\-]+$|) {
5451: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5452: my $imageinfo = <PIPE>;
5453: if (!close(PIPE)) {
5454: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5455: }
5456: chomp($imageinfo);
5457: my ($fullsize) =
1.21 raeburn 5458: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5459: if ($fullsize) {
5460: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5461: }
5462: }
5463: }
5464: return ($fullwidth,$fullheight);
5465: }
5466:
1.9 raeburn 5467: sub check_configuser {
5468: my ($uhome,$dom,$confname,$servadm) = @_;
5469: my ($configuserok,%currroles);
5470: if ($uhome eq 'no_host') {
5471: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5472: my $configpass = &LONCAPA::Enrollment::create_password();
5473: $configuserok =
5474: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5475: $configpass,'','','','','',undef,$servadm);
5476: } else {
5477: $configuserok = 'ok';
5478: %currroles =
5479: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5480: }
5481: return ($configuserok,%currroles);
5482: }
5483:
5484: sub check_authorstatus {
5485: my ($dom,$confname,%currroles) = @_;
5486: my $author_ok;
1.40 raeburn 5487: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5488: my $start = time;
5489: my $end = 0;
5490: $author_ok =
5491: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5492: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5493: } else {
5494: $author_ok = 'ok';
5495: }
5496: return $author_ok;
5497: }
5498:
5499: sub publishlogo {
1.46 raeburn 5500: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5501: my ($output,$fname,$logourl);
5502: if ($action eq 'upload') {
5503: $fname=$env{'form.'.$formname.'.filename'};
5504: chop($env{'form.'.$formname});
5505: } else {
5506: ($fname) = ($formname =~ /([^\/]+)$/);
5507: }
1.46 raeburn 5508: if ($savefileas ne '') {
5509: $fname = $savefileas;
5510: }
1.9 raeburn 5511: $fname=&Apache::lonnet::clean_filename($fname);
5512: # See if there is anything left
5513: unless ($fname) { return ('error: no uploaded file'); }
5514: $fname="$subdir/$fname";
1.160.6.5 raeburn 5515: my $docroot=$r->dir_config('lonDocRoot');
5516: my $filepath="$docroot/priv";
5517: my $relpath = "$dom/$confname";
1.9 raeburn 5518: my ($fnamepath,$file,$fetchthumb);
5519: $file=$fname;
5520: if ($fname=~m|/|) {
5521: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5522: }
1.160.6.5 raeburn 5523: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5524: my $count;
1.160.6.5 raeburn 5525: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5526: $filepath.="/$parts[$count]";
5527: if ((-e $filepath)!=1) {
5528: mkdir($filepath,02770);
5529: }
5530: }
5531: # Check for bad extension and disallow upload
5532: if ($file=~/\.(\w+)$/ &&
5533: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5534: $output =
1.160.6.25! raeburn 5535: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5536: } elsif ($file=~/\.(\w+)$/ &&
5537: !defined(&Apache::loncommon::fileembstyle($1))) {
5538: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5539: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 5540: $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 5541: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 5542: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5543: } else {
5544: my $source = $filepath.'/'.$file;
5545: my $logfile;
5546: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 5547: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5548: }
5549: print $logfile
5550: "\n================= Publish ".localtime()." ================\n".
5551: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5552: # Save the file
5553: if (!open(FH,'>'.$source)) {
5554: &Apache::lonnet::logthis('Failed to create '.$source);
5555: return (&mt('Failed to create file'));
5556: }
5557: if ($action eq 'upload') {
5558: if (!print FH ($env{'form.'.$formname})) {
5559: &Apache::lonnet::logthis('Failed to write to '.$source);
5560: return (&mt('Failed to write file'));
5561: }
5562: } else {
5563: my $original = &Apache::lonnet::filelocation('',$formname);
5564: if(!copy($original,$source)) {
5565: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5566: return (&mt('Failed to write file'));
5567: }
5568: }
5569: close(FH);
5570: chmod(0660, $source); # Permissions to rw-rw---.
5571:
5572: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5573: my $copyfile=$targetdir.'/'.$file;
5574:
5575: my @parts=split(/\//,$targetdir);
5576: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5577: for (my $count=5;$count<=$#parts;$count++) {
5578: $path.="/$parts[$count]";
5579: if (!-e $path) {
5580: print $logfile "\nCreating directory ".$path;
5581: mkdir($path,02770);
5582: }
5583: }
5584: my $versionresult;
5585: if (-e $copyfile) {
5586: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5587: } else {
5588: $versionresult = 'ok';
5589: }
5590: if ($versionresult eq 'ok') {
5591: if (copy($source,$copyfile)) {
5592: print $logfile "\nCopied original source to ".$copyfile."\n";
5593: $output = 'ok';
5594: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5595: push(@{$modified_urls},[$copyfile,$source]);
5596: my $metaoutput =
5597: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5598: unless ($registered_cleanup) {
5599: my $handlers = $r->get_handlers('PerlCleanupHandler');
5600: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5601: $registered_cleanup=1;
5602: }
1.9 raeburn 5603: } else {
5604: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5605: $output = &mt('Failed to copy file to RES space').", $!";
5606: }
5607: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5608: my $inputfile = $filepath.'/'.$file;
5609: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5610: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5611: if ($fullwidth ne '' && $fullheight ne '') {
5612: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5613: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5614: system("convert -sample $thumbsize $inputfile $outfile");
5615: chmod(0660, $filepath.'/tn-'.$file);
5616: if (-e $outfile) {
5617: my $copyfile=$targetdir.'/tn-'.$file;
5618: if (copy($outfile,$copyfile)) {
5619: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5620: my $thumb_metaoutput =
5621: &write_metadata($dom,$confname,$formname,
5622: $targetdir,'tn-'.$file,$logfile);
5623: push(@{$modified_urls},[$copyfile,$outfile]);
5624: unless ($registered_cleanup) {
5625: my $handlers = $r->get_handlers('PerlCleanupHandler');
5626: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5627: $registered_cleanup=1;
5628: }
1.16 raeburn 5629: } else {
5630: print $logfile "\nUnable to write ".$copyfile.
5631: ':'.$!."\n";
5632: }
5633: }
1.9 raeburn 5634: }
5635: }
5636: }
5637: } else {
5638: $output = $versionresult;
5639: }
5640: }
5641: return ($output,$logourl);
5642: }
5643:
5644: sub logo_versioning {
5645: my ($targetdir,$file,$logfile) = @_;
5646: my $target = $targetdir.'/'.$file;
5647: my ($maxversion,$fn,$extn,$output);
5648: $maxversion = 0;
5649: if ($file =~ /^(.+)\.(\w+)$/) {
5650: $fn=$1;
5651: $extn=$2;
5652: }
5653: opendir(DIR,$targetdir);
5654: while (my $filename=readdir(DIR)) {
5655: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5656: $maxversion=($1>$maxversion)?$1:$maxversion;
5657: }
5658: }
5659: $maxversion++;
5660: print $logfile "\nCreating old version ".$maxversion."\n";
5661: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5662: if (copy($target,$copyfile)) {
5663: print $logfile "Copied old target to ".$copyfile."\n";
5664: $copyfile=$copyfile.'.meta';
5665: if (copy($target.'.meta',$copyfile)) {
5666: print $logfile "Copied old target metadata to ".$copyfile."\n";
5667: $output = 'ok';
5668: } else {
5669: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5670: $output = &mt('Failed to copy old meta').", $!, ";
5671: }
5672: } else {
5673: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5674: $output = &mt('Failed to copy old target').", $!, ";
5675: }
5676: return $output;
5677: }
5678:
5679: sub write_metadata {
5680: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5681: my (%metadatafields,%metadatakeys,$output);
5682: $metadatafields{'title'}=$formname;
5683: $metadatafields{'creationdate'}=time;
5684: $metadatafields{'lastrevisiondate'}=time;
5685: $metadatafields{'copyright'}='public';
5686: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5687: $env{'user.domain'};
5688: $metadatafields{'authorspace'}=$confname.':'.$dom;
5689: $metadatafields{'domain'}=$dom;
5690: {
5691: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5692: my $mfh;
1.155 raeburn 5693: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5694: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5695: unless ($_=~/\./) {
5696: my $unikey=$_;
5697: $unikey=~/^([A-Za-z]+)/;
5698: my $tag=$1;
5699: $tag=~tr/A-Z/a-z/;
5700: print $mfh "\n\<$tag";
5701: foreach (split(/\,/,$metadatakeys{$unikey})) {
5702: my $value=$metadatafields{$unikey.'.'.$_};
5703: $value=~s/\"/\'\'/g;
5704: print $mfh ' '.$_.'="'.$value.'"';
5705: }
5706: print $mfh '>'.
5707: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5708: .'</'.$tag.'>';
5709: }
5710: }
5711: $output = 'ok';
5712: print $logfile "\nWrote metadata";
5713: close($mfh);
5714: } else {
5715: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5716: $output = &mt('Could not write metadata');
5717: }
5718: }
1.155 raeburn 5719: return $output;
5720: }
5721:
5722: sub notifysubscribed {
5723: foreach my $targetsource (@{$modified_urls}){
5724: next unless (ref($targetsource) eq 'ARRAY');
5725: my ($target,$source)=@{$targetsource};
5726: if ($source ne '') {
5727: if (open(my $logfh,'>>'.$source.'.log')) {
5728: print $logfh "\nCleanup phase: Notifications\n";
5729: my @subscribed=&subscribed_hosts($target);
5730: foreach my $subhost (@subscribed) {
5731: print $logfh "\nNotifying host ".$subhost.':';
5732: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5733: print $logfh $reply;
5734: }
5735: my @subscribedmeta=&subscribed_hosts("$target.meta");
5736: foreach my $subhost (@subscribedmeta) {
5737: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5738: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5739: $subhost);
5740: print $logfh $reply;
5741: }
5742: print $logfh "\n============ Done ============\n";
1.160 raeburn 5743: close($logfh);
1.155 raeburn 5744: }
5745: }
5746: }
5747: return OK;
5748: }
5749:
5750: sub subscribed_hosts {
5751: my ($target) = @_;
5752: my @subscribed;
5753: if (open(my $fh,"<$target.subscription")) {
5754: while (my $subline=<$fh>) {
5755: if ($subline =~ /^($match_lonid):/) {
5756: my $host = $1;
5757: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5758: unless (grep(/^\Q$host\E$/,@subscribed)) {
5759: push(@subscribed,$host);
5760: }
5761: }
5762: }
5763: }
5764: }
5765: return @subscribed;
1.9 raeburn 5766: }
5767:
5768: sub check_switchserver {
5769: my ($dom,$confname) = @_;
5770: my ($allowed,$switchserver);
5771: my $home = &Apache::lonnet::homeserver($confname,$dom);
5772: if ($home eq 'no_host') {
5773: $home = &Apache::lonnet::domain($dom,'primary');
5774: }
5775: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5776: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5777: if (!$allowed) {
1.160.6.11 raeburn 5778: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5779: }
5780: return $switchserver;
5781: }
5782:
1.1 raeburn 5783: sub modify_quotas {
1.86 raeburn 5784: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5785: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5786: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5787: if ($action eq 'quotas') {
5788: $context = 'tools';
5789: } else {
5790: $context = $action;
5791: }
5792: if ($context eq 'requestcourses') {
1.98 raeburn 5793: @usertools = ('official','unofficial','community');
1.106 raeburn 5794: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5795: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5796: %titles = &courserequest_titles();
5797: $toolregexp = join('|',@usertools);
5798: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5799: } elsif ($context eq 'requestauthor') {
5800: @usertools = ('author');
5801: %titles = &authorrequest_titles();
1.86 raeburn 5802: } else {
1.160.6.4 raeburn 5803: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5804: %titles = &tool_titles();
1.86 raeburn 5805: }
1.72 raeburn 5806: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5807: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5808: foreach my $key (keys(%env)) {
1.101 raeburn 5809: if ($context eq 'requestcourses') {
5810: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5811: my $item = $1;
5812: my $type = $2;
5813: if ($type =~ /^limit_(.+)/) {
5814: $limithash{$item}{$1} = $env{$key};
5815: } else {
5816: $confhash{$item}{$type} = $env{$key};
5817: }
5818: }
1.160.6.5 raeburn 5819: } elsif ($context eq 'requestauthor') {
5820: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5821: $confhash{$1} = $env{$key};
5822: }
1.101 raeburn 5823: } else {
1.86 raeburn 5824: if ($key =~ /^form\.quota_(.+)$/) {
5825: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 5826: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5827: $confhash{'authorquota'}{$1} = $env{$key};
5828: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5829: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5830: }
1.72 raeburn 5831: }
5832: }
1.160.6.5 raeburn 5833: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5834: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5835: @approvalnotify = sort(@approvalnotify);
5836: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5837: if (ref($domconfig{$action}) eq 'HASH') {
5838: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5839: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5840: $changes{'notify'}{'approval'} = 1;
5841: }
5842: } else {
1.144 raeburn 5843: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5844: $changes{'notify'}{'approval'} = 1;
5845: }
5846: }
5847: } else {
1.144 raeburn 5848: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5849: $changes{'notify'}{'approval'} = 1;
5850: }
5851: }
5852: } else {
1.86 raeburn 5853: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 5854: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5855: }
1.72 raeburn 5856: foreach my $item (@usertools) {
5857: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5858: my $unset;
1.101 raeburn 5859: if ($context eq 'requestcourses') {
1.104 raeburn 5860: $unset = '0';
5861: if ($type eq '_LC_adv') {
5862: $unset = '';
5863: }
1.101 raeburn 5864: if ($confhash{$item}{$type} eq 'autolimit') {
5865: $confhash{$item}{$type} .= '=';
5866: unless ($limithash{$item}{$type} =~ /\D/) {
5867: $confhash{$item}{$type} .= $limithash{$item}{$type};
5868: }
5869: }
1.160.6.5 raeburn 5870: } elsif ($context eq 'requestauthor') {
5871: $unset = '0';
5872: if ($type eq '_LC_adv') {
5873: $unset = '';
5874: }
1.72 raeburn 5875: } else {
1.101 raeburn 5876: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5877: $confhash{$item}{$type} = 1;
5878: } else {
5879: $confhash{$item}{$type} = 0;
5880: }
1.72 raeburn 5881: }
1.86 raeburn 5882: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5883: if ($action eq 'requestauthor') {
5884: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5885: $changes{$type} = 1;
5886: }
5887: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5888: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5889: $changes{$item}{$type} = 1;
5890: }
5891: } else {
5892: if ($context eq 'requestcourses') {
1.104 raeburn 5893: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5894: $changes{$item}{$type} = 1;
5895: }
5896: } else {
5897: if (!$confhash{$item}{$type}) {
5898: $changes{$item}{$type} = 1;
5899: }
5900: }
5901: }
5902: } else {
5903: if ($context eq 'requestcourses') {
1.104 raeburn 5904: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5905: $changes{$item}{$type} = 1;
5906: }
1.160.6.5 raeburn 5907: } elsif ($context eq 'requestauthor') {
5908: if ($confhash{$type} ne $unset) {
5909: $changes{$type} = 1;
5910: }
1.72 raeburn 5911: } else {
5912: if (!$confhash{$item}{$type}) {
5913: $changes{$item}{$type} = 1;
5914: }
5915: }
5916: }
1.1 raeburn 5917: }
5918: }
1.160.6.5 raeburn 5919: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5920: if (ref($domconfig{'quotas'}) eq 'HASH') {
5921: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5922: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5923: if (exists($confhash{'defaultquota'}{$key})) {
5924: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5925: $changes{'defaultquota'}{$key} = 1;
5926: }
5927: } else {
5928: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5929: }
5930: }
1.86 raeburn 5931: } else {
5932: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5933: if (exists($confhash{'defaultquota'}{$key})) {
5934: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5935: $changes{'defaultquota'}{$key} = 1;
5936: }
5937: } else {
5938: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5939: }
1.1 raeburn 5940: }
5941: }
1.160.6.20 raeburn 5942: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5943: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5944: if (exists($confhash{'authorquota'}{$key})) {
5945: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5946: $changes{'authorquota'}{$key} = 1;
5947: }
5948: } else {
5949: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5950: }
5951: }
5952: }
1.1 raeburn 5953: }
1.86 raeburn 5954: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5955: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5956: if (ref($domconfig{'quotas'}) eq 'HASH') {
5957: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5958: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5959: $changes{'defaultquota'}{$key} = 1;
5960: }
5961: } else {
5962: if (!exists($domconfig{'quotas'}{$key})) {
5963: $changes{'defaultquota'}{$key} = 1;
5964: }
1.72 raeburn 5965: }
5966: } else {
1.86 raeburn 5967: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5968: }
1.1 raeburn 5969: }
5970: }
1.160.6.20 raeburn 5971: if (ref($confhash{'authorquota'}) eq 'HASH') {
5972: foreach my $key (keys(%{$confhash{'authorquota'}})) {
5973: if (ref($domconfig{'quotas'}) eq 'HASH') {
5974: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5975: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
5976: $changes{'authorquota'}{$key} = 1;
5977: }
5978: } else {
5979: $changes{'authorquota'}{$key} = 1;
5980: }
5981: } else {
5982: $changes{'authorquota'}{$key} = 1;
5983: }
5984: }
5985: }
1.1 raeburn 5986: }
1.72 raeburn 5987:
1.160.6.5 raeburn 5988: if ($context eq 'requestauthor') {
5989: $domdefaults{'requestauthor'} = \%confhash;
5990: } else {
5991: foreach my $key (keys(%confhash)) {
5992: $domdefaults{$key} = $confhash{$key};
5993: }
1.72 raeburn 5994: }
1.160.6.5 raeburn 5995:
1.1 raeburn 5996: my %quotahash = (
1.86 raeburn 5997: $action => { %confhash }
1.1 raeburn 5998: );
5999: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6000: $dom);
6001: if ($putresult eq 'ok') {
6002: if (keys(%changes) > 0) {
1.72 raeburn 6003: my $cachetime = 24*60*60;
6004: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6005:
1.1 raeburn 6006: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 6007: unless (($context eq 'requestcourses') ||
6008: ($context eq 'requestauthor')) {
1.86 raeburn 6009: if (ref($changes{'defaultquota'}) eq 'HASH') {
6010: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6011: foreach my $type (@{$types},'default') {
6012: if (defined($changes{'defaultquota'}{$type})) {
6013: my $typetitle = $usertypes->{$type};
6014: if ($type eq 'default') {
6015: $typetitle = $othertitle;
6016: }
6017: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6018: }
6019: }
1.86 raeburn 6020: $resulttext .= '</ul></li>';
1.72 raeburn 6021: }
1.160.6.20 raeburn 6022: if (ref($changes{'authorquota'}) eq 'HASH') {
6023: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6024: foreach my $type (@{$types},'default') {
6025: if (defined($changes{'authorquota'}{$type})) {
6026: my $typetitle = $usertypes->{$type};
6027: if ($type eq 'default') {
6028: $typetitle = $othertitle;
6029: }
6030: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
6031: }
6032: }
6033: $resulttext .= '</ul></li>';
6034: }
1.72 raeburn 6035: }
1.80 raeburn 6036: my %newenv;
1.72 raeburn 6037: foreach my $item (@usertools) {
1.160.6.5 raeburn 6038: my (%haschgs,%inconf);
6039: if ($context eq 'requestauthor') {
6040: %haschgs = %changes;
6041: %inconf = %confhash;
6042: } else {
6043: if (ref($changes{$item}) eq 'HASH') {
6044: %haschgs = %{$changes{$item}};
6045: }
6046: if (ref($confhash{$item}) eq 'HASH') {
6047: %inconf = %{$confhash{$item}};
6048: }
6049: }
6050: if (keys(%haschgs) > 0) {
1.80 raeburn 6051: my $newacc =
6052: &Apache::lonnet::usertools_access($env{'user.name'},
6053: $env{'user.domain'},
1.86 raeburn 6054: $item,'reload',$context);
1.160.6.5 raeburn 6055: if (($context eq 'requestcourses') ||
6056: ($context eq 'requestauthor')) {
1.108 raeburn 6057: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6058: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6059: }
6060: } else {
6061: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6062: $newenv{'environment.availabletools.'.$item} = $newacc;
6063: }
1.80 raeburn 6064: }
1.160.6.5 raeburn 6065: unless ($context eq 'requestauthor') {
6066: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6067: }
1.72 raeburn 6068: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 6069: if ($haschgs{$type}) {
1.72 raeburn 6070: my $typetitle = $usertypes->{$type};
6071: if ($type eq 'default') {
6072: $typetitle = $othertitle;
6073: } elsif ($type eq '_LC_adv') {
6074: $typetitle = 'LON-CAPA Advanced Users';
6075: }
1.160.6.5 raeburn 6076: if ($inconf{$type}) {
1.101 raeburn 6077: if ($context eq 'requestcourses') {
6078: my $cond;
1.160.6.5 raeburn 6079: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6080: if ($1 eq '') {
6081: $cond = &mt('(Automatic processing of any request).');
6082: } else {
6083: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6084: }
6085: } else {
1.160.6.5 raeburn 6086: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6087: }
6088: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 6089: } elsif ($context eq 'requestauthor') {
6090: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6091: $titles{$inconf{$type}},$typetitle);
6092:
1.101 raeburn 6093: } else {
6094: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6095: }
1.72 raeburn 6096: } else {
1.104 raeburn 6097: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 6098: if ($inconf{$type} eq '0') {
1.104 raeburn 6099: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6100: } else {
6101: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6102: }
6103: } else {
6104: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6105: }
1.72 raeburn 6106: }
6107: }
1.26 raeburn 6108: }
1.160.6.5 raeburn 6109: unless ($context eq 'requestauthor') {
6110: $resulttext .= '</ul></li>';
6111: }
1.26 raeburn 6112: }
1.1 raeburn 6113: }
1.160.6.5 raeburn 6114: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6115: if (ref($changes{'notify'}) eq 'HASH') {
6116: if ($changes{'notify'}{'approval'}) {
6117: if (ref($confhash{'notify'}) eq 'HASH') {
6118: if ($confhash{'notify'}{'approval'}) {
6119: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6120: } else {
1.160.6.5 raeburn 6121: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6122: }
6123: }
6124: }
6125: }
6126: }
1.1 raeburn 6127: $resulttext .= '</ul>';
1.80 raeburn 6128: if (keys(%newenv)) {
6129: &Apache::lonnet::appenv(\%newenv);
6130: }
1.1 raeburn 6131: } else {
1.86 raeburn 6132: if ($context eq 'requestcourses') {
6133: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 6134: } elsif ($context eq 'requestauthor') {
6135: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6136: } else {
1.90 weissno 6137: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6138: }
1.1 raeburn 6139: }
6140: } else {
1.11 albertel 6141: $resulttext = '<span class="LC_error">'.
6142: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6143: }
1.3 raeburn 6144: return $resulttext;
1.1 raeburn 6145: }
6146:
1.3 raeburn 6147: sub modify_autoenroll {
1.160.6.24 raeburn 6148: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6149: my ($resulttext,%changes);
6150: my %currautoenroll;
6151: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6152: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6153: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6154: }
6155: }
6156: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6157: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6158: sender => 'Sender for notification messages',
6159: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6160: my @offon = ('off','on');
1.17 raeburn 6161: my $sender_uname = $env{'form.sender_uname'};
6162: my $sender_domain = $env{'form.sender_domain'};
6163: if ($sender_domain eq '') {
6164: $sender_uname = '';
6165: } elsif ($sender_uname eq '') {
6166: $sender_domain = '';
6167: }
1.129 raeburn 6168: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6169: my %autoenrollhash = (
1.129 raeburn 6170: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6171: 'sender_uname' => $sender_uname,
6172: 'sender_domain' => $sender_domain,
6173: 'co-owners' => $coowners,
1.1 raeburn 6174: }
6175: );
1.4 raeburn 6176: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6177: $dom);
1.1 raeburn 6178: if ($putresult eq 'ok') {
6179: if (exists($currautoenroll{'run'})) {
6180: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6181: $changes{'run'} = 1;
6182: }
6183: } elsif ($autorun) {
6184: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6185: $changes{'run'} = 1;
1.1 raeburn 6186: }
6187: }
1.17 raeburn 6188: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6189: $changes{'sender'} = 1;
6190: }
1.17 raeburn 6191: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6192: $changes{'sender'} = 1;
6193: }
1.129 raeburn 6194: if ($currautoenroll{'co-owners'} ne '') {
6195: if ($currautoenroll{'co-owners'} ne $coowners) {
6196: $changes{'coowners'} = 1;
6197: }
6198: } elsif ($coowners) {
6199: $changes{'coowners'} = 1;
6200: }
1.1 raeburn 6201: if (keys(%changes) > 0) {
6202: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6203: if ($changes{'run'}) {
1.1 raeburn 6204: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6205: }
6206: if ($changes{'sender'}) {
1.17 raeburn 6207: if ($sender_uname eq '' || $sender_domain eq '') {
6208: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6209: } else {
6210: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6211: }
1.1 raeburn 6212: }
1.129 raeburn 6213: if ($changes{'coowners'}) {
6214: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6215: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.24 raeburn 6216: $$lastactref = 'update';
1.129 raeburn 6217: }
1.1 raeburn 6218: $resulttext .= '</ul>';
6219: } else {
6220: $resulttext = &mt('No changes made to auto-enrollment settings');
6221: }
6222: } else {
1.11 albertel 6223: $resulttext = '<span class="LC_error">'.
6224: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6225: }
1.3 raeburn 6226: return $resulttext;
1.1 raeburn 6227: }
6228:
6229: sub modify_autoupdate {
1.3 raeburn 6230: my ($dom,%domconfig) = @_;
1.1 raeburn 6231: my ($resulttext,%currautoupdate,%fields,%changes);
6232: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6233: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6234: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6235: }
6236: }
6237: my @offon = ('off','on');
6238: my %title = &Apache::lonlocal::texthash (
6239: run => 'Auto-update:',
6240: classlists => 'Updates to user information in classlists?'
6241: );
1.44 raeburn 6242: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6243: my %fieldtitles = &Apache::lonlocal::texthash (
6244: id => 'Student/Employee ID',
1.20 raeburn 6245: permanentemail => 'E-mail address',
1.1 raeburn 6246: lastname => 'Last Name',
6247: firstname => 'First Name',
6248: middlename => 'Middle Name',
1.132 raeburn 6249: generation => 'Generation',
1.1 raeburn 6250: );
1.142 raeburn 6251: $othertitle = &mt('All users');
1.1 raeburn 6252: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6253: $othertitle = &mt('Other users');
1.1 raeburn 6254: }
6255: foreach my $key (keys(%env)) {
6256: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6257: my ($usertype,$item) = ($1,$2);
6258: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6259: if ($usertype eq 'default') {
6260: push(@{$fields{$1}},$2);
6261: } elsif (ref($types) eq 'ARRAY') {
6262: if (grep(/^\Q$usertype\E$/,@{$types})) {
6263: push(@{$fields{$1}},$2);
6264: }
6265: }
6266: }
1.1 raeburn 6267: }
6268: }
1.131 raeburn 6269: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6270: @lockablenames = sort(@lockablenames);
6271: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6272: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6273: if (@changed) {
6274: $changes{'lockablenames'} = 1;
6275: }
6276: } else {
6277: if (@lockablenames) {
6278: $changes{'lockablenames'} = 1;
6279: }
6280: }
1.1 raeburn 6281: my %updatehash = (
6282: autoupdate => { run => $env{'form.autoupdate_run'},
6283: classlists => $env{'form.classlists'},
6284: fields => {%fields},
1.131 raeburn 6285: lockablenames => \@lockablenames,
1.1 raeburn 6286: }
6287: );
6288: foreach my $key (keys(%currautoupdate)) {
6289: if (($key eq 'run') || ($key eq 'classlists')) {
6290: if (exists($updatehash{autoupdate}{$key})) {
6291: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6292: $changes{$key} = 1;
6293: }
6294: }
6295: } elsif ($key eq 'fields') {
6296: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6297: foreach my $item (@{$types},'default') {
1.1 raeburn 6298: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6299: my $change = 0;
6300: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6301: if (!exists($fields{$item})) {
6302: $change = 1;
1.132 raeburn 6303: last;
1.1 raeburn 6304: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6305: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6306: $change = 1;
1.132 raeburn 6307: last;
1.1 raeburn 6308: }
6309: }
6310: }
6311: if ($change) {
6312: push(@{$changes{$key}},$item);
6313: }
1.26 raeburn 6314: }
1.1 raeburn 6315: }
6316: }
1.131 raeburn 6317: } elsif ($key eq 'lockablenames') {
6318: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6319: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6320: if (@changed) {
6321: $changes{'lockablenames'} = 1;
6322: }
6323: } else {
6324: if (@lockablenames) {
6325: $changes{'lockablenames'} = 1;
6326: }
6327: }
6328: }
6329: }
6330: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6331: if (@lockablenames) {
6332: $changes{'lockablenames'} = 1;
1.1 raeburn 6333: }
6334: }
1.26 raeburn 6335: foreach my $item (@{$types},'default') {
6336: if (defined($fields{$item})) {
6337: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6338: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6339: my $change = 0;
6340: if (ref($fields{$item}) eq 'ARRAY') {
6341: foreach my $type (@{$fields{$item}}) {
6342: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6343: $change = 1;
6344: last;
6345: }
6346: }
6347: }
6348: if ($change) {
6349: push(@{$changes{'fields'}},$item);
6350: }
6351: } else {
1.26 raeburn 6352: push(@{$changes{'fields'}},$item);
6353: }
6354: } else {
6355: push(@{$changes{'fields'}},$item);
1.1 raeburn 6356: }
6357: }
6358: }
6359: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6360: $dom);
6361: if ($putresult eq 'ok') {
6362: if (keys(%changes) > 0) {
6363: $resulttext = &mt('Changes made:').'<ul>';
6364: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6365: if ($key eq 'lockablenames') {
6366: $resulttext .= '<li>';
6367: if (@lockablenames) {
6368: $usertypes->{'default'} = $othertitle;
6369: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6370: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6371: } else {
6372: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6373: }
6374: $resulttext .= '</li>';
6375: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6376: foreach my $item (@{$changes{$key}}) {
6377: my @newvalues;
6378: foreach my $type (@{$fields{$item}}) {
6379: push(@newvalues,$fieldtitles{$type});
6380: }
1.3 raeburn 6381: my $newvaluestr;
6382: if (@newvalues > 0) {
6383: $newvaluestr = join(', ',@newvalues);
6384: } else {
6385: $newvaluestr = &mt('none');
1.6 raeburn 6386: }
1.1 raeburn 6387: if ($item eq 'default') {
1.26 raeburn 6388: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6389: } else {
1.26 raeburn 6390: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6391: }
6392: }
6393: } else {
6394: my $newvalue;
6395: if ($key eq 'run') {
6396: $newvalue = $offon[$env{'form.autoupdate_run'}];
6397: } else {
6398: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6399: }
1.1 raeburn 6400: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6401: }
6402: }
6403: $resulttext .= '</ul>';
6404: } else {
1.3 raeburn 6405: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6406: }
6407: } else {
1.11 albertel 6408: $resulttext = '<span class="LC_error">'.
6409: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6410: }
1.3 raeburn 6411: return $resulttext;
1.1 raeburn 6412: }
6413:
1.125 raeburn 6414: sub modify_autocreate {
6415: my ($dom,%domconfig) = @_;
6416: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6417: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6418: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6419: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6420: }
6421: }
6422: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6423: req => 'Auto-creation of validated requests for official courses',
6424: xmldc => 'Identity of course creator of courses from XML files',
6425: );
6426: my @types = ('xml','req');
6427: foreach my $item (@types) {
6428: $newvals{$item} = $env{'form.autocreate_'.$item};
6429: $newvals{$item} =~ s/\D//g;
6430: $newvals{$item} = 0 if ($newvals{$item} eq '');
6431: }
6432: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6433: my %domcoords = &get_active_dcs($dom);
6434: unless (exists($domcoords{$newvals{'xmldc'}})) {
6435: $newvals{'xmldc'} = '';
6436: }
6437: %autocreatehash = (
6438: autocreate => { xml => $newvals{'xml'},
6439: req => $newvals{'req'},
6440: }
6441: );
6442: if ($newvals{'xmldc'} ne '') {
6443: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6444: }
6445: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6446: $dom);
6447: if ($putresult eq 'ok') {
6448: my @items = @types;
6449: if ($newvals{'xml'}) {
6450: push(@items,'xmldc');
6451: }
6452: foreach my $item (@items) {
6453: if (exists($currautocreate{$item})) {
6454: if ($currautocreate{$item} ne $newvals{$item}) {
6455: $changes{$item} = 1;
6456: }
6457: } elsif ($newvals{$item}) {
6458: $changes{$item} = 1;
6459: }
6460: }
6461: if (keys(%changes) > 0) {
6462: my @offon = ('off','on');
6463: $resulttext = &mt('Changes made:').'<ul>';
6464: foreach my $item (@types) {
6465: if ($changes{$item}) {
6466: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6467: $resulttext .= '<li>'.
6468: &mt("$title{$item} set to [_1]$newtxt [_2]",
6469: '<b>','</b>').
6470: '</li>';
1.125 raeburn 6471: }
6472: }
6473: if ($changes{'xmldc'}) {
6474: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6475: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6476: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6477: }
6478: $resulttext .= '</ul>';
6479: } else {
6480: $resulttext = &mt('No changes made to auto-creation settings');
6481: }
6482: } else {
6483: $resulttext = '<span class="LC_error">'.
6484: &mt('An error occurred: [_1]',$putresult).'</span>';
6485: }
6486: return $resulttext;
6487: }
6488:
1.23 raeburn 6489: sub modify_directorysrch {
6490: my ($dom,%domconfig) = @_;
6491: my ($resulttext,%changes);
6492: my %currdirsrch;
6493: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6494: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6495: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6496: }
6497: }
6498: my %title = ( available => 'Directory search available',
1.24 raeburn 6499: localonly => 'Other domains can search',
1.23 raeburn 6500: searchby => 'Search types',
6501: searchtypes => 'Search latitude');
6502: my @offon = ('off','on');
1.24 raeburn 6503: my @otherdoms = ('Yes','No');
1.23 raeburn 6504:
1.25 raeburn 6505: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6506: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6507: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6508:
1.44 raeburn 6509: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6510: if (keys(%{$usertypes}) == 0) {
6511: @cansearch = ('default');
6512: } else {
6513: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6514: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6515: if (!grep(/^\Q$type\E$/,@cansearch)) {
6516: push(@{$changes{'cansearch'}},$type);
6517: }
1.23 raeburn 6518: }
1.26 raeburn 6519: foreach my $type (@cansearch) {
6520: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6521: push(@{$changes{'cansearch'}},$type);
6522: }
1.23 raeburn 6523: }
1.26 raeburn 6524: } else {
6525: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6526: }
6527: }
6528:
6529: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6530: foreach my $by (@{$currdirsrch{'searchby'}}) {
6531: if (!grep(/^\Q$by\E$/,@searchby)) {
6532: push(@{$changes{'searchby'}},$by);
6533: }
6534: }
6535: foreach my $by (@searchby) {
6536: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6537: push(@{$changes{'searchby'}},$by);
6538: }
6539: }
6540: } else {
6541: push(@{$changes{'searchby'}},@searchby);
6542: }
1.25 raeburn 6543:
6544: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6545: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6546: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6547: push(@{$changes{'searchtypes'}},$type);
6548: }
6549: }
6550: foreach my $type (@searchtypes) {
6551: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6552: push(@{$changes{'searchtypes'}},$type);
6553: }
6554: }
6555: } else {
6556: if (exists($currdirsrch{'searchtypes'})) {
6557: foreach my $type (@searchtypes) {
6558: if ($type ne $currdirsrch{'searchtypes'}) {
6559: push(@{$changes{'searchtypes'}},$type);
6560: }
6561: }
6562: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6563: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6564: }
6565: } else {
6566: push(@{$changes{'searchtypes'}},@searchtypes);
6567: }
6568: }
6569:
1.23 raeburn 6570: my %dirsrch_hash = (
6571: directorysrch => { available => $env{'form.dirsrch_available'},
6572: cansearch => \@cansearch,
1.24 raeburn 6573: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6574: searchby => \@searchby,
1.25 raeburn 6575: searchtypes => \@searchtypes,
1.23 raeburn 6576: }
6577: );
6578: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6579: $dom);
6580: if ($putresult eq 'ok') {
6581: if (exists($currdirsrch{'available'})) {
6582: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6583: $changes{'available'} = 1;
6584: }
6585: } else {
6586: if ($env{'form.dirsrch_available'} eq '1') {
6587: $changes{'available'} = 1;
6588: }
6589: }
1.24 raeburn 6590: if (exists($currdirsrch{'localonly'})) {
6591: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6592: $changes{'localonly'} = 1;
6593: }
6594: } else {
6595: if ($env{'form.dirsrch_localonly'} eq '1') {
6596: $changes{'localonly'} = 1;
6597: }
6598: }
1.23 raeburn 6599: if (keys(%changes) > 0) {
6600: $resulttext = &mt('Changes made:').'<ul>';
6601: if ($changes{'available'}) {
6602: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6603: }
1.24 raeburn 6604: if ($changes{'localonly'}) {
6605: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6606: }
6607:
1.23 raeburn 6608: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6609: my $chgtext;
1.26 raeburn 6610: if (ref($usertypes) eq 'HASH') {
6611: if (keys(%{$usertypes}) > 0) {
6612: foreach my $type (@{$types}) {
6613: if (grep(/^\Q$type\E$/,@cansearch)) {
6614: $chgtext .= $usertypes->{$type}.'; ';
6615: }
6616: }
6617: if (grep(/^default$/,@cansearch)) {
6618: $chgtext .= $othertitle;
6619: } else {
6620: $chgtext =~ s/\; $//;
6621: }
1.160.6.13 raeburn 6622: $resulttext .=
6623: '<li>'.
6624: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6625: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6626: '</li>';
1.23 raeburn 6627: }
6628: }
6629: }
6630: if (ref($changes{'searchby'}) eq 'ARRAY') {
6631: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6632: my $chgtext;
6633: foreach my $type (@{$titleorder}) {
6634: if (grep(/^\Q$type\E$/,@searchby)) {
6635: if (defined($searchtitles->{$type})) {
6636: $chgtext .= $searchtitles->{$type}.'; ';
6637: }
6638: }
6639: }
6640: $chgtext =~ s/\; $//;
6641: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6642: }
1.25 raeburn 6643: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6644: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6645: my $chgtext;
6646: foreach my $type (@{$srchtypeorder}) {
6647: if (grep(/^\Q$type\E$/,@searchtypes)) {
6648: if (defined($srchtypes_desc->{$type})) {
6649: $chgtext .= $srchtypes_desc->{$type}.'; ';
6650: }
6651: }
6652: }
6653: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 6654: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6655: }
6656: $resulttext .= '</ul>';
6657: } else {
6658: $resulttext = &mt('No changes made to institution directory search settings');
6659: }
6660: } else {
6661: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6662: &mt('An error occurred: [_1]',$putresult).'</span>';
6663: }
6664: return $resulttext;
6665: }
6666:
1.28 raeburn 6667: sub modify_contacts {
1.160.6.24 raeburn 6668: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 6669: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6670: if (ref($domconfig{'contacts'}) eq 'HASH') {
6671: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6672: $currsetting{$key} = $domconfig{'contacts'}{$key};
6673: }
6674: }
1.134 raeburn 6675: my (%others,%to,%bcc);
1.28 raeburn 6676: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6677: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 6678: 'requestsmail','updatesmail','idconflictsmail');
6679: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 6680: foreach my $type (@mailings) {
6681: @{$newsetting{$type}} =
6682: &Apache::loncommon::get_env_multiple('form.'.$type);
6683: foreach my $item (@contacts) {
6684: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6685: $contacts_hash{contacts}{$type}{$item} = 1;
6686: } else {
6687: $contacts_hash{contacts}{$type}{$item} = 0;
6688: }
6689: }
6690: $others{$type} = $env{'form.'.$type.'_others'};
6691: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6692: if ($type eq 'helpdeskmail') {
6693: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6694: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6695: }
1.28 raeburn 6696: }
6697: foreach my $item (@contacts) {
6698: $to{$item} = $env{'form.'.$item};
6699: $contacts_hash{'contacts'}{$item} = $to{$item};
6700: }
1.160.6.23 raeburn 6701: foreach my $item (@toggles) {
6702: if ($env{'form.'.$item} =~ /^(0|1)$/) {
6703: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
6704: }
6705: }
1.28 raeburn 6706: if (keys(%currsetting) > 0) {
6707: foreach my $item (@contacts) {
6708: if ($to{$item} ne $currsetting{$item}) {
6709: $changes{$item} = 1;
6710: }
6711: }
6712: foreach my $type (@mailings) {
6713: foreach my $item (@contacts) {
6714: if (ref($currsetting{$type}) eq 'HASH') {
6715: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6716: push(@{$changes{$type}},$item);
6717: }
6718: } else {
6719: push(@{$changes{$type}},@{$newsetting{$type}});
6720: }
6721: }
6722: if ($others{$type} ne $currsetting{$type}{'others'}) {
6723: push(@{$changes{$type}},'others');
6724: }
1.134 raeburn 6725: if ($type eq 'helpdeskmail') {
6726: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6727: push(@{$changes{$type}},'bcc');
6728: }
6729: }
1.28 raeburn 6730: }
6731: } else {
6732: my %default;
6733: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6734: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6735: $default{'errormail'} = 'adminemail';
6736: $default{'packagesmail'} = 'adminemail';
6737: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6738: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6739: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 6740: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6741: foreach my $item (@contacts) {
6742: if ($to{$item} ne $default{$item}) {
6743: $changes{$item} = 1;
1.160.6.23 raeburn 6744: }
1.28 raeburn 6745: }
6746: foreach my $type (@mailings) {
6747: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6748:
6749: push(@{$changes{$type}},@{$newsetting{$type}});
6750: }
6751: if ($others{$type} ne '') {
6752: push(@{$changes{$type}},'others');
1.134 raeburn 6753: }
6754: if ($type eq 'helpdeskmail') {
6755: if ($bcc{$type} ne '') {
6756: push(@{$changes{$type}},'bcc');
6757: }
6758: }
1.28 raeburn 6759: }
6760: }
1.160.6.23 raeburn 6761: foreach my $item (@toggles) {
6762: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
6763: $changes{$item} = 1;
6764: } elsif ((!$env{'form.'.$item}) &&
6765: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
6766: $changes{$item} = 1;
6767: }
6768: }
1.28 raeburn 6769: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6770: $dom);
6771: if ($putresult eq 'ok') {
6772: if (keys(%changes) > 0) {
1.160.6.24 raeburn 6773: &Apache::loncommon::devalidate_domconfig_cache($dom);
6774: $$lastactref = 'update';
1.28 raeburn 6775: my ($titles,$short_titles) = &contact_titles();
6776: $resulttext = &mt('Changes made:').'<ul>';
6777: foreach my $item (@contacts) {
6778: if ($changes{$item}) {
6779: $resulttext .= '<li>'.$titles->{$item}.
6780: &mt(' set to: ').
6781: '<span class="LC_cusr_emph">'.
6782: $to{$item}.'</span></li>';
6783: }
6784: }
6785: foreach my $type (@mailings) {
6786: if (ref($changes{$type}) eq 'ARRAY') {
6787: $resulttext .= '<li>'.$titles->{$type}.': ';
6788: my @text;
6789: foreach my $item (@{$newsetting{$type}}) {
6790: push(@text,$short_titles->{$item});
6791: }
6792: if ($others{$type} ne '') {
6793: push(@text,$others{$type});
6794: }
6795: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6796: join(', ',@text).'</span>';
6797: if ($type eq 'helpdeskmail') {
6798: if ($bcc{$type} ne '') {
6799: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6800: }
6801: }
6802: $resulttext .= '</li>';
1.28 raeburn 6803: }
6804: }
1.160.6.23 raeburn 6805: my @offon = ('off','on');
6806: if ($changes{'reporterrors'}) {
6807: $resulttext .= '<li>'.
6808: &mt('E-mail error reports to [_1] set to "'.
6809: $offon[$env{'form.reporterrors'}].'".',
6810: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
6811: &mt('LON-CAPA core group - MSU'),600,500)).
6812: '</li>';
6813: }
6814: if ($changes{'reportupdates'}) {
6815: $resulttext .= '<li>'.
6816: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
6817: $offon[$env{'form.reportupdates'}].'".',
6818: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
6819: &mt('LON-CAPA core group - MSU'),600,500)).
6820: '</li>';
6821: }
1.28 raeburn 6822: $resulttext .= '</ul>';
6823: } else {
1.34 raeburn 6824: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6825: }
6826: } else {
6827: $resulttext = '<span class="LC_error">'.
6828: &mt('An error occurred: [_1].',$putresult).'</span>';
6829: }
6830: return $resulttext;
6831: }
6832:
6833: sub modify_usercreation {
1.27 raeburn 6834: my ($dom,%domconfig) = @_;
1.34 raeburn 6835: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6836: my $warningmsg;
1.27 raeburn 6837: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6838: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6839: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6840: }
6841: }
6842: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6843: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6844: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6845: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6846: foreach my $item(@contexts) {
1.45 raeburn 6847: if ($item eq 'selfcreate') {
1.50 raeburn 6848: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6849: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6850: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6851: if (ref($cancreate{$item}) eq 'ARRAY') {
6852: if (grep(/^login$/,@{$cancreate{$item}})) {
6853: $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.');
6854: }
1.43 raeburn 6855: }
6856: }
1.50 raeburn 6857: } else {
6858: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6859: }
1.34 raeburn 6860: }
1.93 raeburn 6861: my ($othertitle,$usertypes,$types) =
6862: &Apache::loncommon::sorted_inst_types($dom);
6863: if (ref($types) eq 'ARRAY') {
6864: if (@{$types} > 0) {
6865: @{$cancreate{'statustocreate'}} =
6866: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6867: } else {
6868: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6869: }
6870: push(@contexts,'statustocreate');
6871: }
1.160.6.5 raeburn 6872: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6873: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6874: foreach my $item (@contexts) {
1.93 raeburn 6875: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6876: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6877: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6878: if (ref($cancreate{$item}) eq 'ARRAY') {
6879: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6880: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6881: push(@{$changes{'cancreate'}},$item);
6882: }
1.50 raeburn 6883: }
6884: }
6885: }
6886: } else {
6887: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6888: if (@{$cancreate{$item}} > 0) {
6889: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6890: push(@{$changes{'cancreate'}},$item);
6891: }
6892: }
6893: } else {
6894: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6895: if (@{$cancreate{$item}} < 3) {
6896: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6897: push(@{$changes{'cancreate'}},$item);
6898: }
6899: }
6900: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6901: if (@{$cancreate{$item}} > 0) {
6902: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6903: push(@{$changes{'cancreate'}},$item);
6904: }
6905: }
6906: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6907: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6908: push(@{$changes{'cancreate'}},$item);
6909: }
6910: }
6911: }
6912: }
6913: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6914: foreach my $type (@{$cancreate{$item}}) {
6915: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6916: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6917: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6918: push(@{$changes{'cancreate'}},$item);
6919: }
6920: }
6921: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6922: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6923: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6924: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6925: push(@{$changes{'cancreate'}},$item);
6926: }
6927: }
6928: }
6929: }
6930: }
6931: } else {
6932: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6933: push(@{$changes{'cancreate'}},$item);
6934: }
6935: }
1.27 raeburn 6936: }
1.34 raeburn 6937: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6938: foreach my $item (@contexts) {
1.43 raeburn 6939: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6940: if ($cancreate{$item} ne 'any') {
6941: push(@{$changes{'cancreate'}},$item);
6942: }
6943: } else {
6944: if ($cancreate{$item} ne 'none') {
6945: push(@{$changes{'cancreate'}},$item);
6946: }
1.27 raeburn 6947: }
6948: }
6949: } else {
1.43 raeburn 6950: foreach my $item (@contexts) {
1.34 raeburn 6951: push(@{$changes{'cancreate'}},$item);
6952: }
1.27 raeburn 6953: }
1.34 raeburn 6954:
1.27 raeburn 6955: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6956: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6957: if (!grep(/^\Q$type\E$/,@username_rule)) {
6958: push(@{$changes{'username_rule'}},$type);
6959: }
6960: }
6961: foreach my $type (@username_rule) {
6962: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6963: push(@{$changes{'username_rule'}},$type);
6964: }
6965: }
6966: } else {
6967: push(@{$changes{'username_rule'}},@username_rule);
6968: }
6969:
1.32 raeburn 6970: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6971: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6972: if (!grep(/^\Q$type\E$/,@id_rule)) {
6973: push(@{$changes{'id_rule'}},$type);
6974: }
6975: }
6976: foreach my $type (@id_rule) {
6977: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6978: push(@{$changes{'id_rule'}},$type);
6979: }
6980: }
6981: } else {
6982: push(@{$changes{'id_rule'}},@id_rule);
6983: }
6984:
1.43 raeburn 6985: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6986: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6987: if (!grep(/^\Q$type\E$/,@email_rule)) {
6988: push(@{$changes{'email_rule'}},$type);
6989: }
6990: }
6991: foreach my $type (@email_rule) {
6992: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6993: push(@{$changes{'email_rule'}},$type);
6994: }
6995: }
6996: } else {
6997: push(@{$changes{'email_rule'}},@email_rule);
6998: }
6999:
7000: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7001: my @authtypes = ('int','krb4','krb5','loc');
7002: my %authhash;
1.43 raeburn 7003: foreach my $item (@authen_contexts) {
1.28 raeburn 7004: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7005: foreach my $auth (@authtypes) {
7006: if (grep(/^\Q$auth\E$/,@authallowed)) {
7007: $authhash{$item}{$auth} = 1;
7008: } else {
7009: $authhash{$item}{$auth} = 0;
7010: }
7011: }
7012: }
7013: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7014: foreach my $item (@authen_contexts) {
1.28 raeburn 7015: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7016: foreach my $auth (@authtypes) {
7017: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7018: push(@{$changes{'authtypes'}},$item);
7019: last;
7020: }
7021: }
7022: }
7023: }
7024: } else {
1.43 raeburn 7025: foreach my $item (@authen_contexts) {
1.28 raeburn 7026: push(@{$changes{'authtypes'}},$item);
7027: }
7028: }
7029:
1.27 raeburn 7030: my %usercreation_hash = (
1.28 raeburn 7031: usercreation => {
1.34 raeburn 7032: cancreate => \%cancreate,
1.27 raeburn 7033: username_rule => \@username_rule,
1.32 raeburn 7034: id_rule => \@id_rule,
1.43 raeburn 7035: email_rule => \@email_rule,
1.32 raeburn 7036: authtypes => \%authhash,
1.27 raeburn 7037: }
7038: );
7039:
7040: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7041: $dom);
1.50 raeburn 7042:
7043: my %selfcreatetypes = (
7044: sso => 'users authenticated by institutional single sign on',
7045: login => 'users authenticated by institutional log-in',
7046: email => 'users who provide a valid e-mail address for use as the username',
7047: );
1.27 raeburn 7048: if ($putresult eq 'ok') {
7049: if (keys(%changes) > 0) {
7050: $resulttext = &mt('Changes made:').'<ul>';
7051: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7052: my %lt = &usercreation_types();
7053: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7054: my $chgtext;
1.160.6.5 raeburn 7055: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7056: $chgtext = $lt{$type}.', ';
7057: }
1.45 raeburn 7058: if ($type eq 'selfcreate') {
1.50 raeburn 7059: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7060: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7061: } else {
1.100 raeburn 7062: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7063: foreach my $case (@{$cancreate{$type}}) {
7064: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7065: }
7066: $chgtext .= '</ul>';
1.100 raeburn 7067: if (ref($cancreate{$type}) eq 'ARRAY') {
7068: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7069: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7070: if (@{$cancreate{'statustocreate'}} == 0) {
7071: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7072: }
7073: }
7074: }
7075: }
1.43 raeburn 7076: }
1.93 raeburn 7077: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7078: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7079: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7080: if (@{$cancreate{'selfcreate'}} > 0) {
7081: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7082:
7083: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7084: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7085: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7086: }
1.96 raeburn 7087: } elsif (ref($usertypes) eq 'HASH') {
7088: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7089: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7090: } else {
7091: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7092: }
7093: $chgtext .= '<ul>';
7094: foreach my $case (@{$cancreate{$type}}) {
7095: if ($case eq 'default') {
7096: $chgtext .= '<li>'.$othertitle.'</li>';
7097: } else {
7098: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7099: }
7100: }
1.100 raeburn 7101: $chgtext .= '</ul>';
7102: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7103: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7104: }
7105: }
7106: } else {
7107: if (@{$cancreate{$type}} == 0) {
7108: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7109: } else {
7110: $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 7111: }
7112: }
7113: }
1.160.6.5 raeburn 7114: } elsif ($type eq 'captcha') {
7115: if ($cancreate{$type} eq 'notused') {
7116: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7117: } else {
7118: my %captchas = &captcha_phrases();
7119: if ($captchas{$cancreate{$type}}) {
7120: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7121: } else {
7122: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7123: }
7124: }
7125: } elsif ($type eq 'recaptchakeys') {
7126: my ($privkey,$pubkey);
7127: if (ref($cancreate{$type}) eq 'HASH') {
7128: $pubkey = $cancreate{$type}{'public'};
7129: $privkey = $cancreate{$type}{'private'};
7130: }
7131: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7132: if (!$pubkey) {
7133: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7134: } else {
7135: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7136: }
7137: if (!$privkey) {
7138: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7139: } else {
7140: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7141: }
7142: $chgtext .= '</ul>';
1.43 raeburn 7143: } else {
7144: if ($cancreate{$type} eq 'none') {
7145: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7146: } elsif ($cancreate{$type} eq 'any') {
7147: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7148: } elsif ($cancreate{$type} eq 'official') {
7149: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7150: } elsif ($cancreate{$type} eq 'unofficial') {
7151: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7152: }
1.34 raeburn 7153: }
7154: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7155: }
7156: }
7157: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7158: my ($rules,$ruleorder) =
7159: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7160: my $chgtext = '<ul>';
7161: foreach my $type (@username_rule) {
7162: if (ref($rules->{$type}) eq 'HASH') {
7163: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7164: }
7165: }
7166: $chgtext .= '</ul>';
7167: if (@username_rule > 0) {
7168: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7169: } else {
1.28 raeburn 7170: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7171: }
7172: }
1.32 raeburn 7173: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7174: my ($idrules,$idruleorder) =
7175: &Apache::lonnet::inst_userrules($dom,'id');
7176: my $chgtext = '<ul>';
7177: foreach my $type (@id_rule) {
7178: if (ref($idrules->{$type}) eq 'HASH') {
7179: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7180: }
7181: }
7182: $chgtext .= '</ul>';
7183: if (@id_rule > 0) {
7184: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7185: } else {
7186: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7187: }
7188: }
1.43 raeburn 7189: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7190: my ($emailrules,$emailruleorder) =
7191: &Apache::lonnet::inst_userrules($dom,'email');
7192: my $chgtext = '<ul>';
7193: foreach my $type (@email_rule) {
7194: if (ref($emailrules->{$type}) eq 'HASH') {
7195: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7196: }
7197: }
7198: $chgtext .= '</ul>';
7199: if (@email_rule > 0) {
7200: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7201: } else {
7202: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7203: }
7204: }
7205:
1.28 raeburn 7206: my %authname = &authtype_names();
7207: my %context_title = &context_names();
7208: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7209: my $chgtext = '<ul>';
7210: foreach my $type (@{$changes{'authtypes'}}) {
7211: my @allowed;
7212: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7213: foreach my $auth (@authtypes) {
7214: if ($authhash{$type}{$auth}) {
7215: push(@allowed,$authname{$auth});
7216: }
7217: }
1.43 raeburn 7218: if (@allowed > 0) {
7219: $chgtext .= join(', ',@allowed).'</li>';
7220: } else {
7221: $chgtext .= &mt('none').'</li>';
7222: }
1.28 raeburn 7223: }
7224: $chgtext .= '</ul>';
7225: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7226: $resulttext .= '</li>';
7227: }
1.27 raeburn 7228: $resulttext .= '</ul>';
7229: } else {
1.28 raeburn 7230: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7231: }
7232: } else {
7233: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7234: &mt('An error occurred: [_1]',$putresult).'</span>';
7235: }
1.43 raeburn 7236: if ($warningmsg ne '') {
7237: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7238: }
1.23 raeburn 7239: return $resulttext;
7240: }
7241:
1.160.6.5 raeburn 7242: sub process_captcha {
7243: my ($container,$changes,$newsettings,$current) = @_;
7244: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7245: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7246: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7247: $newsettings->{'captcha'} = 'original';
7248: }
7249: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7250: if ($container eq 'cancreate') {
7251: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7252: push(@{$changes->{'cancreate'}},'captcha');
7253: } elsif (!defined($changes->{'cancreate'})) {
7254: $changes->{'cancreate'} = ['captcha'];
7255: }
7256: } else {
7257: $changes->{'captcha'} = 1;
7258: }
7259: }
7260: my ($newpub,$newpriv,$currpub,$currpriv);
7261: if ($newsettings->{'captcha'} eq 'recaptcha') {
7262: $newpub = $env{'form.'.$container.'_recaptchapub'};
7263: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7264: $newpub =~ s/\W//g;
7265: $newpriv =~ s/\W//g;
7266: $newsettings->{'recaptchakeys'} = {
7267: public => $newpub,
7268: private => $newpriv,
7269: };
7270: }
7271: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7272: $currpub = $current->{'recaptchakeys'}{'public'};
7273: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7274: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7275: $newsettings->{'recaptchakeys'} = {
7276: public => '',
7277: private => '',
7278: }
7279: }
1.160.6.5 raeburn 7280: }
7281: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7282: if ($container eq 'cancreate') {
7283: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7284: push(@{$changes->{'cancreate'}},'recaptchakeys');
7285: } elsif (!defined($changes->{'cancreate'})) {
7286: $changes->{'cancreate'} = ['recaptchakeys'];
7287: }
7288: } else {
7289: $changes->{'recaptchakeys'} = 1;
7290: }
7291: }
7292: return;
7293: }
7294:
1.33 raeburn 7295: sub modify_usermodification {
7296: my ($dom,%domconfig) = @_;
7297: my ($resulttext,%curr_usermodification,%changes);
7298: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7299: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7300: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7301: }
7302: }
1.63 raeburn 7303: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7304: my %context_title = (
7305: author => 'In author context',
7306: course => 'In course context',
1.63 raeburn 7307: selfcreate => 'When self creating account',
1.33 raeburn 7308: );
7309: my @fields = ('lastname','firstname','middlename','generation',
7310: 'permanentemail','id');
7311: my %roles = (
7312: author => ['ca','aa'],
7313: course => ['st','ep','ta','in','cr'],
7314: );
1.63 raeburn 7315: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7316: if (ref($types) eq 'ARRAY') {
7317: push(@{$types},'default');
7318: $usertypes->{'default'} = $othertitle;
7319: }
7320: $roles{'selfcreate'} = $types;
1.33 raeburn 7321: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7322: my %modifyhash;
7323: foreach my $context (@contexts) {
7324: foreach my $role (@{$roles{$context}}) {
7325: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7326: foreach my $item (@fields) {
7327: if (grep(/^\Q$item\E$/,@modifiable)) {
7328: $modifyhash{$context}{$role}{$item} = 1;
7329: } else {
7330: $modifyhash{$context}{$role}{$item} = 0;
7331: }
7332: }
7333: }
7334: if (ref($curr_usermodification{$context}) eq 'HASH') {
7335: foreach my $role (@{$roles{$context}}) {
7336: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7337: foreach my $field (@fields) {
7338: if ($modifyhash{$context}{$role}{$field} ne
7339: $curr_usermodification{$context}{$role}{$field}) {
7340: push(@{$changes{$context}},$role);
7341: last;
7342: }
7343: }
7344: }
7345: }
7346: } else {
7347: foreach my $context (@contexts) {
7348: foreach my $role (@{$roles{$context}}) {
7349: push(@{$changes{$context}},$role);
7350: }
7351: }
7352: }
7353: }
7354: my %usermodification_hash = (
7355: usermodification => \%modifyhash,
7356: );
7357: my $putresult = &Apache::lonnet::put_dom('configuration',
7358: \%usermodification_hash,$dom);
7359: if ($putresult eq 'ok') {
7360: if (keys(%changes) > 0) {
7361: $resulttext = &mt('Changes made: ').'<ul>';
7362: foreach my $context (@contexts) {
7363: if (ref($changes{$context}) eq 'ARRAY') {
7364: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7365: if (ref($changes{$context}) eq 'ARRAY') {
7366: foreach my $role (@{$changes{$context}}) {
7367: my $rolename;
1.63 raeburn 7368: if ($context eq 'selfcreate') {
7369: $rolename = $role;
7370: if (ref($usertypes) eq 'HASH') {
7371: if ($usertypes->{$role} ne '') {
7372: $rolename = $usertypes->{$role};
7373: }
7374: }
1.33 raeburn 7375: } else {
1.63 raeburn 7376: if ($role eq 'cr') {
7377: $rolename = &mt('Custom');
7378: } else {
7379: $rolename = &Apache::lonnet::plaintext($role);
7380: }
1.33 raeburn 7381: }
7382: my @modifiable;
1.63 raeburn 7383: if ($context eq 'selfcreate') {
1.126 bisitz 7384: $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 7385: } else {
7386: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7387: }
1.33 raeburn 7388: foreach my $field (@fields) {
7389: if ($modifyhash{$context}{$role}{$field}) {
7390: push(@modifiable,$fieldtitles{$field});
7391: }
7392: }
7393: if (@modifiable > 0) {
7394: $resulttext .= join(', ',@modifiable);
7395: } else {
7396: $resulttext .= &mt('none');
7397: }
7398: $resulttext .= '</li>';
7399: }
7400: $resulttext .= '</ul></li>';
7401: }
7402: }
7403: }
7404: $resulttext .= '</ul>';
7405: } else {
7406: $resulttext = &mt('No changes made to user modification settings');
7407: }
7408: } else {
7409: $resulttext = '<span class="LC_error">'.
7410: &mt('An error occurred: [_1]',$putresult).'</span>';
7411: }
7412: return $resulttext;
7413: }
7414:
1.43 raeburn 7415: sub modify_defaults {
1.160.6.23 raeburn 7416: my ($dom,$r,%domconfig) = @_;
1.43 raeburn 7417: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7418: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7419: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7420: my @authtypes = ('internal','krb4','krb5','localauth');
7421: foreach my $item (@items) {
7422: $newvalues{$item} = $env{'form.'.$item};
7423: if ($item eq 'auth_def') {
7424: if ($newvalues{$item} ne '') {
7425: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7426: push(@errors,$item);
7427: }
7428: }
7429: } elsif ($item eq 'lang_def') {
7430: if ($newvalues{$item} ne '') {
7431: if ($newvalues{$item} =~ /^(\w+)/) {
7432: my $langcode = $1;
1.103 raeburn 7433: if ($langcode ne 'x_chef') {
7434: if (code2language($langcode) eq '') {
7435: push(@errors,$item);
7436: }
1.43 raeburn 7437: }
7438: } else {
7439: push(@errors,$item);
7440: }
7441: }
1.54 raeburn 7442: } elsif ($item eq 'timezone_def') {
7443: if ($newvalues{$item} ne '') {
1.62 raeburn 7444: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7445: push(@errors,$item);
7446: }
7447: }
1.68 raeburn 7448: } elsif ($item eq 'datelocale_def') {
7449: if ($newvalues{$item} ne '') {
7450: my @datelocale_ids = DateTime::Locale->ids();
7451: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7452: push(@errors,$item);
7453: }
7454: }
1.141 raeburn 7455: } elsif ($item eq 'portal_def') {
7456: if ($newvalues{$item} ne '') {
7457: 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])\/?$/) {
7458: push(@errors,$item);
7459: }
7460: }
1.43 raeburn 7461: }
7462: if (grep(/^\Q$item\E$/,@errors)) {
7463: $newvalues{$item} = $domdefaults{$item};
7464: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7465: $changes{$item} = 1;
7466: }
1.72 raeburn 7467: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7468: }
7469: my %defaults_hash = (
1.72 raeburn 7470: defaults => \%newvalues,
7471: );
1.43 raeburn 7472: my $title = &defaults_titles();
7473: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7474: $dom);
7475: if ($putresult eq 'ok') {
7476: if (keys(%changes) > 0) {
7477: $resulttext = &mt('Changes made:').'<ul>';
7478: my $version = $r->dir_config('lonVersion');
7479: 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";
7480: foreach my $item (sort(keys(%changes))) {
7481: my $value = $env{'form.'.$item};
7482: if ($value eq '') {
7483: $value = &mt('none');
7484: } elsif ($item eq 'auth_def') {
7485: my %authnames = &authtype_names();
7486: my %shortauth = (
7487: internal => 'int',
7488: krb4 => 'krb4',
7489: krb5 => 'krb5',
7490: localauth => 'loc',
7491: );
7492: $value = $authnames{$shortauth{$value}};
7493: }
7494: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7495: $mailmsgtext .= "$title->{$item} set to $value\n";
7496: }
7497: $resulttext .= '</ul>';
7498: $mailmsgtext .= "\n";
7499: my $cachetime = 24*60*60;
1.72 raeburn 7500: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7501: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 7502: my $notify = 1;
7503: if (ref($domconfig{'contacts'}) eq 'HASH') {
7504: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
7505: $notify = 0;
7506: }
7507: }
7508: if ($notify) {
7509: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
7510: "LON-CAPA Domain Settings Change - $dom",
7511: $mailmsgtext);
7512: }
1.54 raeburn 7513: }
1.43 raeburn 7514: } else {
1.54 raeburn 7515: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7516: }
7517: } else {
7518: $resulttext = '<span class="LC_error">'.
7519: &mt('An error occurred: [_1]',$putresult).'</span>';
7520: }
7521: if (@errors > 0) {
7522: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7523: foreach my $item (@errors) {
7524: $resulttext .= ' "'.$title->{$item}.'",';
7525: }
7526: $resulttext =~ s/,$//;
7527: }
7528: return $resulttext;
7529: }
7530:
1.46 raeburn 7531: sub modify_scantron {
1.160.6.24 raeburn 7532: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 7533: my ($resulttext,%confhash,%changes,$errors);
7534: my $custom = 'custom.tab';
7535: my $default = 'default.tab';
7536: my $servadm = $r->dir_config('lonAdmEMail');
7537: my ($configuserok,$author_ok,$switchserver) =
7538: &config_check($dom,$confname,$servadm);
7539: if ($env{'form.scantronformat.filename'} ne '') {
7540: my $error;
7541: if ($configuserok eq 'ok') {
7542: if ($switchserver) {
1.130 raeburn 7543: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7544: } else {
7545: if ($author_ok eq 'ok') {
7546: my ($result,$scantronurl) =
7547: &publishlogo($r,'upload','scantronformat',$dom,
7548: $confname,'scantron','','',$custom);
7549: if ($result eq 'ok') {
7550: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7551: $changes{'scantronformat'} = 1;
1.46 raeburn 7552: } else {
7553: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7554: }
7555: } else {
7556: $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);
7557: }
7558: }
7559: } else {
7560: $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);
7561: }
7562: if ($error) {
7563: &Apache::lonnet::logthis($error);
7564: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7565: }
7566: }
1.48 raeburn 7567: if (ref($domconfig{'scantron'}) eq 'HASH') {
7568: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7569: if ($env{'form.scantronformat_del'}) {
7570: $confhash{'scantron'}{'scantronformat'} = '';
7571: $changes{'scantronformat'} = 1;
1.46 raeburn 7572: }
7573: }
7574: }
7575: if (keys(%confhash) > 0) {
7576: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7577: $dom);
7578: if ($putresult eq 'ok') {
7579: if (keys(%changes) > 0) {
1.48 raeburn 7580: if (ref($confhash{'scantron'}) eq 'HASH') {
7581: $resulttext = &mt('Changes made:').'<ul>';
7582: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7583: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7584: } else {
1.130 raeburn 7585: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7586: }
1.48 raeburn 7587: $resulttext .= '</ul>';
7588: } else {
1.130 raeburn 7589: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7590: }
7591: $resulttext .= '</ul>';
7592: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.24 raeburn 7593: $$lastactref = 'update';
1.46 raeburn 7594: } else {
1.130 raeburn 7595: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7596: }
7597: } else {
7598: $resulttext = '<span class="LC_error">'.
7599: &mt('An error occurred: [_1]',$putresult).'</span>';
7600: }
7601: } else {
1.130 raeburn 7602: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7603: }
7604: if ($errors) {
7605: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7606: $errors.'</ul>';
7607: }
7608: return $resulttext;
7609: }
7610:
1.48 raeburn 7611: sub modify_coursecategories {
7612: my ($dom,%domconfig) = @_;
1.57 raeburn 7613: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7614: $cathash);
1.48 raeburn 7615: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7616: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7617: $cathash = $domconfig{'coursecategories'}{'cats'};
7618: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7619: $changes{'togglecats'} = 1;
7620: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7621: }
7622: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7623: $changes{'categorize'} = 1;
7624: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7625: }
1.120 raeburn 7626: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7627: $changes{'togglecatscomm'} = 1;
7628: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7629: }
7630: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7631: $changes{'categorizecomm'} = 1;
7632: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7633: }
1.57 raeburn 7634: } else {
7635: $changes{'togglecats'} = 1;
7636: $changes{'categorize'} = 1;
1.124 raeburn 7637: $changes{'togglecatscomm'} = 1;
7638: $changes{'categorizecomm'} = 1;
1.87 raeburn 7639: $domconfig{'coursecategories'} = {
7640: togglecats => $env{'form.togglecats'},
7641: categorize => $env{'form.categorize'},
1.124 raeburn 7642: togglecatscomm => $env{'form.togglecatscomm'},
7643: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7644: };
1.57 raeburn 7645: }
7646: if (ref($cathash) eq 'HASH') {
7647: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7648: push (@deletecategory,'instcode::0');
7649: }
1.120 raeburn 7650: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7651: push(@deletecategory,'communities::0');
7652: }
1.48 raeburn 7653: }
1.57 raeburn 7654: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7655: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7656: if (@deletecategory > 0) {
7657: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7658: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7659: foreach my $item (@deletecategory) {
1.57 raeburn 7660: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7661: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7662: $deletions{$item} = 1;
1.57 raeburn 7663: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7664: }
7665: }
7666: }
1.57 raeburn 7667: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7668: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7669: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7670: $reorderings{$item} = 1;
1.57 raeburn 7671: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7672: }
7673: if ($env{'form.addcategory_name_'.$item} ne '') {
7674: my $newcat = $env{'form.addcategory_name_'.$item};
7675: my $newdepth = $depth+1;
7676: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7677: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7678: $adds{$newitem} = 1;
7679: }
7680: if ($env{'form.subcat_'.$item} ne '') {
7681: my $newcat = $env{'form.subcat_'.$item};
7682: my $newdepth = $depth+1;
7683: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7684: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7685: $adds{$newitem} = 1;
7686: }
7687: }
7688: }
7689: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7690: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7691: my $newitem = 'instcode::0';
1.57 raeburn 7692: if ($cathash->{$newitem} eq '') {
7693: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7694: $adds{$newitem} = 1;
7695: }
7696: } else {
7697: my $newitem = 'instcode::0';
1.57 raeburn 7698: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7699: $adds{$newitem} = 1;
7700: }
7701: }
1.120 raeburn 7702: if ($env{'form.communities'} eq '1') {
7703: if (ref($cathash) eq 'HASH') {
7704: my $newitem = 'communities::0';
7705: if ($cathash->{$newitem} eq '') {
7706: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7707: $adds{$newitem} = 1;
7708: }
7709: } else {
7710: my $newitem = 'communities::0';
7711: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7712: $adds{$newitem} = 1;
7713: }
7714: }
1.48 raeburn 7715: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7716: if (($env{'form.addcategory_name'} ne 'instcode') &&
7717: ($env{'form.addcategory_name'} ne 'communities')) {
7718: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7719: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7720: $adds{$newitem} = 1;
7721: }
1.48 raeburn 7722: }
1.57 raeburn 7723: my $putresult;
1.48 raeburn 7724: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7725: if (keys(%deletions) > 0) {
7726: foreach my $key (keys(%deletions)) {
7727: if ($predelallitems{$key} ne '') {
7728: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7729: }
7730: }
7731: }
7732: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7733: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7734: if (ref($chkcats[0]) eq 'ARRAY') {
7735: my $depth = 0;
7736: my $chg = 0;
7737: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7738: my $name = $chkcats[0][$i];
7739: my $item;
7740: if ($name eq '') {
7741: $chg ++;
7742: } else {
7743: $item = &escape($name).'::0';
7744: if ($chg) {
1.57 raeburn 7745: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7746: }
7747: $depth ++;
1.57 raeburn 7748: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7749: $depth --;
7750: }
7751: }
7752: }
1.57 raeburn 7753: }
7754: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7755: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7756: if ($putresult eq 'ok') {
1.57 raeburn 7757: my %title = (
1.120 raeburn 7758: togglecats => 'Show/Hide a course in catalog',
7759: categorize => 'Assign a category to a course',
7760: togglecatscomm => 'Show/Hide a community in catalog',
7761: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7762: );
7763: my %level = (
1.120 raeburn 7764: dom => 'set in Domain ("Modify Course/Community")',
7765: crs => 'set in Course ("Course Configuration")',
7766: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7767: );
1.48 raeburn 7768: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7769: if ($changes{'togglecats'}) {
7770: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7771: }
7772: if ($changes{'categorize'}) {
7773: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7774: }
1.120 raeburn 7775: if ($changes{'togglecatscomm'}) {
7776: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7777: }
7778: if ($changes{'categorizecomm'}) {
7779: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7780: }
1.57 raeburn 7781: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7782: my $cathash;
7783: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7784: $cathash = $domconfig{'coursecategories'}{'cats'};
7785: } else {
7786: $cathash = {};
7787: }
7788: my (@cats,@trails,%allitems);
7789: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7790: if (keys(%deletions) > 0) {
7791: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7792: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7793: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7794: }
7795: $resulttext .= '</ul></li>';
7796: }
7797: if (keys(%reorderings) > 0) {
7798: my %sort_by_trail;
7799: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7800: foreach my $key (keys(%reorderings)) {
7801: if ($allitems{$key} ne '') {
7802: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7803: }
1.48 raeburn 7804: }
1.57 raeburn 7805: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7806: $resulttext .= '<li>'.$trails[$trail].'</li>';
7807: }
7808: $resulttext .= '</ul></li>';
1.48 raeburn 7809: }
1.57 raeburn 7810: if (keys(%adds) > 0) {
7811: my %sort_by_trail;
7812: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7813: foreach my $key (keys(%adds)) {
7814: if ($allitems{$key} ne '') {
7815: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7816: }
7817: }
7818: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7819: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7820: }
1.57 raeburn 7821: $resulttext .= '</ul></li>';
1.48 raeburn 7822: }
7823: }
7824: $resulttext .= '</ul>';
7825: } else {
7826: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7827: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7828: }
7829: } else {
1.120 raeburn 7830: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7831: }
7832: return $resulttext;
7833: }
7834:
1.69 raeburn 7835: sub modify_serverstatuses {
7836: my ($dom,%domconfig) = @_;
7837: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7838: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7839: %currserverstatus = %{$domconfig{'serverstatuses'}};
7840: }
7841: my @pages = &serverstatus_pages();
7842: foreach my $type (@pages) {
7843: $newserverstatus{$type}{'namedusers'} = '';
7844: $newserverstatus{$type}{'machines'} = '';
7845: if (defined($env{'form.'.$type.'_namedusers'})) {
7846: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7847: my @okusers;
7848: foreach my $user (@users) {
7849: my ($uname,$udom) = split(/:/,$user);
7850: if (($udom =~ /^$match_domain$/) &&
7851: (&Apache::lonnet::domain($udom)) &&
7852: ($uname =~ /^$match_username$/)) {
7853: if (!grep(/^\Q$user\E/,@okusers)) {
7854: push(@okusers,$user);
7855: }
7856: }
7857: }
7858: if (@okusers > 0) {
7859: @okusers = sort(@okusers);
7860: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7861: }
7862: }
7863: if (defined($env{'form.'.$type.'_machines'})) {
7864: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7865: my @okmachines;
7866: foreach my $ip (@machines) {
7867: my @parts = split(/\./,$ip);
7868: next if (@parts < 4);
7869: my $badip = 0;
7870: for (my $i=0; $i<4; $i++) {
7871: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7872: $badip = 1;
7873: last;
7874: }
7875: }
7876: if (!$badip) {
7877: push(@okmachines,$ip);
7878: }
7879: }
7880: @okmachines = sort(@okmachines);
7881: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7882: }
7883: }
7884: my %serverstatushash = (
7885: serverstatuses => \%newserverstatus,
7886: );
7887: foreach my $type (@pages) {
1.83 raeburn 7888: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7889: my (@current,@new);
1.83 raeburn 7890: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7891: if ($currserverstatus{$type}{$setting} ne '') {
7892: @current = split(/,/,$currserverstatus{$type}{$setting});
7893: }
7894: }
7895: if ($newserverstatus{$type}{$setting} ne '') {
7896: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7897: }
7898: if (@current > 0) {
7899: if (@new > 0) {
7900: foreach my $item (@current) {
7901: if (!grep(/^\Q$item\E$/,@new)) {
7902: $changes{$type}{$setting} = 1;
1.82 raeburn 7903: last;
7904: }
7905: }
1.84 raeburn 7906: foreach my $item (@new) {
7907: if (!grep(/^\Q$item\E$/,@current)) {
7908: $changes{$type}{$setting} = 1;
7909: last;
1.82 raeburn 7910: }
7911: }
7912: } else {
1.83 raeburn 7913: $changes{$type}{$setting} = 1;
1.69 raeburn 7914: }
1.83 raeburn 7915: } elsif (@new > 0) {
7916: $changes{$type}{$setting} = 1;
1.69 raeburn 7917: }
7918: }
7919: }
7920: if (keys(%changes) > 0) {
1.81 raeburn 7921: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7922: my $putresult = &Apache::lonnet::put_dom('configuration',
7923: \%serverstatushash,$dom);
7924: if ($putresult eq 'ok') {
7925: $resulttext .= &mt('Changes made:').'<ul>';
7926: foreach my $type (@pages) {
1.84 raeburn 7927: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7928: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7929: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7930: if ($newserverstatus{$type}{'namedusers'} eq '') {
7931: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7932: } else {
7933: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7934: }
1.84 raeburn 7935: }
7936: if ($changes{$type}{'machines'}) {
1.69 raeburn 7937: if ($newserverstatus{$type}{'machines'} eq '') {
7938: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7939: } else {
7940: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7941: }
7942:
7943: }
7944: $resulttext .= '</ul></li>';
7945: }
7946: }
7947: $resulttext .= '</ul>';
7948: } else {
7949: $resulttext = '<span class="LC_error">'.
7950: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7951:
7952: }
7953: } else {
7954: $resulttext = &mt('No changes made to access to server status pages');
7955: }
7956: return $resulttext;
7957: }
7958:
1.118 jms 7959: sub modify_helpsettings {
1.122 jms 7960: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7961: my ($resulttext,$errors,%changes,%helphash);
7962: my %defaultchecked = ('submitbugs' => 'on');
7963: my @offon = ('off','on');
1.118 jms 7964: my @toggles = ('submitbugs');
7965: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7966: foreach my $item (@toggles) {
1.160.6.5 raeburn 7967: if ($defaultchecked{$item} eq 'on') {
7968: if ($domconfig{'helpsettings'}{$item} eq '') {
7969: if ($env{'form.'.$item} eq '0') {
7970: $changes{$item} = 1;
7971: }
7972: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7973: $changes{$item} = 1;
7974: }
7975: } elsif ($defaultchecked{$item} eq 'off') {
7976: if ($domconfig{'helpsettings'}{$item} eq '') {
7977: if ($env{'form.'.$item} eq '1') {
7978: $changes{$item} = 1;
7979: }
7980: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7981: $changes{$item} = 1;
7982: }
7983: }
7984: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7985: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7986: }
7987: }
1.118 jms 7988: }
1.123 jms 7989: my $putresult;
7990: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7991: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7992: if ($putresult eq 'ok') {
7993: $resulttext = &mt('Changes made:').'<ul>';
7994: foreach my $item (sort(keys(%changes))) {
7995: if ($item eq 'submitbugs') {
7996: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7997: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7998: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7999: }
8000: }
8001: $resulttext .= '</ul>';
8002: } else {
8003: $resulttext = &mt('No changes made to help settings');
8004: $errors .= '<li><span class="LC_error">'.
8005: &mt('An error occurred storing the settings: [_1]',
8006: $putresult).'</span></li>';
8007: }
1.118 jms 8008: }
8009: if ($errors) {
1.160.6.5 raeburn 8010: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8011: $errors.'</ul>';
8012: }
8013: return $resulttext;
8014: }
8015:
1.121 raeburn 8016: sub modify_coursedefaults {
8017: my ($dom,%domconfig) = @_;
8018: my ($resulttext,$errors,%changes,%defaultshash);
8019: my %defaultchecked = ('canuse_pdfforms' => 'off');
8020: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 8021: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
8022: 'uploadquota_community');
8023: my @types = ('official','unofficial','community');
8024: my %staticdefaults = (
8025: anonsurvey_threshold => 10,
8026: uploadquota => 500,
8027: );
1.121 raeburn 8028:
8029: $defaultshash{'coursedefaults'} = {};
8030:
8031: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8032: if ($domconfig{'coursedefaults'} eq '') {
8033: $domconfig{'coursedefaults'} = {};
8034: }
8035: }
8036:
8037: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8038: foreach my $item (@toggles) {
8039: if ($defaultchecked{$item} eq 'on') {
8040: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8041: ($env{'form.'.$item} eq '0')) {
8042: $changes{$item} = 1;
1.160.6.16 raeburn 8043: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8044: $changes{$item} = 1;
8045: }
8046: } elsif ($defaultchecked{$item} eq 'off') {
8047: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8048: ($env{'form.'.$item} eq '1')) {
8049: $changes{$item} = 1;
8050: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8051: $changes{$item} = 1;
8052: }
8053: }
8054: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8055: }
1.160.6.21 raeburn 8056: foreach my $item (@numbers) {
8057: my ($currdef,$newdef);
8058: my $newdef = $env{'form.'.$item};
8059: if ($item eq 'anonsurvey_threshold') {
8060: $currdef = $domconfig{'coursedefaults'}{$item};
8061: $newdef =~ s/\D//g;
8062: if ($newdef eq '' || $newdef < 1) {
8063: $newdef = 1;
8064: }
8065: $defaultshash{'coursedefaults'}{$item} = $newdef;
8066: } else {
8067: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8068: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8069: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8070: }
8071: $newdef =~ s/[^\w.\-]//g;
8072: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8073: }
8074: if ($currdef ne $newdef) {
8075: my $staticdef;
8076: if ($item eq 'anonsurvey_threshold') {
8077: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8078: $changes{$item} = 1;
8079: }
8080: } else {
8081: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8082: $changes{'uploadquota'} = 1;
8083: }
8084: }
1.139 raeburn 8085: }
8086: }
1.160.6.16 raeburn 8087: my $officialcreds = $env{'form.official_credits'};
8088: $officialcreds =~ s/^[^\d\.]//g;
8089: my $unofficialcreds = $env{'form.unofficial_credits'};
8090: $unofficialcreds =~ s/^[^\d\.]//g;
8091: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8092: ($env{'form.coursecredits'} eq '1')) {
8093: $changes{'coursecredits'} = 1;
8094: } else {
8095: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
8096: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
8097: $changes{'coursecredits'} = 1;
8098: }
8099: }
8100: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8101: official => $officialcreds,
8102: unofficial => $unofficialcreds,
8103: }
1.121 raeburn 8104: }
8105: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8106: $dom);
8107: if ($putresult eq 'ok') {
1.160.6.16 raeburn 8108: my %domdefaults;
1.121 raeburn 8109: if (keys(%changes) > 0) {
1.160.6.21 raeburn 8110: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.160.6.16 raeburn 8111: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8112: if ($changes{'canuse_pdfforms'}) {
8113: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8114: }
8115: if ($changes{'coursecredits'}) {
8116: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8117: $domdefaults{'officialcredits'} =
8118: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8119: $domdefaults{'unofficialcredits'} =
8120: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8121: }
8122: }
1.160.6.21 raeburn 8123: if ($changes{'uploadquota'}) {
8124: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8125: foreach my $type (@types) {
8126: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8127: }
8128: }
8129: }
1.121 raeburn 8130: my $cachetime = 24*60*60;
8131: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8132: }
8133: $resulttext = &mt('Changes made:').'<ul>';
8134: foreach my $item (sort(keys(%changes))) {
8135: if ($item eq 'canuse_pdfforms') {
8136: if ($env{'form.'.$item} eq '1') {
8137: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8138: } else {
8139: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8140: }
1.139 raeburn 8141: } elsif ($item eq 'anonsurvey_threshold') {
8142: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 8143: } elsif ($item eq 'uploadquota') {
8144: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8145: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8146: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8147: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
8148: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8149: '</ul>'.
8150: '</li>';
8151: } else {
8152: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8153: }
1.160.6.16 raeburn 8154: } elsif ($item eq 'coursecredits') {
8155: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8156: if (($domdefaults{'officialcredits'} eq '') &&
8157: ($domdefaults{'unofficialcredits'} eq '')) {
8158: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8159: } else {
8160: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8161: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8162: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8163: '</ul>'.
8164: '</li>';
8165: }
8166: } else {
8167: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8168: }
1.140 raeburn 8169: }
1.121 raeburn 8170: }
8171: $resulttext .= '</ul>';
8172: } else {
8173: $resulttext = &mt('No changes made to course defaults');
8174: }
8175: } else {
8176: $resulttext = '<span class="LC_error">'.
8177: &mt('An error occurred: [_1]',$putresult).'</span>';
8178: }
8179: return $resulttext;
8180: }
8181:
1.137 raeburn 8182: sub modify_usersessions {
8183: my ($dom,%domconfig) = @_;
1.145 raeburn 8184: my @hostingtypes = ('version','excludedomain','includedomain');
8185: my @offloadtypes = ('primary','default');
8186: my %types = (
8187: remote => \@hostingtypes,
8188: hosted => \@hostingtypes,
8189: spares => \@offloadtypes,
8190: );
8191: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8192: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8193: my (%by_ip,%by_location,@intdoms);
8194: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8195: my @locations = sort(keys(%by_location));
1.137 raeburn 8196: my (%defaultshash,%changes);
8197: foreach my $prefix (@prefixes) {
8198: $defaultshash{'usersessions'}{$prefix} = {};
8199: }
8200: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8201: my $resulttext;
1.138 raeburn 8202: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8203: foreach my $prefix (@prefixes) {
1.145 raeburn 8204: next if ($prefix eq 'spares');
8205: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8206: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8207: if ($type eq 'version') {
8208: my $value = $env{'form.'.$prefix.'_'.$type};
8209: my $okvalue;
8210: if ($value ne '') {
8211: if (grep(/^\Q$value\E$/,@lcversions)) {
8212: $okvalue = $value;
8213: }
8214: }
8215: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8216: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8217: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8218: if ($inuse == 0) {
8219: $changes{$prefix}{$type} = 1;
8220: } else {
8221: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8222: $changes{$prefix}{$type} = 1;
8223: }
8224: if ($okvalue ne '') {
8225: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8226: }
8227: }
8228: } else {
8229: if (($inuse == 1) && ($okvalue ne '')) {
8230: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8231: $changes{$prefix}{$type} = 1;
8232: }
8233: }
8234: } else {
8235: if (($inuse == 1) && ($okvalue ne '')) {
8236: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8237: $changes{$prefix}{$type} = 1;
8238: }
8239: }
8240: } else {
8241: if (($inuse == 1) && ($okvalue ne '')) {
8242: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8243: $changes{$prefix}{$type} = 1;
8244: }
8245: }
8246: } else {
8247: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8248: my @okvals;
8249: foreach my $val (@vals) {
1.138 raeburn 8250: if ($val =~ /:/) {
8251: my @items = split(/:/,$val);
8252: foreach my $item (@items) {
8253: if (ref($by_location{$item}) eq 'ARRAY') {
8254: push(@okvals,$item);
8255: }
8256: }
8257: } else {
8258: if (ref($by_location{$val}) eq 'ARRAY') {
8259: push(@okvals,$val);
8260: }
1.137 raeburn 8261: }
8262: }
8263: @okvals = sort(@okvals);
8264: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8265: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8266: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8267: if ($inuse == 0) {
8268: $changes{$prefix}{$type} = 1;
8269: } else {
8270: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8271: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8272: if (@changed > 0) {
8273: $changes{$prefix}{$type} = 1;
8274: }
8275: }
8276: } else {
8277: if ($inuse == 1) {
8278: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8279: $changes{$prefix}{$type} = 1;
8280: }
8281: }
8282: } else {
8283: if ($inuse == 1) {
8284: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8285: $changes{$prefix}{$type} = 1;
8286: }
8287: }
8288: } else {
8289: if ($inuse == 1) {
8290: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8291: $changes{$prefix}{$type} = 1;
8292: }
8293: }
8294: }
8295: }
8296: }
1.145 raeburn 8297:
8298: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8299: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8300: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8301: my $savespares;
8302:
8303: foreach my $lonhost (sort(keys(%servers))) {
8304: my $serverhomeID =
8305: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8306: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8307: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8308: my %spareschg;
8309: foreach my $type (@{$types{'spares'}}) {
8310: my @okspares;
8311: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8312: foreach my $server (@checked) {
1.152 raeburn 8313: if (&Apache::lonnet::hostname($server) ne '') {
8314: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8315: unless (grep(/^\Q$server\E$/,@okspares)) {
8316: push(@okspares,$server);
8317: }
1.145 raeburn 8318: }
8319: }
8320: }
8321: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8322: my $newspare;
1.152 raeburn 8323: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8324: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8325: $newspare = $new;
8326: }
8327: }
1.152 raeburn 8328: my @spares;
8329: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8330: @spares = sort(@okspares,$newspare);
8331: } else {
8332: @spares = sort(@okspares);
8333: }
8334: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8335: if (ref($spareid{$lonhost}) eq 'HASH') {
8336: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8337: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8338: if (@diffs > 0) {
8339: $spareschg{$type} = 1;
8340: }
8341: }
8342: }
8343: }
8344: if (keys(%spareschg) > 0) {
8345: $changes{'spares'}{$lonhost} = \%spareschg;
8346: }
8347: }
8348:
8349: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8350: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8351: if (ref($changes{'spares'}) eq 'HASH') {
8352: if (keys(%{$changes{'spares'}}) > 0) {
8353: $savespares = 1;
8354: }
8355: }
8356: } else {
8357: $savespares = 1;
8358: }
8359: }
8360:
1.147 raeburn 8361: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8362: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8363: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8364: $dom);
8365: if ($putresult eq 'ok') {
8366: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8367: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8368: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8369: }
8370: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8371: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8372: }
8373: }
8374: my $cachetime = 24*60*60;
8375: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8376: if (keys(%changes) > 0) {
8377: my %lt = &usersession_titles();
8378: $resulttext = &mt('Changes made:').'<ul>';
8379: foreach my $prefix (@prefixes) {
8380: if (ref($changes{$prefix}) eq 'HASH') {
8381: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8382: if ($prefix eq 'spares') {
8383: if (ref($changes{$prefix}) eq 'HASH') {
8384: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8385: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8386: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8387: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8388: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8389: foreach my $type (@{$types{$prefix}}) {
8390: if ($changes{$prefix}{$lonhost}{$type}) {
8391: my $offloadto = &mt('None');
8392: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8393: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8394: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8395: }
1.145 raeburn 8396: }
1.147 raeburn 8397: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8398: }
1.137 raeburn 8399: }
8400: }
1.147 raeburn 8401: $resulttext .= '</li>';
1.137 raeburn 8402: }
8403: }
1.147 raeburn 8404: } else {
8405: foreach my $type (@{$types{$prefix}}) {
8406: if (defined($changes{$prefix}{$type})) {
8407: my $newvalue;
8408: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8409: if (ref($defaultshash{'usersessions'}{$prefix})) {
8410: if ($type eq 'version') {
8411: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8412: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8413: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8414: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8415: }
1.145 raeburn 8416: }
8417: }
8418: }
1.147 raeburn 8419: if ($newvalue eq '') {
8420: if ($type eq 'version') {
8421: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8422: } else {
8423: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8424: }
1.145 raeburn 8425: } else {
1.147 raeburn 8426: if ($type eq 'version') {
8427: $newvalue .= ' '.&mt('(or later)');
8428: }
8429: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8430: }
1.137 raeburn 8431: }
8432: }
8433: }
1.147 raeburn 8434: $resulttext .= '</ul>';
1.137 raeburn 8435: }
8436: }
1.147 raeburn 8437: $resulttext .= '</ul>';
8438: } else {
8439: $resulttext = $nochgmsg;
1.137 raeburn 8440: }
8441: } else {
8442: $resulttext = '<span class="LC_error">'.
8443: &mt('An error occurred: [_1]',$putresult).'</span>';
8444: }
8445: } else {
1.147 raeburn 8446: $resulttext = $nochgmsg;
1.137 raeburn 8447: }
8448: return $resulttext;
8449: }
8450:
1.150 raeburn 8451: sub modify_loadbalancing {
8452: my ($dom,%domconfig) = @_;
8453: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8454: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8455: my ($othertitle,$usertypes,$types) =
8456: &Apache::loncommon::sorted_inst_types($dom);
8457: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8458: my @sparestypes = ('primary','default');
8459: my %typetitles = &sparestype_titles();
8460: my $resulttext;
1.160.6.7 raeburn 8461: my (%currbalancer,%currtargets,%currrules,%existing);
8462: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8463: %existing = %{$domconfig{'loadbalancing'}};
8464: }
8465: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8466: \%currtargets,\%currrules);
8467: my ($saveloadbalancing,%defaultshash,%changes);
8468: my ($alltypes,$othertypes,$titles) =
8469: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8470: my %ruletitles = &offloadtype_text();
8471: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8472: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8473: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8474: if ($balancer eq '') {
8475: next;
8476: }
8477: if (!exists($servers{$balancer})) {
8478: if (exists($currbalancer{$balancer})) {
8479: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8480: }
1.160.6.7 raeburn 8481: next;
8482: }
8483: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8484: push(@{$changes{'delete'}},$balancer);
8485: next;
8486: }
8487: if (!exists($currbalancer{$balancer})) {
8488: push(@{$changes{'add'}},$balancer);
8489: }
8490: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8491: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8492: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8493: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8494: $saveloadbalancing = 1;
8495: }
8496: foreach my $sparetype (@sparestypes) {
8497: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8498: my @offloadto;
8499: foreach my $target (@targets) {
8500: if (($servers{$target}) && ($target ne $balancer)) {
8501: if ($sparetype eq 'default') {
8502: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8503: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8504: }
8505: }
1.160.6.7 raeburn 8506: unless(grep(/^\Q$target\E$/,@offloadto)) {
8507: push(@offloadto,$target);
8508: }
1.150 raeburn 8509: }
1.160.6.7 raeburn 8510: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8511: }
8512: }
1.160.6.7 raeburn 8513: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8514: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8515: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8516: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8517: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8518: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8519: }
1.160.6.7 raeburn 8520: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8521: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8522: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8523: }
8524: }
8525: }
8526: } else {
1.160.6.7 raeburn 8527: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8528: foreach my $sparetype (@sparestypes) {
8529: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8530: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8531: $changes{'curr'}{$balancer}{'targets'} = 1;
8532: }
1.150 raeburn 8533: }
8534: }
1.160.6.7 raeburn 8535: }
1.150 raeburn 8536: }
8537: my $ishomedom;
1.160.6.7 raeburn 8538: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8539: $ishomedom = 1;
1.150 raeburn 8540: }
8541: if (ref($alltypes) eq 'ARRAY') {
8542: foreach my $type (@{$alltypes}) {
8543: my $rule;
1.160.6.7 raeburn 8544: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8545: (!$ishomedom)) {
1.160.6.7 raeburn 8546: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8547: }
8548: if ($rule eq 'specific') {
8549: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8550: }
1.160.6.7 raeburn 8551: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8552: if (ref($currrules{$balancer}) eq 'HASH') {
8553: if ($rule ne $currrules{$balancer}{$type}) {
8554: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8555: }
8556: } elsif ($rule ne '') {
1.160.6.7 raeburn 8557: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8558: }
8559: }
8560: }
1.160.6.7 raeburn 8561: }
8562: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8563: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8564: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8565: $defaultshash{'loadbalancing'} = {};
8566: }
8567: my $putresult = &Apache::lonnet::put_dom('configuration',
8568: \%defaultshash,$dom);
8569:
8570: if ($putresult eq 'ok') {
8571: if (keys(%changes) > 0) {
8572: if (ref($changes{'delete'}) eq 'ARRAY') {
8573: foreach my $balancer (sort(@{$changes{'delete'}})) {
8574: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8575: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8576: }
1.160.6.7 raeburn 8577: }
8578: if (ref($changes{'add'}) eq 'ARRAY') {
8579: foreach my $balancer (sort(@{$changes{'add'}})) {
8580: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8581: }
8582: }
8583: if (ref($changes{'curr'}) eq 'HASH') {
8584: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8585: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8586: if ($changes{'curr'}{$balancer}{'targets'}) {
8587: my %offloadstr;
8588: foreach my $sparetype (@sparestypes) {
8589: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8590: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8591: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8592: }
8593: }
1.150 raeburn 8594: }
1.160.6.7 raeburn 8595: if (keys(%offloadstr) == 0) {
8596: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8597: } else {
1.160.6.7 raeburn 8598: my $showoffload;
8599: foreach my $sparetype (@sparestypes) {
8600: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8601: if (defined($offloadstr{$sparetype})) {
8602: $showoffload .= $offloadstr{$sparetype};
8603: } else {
8604: $showoffload .= &mt('None');
8605: }
8606: $showoffload .= (' 'x3);
8607: }
8608: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8609: }
8610: }
8611: }
1.160.6.7 raeburn 8612: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8613: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8614: foreach my $type (@{$alltypes}) {
8615: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8616: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8617: my $balancetext;
8618: if ($rule eq '') {
8619: $balancetext = $ruletitles{'default'};
8620: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8621: $balancetext = $ruletitles{$rule};
8622: } else {
8623: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8624: }
8625: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8626: }
8627: }
8628: }
8629: }
1.160.6.7 raeburn 8630: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8631: }
1.160.6.7 raeburn 8632: }
8633: if ($resulttext ne '') {
8634: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8635: } else {
8636: $resulttext = $nochgmsg;
8637: }
8638: } else {
1.160.6.7 raeburn 8639: $resulttext = $nochgmsg;
1.150 raeburn 8640: }
8641: } else {
1.160.6.7 raeburn 8642: $resulttext = '<span class="LC_error">'.
8643: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8644: }
8645: } else {
1.160.6.7 raeburn 8646: $resulttext = $nochgmsg;
1.150 raeburn 8647: }
8648: return $resulttext;
8649: }
8650:
1.48 raeburn 8651: sub recurse_check {
8652: my ($chkcats,$categories,$depth,$name) = @_;
8653: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8654: my $chg = 0;
8655: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8656: my $category = $chkcats->[$depth]{$name}[$j];
8657: my $item;
8658: if ($category eq '') {
8659: $chg ++;
8660: } else {
8661: my $deeper = $depth + 1;
8662: $item = &escape($category).':'.&escape($name).':'.$depth;
8663: if ($chg) {
8664: $categories->{$item} -= $chg;
8665: }
8666: &recurse_check($chkcats,$categories,$deeper,$category);
8667: $deeper --;
8668: }
8669: }
8670: }
8671: return;
8672: }
8673:
8674: sub recurse_cat_deletes {
8675: my ($item,$coursecategories,$deletions) = @_;
8676: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8677: my $subdepth = $depth + 1;
8678: if (ref($coursecategories) eq 'HASH') {
8679: foreach my $subitem (keys(%{$coursecategories})) {
8680: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8681: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8682: delete($coursecategories->{$subitem});
8683: $deletions->{$subitem} = 1;
8684: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8685: }
8686: }
8687: }
8688: return;
8689: }
8690:
1.125 raeburn 8691: sub get_active_dcs {
8692: my ($dom) = @_;
1.160.6.16 raeburn 8693: my $now = time;
8694: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8695: my %domcoords;
8696: my $numdcs = 0;
8697: foreach my $server (keys(%dompersonnel)) {
8698: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8699: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 8700: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8701: }
8702: }
8703: return %domcoords;
8704: }
8705:
8706: sub active_dc_picker {
1.160.6.16 raeburn 8707: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8708: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 8709: my @domcoord = keys(%domcoords);
8710: if (keys(%currhash)) {
8711: foreach my $dc (keys(%currhash)) {
8712: unless (exists($domcoords{$dc})) {
8713: push(@domcoord,$dc);
8714: }
8715: }
8716: }
8717: @domcoord = sort(@domcoord);
8718: my $numdcs = scalar(@domcoord);
8719: my $rows = 0;
8720: my $table;
1.125 raeburn 8721: if ($numdcs > 1) {
1.160.6.16 raeburn 8722: $table = '<table>';
8723: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8724: my $rem = $i%($numinrow);
8725: if ($rem == 0) {
8726: if ($i > 0) {
1.160.6.16 raeburn 8727: $table .= '</tr>';
1.125 raeburn 8728: }
1.160.6.16 raeburn 8729: $table .= '<tr>';
8730: $rows ++;
1.125 raeburn 8731: }
1.160.6.16 raeburn 8732: my $check = '';
8733: if ($inputtype eq 'radio') {
8734: if (keys(%currhash) == 0) {
8735: if (!$i) {
8736: $check = ' checked="checked"';
8737: }
8738: } elsif (exists($currhash{$domcoord[$i]})) {
8739: $check = ' checked="checked"';
8740: }
8741: } else {
8742: if (exists($currhash{$domcoord[$i]})) {
8743: $check = ' checked="checked"';
1.125 raeburn 8744: }
8745: }
1.160.6.16 raeburn 8746: if ($i == @domcoord - 1) {
1.125 raeburn 8747: my $colsleft = $numinrow - $rem;
8748: if ($colsleft > 1) {
1.160.6.16 raeburn 8749: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8750: } else {
1.160.6.16 raeburn 8751: $table .= '<td class="LC_left_item">';
1.125 raeburn 8752: }
8753: } else {
1.160.6.16 raeburn 8754: $table .= '<td class="LC_left_item">';
8755: }
8756: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8757: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8758: $table .= '<span class="LC_nobreak"><label>'.
8759: '<input type="'.$inputtype.'" name="'.$name.'"'.
8760: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8761: if ($user ne $dcname.':'.$dcdom) {
8762: $table .= ' ('.$dcname.':'.$dcdom.')'.
8763: '</label></span></td>';
1.125 raeburn 8764: }
8765: }
1.160.6.16 raeburn 8766: $table .= '</tr></table>';
8767: } elsif ($numdcs == 1) {
8768: if ($inputtype eq 'radio') {
8769: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8770: } else {
8771: my $check;
8772: if (exists($currhash{$domcoord[0]})) {
8773: $check = ' checked="checked"';
8774: }
8775: $table .= '<input type="checkbox" name="'.$name.'" '.
8776: 'value="'.$domcoord[0].'"'.$check.' />';
8777: $rows ++;
8778: }
1.125 raeburn 8779: }
1.160.6.16 raeburn 8780: return ($numdcs,$table,$rows);
1.125 raeburn 8781: }
8782:
1.137 raeburn 8783: sub usersession_titles {
8784: return &Apache::lonlocal::texthash(
8785: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8786: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8787: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8788: version => 'LON-CAPA version requirement',
1.138 raeburn 8789: excludedomain => 'Allow all, but exclude specific domains',
8790: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8791: primary => 'Primary (checked first)',
1.154 raeburn 8792: default => 'Default',
1.137 raeburn 8793: );
8794: }
8795:
1.152 raeburn 8796: sub id_for_thisdom {
8797: my (%servers) = @_;
8798: my %altids;
8799: foreach my $server (keys(%servers)) {
8800: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8801: if ($serverhome ne $server) {
8802: $altids{$serverhome} = $server;
8803: }
8804: }
8805: return %altids;
8806: }
8807:
1.150 raeburn 8808: sub count_servers {
8809: my ($currbalancer,%servers) = @_;
8810: my (@spares,$numspares);
8811: foreach my $lonhost (sort(keys(%servers))) {
8812: next if ($currbalancer eq $lonhost);
8813: push(@spares,$lonhost);
8814: }
8815: if ($currbalancer) {
8816: $numspares = scalar(@spares);
8817: } else {
8818: $numspares = scalar(@spares) - 1;
8819: }
8820: return ($numspares,@spares);
8821: }
8822:
8823: sub lonbalance_targets_js {
1.160.6.7 raeburn 8824: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8825: my $select = &mt('Select');
8826: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8827: if (ref($servers) eq 'HASH') {
8828: $alltargets = join("','",sort(keys(%{$servers})));
8829: my @homedoms;
8830: foreach my $server (sort(keys(%{$servers}))) {
8831: if (&Apache::lonnet::host_domain($server) eq $dom) {
8832: push(@homedoms,'1');
8833: } else {
8834: push(@homedoms,'0');
8835: }
8836: }
8837: $allishome = join("','",@homedoms);
8838: }
8839: if (ref($types) eq 'ARRAY') {
8840: if (@{$types} > 0) {
8841: @alltypes = @{$types};
8842: }
8843: }
8844: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8845: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8846: my (%currbalancer,%currtargets,%currrules,%existing);
8847: if (ref($settings) eq 'HASH') {
8848: %existing = %{$settings};
8849: }
8850: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8851: \%currtargets,\%currrules);
8852: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8853: return <<"END";
8854:
8855: <script type="text/javascript">
8856: // <![CDATA[
8857:
1.160.6.7 raeburn 8858: currBalancers = new Array('$balancers');
8859:
8860: function toggleTargets(balnum) {
8861: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8862: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8863: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8864: var prevbalancer = prevhostitem.value;
8865: var baltotal = document.getElementById('loadbalancing_total').value;
8866: prevhostitem.value = balancer;
8867: if (prevbalancer != '') {
8868: var prevIdx = currBalancers.indexOf(prevbalancer);
8869: if (prevIdx != -1) {
8870: currBalancers.splice(prevIdx,1);
8871: }
8872: }
1.150 raeburn 8873: if (balancer == '') {
1.160.6.7 raeburn 8874: hideSpares(balnum);
1.150 raeburn 8875: } else {
1.160.6.7 raeburn 8876: var currIdx = currBalancers.indexOf(balancer);
8877: if (currIdx == -1) {
8878: currBalancers.push(balancer);
8879: }
1.150 raeburn 8880: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8881: var ishomedom = homedoms[lonhostitem.selectedIndex];
8882: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8883: }
1.160.6.7 raeburn 8884: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8885: return;
8886: }
8887:
1.160.6.7 raeburn 8888: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8889: var alltargets = new Array('$alltargets');
8890: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8891: var offloadtypes = new Array('primary','default');
8892:
1.160.6.7 raeburn 8893: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8894: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8895:
1.151 raeburn 8896: for (var i=0; i<offloadtypes.length; i++) {
8897: var count = 0;
8898: for (var j=0; j<alltargets.length; j++) {
8899: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8900: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8901: item.value = alltargets[j];
8902: item.style.textAlign='left';
8903: item.style.textFace='normal';
8904: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8905: if (currBalancers.indexOf(alltargets[j]) == -1) {
8906: item.disabled = '';
8907: } else {
8908: item.disabled = 'disabled';
8909: item.checked = false;
8910: }
1.151 raeburn 8911: count ++;
8912: }
1.150 raeburn 8913: }
8914: }
1.151 raeburn 8915: for (var k=0; k<insttypes.length; k++) {
8916: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8917: if (ishomedom == 1) {
1.160.6.7 raeburn 8918: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8919: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8920: } else {
1.160.6.7 raeburn 8921: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8922: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8923:
8924: }
8925: } else {
1.160.6.7 raeburn 8926: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8927: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8928: }
1.151 raeburn 8929: if ((insttypes[k] != '_LC_external') &&
8930: ((insttypes[k] != '_LC_internetdom') ||
8931: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8932: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8933: item.options.length = 0;
8934: item.options[0] = new Option("","",true,true);
8935: var idx = 0;
1.151 raeburn 8936: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8937: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8938: idx ++;
8939: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8940:
1.150 raeburn 8941: }
8942: }
8943: }
8944: }
8945: return;
8946: }
8947:
1.160.6.7 raeburn 8948: function hideSpares(balnum) {
1.150 raeburn 8949: var alltargets = new Array('$alltargets');
8950: var insttypes = new Array('$allinsttypes');
8951: var offloadtypes = new Array('primary','default');
8952:
1.160.6.7 raeburn 8953: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8954: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8955:
8956: var total = alltargets.length - 1;
8957: for (var i=0; i<offloadtypes; i++) {
8958: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8959: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8960: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8961: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8962: }
1.150 raeburn 8963: }
8964: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8965: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8966: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8967: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8968: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8969: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8970: }
8971: }
8972: return;
8973: }
8974:
1.160.6.7 raeburn 8975: function checkOffloads(item,balnum,type) {
1.150 raeburn 8976: var alltargets = new Array('$alltargets');
8977: var offloadtypes = new Array('primary','default');
8978: if (item.checked) {
8979: var total = alltargets.length - 1;
8980: var other;
8981: if (type == offloadtypes[0]) {
1.151 raeburn 8982: other = offloadtypes[1];
1.150 raeburn 8983: } else {
1.151 raeburn 8984: other = offloadtypes[0];
1.150 raeburn 8985: }
8986: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8987: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8988: if (server == item.value) {
1.160.6.7 raeburn 8989: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8990: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8991: }
8992: }
8993: }
8994: }
8995: return;
8996: }
8997:
1.160.6.7 raeburn 8998: function singleServerToggle(balnum,type) {
8999: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9000: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 9001: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9002: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9003:
9004: } else {
1.160.6.7 raeburn 9005: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9006: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9007: }
9008: return;
9009: }
9010:
1.160.6.7 raeburn 9011: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9012: if (type == '_LC_external') {
9013: return;
9014: }
1.160.6.7 raeburn 9015: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9016: for (var i=0; i<typesRules.length; i++) {
9017: if (formname.elements[typesRules[i]].checked) {
9018: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 9019: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9020: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9021: } else {
1.160.6.7 raeburn 9022: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9023: }
9024: }
9025: }
9026: return;
9027: }
9028:
9029: function balancerDeleteChange(balnum) {
9030: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9031: var baltotal = document.getElementById('loadbalancing_total').value;
9032: var addtarget;
9033: var removetarget;
9034: var action = 'delete';
9035: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9036: var lonhost = hostitem.value;
9037: var currIdx = currBalancers.indexOf(lonhost);
9038: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9039: if (currIdx != -1) {
9040: currBalancers.splice(currIdx,1);
9041: }
9042: addtarget = lonhost;
9043: } else {
9044: if (currIdx == -1) {
9045: currBalancers.push(lonhost);
9046: }
9047: removetarget = lonhost;
9048: action = 'undelete';
9049: }
9050: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9051: }
9052: return;
9053: }
9054:
9055: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9056: if (baltotal > 1) {
9057: var offloadtypes = new Array('primary','default');
9058: var alltargets = new Array('$alltargets');
9059: var insttypes = new Array('$allinsttypes');
9060: for (var i=0; i<baltotal; i++) {
9061: if (i != balnum) {
9062: for (var j=0; j<offloadtypes.length; j++) {
9063: var total = alltargets.length - 1;
9064: for (var k=0; k<total; k++) {
9065: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9066: var server = serveritem.value;
9067: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9068: if (server == addtarget) {
9069: serveritem.disabled = '';
9070: }
9071: }
9072: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9073: if (server == removetarget) {
9074: serveritem.disabled = 'disabled';
9075: serveritem.checked = false;
9076: }
9077: }
9078: }
9079: }
9080: for (var j=0; j<insttypes.length; j++) {
9081: if (insttypes[j] != '_LC_external') {
9082: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9083: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9084: var currSel = singleserver.selectedIndex;
9085: var currVal = singleserver.options[currSel].value;
9086: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9087: var numoptions = singleserver.options.length;
9088: var needsnew = 1;
9089: for (var k=0; k<numoptions; k++) {
9090: if (singleserver.options[k] == addtarget) {
9091: needsnew = 0;
9092: break;
9093: }
9094: }
9095: if (needsnew == 1) {
9096: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9097: }
9098: }
9099: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9100: singleserver.options.length = 0;
9101: if ((currVal) && (currVal != removetarget)) {
9102: singleserver.options[0] = new Option("","",false,false);
9103: } else {
9104: singleserver.options[0] = new Option("","",true,true);
9105: }
9106: var idx = 0;
9107: for (var m=0; m<alltargets.length; m++) {
9108: if (currBalancers.indexOf(alltargets[m]) == -1) {
9109: idx ++;
9110: if (currVal == alltargets[m]) {
9111: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9112: } else {
9113: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9114: }
9115: }
9116: }
9117: }
9118: }
9119: }
9120: }
1.150 raeburn 9121: }
9122: }
9123: }
9124: return;
9125: }
9126:
1.152 raeburn 9127: // ]]>
9128: </script>
9129:
9130: END
9131: }
9132:
9133: sub new_spares_js {
9134: my @sparestypes = ('primary','default');
9135: my $types = join("','",@sparestypes);
9136: my $select = &mt('Select');
9137: return <<"END";
9138:
9139: <script type="text/javascript">
9140: // <![CDATA[
9141:
9142: function updateNewSpares(formname,lonhost) {
9143: var types = new Array('$types');
9144: var include = new Array();
9145: var exclude = new Array();
9146: for (var i=0; i<types.length; i++) {
9147: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9148: for (var j=0; j<spareboxes.length; j++) {
9149: if (formname.elements[spareboxes[j]].checked) {
9150: exclude.push(formname.elements[spareboxes[j]].value);
9151: } else {
9152: include.push(formname.elements[spareboxes[j]].value);
9153: }
9154: }
9155: }
9156: for (var i=0; i<types.length; i++) {
9157: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9158: var selIdx = newSpare.selectedIndex;
9159: var currnew = newSpare.options[selIdx].value;
9160: var okSpares = new Array();
9161: for (var j=0; j<newSpare.options.length; j++) {
9162: var possible = newSpare.options[j].value;
9163: if (possible != '') {
9164: if (exclude.indexOf(possible) == -1) {
9165: okSpares.push(possible);
9166: } else {
9167: if (currnew == possible) {
9168: selIdx = 0;
9169: }
9170: }
9171: }
9172: }
9173: for (var k=0; k<include.length; k++) {
9174: if (okSpares.indexOf(include[k]) == -1) {
9175: okSpares.push(include[k]);
9176: }
9177: }
9178: okSpares.sort();
9179: newSpare.options.length = 0;
9180: if (selIdx == 0) {
9181: newSpare.options[0] = new Option("$select","",true,true);
9182: } else {
9183: newSpare.options[0] = new Option("$select","",false,false);
9184: }
9185: for (var m=0; m<okSpares.length; m++) {
9186: var idx = m+1;
9187: var selThis = 0;
9188: if (selIdx != 0) {
9189: if (okSpares[m] == currnew) {
9190: selThis = 1;
9191: }
9192: }
9193: if (selThis == 1) {
9194: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9195: } else {
9196: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9197: }
9198: }
9199: }
9200: return;
9201: }
9202:
9203: function checkNewSpares(lonhost,type) {
9204: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9205: var chosen = newSpare.options[newSpare.selectedIndex].value;
9206: if (chosen != '') {
9207: var othertype;
9208: var othernewSpare;
9209: if (type == 'primary') {
9210: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9211: }
9212: if (type == 'default') {
9213: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9214: }
9215: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9216: othernewSpare.selectedIndex = 0;
9217: }
9218: }
9219: return;
9220: }
9221:
9222: // ]]>
9223: </script>
9224:
9225: END
9226:
9227: }
9228:
9229: sub common_domprefs_js {
9230: return <<"END";
9231:
9232: <script type="text/javascript">
9233: // <![CDATA[
9234:
1.150 raeburn 9235: function getIndicesByName(formname,item) {
1.152 raeburn 9236: var group = new Array();
1.150 raeburn 9237: for (var i=0;i<formname.elements.length;i++) {
9238: if (formname.elements[i].name == item) {
1.152 raeburn 9239: group.push(formname.elements[i].id);
1.150 raeburn 9240: }
9241: }
1.152 raeburn 9242: return group;
1.150 raeburn 9243: }
9244:
9245: // ]]>
9246: </script>
9247:
9248: END
1.152 raeburn 9249:
1.150 raeburn 9250: }
9251:
1.160.6.5 raeburn 9252: sub recaptcha_js {
9253: my %lt = &captcha_phrases();
9254: return <<"END";
9255:
9256: <script type="text/javascript">
9257: // <![CDATA[
9258:
9259: function updateCaptcha(caller,context) {
9260: var privitem;
9261: var pubitem;
9262: var privtext;
9263: var pubtext;
9264: if (document.getElementById(context+'_recaptchapub')) {
9265: pubitem = document.getElementById(context+'_recaptchapub');
9266: } else {
9267: return;
9268: }
9269: if (document.getElementById(context+'_recaptchapriv')) {
9270: privitem = document.getElementById(context+'_recaptchapriv');
9271: } else {
9272: return;
9273: }
9274: if (document.getElementById(context+'_recaptchapubtxt')) {
9275: pubtext = document.getElementById(context+'_recaptchapubtxt');
9276: } else {
9277: return;
9278: }
9279: if (document.getElementById(context+'_recaptchaprivtxt')) {
9280: privtext = document.getElementById(context+'_recaptchaprivtxt');
9281: } else {
9282: return;
9283: }
9284: if (caller.checked) {
9285: if (caller.value == 'recaptcha') {
9286: pubitem.type = 'text';
9287: privitem.type = 'text';
9288: pubitem.size = '40';
9289: privitem.size = '40';
9290: pubtext.innerHTML = "$lt{'pub'}";
9291: privtext.innerHTML = "$lt{'priv'}";
9292: } else {
9293: pubitem.type = 'hidden';
9294: privitem.type = 'hidden';
9295: pubtext.innerHTML = '';
9296: privtext.innerHTML = '';
9297: }
9298: }
9299: return;
9300: }
9301:
9302: // ]]>
9303: </script>
9304:
9305: END
9306:
9307: }
9308:
1.160.6.16 raeburn 9309: sub credits_js {
9310: return <<"END";
9311:
9312: <script type="text/javascript">
9313: // <![CDATA[
9314:
9315: function toggleCredits(domForm) {
9316: if (document.getElementById('credits')) {
9317: creditsitem = document.getElementById('credits');
9318: var creditsLength = domForm.coursecredits.length;
9319: if (creditsLength) {
9320: var currval;
9321: for (var i=0; i<creditsLength; i++) {
9322: if (domForm.coursecredits[i].checked) {
9323: currval = domForm.coursecredits[i].value;
9324: }
9325: }
9326: if (currval == 1) {
9327: creditsitem.style.display = 'block';
9328: } else {
9329: creditsitem.style.display = 'none';
9330: }
9331: }
9332: }
9333: return;
9334: }
9335:
9336: // ]]>
9337: </script>
9338:
9339: END
9340:
9341: }
9342:
1.160.6.5 raeburn 9343: sub captcha_phrases {
9344: return &Apache::lonlocal::texthash (
9345: priv => 'Private key',
9346: pub => 'Public key',
9347: original => 'original (CAPTCHA)',
9348: recaptcha => 'successor (ReCAPTCHA)',
9349: notused => 'unused',
9350: );
9351: }
9352:
1.160.6.24 raeburn 9353: sub devalidate_remote_domconfs {
9354: my ($dom) = @_;
9355: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9356: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9357: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9358: my %thismachine;
9359: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
9360: if (keys(%servers) > 1) {
9361: foreach my $server (keys(%servers)) {
9362: next if ($thismachine{$server});
9363: &Apache::lonnet::remote_devalidate_cache($server,'domainconfig',$dom);
9364: }
9365: }
9366: return;
9367: }
9368:
1.3 raeburn 9369: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>