Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.21
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.21! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.20 2013/07/05 19:18:34 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.5 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
99:
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
107: (official, unofficial and community). In each case the radio buttons allow the
108: selection of one of four values:
109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.69 raeburn 168: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 169: use LONCAPA::Enrollment;
1.81 raeburn 170: use LONCAPA::lonauthcgi();
1.9 raeburn 171: use File::Copy;
1.43 raeburn 172: use Locale::Language;
1.62 raeburn 173: use DateTime::TimeZone;
1.68 raeburn 174: use DateTime::Locale;
1.1 raeburn 175:
1.155 raeburn 176: my $registered_cleanup;
177: my $modified_urls;
178:
1.1 raeburn 179: sub handler {
180: my $r=shift;
181: if ($r->header_only) {
182: &Apache::loncommon::content_type($r,'text/html');
183: $r->send_http_header;
184: return OK;
185: }
186:
1.91 raeburn 187: my $context = 'domain';
1.1 raeburn 188: my $dom = $env{'request.role.domain'};
1.5 albertel 189: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 190: if (&Apache::lonnet::allowed('mau',$dom)) {
191: &Apache::loncommon::content_type($r,'text/html');
192: $r->send_http_header;
193: } else {
194: $env{'user.error.msg'}=
195: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
196: return HTTP_NOT_ACCEPTABLE;
197: }
1.155 raeburn 198:
199: $registered_cleanup=0;
200: @{$modified_urls}=();
201:
1.1 raeburn 202: &Apache::lonhtmlcommon::clear_breadcrumbs();
203: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 204: ['phase','actions']);
1.30 raeburn 205: my $phase = 'pickactions';
1.3 raeburn 206: if ( exists($env{'form.phase'}) ) {
207: $phase = $env{'form.phase'};
208: }
1.150 raeburn 209: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 210: my %domconfig =
1.6 raeburn 211: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 212: 'quotas','autoenroll','autoupdate','autocreate',
213: 'directorysrch','usercreation','usermodification',
214: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 215: 'serverstatuses','requestcourses','coursedefaults',
216: 'usersessions','loadbalancing','requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 219: 'usercreation','usermodification','scantron',
1.160.6.5 raeburn 220: 'requestcourses','requestauthor','coursecategories',
1.160.6.16 raeburn 221: 'serverstatuses','coursedefaults','usersessions');
1.160.6.7 raeburn 222: my %existing;
223: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
224: %existing = %{$domconfig{'loadbalancing'}};
225: }
226: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 227: push(@prefs_order,'loadbalancing');
228: }
1.30 raeburn 229: my %prefs = (
230: 'rolecolors' =>
231: { text => 'Default color schemes',
1.67 raeburn 232: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 233: header => [{col1 => 'Student Settings',
234: col2 => '',},
235: {col1 => 'Coordinator Settings',
236: col2 => '',},
237: {col1 => 'Author Settings',
238: col2 => '',},
239: {col1 => 'Administrator Settings',
240: col2 => '',}],
241: },
1.110 raeburn 242: 'login' =>
1.30 raeburn 243: { text => 'Log-in page options',
1.67 raeburn 244: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 245: header => [{col1 => 'Log-in Page Items',
246: col2 => '',},
247: {col1 => 'Log-in Help',
248: col2 => 'Value'}],
1.30 raeburn 249: },
1.43 raeburn 250: 'defaults' =>
1.141 raeburn 251: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 252: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 253: header => [{col1 => 'Setting',
254: col2 => 'Value'}],
255: },
1.30 raeburn 256: 'quotas' =>
1.160.6.20 raeburn 257: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 258: help => 'Domain_Configuration_Quotas',
1.77 raeburn 259: header => [{col1 => 'User affiliation',
1.72 raeburn 260: col2 => 'Available tools',
1.160.6.20 raeburn 261: col3 => 'Quotas, Mb; (Authoring requires role)',}],
1.30 raeburn 262: },
263: 'autoenroll' =>
264: { text => 'Auto-enrollment settings',
1.67 raeburn 265: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 266: header => [{col1 => 'Configuration setting',
267: col2 => 'Value(s)'}],
268: },
269: 'autoupdate' =>
270: { text => 'Auto-update settings',
1.67 raeburn 271: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 272: header => [{col1 => 'Setting',
273: col2 => 'Value',},
1.131 raeburn 274: {col1 => 'Setting',
275: col2 => 'Affiliation'},
1.43 raeburn 276: {col1 => 'User population',
1.131 raeburn 277: col2 => 'Updateable user data'}],
1.30 raeburn 278: },
1.125 raeburn 279: 'autocreate' =>
280: { text => 'Auto-course creation settings',
281: help => 'Domain_Configuration_Auto_Creation',
282: header => [{col1 => 'Configuration Setting',
283: col2 => 'Value',}],
284: },
1.30 raeburn 285: 'directorysrch' =>
286: { text => 'Institutional directory searches',
1.67 raeburn 287: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 288: header => [{col1 => 'Setting',
289: col2 => 'Value',}],
290: },
291: 'contacts' =>
292: { text => 'Contact Information',
1.67 raeburn 293: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 294: header => [{col1 => 'Setting',
295: col2 => 'Value',}],
296: },
297:
298: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.69 raeburn 308: 'usermodification' =>
1.33 raeburn 309: { text => 'User modification',
1.67 raeburn 310: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 311: header => [{col1 => 'Target user has role',
312: col2 => 'User information updateable in author context'},
313: {col1 => 'Target user has role',
1.63 raeburn 314: col2 => 'User information updateable in course context'},
315: {col1 => "Status of user",
316: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 317: },
1.69 raeburn 318: 'scantron' =>
1.95 www 319: { text => 'Bubblesheet format file',
1.67 raeburn 320: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 321: header => [ {col1 => 'Item',
322: col2 => '',
323: }],
324: },
1.86 raeburn 325: 'requestcourses' =>
326: {text => 'Request creation of courses',
327: help => 'Domain_Configuration_Request_Courses',
328: header => [{col1 => 'User affiliation',
1.102 raeburn 329: col2 => 'Availability/Processing of requests',},
330: {col1 => 'Setting',
331: col2 => 'Value'}],
1.86 raeburn 332: },
1.160.6.5 raeburn 333: 'requestauthor' =>
334: {text => 'Request authoring space',
335: help => 'Domain_Configuration_Request_Author',
336: header => [{col1 => 'User affiliation',
337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
339: col2 => 'Value'}],
340: },
1.69 raeburn 341: 'coursecategories' =>
1.120 raeburn 342: { text => 'Cataloging of courses/communities',
1.67 raeburn 343: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 344: header => [{col1 => 'Category settings',
1.57 raeburn 345: col2 => '',},
346: {col1 => 'Categories',
347: col2 => '',
348: }],
1.69 raeburn 349: },
350: 'serverstatuses' =>
1.77 raeburn 351: {text => 'Access to server status pages',
1.69 raeburn 352: help => 'Domain_Configuration_Server_Status',
353: header => [{col1 => 'Status Page',
354: col2 => 'Other named users',
355: col3 => 'Specific IPs',
356: }],
357: },
1.160.6.16 raeburn 358: 'coursedefaults' =>
359: {text => 'Course/Community defaults',
360: help => 'Domain_Configuration_Course_Defaults',
361: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
362: col2 => 'Value',},],
363: },
1.141 raeburn 364: 'usersessions' =>
1.145 raeburn 365: {text => 'User session hosting/offloading',
1.137 raeburn 366: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 367: header => [{col1 => 'Domain server',
368: col2 => 'Servers to offload sessions to when busy'},
369: {col1 => 'Hosting of users from other domains',
1.137 raeburn 370: col2 => 'Rules'},
371: {col1 => "Hosting domain's own users elsewhere",
372: col2 => 'Rules'}],
373: },
1.150 raeburn 374: 'loadbalancing' =>
1.160.6.7 raeburn 375: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 376: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 377: header => [{col1 => 'Balancers',
1.150 raeburn 378: col2 => 'Default destinations',
1.160.6.13 raeburn 379: col3 => 'User affiliation',
1.150 raeburn 380: col4 => 'Overrides'},
381: ],
382: },
1.3 raeburn 383: );
1.110 raeburn 384: if (keys(%servers) > 1) {
385: $prefs{'login'} = { text => 'Log-in page options',
386: help => 'Domain_Configuration_Login_Page',
387: header => [{col1 => 'Log-in Service',
388: col2 => 'Server Setting',},
389: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 390: col2 => ''},
391: {col1 => 'Log-in Help',
392: col2 => 'Value'}],
1.110 raeburn 393: };
394: }
1.160.6.13 raeburn 395:
1.6 raeburn 396: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 397: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 398: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 399: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 400: text=>"Settings to display/modify"});
1.9 raeburn 401: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 402:
1.3 raeburn 403: if ($phase eq 'process') {
1.91 raeburn 404: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 405: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 406: my $js = &recaptcha_js().
407: &credits_js();
1.160.6.7 raeburn 408: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 409: my ($othertitle,$usertypes,$types) =
410: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 411: $js .= &lonbalance_targets_js($dom,$types,\%servers,
412: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 413: &new_spares_js().
414: &common_domprefs_js().
415: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 416: }
1.150 raeburn 417: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 418: } else {
1.160.6.11 raeburn 419: # check if domconfig user exists for the domain.
420: my $servadm = $r->dir_config('lonAdmEMail');
421: my ($configuserok,$author_ok,$switchserver) =
422: &config_check($dom,$confname,$servadm);
423: unless ($configuserok eq 'ok') {
424: &Apache::lonconfigsettings::print_header($r,$phase,$context);
425: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
426: $confname).
427: '<br />'
428: );
429: if ($switchserver) {
430: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
431: '<br />'.
432: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
433: '<br />'.
434: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
435: '<br />'.
436: &mt('To do that now, use the following link: [_1]',$switchserver)
437: );
438: } else {
439: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
440: '<br />'.
441: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
442: );
443: }
444: $r->print(&Apache::loncommon::end_page());
445: return OK;
446: }
1.21 raeburn 447: if (keys(%domconfig) == 0) {
448: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 449: my @ids=&Apache::lonnet::current_machine_ids();
450: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 451: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 452: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 453: my $custom_img_count = 0;
454: foreach my $img (@loginimages) {
455: if ($designhash{$dom.'.login.'.$img} ne '') {
456: $custom_img_count ++;
457: }
458: }
459: foreach my $role (@roles) {
460: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
461: $custom_img_count ++;
462: }
463: }
464: if ($custom_img_count > 0) {
1.94 raeburn 465: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 466: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 467: $r->print(
468: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
469: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
470: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
471: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
472: if ($switch_server) {
1.30 raeburn 473: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 474: }
1.91 raeburn 475: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 476: return OK;
477: }
478: }
479: }
1.91 raeburn 480: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 481: }
482: return OK;
483: }
484:
485: sub process_changes {
1.92 raeburn 486: my ($r,$dom,$confname,$action,$roles,$values) = @_;
487: my %domconfig;
488: if (ref($values) eq 'HASH') {
489: %domconfig = %{$values};
490: }
1.3 raeburn 491: my $output;
492: if ($action eq 'login') {
1.9 raeburn 493: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 494: } elsif ($action eq 'rolecolors') {
1.9 raeburn 495: $output = &modify_rolecolors($r,$dom,$confname,$roles,
496: %domconfig);
1.3 raeburn 497: } elsif ($action eq 'quotas') {
1.86 raeburn 498: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 499: } elsif ($action eq 'autoenroll') {
500: $output = &modify_autoenroll($dom,%domconfig);
501: } elsif ($action eq 'autoupdate') {
502: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 503: } elsif ($action eq 'autocreate') {
504: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 505: } elsif ($action eq 'directorysrch') {
506: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 507: } elsif ($action eq 'usercreation') {
1.28 raeburn 508: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 509: } elsif ($action eq 'usermodification') {
510: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 511: } elsif ($action eq 'contacts') {
512: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 513: } elsif ($action eq 'defaults') {
514: $output = &modify_defaults($dom,$r);
1.46 raeburn 515: } elsif ($action eq 'scantron') {
1.48 raeburn 516: $output = &modify_scantron($r,$dom,$confname,%domconfig);
517: } elsif ($action eq 'coursecategories') {
518: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 519: } elsif ($action eq 'serverstatuses') {
520: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 521: } elsif ($action eq 'requestcourses') {
522: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.5 raeburn 523: } elsif ($action eq 'requestauthor') {
524: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.16 raeburn 525: } elsif ($action eq 'coursedefaults') {
526: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 527: } elsif ($action eq 'usersessions') {
528: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 529: } elsif ($action eq 'loadbalancing') {
530: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 531: }
532: return $output;
533: }
534:
535: sub print_config_box {
1.9 raeburn 536: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 537: my $rowtotal = 0;
1.49 raeburn 538: my $output;
539: if ($action eq 'coursecategories') {
540: $output = &coursecategories_javascript($settings);
1.91 raeburn 541: }
1.49 raeburn 542: $output .=
1.30 raeburn 543: '<table class="LC_nested_outer">
1.3 raeburn 544: <tr>
1.66 raeburn 545: <th align="left" valign="middle"><span class="LC_nobreak">'.
546: &mt($item->{text}).' '.
547: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
548: '</tr>';
1.30 raeburn 549: $rowtotal ++;
1.110 raeburn 550: my $numheaders = 1;
551: if (ref($item->{'header'}) eq 'ARRAY') {
552: $numheaders = scalar(@{$item->{'header'}});
553: }
554: if ($numheaders > 1) {
1.64 raeburn 555: my $colspan = '';
1.145 raeburn 556: my $rightcolspan = '';
1.160.6.5 raeburn 557: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
558: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 559: $colspan = ' colspan="2"';
560: }
1.145 raeburn 561: if ($action eq 'usersessions') {
562: $rightcolspan = ' colspan="3"';
563: }
1.30 raeburn 564: $output .= '
1.3 raeburn 565: <tr>
566: <td>
567: <table class="LC_nested">
568: <tr class="LC_info_row">
1.59 bisitz 569: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 570: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 571: </tr>';
1.69 raeburn 572: $rowtotal ++;
1.6 raeburn 573: if ($action eq 'autoupdate') {
1.30 raeburn 574: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 575: } elsif ($action eq 'usercreation') {
1.33 raeburn 576: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
577: } elsif ($action eq 'usermodification') {
578: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 579: } elsif ($action eq 'coursecategories') {
580: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 581: } elsif ($action eq 'login') {
1.160.6.5 raeburn 582: if ($numheaders == 3) {
583: $colspan = ' colspan="2"';
584: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
585: } else {
586: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
587: }
1.102 raeburn 588: } elsif ($action eq 'requestcourses') {
589: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 590: } elsif ($action eq 'requestauthor') {
591: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 592: } elsif ($action eq 'usersessions') {
593: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 594: } elsif ($action eq 'rolecolors') {
1.30 raeburn 595: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 596: }
1.30 raeburn 597: $output .= '
1.6 raeburn 598: </table>
599: </td>
600: </tr>
601: <tr>
602: <td>
603: <table class="LC_nested">
604: <tr class="LC_info_row">
1.59 bisitz 605: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 606: $output .= '
1.59 bisitz 607: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 608: </tr>';
609: $rowtotal ++;
1.6 raeburn 610: if ($action eq 'autoupdate') {
1.131 raeburn 611: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
612: </table>
613: </td>
614: </tr>
615: <tr>
616: <td>
617: <table class="LC_nested">
618: <tr class="LC_info_row">
619: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
620: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
621: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
622: $rowtotal ++;
1.28 raeburn 623: } elsif ($action eq 'usercreation') {
1.34 raeburn 624: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
625: </table>
626: </td>
627: </tr>
628: <tr>
629: <td>
630: <table class="LC_nested">
631: <tr class="LC_info_row">
1.59 bisitz 632: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
633: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 634: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
635: $rowtotal ++;
1.33 raeburn 636: } elsif ($action eq 'usermodification') {
1.63 raeburn 637: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
638: </table>
639: </td>
640: </tr>
641: <tr>
642: <td>
643: <table class="LC_nested">
644: <tr class="LC_info_row">
645: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
646: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
647: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
648: $rowtotal ++;
1.57 raeburn 649: } elsif ($action eq 'coursecategories') {
650: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 651: } elsif ($action eq 'login') {
1.160.6.5 raeburn 652: if ($numheaders == 3) {
653: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
654: </table>
655: </td>
656: </tr>
657: <tr>
658: <td>
659: <table class="LC_nested">
660: <tr class="LC_info_row">
661: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
662: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
663: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
664: $rowtotal ++;
665: } else {
666: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
667: }
1.102 raeburn 668: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 669: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
670: } elsif ($action eq 'requestauthor') {
671: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 672: } elsif ($action eq 'usersessions') {
1.145 raeburn 673: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
674: </table>
675: </td>
676: </tr>
677: <tr>
678: <td>
679: <table class="LC_nested">
680: <tr class="LC_info_row">
681: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
682: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
683: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
684: $rowtotal ++;
1.122 jms 685: } elsif ($action eq 'rolecolors') {
1.30 raeburn 686: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 687: </table>
688: </td>
689: </tr>
690: <tr>
691: <td>
692: <table class="LC_nested">
693: <tr class="LC_info_row">
1.69 raeburn 694: <td class="LC_left_item"'.$colspan.' valign="top">'.
695: &mt($item->{'header'}->[2]->{'col1'}).'</td>
696: <td class="LC_right_item" valign="top">'.
697: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 698: </tr>'.
1.30 raeburn 699: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 700: </table>
701: </td>
702: </tr>
703: <tr>
704: <td>
705: <table class="LC_nested">
706: <tr class="LC_info_row">
1.59 bisitz 707: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
708: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 709: </tr>'.
1.30 raeburn 710: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
711: $rowtotal += 2;
1.6 raeburn 712: }
1.3 raeburn 713: } else {
1.30 raeburn 714: $output .= '
1.3 raeburn 715: <tr>
716: <td>
717: <table class="LC_nested">
1.30 raeburn 718: <tr class="LC_info_row">';
1.24 raeburn 719: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 720: $output .= '
1.59 bisitz 721: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 722: } elsif ($action eq 'serverstatuses') {
723: $output .= '
724: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
725: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
726:
1.6 raeburn 727: } else {
1.30 raeburn 728: $output .= '
1.69 raeburn 729: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
730: }
1.72 raeburn 731: if (defined($item->{'header'}->[0]->{'col3'})) {
732: $output .= '<td class="LC_left_item" valign="top">'.
733: &mt($item->{'header'}->[0]->{'col2'});
734: if ($action eq 'serverstatuses') {
735: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
736: }
1.69 raeburn 737: } else {
738: $output .= '<td class="LC_right_item" valign="top">'.
739: &mt($item->{'header'}->[0]->{'col2'});
740: }
741: $output .= '</td>';
742: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 743: if (defined($item->{'header'}->[0]->{'col4'})) {
744: $output .= '<td class="LC_left_item" valign="top">'.
745: &mt($item->{'header'}->[0]->{'col3'});
746: } else {
747: $output .= '<td class="LC_right_item" valign="top">'.
748: &mt($item->{'header'}->[0]->{'col3'});
749: }
1.69 raeburn 750: if ($action eq 'serverstatuses') {
751: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
752: }
753: $output .= '</td>';
1.6 raeburn 754: }
1.150 raeburn 755: if ($item->{'header'}->[0]->{'col4'}) {
756: $output .= '<td class="LC_right_item" valign="top">'.
757: &mt($item->{'header'}->[0]->{'col4'});
758: }
1.69 raeburn 759: $output .= '</tr>';
1.48 raeburn 760: $rowtotal ++;
1.160.6.5 raeburn 761: if ($action eq 'quotas') {
1.86 raeburn 762: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 763: } elsif ($action eq 'autoenroll') {
1.30 raeburn 764: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 765: } elsif ($action eq 'autocreate') {
766: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 767: } elsif ($action eq 'directorysrch') {
1.30 raeburn 768: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 769: } elsif ($action eq 'contacts') {
1.30 raeburn 770: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 771: } elsif ($action eq 'defaults') {
772: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 773: } elsif ($action eq 'scantron') {
774: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 775: } elsif ($action eq 'serverstatuses') {
776: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 777: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 778: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 779: } elsif ($action eq 'loadbalancing') {
780: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.160.6.16 raeburn 781: } elsif ($action eq 'coursedefaults') {
782: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 783: }
1.3 raeburn 784: }
1.30 raeburn 785: $output .= '
1.3 raeburn 786: </table>
787: </td>
788: </tr>
1.30 raeburn 789: </table><br />';
790: return ($output,$rowtotal);
1.1 raeburn 791: }
792:
1.3 raeburn 793: sub print_login {
1.160.6.5 raeburn 794: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 795: my ($css_class,$datatable);
1.6 raeburn 796: my %choices = &login_choices();
1.110 raeburn 797:
1.160.6.5 raeburn 798: if ($caller eq 'service') {
1.149 raeburn 799: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 800: my $choice = $choices{'disallowlogin'};
801: $css_class = ' class="LC_odd_row"';
1.128 raeburn 802: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 803: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 804: '<th>'.$choices{'server'}.'</th>'.
805: '<th>'.$choices{'serverpath'}.'</th>'.
806: '<th>'.$choices{'custompath'}.'</th>'.
807: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 808: my %disallowed;
809: if (ref($settings) eq 'HASH') {
810: if (ref($settings->{'loginvia'}) eq 'HASH') {
811: %disallowed = %{$settings->{'loginvia'}};
812: }
813: }
814: foreach my $lonhost (sort(keys(%servers))) {
815: my $direct = 'selected="selected"';
1.128 raeburn 816: if (ref($disallowed{$lonhost}) eq 'HASH') {
817: if ($disallowed{$lonhost}{'server'} ne '') {
818: $direct = '';
819: }
1.110 raeburn 820: }
1.115 raeburn 821: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 822: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 823: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
824: '</option>';
1.160.6.13 raeburn 825: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 826: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 827: my $selected = '';
1.128 raeburn 828: if (ref($disallowed{$lonhost}) eq 'HASH') {
829: if ($hostid eq $disallowed{$lonhost}{'server'}) {
830: $selected = 'selected="selected"';
831: }
1.110 raeburn 832: }
833: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
834: $servers{$hostid}.'</option>';
835: }
1.128 raeburn 836: $datatable .= '</select></td>'.
837: '<td><select name="'.$lonhost.'_serverpath">';
838: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
839: my $pathname = $path;
840: if ($path eq 'custom') {
841: $pathname = &mt('Custom Path').' ->';
842: }
843: my $selected = '';
844: if (ref($disallowed{$lonhost}) eq 'HASH') {
845: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
846: $selected = 'selected="selected"';
847: }
848: } elsif ($path eq '') {
849: $selected = 'selected="selected"';
850: }
851: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
852: }
853: $datatable .= '</select></td>';
854: my ($custom,$exempt);
855: if (ref($disallowed{$lonhost}) eq 'HASH') {
856: $custom = $disallowed{$lonhost}{'custompath'};
857: $exempt = $disallowed{$lonhost}{'exempt'};
858: }
859: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
860: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
861: '</tr>';
1.110 raeburn 862: }
863: $datatable .= '</table></td></tr>';
864: return $datatable;
1.160.6.5 raeburn 865: } elsif ($caller eq 'page') {
866: my %defaultchecked = (
867: 'coursecatalog' => 'on',
1.160.6.14 raeburn 868: 'helpdesk' => 'on',
1.160.6.5 raeburn 869: 'adminmail' => 'off',
870: 'newuser' => 'off',
871: );
1.160.6.14 raeburn 872: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 873: my (%checkedon,%checkedoff);
1.42 raeburn 874: foreach my $item (@toggles) {
1.160.6.5 raeburn 875: if ($defaultchecked{$item} eq 'on') {
876: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 877: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 878: } elsif ($defaultchecked{$item} eq 'off') {
879: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 880: $checkedon{$item} = ' ';
881: }
1.1 raeburn 882: }
1.160.6.5 raeburn 883: my @images = ('img','logo','domlogo','login');
884: my @logintext = ('textcol','bgcol');
885: my @bgs = ('pgbg','mainbg','sidebg');
886: my @links = ('link','alink','vlink');
887: my %designhash = &Apache::loncommon::get_domainconf($dom);
888: my %defaultdesign = %Apache::loncommon::defaultdesign;
889: my (%is_custom,%designs);
890: my %defaults = (
891: font => $defaultdesign{'login.font'},
892: );
1.6 raeburn 893: foreach my $item (@images) {
1.160.6.5 raeburn 894: $defaults{$item} = $defaultdesign{'login.'.$item};
895: $defaults{'showlogo'}{$item} = 1;
896: }
897: foreach my $item (@bgs) {
898: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 899: }
1.41 raeburn 900: foreach my $item (@logintext) {
1.160.6.5 raeburn 901: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 902: }
1.160.6.5 raeburn 903: foreach my $item (@links) {
904: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 905: }
1.160.6.5 raeburn 906: if (ref($settings) eq 'HASH') {
907: foreach my $item (@toggles) {
908: if ($settings->{$item} eq '1') {
909: $checkedon{$item} = ' checked="checked" ';
910: $checkedoff{$item} = ' ';
911: } elsif ($settings->{$item} eq '0') {
912: $checkedoff{$item} = ' checked="checked" ';
913: $checkedon{$item} = ' ';
914: }
1.6 raeburn 915: }
1.160.6.5 raeburn 916: foreach my $item (@images) {
917: if (defined($settings->{$item})) {
918: $designs{$item} = $settings->{$item};
919: $is_custom{$item} = 1;
920: }
921: if (defined($settings->{'showlogo'}{$item})) {
922: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
923: }
924: }
925: foreach my $item (@logintext) {
926: if ($settings->{$item} ne '') {
927: $designs{'logintext'}{$item} = $settings->{$item};
928: $is_custom{$item} = 1;
929: }
930: }
931: if ($settings->{'font'} ne '') {
932: $designs{'font'} = $settings->{'font'};
933: $is_custom{'font'} = 1;
934: }
935: foreach my $item (@bgs) {
936: if ($settings->{$item} ne '') {
937: $designs{'bgs'}{$item} = $settings->{$item};
938: $is_custom{$item} = 1;
939: }
940: }
941: foreach my $item (@links) {
942: if ($settings->{$item} ne '') {
943: $designs{'links'}{$item} = $settings->{$item};
944: $is_custom{$item} = 1;
945: }
946: }
947: } else {
948: if ($designhash{$dom.'.login.font'} ne '') {
949: $designs{'font'} = $designhash{$dom.'.login.font'};
950: $is_custom{'font'} = 1;
951: }
952: foreach my $item (@images) {
953: if ($designhash{$dom.'.login.'.$item} ne '') {
954: $designs{$item} = $designhash{$dom.'.login.'.$item};
955: $is_custom{$item} = 1;
956: }
957: }
958: foreach my $item (@bgs) {
959: if ($designhash{$dom.'.login.'.$item} ne '') {
960: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
961: $is_custom{$item} = 1;
962: }
963: }
964: foreach my $item (@links) {
965: if ($designhash{$dom.'.login.'.$item} ne '') {
966: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
967: $is_custom{$item} = 1;
968: }
1.6 raeburn 969: }
970: }
1.160.6.5 raeburn 971: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
972: logo => 'Institution Logo',
973: domlogo => 'Domain Logo',
974: login => 'Login box');
975: my $itemcount = 1;
976: foreach my $item (@toggles) {
977: $css_class = $itemcount%2?' class="LC_odd_row"':'';
978: $datatable .=
979: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
980: '</td><td>'.
981: '<span class="LC_nobreak"><label><input type="radio" name="'.
982: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
983: '</label> <label><input type="radio" name="'.$item.'"'.
984: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
985: '</tr>';
986: $itemcount ++;
1.6 raeburn 987: }
1.160.6.5 raeburn 988: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
989: $datatable .= '</tr></table></td></tr>';
990: } elsif ($caller eq 'help') {
991: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
992: my $switchserver = &check_switchserver($dom,$confname);
993: my $itemcount = 1;
994: $defaulturl = '/adm/loginproblems.html';
995: $defaulttype = 'default';
996: %lt = &Apache::lonlocal::texthash (
997: del => 'Delete?',
998: rep => 'Replace:',
999: upl => 'Upload:',
1000: default => 'Default',
1001: custom => 'Custom',
1002: );
1003: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1004: my @currlangs;
1005: if (ref($settings) eq 'HASH') {
1006: if (ref($settings->{'helpurl'}) eq 'HASH') {
1007: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1008: next if ($settings->{'helpurl'}{$key} eq '');
1009: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1010: $type{$key} = 'custom';
1011: unless ($key eq 'nolang') {
1012: push(@currlangs,$key);
1013: }
1014: }
1015: } elsif ($settings->{'helpurl'} ne '') {
1016: $type{'nolang'} = 'custom';
1017: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1018: }
1019: }
1.160.6.5 raeburn 1020: foreach my $lang ('nolang',sort(@currlangs)) {
1021: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1022: $datatable .= '<tr'.$css_class.'>';
1023: if ($url{$lang} eq '') {
1024: $url{$lang} = $defaulturl;
1025: }
1026: if ($type{$lang} eq '') {
1027: $type{$lang} = $defaulttype;
1028: }
1029: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1030: if ($lang eq 'nolang') {
1031: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1032: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1033: } else {
1034: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1035: $langchoices{$lang},
1036: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1037: }
1038: $datatable .= '</span></td>'."\n".
1039: '<td class="LC_left_item">';
1040: if ($type{$lang} eq 'custom') {
1041: $datatable .= '<span class="LC_nobreak"><label>'.
1042: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1043: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1044: } else {
1045: $datatable .= $lt{'upl'};
1046: }
1047: $datatable .='<br />';
1048: if ($switchserver) {
1049: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1050: } else {
1051: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1052: }
1.160.6.5 raeburn 1053: $datatable .= '</td></tr>';
1054: $itemcount ++;
1.6 raeburn 1055: }
1.160.6.5 raeburn 1056: my @addlangs;
1057: foreach my $lang (sort(keys(%langchoices))) {
1058: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1059: push(@addlangs,$lang);
1060: }
1061: if (@addlangs > 0) {
1062: my %toadd;
1063: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1064: $toadd{''} = &mt('Select');
1065: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1066: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1067: &mt('Add log-in help page for a specific language:').' '.
1068: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1069: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1070: if ($switchserver) {
1071: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1072: } else {
1073: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1074: }
1.160.6.5 raeburn 1075: $datatable .= '</td></tr>';
1076: $itemcount ++;
1.6 raeburn 1077: }
1.160.6.5 raeburn 1078: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1079: }
1.6 raeburn 1080: return $datatable;
1081: }
1082:
1083: sub login_choices {
1084: my %choices =
1085: &Apache::lonlocal::texthash (
1.116 bisitz 1086: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1087: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1088: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1089: disallowlogin => "Login page requests redirected",
1090: hostid => "Server",
1.128 raeburn 1091: server => "Redirect to:",
1092: serverpath => "Path",
1093: custompath => "Custom",
1094: exempt => "Exempt IP(s)",
1.110 raeburn 1095: directlogin => "No redirect",
1096: newuser => "Link to create a user account",
1097: img => "Header",
1098: logo => "Main Logo",
1099: domlogo => "Domain Logo",
1100: login => "Log-in Header",
1101: textcol => "Text color",
1102: bgcol => "Box color",
1103: bgs => "Background colors",
1104: links => "Link colors",
1105: font => "Font color",
1106: pgbg => "Header",
1107: mainbg => "Page",
1108: sidebg => "Login box",
1109: link => "Link",
1110: alink => "Active link",
1111: vlink => "Visited link",
1.6 raeburn 1112: );
1113: return %choices;
1114: }
1115:
1116: sub print_rolecolors {
1.30 raeburn 1117: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1118: my %choices = &color_font_choices();
1119: my @bgs = ('pgbg','tabbg','sidebg');
1120: my @links = ('link','alink','vlink');
1121: my @images = ('img');
1122: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1123: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1124: my %defaultdesign = %Apache::loncommon::defaultdesign;
1125: my (%is_custom,%designs);
1126: my %defaults = (
1127: img => $defaultdesign{$role.'.img'},
1128: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1129: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1130: );
1131: foreach my $item (@bgs) {
1132: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1133: }
1134: foreach my $item (@links) {
1135: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1136: }
1137: if (ref($settings) eq 'HASH') {
1138: if (ref($settings->{$role}) eq 'HASH') {
1139: if ($settings->{$role}->{'img'} ne '') {
1140: $designs{'img'} = $settings->{$role}->{'img'};
1141: $is_custom{'img'} = 1;
1142: }
1143: if ($settings->{$role}->{'font'} ne '') {
1144: $designs{'font'} = $settings->{$role}->{'font'};
1145: $is_custom{'font'} = 1;
1146: }
1.97 tempelho 1147: if ($settings->{$role}->{'fontmenu'} ne '') {
1148: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1149: $is_custom{'fontmenu'} = 1;
1150: }
1.6 raeburn 1151: foreach my $item (@bgs) {
1152: if ($settings->{$role}->{$item} ne '') {
1153: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1154: $is_custom{$item} = 1;
1155: }
1156: }
1157: foreach my $item (@links) {
1158: if ($settings->{$role}->{$item} ne '') {
1159: $designs{'links'}{$item} = $settings->{$role}->{$item};
1160: $is_custom{$item} = 1;
1161: }
1162: }
1163: }
1164: } else {
1165: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1166: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1167: $is_custom{'img'} = 1;
1168: }
1.97 tempelho 1169: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1170: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1171: $is_custom{'fontmenu'} = 1;
1172: }
1.6 raeburn 1173: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1174: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1175: $is_custom{'font'} = 1;
1176: }
1177: foreach my $item (@bgs) {
1178: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1179: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1180: $is_custom{$item} = 1;
1181:
1182: }
1183: }
1184: foreach my $item (@links) {
1185: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1186: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1187: $is_custom{$item} = 1;
1188: }
1189: }
1190: }
1191: my $itemcount = 1;
1.30 raeburn 1192: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1193: $datatable .= '</tr></table></td></tr>';
1194: return $datatable;
1195: }
1196:
1197: sub display_color_options {
1.9 raeburn 1198: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1199: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1200: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1201: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1202: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1203: '<td>'.$choices->{'font'}.'</td>';
1204: if (!$is_custom->{'font'}) {
1.30 raeburn 1205: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1206: } else {
1207: $datatable .= '<td> </td>';
1208: }
1.160.6.9 raeburn 1209: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1210:
1.8 raeburn 1211: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1212: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1213: ' value="'.$current_color.'" /> '.
1214: ' </td></tr>';
1.107 raeburn 1215: unless ($role eq 'login') {
1216: $datatable .= '<tr'.$css_class.'>'.
1217: '<td>'.$choices->{'fontmenu'}.'</td>';
1218: if (!$is_custom->{'fontmenu'}) {
1219: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1220: } else {
1221: $datatable .= '<td> </td>';
1222: }
1.160.6.9 raeburn 1223: $current_color = $designs->{'fontmenu'} ?
1224: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1225: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1226: '<input class="colorchooser" type="text" size="10" name="'
1227: .$role.'_fontmenu"'.
1228: ' value="'.$current_color.'" /> '.
1229: ' </td></tr>';
1.97 tempelho 1230: }
1.9 raeburn 1231: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1232: foreach my $img (@{$images}) {
1.18 albertel 1233: $itemcount ++;
1.6 raeburn 1234: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1235: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1236: '<td>'.$choices->{$img};
1.41 raeburn 1237: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1238: if ($role eq 'login') {
1239: if ($img eq 'login') {
1240: $login_hdr_pick =
1.135 bisitz 1241: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1242: $logincolors =
1243: &login_text_colors($img,$role,$logintext,$phase,$choices,
1244: $designs);
1245: } elsif ($img ne 'domlogo') {
1246: $datatable.= &logo_display_options($img,$defaults,$designs);
1247: }
1248: }
1249: $datatable .= '</td>';
1.6 raeburn 1250: if ($designs->{$img} ne '') {
1251: $imgfile = $designs->{$img};
1.18 albertel 1252: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1253: } else {
1254: $imgfile = $defaults->{$img};
1255: }
1256: if ($imgfile) {
1.9 raeburn 1257: my ($showfile,$fullsize);
1258: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1259: my $urldir = $1;
1260: my $filename = $2;
1261: my @info = &Apache::lonnet::stat_file($designs->{$img});
1262: if (@info) {
1263: my $thumbfile = 'tn-'.$filename;
1264: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1265: if (@thumb) {
1266: $showfile = $urldir.'/'.$thumbfile;
1267: } else {
1268: $showfile = $imgfile;
1269: }
1270: } else {
1271: $showfile = '';
1272: }
1273: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1274: $showfile = $imgfile;
1.6 raeburn 1275: my $imgdir = $1;
1276: my $filename = $2;
1.159 raeburn 1277: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1278: $showfile = "/$imgdir/tn-".$filename;
1279: } else {
1.159 raeburn 1280: my $input = $londocroot.$imgfile;
1281: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1282: if (!-e $output) {
1.9 raeburn 1283: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1284: my ($fullwidth,$fullheight) = &check_dimensions($input);
1285: if ($fullwidth ne '' && $fullheight ne '') {
1286: if ($fullwidth > $width && $fullheight > $height) {
1287: my $size = $width.'x'.$height;
1288: system("convert -sample $size $input $output");
1.159 raeburn 1289: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1290: }
1291: }
1.6 raeburn 1292: }
1293: }
1.16 raeburn 1294: }
1.6 raeburn 1295: if ($showfile) {
1.40 raeburn 1296: if ($showfile =~ m{^/(adm|res)/}) {
1297: if ($showfile =~ m{^/res/}) {
1298: my $local_showfile =
1299: &Apache::lonnet::filelocation('',$showfile);
1300: &Apache::lonnet::repcopy($local_showfile);
1301: }
1302: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1303: }
1304: if ($imgfile) {
1305: if ($imgfile =~ m{^/(adm|res)/}) {
1306: if ($imgfile =~ m{^/res/}) {
1307: my $local_imgfile =
1308: &Apache::lonnet::filelocation('',$imgfile);
1309: &Apache::lonnet::repcopy($local_imgfile);
1310: }
1311: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1312: } else {
1313: $fullsize = $imgfile;
1314: }
1315: }
1.41 raeburn 1316: $datatable .= '<td>';
1317: if ($img eq 'login') {
1.135 bisitz 1318: $datatable .= $login_hdr_pick;
1319: }
1.41 raeburn 1320: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1321: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1322: } else {
1323: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1324: &mt('Upload:');
1325: }
1326: } else {
1327: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1328: &mt('Upload:');
1329: }
1.9 raeburn 1330: if ($switchserver) {
1331: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1332: } else {
1.135 bisitz 1333: if ($img ne 'login') { # suppress file selection for Log-in header
1334: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1335: }
1.9 raeburn 1336: }
1337: $datatable .= '</td></tr>';
1.6 raeburn 1338: }
1339: $itemcount ++;
1340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1341: $datatable .= '<tr'.$css_class.'>'.
1342: '<td>'.$choices->{'bgs'}.'</td>';
1343: my $bgs_def;
1344: foreach my $item (@{$bgs}) {
1345: if (!$is_custom->{$item}) {
1.70 raeburn 1346: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1347: }
1348: }
1349: if ($bgs_def) {
1.8 raeburn 1350: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1351: } else {
1352: $datatable .= '<td> </td>';
1353: }
1354: $datatable .= '<td class="LC_right_item">'.
1355: '<table border="0"><tr>';
1.160.6.13 raeburn 1356:
1.6 raeburn 1357: foreach my $item (@{$bgs}) {
1.160.6.9 raeburn 1358: $datatable .= '<td align="center">';
1359: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1360: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1361: $datatable .= ' ';
1.6 raeburn 1362: }
1.160.6.9 raeburn 1363: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1364: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1365: }
1366: $datatable .= '</tr></table></td></tr>';
1367: $itemcount ++;
1368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1369: $datatable .= '<tr'.$css_class.'>'.
1370: '<td>'.$choices->{'links'}.'</td>';
1371: my $links_def;
1372: foreach my $item (@{$links}) {
1373: if (!$is_custom->{$item}) {
1.30 raeburn 1374: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1375: }
1376: }
1377: if ($links_def) {
1.8 raeburn 1378: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1379: } else {
1380: $datatable .= '<td> </td>';
1381: }
1382: $datatable .= '<td class="LC_right_item">'.
1383: '<table border="0"><tr>';
1384: foreach my $item (@{$links}) {
1.160.6.9 raeburn 1385: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1386: $datatable .= '<td align="center">'."\n";
1387:
1.6 raeburn 1388: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1389: $datatable.=' ';
1.6 raeburn 1390: }
1.160.6.9 raeburn 1391: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1392: '" /></td>';
1393: }
1.30 raeburn 1394: $$rowtotal += $itemcount;
1.3 raeburn 1395: return $datatable;
1396: }
1397:
1.70 raeburn 1398: sub logo_display_options {
1399: my ($img,$defaults,$designs) = @_;
1400: my $checkedon;
1401: if (ref($defaults) eq 'HASH') {
1402: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1403: if ($defaults->{'showlogo'}{$img}) {
1404: $checkedon = 'checked="checked" ';
1405: }
1406: }
1407: }
1408: if (ref($designs) eq 'HASH') {
1409: if (ref($designs->{'showlogo'}) eq 'HASH') {
1410: if (defined($designs->{'showlogo'}{$img})) {
1411: if ($designs->{'showlogo'}{$img} == 0) {
1412: $checkedon = '';
1413: } elsif ($designs->{'showlogo'}{$img} == 1) {
1414: $checkedon = 'checked="checked" ';
1415: }
1416: }
1417: }
1418: }
1419: return '<br /><label> <input type="checkbox" name="'.
1420: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1421: &mt('show').'</label>'."\n";
1422: }
1423:
1.41 raeburn 1424: sub login_header_options {
1.135 bisitz 1425: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1426: my $output = '';
1.41 raeburn 1427: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1428: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1429: if (!$is_custom->{'textcol'}) {
1430: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1431: ' ';
1432: }
1433: if (!$is_custom->{'bgcol'}) {
1434: $output .= $choices->{'bgcol'}.': '.
1435: '<span id="css_'.$role.'_font" style="background-color: '.
1436: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1437: }
1438: $output .= '<br />';
1439: }
1440: $output .='<br />';
1441: return $output;
1442: }
1443:
1444: sub login_text_colors {
1445: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1446: my $color_menu = '<table border="0"><tr>';
1447: foreach my $item (@{$logintext}) {
1448: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1449: $color_menu .= '<td align="center">'.$link;
1450: if ($designs->{'logintext'}{$item}) {
1451: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1452: }
1453: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1454: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1455: '<td> </td>';
1456: }
1457: $color_menu .= '</tr></table><br />';
1458: return $color_menu;
1459: }
1460:
1461: sub image_changes {
1462: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1463: my $output;
1.135 bisitz 1464: if ($img eq 'login') {
1465: # suppress image for Log-in header
1466: } elsif (!$is_custom) {
1.70 raeburn 1467: if ($img ne 'domlogo') {
1.41 raeburn 1468: $output .= &mt('Default image:').'<br />';
1469: } else {
1470: $output .= &mt('Default in use:').'<br />';
1471: }
1472: }
1.135 bisitz 1473: if ($img eq 'login') { # suppress image for Log-in header
1474: $output .= '<td>'.$logincolors;
1.41 raeburn 1475: } else {
1.135 bisitz 1476: if ($img_import) {
1477: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1478: }
1479: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1480: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1481: if ($is_custom) {
1482: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1483: '<input type="checkbox" name="'.
1484: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1485: '</label> '.&mt('Replace:').'</span><br />';
1486: } else {
1487: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1488: }
1.41 raeburn 1489: }
1490: return $output;
1491: }
1492:
1.6 raeburn 1493: sub color_pick {
1494: my ($phase,$role,$item,$desc,$curcol) = @_;
1495: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1496: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1497: ');">'.$desc.'</a>';
1498: return $link;
1499: }
1500:
1.3 raeburn 1501: sub print_quotas {
1.86 raeburn 1502: my ($dom,$settings,$rowtotal,$action) = @_;
1503: my $context;
1504: if ($action eq 'quotas') {
1505: $context = 'tools';
1506: } else {
1507: $context = $action;
1508: }
1.160.6.20 raeburn 1509: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1510: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1511: my $typecount = 0;
1.101 raeburn 1512: my ($css_class,%titles);
1.86 raeburn 1513: if ($context eq 'requestcourses') {
1.98 raeburn 1514: @usertools = ('official','unofficial','community');
1.106 raeburn 1515: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1516: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1517: %titles = &courserequest_titles();
1.160.6.5 raeburn 1518: } elsif ($context eq 'requestauthor') {
1519: @usertools = ('author');
1520: @options = ('norequest','approval','automatic');
1521: %titles = &authorrequest_titles();
1.86 raeburn 1522: } else {
1.160.6.4 raeburn 1523: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1524: %titles = &tool_titles();
1.86 raeburn 1525: }
1.26 raeburn 1526: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1527: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1528: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1529: unless (($context eq 'requestcourses') ||
1530: ($context eq 'requestauthor')) {
1.86 raeburn 1531: if (ref($settings) eq 'HASH') {
1532: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1533: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1534: } else {
1535: $currdefquota = $settings->{$type};
1536: }
1.160.6.20 raeburn 1537: if (ref($settings->{authorquota}) eq 'HASH') {
1538: $currauthorquota = $settings->{authorquota}->{$type};
1539: }
1.78 raeburn 1540: }
1.72 raeburn 1541: }
1.3 raeburn 1542: if (defined($usertypes->{$type})) {
1543: $typecount ++;
1544: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1545: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1546: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1547: '<td class="LC_left_item">';
1.101 raeburn 1548: if ($context eq 'requestcourses') {
1549: $datatable .= '<table><tr>';
1550: }
1551: my %cell;
1.72 raeburn 1552: foreach my $item (@usertools) {
1.101 raeburn 1553: if ($context eq 'requestcourses') {
1554: my ($curroption,$currlimit);
1555: if (ref($settings) eq 'HASH') {
1556: if (ref($settings->{$item}) eq 'HASH') {
1557: $curroption = $settings->{$item}->{$type};
1558: if ($curroption =~ /^autolimit=(\d*)$/) {
1559: $currlimit = $1;
1560: }
1561: }
1562: }
1563: if (!$curroption) {
1564: $curroption = 'norequest';
1565: }
1566: $datatable .= '<th>'.$titles{$item}.'</th>';
1567: foreach my $option (@options) {
1568: my $val = $option;
1569: if ($option eq 'norequest') {
1570: $val = 0;
1571: }
1572: if ($option eq 'validate') {
1573: my $canvalidate = 0;
1574: if (ref($validations{$item}) eq 'HASH') {
1575: if ($validations{$item}{$type}) {
1576: $canvalidate = 1;
1577: }
1578: }
1579: next if (!$canvalidate);
1580: }
1581: my $checked = '';
1582: if ($option eq $curroption) {
1583: $checked = ' checked="checked"';
1584: } elsif ($option eq 'autolimit') {
1585: if ($curroption =~ /^autolimit/) {
1586: $checked = ' checked="checked"';
1587: }
1588: }
1589: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1590: '<input type="radio" name="crsreq_'.$item.
1591: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1592: $titles{$option}.'</label>';
1.101 raeburn 1593: if ($option eq 'autolimit') {
1.127 raeburn 1594: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1595: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1596: 'value="'.$currlimit.'" />';
1.101 raeburn 1597: }
1.127 raeburn 1598: $cell{$item} .= '</span> ';
1.103 raeburn 1599: if ($option eq 'autolimit') {
1.127 raeburn 1600: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1601: }
1.101 raeburn 1602: }
1.160.6.5 raeburn 1603: } elsif ($context eq 'requestauthor') {
1604: my $curroption;
1605: if (ref($settings) eq 'HASH') {
1606: $curroption = $settings->{$type};
1607: }
1608: if (!$curroption) {
1609: $curroption = 'norequest';
1610: }
1611: foreach my $option (@options) {
1612: my $val = $option;
1613: if ($option eq 'norequest') {
1614: $val = 0;
1615: }
1616: my $checked = '';
1617: if ($option eq $curroption) {
1618: $checked = ' checked="checked"';
1619: }
1620: $datatable .= '<span class="LC_nobreak"><label>'.
1621: '<input type="radio" name="authorreq_'.$type.
1622: '" value="'.$val.'"'.$checked.' />'.
1623: $titles{$option}.'</label></span> ';
1624: }
1.101 raeburn 1625: } else {
1626: my $checked = 'checked="checked" ';
1627: if (ref($settings) eq 'HASH') {
1628: if (ref($settings->{$item}) eq 'HASH') {
1629: if ($settings->{$item}->{$type} == 0) {
1630: $checked = '';
1631: } elsif ($settings->{$item}->{$type} == 1) {
1632: $checked = 'checked="checked" ';
1633: }
1.78 raeburn 1634: }
1.72 raeburn 1635: }
1.101 raeburn 1636: $datatable .= '<span class="LC_nobreak"><label>'.
1637: '<input type="checkbox" name="'.$context.'_'.$item.
1638: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1639: '</label></span> ';
1.72 raeburn 1640: }
1.101 raeburn 1641: }
1642: if ($context eq 'requestcourses') {
1643: $datatable .= '</tr><tr>';
1644: foreach my $item (@usertools) {
1.106 raeburn 1645: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1646: }
1647: $datatable .= '</tr></table>';
1.72 raeburn 1648: }
1.86 raeburn 1649: $datatable .= '</td>';
1.160.6.5 raeburn 1650: unless (($context eq 'requestcourses') ||
1651: ($context eq 'requestauthor')) {
1.86 raeburn 1652: $datatable .=
1.160.6.20 raeburn 1653: '<td class="LC_right_item">'.
1654: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1655: '<input type="text" name="quota_'.$type.
1.72 raeburn 1656: '" value="'.$currdefquota.
1.160.6.20 raeburn 1657: '" size="5" /></span>'.(' ' x 2).
1658: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1659: '<input type="text" name="authorquota_'.$type.
1660: '" value="'.$currauthorquota.
1661: '" size="5" /></span></td>';
1.86 raeburn 1662: }
1663: $datatable .= '</tr>';
1.3 raeburn 1664: }
1665: }
1666: }
1.160.6.5 raeburn 1667: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1668: $defaultquota = '20';
1.160.6.20 raeburn 1669: $authorquota = '500';
1.86 raeburn 1670: if (ref($settings) eq 'HASH') {
1671: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1672: $defaultquota = $settings->{'defaultquota'}->{'default'};
1673: } elsif (defined($settings->{'default'})) {
1674: $defaultquota = $settings->{'default'};
1675: }
1.160.6.20 raeburn 1676: if (ref($settings->{'authorquota'}) eq 'HASH') {
1677: $authorquota = $settings->{'authorquota'}->{'default'};
1678: }
1.3 raeburn 1679: }
1680: }
1681: $typecount ++;
1682: $css_class = $typecount%2?' class="LC_odd_row"':'';
1683: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1684: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1685: '<td class="LC_left_item">';
1.101 raeburn 1686: if ($context eq 'requestcourses') {
1687: $datatable .= '<table><tr>';
1688: }
1689: my %defcell;
1.72 raeburn 1690: foreach my $item (@usertools) {
1.101 raeburn 1691: if ($context eq 'requestcourses') {
1692: my ($curroption,$currlimit);
1693: if (ref($settings) eq 'HASH') {
1694: if (ref($settings->{$item}) eq 'HASH') {
1695: $curroption = $settings->{$item}->{'default'};
1696: if ($curroption =~ /^autolimit=(\d*)$/) {
1697: $currlimit = $1;
1698: }
1699: }
1700: }
1701: if (!$curroption) {
1702: $curroption = 'norequest';
1703: }
1704: $datatable .= '<th>'.$titles{$item}.'</th>';
1705: foreach my $option (@options) {
1706: my $val = $option;
1707: if ($option eq 'norequest') {
1708: $val = 0;
1709: }
1710: if ($option eq 'validate') {
1711: my $canvalidate = 0;
1712: if (ref($validations{$item}) eq 'HASH') {
1713: if ($validations{$item}{'default'}) {
1714: $canvalidate = 1;
1715: }
1716: }
1717: next if (!$canvalidate);
1718: }
1719: my $checked = '';
1720: if ($option eq $curroption) {
1721: $checked = ' checked="checked"';
1722: } elsif ($option eq 'autolimit') {
1723: if ($curroption =~ /^autolimit/) {
1724: $checked = ' checked="checked"';
1725: }
1726: }
1727: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1728: '<input type="radio" name="crsreq_'.$item.
1729: '_default" value="'.$val.'"'.$checked.' />'.
1730: $titles{$option}.'</label>';
1731: if ($option eq 'autolimit') {
1.127 raeburn 1732: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1733: $item.'_limit_default" size="1" '.
1734: 'value="'.$currlimit.'" />';
1735: }
1.127 raeburn 1736: $defcell{$item} .= '</span> ';
1.104 raeburn 1737: if ($option eq 'autolimit') {
1.127 raeburn 1738: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1739: }
1.101 raeburn 1740: }
1.160.6.5 raeburn 1741: } elsif ($context eq 'requestauthor') {
1742: my $curroption;
1743: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1744: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1745: }
1746: if (!$curroption) {
1747: $curroption = 'norequest';
1748: }
1749: foreach my $option (@options) {
1750: my $val = $option;
1751: if ($option eq 'norequest') {
1752: $val = 0;
1753: }
1754: my $checked = '';
1755: if ($option eq $curroption) {
1756: $checked = ' checked="checked"';
1757: }
1758: $datatable .= '<span class="LC_nobreak"><label>'.
1759: '<input type="radio" name="authorreq_default"'.
1760: ' value="'.$val.'"'.$checked.' />'.
1761: $titles{$option}.'</label></span> ';
1762: }
1.101 raeburn 1763: } else {
1764: my $checked = 'checked="checked" ';
1765: if (ref($settings) eq 'HASH') {
1766: if (ref($settings->{$item}) eq 'HASH') {
1767: if ($settings->{$item}->{'default'} == 0) {
1768: $checked = '';
1769: } elsif ($settings->{$item}->{'default'} == 1) {
1770: $checked = 'checked="checked" ';
1771: }
1.78 raeburn 1772: }
1.72 raeburn 1773: }
1.101 raeburn 1774: $datatable .= '<span class="LC_nobreak"><label>'.
1775: '<input type="checkbox" name="'.$context.'_'.$item.
1776: '" value="default" '.$checked.'/>'.$titles{$item}.
1777: '</label></span> ';
1778: }
1779: }
1780: if ($context eq 'requestcourses') {
1781: $datatable .= '</tr><tr>';
1782: foreach my $item (@usertools) {
1.106 raeburn 1783: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1784: }
1.101 raeburn 1785: $datatable .= '</tr></table>';
1.72 raeburn 1786: }
1.86 raeburn 1787: $datatable .= '</td>';
1.160.6.5 raeburn 1788: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1789: $datatable .= '<td class="LC_right_item">'.
1790: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1791: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1792: $defaultquota.'" size="5" /></span>'.(' ' x2).
1793: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1794: '<input type="text" name="authorquota" value="'.
1795: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1796: }
1797: $datatable .= '</tr>';
1.72 raeburn 1798: $typecount ++;
1799: $css_class = $typecount%2?' class="LC_odd_row"':'';
1800: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1801: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1802: if ($context eq 'requestcourses') {
1.109 raeburn 1803: $datatable .= &mt('(overrides affiliation, if set)').
1804: '</td>'.
1805: '<td class="LC_left_item">'.
1806: '<table><tr>';
1.101 raeburn 1807: } else {
1.109 raeburn 1808: $datatable .= &mt('(overrides affiliation, if checked)').
1809: '</td>'.
1810: '<td class="LC_left_item" colspan="2">'.
1811: '<br />';
1.101 raeburn 1812: }
1813: my %advcell;
1.72 raeburn 1814: foreach my $item (@usertools) {
1.101 raeburn 1815: if ($context eq 'requestcourses') {
1816: my ($curroption,$currlimit);
1817: if (ref($settings) eq 'HASH') {
1818: if (ref($settings->{$item}) eq 'HASH') {
1819: $curroption = $settings->{$item}->{'_LC_adv'};
1820: if ($curroption =~ /^autolimit=(\d*)$/) {
1821: $currlimit = $1;
1822: }
1823: }
1824: }
1825: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1826: my $checked = '';
1827: if ($curroption eq '') {
1828: $checked = ' checked="checked"';
1829: }
1830: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1831: '<input type="radio" name="crsreq_'.$item.
1832: '__LC_adv" value=""'.$checked.' />'.
1833: &mt('No override set').'</label></span> ';
1.101 raeburn 1834: foreach my $option (@options) {
1835: my $val = $option;
1836: if ($option eq 'norequest') {
1837: $val = 0;
1838: }
1839: if ($option eq 'validate') {
1840: my $canvalidate = 0;
1841: if (ref($validations{$item}) eq 'HASH') {
1842: if ($validations{$item}{'_LC_adv'}) {
1843: $canvalidate = 1;
1844: }
1845: }
1846: next if (!$canvalidate);
1847: }
1848: my $checked = '';
1.104 raeburn 1849: if ($val eq $curroption) {
1.101 raeburn 1850: $checked = ' checked="checked"';
1851: } elsif ($option eq 'autolimit') {
1852: if ($curroption =~ /^autolimit/) {
1853: $checked = ' checked="checked"';
1854: }
1855: }
1856: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1857: '<input type="radio" name="crsreq_'.$item.
1858: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1859: $titles{$option}.'</label>';
1860: if ($option eq 'autolimit') {
1.127 raeburn 1861: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1862: $item.'_limit__LC_adv" size="1" '.
1863: 'value="'.$currlimit.'" />';
1864: }
1.127 raeburn 1865: $advcell{$item} .= '</span> ';
1.104 raeburn 1866: if ($option eq 'autolimit') {
1.127 raeburn 1867: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1868: }
1.101 raeburn 1869: }
1.160.6.5 raeburn 1870: } elsif ($context eq 'requestauthor') {
1871: my $curroption;
1872: if (ref($settings) eq 'HASH') {
1873: $curroption = $settings->{'_LC_adv'};
1874: }
1875: my $checked = '';
1876: if ($curroption eq '') {
1877: $checked = ' checked="checked"';
1878: }
1879: $datatable .= '<span class="LC_nobreak"><label>'.
1880: '<input type="radio" name="authorreq__LC_adv"'.
1881: ' value=""'.$checked.' />'.
1882: &mt('No override set').'</label></span> ';
1883: foreach my $option (@options) {
1884: my $val = $option;
1885: if ($option eq 'norequest') {
1886: $val = 0;
1887: }
1888: my $checked = '';
1889: if ($val eq $curroption) {
1890: $checked = ' checked="checked"';
1891: }
1892: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1893: '<input type="radio" name="authorreq__LC_adv"'.
1894: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1895: $titles{$option}.'</label></span> ';
1896: }
1.101 raeburn 1897: } else {
1898: my $checked = 'checked="checked" ';
1899: if (ref($settings) eq 'HASH') {
1900: if (ref($settings->{$item}) eq 'HASH') {
1901: if ($settings->{$item}->{'_LC_adv'} == 0) {
1902: $checked = '';
1903: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1904: $checked = 'checked="checked" ';
1905: }
1.79 raeburn 1906: }
1.72 raeburn 1907: }
1.101 raeburn 1908: $datatable .= '<span class="LC_nobreak"><label>'.
1909: '<input type="checkbox" name="'.$context.'_'.$item.
1910: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1911: '</label></span> ';
1912: }
1913: }
1914: if ($context eq 'requestcourses') {
1915: $datatable .= '</tr><tr>';
1916: foreach my $item (@usertools) {
1.106 raeburn 1917: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1918: }
1.101 raeburn 1919: $datatable .= '</tr></table>';
1.72 raeburn 1920: }
1.98 raeburn 1921: $datatable .= '</td></tr>';
1.30 raeburn 1922: $$rowtotal += $typecount;
1.3 raeburn 1923: return $datatable;
1924: }
1925:
1.160.6.5 raeburn 1926: sub print_requestmail {
1927: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 1928: my ($now,$datatable,%currapp,$rows);
1.102 raeburn 1929: $now = time;
1930: if (ref($settings) eq 'HASH') {
1931: if (ref($settings->{'notify'}) eq 'HASH') {
1932: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.16 raeburn 1933: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1934: }
1935: }
1936: }
1.160.6.16 raeburn 1937: my $numinrow = 2;
1.102 raeburn 1938: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1939: my $text;
1940: if ($action eq 'requestcourses') {
1941: $text = &mt('Receive notification of course requests requiring approval');
1942: } else {
1943: $text = &mt('Receive notification of authoring space requests requiring approval')
1944: }
1945: $datatable = '<tr '.$css_class.'>'.
1946: ' <td>'.$text.'</td>'.
1.102 raeburn 1947: ' <td class="LC_left_item">';
1.160.6.16 raeburn 1948: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1949: 'reqapprovalnotify',%currapp);
1950: if ($numdc > 0) {
1951: $datatable .= $table;
1.102 raeburn 1952: } else {
1953: $datatable .= &mt('There are no active Domain Coordinators');
1954: }
1955: $datatable .='</td></tr>';
1956: $$rowtotal += $rows;
1957: return $datatable;
1958: }
1959:
1.3 raeburn 1960: sub print_autoenroll {
1.30 raeburn 1961: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1962: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1963: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1964: if (ref($settings) eq 'HASH') {
1965: if (exists($settings->{'run'})) {
1966: if ($settings->{'run'} eq '0') {
1967: $runoff = ' checked="checked" ';
1968: $runon = ' ';
1969: } else {
1970: $runon = ' checked="checked" ';
1971: $runoff = ' ';
1972: }
1973: } else {
1974: if ($autorun) {
1975: $runon = ' checked="checked" ';
1976: $runoff = ' ';
1977: } else {
1978: $runoff = ' checked="checked" ';
1979: $runon = ' ';
1980: }
1981: }
1.129 raeburn 1982: if (exists($settings->{'co-owners'})) {
1983: if ($settings->{'co-owners'} eq '0') {
1984: $coownersoff = ' checked="checked" ';
1985: $coownerson = ' ';
1986: } else {
1987: $coownerson = ' checked="checked" ';
1988: $coownersoff = ' ';
1989: }
1990: } else {
1991: $coownersoff = ' checked="checked" ';
1992: $coownerson = ' ';
1993: }
1.3 raeburn 1994: if (exists($settings->{'sender_domain'})) {
1995: $defdom = $settings->{'sender_domain'};
1996: }
1.14 raeburn 1997: } else {
1998: if ($autorun) {
1999: $runon = ' checked="checked" ';
2000: $runoff = ' ';
2001: } else {
2002: $runoff = ' checked="checked" ';
2003: $runon = ' ';
2004: }
1.3 raeburn 2005: }
2006: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2007: my $notif_sender;
2008: if (ref($settings) eq 'HASH') {
2009: $notif_sender = $settings->{'sender_uname'};
2010: }
1.3 raeburn 2011: my $datatable='<tr class="LC_odd_row">'.
2012: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2013: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2014: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2015: $runon.' value="1" />'.&mt('Yes').'</label> '.
2016: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2017: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2018: '</tr><tr>'.
2019: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2020: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2021: &mt('username').': '.
2022: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2023: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2024: ': '.$domform.'</span></td></tr>'.
2025: '<tr class="LC_odd_row">'.
2026: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2027: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2028: '<input type="radio" name="autoassign_coowners"'.
2029: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2030: '<label><input type="radio" name="autoassign_coowners"'.
2031: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2032: '</tr>';
2033: $$rowtotal += 3;
1.3 raeburn 2034: return $datatable;
2035: }
2036:
2037: sub print_autoupdate {
1.30 raeburn 2038: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2039: my $datatable;
2040: if ($position eq 'top') {
2041: my $updateon = ' ';
2042: my $updateoff = ' checked="checked" ';
2043: my $classlistson = ' ';
2044: my $classlistsoff = ' checked="checked" ';
2045: if (ref($settings) eq 'HASH') {
2046: if ($settings->{'run'} eq '1') {
2047: $updateon = $updateoff;
2048: $updateoff = ' ';
2049: }
2050: if ($settings->{'classlists'} eq '1') {
2051: $classlistson = $classlistsoff;
2052: $classlistsoff = ' ';
2053: }
2054: }
2055: my %title = (
2056: run => 'Auto-update active?',
2057: classlists => 'Update information in classlists?',
2058: );
2059: $datatable = '<tr class="LC_odd_row">'.
2060: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2061: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2062: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2063: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2064: '<label><input type="radio" name="autoupdate_run"'.
2065: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2066: '</tr><tr>'.
2067: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2068: '<td class="LC_right_item"><span class="LC_nobreak">'.
2069: '<label><input type="radio" name="classlists"'.
2070: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2071: '<label><input type="radio" name="classlists"'.
2072: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2073: '</tr>';
1.30 raeburn 2074: $$rowtotal += 2;
1.131 raeburn 2075: } elsif ($position eq 'middle') {
2076: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2077: my $numinrow = 3;
2078: my $locknamesettings;
2079: $datatable .= &insttypes_row($settings,$types,$usertypes,
2080: $dom,$numinrow,$othertitle,
2081: 'lockablenames');
2082: $$rowtotal ++;
1.3 raeburn 2083: } else {
1.44 raeburn 2084: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2085: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2086: 'permanentemail','id');
1.33 raeburn 2087: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2088: my $numrows = 0;
1.26 raeburn 2089: if (ref($types) eq 'ARRAY') {
2090: if (@{$types} > 0) {
2091: $datatable =
2092: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2093: \@fields,$types,\$numrows);
1.30 raeburn 2094: $$rowtotal += @{$types};
1.26 raeburn 2095: }
1.3 raeburn 2096: }
2097: $datatable .=
2098: &usertype_update_row($settings,{'default' => $othertitle},
2099: \%fieldtitles,\@fields,['default'],
2100: \$numrows);
1.30 raeburn 2101: $$rowtotal ++;
1.3 raeburn 2102: }
2103: return $datatable;
2104: }
2105:
1.125 raeburn 2106: sub print_autocreate {
2107: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2108: my (%createon,%createoff,%currhash);
1.125 raeburn 2109: my @types = ('xml','req');
2110: if (ref($settings) eq 'HASH') {
2111: foreach my $item (@types) {
2112: $createoff{$item} = ' checked="checked" ';
2113: $createon{$item} = ' ';
2114: if (exists($settings->{$item})) {
2115: if ($settings->{$item}) {
2116: $createon{$item} = ' checked="checked" ';
2117: $createoff{$item} = ' ';
2118: }
2119: }
2120: }
1.160.6.16 raeburn 2121: if ($settings->{'xmldc'} ne '') {
2122: $currhash{$settings->{'xmldc'}} = 1;
2123: }
1.125 raeburn 2124: } else {
2125: foreach my $item (@types) {
2126: $createoff{$item} = ' checked="checked" ';
2127: $createon{$item} = ' ';
2128: }
2129: }
2130: $$rowtotal += 2;
1.160.6.16 raeburn 2131: my $numinrow = 2;
1.125 raeburn 2132: my $datatable='<tr class="LC_odd_row">'.
2133: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2134: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2135: '<input type="radio" name="autocreate_xml"'.
2136: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2137: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2138: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2139: '</td></tr><tr>'.
2140: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2141: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2142: '<input type="radio" name="autocreate_req"'.
2143: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2144: '<label><input type="radio" name="autocreate_req"'.
2145: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2146: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2147: 'autocreate_xmldc',%currhash);
1.125 raeburn 2148: if ($numdc > 1) {
1.143 raeburn 2149: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2150: &mt('Course creation processed as: (choose Dom. Coord.)').
2151: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2152: } else {
1.143 raeburn 2153: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2154: }
1.160.6.16 raeburn 2155: $$rowtotal += $rows;
1.125 raeburn 2156: return $datatable;
2157: }
2158:
1.23 raeburn 2159: sub print_directorysrch {
1.30 raeburn 2160: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2161: my $srchon = ' ';
2162: my $srchoff = ' checked="checked" ';
1.25 raeburn 2163: my ($exacton,$containson,$beginson);
1.24 raeburn 2164: my $localon = ' ';
2165: my $localoff = ' checked="checked" ';
1.23 raeburn 2166: if (ref($settings) eq 'HASH') {
2167: if ($settings->{'available'} eq '1') {
2168: $srchon = $srchoff;
2169: $srchoff = ' ';
2170: }
1.24 raeburn 2171: if ($settings->{'localonly'} eq '1') {
2172: $localon = $localoff;
2173: $localoff = ' ';
2174: }
1.25 raeburn 2175: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2176: foreach my $type (@{$settings->{'searchtypes'}}) {
2177: if ($type eq 'exact') {
2178: $exacton = ' checked="checked" ';
2179: } elsif ($type eq 'contains') {
2180: $containson = ' checked="checked" ';
2181: } elsif ($type eq 'begins') {
2182: $beginson = ' checked="checked" ';
2183: }
2184: }
2185: } else {
2186: if ($settings->{'searchtypes'} eq 'exact') {
2187: $exacton = ' checked="checked" ';
2188: } elsif ($settings->{'searchtypes'} eq 'contains') {
2189: $containson = ' checked="checked" ';
2190: } elsif ($settings->{'searchtypes'} eq 'specify') {
2191: $exacton = ' checked="checked" ';
2192: $containson = ' checked="checked" ';
2193: }
1.23 raeburn 2194: }
2195: }
2196: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2197: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2198:
2199: my $numinrow = 4;
1.26 raeburn 2200: my $cansrchrow = 0;
1.23 raeburn 2201: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2202: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2203: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2204: '<input type="radio" name="dirsrch_available"'.
2205: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2206: '<label><input type="radio" name="dirsrch_available"'.
2207: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2208: '</tr><tr>'.
1.30 raeburn 2209: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2210: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2211: '<input type="radio" name="dirsrch_localonly"'.
2212: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2213: '<label><input type="radio" name="dirsrch_localonly"'.
2214: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2215: '</tr>';
1.30 raeburn 2216: $$rowtotal += 2;
1.26 raeburn 2217: if (ref($usertypes) eq 'HASH') {
2218: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2219: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2220: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2221: $cansrchrow = 1;
2222: }
2223: }
2224: if ($cansrchrow) {
1.30 raeburn 2225: $$rowtotal ++;
1.26 raeburn 2226: $datatable .= '<tr>';
2227: } else {
2228: $datatable .= '<tr class="LC_odd_row">';
2229: }
1.30 raeburn 2230: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2231: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2232: foreach my $title (@{$titleorder}) {
2233: if (defined($searchtitles->{$title})) {
2234: my $check = ' ';
1.93 raeburn 2235: if (ref($settings) eq 'HASH') {
1.39 raeburn 2236: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2237: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2238: $check = ' checked="checked" ';
2239: }
1.25 raeburn 2240: }
2241: }
2242: $datatable .= '<td class="LC_left_item">'.
2243: '<span class="LC_nobreak"><label>'.
2244: '<input type="checkbox" name="searchby" '.
2245: 'value="'.$title.'"'.$check.'/>'.
2246: $searchtitles->{$title}.'</label></span></td>';
2247: }
2248: }
1.26 raeburn 2249: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2250: $$rowtotal ++;
1.26 raeburn 2251: if ($cansrchrow) {
2252: $datatable .= '<tr class="LC_odd_row">';
2253: } else {
2254: $datatable .= '<tr>';
2255: }
1.30 raeburn 2256: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2257: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2258: '<span class="LC_nobreak"><label>'.
2259: '<input type="checkbox" name="searchtypes" '.
2260: $exacton.' value="exact" />'.&mt('Exact match').
2261: '</label> '.
2262: '<label><input type="checkbox" name="searchtypes" '.
2263: $beginson.' value="begins" />'.&mt('Begins with').
2264: '</label> '.
2265: '<label><input type="checkbox" name="searchtypes" '.
2266: $containson.' value="contains" />'.&mt('Contains').
2267: '</label></span></td></tr>';
1.30 raeburn 2268: $$rowtotal ++;
1.25 raeburn 2269: return $datatable;
2270: }
2271:
1.28 raeburn 2272: sub print_contacts {
1.30 raeburn 2273: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2274: my $datatable;
2275: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2276: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2277: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.15 raeburn 2278: 'requestsmail','updatesmail');
1.28 raeburn 2279: foreach my $type (@mailings) {
2280: $otheremails{$type} = '';
2281: }
1.134 raeburn 2282: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2283: if (ref($settings) eq 'HASH') {
2284: foreach my $item (@contacts) {
2285: if (exists($settings->{$item})) {
2286: $to{$item} = $settings->{$item};
2287: }
2288: }
2289: foreach my $type (@mailings) {
2290: if (exists($settings->{$type})) {
2291: if (ref($settings->{$type}) eq 'HASH') {
2292: foreach my $item (@contacts) {
2293: if ($settings->{$type}{$item}) {
2294: $checked{$type}{$item} = ' checked="checked" ';
2295: }
2296: }
2297: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2298: if ($type eq 'helpdeskmail') {
2299: $bccemails{$type} = $settings->{$type}{'bcc'};
2300: }
1.28 raeburn 2301: }
1.89 raeburn 2302: } elsif ($type eq 'lonstatusmail') {
2303: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2304: }
2305: }
2306: } else {
2307: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2308: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2309: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2310: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2311: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2312: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2313: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.15 raeburn 2314: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2315: }
2316: my ($titles,$short_titles) = &contact_titles();
2317: my $rownum = 0;
2318: my $css_class;
2319: foreach my $item (@contacts) {
1.69 raeburn 2320: $rownum ++;
2321: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2322: $datatable .= '<tr'.$css_class.'>'.
2323: '<td><span class="LC_nobreak">'.$titles->{$item}.
2324: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2325: '<input type="text" name="'.$item.'" value="'.
2326: $to{$item}.'" /></td></tr>';
2327: }
2328: foreach my $type (@mailings) {
1.69 raeburn 2329: $rownum ++;
2330: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2331: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2332: '<td><span class="LC_nobreak">'.
2333: $titles->{$type}.': </span></td>'.
1.28 raeburn 2334: '<td class="LC_left_item">'.
2335: '<span class="LC_nobreak">';
2336: foreach my $item (@contacts) {
2337: $datatable .= '<label>'.
2338: '<input type="checkbox" name="'.$type.'"'.
2339: $checked{$type}{$item}.
2340: ' value="'.$item.'" />'.$short_titles->{$item}.
2341: '</label> ';
2342: }
2343: $datatable .= '</span><br />'.&mt('Others').': '.
2344: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2345: 'value="'.$otheremails{$type}.'" />';
2346: if ($type eq 'helpdeskmail') {
1.136 raeburn 2347: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2348: '<input type="text" name="'.$type.'_bcc" '.
2349: 'value="'.$bccemails{$type}.'" />';
2350: }
2351: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2352: }
1.30 raeburn 2353: $$rowtotal += $rownum;
1.28 raeburn 2354: return $datatable;
2355: }
2356:
1.118 jms 2357: sub print_helpsettings {
1.160.6.5 raeburn 2358: my ($dom,$confname,$settings,$rowtotal) = @_;
2359: my ($datatable,$itemcount);
2360: $itemcount = 1;
2361: my (%choices,%defaultchecked,@toggles);
2362: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2363: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2364: &mt('LON-CAPA bug tracker'),600,500));
2365: %defaultchecked = ('submitbugs' => 'on');
2366: @toggles = ('submitbugs',);
1.122 jms 2367:
1.160.6.5 raeburn 2368: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2369: \%choices,$itemcount);
2370: return $datatable;
1.121 raeburn 2371: }
2372:
2373: sub radiobutton_prefs {
1.160.6.16 raeburn 2374: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2375: $additional) = @_;
1.121 raeburn 2376: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2377: (ref($choices) eq 'HASH'));
2378:
2379: my (%checkedon,%checkedoff,$datatable,$css_class);
2380:
2381: foreach my $item (@{$toggles}) {
2382: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2383: $checkedon{$item} = ' checked="checked" ';
2384: $checkedoff{$item} = ' ';
1.121 raeburn 2385: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2386: $checkedoff{$item} = ' checked="checked" ';
2387: $checkedon{$item} = ' ';
2388: }
2389: }
2390: if (ref($settings) eq 'HASH') {
1.121 raeburn 2391: foreach my $item (@{$toggles}) {
1.118 jms 2392: if ($settings->{$item} eq '1') {
2393: $checkedon{$item} = ' checked="checked" ';
2394: $checkedoff{$item} = ' ';
2395: } elsif ($settings->{$item} eq '0') {
2396: $checkedoff{$item} = ' checked="checked" ';
2397: $checkedon{$item} = ' ';
2398: }
2399: }
1.121 raeburn 2400: }
1.160.6.16 raeburn 2401: if ($onclick) {
2402: $onclick = ' onclick="'.$onclick.'"';
2403: }
1.121 raeburn 2404: foreach my $item (@{$toggles}) {
1.118 jms 2405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2406: $datatable .=
1.160.6.16 raeburn 2407: '<tr'.$css_class.'><td valign="top">'.
2408: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2409: '</span></td>'.
2410: '<td class="LC_right_item"><span class="LC_nobreak">'.
2411: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2412: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2413: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2414: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2415: '</span>'.$additional.
2416: '</td>'.
1.118 jms 2417: '</tr>';
2418: $itemcount ++;
1.121 raeburn 2419: }
2420: return ($datatable,$itemcount);
2421: }
2422:
2423: sub print_coursedefaults {
1.139 raeburn 2424: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2425: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2426: my $itemcount = 1;
1.160.6.16 raeburn 2427: my %choices = &Apache::lonlocal::texthash (
2428: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21! raeburn 2429: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2430: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2431: coursecredits => 'Credits can be specified for courses',
2432: );
1.160.6.21! raeburn 2433: my %staticdefaults = (
! 2434: anonsurvey_threshold => 10,
! 2435: uploadquota => 500,
! 2436: );
1.139 raeburn 2437: if ($position eq 'top') {
2438: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2439: @toggles = ('canuse_pdfforms');
1.139 raeburn 2440: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2441: \%choices,$itemcount);
1.139 raeburn 2442: } else {
2443: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.21! raeburn 2444: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.160.6.16 raeburn 2445: my $currusecredits = 0;
1.160.6.21! raeburn 2446: my @types = ('official','unofficial','community');
1.139 raeburn 2447: if (ref($settings) eq 'HASH') {
2448: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21! raeburn 2449: if (ref($settings->{'uploadquota'}) eq 'HASH') {
! 2450: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
! 2451: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
! 2452: }
! 2453: }
1.160.6.16 raeburn 2454: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2455: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2456: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2457: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2458: $currusecredits = 1;
2459: }
2460: }
1.139 raeburn 2461: }
2462: if (!$currdefresponder) {
1.160.6.21! raeburn 2463: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2464: } elsif ($currdefresponder < 1) {
2465: $currdefresponder = 1;
2466: }
1.160.6.21! raeburn 2467: foreach my $type (@types) {
! 2468: if ($curruploadquota{$type} eq '') {
! 2469: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
! 2470: }
! 2471: }
1.139 raeburn 2472: $datatable .=
1.160.6.16 raeburn 2473: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2474: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2475: '</span></td>'.
2476: '<td class="LC_right_item"><span class="LC_nobreak">'.
2477: '<input type="text" name="anonsurvey_threshold"'.
2478: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.21! raeburn 2479: '</td></tr>'."\n".
! 2480: '<tr><td><span class="LC_nobreak">'.
! 2481: $choices{'uploadquota'}.
! 2482: '</span></td>'.
! 2483: '<td align="right" class="LC_right_item">'.
! 2484: '<table><tr>';
! 2485: foreach my $type (@types) {
! 2486: $datatable .= '<td align="center">'.&mt($type).'<br />'.
! 2487: '<input type="text" name="uploadquota_'.$type.'"'.
! 2488: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
! 2489: }
! 2490: $datatable .= '</tr></table></td></tr>'."\n";
! 2491: $itemcount += 2;
1.160.6.16 raeburn 2492: my $onclick = 'toggleCredits(this.form);';
2493: my $display = 'none';
2494: if ($currusecredits) {
2495: $display = 'block';
2496: }
2497: my $additional = '<div id="credits" style="display: '.$display.'">'.
2498: '<span class="LC_nobreak">'.
2499: &mt('Default credits for official courses [_1]',
2500: '<input type="text" name="official_credits" value="'.
2501: $def_official_credits.'" size="3" />').
2502: '</span><br />'.
2503: '<span class="LC_nobreak">'.
2504: &mt('Default credits for unofficial courses [_1]',
2505: '<input type="text" name="unofficial_credits" value="'.
2506: $def_unofficial_credits.'" size="3" />').
2507: '</span></div>'."\n";
2508: %defaultchecked = ('coursecredits' => 'off');
2509: @toggles = ('coursecredits');
2510: my $current = {
2511: 'coursecredits' => $currusecredits,
2512: };
2513: (my $table,$itemcount) =
2514: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2515: \%choices,$itemcount,$onclick,$additional);
2516: $datatable .= $table;
1.139 raeburn 2517: }
1.160.6.16 raeburn 2518: $$rowtotal += $itemcount;
1.121 raeburn 2519: return $datatable;
1.118 jms 2520: }
2521:
1.137 raeburn 2522: sub print_usersessions {
2523: my ($position,$dom,$settings,$rowtotal) = @_;
2524: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2525: my (%by_ip,%by_location,@intdoms);
2526: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2527:
2528: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2529: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2530: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2531: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2532: my $itemcount = 1;
2533: if ($position eq 'top') {
1.152 raeburn 2534: if (keys(%serverhomes) > 1) {
1.145 raeburn 2535: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2536: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2537: } else {
1.140 raeburn 2538: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2539: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2540: }
1.137 raeburn 2541: } else {
1.145 raeburn 2542: if (keys(%by_location) == 0) {
2543: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2544: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2545: } else {
2546: my %lt = &usersession_titles();
2547: my $numinrow = 5;
2548: my $prefix;
2549: my @types;
2550: if ($position eq 'bottom') {
2551: $prefix = 'remote';
2552: @types = ('version','excludedomain','includedomain');
2553: } else {
2554: $prefix = 'hosted';
2555: @types = ('excludedomain','includedomain');
2556: }
2557: my (%current,%checkedon,%checkedoff);
2558: my @lcversions = &Apache::lonnet::all_loncaparevs();
2559: my @locations = sort(keys(%by_location));
2560: foreach my $type (@types) {
2561: $checkedon{$type} = '';
2562: $checkedoff{$type} = ' checked="checked"';
2563: }
2564: if (ref($settings) eq 'HASH') {
2565: if (ref($settings->{$prefix}) eq 'HASH') {
2566: foreach my $key (keys(%{$settings->{$prefix}})) {
2567: $current{$key} = $settings->{$prefix}{$key};
2568: if ($key eq 'version') {
2569: if ($current{$key} ne '') {
2570: $checkedon{$key} = ' checked="checked"';
2571: $checkedoff{$key} = '';
2572: }
2573: } elsif (ref($current{$key}) eq 'ARRAY') {
2574: $checkedon{$key} = ' checked="checked"';
2575: $checkedoff{$key} = '';
2576: }
1.137 raeburn 2577: }
2578: }
2579: }
1.145 raeburn 2580: foreach my $type (@types) {
2581: next if ($type ne 'version' && !@locations);
2582: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2583: $datatable .= '<tr'.$css_class.'>
2584: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2585: <span class="LC_nobreak">
2586: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2587: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2588: if ($type eq 'version') {
2589: my $selector = '<select name="'.$prefix.'_version">';
2590: foreach my $version (@lcversions) {
2591: my $selected = '';
2592: if ($current{'version'} eq $version) {
2593: $selected = ' selected="selected"';
2594: }
2595: $selector .= ' <option value="'.$version.'"'.
2596: $selected.'>'.$version.'</option>';
2597: }
2598: $selector .= '</select> ';
2599: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2600: } else {
2601: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2602: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2603: ' />'.(' 'x2).
2604: '<input type="button" value="'.&mt('uncheck all').'" '.
2605: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2606: "\n".
2607: '</div><div><table>';
2608: my $rem;
2609: for (my $i=0; $i<@locations; $i++) {
2610: my ($showloc,$value,$checkedtype);
2611: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2612: my $ip = $by_location{$locations[$i]}->[0];
2613: if (ref($by_ip{$ip}) eq 'ARRAY') {
2614: $value = join(':',@{$by_ip{$ip}});
2615: $showloc = join(', ',@{$by_ip{$ip}});
2616: if (ref($current{$type}) eq 'ARRAY') {
2617: foreach my $loc (@{$by_ip{$ip}}) {
2618: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2619: $checkedtype = ' checked="checked"';
2620: last;
2621: }
2622: }
1.138 raeburn 2623: }
2624: }
2625: }
1.145 raeburn 2626: $rem = $i%($numinrow);
2627: if ($rem == 0) {
2628: if ($i > 0) {
2629: $datatable .= '</tr>';
2630: }
2631: $datatable .= '<tr>';
2632: }
2633: $datatable .= '<td class="LC_left_item">'.
2634: '<span class="LC_nobreak"><label>'.
2635: '<input type="checkbox" name="'.$prefix.'_'.$type.
2636: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2637: '</label></span></td>';
1.137 raeburn 2638: }
1.145 raeburn 2639: $rem = @locations%($numinrow);
2640: my $colsleft = $numinrow - $rem;
2641: if ($colsleft > 1 ) {
2642: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2643: ' </td>';
2644: } elsif ($colsleft == 1) {
2645: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2646: }
1.145 raeburn 2647: $datatable .= '</tr></table>';
1.137 raeburn 2648: }
1.145 raeburn 2649: $datatable .= '</td></tr>';
2650: $itemcount ++;
1.137 raeburn 2651: }
2652: }
2653: }
2654: $$rowtotal += $itemcount;
2655: return $datatable;
2656: }
2657:
1.138 raeburn 2658: sub build_location_hashes {
2659: my ($intdoms,$by_ip,$by_location) = @_;
2660: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2661: (ref($by_location) eq 'HASH'));
2662: my %iphost = &Apache::lonnet::get_iphost();
2663: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2664: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2665: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2666: foreach my $id (@{$iphost{$primary_ip}}) {
2667: my $intdom = &Apache::lonnet::internet_dom($id);
2668: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2669: push(@{$intdoms},$intdom);
2670: }
2671: }
2672: }
2673: foreach my $ip (keys(%iphost)) {
2674: if (ref($iphost{$ip}) eq 'ARRAY') {
2675: foreach my $id (@{$iphost{$ip}}) {
2676: my $location = &Apache::lonnet::internet_dom($id);
2677: if ($location) {
2678: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2679: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2680: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2681: push(@{$by_ip->{$ip}},$location);
2682: }
2683: } else {
2684: $by_ip->{$ip} = [$location];
2685: }
2686: }
2687: }
2688: }
2689: }
2690: foreach my $ip (sort(keys(%{$by_ip}))) {
2691: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2692: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2693: my $first = $by_ip->{$ip}->[0];
2694: if (ref($by_location->{$first}) eq 'ARRAY') {
2695: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2696: push(@{$by_location->{$first}},$ip);
2697: }
2698: } else {
2699: $by_location->{$first} = [$ip];
2700: }
2701: }
2702: }
2703: return;
2704: }
2705:
1.145 raeburn 2706: sub current_offloads_to {
2707: my ($dom,$settings,$servers) = @_;
2708: my (%spareid,%otherdomconfigs);
1.152 raeburn 2709: if (ref($servers) eq 'HASH') {
1.145 raeburn 2710: foreach my $lonhost (sort(keys(%{$servers}))) {
2711: my $gotspares;
1.152 raeburn 2712: if (ref($settings) eq 'HASH') {
2713: if (ref($settings->{'spares'}) eq 'HASH') {
2714: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2715: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2716: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2717: $gotspares = 1;
2718: }
1.145 raeburn 2719: }
2720: }
2721: unless ($gotspares) {
2722: my $gotspares;
2723: my $serverhomeID =
2724: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2725: my $serverhomedom =
2726: &Apache::lonnet::host_domain($serverhomeID);
2727: if ($serverhomedom ne $dom) {
2728: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2729: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2730: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2731: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2732: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2733: $gotspares = 1;
2734: }
2735: }
2736: } else {
2737: $otherdomconfigs{$serverhomedom} =
2738: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2739: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2740: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2741: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2742: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2743: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2744: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2745: $gotspares = 1;
2746: }
2747: }
2748: }
2749: }
2750: }
2751: }
2752: }
2753: unless ($gotspares) {
2754: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2755: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2756: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2757: } else {
2758: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2759: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2760: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2761: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2762: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2763: } else {
1.150 raeburn 2764: my %what = (
2765: spareid => 1,
2766: );
2767: my ($result,$returnhash) =
2768: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2769: if ($result eq 'ok') {
2770: if (ref($returnhash) eq 'HASH') {
2771: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2772: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2773: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2774: }
2775: }
1.145 raeburn 2776: }
2777: }
2778: }
2779: }
2780: }
2781: }
2782: return %spareid;
2783: }
2784:
2785: sub spares_row {
1.152 raeburn 2786: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2787: my $css_class;
2788: my $numinrow = 4;
2789: my $itemcount = 1;
2790: my $datatable;
1.152 raeburn 2791: my %typetitles = &sparestype_titles();
2792: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2793: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2794: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2795: my ($othercontrol,$serverdom);
2796: if ($serverhome ne $server) {
2797: $serverdom = &Apache::lonnet::host_domain($serverhome);
2798: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2799: } else {
2800: $serverdom = &Apache::lonnet::host_domain($server);
2801: if ($serverdom ne $dom) {
2802: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2803: }
2804: }
2805: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2806: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2807: $datatable .= '<tr'.$css_class.'>
2808: <td rowspan="2">
1.160.6.13 raeburn 2809: <span class="LC_nobreak">'.
2810: &mt('[_1] when busy, offloads to:'
2811: ,'<b>'.$server.'</b>').
2812: "\n";
1.145 raeburn 2813: my (%current,%canselect);
1.152 raeburn 2814: my @choices =
2815: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2816: foreach my $type ('primary','default') {
2817: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2818: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2819: my @spares = @{$spareid->{$server}{$type}};
2820: if (@spares > 0) {
1.152 raeburn 2821: if ($othercontrol) {
2822: $current{$type} = join(', ',@spares);
2823: } else {
2824: $current{$type} .= '<table>';
2825: my $numspares = scalar(@spares);
2826: for (my $i=0; $i<@spares; $i++) {
2827: my $rem = $i%($numinrow);
2828: if ($rem == 0) {
2829: if ($i > 0) {
2830: $current{$type} .= '</tr>';
2831: }
2832: $current{$type} .= '<tr>';
1.145 raeburn 2833: }
1.152 raeburn 2834: $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'".');" /> '.
2835: $spareid->{$server}{$type}[$i].
2836: '</label></td>'."\n";
2837: }
2838: my $rem = @spares%($numinrow);
2839: my $colsleft = $numinrow - $rem;
2840: if ($colsleft > 1 ) {
2841: $current{$type} .= '<td colspan="'.$colsleft.
2842: '" class="LC_left_item">'.
2843: ' </td>';
2844: } elsif ($colsleft == 1) {
2845: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2846: }
1.152 raeburn 2847: $current{$type} .= '</tr></table>';
1.150 raeburn 2848: }
1.145 raeburn 2849: }
2850: }
2851: if ($current{$type} eq '') {
2852: $current{$type} = &mt('None specified');
2853: }
1.152 raeburn 2854: if ($othercontrol) {
2855: if ($type eq 'primary') {
2856: $canselect{$type} = $othercontrol;
2857: }
2858: } else {
2859: $canselect{$type} =
2860: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2861: '<select name="newspare_'.$type.'_'.$server.'" '.
2862: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2863: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2864: if (@choices > 0) {
2865: foreach my $lonhost (@choices) {
2866: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2867: }
2868: }
2869: $canselect{$type} .= '</select>'."\n";
2870: }
2871: } else {
2872: $current{$type} = &mt('Could not be determined');
2873: if ($type eq 'primary') {
2874: $canselect{$type} = $othercontrol;
2875: }
1.145 raeburn 2876: }
1.152 raeburn 2877: if ($type eq 'default') {
2878: $datatable .= '<tr'.$css_class.'>';
2879: }
2880: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2881: '<td>'.$current{$type}.'</td>'."\n".
2882: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2883: }
2884: $itemcount ++;
2885: }
2886: }
2887: $$rowtotal += $itemcount;
2888: return $datatable;
2889: }
2890:
1.152 raeburn 2891: sub possible_newspares {
2892: my ($server,$currspares,$serverhomes,$altids) = @_;
2893: my $serverhostname = &Apache::lonnet::hostname($server);
2894: my %excluded;
2895: if ($serverhostname ne '') {
2896: %excluded = (
2897: $serverhostname => 1,
2898: );
2899: }
2900: if (ref($currspares) eq 'HASH') {
2901: foreach my $type (keys(%{$currspares})) {
2902: if (ref($currspares->{$type}) eq 'ARRAY') {
2903: if (@{$currspares->{$type}} > 0) {
2904: foreach my $curr (@{$currspares->{$type}}) {
2905: my $hostname = &Apache::lonnet::hostname($curr);
2906: $excluded{$hostname} = 1;
2907: }
2908: }
2909: }
2910: }
2911: }
2912: my @choices;
2913: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2914: if (keys(%{$serverhomes}) > 1) {
2915: foreach my $name (sort(keys(%{$serverhomes}))) {
2916: unless ($excluded{$name}) {
2917: if (exists($altids->{$serverhomes->{$name}})) {
2918: push(@choices,$altids->{$serverhomes->{$name}});
2919: } else {
2920: push(@choices,$serverhomes->{$name});
1.145 raeburn 2921: }
2922: }
2923: }
2924: }
2925: }
1.152 raeburn 2926: return sort(@choices);
1.145 raeburn 2927: }
2928:
1.150 raeburn 2929: sub print_loadbalancing {
2930: my ($dom,$settings,$rowtotal) = @_;
2931: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2932: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2933: my $numinrow = 1;
2934: my $datatable;
2935: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2936: my (%currbalancer,%currtargets,%currrules,%existing);
2937: if (ref($settings) eq 'HASH') {
2938: %existing = %{$settings};
2939: }
2940: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2941: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2942: \%currtargets,\%currrules);
1.150 raeburn 2943: } else {
2944: return;
2945: }
2946: my ($othertitle,$usertypes,$types) =
2947: &Apache::loncommon::sorted_inst_types($dom);
2948: my $rownum = 6;
2949: if (ref($types) eq 'ARRAY') {
2950: $rownum += scalar(@{$types});
2951: }
1.160.6.7 raeburn 2952: my @css_class = ('LC_odd_row','LC_even_row');
2953: my $balnum = 0;
2954: my $islast;
2955: my (@toshow,$disabledtext);
2956: if (keys(%currbalancer) > 0) {
2957: @toshow = sort(keys(%currbalancer));
2958: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2959: push(@toshow,'');
2960: }
2961: } else {
2962: @toshow = ('');
2963: $disabledtext = &mt('No existing load balancer');
2964: }
2965: foreach my $lonhost (@toshow) {
2966: if ($balnum == scalar(@toshow)-1) {
2967: $islast = 1;
2968: } else {
2969: $islast = 0;
2970: }
2971: my $cssidx = $balnum%2;
2972: my $targets_div_style = 'display: none';
2973: my $disabled_div_style = 'display: block';
2974: my $homedom_div_style = 'display: none';
2975: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2976: '<td rowspan="'.$rownum.'" valign="top">'.
2977: '<p>';
2978: if ($lonhost eq '') {
2979: $datatable .= '<span class="LC_nobreak">';
2980: if (keys(%currbalancer) > 0) {
2981: $datatable .= &mt('Add balancer:');
2982: } else {
2983: $datatable .= &mt('Enable balancer:');
2984: }
2985: $datatable .= ' '.
2986: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2987: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2988: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2989: '<option value="" selected="selected">'.&mt('None').
2990: '</option>'."\n";
2991: foreach my $server (sort(keys(%servers))) {
2992: next if ($currbalancer{$server});
2993: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2994: }
2995: $datatable .=
2996: '</select>'."\n".
2997: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2998: } else {
2999: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3000: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3001: &mt('Stop balancing').'</label>'.
3002: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3003: $targets_div_style = 'display: block';
3004: $disabled_div_style = 'display: none';
3005: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3006: $homedom_div_style = 'display: block';
3007: }
3008: }
3009: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3010: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3011: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3012: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3013: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3014: my @sparestypes = ('primary','default');
3015: my %typetitles = &sparestype_titles();
3016: foreach my $sparetype (@sparestypes) {
3017: my $targettable;
3018: for (my $i=0; $i<$numspares; $i++) {
3019: my $checked;
3020: if (ref($currtargets{$lonhost}) eq 'HASH') {
3021: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3022: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3023: $checked = ' checked="checked"';
3024: }
3025: }
3026: }
3027: my ($chkboxval,$disabled);
3028: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3029: $chkboxval = $spares[$i];
3030: }
3031: if (exists($currbalancer{$spares[$i]})) {
3032: $disabled = ' disabled="disabled"';
3033: }
3034: $targettable .=
3035: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3036: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3037: '</span></label></td>';
3038: my $rem = $i%($numinrow);
3039: if ($rem == 0) {
3040: if (($i > 0) && ($i < $numspares-1)) {
3041: $targettable .= '</tr>';
3042: }
3043: if ($i < $numspares-1) {
3044: $targettable .= '<tr>';
1.150 raeburn 3045: }
3046: }
3047: }
1.160.6.7 raeburn 3048: if ($targettable ne '') {
3049: my $rem = $numspares%($numinrow);
3050: my $colsleft = $numinrow - $rem;
3051: if ($colsleft > 1 ) {
3052: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3053: ' </td>';
3054: } elsif ($colsleft == 1) {
3055: $targettable .= '<td class="LC_left_item"> </td>';
3056: }
3057: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3058: '<table><tr>'.$targettable.'</tr></table><br />';
3059: }
3060: }
3061: $datatable .= '</div></td></tr>'.
3062: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3063: $othertitle,$usertypes,$types,\%servers,
3064: \%currbalancer,$lonhost,
3065: $targets_div_style,$homedom_div_style,
3066: $css_class[$cssidx],$balnum,$islast);
3067: $$rowtotal += $rownum;
3068: $balnum ++;
3069: }
3070: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3071: return $datatable;
3072: }
3073:
3074: sub get_loadbalancers_config {
3075: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3076: return unless ((ref($servers) eq 'HASH') &&
3077: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3078: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3079: if (keys(%{$existing}) > 0) {
3080: my $oldlonhost;
3081: foreach my $key (sort(keys(%{$existing}))) {
3082: if ($key eq 'lonhost') {
3083: $oldlonhost = $existing->{'lonhost'};
3084: $currbalancer->{$oldlonhost} = 1;
3085: } elsif ($key eq 'targets') {
3086: if ($oldlonhost) {
3087: $currtargets->{$oldlonhost} = $existing->{'targets'};
3088: }
3089: } elsif ($key eq 'rules') {
3090: if ($oldlonhost) {
3091: $currrules->{$oldlonhost} = $existing->{'rules'};
3092: }
3093: } elsif (ref($existing->{$key}) eq 'HASH') {
3094: $currbalancer->{$key} = 1;
3095: $currtargets->{$key} = $existing->{$key}{'targets'};
3096: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3097: }
3098: }
1.160.6.7 raeburn 3099: } else {
3100: my ($balancerref,$targetsref) =
3101: &Apache::lonnet::get_lonbalancer_config($servers);
3102: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3103: foreach my $server (sort(keys(%{$balancerref}))) {
3104: $currbalancer->{$server} = 1;
3105: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3106: }
3107: }
3108: }
1.160.6.7 raeburn 3109: return;
1.150 raeburn 3110: }
3111:
3112: sub loadbalancing_rules {
3113: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3114: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3115: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3116: my $output;
1.160.6.7 raeburn 3117: my $num = 0;
3118: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3119: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3120: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3121: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3122: $num ++;
1.150 raeburn 3123: my $current;
3124: if (ref($currrules) eq 'HASH') {
3125: $current = $currrules->{$type};
3126: }
3127: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3128: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3129: $current = '';
3130: }
3131: }
3132: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3133: $servers,$currbalancer,$lonhost,$dom,
3134: $targets_div_style,$homedom_div_style,
3135: $css_class,$balnum,$num,$islast);
1.150 raeburn 3136: }
3137: }
3138: return $output;
3139: }
3140:
3141: sub loadbalancing_titles {
3142: my ($dom,$intdom,$usertypes,$types) = @_;
3143: my %othertypes = (
3144: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3145: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3146: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3147: '_LC_external' => &mt('Users not from [_1]',$intdom),
3148: );
3149: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3150: if (ref($types) eq 'ARRAY') {
3151: unshift(@alltypes,@{$types},'default');
3152: }
3153: my %titles;
3154: foreach my $type (@alltypes) {
3155: if ($type =~ /^_LC_/) {
3156: $titles{$type} = $othertypes{$type};
3157: } elsif ($type eq 'default') {
3158: $titles{$type} = &mt('All users from [_1]',$dom);
3159: if (ref($types) eq 'ARRAY') {
3160: if (@{$types} > 0) {
3161: $titles{$type} = &mt('Other users from [_1]',$dom);
3162: }
3163: }
3164: } elsif (ref($usertypes) eq 'HASH') {
3165: $titles{$type} = $usertypes->{$type};
3166: }
3167: }
3168: return (\@alltypes,\%othertypes,\%titles);
3169: }
3170:
3171: sub loadbalance_rule_row {
1.160.6.7 raeburn 3172: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3173: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3174: my @rulenames = ('default','homeserver');
3175: my %ruletitles = &offloadtype_text();
3176: if ($type eq '_LC_external') {
3177: push(@rulenames,'externalbalancer');
3178: } else {
3179: push(@rulenames,'specific');
3180: }
1.160.6.3 raeburn 3181: push(@rulenames,'none');
1.150 raeburn 3182: my $style = $targets_div_style;
3183: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3184: $style = $homedom_div_style;
3185: }
1.160.6.7 raeburn 3186: my $space;
3187: if ($islast && $num == 1) {
3188: $space = '<div display="inline-block"> </div>';
3189: }
3190: my $output =
3191: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3192: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3193: '<td valaign="top">'.$space.
3194: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3195: for (my $i=0; $i<@rulenames; $i++) {
3196: my $rule = $rulenames[$i];
3197: my ($checked,$extra);
3198: if ($rulenames[$i] eq 'default') {
3199: $rule = '';
3200: }
3201: if ($rulenames[$i] eq 'specific') {
3202: if (ref($servers) eq 'HASH') {
3203: my $default;
3204: if (($current ne '') && (exists($servers->{$current}))) {
3205: $checked = ' checked="checked"';
3206: }
3207: unless ($checked) {
3208: $default = ' selected="selected"';
3209: }
1.160.6.7 raeburn 3210: $extra =
3211: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3212: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3213: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3214: '<option value=""'.$default.'></option>'."\n";
3215: foreach my $server (sort(keys(%{$servers}))) {
3216: if (ref($currbalancer) eq 'HASH') {
3217: next if (exists($currbalancer->{$server}));
3218: }
1.150 raeburn 3219: my $selected;
1.160.6.7 raeburn 3220: if ($server eq $current) {
1.150 raeburn 3221: $selected = ' selected="selected"';
3222: }
1.160.6.7 raeburn 3223: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3224: }
3225: $extra .= '</select>';
3226: }
3227: } elsif ($rule eq $current) {
3228: $checked = ' checked="checked"';
3229: }
3230: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3231: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3232: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3233: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3234: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3235: '</label>'.$extra.'</span><br />'."\n";
3236: }
3237: $output .= '</div></td></tr>'."\n";
3238: return $output;
3239: }
3240:
3241: sub offloadtype_text {
3242: my %ruletitles = &Apache::lonlocal::texthash (
3243: 'default' => 'Offloads to default destinations',
3244: 'homeserver' => "Offloads to user's home server",
3245: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3246: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3247: 'none' => 'No offload',
1.150 raeburn 3248: );
3249: return %ruletitles;
3250: }
3251:
3252: sub sparestype_titles {
3253: my %typestitles = &Apache::lonlocal::texthash (
3254: 'primary' => 'primary',
3255: 'default' => 'default',
3256: );
3257: return %typestitles;
3258: }
3259:
1.28 raeburn 3260: sub contact_titles {
3261: my %titles = &Apache::lonlocal::texthash (
3262: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3263: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3264: 'errormail' => 'Error reports to be e-mailed to',
3265: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3266: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3267: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3268: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3269: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.28 raeburn 3270: );
3271: my %short_titles = &Apache::lonlocal::texthash (
3272: adminemail => 'Admin E-mail address',
3273: supportemail => 'Support E-mail',
3274: );
3275: return (\%titles,\%short_titles);
3276: }
3277:
1.72 raeburn 3278: sub tool_titles {
3279: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3280: aboutme => 'Personal web page',
1.86 raeburn 3281: blog => 'Blog',
1.160.6.4 raeburn 3282: webdav => 'WebDAV',
1.86 raeburn 3283: portfolio => 'Portfolio',
1.88 bisitz 3284: official => 'Official courses (with institutional codes)',
3285: unofficial => 'Unofficial courses',
1.98 raeburn 3286: community => 'Communities',
1.86 raeburn 3287: );
1.72 raeburn 3288: return %titles;
3289: }
3290:
1.101 raeburn 3291: sub courserequest_titles {
3292: my %titles = &Apache::lonlocal::texthash (
3293: official => 'Official',
3294: unofficial => 'Unofficial',
3295: community => 'Communities',
3296: norequest => 'Not allowed',
1.104 raeburn 3297: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3298: validate => 'With validation',
3299: autolimit => 'Numerical limit',
1.103 raeburn 3300: unlimited => '(blank for unlimited)',
1.101 raeburn 3301: );
3302: return %titles;
3303: }
3304:
1.160.6.5 raeburn 3305: sub authorrequest_titles {
3306: my %titles = &Apache::lonlocal::texthash (
3307: norequest => 'Not allowed',
3308: approval => 'Approval by Dom. Coord.',
3309: automatic => 'Automatic approval',
3310: );
3311: return %titles;
3312: }
3313:
1.101 raeburn 3314: sub courserequest_conditions {
3315: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3316: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3317: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3318: );
3319: return %conditions;
3320: }
3321:
3322:
1.27 raeburn 3323: sub print_usercreation {
1.30 raeburn 3324: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3325: my $numinrow = 4;
1.28 raeburn 3326: my $datatable;
3327: if ($position eq 'top') {
1.30 raeburn 3328: $$rowtotal ++;
1.34 raeburn 3329: my $rowcount = 0;
1.32 raeburn 3330: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3331: if (ref($rules) eq 'HASH') {
3332: if (keys(%{$rules}) > 0) {
1.32 raeburn 3333: $datatable .= &user_formats_row('username',$settings,$rules,
3334: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3335: $$rowtotal ++;
1.32 raeburn 3336: $rowcount ++;
3337: }
3338: }
3339: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3340: if (ref($idrules) eq 'HASH') {
3341: if (keys(%{$idrules}) > 0) {
3342: $datatable .= &user_formats_row('id',$settings,$idrules,
3343: $idruleorder,$numinrow,$rowcount);
3344: $$rowtotal ++;
3345: $rowcount ++;
1.28 raeburn 3346: }
3347: }
1.43 raeburn 3348: my ($emailrules,$emailruleorder) =
3349: &Apache::lonnet::inst_userrules($dom,'email');
3350: if (ref($emailrules) eq 'HASH') {
3351: if (keys(%{$emailrules}) > 0) {
3352: $datatable .= &user_formats_row('email',$settings,$emailrules,
3353: $emailruleorder,$numinrow,$rowcount);
3354: $$rowtotal ++;
3355: $rowcount ++;
3356: }
3357: }
1.39 raeburn 3358: if ($rowcount == 0) {
3359: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3360: $$rowtotal ++;
3361: $rowcount ++;
3362: }
1.34 raeburn 3363: } elsif ($position eq 'middle') {
1.100 raeburn 3364: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3365: my ($rules,$ruleorder) =
3366: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3367: my %lt = &usercreation_types();
3368: my %checked;
1.50 raeburn 3369: my @selfcreate;
1.34 raeburn 3370: if (ref($settings) eq 'HASH') {
3371: if (ref($settings->{'cancreate'}) eq 'HASH') {
3372: foreach my $item (@creators) {
3373: $checked{$item} = $settings->{'cancreate'}{$item};
3374: }
1.50 raeburn 3375: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3376: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3377: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3378: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3379: @selfcreate = ('email','login','sso');
3380: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3381: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3382: }
3383: }
1.34 raeburn 3384: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3385: foreach my $item (@creators) {
3386: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3387: $checked{$item} = 'none';
3388: }
3389: }
3390: }
3391: }
3392: my $rownum = 0;
3393: foreach my $item (@creators) {
3394: $rownum ++;
1.50 raeburn 3395: if ($item ne 'selfcreate') {
3396: if ($checked{$item} eq '') {
1.43 raeburn 3397: $checked{$item} = 'any';
3398: }
1.34 raeburn 3399: }
3400: my $css_class;
3401: if ($rownum%2) {
3402: $css_class = '';
3403: } else {
3404: $css_class = ' class="LC_odd_row" ';
3405: }
3406: $datatable .= '<tr'.$css_class.'>'.
3407: '<td><span class="LC_nobreak">'.$lt{$item}.
3408: '</span></td><td align="right">';
1.50 raeburn 3409: my @options;
1.45 raeburn 3410: if ($item eq 'selfcreate') {
1.43 raeburn 3411: push(@options,('email','login','sso'));
3412: } else {
1.50 raeburn 3413: @options = ('any');
1.43 raeburn 3414: if (ref($rules) eq 'HASH') {
3415: if (keys(%{$rules}) > 0) {
3416: push(@options,('official','unofficial'));
3417: }
1.37 raeburn 3418: }
1.50 raeburn 3419: push(@options,'none');
1.37 raeburn 3420: }
3421: foreach my $option (@options) {
1.50 raeburn 3422: my $type = 'radio';
1.34 raeburn 3423: my $check = ' ';
1.50 raeburn 3424: if ($item eq 'selfcreate') {
3425: $type = 'checkbox';
3426: if (grep(/^\Q$option\E$/,@selfcreate)) {
3427: $check = ' checked="checked" ';
3428: }
3429: } else {
3430: if ($checked{$item} eq $option) {
3431: $check = ' checked="checked" ';
3432: }
1.34 raeburn 3433: }
3434: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3435: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3436: $item.'" value="'.$option.'"'.$check.'/> '.
3437: $lt{$option}.'</label> </span>';
3438: }
3439: $datatable .= '</td></tr>';
3440: }
1.93 raeburn 3441: my ($othertitle,$usertypes,$types) =
3442: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3443: my $createsettings;
3444: if (ref($settings) eq 'HASH') {
3445: $createsettings = $settings->{cancreate};
3446: }
1.93 raeburn 3447: if (ref($usertypes) eq 'HASH') {
3448: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3449: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3450: $dom,$numinrow,$othertitle,
3451: 'statustocreate');
3452: $$rowtotal ++;
1.160.6.5 raeburn 3453: $rownum ++;
1.93 raeburn 3454: }
3455: }
1.160.6.5 raeburn 3456: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3457: } else {
3458: my @contexts = ('author','course','domain');
3459: my @authtypes = ('int','krb4','krb5','loc');
3460: my %checked;
3461: if (ref($settings) eq 'HASH') {
3462: if (ref($settings->{'authtypes'}) eq 'HASH') {
3463: foreach my $item (@contexts) {
3464: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3465: foreach my $auth (@authtypes) {
3466: if ($settings->{'authtypes'}{$item}{$auth}) {
3467: $checked{$item}{$auth} = ' checked="checked" ';
3468: }
3469: }
3470: }
3471: }
1.27 raeburn 3472: }
1.35 raeburn 3473: } else {
3474: foreach my $item (@contexts) {
1.36 raeburn 3475: foreach my $auth (@authtypes) {
1.35 raeburn 3476: $checked{$item}{$auth} = ' checked="checked" ';
3477: }
3478: }
1.27 raeburn 3479: }
1.28 raeburn 3480: my %title = &context_names();
3481: my %authname = &authtype_names();
3482: my $rownum = 0;
3483: my $css_class;
3484: foreach my $item (@contexts) {
3485: if ($rownum%2) {
3486: $css_class = '';
3487: } else {
3488: $css_class = ' class="LC_odd_row" ';
3489: }
1.30 raeburn 3490: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3491: '<td>'.$title{$item}.
3492: '</td><td class="LC_left_item">'.
3493: '<span class="LC_nobreak">';
3494: foreach my $auth (@authtypes) {
3495: $datatable .= '<label>'.
3496: '<input type="checkbox" name="'.$item.'_auth" '.
3497: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3498: $authname{$auth}.'</label> ';
3499: }
3500: $datatable .= '</span></td></tr>';
3501: $rownum ++;
1.27 raeburn 3502: }
1.30 raeburn 3503: $$rowtotal += $rownum;
1.27 raeburn 3504: }
3505: return $datatable;
3506: }
3507:
1.160.6.5 raeburn 3508: sub captcha_choice {
3509: my ($context,$settings,$itemcount) = @_;
3510: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3511: my %lt = &captcha_phrases();
3512: $keyentry = 'hidden';
3513: if ($context eq 'cancreate') {
3514: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3515: } elsif ($context eq 'login') {
3516: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3517: }
3518: if (ref($settings) eq 'HASH') {
3519: if ($settings->{'captcha'}) {
3520: $checked{$settings->{'captcha'}} = ' checked="checked"';
3521: } else {
3522: $checked{'original'} = ' checked="checked"';
3523: }
3524: if ($settings->{'captcha'} eq 'recaptcha') {
3525: $pubtext = $lt{'pub'};
3526: $privtext = $lt{'priv'};
3527: $keyentry = 'text';
3528: }
3529: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3530: $currpub = $settings->{'recaptchakeys'}{'public'};
3531: $currpriv = $settings->{'recaptchakeys'}{'private'};
3532: }
3533: } else {
3534: $checked{'original'} = ' checked="checked"';
3535: }
3536: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3537: my $output = '<tr'.$css_class.'>'.
3538: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3539: '<table><tr><td>'."\n";
3540: foreach my $option ('original','recaptcha','notused') {
3541: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3542: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3543: $lt{$option}.'</label></span>';
3544: unless ($option eq 'notused') {
3545: $output .= (' 'x2)."\n";
3546: }
3547: }
3548: #
3549: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3550: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3551: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3552: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3553: #
3554: $output .= '</td></tr>'."\n".
3555: '<tr><td>'."\n".
3556: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3557: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3558: $currpub.'" size="40" /></span><br />'."\n".
3559: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3560: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3561: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3562: '</td></tr>';
3563: return $output;
3564: }
3565:
1.32 raeburn 3566: sub user_formats_row {
3567: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3568: my $output;
3569: my %text = (
3570: 'username' => 'new usernames',
3571: 'id' => 'IDs',
1.45 raeburn 3572: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3573: );
3574: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3575: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3576: '<td><span class="LC_nobreak">';
3577: if ($type eq 'email') {
3578: $output .= &mt("Formats disallowed for $text{$type}: ");
3579: } else {
3580: $output .= &mt("Format rules to check for $text{$type}: ");
3581: }
3582: $output .= '</span></td>'.
3583: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3584: my $rem;
3585: if (ref($ruleorder) eq 'ARRAY') {
3586: for (my $i=0; $i<@{$ruleorder}; $i++) {
3587: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3588: my $rem = $i%($numinrow);
3589: if ($rem == 0) {
3590: if ($i > 0) {
3591: $output .= '</tr>';
3592: }
3593: $output .= '<tr>';
3594: }
3595: my $check = ' ';
1.39 raeburn 3596: if (ref($settings) eq 'HASH') {
3597: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3598: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3599: $check = ' checked="checked" ';
3600: }
1.27 raeburn 3601: }
3602: }
3603: $output .= '<td class="LC_left_item">'.
3604: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3605: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3606: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3607: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3608: }
3609: }
3610: $rem = @{$ruleorder}%($numinrow);
3611: }
3612: my $colsleft = $numinrow - $rem;
3613: if ($colsleft > 1 ) {
3614: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3615: ' </td>';
3616: } elsif ($colsleft == 1) {
3617: $output .= '<td class="LC_left_item"> </td>';
3618: }
3619: $output .= '</tr></table></td></tr>';
3620: return $output;
3621: }
3622:
1.34 raeburn 3623: sub usercreation_types {
3624: my %lt = &Apache::lonlocal::texthash (
3625: author => 'When adding a co-author',
3626: course => 'When adding a user to a course',
1.100 raeburn 3627: requestcrs => 'When requesting a course',
1.45 raeburn 3628: selfcreate => 'User creates own account',
1.34 raeburn 3629: any => 'Any',
3630: official => 'Institutional only ',
3631: unofficial => 'Non-institutional only',
1.85 schafran 3632: email => 'E-mail address',
1.43 raeburn 3633: login => 'Institutional Login',
3634: sso => 'SSO',
1.34 raeburn 3635: none => 'None',
3636: );
3637: return %lt;
1.48 raeburn 3638: }
1.34 raeburn 3639:
1.28 raeburn 3640: sub authtype_names {
3641: my %lt = &Apache::lonlocal::texthash(
3642: int => 'Internal',
3643: krb4 => 'Kerberos 4',
3644: krb5 => 'Kerberos 5',
3645: loc => 'Local',
3646: );
3647: return %lt;
3648: }
3649:
3650: sub context_names {
3651: my %context_title = &Apache::lonlocal::texthash(
3652: author => 'Creating users when an Author',
3653: course => 'Creating users when in a course',
3654: domain => 'Creating users when a Domain Coordinator',
3655: );
3656: return %context_title;
3657: }
3658:
1.33 raeburn 3659: sub print_usermodification {
3660: my ($position,$dom,$settings,$rowtotal) = @_;
3661: my $numinrow = 4;
3662: my ($context,$datatable,$rowcount);
3663: if ($position eq 'top') {
3664: $rowcount = 0;
3665: $context = 'author';
3666: foreach my $role ('ca','aa') {
3667: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3668: $numinrow,$rowcount);
3669: $$rowtotal ++;
3670: $rowcount ++;
3671: }
1.63 raeburn 3672: } elsif ($position eq 'middle') {
1.33 raeburn 3673: $context = 'course';
3674: $rowcount = 0;
3675: foreach my $role ('st','ep','ta','in','cr') {
3676: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3677: $numinrow,$rowcount);
3678: $$rowtotal ++;
3679: $rowcount ++;
3680: }
1.63 raeburn 3681: } elsif ($position eq 'bottom') {
3682: $context = 'selfcreate';
3683: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3684: $usertypes->{'default'} = $othertitle;
3685: if (ref($types) eq 'ARRAY') {
3686: push(@{$types},'default');
3687: $usertypes->{'default'} = $othertitle;
3688: foreach my $status (@{$types}) {
3689: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3690: $numinrow,$rowcount,$usertypes);
3691: $$rowtotal ++;
3692: $rowcount ++;
3693: }
3694: }
1.33 raeburn 3695: }
3696: return $datatable;
3697: }
3698:
1.43 raeburn 3699: sub print_defaults {
3700: my ($dom,$rowtotal) = @_;
1.68 raeburn 3701: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3702: 'datelocale_def','portal_def');
1.43 raeburn 3703: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3704: my $titles = &defaults_titles($dom);
1.43 raeburn 3705: my $rownum = 0;
3706: my ($datatable,$css_class);
3707: foreach my $item (@items) {
3708: if ($rownum%2) {
3709: $css_class = '';
3710: } else {
3711: $css_class = ' class="LC_odd_row" ';
3712: }
3713: $datatable .= '<tr'.$css_class.'>'.
3714: '<td><span class="LC_nobreak">'.$titles->{$item}.
3715: '</span></td><td class="LC_right_item">';
3716: if ($item eq 'auth_def') {
3717: my @authtypes = ('internal','krb4','krb5','localauth');
3718: my %shortauth = (
3719: internal => 'int',
3720: krb4 => 'krb4',
3721: krb5 => 'krb5',
3722: localauth => 'loc'
3723: );
3724: my %authnames = &authtype_names();
3725: foreach my $auth (@authtypes) {
3726: my $checked = ' ';
3727: if ($domdefaults{$item} eq $auth) {
3728: $checked = ' checked="checked" ';
3729: }
3730: $datatable .= '<label><input type="radio" name="'.$item.
3731: '" value="'.$auth.'"'.$checked.'/>'.
3732: $authnames{$shortauth{$auth}}.'</label> ';
3733: }
1.54 raeburn 3734: } elsif ($item eq 'timezone_def') {
3735: my $includeempty = 1;
3736: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3737: } elsif ($item eq 'datelocale_def') {
3738: my $includeempty = 1;
3739: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3740: } elsif ($item eq 'lang_def') {
3741: my %langchoices = &get_languages_hash();
3742: $langchoices{''} = 'No language preference';
3743: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3744: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3745: \%langchoices);
1.43 raeburn 3746: } else {
1.141 raeburn 3747: my $size;
3748: if ($item eq 'portal_def') {
3749: $size = ' size="25"';
3750: }
1.43 raeburn 3751: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3752: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3753: }
3754: $datatable .= '</td></tr>';
3755: $rownum ++;
3756: }
3757: $$rowtotal += $rownum;
3758: return $datatable;
3759: }
3760:
1.160.6.5 raeburn 3761: sub get_languages_hash {
3762: my %langchoices;
3763: foreach my $id (&Apache::loncommon::languageids()) {
3764: my $code = &Apache::loncommon::supportedlanguagecode($id);
3765: if ($code ne '') {
3766: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3767: }
3768: }
3769: return %langchoices;
3770: }
3771:
1.43 raeburn 3772: sub defaults_titles {
1.141 raeburn 3773: my ($dom) = @_;
1.43 raeburn 3774: my %titles = &Apache::lonlocal::texthash (
3775: 'auth_def' => 'Default authentication type',
3776: 'auth_arg_def' => 'Default authentication argument',
3777: 'lang_def' => 'Default language',
1.54 raeburn 3778: 'timezone_def' => 'Default timezone',
1.68 raeburn 3779: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3780: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3781: );
1.141 raeburn 3782: if ($dom) {
3783: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3784: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3785: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3786: $protocol = 'http' if ($protocol ne 'https');
3787: if ($uint_dom) {
3788: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3789: $uint_dom);
3790: }
3791: }
1.43 raeburn 3792: return (\%titles);
3793: }
3794:
1.46 raeburn 3795: sub print_scantronformat {
3796: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3797: my $itemcount = 1;
1.60 raeburn 3798: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3799: %confhash);
1.46 raeburn 3800: my $switchserver = &check_switchserver($dom,$confname);
3801: my %lt = &Apache::lonlocal::texthash (
1.95 www 3802: default => 'Default bubblesheet format file error',
3803: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3804: );
3805: my %scantronfiles = (
3806: default => 'default.tab',
3807: custom => 'custom.tab',
3808: );
3809: foreach my $key (keys(%scantronfiles)) {
3810: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3811: .$scantronfiles{$key};
3812: }
3813: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3814: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3815: if (!$switchserver) {
3816: my $servadm = $r->dir_config('lonAdmEMail');
3817: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3818: if ($configuserok eq 'ok') {
3819: if ($author_ok eq 'ok') {
3820: my %legacyfile = (
3821: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3822: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3823: );
3824: my %md5chk;
3825: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3826: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3827: chomp($md5chk{$type});
1.46 raeburn 3828: }
3829: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3830: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3831: ($scantronurls{$type},my $error) =
1.46 raeburn 3832: &legacy_scantronformat($r,$dom,$confname,
3833: $type,$legacyfile{$type},
3834: $scantronurls{$type},
3835: $scantronfiles{$type});
1.60 raeburn 3836: if ($error ne '') {
3837: $error{$type} = $error;
3838: }
3839: }
3840: if (keys(%error) == 0) {
3841: $is_custom = 1;
3842: $confhash{'scantron'}{'scantronformat'} =
3843: $scantronurls{'custom'};
3844: my $putresult =
3845: &Apache::lonnet::put_dom('configuration',
3846: \%confhash,$dom);
3847: if ($putresult ne 'ok') {
3848: $error{'custom'} =
3849: '<span class="LC_error">'.
3850: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3851: }
1.46 raeburn 3852: }
3853: } else {
1.60 raeburn 3854: ($scantronurls{'default'},my $error) =
1.46 raeburn 3855: &legacy_scantronformat($r,$dom,$confname,
3856: 'default',$legacyfile{'default'},
3857: $scantronurls{'default'},
3858: $scantronfiles{'default'});
1.60 raeburn 3859: if ($error eq '') {
3860: $confhash{'scantron'}{'scantronformat'} = '';
3861: my $putresult =
3862: &Apache::lonnet::put_dom('configuration',
3863: \%confhash,$dom);
3864: if ($putresult ne 'ok') {
3865: $error{'default'} =
3866: '<span class="LC_error">'.
3867: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3868: }
3869: } else {
3870: $error{'default'} = $error;
3871: }
1.46 raeburn 3872: }
3873: }
3874: }
3875: } else {
1.95 www 3876: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3877: }
3878: }
3879: if (ref($settings) eq 'HASH') {
3880: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3881: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3882: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3883: $scantronurl = '';
3884: } else {
3885: $scantronurl = $settings->{'scantronformat'};
3886: }
3887: $is_custom = 1;
3888: } else {
3889: $scantronurl = $scantronurls{'default'};
3890: }
3891: } else {
1.60 raeburn 3892: if ($is_custom) {
3893: $scantronurl = $scantronurls{'custom'};
3894: } else {
3895: $scantronurl = $scantronurls{'default'};
3896: }
1.46 raeburn 3897: }
3898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3899: $datatable .= '<tr'.$css_class.'>';
3900: if (!$is_custom) {
1.65 raeburn 3901: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3902: '<span class="LC_nobreak">';
1.46 raeburn 3903: if ($scantronurl) {
1.160.6.21! raeburn 3904: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
! 3905: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 3906: } else {
3907: $datatable = &mt('File unavailable for display');
3908: }
1.65 raeburn 3909: $datatable .= '</span></td>';
1.60 raeburn 3910: if (keys(%error) == 0) {
3911: $datatable .= '<td valign="bottom">';
3912: if (!$switchserver) {
3913: $datatable .= &mt('Upload:').'<br />';
3914: }
3915: } else {
3916: my $errorstr;
3917: foreach my $key (sort(keys(%error))) {
3918: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3919: }
3920: $datatable .= '<td>'.$errorstr;
3921: }
1.46 raeburn 3922: } else {
3923: if (keys(%error) > 0) {
3924: my $errorstr;
3925: foreach my $key (sort(keys(%error))) {
3926: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3927: }
1.60 raeburn 3928: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3929: } elsif ($scantronurl) {
1.160.6.21! raeburn 3930: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
! 3931: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 3932: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21! raeburn 3933: $link.
! 3934: '<label><input type="checkbox" name="scantronformat_del"'.
! 3935: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 3936: '<td><span class="LC_nobreak"> '.
3937: &mt('Replace:').'</span><br />';
1.46 raeburn 3938: }
3939: }
3940: if (keys(%error) == 0) {
3941: if ($switchserver) {
3942: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3943: } else {
1.65 raeburn 3944: $datatable .='<span class="LC_nobreak"> '.
3945: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3946: }
3947: }
3948: $datatable .= '</td></tr>';
3949: $$rowtotal ++;
3950: return $datatable;
3951: }
3952:
3953: sub legacy_scantronformat {
3954: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3955: my ($url,$error);
3956: my @statinfo = &Apache::lonnet::stat_file($newurl);
3957: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3958: (my $result,$url) =
3959: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3960: '','',$newfile);
3961: if ($result ne 'ok') {
1.130 raeburn 3962: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3963: }
3964: }
3965: return ($url,$error);
3966: }
1.43 raeburn 3967:
1.49 raeburn 3968: sub print_coursecategories {
1.57 raeburn 3969: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3970: my $datatable;
3971: if ($position eq 'top') {
3972: my $toggle_cats_crs = ' ';
3973: my $toggle_cats_dom = ' checked="checked" ';
3974: my $can_cat_crs = ' ';
3975: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3976: my $toggle_catscomm_comm = ' ';
3977: my $toggle_catscomm_dom = ' checked="checked" ';
3978: my $can_catcomm_comm = ' ';
3979: my $can_catcomm_dom = ' checked="checked" ';
3980:
1.57 raeburn 3981: if (ref($settings) eq 'HASH') {
3982: if ($settings->{'togglecats'} eq 'crs') {
3983: $toggle_cats_crs = $toggle_cats_dom;
3984: $toggle_cats_dom = ' ';
3985: }
3986: if ($settings->{'categorize'} eq 'crs') {
3987: $can_cat_crs = $can_cat_dom;
3988: $can_cat_dom = ' ';
3989: }
1.120 raeburn 3990: if ($settings->{'togglecatscomm'} eq 'comm') {
3991: $toggle_catscomm_comm = $toggle_catscomm_dom;
3992: $toggle_catscomm_dom = ' ';
3993: }
3994: if ($settings->{'categorizecomm'} eq 'comm') {
3995: $can_catcomm_comm = $can_catcomm_dom;
3996: $can_catcomm_dom = ' ';
3997: }
1.57 raeburn 3998: }
3999: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4000: togglecats => 'Show/Hide a course in catalog',
4001: togglecatscomm => 'Show/Hide a community in catalog',
4002: categorize => 'Assign a category to a course',
4003: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4004: );
4005: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4006: dom => 'Set in Domain',
4007: crs => 'Set in Course',
4008: comm => 'Set in Community',
1.57 raeburn 4009: );
4010: $datatable = '<tr class="LC_odd_row">'.
4011: '<td>'.$title{'togglecats'}.'</td>'.
4012: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4013: '<input type="radio" name="togglecats"'.
4014: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4015: '<label><input type="radio" name="togglecats"'.
4016: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4017: '</tr><tr>'.
4018: '<td>'.$title{'categorize'}.'</td>'.
4019: '<td class="LC_right_item"><span class="LC_nobreak">'.
4020: '<label><input type="radio" name="categorize"'.
4021: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4022: '<label><input type="radio" name="categorize"'.
4023: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4024: '</tr><tr class="LC_odd_row">'.
4025: '<td>'.$title{'togglecatscomm'}.'</td>'.
4026: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4027: '<input type="radio" name="togglecatscomm"'.
4028: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4029: '<label><input type="radio" name="togglecatscomm"'.
4030: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4031: '</tr><tr>'.
4032: '<td>'.$title{'categorizecomm'}.'</td>'.
4033: '<td class="LC_right_item"><span class="LC_nobreak">'.
4034: '<label><input type="radio" name="categorizecomm"'.
4035: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4036: '<label><input type="radio" name="categorizecomm"'.
4037: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4038: '</tr>';
1.120 raeburn 4039: $$rowtotal += 4;
1.57 raeburn 4040: } else {
4041: my $css_class;
4042: my $itemcount = 1;
4043: my $cathash;
4044: if (ref($settings) eq 'HASH') {
4045: $cathash = $settings->{'cats'};
4046: }
4047: if (ref($cathash) eq 'HASH') {
4048: my (@cats,@trails,%allitems,%idx,@jsarray);
4049: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4050: \%allitems,\%idx,\@jsarray);
4051: my $maxdepth = scalar(@cats);
4052: my $colattrib = '';
4053: if ($maxdepth > 2) {
4054: $colattrib = ' colspan="2" ';
4055: }
4056: my @path;
4057: if (@cats > 0) {
4058: if (ref($cats[0]) eq 'ARRAY') {
4059: my $numtop = @{$cats[0]};
4060: my $maxnum = $numtop;
1.120 raeburn 4061: my %default_names = (
4062: instcode => &mt('Official courses'),
4063: communities => &mt('Communities'),
4064: );
4065:
4066: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4067: ($cathash->{'instcode::0'} eq '') ||
4068: (!grep(/^communities$/,@{$cats[0]})) ||
4069: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4070: $maxnum ++;
4071: }
4072: my $lastidx;
4073: for (my $i=0; $i<$numtop; $i++) {
4074: my $parent = $cats[0][$i];
4075: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4076: my $item = &escape($parent).'::0';
4077: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4078: $lastidx = $idx{$item};
4079: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4080: .'<select name="'.$item.'"'.$chgstr.'>';
4081: for (my $k=0; $k<=$maxnum; $k++) {
4082: my $vpos = $k+1;
4083: my $selstr;
4084: if ($k == $i) {
4085: $selstr = ' selected="selected" ';
4086: }
4087: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4088: }
4089: $datatable .= '</select></td><td>';
1.120 raeburn 4090: if ($parent eq 'instcode' || $parent eq 'communities') {
4091: $datatable .= '<span class="LC_nobreak">'
4092: .$default_names{$parent}.'</span>';
4093: if ($parent eq 'instcode') {
4094: $datatable .= '<br /><span class="LC_nobreak">('
4095: .&mt('with institutional codes')
4096: .')</span></td><td'.$colattrib.'>';
4097: } else {
4098: $datatable .= '<table><tr><td>';
4099: }
4100: $datatable .= '<span class="LC_nobreak">'
4101: .'<label><input type="radio" name="'
4102: .$parent.'" value="1" checked="checked" />'
4103: .&mt('Display').'</label>';
4104: if ($parent eq 'instcode') {
4105: $datatable .= ' ';
4106: } else {
4107: $datatable .= '</span></td></tr><tr><td>'
4108: .'<span class="LC_nobreak">';
4109: }
4110: $datatable .= '<label><input type="radio" name="'
4111: .$parent.'" value="0" />'
4112: .&mt('Do not display').'</label></span>';
4113: if ($parent eq 'communities') {
4114: $datatable .= '</td></tr></table>';
4115: }
4116: $datatable .= '</td>';
1.57 raeburn 4117: } else {
4118: $datatable .= $parent
4119: .' <label><input type="checkbox" name="deletecategory" '
4120: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4121: }
4122: my $depth = 1;
4123: push(@path,$parent);
4124: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4125: pop(@path);
4126: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4127: $itemcount ++;
4128: }
1.48 raeburn 4129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4130: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4131: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4132: for (my $k=0; $k<=$maxnum; $k++) {
4133: my $vpos = $k+1;
4134: my $selstr;
1.57 raeburn 4135: if ($k == $numtop) {
1.48 raeburn 4136: $selstr = ' selected="selected" ';
4137: }
4138: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4139: }
1.59 bisitz 4140: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4141: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4142: .'</tr>'."\n";
1.48 raeburn 4143: $itemcount ++;
1.120 raeburn 4144: foreach my $default ('instcode','communities') {
4145: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4146: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4147: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4148: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4149: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4150: for (my $k=0; $k<=$maxnum; $k++) {
4151: my $vpos = $k+1;
4152: my $selstr;
4153: if ($k == $maxnum) {
4154: $selstr = ' selected="selected" ';
4155: }
4156: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4157: }
1.120 raeburn 4158: $datatable .= '</select></span></td>'.
4159: '<td><span class="LC_nobreak">'.
4160: $default_names{$default}.'</span>';
4161: if ($default eq 'instcode') {
4162: $datatable .= '<br /><span class="LC_nobreak">('
4163: .&mt('with institutional codes').')</span>';
4164: }
4165: $datatable .= '</td>'
4166: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4167: .&mt('Display').'</label> '
4168: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4169: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4170: }
4171: }
4172: }
1.57 raeburn 4173: } else {
4174: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4175: }
4176: } else {
1.57 raeburn 4177: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4178: .&initialize_categories($itemcount);
1.48 raeburn 4179: }
1.57 raeburn 4180: $$rowtotal += $itemcount;
1.48 raeburn 4181: }
4182: return $datatable;
4183: }
4184:
1.69 raeburn 4185: sub print_serverstatuses {
4186: my ($dom,$settings,$rowtotal) = @_;
4187: my $datatable;
4188: my @pages = &serverstatus_pages();
4189: my (%namedaccess,%machineaccess);
4190: foreach my $type (@pages) {
4191: $namedaccess{$type} = '';
4192: $machineaccess{$type}= '';
4193: }
4194: if (ref($settings) eq 'HASH') {
4195: foreach my $type (@pages) {
4196: if (exists($settings->{$type})) {
4197: if (ref($settings->{$type}) eq 'HASH') {
4198: foreach my $key (keys(%{$settings->{$type}})) {
4199: if ($key eq 'namedusers') {
4200: $namedaccess{$type} = $settings->{$type}->{$key};
4201: } elsif ($key eq 'machines') {
4202: $machineaccess{$type} = $settings->{$type}->{$key};
4203: }
4204: }
4205: }
4206: }
4207: }
4208: }
1.81 raeburn 4209: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4210: my $rownum = 0;
4211: my $css_class;
4212: foreach my $type (@pages) {
4213: $rownum ++;
4214: $css_class = $rownum%2?' class="LC_odd_row"':'';
4215: $datatable .= '<tr'.$css_class.'>'.
4216: '<td><span class="LC_nobreak">'.
4217: $titles->{$type}.'</span></td>'.
4218: '<td class="LC_left_item">'.
4219: '<input type="text" name="'.$type.'_namedusers" '.
4220: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4221: '<td class="LC_right_item">'.
4222: '<span class="LC_nobreak">'.
4223: '<input type="text" name="'.$type.'_machines" '.
4224: 'value="'.$machineaccess{$type}.'" size="10" />'.
4225: '</td></tr>'."\n";
4226: }
4227: $$rowtotal += $rownum;
4228: return $datatable;
4229: }
4230:
4231: sub serverstatus_pages {
4232: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4233: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4234: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4235: }
4236:
1.49 raeburn 4237: sub coursecategories_javascript {
4238: my ($settings) = @_;
1.57 raeburn 4239: my ($output,$jstext,$cathash);
1.49 raeburn 4240: if (ref($settings) eq 'HASH') {
1.57 raeburn 4241: $cathash = $settings->{'cats'};
4242: }
4243: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4244: my (@cats,@jsarray,%idx);
1.57 raeburn 4245: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4246: if (@jsarray > 0) {
4247: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4248: for (my $i=0; $i<@jsarray; $i++) {
4249: if (ref($jsarray[$i]) eq 'ARRAY') {
4250: my $catstr = join('","',@{$jsarray[$i]});
4251: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4252: }
4253: }
4254: }
4255: } else {
4256: $jstext = ' var categories = Array(1);'."\n".
4257: ' categories[0] = Array("instcode_pos");'."\n";
4258: }
1.120 raeburn 4259: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4260: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4261: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4262: $output = <<"ENDSCRIPT";
4263: <script type="text/javascript">
1.109 raeburn 4264: // <![CDATA[
1.49 raeburn 4265: function reorderCats(form,parent,item,idx) {
4266: var changedVal;
4267: $jstext
4268: var newpos = 'addcategory_pos';
4269: var current = new Array;
4270: if (parent == '') {
4271: var has_instcode = 0;
4272: var maxtop = categories[idx].length;
4273: for (var j=0; j<maxtop; j++) {
4274: if (categories[idx][j] == 'instcode::0') {
4275: has_instcode == 1;
4276: }
4277: }
4278: if (has_instcode == 0) {
4279: categories[idx][maxtop] = 'instcode_pos';
4280: }
4281: } else {
4282: newpos += '_'+parent;
4283: }
4284: var maxh = 1 + categories[idx].length;
4285: var current = new Array;
4286: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4287: if (item == newpos) {
4288: changedVal = newitemVal;
4289: } else {
4290: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4291: current[newitemVal] = newpos;
4292: }
4293: for (var i=0; i<categories[idx].length; i++) {
4294: var elementName = categories[idx][i];
4295: if (elementName != item) {
4296: if (form.elements[elementName]) {
4297: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4298: current[currVal] = elementName;
4299: }
4300: }
4301: }
4302: var oldVal;
4303: for (var j=0; j<maxh; j++) {
4304: if (current[j] == undefined) {
4305: oldVal = j;
4306: }
4307: }
4308: if (oldVal < changedVal) {
4309: for (var k=oldVal+1; k<=changedVal ; k++) {
4310: var elementName = current[k];
4311: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4312: }
4313: } else {
4314: for (var k=changedVal; k<oldVal; k++) {
4315: var elementName = current[k];
4316: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4317: }
4318: }
4319: return;
4320: }
1.120 raeburn 4321:
4322: function categoryCheck(form) {
4323: if (form.elements['addcategory_name'].value == 'instcode') {
4324: alert('$instcode_reserved\\n$choose_again');
4325: return false;
4326: }
4327: if (form.elements['addcategory_name'].value == 'communities') {
4328: alert('$communities_reserved\\n$choose_again');
4329: return false;
4330: }
4331: return true;
4332: }
4333:
1.109 raeburn 4334: // ]]>
1.49 raeburn 4335: </script>
4336:
4337: ENDSCRIPT
4338: return $output;
4339: }
4340:
1.48 raeburn 4341: sub initialize_categories {
4342: my ($itemcount) = @_;
1.120 raeburn 4343: my ($datatable,$css_class,$chgstr);
4344: my %default_names = (
4345: instcode => 'Official courses (with institutional codes)',
4346: communities => 'Communities',
4347: );
4348: my $select0 = ' selected="selected"';
4349: my $select1 = '';
4350: foreach my $default ('instcode','communities') {
4351: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4352: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4353: if ($default eq 'communities') {
4354: $select1 = $select0;
4355: $select0 = '';
4356: }
4357: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4358: .'<select name="'.$default.'_pos">'
4359: .'<option value="0"'.$select0.'>1</option>'
4360: .'<option value="1"'.$select1.'>2</option>'
4361: .'<option value="2">3</option></select> '
4362: .$default_names{$default}
4363: .'</span></td><td><span class="LC_nobreak">'
4364: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4365: .&mt('Display').'</label> <label>'
4366: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4367: .'</label></span></td></tr>';
1.120 raeburn 4368: $itemcount ++;
4369: }
1.48 raeburn 4370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4371: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4372: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4373: .'<select name="addcategory_pos"'.$chgstr.'>'
4374: .'<option value="0">1</option>'
4375: .'<option value="1">2</option>'
4376: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4377: .&mt('Add category').'</td><td>'.&mt('Name:')
4378: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4379: return $datatable;
4380: }
4381:
4382: sub build_category_rows {
1.49 raeburn 4383: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4384: my ($text,$name,$item,$chgstr);
1.48 raeburn 4385: if (ref($cats) eq 'ARRAY') {
4386: my $maxdepth = scalar(@{$cats});
4387: if (ref($cats->[$depth]) eq 'HASH') {
4388: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4389: my $numchildren = @{$cats->[$depth]{$parent}};
4390: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4391: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4392: my ($idxnum,$parent_name,$parent_item);
4393: my $higher = $depth - 1;
4394: if ($higher == 0) {
4395: $parent_name = &escape($parent).'::'.$higher;
4396: } else {
4397: if (ref($path) eq 'ARRAY') {
4398: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4399: }
4400: }
4401: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4402: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4403: if ($j < $numchildren) {
1.48 raeburn 4404: $name = $cats->[$depth]{$parent}[$j];
4405: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4406: $idxnum = $idx->{$item};
4407: } else {
4408: $name = $parent_name;
4409: $item = $parent_item;
1.48 raeburn 4410: }
1.49 raeburn 4411: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4412: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4413: for (my $i=0; $i<=$numchildren; $i++) {
4414: my $vpos = $i+1;
4415: my $selstr;
4416: if ($j == $i) {
4417: $selstr = ' selected="selected" ';
4418: }
4419: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4420: }
4421: $text .= '</select> ';
4422: if ($j < $numchildren) {
4423: my $deeper = $depth+1;
4424: $text .= $name.' '
4425: .'<label><input type="checkbox" name="deletecategory" value="'
4426: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4427: if(ref($path) eq 'ARRAY') {
4428: push(@{$path},$name);
1.49 raeburn 4429: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4430: pop(@{$path});
4431: }
4432: } else {
1.59 bisitz 4433: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4434: if ($j == $numchildren) {
4435: $text .= $name;
4436: } else {
4437: $text .= $item;
4438: }
4439: $text .= '" value="" />';
4440: }
4441: $text .= '</td></tr>';
4442: }
4443: $text .= '</table></td>';
4444: } else {
4445: my $higher = $depth-1;
4446: if ($higher == 0) {
4447: $name = &escape($parent).'::'.$higher;
4448: } else {
4449: if (ref($path) eq 'ARRAY') {
4450: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4451: }
4452: }
4453: my $colspan;
4454: if ($parent ne 'instcode') {
4455: $colspan = $maxdepth - $depth - 1;
4456: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4457: }
4458: }
4459: }
4460: }
4461: return $text;
4462: }
4463:
1.33 raeburn 4464: sub modifiable_userdata_row {
1.63 raeburn 4465: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4466: my $rolename;
1.63 raeburn 4467: if ($context eq 'selfcreate') {
4468: if (ref($usertypes) eq 'HASH') {
4469: $rolename = $usertypes->{$role};
4470: } else {
4471: $rolename = $role;
4472: }
1.33 raeburn 4473: } else {
1.63 raeburn 4474: if ($role eq 'cr') {
4475: $rolename = &mt('Custom role');
4476: } else {
4477: $rolename = &Apache::lonnet::plaintext($role);
4478: }
1.33 raeburn 4479: }
4480: my @fields = ('lastname','firstname','middlename','generation',
4481: 'permanentemail','id');
4482: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4483: my $output;
4484: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4485: $output = '<tr '.$css_class.'>'.
4486: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4487: '<td class="LC_left_item" colspan="2"><table>';
4488: my $rem;
4489: my %checks;
4490: if (ref($settings) eq 'HASH') {
4491: if (ref($settings->{$context}) eq 'HASH') {
4492: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4493: foreach my $field (@fields) {
4494: if ($settings->{$context}->{$role}->{$field}) {
4495: $checks{$field} = ' checked="checked" ';
4496: }
4497: }
4498: }
4499: }
4500: }
4501: for (my $i=0; $i<@fields; $i++) {
4502: my $rem = $i%($numinrow);
4503: if ($rem == 0) {
4504: if ($i > 0) {
4505: $output .= '</tr>';
4506: }
4507: $output .= '<tr>';
4508: }
4509: my $check = ' ';
4510: if (exists($checks{$fields[$i]})) {
4511: $check = $checks{$fields[$i]}
4512: } else {
4513: if ($role eq 'st') {
4514: if (ref($settings) ne 'HASH') {
4515: $check = ' checked="checked" ';
4516: }
4517: }
4518: }
4519: $output .= '<td class="LC_left_item">'.
4520: '<span class="LC_nobreak"><label>'.
4521: '<input type="checkbox" name="canmodify_'.$role.'" '.
4522: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4523: '</label></span></td>';
4524: $rem = @fields%($numinrow);
4525: }
4526: my $colsleft = $numinrow - $rem;
4527: if ($colsleft > 1 ) {
4528: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4529: ' </td>';
4530: } elsif ($colsleft == 1) {
4531: $output .= '<td class="LC_left_item"> </td>';
4532: }
4533: $output .= '</tr></table></td></tr>';
4534: return $output;
4535: }
1.28 raeburn 4536:
1.93 raeburn 4537: sub insttypes_row {
4538: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4539: my %lt = &Apache::lonlocal::texthash (
4540: cansearch => 'Users allowed to search',
4541: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4542: lockablenames => 'User preference to lock name',
1.93 raeburn 4543: );
4544: my $showdom;
4545: if ($context eq 'cansearch') {
4546: $showdom = ' ('.$dom.')';
4547: }
1.160.6.5 raeburn 4548: my $class = 'LC_left_item';
4549: if ($context eq 'statustocreate') {
4550: $class = 'LC_right_item';
4551: }
1.25 raeburn 4552: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4553: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4554: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4555: my $rem;
4556: if (ref($types) eq 'ARRAY') {
4557: for (my $i=0; $i<@{$types}; $i++) {
4558: if (defined($usertypes->{$types->[$i]})) {
4559: my $rem = $i%($numinrow);
4560: if ($rem == 0) {
4561: if ($i > 0) {
4562: $output .= '</tr>';
4563: }
4564: $output .= '<tr>';
1.23 raeburn 4565: }
1.26 raeburn 4566: my $check = ' ';
1.99 raeburn 4567: if (ref($settings) eq 'HASH') {
4568: if (ref($settings->{$context}) eq 'ARRAY') {
4569: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4570: $check = ' checked="checked" ';
4571: }
4572: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4573: $check = ' checked="checked" ';
4574: }
1.23 raeburn 4575: }
1.26 raeburn 4576: $output .= '<td class="LC_left_item">'.
4577: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4578: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4579: 'value="'.$types->[$i].'"'.$check.'/>'.
4580: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4581: }
4582: }
1.26 raeburn 4583: $rem = @{$types}%($numinrow);
1.23 raeburn 4584: }
4585: my $colsleft = $numinrow - $rem;
1.131 raeburn 4586: if (($rem == 0) && (@{$types} > 0)) {
4587: $output .= '<tr>';
4588: }
1.23 raeburn 4589: if ($colsleft > 1) {
1.25 raeburn 4590: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4591: } else {
1.25 raeburn 4592: $output .= '<td class="LC_left_item">';
1.23 raeburn 4593: }
4594: my $defcheck = ' ';
1.99 raeburn 4595: if (ref($settings) eq 'HASH') {
4596: if (ref($settings->{$context}) eq 'ARRAY') {
4597: if (grep(/^default$/,@{$settings->{$context}})) {
4598: $defcheck = ' checked="checked" ';
4599: }
4600: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4601: $defcheck = ' checked="checked" ';
4602: }
1.23 raeburn 4603: }
1.25 raeburn 4604: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4605: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4606: 'value="default"'.$defcheck.'/>'.
4607: $othertitle.'</label></span></td>'.
4608: '</tr></table></td></tr>';
4609: return $output;
1.23 raeburn 4610: }
4611:
4612: sub sorted_searchtitles {
4613: my %searchtitles = &Apache::lonlocal::texthash(
4614: 'uname' => 'username',
4615: 'lastname' => 'last name',
4616: 'lastfirst' => 'last name, first name',
4617: );
4618: my @titleorder = ('uname','lastname','lastfirst');
4619: return (\%searchtitles,\@titleorder);
4620: }
4621:
1.25 raeburn 4622: sub sorted_searchtypes {
4623: my %srchtypes_desc = (
4624: exact => 'is exact match',
4625: contains => 'contains ..',
4626: begins => 'begins with ..',
4627: );
4628: my @srchtypeorder = ('exact','begins','contains');
4629: return (\%srchtypes_desc,\@srchtypeorder);
4630: }
4631:
1.3 raeburn 4632: sub usertype_update_row {
4633: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4634: my $datatable;
4635: my $numinrow = 4;
4636: foreach my $type (@{$types}) {
4637: if (defined($usertypes->{$type})) {
4638: $$rownums ++;
4639: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4640: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4641: '</td><td class="LC_left_item"><table>';
4642: for (my $i=0; $i<@{$fields}; $i++) {
4643: my $rem = $i%($numinrow);
4644: if ($rem == 0) {
4645: if ($i > 0) {
4646: $datatable .= '</tr>';
4647: }
4648: $datatable .= '<tr>';
4649: }
4650: my $check = ' ';
1.39 raeburn 4651: if (ref($settings) eq 'HASH') {
4652: if (ref($settings->{'fields'}) eq 'HASH') {
4653: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4654: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4655: $check = ' checked="checked" ';
4656: }
1.3 raeburn 4657: }
4658: }
4659: }
4660:
4661: if ($i == @{$fields}-1) {
4662: my $colsleft = $numinrow - $rem;
4663: if ($colsleft > 1) {
4664: $datatable .= '<td colspan="'.$colsleft.'">';
4665: } else {
4666: $datatable .= '<td>';
4667: }
4668: } else {
4669: $datatable .= '<td>';
4670: }
1.8 raeburn 4671: $datatable .= '<span class="LC_nobreak"><label>'.
4672: '<input type="checkbox" name="updateable_'.$type.
4673: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4674: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4675: }
4676: $datatable .= '</tr></table></td></tr>';
4677: }
4678: }
4679: return $datatable;
1.1 raeburn 4680: }
4681:
4682: sub modify_login {
1.9 raeburn 4683: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4684: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4685: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4686: %title = ( coursecatalog => 'Display course catalog',
4687: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 4688: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4689: newuser => 'Link for visitors to create a user account',
4690: loginheader => 'Log-in box header');
4691: @offon = ('off','on');
1.112 raeburn 4692: if (ref($domconfig{login}) eq 'HASH') {
4693: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4694: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4695: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4696: }
4697: }
4698: }
1.9 raeburn 4699: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4700: \%domconfig,\%loginhash);
1.160.6.14 raeburn 4701: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4702: foreach my $item (@toggles) {
4703: $loginhash{login}{$item} = $env{'form.'.$item};
4704: }
1.41 raeburn 4705: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4706: if (ref($colchanges{'login'}) eq 'HASH') {
4707: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4708: \%loginhash);
4709: }
1.110 raeburn 4710:
1.149 raeburn 4711: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4712: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4713: if (keys(%servers) > 1) {
4714: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4715: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4716: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4717: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4718: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4719: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4720: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4721: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4722: $changes{'loginvia'}{$lonhost} = 1;
4723: } else {
4724: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4725: $changes{'loginvia'}{$lonhost} = 1;
4726: }
4727: } else {
4728: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4729: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4730: $changes{'loginvia'}{$lonhost} = 1;
4731: }
4732: }
4733: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4734: foreach my $item (@loginvia_attribs) {
4735: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4736: }
4737: } else {
4738: foreach my $item (@loginvia_attribs) {
4739: my $new = $env{'form.'.$lonhost.'_'.$item};
4740: if (($item eq 'serverpath') && ($new eq 'custom')) {
4741: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4742: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4743: $new = '/';
4744: }
4745: }
4746: if (($item eq 'custompath') &&
4747: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4748: $new = '';
4749: }
4750: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4751: $changes{'loginvia'}{$lonhost} = 1;
4752: }
4753: if ($item eq 'exempt') {
4754: $new =~ s/^\s+//;
4755: $new =~ s/\s+$//;
4756: my @poss_ips = split(/\s*[,:]\s*/,$new);
4757: my @okips;
4758: foreach my $ip (@poss_ips) {
4759: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4760: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4761: push(@okips,$ip);
4762: }
4763: }
4764: }
4765: if (@okips > 0) {
4766: $new = join(',',@okips);
4767: } else {
4768: $new = '';
4769: }
4770: }
4771: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4772: }
4773: }
1.112 raeburn 4774: } else {
1.128 raeburn 4775: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4776: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4777: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4778: foreach my $item (@loginvia_attribs) {
4779: my $new = $env{'form.'.$lonhost.'_'.$item};
4780: if (($item eq 'serverpath') && ($new eq 'custom')) {
4781: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4782: $new = '/';
4783: }
4784: }
4785: if (($item eq 'custompath') &&
4786: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4787: $new = '';
4788: }
4789: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4790: }
1.110 raeburn 4791: }
4792: }
4793: }
4794: }
1.119 raeburn 4795:
1.160.6.5 raeburn 4796: my $servadm = $r->dir_config('lonAdmEMail');
4797: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4798: if (ref($domconfig{'login'}) eq 'HASH') {
4799: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4800: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4801: if ($lang eq 'nolang') {
4802: push(@currlangs,$lang);
4803: } elsif (defined($langchoices{$lang})) {
4804: push(@currlangs,$lang);
4805: } else {
4806: next;
4807: }
4808: }
4809: }
4810: }
4811: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4812: if (@currlangs > 0) {
4813: foreach my $lang (@currlangs) {
4814: if (grep(/^\Q$lang\E$/,@delurls)) {
4815: $changes{'helpurl'}{$lang} = 1;
4816: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4817: $changes{'helpurl'}{$lang} = 1;
4818: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4819: push(@newlangs,$lang);
4820: } else {
4821: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4822: }
4823: }
4824: }
4825: unless (grep(/^nolang$/,@currlangs)) {
4826: if ($env{'form.loginhelpurl_nolang.filename'}) {
4827: $changes{'helpurl'}{'nolang'} = 1;
4828: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4829: push(@newlangs,'nolang');
4830: }
4831: }
4832: if ($env{'form.loginhelpurl_add_lang'}) {
4833: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4834: ($env{'form.loginhelpurl_add_file.filename'})) {
4835: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4836: $addedfile = $env{'form.loginhelpurl_add_lang'};
4837: }
4838: }
4839: if ((@newlangs > 0) || ($addedfile)) {
4840: my $error;
4841: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4842: if ($configuserok eq 'ok') {
4843: if ($switchserver) {
4844: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4845: } elsif ($author_ok eq 'ok') {
4846: my @allnew = @newlangs;
4847: if ($addedfile ne '') {
4848: push(@allnew,$addedfile);
4849: }
4850: foreach my $lang (@allnew) {
4851: my $formelem = 'loginhelpurl_'.$lang;
4852: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4853: $formelem = 'loginhelpurl_add_file';
4854: }
4855: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4856: "help/$lang",'','',$newfile{$lang});
4857: if ($result eq 'ok') {
4858: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4859: $changes{'helpurl'}{$lang} = 1;
4860: } else {
4861: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4862: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4863: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4864: (!grep(/^\Q$lang\E$/,@delurls))) {
4865:
4866: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4867: }
4868: }
4869: }
4870: } else {
4871: $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);
4872: }
4873: } else {
4874: $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);
4875: }
4876: if ($error) {
4877: &Apache::lonnet::logthis($error);
4878: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4879: }
4880: }
4881: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4882:
4883: my $defaulthelpfile = '/adm/loginproblems.html';
4884: my $defaulttext = &mt('Default in use');
4885:
1.1 raeburn 4886: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4887: $dom);
4888: if ($putresult eq 'ok') {
1.160.6.14 raeburn 4889: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4890: my %defaultchecked = (
4891: 'coursecatalog' => 'on',
1.160.6.14 raeburn 4892: 'helpdesk' => 'on',
1.42 raeburn 4893: 'adminmail' => 'off',
1.43 raeburn 4894: 'newuser' => 'off',
1.42 raeburn 4895: );
1.55 raeburn 4896: if (ref($domconfig{'login'}) eq 'HASH') {
4897: foreach my $item (@toggles) {
4898: if ($defaultchecked{$item} eq 'on') {
4899: if (($domconfig{'login'}{$item} eq '0') &&
4900: ($env{'form.'.$item} eq '1')) {
4901: $changes{$item} = 1;
4902: } elsif (($domconfig{'login'}{$item} eq '' ||
4903: $domconfig{'login'}{$item} eq '1') &&
4904: ($env{'form.'.$item} eq '0')) {
4905: $changes{$item} = 1;
4906: }
4907: } elsif ($defaultchecked{$item} eq 'off') {
4908: if (($domconfig{'login'}{$item} eq '1') &&
4909: ($env{'form.'.$item} eq '0')) {
4910: $changes{$item} = 1;
4911: } elsif (($domconfig{'login'}{$item} eq '' ||
4912: $domconfig{'login'}{$item} eq '0') &&
4913: ($env{'form.'.$item} eq '1')) {
4914: $changes{$item} = 1;
4915: }
1.42 raeburn 4916: }
4917: }
1.41 raeburn 4918: }
1.6 raeburn 4919: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4920: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4921: $resulttext = &mt('Changes made:').'<ul>';
4922: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4923: if ($item eq 'loginvia') {
1.112 raeburn 4924: if (ref($changes{$item}) eq 'HASH') {
4925: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4926: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4927: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4928: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4929: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4930: $protocol = 'http' if ($protocol ne 'https');
4931: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4932:
4933: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4934: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4935: } else {
4936: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4937: }
4938: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4939: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4940: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4941: }
4942: $resulttext .= '</li>';
4943: } else {
4944: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4945: }
1.112 raeburn 4946: } else {
1.128 raeburn 4947: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4948: }
4949: }
1.128 raeburn 4950: $resulttext .= '</ul></li>';
1.112 raeburn 4951: }
1.160.6.5 raeburn 4952: } elsif ($item eq 'helpurl') {
4953: if (ref($changes{$item}) eq 'HASH') {
4954: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4955: if (grep(/^\Q$lang\E$/,@delurls)) {
4956: my ($chg,$link);
4957: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4958: if ($lang eq 'nolang') {
4959: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4960: } else {
4961: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4962: }
4963: $resulttext .= '<li>'.$chg.'</li>';
4964: } else {
4965: my $chg;
4966: if ($lang eq 'nolang') {
4967: $chg = &mt('custom log-in help file for no preferred language');
4968: } else {
4969: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4970: }
4971: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4972: $loginhash{'login'}{'helpurl'}{$lang}.
4973: '?inhibitmenu=yes',$chg,600,500).
4974: '</li>';
4975: }
4976: }
4977: }
4978: } elsif ($item eq 'captcha') {
4979: if (ref($loginhash{'login'}) eq 'HASH') {
4980: my $chgtxt;
4981: if ($loginhash{'login'}{$item} eq 'notused') {
4982: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4983: } else {
4984: my %captchas = &captcha_phrases();
4985: if ($captchas{$loginhash{'login'}{$item}}) {
4986: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4987: } else {
4988: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4989: }
4990: }
4991: $resulttext .= '<li>'.$chgtxt.'</li>';
4992: }
4993: } elsif ($item eq 'recaptchakeys') {
4994: if (ref($loginhash{'login'}) eq 'HASH') {
4995: my ($privkey,$pubkey);
4996: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4997: $pubkey = $loginhash{'login'}{$item}{'public'};
4998: $privkey = $loginhash{'login'}{$item}{'private'};
4999: }
5000: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5001: if (!$pubkey) {
5002: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5003: } else {
5004: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5005: }
5006: if (!$privkey) {
5007: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5008: } else {
5009: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5010: }
5011: $chgtxt .= '</ul>';
5012: $resulttext .= '<li>'.$chgtxt.'</li>';
5013: }
1.41 raeburn 5014: } else {
5015: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5016: }
1.1 raeburn 5017: }
1.6 raeburn 5018: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5019: } else {
5020: $resulttext = &mt('No changes made to log-in page settings');
5021: }
5022: } else {
1.11 albertel 5023: $resulttext = '<span class="LC_error">'.
5024: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5025: }
1.6 raeburn 5026: if ($errors) {
1.9 raeburn 5027: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5028: $errors.'</ul>';
5029: }
5030: return $resulttext;
5031: }
5032:
5033: sub color_font_choices {
5034: my %choices =
5035: &Apache::lonlocal::texthash (
5036: img => "Header",
5037: bgs => "Background colors",
5038: links => "Link colors",
1.55 raeburn 5039: images => "Images",
1.6 raeburn 5040: font => "Font color",
1.97 tempelho 5041: fontmenu => "Font Menu",
1.76 raeburn 5042: pgbg => "Page",
1.6 raeburn 5043: tabbg => "Header",
5044: sidebg => "Border",
5045: link => "Link",
5046: alink => "Active link",
5047: vlink => "Visited link",
5048: );
5049: return %choices;
5050: }
5051:
5052: sub modify_rolecolors {
1.9 raeburn 5053: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5054: my ($resulttext,%rolehash);
5055: $rolehash{'rolecolors'} = {};
1.55 raeburn 5056: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5057: if ($domconfig{'rolecolors'} eq '') {
5058: $domconfig{'rolecolors'} = {};
5059: }
5060: }
1.9 raeburn 5061: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5062: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5063: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5064: $dom);
5065: if ($putresult eq 'ok') {
5066: if (keys(%changes) > 0) {
1.41 raeburn 5067: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5068: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5069: $rolehash{'rolecolors'});
5070: } else {
5071: $resulttext = &mt('No changes made to default color schemes');
5072: }
5073: } else {
1.11 albertel 5074: $resulttext = '<span class="LC_error">'.
5075: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5076: }
5077: if ($errors) {
5078: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5079: $errors.'</ul>';
5080: }
5081: return $resulttext;
5082: }
5083:
5084: sub modify_colors {
1.9 raeburn 5085: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5086: my (%changes,%choices);
1.51 raeburn 5087: my @bgs;
1.6 raeburn 5088: my @links = ('link','alink','vlink');
1.41 raeburn 5089: my @logintext;
1.6 raeburn 5090: my @images;
5091: my $servadm = $r->dir_config('lonAdmEMail');
5092: my $errors;
5093: foreach my $role (@{$roles}) {
5094: if ($role eq 'login') {
1.12 raeburn 5095: %choices = &login_choices();
1.41 raeburn 5096: @logintext = ('textcol','bgcol');
1.12 raeburn 5097: } else {
5098: %choices = &color_font_choices();
1.107 raeburn 5099: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5100: }
5101: if ($role eq 'login') {
1.41 raeburn 5102: @images = ('img','logo','domlogo','login');
1.51 raeburn 5103: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5104: } else {
5105: @images = ('img');
1.51 raeburn 5106: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5107: }
5108: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5109: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5110: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5111: }
1.46 raeburn 5112: my ($configuserok,$author_ok,$switchserver) =
5113: &config_check($dom,$confname,$servadm);
1.9 raeburn 5114: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5115: if (ref($domconfig->{$role}) ne 'HASH') {
5116: $domconfig->{$role} = {};
5117: }
1.8 raeburn 5118: foreach my $img (@images) {
1.70 raeburn 5119: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5120: if (defined($env{'form.login_showlogo_'.$img})) {
5121: $confhash->{$role}{'showlogo'}{$img} = 1;
5122: } else {
5123: $confhash->{$role}{'showlogo'}{$img} = 0;
5124: }
5125: }
1.18 albertel 5126: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5127: && !defined($domconfig->{$role}{$img})
5128: && !$env{'form.'.$role.'_del_'.$img}
5129: && $env{'form.'.$role.'_import_'.$img}) {
5130: # import the old configured image from the .tab setting
5131: # if they haven't provided a new one
5132: $domconfig->{$role}{$img} =
5133: $env{'form.'.$role.'_import_'.$img};
5134: }
1.6 raeburn 5135: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5136: my $error;
1.6 raeburn 5137: if ($configuserok eq 'ok') {
1.9 raeburn 5138: if ($switchserver) {
1.12 raeburn 5139: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5140: } else {
5141: if ($author_ok eq 'ok') {
5142: my ($result,$logourl) =
5143: &publishlogo($r,'upload',$role.'_'.$img,
5144: $dom,$confname,$img,$width,$height);
5145: if ($result eq 'ok') {
5146: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5147: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5148: } else {
1.12 raeburn 5149: $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 5150: }
5151: } else {
1.46 raeburn 5152: $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 5153: }
5154: }
5155: } else {
1.46 raeburn 5156: $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 5157: }
5158: if ($error) {
1.8 raeburn 5159: &Apache::lonnet::logthis($error);
1.11 albertel 5160: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5161: }
5162: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5163: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5164: my $error;
5165: if ($configuserok eq 'ok') {
5166: # is confname an author?
5167: if ($switchserver eq '') {
5168: if ($author_ok eq 'ok') {
5169: my ($result,$logourl) =
5170: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5171: $dom,$confname,$img,$width,$height);
5172: if ($result eq 'ok') {
5173: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5174: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5175: }
5176: }
5177: }
5178: }
1.6 raeburn 5179: }
5180: }
5181: }
5182: if (ref($domconfig) eq 'HASH') {
5183: if (ref($domconfig->{$role}) eq 'HASH') {
5184: foreach my $img (@images) {
5185: if ($domconfig->{$role}{$img} ne '') {
5186: if ($env{'form.'.$role.'_del_'.$img}) {
5187: $confhash->{$role}{$img} = '';
1.12 raeburn 5188: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5189: } else {
1.9 raeburn 5190: if ($confhash->{$role}{$img} eq '') {
5191: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5192: }
1.6 raeburn 5193: }
5194: } else {
5195: if ($env{'form.'.$role.'_del_'.$img}) {
5196: $confhash->{$role}{$img} = '';
1.12 raeburn 5197: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5198: }
5199: }
1.70 raeburn 5200: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5201: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5202: if ($confhash->{$role}{'showlogo'}{$img} ne
5203: $domconfig->{$role}{'showlogo'}{$img}) {
5204: $changes{$role}{'showlogo'}{$img} = 1;
5205: }
5206: } else {
5207: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5208: $changes{$role}{'showlogo'}{$img} = 1;
5209: }
5210: }
5211: }
5212: }
1.6 raeburn 5213: if ($domconfig->{$role}{'font'} ne '') {
5214: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5215: $changes{$role}{'font'} = 1;
5216: }
5217: } else {
5218: if ($confhash->{$role}{'font'}) {
5219: $changes{$role}{'font'} = 1;
5220: }
5221: }
1.107 raeburn 5222: if ($role ne 'login') {
5223: if ($domconfig->{$role}{'fontmenu'} ne '') {
5224: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5225: $changes{$role}{'fontmenu'} = 1;
5226: }
5227: } else {
5228: if ($confhash->{$role}{'fontmenu'}) {
5229: $changes{$role}{'fontmenu'} = 1;
5230: }
1.97 tempelho 5231: }
5232: }
1.6 raeburn 5233: foreach my $item (@bgs) {
5234: if ($domconfig->{$role}{$item} ne '') {
5235: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5236: $changes{$role}{'bgs'}{$item} = 1;
5237: }
5238: } else {
5239: if ($confhash->{$role}{$item}) {
5240: $changes{$role}{'bgs'}{$item} = 1;
5241: }
5242: }
5243: }
5244: foreach my $item (@links) {
5245: if ($domconfig->{$role}{$item} ne '') {
5246: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5247: $changes{$role}{'links'}{$item} = 1;
5248: }
5249: } else {
5250: if ($confhash->{$role}{$item}) {
5251: $changes{$role}{'links'}{$item} = 1;
5252: }
5253: }
5254: }
1.41 raeburn 5255: foreach my $item (@logintext) {
5256: if ($domconfig->{$role}{$item} ne '') {
5257: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5258: $changes{$role}{'logintext'}{$item} = 1;
5259: }
5260: } else {
5261: if ($confhash->{$role}{$item}) {
5262: $changes{$role}{'logintext'}{$item} = 1;
5263: }
5264: }
5265: }
1.6 raeburn 5266: } else {
5267: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5268: \@logintext,$confhash,\%changes);
1.6 raeburn 5269: }
5270: } else {
5271: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5272: \@logintext,$confhash,\%changes);
1.6 raeburn 5273: }
5274: }
5275: return ($errors,%changes);
5276: }
5277:
1.46 raeburn 5278: sub config_check {
5279: my ($dom,$confname,$servadm) = @_;
5280: my ($configuserok,$author_ok,$switchserver,%currroles);
5281: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5282: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5283: $confname,$servadm);
5284: if ($configuserok eq 'ok') {
5285: $switchserver = &check_switchserver($dom,$confname);
5286: if ($switchserver eq '') {
5287: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5288: }
5289: }
5290: return ($configuserok,$author_ok,$switchserver);
5291: }
5292:
1.6 raeburn 5293: sub default_change_checker {
1.41 raeburn 5294: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5295: foreach my $item (@{$links}) {
5296: if ($confhash->{$role}{$item}) {
5297: $changes->{$role}{'links'}{$item} = 1;
5298: }
5299: }
5300: foreach my $item (@{$bgs}) {
5301: if ($confhash->{$role}{$item}) {
5302: $changes->{$role}{'bgs'}{$item} = 1;
5303: }
5304: }
1.41 raeburn 5305: foreach my $item (@{$logintext}) {
5306: if ($confhash->{$role}{$item}) {
5307: $changes->{$role}{'logintext'}{$item} = 1;
5308: }
5309: }
1.6 raeburn 5310: foreach my $img (@{$images}) {
5311: if ($env{'form.'.$role.'_del_'.$img}) {
5312: $confhash->{$role}{$img} = '';
1.12 raeburn 5313: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5314: }
1.70 raeburn 5315: if ($role eq 'login') {
5316: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5317: $changes->{$role}{'showlogo'}{$img} = 1;
5318: }
5319: }
1.6 raeburn 5320: }
5321: if ($confhash->{$role}{'font'}) {
5322: $changes->{$role}{'font'} = 1;
5323: }
1.48 raeburn 5324: }
1.6 raeburn 5325:
5326: sub display_colorchgs {
5327: my ($dom,$changes,$roles,$confhash) = @_;
5328: my (%choices,$resulttext);
5329: if (!grep(/^login$/,@{$roles})) {
5330: $resulttext = &mt('Changes made:').'<br />';
5331: }
5332: foreach my $role (@{$roles}) {
5333: if ($role eq 'login') {
5334: %choices = &login_choices();
5335: } else {
5336: %choices = &color_font_choices();
5337: }
5338: if (ref($changes->{$role}) eq 'HASH') {
5339: if ($role ne 'login') {
5340: $resulttext .= '<h4>'.&mt($role).'</h4>';
5341: }
5342: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5343: if ($role ne 'login') {
5344: $resulttext .= '<ul>';
5345: }
5346: if (ref($changes->{$role}{$key}) eq 'HASH') {
5347: if ($role ne 'login') {
5348: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5349: }
5350: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5351: if (($role eq 'login') && ($key eq 'showlogo')) {
5352: if ($confhash->{$role}{$key}{$item}) {
5353: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5354: } else {
5355: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5356: }
5357: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5358: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5359: } else {
1.12 raeburn 5360: my $newitem = $confhash->{$role}{$item};
5361: if ($key eq 'images') {
5362: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5363: }
5364: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5365: }
5366: }
5367: if ($role ne 'login') {
5368: $resulttext .= '</ul></li>';
5369: }
5370: } else {
5371: if ($confhash->{$role}{$key} eq '') {
5372: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5373: } else {
5374: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5375: }
5376: }
5377: if ($role ne 'login') {
5378: $resulttext .= '</ul>';
5379: }
5380: }
5381: }
5382: }
1.3 raeburn 5383: return $resulttext;
1.1 raeburn 5384: }
5385:
1.9 raeburn 5386: sub thumb_dimensions {
5387: return ('200','50');
5388: }
5389:
1.16 raeburn 5390: sub check_dimensions {
5391: my ($inputfile) = @_;
5392: my ($fullwidth,$fullheight);
5393: if ($inputfile =~ m|^[/\w.\-]+$|) {
5394: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5395: my $imageinfo = <PIPE>;
5396: if (!close(PIPE)) {
5397: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5398: }
5399: chomp($imageinfo);
5400: my ($fullsize) =
1.21 raeburn 5401: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5402: if ($fullsize) {
5403: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5404: }
5405: }
5406: }
5407: return ($fullwidth,$fullheight);
5408: }
5409:
1.9 raeburn 5410: sub check_configuser {
5411: my ($uhome,$dom,$confname,$servadm) = @_;
5412: my ($configuserok,%currroles);
5413: if ($uhome eq 'no_host') {
5414: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5415: my $configpass = &LONCAPA::Enrollment::create_password();
5416: $configuserok =
5417: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5418: $configpass,'','','','','',undef,$servadm);
5419: } else {
5420: $configuserok = 'ok';
5421: %currroles =
5422: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5423: }
5424: return ($configuserok,%currroles);
5425: }
5426:
5427: sub check_authorstatus {
5428: my ($dom,$confname,%currroles) = @_;
5429: my $author_ok;
1.40 raeburn 5430: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5431: my $start = time;
5432: my $end = 0;
5433: $author_ok =
5434: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5435: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5436: } else {
5437: $author_ok = 'ok';
5438: }
5439: return $author_ok;
5440: }
5441:
5442: sub publishlogo {
1.46 raeburn 5443: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5444: my ($output,$fname,$logourl);
5445: if ($action eq 'upload') {
5446: $fname=$env{'form.'.$formname.'.filename'};
5447: chop($env{'form.'.$formname});
5448: } else {
5449: ($fname) = ($formname =~ /([^\/]+)$/);
5450: }
1.46 raeburn 5451: if ($savefileas ne '') {
5452: $fname = $savefileas;
5453: }
1.9 raeburn 5454: $fname=&Apache::lonnet::clean_filename($fname);
5455: # See if there is anything left
5456: unless ($fname) { return ('error: no uploaded file'); }
5457: $fname="$subdir/$fname";
1.160.6.5 raeburn 5458: my $docroot=$r->dir_config('lonDocRoot');
5459: my $filepath="$docroot/priv";
5460: my $relpath = "$dom/$confname";
1.9 raeburn 5461: my ($fnamepath,$file,$fetchthumb);
5462: $file=$fname;
5463: if ($fname=~m|/|) {
5464: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5465: }
1.160.6.5 raeburn 5466: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5467: my $count;
1.160.6.5 raeburn 5468: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5469: $filepath.="/$parts[$count]";
5470: if ((-e $filepath)!=1) {
5471: mkdir($filepath,02770);
5472: }
5473: }
5474: # Check for bad extension and disallow upload
5475: if ($file=~/\.(\w+)$/ &&
5476: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5477: $output =
5478: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5479: } elsif ($file=~/\.(\w+)$/ &&
5480: !defined(&Apache::loncommon::fileembstyle($1))) {
5481: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5482: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 5483: $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 5484: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 5485: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5486: } else {
5487: my $source = $filepath.'/'.$file;
5488: my $logfile;
5489: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 5490: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5491: }
5492: print $logfile
5493: "\n================= Publish ".localtime()." ================\n".
5494: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5495: # Save the file
5496: if (!open(FH,'>'.$source)) {
5497: &Apache::lonnet::logthis('Failed to create '.$source);
5498: return (&mt('Failed to create file'));
5499: }
5500: if ($action eq 'upload') {
5501: if (!print FH ($env{'form.'.$formname})) {
5502: &Apache::lonnet::logthis('Failed to write to '.$source);
5503: return (&mt('Failed to write file'));
5504: }
5505: } else {
5506: my $original = &Apache::lonnet::filelocation('',$formname);
5507: if(!copy($original,$source)) {
5508: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5509: return (&mt('Failed to write file'));
5510: }
5511: }
5512: close(FH);
5513: chmod(0660, $source); # Permissions to rw-rw---.
5514:
5515: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5516: my $copyfile=$targetdir.'/'.$file;
5517:
5518: my @parts=split(/\//,$targetdir);
5519: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5520: for (my $count=5;$count<=$#parts;$count++) {
5521: $path.="/$parts[$count]";
5522: if (!-e $path) {
5523: print $logfile "\nCreating directory ".$path;
5524: mkdir($path,02770);
5525: }
5526: }
5527: my $versionresult;
5528: if (-e $copyfile) {
5529: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5530: } else {
5531: $versionresult = 'ok';
5532: }
5533: if ($versionresult eq 'ok') {
5534: if (copy($source,$copyfile)) {
5535: print $logfile "\nCopied original source to ".$copyfile."\n";
5536: $output = 'ok';
5537: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5538: push(@{$modified_urls},[$copyfile,$source]);
5539: my $metaoutput =
5540: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5541: unless ($registered_cleanup) {
5542: my $handlers = $r->get_handlers('PerlCleanupHandler');
5543: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5544: $registered_cleanup=1;
5545: }
1.9 raeburn 5546: } else {
5547: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5548: $output = &mt('Failed to copy file to RES space').", $!";
5549: }
5550: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5551: my $inputfile = $filepath.'/'.$file;
5552: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5553: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5554: if ($fullwidth ne '' && $fullheight ne '') {
5555: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5556: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5557: system("convert -sample $thumbsize $inputfile $outfile");
5558: chmod(0660, $filepath.'/tn-'.$file);
5559: if (-e $outfile) {
5560: my $copyfile=$targetdir.'/tn-'.$file;
5561: if (copy($outfile,$copyfile)) {
5562: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5563: my $thumb_metaoutput =
5564: &write_metadata($dom,$confname,$formname,
5565: $targetdir,'tn-'.$file,$logfile);
5566: push(@{$modified_urls},[$copyfile,$outfile]);
5567: unless ($registered_cleanup) {
5568: my $handlers = $r->get_handlers('PerlCleanupHandler');
5569: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5570: $registered_cleanup=1;
5571: }
1.16 raeburn 5572: } else {
5573: print $logfile "\nUnable to write ".$copyfile.
5574: ':'.$!."\n";
5575: }
5576: }
1.9 raeburn 5577: }
5578: }
5579: }
5580: } else {
5581: $output = $versionresult;
5582: }
5583: }
5584: return ($output,$logourl);
5585: }
5586:
5587: sub logo_versioning {
5588: my ($targetdir,$file,$logfile) = @_;
5589: my $target = $targetdir.'/'.$file;
5590: my ($maxversion,$fn,$extn,$output);
5591: $maxversion = 0;
5592: if ($file =~ /^(.+)\.(\w+)$/) {
5593: $fn=$1;
5594: $extn=$2;
5595: }
5596: opendir(DIR,$targetdir);
5597: while (my $filename=readdir(DIR)) {
5598: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5599: $maxversion=($1>$maxversion)?$1:$maxversion;
5600: }
5601: }
5602: $maxversion++;
5603: print $logfile "\nCreating old version ".$maxversion."\n";
5604: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5605: if (copy($target,$copyfile)) {
5606: print $logfile "Copied old target to ".$copyfile."\n";
5607: $copyfile=$copyfile.'.meta';
5608: if (copy($target.'.meta',$copyfile)) {
5609: print $logfile "Copied old target metadata to ".$copyfile."\n";
5610: $output = 'ok';
5611: } else {
5612: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5613: $output = &mt('Failed to copy old meta').", $!, ";
5614: }
5615: } else {
5616: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5617: $output = &mt('Failed to copy old target').", $!, ";
5618: }
5619: return $output;
5620: }
5621:
5622: sub write_metadata {
5623: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5624: my (%metadatafields,%metadatakeys,$output);
5625: $metadatafields{'title'}=$formname;
5626: $metadatafields{'creationdate'}=time;
5627: $metadatafields{'lastrevisiondate'}=time;
5628: $metadatafields{'copyright'}='public';
5629: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5630: $env{'user.domain'};
5631: $metadatafields{'authorspace'}=$confname.':'.$dom;
5632: $metadatafields{'domain'}=$dom;
5633: {
5634: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5635: my $mfh;
1.155 raeburn 5636: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5637: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5638: unless ($_=~/\./) {
5639: my $unikey=$_;
5640: $unikey=~/^([A-Za-z]+)/;
5641: my $tag=$1;
5642: $tag=~tr/A-Z/a-z/;
5643: print $mfh "\n\<$tag";
5644: foreach (split(/\,/,$metadatakeys{$unikey})) {
5645: my $value=$metadatafields{$unikey.'.'.$_};
5646: $value=~s/\"/\'\'/g;
5647: print $mfh ' '.$_.'="'.$value.'"';
5648: }
5649: print $mfh '>'.
5650: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5651: .'</'.$tag.'>';
5652: }
5653: }
5654: $output = 'ok';
5655: print $logfile "\nWrote metadata";
5656: close($mfh);
5657: } else {
5658: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5659: $output = &mt('Could not write metadata');
5660: }
5661: }
1.155 raeburn 5662: return $output;
5663: }
5664:
5665: sub notifysubscribed {
5666: foreach my $targetsource (@{$modified_urls}){
5667: next unless (ref($targetsource) eq 'ARRAY');
5668: my ($target,$source)=@{$targetsource};
5669: if ($source ne '') {
5670: if (open(my $logfh,'>>'.$source.'.log')) {
5671: print $logfh "\nCleanup phase: Notifications\n";
5672: my @subscribed=&subscribed_hosts($target);
5673: foreach my $subhost (@subscribed) {
5674: print $logfh "\nNotifying host ".$subhost.':';
5675: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5676: print $logfh $reply;
5677: }
5678: my @subscribedmeta=&subscribed_hosts("$target.meta");
5679: foreach my $subhost (@subscribedmeta) {
5680: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5681: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5682: $subhost);
5683: print $logfh $reply;
5684: }
5685: print $logfh "\n============ Done ============\n";
1.160 raeburn 5686: close($logfh);
1.155 raeburn 5687: }
5688: }
5689: }
5690: return OK;
5691: }
5692:
5693: sub subscribed_hosts {
5694: my ($target) = @_;
5695: my @subscribed;
5696: if (open(my $fh,"<$target.subscription")) {
5697: while (my $subline=<$fh>) {
5698: if ($subline =~ /^($match_lonid):/) {
5699: my $host = $1;
5700: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5701: unless (grep(/^\Q$host\E$/,@subscribed)) {
5702: push(@subscribed,$host);
5703: }
5704: }
5705: }
5706: }
5707: }
5708: return @subscribed;
1.9 raeburn 5709: }
5710:
5711: sub check_switchserver {
5712: my ($dom,$confname) = @_;
5713: my ($allowed,$switchserver);
5714: my $home = &Apache::lonnet::homeserver($confname,$dom);
5715: if ($home eq 'no_host') {
5716: $home = &Apache::lonnet::domain($dom,'primary');
5717: }
5718: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5719: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5720: if (!$allowed) {
1.160.6.11 raeburn 5721: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5722: }
5723: return $switchserver;
5724: }
5725:
1.1 raeburn 5726: sub modify_quotas {
1.86 raeburn 5727: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5728: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5729: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5730: if ($action eq 'quotas') {
5731: $context = 'tools';
5732: } else {
5733: $context = $action;
5734: }
5735: if ($context eq 'requestcourses') {
1.98 raeburn 5736: @usertools = ('official','unofficial','community');
1.106 raeburn 5737: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5738: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5739: %titles = &courserequest_titles();
5740: $toolregexp = join('|',@usertools);
5741: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5742: } elsif ($context eq 'requestauthor') {
5743: @usertools = ('author');
5744: %titles = &authorrequest_titles();
1.86 raeburn 5745: } else {
1.160.6.4 raeburn 5746: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5747: %titles = &tool_titles();
1.86 raeburn 5748: }
1.72 raeburn 5749: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5750: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5751: foreach my $key (keys(%env)) {
1.101 raeburn 5752: if ($context eq 'requestcourses') {
5753: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5754: my $item = $1;
5755: my $type = $2;
5756: if ($type =~ /^limit_(.+)/) {
5757: $limithash{$item}{$1} = $env{$key};
5758: } else {
5759: $confhash{$item}{$type} = $env{$key};
5760: }
5761: }
1.160.6.5 raeburn 5762: } elsif ($context eq 'requestauthor') {
5763: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5764: $confhash{$1} = $env{$key};
5765: }
1.101 raeburn 5766: } else {
1.86 raeburn 5767: if ($key =~ /^form\.quota_(.+)$/) {
5768: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 5769: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5770: $confhash{'authorquota'}{$1} = $env{$key};
5771: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5772: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5773: }
1.72 raeburn 5774: }
5775: }
1.160.6.5 raeburn 5776: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5777: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5778: @approvalnotify = sort(@approvalnotify);
5779: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5780: if (ref($domconfig{$action}) eq 'HASH') {
5781: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5782: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5783: $changes{'notify'}{'approval'} = 1;
5784: }
5785: } else {
1.144 raeburn 5786: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5787: $changes{'notify'}{'approval'} = 1;
5788: }
5789: }
5790: } else {
1.144 raeburn 5791: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5792: $changes{'notify'}{'approval'} = 1;
5793: }
5794: }
5795: } else {
1.86 raeburn 5796: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 5797: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5798: }
1.72 raeburn 5799: foreach my $item (@usertools) {
5800: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5801: my $unset;
1.101 raeburn 5802: if ($context eq 'requestcourses') {
1.104 raeburn 5803: $unset = '0';
5804: if ($type eq '_LC_adv') {
5805: $unset = '';
5806: }
1.101 raeburn 5807: if ($confhash{$item}{$type} eq 'autolimit') {
5808: $confhash{$item}{$type} .= '=';
5809: unless ($limithash{$item}{$type} =~ /\D/) {
5810: $confhash{$item}{$type} .= $limithash{$item}{$type};
5811: }
5812: }
1.160.6.5 raeburn 5813: } elsif ($context eq 'requestauthor') {
5814: $unset = '0';
5815: if ($type eq '_LC_adv') {
5816: $unset = '';
5817: }
1.72 raeburn 5818: } else {
1.101 raeburn 5819: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5820: $confhash{$item}{$type} = 1;
5821: } else {
5822: $confhash{$item}{$type} = 0;
5823: }
1.72 raeburn 5824: }
1.86 raeburn 5825: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5826: if ($action eq 'requestauthor') {
5827: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5828: $changes{$type} = 1;
5829: }
5830: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5831: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5832: $changes{$item}{$type} = 1;
5833: }
5834: } else {
5835: if ($context eq 'requestcourses') {
1.104 raeburn 5836: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5837: $changes{$item}{$type} = 1;
5838: }
5839: } else {
5840: if (!$confhash{$item}{$type}) {
5841: $changes{$item}{$type} = 1;
5842: }
5843: }
5844: }
5845: } else {
5846: if ($context eq 'requestcourses') {
1.104 raeburn 5847: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5848: $changes{$item}{$type} = 1;
5849: }
1.160.6.5 raeburn 5850: } elsif ($context eq 'requestauthor') {
5851: if ($confhash{$type} ne $unset) {
5852: $changes{$type} = 1;
5853: }
1.72 raeburn 5854: } else {
5855: if (!$confhash{$item}{$type}) {
5856: $changes{$item}{$type} = 1;
5857: }
5858: }
5859: }
1.1 raeburn 5860: }
5861: }
1.160.6.5 raeburn 5862: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5863: if (ref($domconfig{'quotas'}) eq 'HASH') {
5864: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5865: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5866: if (exists($confhash{'defaultquota'}{$key})) {
5867: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5868: $changes{'defaultquota'}{$key} = 1;
5869: }
5870: } else {
5871: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5872: }
5873: }
1.86 raeburn 5874: } else {
5875: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5876: if (exists($confhash{'defaultquota'}{$key})) {
5877: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5878: $changes{'defaultquota'}{$key} = 1;
5879: }
5880: } else {
5881: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5882: }
1.1 raeburn 5883: }
5884: }
1.160.6.20 raeburn 5885: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5886: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5887: if (exists($confhash{'authorquota'}{$key})) {
5888: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5889: $changes{'authorquota'}{$key} = 1;
5890: }
5891: } else {
5892: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5893: }
5894: }
5895: }
1.1 raeburn 5896: }
1.86 raeburn 5897: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5898: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5899: if (ref($domconfig{'quotas'}) eq 'HASH') {
5900: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5901: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5902: $changes{'defaultquota'}{$key} = 1;
5903: }
5904: } else {
5905: if (!exists($domconfig{'quotas'}{$key})) {
5906: $changes{'defaultquota'}{$key} = 1;
5907: }
1.72 raeburn 5908: }
5909: } else {
1.86 raeburn 5910: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5911: }
1.1 raeburn 5912: }
5913: }
1.160.6.20 raeburn 5914: if (ref($confhash{'authorquota'}) eq 'HASH') {
5915: foreach my $key (keys(%{$confhash{'authorquota'}})) {
5916: if (ref($domconfig{'quotas'}) eq 'HASH') {
5917: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5918: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
5919: $changes{'authorquota'}{$key} = 1;
5920: }
5921: } else {
5922: $changes{'authorquota'}{$key} = 1;
5923: }
5924: } else {
5925: $changes{'authorquota'}{$key} = 1;
5926: }
5927: }
5928: }
1.1 raeburn 5929: }
1.72 raeburn 5930:
1.160.6.5 raeburn 5931: if ($context eq 'requestauthor') {
5932: $domdefaults{'requestauthor'} = \%confhash;
5933: } else {
5934: foreach my $key (keys(%confhash)) {
5935: $domdefaults{$key} = $confhash{$key};
5936: }
1.72 raeburn 5937: }
1.160.6.5 raeburn 5938:
1.1 raeburn 5939: my %quotahash = (
1.86 raeburn 5940: $action => { %confhash }
1.1 raeburn 5941: );
5942: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5943: $dom);
5944: if ($putresult eq 'ok') {
5945: if (keys(%changes) > 0) {
1.72 raeburn 5946: my $cachetime = 24*60*60;
5947: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5948:
1.1 raeburn 5949: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 5950: unless (($context eq 'requestcourses') ||
5951: ($context eq 'requestauthor')) {
1.86 raeburn 5952: if (ref($changes{'defaultquota'}) eq 'HASH') {
5953: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5954: foreach my $type (@{$types},'default') {
5955: if (defined($changes{'defaultquota'}{$type})) {
5956: my $typetitle = $usertypes->{$type};
5957: if ($type eq 'default') {
5958: $typetitle = $othertitle;
5959: }
5960: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5961: }
5962: }
1.86 raeburn 5963: $resulttext .= '</ul></li>';
1.72 raeburn 5964: }
1.160.6.20 raeburn 5965: if (ref($changes{'authorquota'}) eq 'HASH') {
5966: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
5967: foreach my $type (@{$types},'default') {
5968: if (defined($changes{'authorquota'}{$type})) {
5969: my $typetitle = $usertypes->{$type};
5970: if ($type eq 'default') {
5971: $typetitle = $othertitle;
5972: }
5973: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
5974: }
5975: }
5976: $resulttext .= '</ul></li>';
5977: }
1.72 raeburn 5978: }
1.80 raeburn 5979: my %newenv;
1.72 raeburn 5980: foreach my $item (@usertools) {
1.160.6.5 raeburn 5981: my (%haschgs,%inconf);
5982: if ($context eq 'requestauthor') {
5983: %haschgs = %changes;
5984: %inconf = %confhash;
5985: } else {
5986: if (ref($changes{$item}) eq 'HASH') {
5987: %haschgs = %{$changes{$item}};
5988: }
5989: if (ref($confhash{$item}) eq 'HASH') {
5990: %inconf = %{$confhash{$item}};
5991: }
5992: }
5993: if (keys(%haschgs) > 0) {
1.80 raeburn 5994: my $newacc =
5995: &Apache::lonnet::usertools_access($env{'user.name'},
5996: $env{'user.domain'},
1.86 raeburn 5997: $item,'reload',$context);
1.160.6.5 raeburn 5998: if (($context eq 'requestcourses') ||
5999: ($context eq 'requestauthor')) {
1.108 raeburn 6000: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6001: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6002: }
6003: } else {
6004: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6005: $newenv{'environment.availabletools.'.$item} = $newacc;
6006: }
1.80 raeburn 6007: }
1.160.6.5 raeburn 6008: unless ($context eq 'requestauthor') {
6009: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6010: }
1.72 raeburn 6011: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 6012: if ($haschgs{$type}) {
1.72 raeburn 6013: my $typetitle = $usertypes->{$type};
6014: if ($type eq 'default') {
6015: $typetitle = $othertitle;
6016: } elsif ($type eq '_LC_adv') {
6017: $typetitle = 'LON-CAPA Advanced Users';
6018: }
1.160.6.5 raeburn 6019: if ($inconf{$type}) {
1.101 raeburn 6020: if ($context eq 'requestcourses') {
6021: my $cond;
1.160.6.5 raeburn 6022: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6023: if ($1 eq '') {
6024: $cond = &mt('(Automatic processing of any request).');
6025: } else {
6026: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6027: }
6028: } else {
1.160.6.5 raeburn 6029: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6030: }
6031: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 6032: } elsif ($context eq 'requestauthor') {
6033: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6034: $titles{$inconf{$type}},$typetitle);
6035:
1.101 raeburn 6036: } else {
6037: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6038: }
1.72 raeburn 6039: } else {
1.104 raeburn 6040: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 6041: if ($inconf{$type} eq '0') {
1.104 raeburn 6042: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6043: } else {
6044: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6045: }
6046: } else {
6047: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6048: }
1.72 raeburn 6049: }
6050: }
1.26 raeburn 6051: }
1.160.6.5 raeburn 6052: unless ($context eq 'requestauthor') {
6053: $resulttext .= '</ul></li>';
6054: }
1.26 raeburn 6055: }
1.1 raeburn 6056: }
1.160.6.5 raeburn 6057: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6058: if (ref($changes{'notify'}) eq 'HASH') {
6059: if ($changes{'notify'}{'approval'}) {
6060: if (ref($confhash{'notify'}) eq 'HASH') {
6061: if ($confhash{'notify'}{'approval'}) {
6062: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6063: } else {
1.160.6.5 raeburn 6064: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6065: }
6066: }
6067: }
6068: }
6069: }
1.1 raeburn 6070: $resulttext .= '</ul>';
1.80 raeburn 6071: if (keys(%newenv)) {
6072: &Apache::lonnet::appenv(\%newenv);
6073: }
1.1 raeburn 6074: } else {
1.86 raeburn 6075: if ($context eq 'requestcourses') {
6076: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 6077: } elsif ($context eq 'requestauthor') {
6078: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6079: } else {
1.90 weissno 6080: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6081: }
1.1 raeburn 6082: }
6083: } else {
1.11 albertel 6084: $resulttext = '<span class="LC_error">'.
6085: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6086: }
1.3 raeburn 6087: return $resulttext;
1.1 raeburn 6088: }
6089:
1.3 raeburn 6090: sub modify_autoenroll {
6091: my ($dom,%domconfig) = @_;
1.1 raeburn 6092: my ($resulttext,%changes);
6093: my %currautoenroll;
6094: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6095: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6096: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6097: }
6098: }
6099: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6100: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6101: sender => 'Sender for notification messages',
6102: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6103: my @offon = ('off','on');
1.17 raeburn 6104: my $sender_uname = $env{'form.sender_uname'};
6105: my $sender_domain = $env{'form.sender_domain'};
6106: if ($sender_domain eq '') {
6107: $sender_uname = '';
6108: } elsif ($sender_uname eq '') {
6109: $sender_domain = '';
6110: }
1.129 raeburn 6111: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6112: my %autoenrollhash = (
1.129 raeburn 6113: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6114: 'sender_uname' => $sender_uname,
6115: 'sender_domain' => $sender_domain,
6116: 'co-owners' => $coowners,
1.1 raeburn 6117: }
6118: );
1.4 raeburn 6119: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6120: $dom);
1.1 raeburn 6121: if ($putresult eq 'ok') {
6122: if (exists($currautoenroll{'run'})) {
6123: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6124: $changes{'run'} = 1;
6125: }
6126: } elsif ($autorun) {
6127: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6128: $changes{'run'} = 1;
1.1 raeburn 6129: }
6130: }
1.17 raeburn 6131: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6132: $changes{'sender'} = 1;
6133: }
1.17 raeburn 6134: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6135: $changes{'sender'} = 1;
6136: }
1.129 raeburn 6137: if ($currautoenroll{'co-owners'} ne '') {
6138: if ($currautoenroll{'co-owners'} ne $coowners) {
6139: $changes{'coowners'} = 1;
6140: }
6141: } elsif ($coowners) {
6142: $changes{'coowners'} = 1;
6143: }
1.1 raeburn 6144: if (keys(%changes) > 0) {
6145: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6146: if ($changes{'run'}) {
1.1 raeburn 6147: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6148: }
6149: if ($changes{'sender'}) {
1.17 raeburn 6150: if ($sender_uname eq '' || $sender_domain eq '') {
6151: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6152: } else {
6153: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6154: }
1.1 raeburn 6155: }
1.129 raeburn 6156: if ($changes{'coowners'}) {
6157: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6158: &Apache::loncommon::devalidate_domconfig_cache($dom);
6159: }
1.1 raeburn 6160: $resulttext .= '</ul>';
6161: } else {
6162: $resulttext = &mt('No changes made to auto-enrollment settings');
6163: }
6164: } else {
1.11 albertel 6165: $resulttext = '<span class="LC_error">'.
6166: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6167: }
1.3 raeburn 6168: return $resulttext;
1.1 raeburn 6169: }
6170:
6171: sub modify_autoupdate {
1.3 raeburn 6172: my ($dom,%domconfig) = @_;
1.1 raeburn 6173: my ($resulttext,%currautoupdate,%fields,%changes);
6174: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6175: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6176: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6177: }
6178: }
6179: my @offon = ('off','on');
6180: my %title = &Apache::lonlocal::texthash (
6181: run => 'Auto-update:',
6182: classlists => 'Updates to user information in classlists?'
6183: );
1.44 raeburn 6184: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6185: my %fieldtitles = &Apache::lonlocal::texthash (
6186: id => 'Student/Employee ID',
1.20 raeburn 6187: permanentemail => 'E-mail address',
1.1 raeburn 6188: lastname => 'Last Name',
6189: firstname => 'First Name',
6190: middlename => 'Middle Name',
1.132 raeburn 6191: generation => 'Generation',
1.1 raeburn 6192: );
1.142 raeburn 6193: $othertitle = &mt('All users');
1.1 raeburn 6194: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6195: $othertitle = &mt('Other users');
1.1 raeburn 6196: }
6197: foreach my $key (keys(%env)) {
6198: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6199: my ($usertype,$item) = ($1,$2);
6200: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6201: if ($usertype eq 'default') {
6202: push(@{$fields{$1}},$2);
6203: } elsif (ref($types) eq 'ARRAY') {
6204: if (grep(/^\Q$usertype\E$/,@{$types})) {
6205: push(@{$fields{$1}},$2);
6206: }
6207: }
6208: }
1.1 raeburn 6209: }
6210: }
1.131 raeburn 6211: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6212: @lockablenames = sort(@lockablenames);
6213: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6214: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6215: if (@changed) {
6216: $changes{'lockablenames'} = 1;
6217: }
6218: } else {
6219: if (@lockablenames) {
6220: $changes{'lockablenames'} = 1;
6221: }
6222: }
1.1 raeburn 6223: my %updatehash = (
6224: autoupdate => { run => $env{'form.autoupdate_run'},
6225: classlists => $env{'form.classlists'},
6226: fields => {%fields},
1.131 raeburn 6227: lockablenames => \@lockablenames,
1.1 raeburn 6228: }
6229: );
6230: foreach my $key (keys(%currautoupdate)) {
6231: if (($key eq 'run') || ($key eq 'classlists')) {
6232: if (exists($updatehash{autoupdate}{$key})) {
6233: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6234: $changes{$key} = 1;
6235: }
6236: }
6237: } elsif ($key eq 'fields') {
6238: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6239: foreach my $item (@{$types},'default') {
1.1 raeburn 6240: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6241: my $change = 0;
6242: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6243: if (!exists($fields{$item})) {
6244: $change = 1;
1.132 raeburn 6245: last;
1.1 raeburn 6246: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6247: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6248: $change = 1;
1.132 raeburn 6249: last;
1.1 raeburn 6250: }
6251: }
6252: }
6253: if ($change) {
6254: push(@{$changes{$key}},$item);
6255: }
1.26 raeburn 6256: }
1.1 raeburn 6257: }
6258: }
1.131 raeburn 6259: } elsif ($key eq 'lockablenames') {
6260: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6261: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6262: if (@changed) {
6263: $changes{'lockablenames'} = 1;
6264: }
6265: } else {
6266: if (@lockablenames) {
6267: $changes{'lockablenames'} = 1;
6268: }
6269: }
6270: }
6271: }
6272: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6273: if (@lockablenames) {
6274: $changes{'lockablenames'} = 1;
1.1 raeburn 6275: }
6276: }
1.26 raeburn 6277: foreach my $item (@{$types},'default') {
6278: if (defined($fields{$item})) {
6279: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6280: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6281: my $change = 0;
6282: if (ref($fields{$item}) eq 'ARRAY') {
6283: foreach my $type (@{$fields{$item}}) {
6284: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6285: $change = 1;
6286: last;
6287: }
6288: }
6289: }
6290: if ($change) {
6291: push(@{$changes{'fields'}},$item);
6292: }
6293: } else {
1.26 raeburn 6294: push(@{$changes{'fields'}},$item);
6295: }
6296: } else {
6297: push(@{$changes{'fields'}},$item);
1.1 raeburn 6298: }
6299: }
6300: }
6301: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6302: $dom);
6303: if ($putresult eq 'ok') {
6304: if (keys(%changes) > 0) {
6305: $resulttext = &mt('Changes made:').'<ul>';
6306: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6307: if ($key eq 'lockablenames') {
6308: $resulttext .= '<li>';
6309: if (@lockablenames) {
6310: $usertypes->{'default'} = $othertitle;
6311: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6312: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6313: } else {
6314: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6315: }
6316: $resulttext .= '</li>';
6317: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6318: foreach my $item (@{$changes{$key}}) {
6319: my @newvalues;
6320: foreach my $type (@{$fields{$item}}) {
6321: push(@newvalues,$fieldtitles{$type});
6322: }
1.3 raeburn 6323: my $newvaluestr;
6324: if (@newvalues > 0) {
6325: $newvaluestr = join(', ',@newvalues);
6326: } else {
6327: $newvaluestr = &mt('none');
1.6 raeburn 6328: }
1.1 raeburn 6329: if ($item eq 'default') {
1.26 raeburn 6330: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6331: } else {
1.26 raeburn 6332: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6333: }
6334: }
6335: } else {
6336: my $newvalue;
6337: if ($key eq 'run') {
6338: $newvalue = $offon[$env{'form.autoupdate_run'}];
6339: } else {
6340: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6341: }
1.1 raeburn 6342: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6343: }
6344: }
6345: $resulttext .= '</ul>';
6346: } else {
1.3 raeburn 6347: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6348: }
6349: } else {
1.11 albertel 6350: $resulttext = '<span class="LC_error">'.
6351: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6352: }
1.3 raeburn 6353: return $resulttext;
1.1 raeburn 6354: }
6355:
1.125 raeburn 6356: sub modify_autocreate {
6357: my ($dom,%domconfig) = @_;
6358: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6359: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6360: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6361: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6362: }
6363: }
6364: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6365: req => 'Auto-creation of validated requests for official courses',
6366: xmldc => 'Identity of course creator of courses from XML files',
6367: );
6368: my @types = ('xml','req');
6369: foreach my $item (@types) {
6370: $newvals{$item} = $env{'form.autocreate_'.$item};
6371: $newvals{$item} =~ s/\D//g;
6372: $newvals{$item} = 0 if ($newvals{$item} eq '');
6373: }
6374: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6375: my %domcoords = &get_active_dcs($dom);
6376: unless (exists($domcoords{$newvals{'xmldc'}})) {
6377: $newvals{'xmldc'} = '';
6378: }
6379: %autocreatehash = (
6380: autocreate => { xml => $newvals{'xml'},
6381: req => $newvals{'req'},
6382: }
6383: );
6384: if ($newvals{'xmldc'} ne '') {
6385: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6386: }
6387: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6388: $dom);
6389: if ($putresult eq 'ok') {
6390: my @items = @types;
6391: if ($newvals{'xml'}) {
6392: push(@items,'xmldc');
6393: }
6394: foreach my $item (@items) {
6395: if (exists($currautocreate{$item})) {
6396: if ($currautocreate{$item} ne $newvals{$item}) {
6397: $changes{$item} = 1;
6398: }
6399: } elsif ($newvals{$item}) {
6400: $changes{$item} = 1;
6401: }
6402: }
6403: if (keys(%changes) > 0) {
6404: my @offon = ('off','on');
6405: $resulttext = &mt('Changes made:').'<ul>';
6406: foreach my $item (@types) {
6407: if ($changes{$item}) {
6408: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6409: $resulttext .= '<li>'.
6410: &mt("$title{$item} set to [_1]$newtxt [_2]",
6411: '<b>','</b>').
6412: '</li>';
1.125 raeburn 6413: }
6414: }
6415: if ($changes{'xmldc'}) {
6416: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6417: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6418: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6419: }
6420: $resulttext .= '</ul>';
6421: } else {
6422: $resulttext = &mt('No changes made to auto-creation settings');
6423: }
6424: } else {
6425: $resulttext = '<span class="LC_error">'.
6426: &mt('An error occurred: [_1]',$putresult).'</span>';
6427: }
6428: return $resulttext;
6429: }
6430:
1.23 raeburn 6431: sub modify_directorysrch {
6432: my ($dom,%domconfig) = @_;
6433: my ($resulttext,%changes);
6434: my %currdirsrch;
6435: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6436: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6437: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6438: }
6439: }
6440: my %title = ( available => 'Directory search available',
1.24 raeburn 6441: localonly => 'Other domains can search',
1.23 raeburn 6442: searchby => 'Search types',
6443: searchtypes => 'Search latitude');
6444: my @offon = ('off','on');
1.24 raeburn 6445: my @otherdoms = ('Yes','No');
1.23 raeburn 6446:
1.25 raeburn 6447: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6448: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6449: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6450:
1.44 raeburn 6451: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6452: if (keys(%{$usertypes}) == 0) {
6453: @cansearch = ('default');
6454: } else {
6455: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6456: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6457: if (!grep(/^\Q$type\E$/,@cansearch)) {
6458: push(@{$changes{'cansearch'}},$type);
6459: }
1.23 raeburn 6460: }
1.26 raeburn 6461: foreach my $type (@cansearch) {
6462: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6463: push(@{$changes{'cansearch'}},$type);
6464: }
1.23 raeburn 6465: }
1.26 raeburn 6466: } else {
6467: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6468: }
6469: }
6470:
6471: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6472: foreach my $by (@{$currdirsrch{'searchby'}}) {
6473: if (!grep(/^\Q$by\E$/,@searchby)) {
6474: push(@{$changes{'searchby'}},$by);
6475: }
6476: }
6477: foreach my $by (@searchby) {
6478: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6479: push(@{$changes{'searchby'}},$by);
6480: }
6481: }
6482: } else {
6483: push(@{$changes{'searchby'}},@searchby);
6484: }
1.25 raeburn 6485:
6486: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6487: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6488: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6489: push(@{$changes{'searchtypes'}},$type);
6490: }
6491: }
6492: foreach my $type (@searchtypes) {
6493: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6494: push(@{$changes{'searchtypes'}},$type);
6495: }
6496: }
6497: } else {
6498: if (exists($currdirsrch{'searchtypes'})) {
6499: foreach my $type (@searchtypes) {
6500: if ($type ne $currdirsrch{'searchtypes'}) {
6501: push(@{$changes{'searchtypes'}},$type);
6502: }
6503: }
6504: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6505: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6506: }
6507: } else {
6508: push(@{$changes{'searchtypes'}},@searchtypes);
6509: }
6510: }
6511:
1.23 raeburn 6512: my %dirsrch_hash = (
6513: directorysrch => { available => $env{'form.dirsrch_available'},
6514: cansearch => \@cansearch,
1.24 raeburn 6515: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6516: searchby => \@searchby,
1.25 raeburn 6517: searchtypes => \@searchtypes,
1.23 raeburn 6518: }
6519: );
6520: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6521: $dom);
6522: if ($putresult eq 'ok') {
6523: if (exists($currdirsrch{'available'})) {
6524: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6525: $changes{'available'} = 1;
6526: }
6527: } else {
6528: if ($env{'form.dirsrch_available'} eq '1') {
6529: $changes{'available'} = 1;
6530: }
6531: }
1.24 raeburn 6532: if (exists($currdirsrch{'localonly'})) {
6533: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6534: $changes{'localonly'} = 1;
6535: }
6536: } else {
6537: if ($env{'form.dirsrch_localonly'} eq '1') {
6538: $changes{'localonly'} = 1;
6539: }
6540: }
1.23 raeburn 6541: if (keys(%changes) > 0) {
6542: $resulttext = &mt('Changes made:').'<ul>';
6543: if ($changes{'available'}) {
6544: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6545: }
1.24 raeburn 6546: if ($changes{'localonly'}) {
6547: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6548: }
6549:
1.23 raeburn 6550: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6551: my $chgtext;
1.26 raeburn 6552: if (ref($usertypes) eq 'HASH') {
6553: if (keys(%{$usertypes}) > 0) {
6554: foreach my $type (@{$types}) {
6555: if (grep(/^\Q$type\E$/,@cansearch)) {
6556: $chgtext .= $usertypes->{$type}.'; ';
6557: }
6558: }
6559: if (grep(/^default$/,@cansearch)) {
6560: $chgtext .= $othertitle;
6561: } else {
6562: $chgtext =~ s/\; $//;
6563: }
1.160.6.13 raeburn 6564: $resulttext .=
6565: '<li>'.
6566: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6567: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6568: '</li>';
1.23 raeburn 6569: }
6570: }
6571: }
6572: if (ref($changes{'searchby'}) eq 'ARRAY') {
6573: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6574: my $chgtext;
6575: foreach my $type (@{$titleorder}) {
6576: if (grep(/^\Q$type\E$/,@searchby)) {
6577: if (defined($searchtitles->{$type})) {
6578: $chgtext .= $searchtitles->{$type}.'; ';
6579: }
6580: }
6581: }
6582: $chgtext =~ s/\; $//;
6583: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6584: }
1.25 raeburn 6585: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6586: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6587: my $chgtext;
6588: foreach my $type (@{$srchtypeorder}) {
6589: if (grep(/^\Q$type\E$/,@searchtypes)) {
6590: if (defined($srchtypes_desc->{$type})) {
6591: $chgtext .= $srchtypes_desc->{$type}.'; ';
6592: }
6593: }
6594: }
6595: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 6596: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6597: }
6598: $resulttext .= '</ul>';
6599: } else {
6600: $resulttext = &mt('No changes made to institution directory search settings');
6601: }
6602: } else {
6603: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6604: &mt('An error occurred: [_1]',$putresult).'</span>';
6605: }
6606: return $resulttext;
6607: }
6608:
1.28 raeburn 6609: sub modify_contacts {
6610: my ($dom,%domconfig) = @_;
6611: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6612: if (ref($domconfig{'contacts'}) eq 'HASH') {
6613: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6614: $currsetting{$key} = $domconfig{'contacts'}{$key};
6615: }
6616: }
1.134 raeburn 6617: my (%others,%to,%bcc);
1.28 raeburn 6618: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6619: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.15 raeburn 6620: 'requestsmail','updatesmail');
1.28 raeburn 6621: foreach my $type (@mailings) {
6622: @{$newsetting{$type}} =
6623: &Apache::loncommon::get_env_multiple('form.'.$type);
6624: foreach my $item (@contacts) {
6625: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6626: $contacts_hash{contacts}{$type}{$item} = 1;
6627: } else {
6628: $contacts_hash{contacts}{$type}{$item} = 0;
6629: }
6630: }
6631: $others{$type} = $env{'form.'.$type.'_others'};
6632: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6633: if ($type eq 'helpdeskmail') {
6634: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6635: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6636: }
1.28 raeburn 6637: }
6638: foreach my $item (@contacts) {
6639: $to{$item} = $env{'form.'.$item};
6640: $contacts_hash{'contacts'}{$item} = $to{$item};
6641: }
6642: if (keys(%currsetting) > 0) {
6643: foreach my $item (@contacts) {
6644: if ($to{$item} ne $currsetting{$item}) {
6645: $changes{$item} = 1;
6646: }
6647: }
6648: foreach my $type (@mailings) {
6649: foreach my $item (@contacts) {
6650: if (ref($currsetting{$type}) eq 'HASH') {
6651: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6652: push(@{$changes{$type}},$item);
6653: }
6654: } else {
6655: push(@{$changes{$type}},@{$newsetting{$type}});
6656: }
6657: }
6658: if ($others{$type} ne $currsetting{$type}{'others'}) {
6659: push(@{$changes{$type}},'others');
6660: }
1.134 raeburn 6661: if ($type eq 'helpdeskmail') {
6662: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6663: push(@{$changes{$type}},'bcc');
6664: }
6665: }
1.28 raeburn 6666: }
6667: } else {
6668: my %default;
6669: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6670: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6671: $default{'errormail'} = 'adminemail';
6672: $default{'packagesmail'} = 'adminemail';
6673: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6674: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6675: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 6676: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6677: foreach my $item (@contacts) {
6678: if ($to{$item} ne $default{$item}) {
6679: $changes{$item} = 1;
6680: }
6681: }
6682: foreach my $type (@mailings) {
6683: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6684:
6685: push(@{$changes{$type}},@{$newsetting{$type}});
6686: }
6687: if ($others{$type} ne '') {
6688: push(@{$changes{$type}},'others');
1.134 raeburn 6689: }
6690: if ($type eq 'helpdeskmail') {
6691: if ($bcc{$type} ne '') {
6692: push(@{$changes{$type}},'bcc');
6693: }
6694: }
1.28 raeburn 6695: }
6696: }
6697: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6698: $dom);
6699: if ($putresult eq 'ok') {
6700: if (keys(%changes) > 0) {
6701: my ($titles,$short_titles) = &contact_titles();
6702: $resulttext = &mt('Changes made:').'<ul>';
6703: foreach my $item (@contacts) {
6704: if ($changes{$item}) {
6705: $resulttext .= '<li>'.$titles->{$item}.
6706: &mt(' set to: ').
6707: '<span class="LC_cusr_emph">'.
6708: $to{$item}.'</span></li>';
6709: }
6710: }
6711: foreach my $type (@mailings) {
6712: if (ref($changes{$type}) eq 'ARRAY') {
6713: $resulttext .= '<li>'.$titles->{$type}.': ';
6714: my @text;
6715: foreach my $item (@{$newsetting{$type}}) {
6716: push(@text,$short_titles->{$item});
6717: }
6718: if ($others{$type} ne '') {
6719: push(@text,$others{$type});
6720: }
6721: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6722: join(', ',@text).'</span>';
6723: if ($type eq 'helpdeskmail') {
6724: if ($bcc{$type} ne '') {
6725: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6726: }
6727: }
6728: $resulttext .= '</li>';
1.28 raeburn 6729: }
6730: }
6731: $resulttext .= '</ul>';
6732: } else {
1.34 raeburn 6733: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6734: }
6735: } else {
6736: $resulttext = '<span class="LC_error">'.
6737: &mt('An error occurred: [_1].',$putresult).'</span>';
6738: }
6739: return $resulttext;
6740: }
6741:
6742: sub modify_usercreation {
1.27 raeburn 6743: my ($dom,%domconfig) = @_;
1.34 raeburn 6744: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6745: my $warningmsg;
1.27 raeburn 6746: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6747: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6748: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6749: }
6750: }
6751: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6752: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6753: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6754: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6755: foreach my $item(@contexts) {
1.45 raeburn 6756: if ($item eq 'selfcreate') {
1.50 raeburn 6757: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6758: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6759: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6760: if (ref($cancreate{$item}) eq 'ARRAY') {
6761: if (grep(/^login$/,@{$cancreate{$item}})) {
6762: $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.');
6763: }
1.43 raeburn 6764: }
6765: }
1.50 raeburn 6766: } else {
6767: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6768: }
1.34 raeburn 6769: }
1.93 raeburn 6770: my ($othertitle,$usertypes,$types) =
6771: &Apache::loncommon::sorted_inst_types($dom);
6772: if (ref($types) eq 'ARRAY') {
6773: if (@{$types} > 0) {
6774: @{$cancreate{'statustocreate'}} =
6775: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6776: } else {
6777: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6778: }
6779: push(@contexts,'statustocreate');
6780: }
1.160.6.5 raeburn 6781: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6782: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6783: foreach my $item (@contexts) {
1.93 raeburn 6784: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6785: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6786: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6787: if (ref($cancreate{$item}) eq 'ARRAY') {
6788: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6789: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6790: push(@{$changes{'cancreate'}},$item);
6791: }
1.50 raeburn 6792: }
6793: }
6794: }
6795: } else {
6796: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6797: if (@{$cancreate{$item}} > 0) {
6798: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6799: push(@{$changes{'cancreate'}},$item);
6800: }
6801: }
6802: } else {
6803: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6804: if (@{$cancreate{$item}} < 3) {
6805: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6806: push(@{$changes{'cancreate'}},$item);
6807: }
6808: }
6809: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6810: if (@{$cancreate{$item}} > 0) {
6811: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6812: push(@{$changes{'cancreate'}},$item);
6813: }
6814: }
6815: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6816: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6817: push(@{$changes{'cancreate'}},$item);
6818: }
6819: }
6820: }
6821: }
6822: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6823: foreach my $type (@{$cancreate{$item}}) {
6824: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6825: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6826: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6827: push(@{$changes{'cancreate'}},$item);
6828: }
6829: }
6830: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6831: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6832: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6833: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6834: push(@{$changes{'cancreate'}},$item);
6835: }
6836: }
6837: }
6838: }
6839: }
6840: } else {
6841: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6842: push(@{$changes{'cancreate'}},$item);
6843: }
6844: }
1.27 raeburn 6845: }
1.34 raeburn 6846: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6847: foreach my $item (@contexts) {
1.43 raeburn 6848: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6849: if ($cancreate{$item} ne 'any') {
6850: push(@{$changes{'cancreate'}},$item);
6851: }
6852: } else {
6853: if ($cancreate{$item} ne 'none') {
6854: push(@{$changes{'cancreate'}},$item);
6855: }
1.27 raeburn 6856: }
6857: }
6858: } else {
1.43 raeburn 6859: foreach my $item (@contexts) {
1.34 raeburn 6860: push(@{$changes{'cancreate'}},$item);
6861: }
1.27 raeburn 6862: }
1.34 raeburn 6863:
1.27 raeburn 6864: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6865: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6866: if (!grep(/^\Q$type\E$/,@username_rule)) {
6867: push(@{$changes{'username_rule'}},$type);
6868: }
6869: }
6870: foreach my $type (@username_rule) {
6871: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6872: push(@{$changes{'username_rule'}},$type);
6873: }
6874: }
6875: } else {
6876: push(@{$changes{'username_rule'}},@username_rule);
6877: }
6878:
1.32 raeburn 6879: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6880: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6881: if (!grep(/^\Q$type\E$/,@id_rule)) {
6882: push(@{$changes{'id_rule'}},$type);
6883: }
6884: }
6885: foreach my $type (@id_rule) {
6886: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6887: push(@{$changes{'id_rule'}},$type);
6888: }
6889: }
6890: } else {
6891: push(@{$changes{'id_rule'}},@id_rule);
6892: }
6893:
1.43 raeburn 6894: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6895: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6896: if (!grep(/^\Q$type\E$/,@email_rule)) {
6897: push(@{$changes{'email_rule'}},$type);
6898: }
6899: }
6900: foreach my $type (@email_rule) {
6901: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6902: push(@{$changes{'email_rule'}},$type);
6903: }
6904: }
6905: } else {
6906: push(@{$changes{'email_rule'}},@email_rule);
6907: }
6908:
6909: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6910: my @authtypes = ('int','krb4','krb5','loc');
6911: my %authhash;
1.43 raeburn 6912: foreach my $item (@authen_contexts) {
1.28 raeburn 6913: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6914: foreach my $auth (@authtypes) {
6915: if (grep(/^\Q$auth\E$/,@authallowed)) {
6916: $authhash{$item}{$auth} = 1;
6917: } else {
6918: $authhash{$item}{$auth} = 0;
6919: }
6920: }
6921: }
6922: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6923: foreach my $item (@authen_contexts) {
1.28 raeburn 6924: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6925: foreach my $auth (@authtypes) {
6926: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6927: push(@{$changes{'authtypes'}},$item);
6928: last;
6929: }
6930: }
6931: }
6932: }
6933: } else {
1.43 raeburn 6934: foreach my $item (@authen_contexts) {
1.28 raeburn 6935: push(@{$changes{'authtypes'}},$item);
6936: }
6937: }
6938:
1.27 raeburn 6939: my %usercreation_hash = (
1.28 raeburn 6940: usercreation => {
1.34 raeburn 6941: cancreate => \%cancreate,
1.27 raeburn 6942: username_rule => \@username_rule,
1.32 raeburn 6943: id_rule => \@id_rule,
1.43 raeburn 6944: email_rule => \@email_rule,
1.32 raeburn 6945: authtypes => \%authhash,
1.27 raeburn 6946: }
6947: );
6948:
6949: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6950: $dom);
1.50 raeburn 6951:
6952: my %selfcreatetypes = (
6953: sso => 'users authenticated by institutional single sign on',
6954: login => 'users authenticated by institutional log-in',
6955: email => 'users who provide a valid e-mail address for use as the username',
6956: );
1.27 raeburn 6957: if ($putresult eq 'ok') {
6958: if (keys(%changes) > 0) {
6959: $resulttext = &mt('Changes made:').'<ul>';
6960: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6961: my %lt = &usercreation_types();
6962: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6963: my $chgtext;
1.160.6.5 raeburn 6964: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6965: $chgtext = $lt{$type}.', ';
6966: }
1.45 raeburn 6967: if ($type eq 'selfcreate') {
1.50 raeburn 6968: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6969: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6970: } else {
1.100 raeburn 6971: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6972: foreach my $case (@{$cancreate{$type}}) {
6973: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6974: }
6975: $chgtext .= '</ul>';
1.100 raeburn 6976: if (ref($cancreate{$type}) eq 'ARRAY') {
6977: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6978: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6979: if (@{$cancreate{'statustocreate'}} == 0) {
6980: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6981: }
6982: }
6983: }
6984: }
1.43 raeburn 6985: }
1.93 raeburn 6986: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6987: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6988: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6989: if (@{$cancreate{'selfcreate'}} > 0) {
6990: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6991:
6992: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6993: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6994: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6995: }
1.96 raeburn 6996: } elsif (ref($usertypes) eq 'HASH') {
6997: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6998: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6999: } else {
7000: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7001: }
7002: $chgtext .= '<ul>';
7003: foreach my $case (@{$cancreate{$type}}) {
7004: if ($case eq 'default') {
7005: $chgtext .= '<li>'.$othertitle.'</li>';
7006: } else {
7007: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7008: }
7009: }
1.100 raeburn 7010: $chgtext .= '</ul>';
7011: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7012: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7013: }
7014: }
7015: } else {
7016: if (@{$cancreate{$type}} == 0) {
7017: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7018: } else {
7019: $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 7020: }
7021: }
7022: }
1.160.6.5 raeburn 7023: } elsif ($type eq 'captcha') {
7024: if ($cancreate{$type} eq 'notused') {
7025: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7026: } else {
7027: my %captchas = &captcha_phrases();
7028: if ($captchas{$cancreate{$type}}) {
7029: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7030: } else {
7031: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7032: }
7033: }
7034: } elsif ($type eq 'recaptchakeys') {
7035: my ($privkey,$pubkey);
7036: if (ref($cancreate{$type}) eq 'HASH') {
7037: $pubkey = $cancreate{$type}{'public'};
7038: $privkey = $cancreate{$type}{'private'};
7039: }
7040: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7041: if (!$pubkey) {
7042: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7043: } else {
7044: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7045: }
7046: if (!$privkey) {
7047: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7048: } else {
7049: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7050: }
7051: $chgtext .= '</ul>';
1.43 raeburn 7052: } else {
7053: if ($cancreate{$type} eq 'none') {
7054: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7055: } elsif ($cancreate{$type} eq 'any') {
7056: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7057: } elsif ($cancreate{$type} eq 'official') {
7058: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7059: } elsif ($cancreate{$type} eq 'unofficial') {
7060: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7061: }
1.34 raeburn 7062: }
7063: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7064: }
7065: }
7066: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7067: my ($rules,$ruleorder) =
7068: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7069: my $chgtext = '<ul>';
7070: foreach my $type (@username_rule) {
7071: if (ref($rules->{$type}) eq 'HASH') {
7072: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7073: }
7074: }
7075: $chgtext .= '</ul>';
7076: if (@username_rule > 0) {
7077: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7078: } else {
1.28 raeburn 7079: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7080: }
7081: }
1.32 raeburn 7082: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7083: my ($idrules,$idruleorder) =
7084: &Apache::lonnet::inst_userrules($dom,'id');
7085: my $chgtext = '<ul>';
7086: foreach my $type (@id_rule) {
7087: if (ref($idrules->{$type}) eq 'HASH') {
7088: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7089: }
7090: }
7091: $chgtext .= '</ul>';
7092: if (@id_rule > 0) {
7093: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7094: } else {
7095: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7096: }
7097: }
1.43 raeburn 7098: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7099: my ($emailrules,$emailruleorder) =
7100: &Apache::lonnet::inst_userrules($dom,'email');
7101: my $chgtext = '<ul>';
7102: foreach my $type (@email_rule) {
7103: if (ref($emailrules->{$type}) eq 'HASH') {
7104: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7105: }
7106: }
7107: $chgtext .= '</ul>';
7108: if (@email_rule > 0) {
7109: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7110: } else {
7111: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7112: }
7113: }
7114:
1.28 raeburn 7115: my %authname = &authtype_names();
7116: my %context_title = &context_names();
7117: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7118: my $chgtext = '<ul>';
7119: foreach my $type (@{$changes{'authtypes'}}) {
7120: my @allowed;
7121: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7122: foreach my $auth (@authtypes) {
7123: if ($authhash{$type}{$auth}) {
7124: push(@allowed,$authname{$auth});
7125: }
7126: }
1.43 raeburn 7127: if (@allowed > 0) {
7128: $chgtext .= join(', ',@allowed).'</li>';
7129: } else {
7130: $chgtext .= &mt('none').'</li>';
7131: }
1.28 raeburn 7132: }
7133: $chgtext .= '</ul>';
7134: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7135: $resulttext .= '</li>';
7136: }
1.27 raeburn 7137: $resulttext .= '</ul>';
7138: } else {
1.28 raeburn 7139: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7140: }
7141: } else {
7142: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7143: &mt('An error occurred: [_1]',$putresult).'</span>';
7144: }
1.43 raeburn 7145: if ($warningmsg ne '') {
7146: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7147: }
1.23 raeburn 7148: return $resulttext;
7149: }
7150:
1.160.6.5 raeburn 7151: sub process_captcha {
7152: my ($container,$changes,$newsettings,$current) = @_;
7153: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7154: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7155: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7156: $newsettings->{'captcha'} = 'original';
7157: }
7158: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7159: if ($container eq 'cancreate') {
7160: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7161: push(@{$changes->{'cancreate'}},'captcha');
7162: } elsif (!defined($changes->{'cancreate'})) {
7163: $changes->{'cancreate'} = ['captcha'];
7164: }
7165: } else {
7166: $changes->{'captcha'} = 1;
7167: }
7168: }
7169: my ($newpub,$newpriv,$currpub,$currpriv);
7170: if ($newsettings->{'captcha'} eq 'recaptcha') {
7171: $newpub = $env{'form.'.$container.'_recaptchapub'};
7172: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7173: $newpub =~ s/\W//g;
7174: $newpriv =~ s/\W//g;
7175: $newsettings->{'recaptchakeys'} = {
7176: public => $newpub,
7177: private => $newpriv,
7178: };
7179: }
7180: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7181: $currpub = $current->{'recaptchakeys'}{'public'};
7182: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7183: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7184: $newsettings->{'recaptchakeys'} = {
7185: public => '',
7186: private => '',
7187: }
7188: }
1.160.6.5 raeburn 7189: }
7190: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7191: if ($container eq 'cancreate') {
7192: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7193: push(@{$changes->{'cancreate'}},'recaptchakeys');
7194: } elsif (!defined($changes->{'cancreate'})) {
7195: $changes->{'cancreate'} = ['recaptchakeys'];
7196: }
7197: } else {
7198: $changes->{'recaptchakeys'} = 1;
7199: }
7200: }
7201: return;
7202: }
7203:
1.33 raeburn 7204: sub modify_usermodification {
7205: my ($dom,%domconfig) = @_;
7206: my ($resulttext,%curr_usermodification,%changes);
7207: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7208: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7209: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7210: }
7211: }
1.63 raeburn 7212: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7213: my %context_title = (
7214: author => 'In author context',
7215: course => 'In course context',
1.63 raeburn 7216: selfcreate => 'When self creating account',
1.33 raeburn 7217: );
7218: my @fields = ('lastname','firstname','middlename','generation',
7219: 'permanentemail','id');
7220: my %roles = (
7221: author => ['ca','aa'],
7222: course => ['st','ep','ta','in','cr'],
7223: );
1.63 raeburn 7224: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7225: if (ref($types) eq 'ARRAY') {
7226: push(@{$types},'default');
7227: $usertypes->{'default'} = $othertitle;
7228: }
7229: $roles{'selfcreate'} = $types;
1.33 raeburn 7230: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7231: my %modifyhash;
7232: foreach my $context (@contexts) {
7233: foreach my $role (@{$roles{$context}}) {
7234: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7235: foreach my $item (@fields) {
7236: if (grep(/^\Q$item\E$/,@modifiable)) {
7237: $modifyhash{$context}{$role}{$item} = 1;
7238: } else {
7239: $modifyhash{$context}{$role}{$item} = 0;
7240: }
7241: }
7242: }
7243: if (ref($curr_usermodification{$context}) eq 'HASH') {
7244: foreach my $role (@{$roles{$context}}) {
7245: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7246: foreach my $field (@fields) {
7247: if ($modifyhash{$context}{$role}{$field} ne
7248: $curr_usermodification{$context}{$role}{$field}) {
7249: push(@{$changes{$context}},$role);
7250: last;
7251: }
7252: }
7253: }
7254: }
7255: } else {
7256: foreach my $context (@contexts) {
7257: foreach my $role (@{$roles{$context}}) {
7258: push(@{$changes{$context}},$role);
7259: }
7260: }
7261: }
7262: }
7263: my %usermodification_hash = (
7264: usermodification => \%modifyhash,
7265: );
7266: my $putresult = &Apache::lonnet::put_dom('configuration',
7267: \%usermodification_hash,$dom);
7268: if ($putresult eq 'ok') {
7269: if (keys(%changes) > 0) {
7270: $resulttext = &mt('Changes made: ').'<ul>';
7271: foreach my $context (@contexts) {
7272: if (ref($changes{$context}) eq 'ARRAY') {
7273: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7274: if (ref($changes{$context}) eq 'ARRAY') {
7275: foreach my $role (@{$changes{$context}}) {
7276: my $rolename;
1.63 raeburn 7277: if ($context eq 'selfcreate') {
7278: $rolename = $role;
7279: if (ref($usertypes) eq 'HASH') {
7280: if ($usertypes->{$role} ne '') {
7281: $rolename = $usertypes->{$role};
7282: }
7283: }
1.33 raeburn 7284: } else {
1.63 raeburn 7285: if ($role eq 'cr') {
7286: $rolename = &mt('Custom');
7287: } else {
7288: $rolename = &Apache::lonnet::plaintext($role);
7289: }
1.33 raeburn 7290: }
7291: my @modifiable;
1.63 raeburn 7292: if ($context eq 'selfcreate') {
1.126 bisitz 7293: $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 7294: } else {
7295: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7296: }
1.33 raeburn 7297: foreach my $field (@fields) {
7298: if ($modifyhash{$context}{$role}{$field}) {
7299: push(@modifiable,$fieldtitles{$field});
7300: }
7301: }
7302: if (@modifiable > 0) {
7303: $resulttext .= join(', ',@modifiable);
7304: } else {
7305: $resulttext .= &mt('none');
7306: }
7307: $resulttext .= '</li>';
7308: }
7309: $resulttext .= '</ul></li>';
7310: }
7311: }
7312: }
7313: $resulttext .= '</ul>';
7314: } else {
7315: $resulttext = &mt('No changes made to user modification settings');
7316: }
7317: } else {
7318: $resulttext = '<span class="LC_error">'.
7319: &mt('An error occurred: [_1]',$putresult).'</span>';
7320: }
7321: return $resulttext;
7322: }
7323:
1.43 raeburn 7324: sub modify_defaults {
7325: my ($dom,$r) = @_;
7326: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7327: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7328: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7329: my @authtypes = ('internal','krb4','krb5','localauth');
7330: foreach my $item (@items) {
7331: $newvalues{$item} = $env{'form.'.$item};
7332: if ($item eq 'auth_def') {
7333: if ($newvalues{$item} ne '') {
7334: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7335: push(@errors,$item);
7336: }
7337: }
7338: } elsif ($item eq 'lang_def') {
7339: if ($newvalues{$item} ne '') {
7340: if ($newvalues{$item} =~ /^(\w+)/) {
7341: my $langcode = $1;
1.103 raeburn 7342: if ($langcode ne 'x_chef') {
7343: if (code2language($langcode) eq '') {
7344: push(@errors,$item);
7345: }
1.43 raeburn 7346: }
7347: } else {
7348: push(@errors,$item);
7349: }
7350: }
1.54 raeburn 7351: } elsif ($item eq 'timezone_def') {
7352: if ($newvalues{$item} ne '') {
1.62 raeburn 7353: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7354: push(@errors,$item);
7355: }
7356: }
1.68 raeburn 7357: } elsif ($item eq 'datelocale_def') {
7358: if ($newvalues{$item} ne '') {
7359: my @datelocale_ids = DateTime::Locale->ids();
7360: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7361: push(@errors,$item);
7362: }
7363: }
1.141 raeburn 7364: } elsif ($item eq 'portal_def') {
7365: if ($newvalues{$item} ne '') {
7366: 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])\/?$/) {
7367: push(@errors,$item);
7368: }
7369: }
1.43 raeburn 7370: }
7371: if (grep(/^\Q$item\E$/,@errors)) {
7372: $newvalues{$item} = $domdefaults{$item};
7373: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7374: $changes{$item} = 1;
7375: }
1.72 raeburn 7376: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7377: }
7378: my %defaults_hash = (
1.72 raeburn 7379: defaults => \%newvalues,
7380: );
1.43 raeburn 7381: my $title = &defaults_titles();
7382: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7383: $dom);
7384: if ($putresult eq 'ok') {
7385: if (keys(%changes) > 0) {
7386: $resulttext = &mt('Changes made:').'<ul>';
7387: my $version = $r->dir_config('lonVersion');
7388: 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";
7389: foreach my $item (sort(keys(%changes))) {
7390: my $value = $env{'form.'.$item};
7391: if ($value eq '') {
7392: $value = &mt('none');
7393: } elsif ($item eq 'auth_def') {
7394: my %authnames = &authtype_names();
7395: my %shortauth = (
7396: internal => 'int',
7397: krb4 => 'krb4',
7398: krb5 => 'krb5',
7399: localauth => 'loc',
7400: );
7401: $value = $authnames{$shortauth{$value}};
7402: }
7403: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7404: $mailmsgtext .= "$title->{$item} set to $value\n";
7405: }
7406: $resulttext .= '</ul>';
7407: $mailmsgtext .= "\n";
7408: my $cachetime = 24*60*60;
1.72 raeburn 7409: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7410: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7411: my $sysmail = $r->dir_config('lonSysEMail');
7412: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7413: }
1.43 raeburn 7414: } else {
1.54 raeburn 7415: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7416: }
7417: } else {
7418: $resulttext = '<span class="LC_error">'.
7419: &mt('An error occurred: [_1]',$putresult).'</span>';
7420: }
7421: if (@errors > 0) {
7422: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7423: foreach my $item (@errors) {
7424: $resulttext .= ' "'.$title->{$item}.'",';
7425: }
7426: $resulttext =~ s/,$//;
7427: }
7428: return $resulttext;
7429: }
7430:
1.46 raeburn 7431: sub modify_scantron {
1.48 raeburn 7432: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7433: my ($resulttext,%confhash,%changes,$errors);
7434: my $custom = 'custom.tab';
7435: my $default = 'default.tab';
7436: my $servadm = $r->dir_config('lonAdmEMail');
7437: my ($configuserok,$author_ok,$switchserver) =
7438: &config_check($dom,$confname,$servadm);
7439: if ($env{'form.scantronformat.filename'} ne '') {
7440: my $error;
7441: if ($configuserok eq 'ok') {
7442: if ($switchserver) {
1.130 raeburn 7443: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7444: } else {
7445: if ($author_ok eq 'ok') {
7446: my ($result,$scantronurl) =
7447: &publishlogo($r,'upload','scantronformat',$dom,
7448: $confname,'scantron','','',$custom);
7449: if ($result eq 'ok') {
7450: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7451: $changes{'scantronformat'} = 1;
1.46 raeburn 7452: } else {
7453: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7454: }
7455: } else {
7456: $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);
7457: }
7458: }
7459: } else {
7460: $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);
7461: }
7462: if ($error) {
7463: &Apache::lonnet::logthis($error);
7464: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7465: }
7466: }
1.48 raeburn 7467: if (ref($domconfig{'scantron'}) eq 'HASH') {
7468: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7469: if ($env{'form.scantronformat_del'}) {
7470: $confhash{'scantron'}{'scantronformat'} = '';
7471: $changes{'scantronformat'} = 1;
1.46 raeburn 7472: }
7473: }
7474: }
7475: if (keys(%confhash) > 0) {
7476: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7477: $dom);
7478: if ($putresult eq 'ok') {
7479: if (keys(%changes) > 0) {
1.48 raeburn 7480: if (ref($confhash{'scantron'}) eq 'HASH') {
7481: $resulttext = &mt('Changes made:').'<ul>';
7482: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7483: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7484: } else {
1.130 raeburn 7485: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7486: }
1.48 raeburn 7487: $resulttext .= '</ul>';
7488: } else {
1.130 raeburn 7489: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7490: }
7491: $resulttext .= '</ul>';
7492: &Apache::loncommon::devalidate_domconfig_cache($dom);
7493: } else {
1.130 raeburn 7494: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7495: }
7496: } else {
7497: $resulttext = '<span class="LC_error">'.
7498: &mt('An error occurred: [_1]',$putresult).'</span>';
7499: }
7500: } else {
1.130 raeburn 7501: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7502: }
7503: if ($errors) {
7504: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7505: $errors.'</ul>';
7506: }
7507: return $resulttext;
7508: }
7509:
1.48 raeburn 7510: sub modify_coursecategories {
7511: my ($dom,%domconfig) = @_;
1.57 raeburn 7512: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7513: $cathash);
1.48 raeburn 7514: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7515: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7516: $cathash = $domconfig{'coursecategories'}{'cats'};
7517: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7518: $changes{'togglecats'} = 1;
7519: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7520: }
7521: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7522: $changes{'categorize'} = 1;
7523: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7524: }
1.120 raeburn 7525: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7526: $changes{'togglecatscomm'} = 1;
7527: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7528: }
7529: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7530: $changes{'categorizecomm'} = 1;
7531: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7532: }
1.57 raeburn 7533: } else {
7534: $changes{'togglecats'} = 1;
7535: $changes{'categorize'} = 1;
1.124 raeburn 7536: $changes{'togglecatscomm'} = 1;
7537: $changes{'categorizecomm'} = 1;
1.87 raeburn 7538: $domconfig{'coursecategories'} = {
7539: togglecats => $env{'form.togglecats'},
7540: categorize => $env{'form.categorize'},
1.124 raeburn 7541: togglecatscomm => $env{'form.togglecatscomm'},
7542: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7543: };
1.57 raeburn 7544: }
7545: if (ref($cathash) eq 'HASH') {
7546: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7547: push (@deletecategory,'instcode::0');
7548: }
1.120 raeburn 7549: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7550: push(@deletecategory,'communities::0');
7551: }
1.48 raeburn 7552: }
1.57 raeburn 7553: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7554: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7555: if (@deletecategory > 0) {
7556: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7557: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7558: foreach my $item (@deletecategory) {
1.57 raeburn 7559: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7560: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7561: $deletions{$item} = 1;
1.57 raeburn 7562: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7563: }
7564: }
7565: }
1.57 raeburn 7566: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7567: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7568: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7569: $reorderings{$item} = 1;
1.57 raeburn 7570: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7571: }
7572: if ($env{'form.addcategory_name_'.$item} ne '') {
7573: my $newcat = $env{'form.addcategory_name_'.$item};
7574: my $newdepth = $depth+1;
7575: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7576: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7577: $adds{$newitem} = 1;
7578: }
7579: if ($env{'form.subcat_'.$item} ne '') {
7580: my $newcat = $env{'form.subcat_'.$item};
7581: my $newdepth = $depth+1;
7582: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7583: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7584: $adds{$newitem} = 1;
7585: }
7586: }
7587: }
7588: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7589: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7590: my $newitem = 'instcode::0';
1.57 raeburn 7591: if ($cathash->{$newitem} eq '') {
7592: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7593: $adds{$newitem} = 1;
7594: }
7595: } else {
7596: my $newitem = 'instcode::0';
1.57 raeburn 7597: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7598: $adds{$newitem} = 1;
7599: }
7600: }
1.120 raeburn 7601: if ($env{'form.communities'} eq '1') {
7602: if (ref($cathash) eq 'HASH') {
7603: my $newitem = 'communities::0';
7604: if ($cathash->{$newitem} eq '') {
7605: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7606: $adds{$newitem} = 1;
7607: }
7608: } else {
7609: my $newitem = 'communities::0';
7610: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7611: $adds{$newitem} = 1;
7612: }
7613: }
1.48 raeburn 7614: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7615: if (($env{'form.addcategory_name'} ne 'instcode') &&
7616: ($env{'form.addcategory_name'} ne 'communities')) {
7617: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7618: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7619: $adds{$newitem} = 1;
7620: }
1.48 raeburn 7621: }
1.57 raeburn 7622: my $putresult;
1.48 raeburn 7623: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7624: if (keys(%deletions) > 0) {
7625: foreach my $key (keys(%deletions)) {
7626: if ($predelallitems{$key} ne '') {
7627: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7628: }
7629: }
7630: }
7631: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7632: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7633: if (ref($chkcats[0]) eq 'ARRAY') {
7634: my $depth = 0;
7635: my $chg = 0;
7636: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7637: my $name = $chkcats[0][$i];
7638: my $item;
7639: if ($name eq '') {
7640: $chg ++;
7641: } else {
7642: $item = &escape($name).'::0';
7643: if ($chg) {
1.57 raeburn 7644: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7645: }
7646: $depth ++;
1.57 raeburn 7647: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7648: $depth --;
7649: }
7650: }
7651: }
1.57 raeburn 7652: }
7653: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7654: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7655: if ($putresult eq 'ok') {
1.57 raeburn 7656: my %title = (
1.120 raeburn 7657: togglecats => 'Show/Hide a course in catalog',
7658: categorize => 'Assign a category to a course',
7659: togglecatscomm => 'Show/Hide a community in catalog',
7660: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7661: );
7662: my %level = (
1.120 raeburn 7663: dom => 'set in Domain ("Modify Course/Community")',
7664: crs => 'set in Course ("Course Configuration")',
7665: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7666: );
1.48 raeburn 7667: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7668: if ($changes{'togglecats'}) {
7669: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7670: }
7671: if ($changes{'categorize'}) {
7672: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7673: }
1.120 raeburn 7674: if ($changes{'togglecatscomm'}) {
7675: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7676: }
7677: if ($changes{'categorizecomm'}) {
7678: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7679: }
1.57 raeburn 7680: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7681: my $cathash;
7682: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7683: $cathash = $domconfig{'coursecategories'}{'cats'};
7684: } else {
7685: $cathash = {};
7686: }
7687: my (@cats,@trails,%allitems);
7688: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7689: if (keys(%deletions) > 0) {
7690: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7691: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7692: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7693: }
7694: $resulttext .= '</ul></li>';
7695: }
7696: if (keys(%reorderings) > 0) {
7697: my %sort_by_trail;
7698: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7699: foreach my $key (keys(%reorderings)) {
7700: if ($allitems{$key} ne '') {
7701: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7702: }
1.48 raeburn 7703: }
1.57 raeburn 7704: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7705: $resulttext .= '<li>'.$trails[$trail].'</li>';
7706: }
7707: $resulttext .= '</ul></li>';
1.48 raeburn 7708: }
1.57 raeburn 7709: if (keys(%adds) > 0) {
7710: my %sort_by_trail;
7711: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7712: foreach my $key (keys(%adds)) {
7713: if ($allitems{$key} ne '') {
7714: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7715: }
7716: }
7717: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7718: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7719: }
1.57 raeburn 7720: $resulttext .= '</ul></li>';
1.48 raeburn 7721: }
7722: }
7723: $resulttext .= '</ul>';
7724: } else {
7725: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7726: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7727: }
7728: } else {
1.120 raeburn 7729: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7730: }
7731: return $resulttext;
7732: }
7733:
1.69 raeburn 7734: sub modify_serverstatuses {
7735: my ($dom,%domconfig) = @_;
7736: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7737: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7738: %currserverstatus = %{$domconfig{'serverstatuses'}};
7739: }
7740: my @pages = &serverstatus_pages();
7741: foreach my $type (@pages) {
7742: $newserverstatus{$type}{'namedusers'} = '';
7743: $newserverstatus{$type}{'machines'} = '';
7744: if (defined($env{'form.'.$type.'_namedusers'})) {
7745: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7746: my @okusers;
7747: foreach my $user (@users) {
7748: my ($uname,$udom) = split(/:/,$user);
7749: if (($udom =~ /^$match_domain$/) &&
7750: (&Apache::lonnet::domain($udom)) &&
7751: ($uname =~ /^$match_username$/)) {
7752: if (!grep(/^\Q$user\E/,@okusers)) {
7753: push(@okusers,$user);
7754: }
7755: }
7756: }
7757: if (@okusers > 0) {
7758: @okusers = sort(@okusers);
7759: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7760: }
7761: }
7762: if (defined($env{'form.'.$type.'_machines'})) {
7763: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7764: my @okmachines;
7765: foreach my $ip (@machines) {
7766: my @parts = split(/\./,$ip);
7767: next if (@parts < 4);
7768: my $badip = 0;
7769: for (my $i=0; $i<4; $i++) {
7770: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7771: $badip = 1;
7772: last;
7773: }
7774: }
7775: if (!$badip) {
7776: push(@okmachines,$ip);
7777: }
7778: }
7779: @okmachines = sort(@okmachines);
7780: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7781: }
7782: }
7783: my %serverstatushash = (
7784: serverstatuses => \%newserverstatus,
7785: );
7786: foreach my $type (@pages) {
1.83 raeburn 7787: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7788: my (@current,@new);
1.83 raeburn 7789: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7790: if ($currserverstatus{$type}{$setting} ne '') {
7791: @current = split(/,/,$currserverstatus{$type}{$setting});
7792: }
7793: }
7794: if ($newserverstatus{$type}{$setting} ne '') {
7795: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7796: }
7797: if (@current > 0) {
7798: if (@new > 0) {
7799: foreach my $item (@current) {
7800: if (!grep(/^\Q$item\E$/,@new)) {
7801: $changes{$type}{$setting} = 1;
1.82 raeburn 7802: last;
7803: }
7804: }
1.84 raeburn 7805: foreach my $item (@new) {
7806: if (!grep(/^\Q$item\E$/,@current)) {
7807: $changes{$type}{$setting} = 1;
7808: last;
1.82 raeburn 7809: }
7810: }
7811: } else {
1.83 raeburn 7812: $changes{$type}{$setting} = 1;
1.69 raeburn 7813: }
1.83 raeburn 7814: } elsif (@new > 0) {
7815: $changes{$type}{$setting} = 1;
1.69 raeburn 7816: }
7817: }
7818: }
7819: if (keys(%changes) > 0) {
1.81 raeburn 7820: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7821: my $putresult = &Apache::lonnet::put_dom('configuration',
7822: \%serverstatushash,$dom);
7823: if ($putresult eq 'ok') {
7824: $resulttext .= &mt('Changes made:').'<ul>';
7825: foreach my $type (@pages) {
1.84 raeburn 7826: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7827: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7828: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7829: if ($newserverstatus{$type}{'namedusers'} eq '') {
7830: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7831: } else {
7832: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7833: }
1.84 raeburn 7834: }
7835: if ($changes{$type}{'machines'}) {
1.69 raeburn 7836: if ($newserverstatus{$type}{'machines'} eq '') {
7837: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7838: } else {
7839: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7840: }
7841:
7842: }
7843: $resulttext .= '</ul></li>';
7844: }
7845: }
7846: $resulttext .= '</ul>';
7847: } else {
7848: $resulttext = '<span class="LC_error">'.
7849: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7850:
7851: }
7852: } else {
7853: $resulttext = &mt('No changes made to access to server status pages');
7854: }
7855: return $resulttext;
7856: }
7857:
1.118 jms 7858: sub modify_helpsettings {
1.122 jms 7859: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7860: my ($resulttext,$errors,%changes,%helphash);
7861: my %defaultchecked = ('submitbugs' => 'on');
7862: my @offon = ('off','on');
1.118 jms 7863: my @toggles = ('submitbugs');
7864: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7865: foreach my $item (@toggles) {
1.160.6.5 raeburn 7866: if ($defaultchecked{$item} eq 'on') {
7867: if ($domconfig{'helpsettings'}{$item} eq '') {
7868: if ($env{'form.'.$item} eq '0') {
7869: $changes{$item} = 1;
7870: }
7871: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7872: $changes{$item} = 1;
7873: }
7874: } elsif ($defaultchecked{$item} eq 'off') {
7875: if ($domconfig{'helpsettings'}{$item} eq '') {
7876: if ($env{'form.'.$item} eq '1') {
7877: $changes{$item} = 1;
7878: }
7879: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7880: $changes{$item} = 1;
7881: }
7882: }
7883: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7884: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7885: }
7886: }
1.118 jms 7887: }
1.123 jms 7888: my $putresult;
7889: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7890: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7891: if ($putresult eq 'ok') {
7892: $resulttext = &mt('Changes made:').'<ul>';
7893: foreach my $item (sort(keys(%changes))) {
7894: if ($item eq 'submitbugs') {
7895: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7896: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7897: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7898: }
7899: }
7900: $resulttext .= '</ul>';
7901: } else {
7902: $resulttext = &mt('No changes made to help settings');
7903: $errors .= '<li><span class="LC_error">'.
7904: &mt('An error occurred storing the settings: [_1]',
7905: $putresult).'</span></li>';
7906: }
1.118 jms 7907: }
7908: if ($errors) {
1.160.6.5 raeburn 7909: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7910: $errors.'</ul>';
7911: }
7912: return $resulttext;
7913: }
7914:
1.121 raeburn 7915: sub modify_coursedefaults {
7916: my ($dom,%domconfig) = @_;
7917: my ($resulttext,$errors,%changes,%defaultshash);
7918: my %defaultchecked = ('canuse_pdfforms' => 'off');
7919: my @toggles = ('canuse_pdfforms');
1.160.6.21! raeburn 7920: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
! 7921: 'uploadquota_community');
! 7922: my @types = ('official','unofficial','community');
! 7923: my %staticdefaults = (
! 7924: anonsurvey_threshold => 10,
! 7925: uploadquota => 500,
! 7926: );
1.121 raeburn 7927:
7928: $defaultshash{'coursedefaults'} = {};
7929:
7930: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7931: if ($domconfig{'coursedefaults'} eq '') {
7932: $domconfig{'coursedefaults'} = {};
7933: }
7934: }
7935:
7936: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7937: foreach my $item (@toggles) {
7938: if ($defaultchecked{$item} eq 'on') {
7939: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7940: ($env{'form.'.$item} eq '0')) {
7941: $changes{$item} = 1;
1.160.6.16 raeburn 7942: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 7943: $changes{$item} = 1;
7944: }
7945: } elsif ($defaultchecked{$item} eq 'off') {
7946: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7947: ($env{'form.'.$item} eq '1')) {
7948: $changes{$item} = 1;
7949: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7950: $changes{$item} = 1;
7951: }
7952: }
7953: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7954: }
1.160.6.21! raeburn 7955: foreach my $item (@numbers) {
! 7956: my ($currdef,$newdef);
! 7957: my $newdef = $env{'form.'.$item};
! 7958: if ($item eq 'anonsurvey_threshold') {
! 7959: $currdef = $domconfig{'coursedefaults'}{$item};
! 7960: $newdef =~ s/\D//g;
! 7961: if ($newdef eq '' || $newdef < 1) {
! 7962: $newdef = 1;
! 7963: }
! 7964: $defaultshash{'coursedefaults'}{$item} = $newdef;
! 7965: } else {
! 7966: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
! 7967: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
! 7968: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
! 7969: }
! 7970: $newdef =~ s/[^\w.\-]//g;
! 7971: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
! 7972: }
! 7973: if ($currdef ne $newdef) {
! 7974: my $staticdef;
! 7975: if ($item eq 'anonsurvey_threshold') {
! 7976: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
! 7977: $changes{$item} = 1;
! 7978: }
! 7979: } else {
! 7980: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
! 7981: $changes{'uploadquota'} = 1;
! 7982: }
! 7983: }
1.139 raeburn 7984: }
7985: }
1.160.6.16 raeburn 7986: my $officialcreds = $env{'form.official_credits'};
7987: $officialcreds =~ s/^[^\d\.]//g;
7988: my $unofficialcreds = $env{'form.unofficial_credits'};
7989: $unofficialcreds =~ s/^[^\d\.]//g;
7990: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
7991: ($env{'form.coursecredits'} eq '1')) {
7992: $changes{'coursecredits'} = 1;
7993: } else {
7994: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
7995: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
7996: $changes{'coursecredits'} = 1;
7997: }
7998: }
7999: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8000: official => $officialcreds,
8001: unofficial => $unofficialcreds,
8002: }
1.121 raeburn 8003: }
8004: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8005: $dom);
8006: if ($putresult eq 'ok') {
1.160.6.16 raeburn 8007: my %domdefaults;
1.121 raeburn 8008: if (keys(%changes) > 0) {
1.160.6.21! raeburn 8009: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.160.6.16 raeburn 8010: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8011: if ($changes{'canuse_pdfforms'}) {
8012: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8013: }
8014: if ($changes{'coursecredits'}) {
8015: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8016: $domdefaults{'officialcredits'} =
8017: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8018: $domdefaults{'unofficialcredits'} =
8019: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8020: }
8021: }
1.160.6.21! raeburn 8022: if ($changes{'uploadquota'}) {
! 8023: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
! 8024: foreach my $type (@types) {
! 8025: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
! 8026: }
! 8027: }
! 8028: }
1.121 raeburn 8029: my $cachetime = 24*60*60;
8030: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8031: }
8032: $resulttext = &mt('Changes made:').'<ul>';
8033: foreach my $item (sort(keys(%changes))) {
8034: if ($item eq 'canuse_pdfforms') {
8035: if ($env{'form.'.$item} eq '1') {
8036: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8037: } else {
8038: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8039: }
1.139 raeburn 8040: } elsif ($item eq 'anonsurvey_threshold') {
8041: $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 8042: } elsif ($item eq 'uploadquota') {
! 8043: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
! 8044: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
! 8045: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
! 8046: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
! 8047: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
! 8048: '</ul>'.
! 8049: '</li>';
! 8050: } else {
! 8051: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
! 8052: }
1.160.6.16 raeburn 8053: } elsif ($item eq 'coursecredits') {
8054: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8055: if (($domdefaults{'officialcredits'} eq '') &&
8056: ($domdefaults{'unofficialcredits'} eq '')) {
8057: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8058: } else {
8059: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8060: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8061: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8062: '</ul>'.
8063: '</li>';
8064: }
8065: } else {
8066: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8067: }
1.140 raeburn 8068: }
1.121 raeburn 8069: }
8070: $resulttext .= '</ul>';
8071: } else {
8072: $resulttext = &mt('No changes made to course defaults');
8073: }
8074: } else {
8075: $resulttext = '<span class="LC_error">'.
8076: &mt('An error occurred: [_1]',$putresult).'</span>';
8077: }
8078: return $resulttext;
8079: }
8080:
1.137 raeburn 8081: sub modify_usersessions {
8082: my ($dom,%domconfig) = @_;
1.145 raeburn 8083: my @hostingtypes = ('version','excludedomain','includedomain');
8084: my @offloadtypes = ('primary','default');
8085: my %types = (
8086: remote => \@hostingtypes,
8087: hosted => \@hostingtypes,
8088: spares => \@offloadtypes,
8089: );
8090: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8091: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8092: my (%by_ip,%by_location,@intdoms);
8093: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8094: my @locations = sort(keys(%by_location));
1.137 raeburn 8095: my (%defaultshash,%changes);
8096: foreach my $prefix (@prefixes) {
8097: $defaultshash{'usersessions'}{$prefix} = {};
8098: }
8099: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8100: my $resulttext;
1.138 raeburn 8101: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8102: foreach my $prefix (@prefixes) {
1.145 raeburn 8103: next if ($prefix eq 'spares');
8104: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8105: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8106: if ($type eq 'version') {
8107: my $value = $env{'form.'.$prefix.'_'.$type};
8108: my $okvalue;
8109: if ($value ne '') {
8110: if (grep(/^\Q$value\E$/,@lcversions)) {
8111: $okvalue = $value;
8112: }
8113: }
8114: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8115: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8116: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8117: if ($inuse == 0) {
8118: $changes{$prefix}{$type} = 1;
8119: } else {
8120: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8121: $changes{$prefix}{$type} = 1;
8122: }
8123: if ($okvalue ne '') {
8124: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8125: }
8126: }
8127: } else {
8128: if (($inuse == 1) && ($okvalue ne '')) {
8129: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8130: $changes{$prefix}{$type} = 1;
8131: }
8132: }
8133: } else {
8134: if (($inuse == 1) && ($okvalue ne '')) {
8135: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8136: $changes{$prefix}{$type} = 1;
8137: }
8138: }
8139: } else {
8140: if (($inuse == 1) && ($okvalue ne '')) {
8141: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8142: $changes{$prefix}{$type} = 1;
8143: }
8144: }
8145: } else {
8146: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8147: my @okvals;
8148: foreach my $val (@vals) {
1.138 raeburn 8149: if ($val =~ /:/) {
8150: my @items = split(/:/,$val);
8151: foreach my $item (@items) {
8152: if (ref($by_location{$item}) eq 'ARRAY') {
8153: push(@okvals,$item);
8154: }
8155: }
8156: } else {
8157: if (ref($by_location{$val}) eq 'ARRAY') {
8158: push(@okvals,$val);
8159: }
1.137 raeburn 8160: }
8161: }
8162: @okvals = sort(@okvals);
8163: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8164: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8165: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8166: if ($inuse == 0) {
8167: $changes{$prefix}{$type} = 1;
8168: } else {
8169: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8170: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8171: if (@changed > 0) {
8172: $changes{$prefix}{$type} = 1;
8173: }
8174: }
8175: } else {
8176: if ($inuse == 1) {
8177: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8178: $changes{$prefix}{$type} = 1;
8179: }
8180: }
8181: } else {
8182: if ($inuse == 1) {
8183: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8184: $changes{$prefix}{$type} = 1;
8185: }
8186: }
8187: } else {
8188: if ($inuse == 1) {
8189: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8190: $changes{$prefix}{$type} = 1;
8191: }
8192: }
8193: }
8194: }
8195: }
1.145 raeburn 8196:
8197: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8198: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8199: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8200: my $savespares;
8201:
8202: foreach my $lonhost (sort(keys(%servers))) {
8203: my $serverhomeID =
8204: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8205: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8206: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8207: my %spareschg;
8208: foreach my $type (@{$types{'spares'}}) {
8209: my @okspares;
8210: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8211: foreach my $server (@checked) {
1.152 raeburn 8212: if (&Apache::lonnet::hostname($server) ne '') {
8213: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8214: unless (grep(/^\Q$server\E$/,@okspares)) {
8215: push(@okspares,$server);
8216: }
1.145 raeburn 8217: }
8218: }
8219: }
8220: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8221: my $newspare;
1.152 raeburn 8222: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8223: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8224: $newspare = $new;
8225: }
8226: }
1.152 raeburn 8227: my @spares;
8228: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8229: @spares = sort(@okspares,$newspare);
8230: } else {
8231: @spares = sort(@okspares);
8232: }
8233: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8234: if (ref($spareid{$lonhost}) eq 'HASH') {
8235: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8236: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8237: if (@diffs > 0) {
8238: $spareschg{$type} = 1;
8239: }
8240: }
8241: }
8242: }
8243: if (keys(%spareschg) > 0) {
8244: $changes{'spares'}{$lonhost} = \%spareschg;
8245: }
8246: }
8247:
8248: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8249: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8250: if (ref($changes{'spares'}) eq 'HASH') {
8251: if (keys(%{$changes{'spares'}}) > 0) {
8252: $savespares = 1;
8253: }
8254: }
8255: } else {
8256: $savespares = 1;
8257: }
8258: }
8259:
1.147 raeburn 8260: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8261: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8262: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8263: $dom);
8264: if ($putresult eq 'ok') {
8265: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8266: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8267: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8268: }
8269: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8270: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8271: }
8272: }
8273: my $cachetime = 24*60*60;
8274: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8275: if (keys(%changes) > 0) {
8276: my %lt = &usersession_titles();
8277: $resulttext = &mt('Changes made:').'<ul>';
8278: foreach my $prefix (@prefixes) {
8279: if (ref($changes{$prefix}) eq 'HASH') {
8280: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8281: if ($prefix eq 'spares') {
8282: if (ref($changes{$prefix}) eq 'HASH') {
8283: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8284: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8285: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8286: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8287: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8288: foreach my $type (@{$types{$prefix}}) {
8289: if ($changes{$prefix}{$lonhost}{$type}) {
8290: my $offloadto = &mt('None');
8291: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8292: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8293: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8294: }
1.145 raeburn 8295: }
1.147 raeburn 8296: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8297: }
1.137 raeburn 8298: }
8299: }
1.147 raeburn 8300: $resulttext .= '</li>';
1.137 raeburn 8301: }
8302: }
1.147 raeburn 8303: } else {
8304: foreach my $type (@{$types{$prefix}}) {
8305: if (defined($changes{$prefix}{$type})) {
8306: my $newvalue;
8307: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8308: if (ref($defaultshash{'usersessions'}{$prefix})) {
8309: if ($type eq 'version') {
8310: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8311: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8312: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8313: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8314: }
1.145 raeburn 8315: }
8316: }
8317: }
1.147 raeburn 8318: if ($newvalue eq '') {
8319: if ($type eq 'version') {
8320: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8321: } else {
8322: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8323: }
1.145 raeburn 8324: } else {
1.147 raeburn 8325: if ($type eq 'version') {
8326: $newvalue .= ' '.&mt('(or later)');
8327: }
8328: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8329: }
1.137 raeburn 8330: }
8331: }
8332: }
1.147 raeburn 8333: $resulttext .= '</ul>';
1.137 raeburn 8334: }
8335: }
1.147 raeburn 8336: $resulttext .= '</ul>';
8337: } else {
8338: $resulttext = $nochgmsg;
1.137 raeburn 8339: }
8340: } else {
8341: $resulttext = '<span class="LC_error">'.
8342: &mt('An error occurred: [_1]',$putresult).'</span>';
8343: }
8344: } else {
1.147 raeburn 8345: $resulttext = $nochgmsg;
1.137 raeburn 8346: }
8347: return $resulttext;
8348: }
8349:
1.150 raeburn 8350: sub modify_loadbalancing {
8351: my ($dom,%domconfig) = @_;
8352: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8353: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8354: my ($othertitle,$usertypes,$types) =
8355: &Apache::loncommon::sorted_inst_types($dom);
8356: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8357: my @sparestypes = ('primary','default');
8358: my %typetitles = &sparestype_titles();
8359: my $resulttext;
1.160.6.7 raeburn 8360: my (%currbalancer,%currtargets,%currrules,%existing);
8361: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8362: %existing = %{$domconfig{'loadbalancing'}};
8363: }
8364: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8365: \%currtargets,\%currrules);
8366: my ($saveloadbalancing,%defaultshash,%changes);
8367: my ($alltypes,$othertypes,$titles) =
8368: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8369: my %ruletitles = &offloadtype_text();
8370: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8371: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8372: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8373: if ($balancer eq '') {
8374: next;
8375: }
8376: if (!exists($servers{$balancer})) {
8377: if (exists($currbalancer{$balancer})) {
8378: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8379: }
1.160.6.7 raeburn 8380: next;
8381: }
8382: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8383: push(@{$changes{'delete'}},$balancer);
8384: next;
8385: }
8386: if (!exists($currbalancer{$balancer})) {
8387: push(@{$changes{'add'}},$balancer);
8388: }
8389: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8390: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8391: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8392: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8393: $saveloadbalancing = 1;
8394: }
8395: foreach my $sparetype (@sparestypes) {
8396: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8397: my @offloadto;
8398: foreach my $target (@targets) {
8399: if (($servers{$target}) && ($target ne $balancer)) {
8400: if ($sparetype eq 'default') {
8401: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8402: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8403: }
8404: }
1.160.6.7 raeburn 8405: unless(grep(/^\Q$target\E$/,@offloadto)) {
8406: push(@offloadto,$target);
8407: }
1.150 raeburn 8408: }
1.160.6.7 raeburn 8409: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8410: }
8411: }
1.160.6.7 raeburn 8412: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8413: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8414: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8415: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8416: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8417: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8418: }
1.160.6.7 raeburn 8419: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8420: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8421: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8422: }
8423: }
8424: }
8425: } else {
1.160.6.7 raeburn 8426: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8427: foreach my $sparetype (@sparestypes) {
8428: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8429: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8430: $changes{'curr'}{$balancer}{'targets'} = 1;
8431: }
1.150 raeburn 8432: }
8433: }
1.160.6.7 raeburn 8434: }
1.150 raeburn 8435: }
8436: my $ishomedom;
1.160.6.7 raeburn 8437: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8438: $ishomedom = 1;
1.150 raeburn 8439: }
8440: if (ref($alltypes) eq 'ARRAY') {
8441: foreach my $type (@{$alltypes}) {
8442: my $rule;
1.160.6.7 raeburn 8443: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8444: (!$ishomedom)) {
1.160.6.7 raeburn 8445: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8446: }
8447: if ($rule eq 'specific') {
8448: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8449: }
1.160.6.7 raeburn 8450: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8451: if (ref($currrules{$balancer}) eq 'HASH') {
8452: if ($rule ne $currrules{$balancer}{$type}) {
8453: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8454: }
8455: } elsif ($rule ne '') {
1.160.6.7 raeburn 8456: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8457: }
8458: }
8459: }
1.160.6.7 raeburn 8460: }
8461: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8462: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8463: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8464: $defaultshash{'loadbalancing'} = {};
8465: }
8466: my $putresult = &Apache::lonnet::put_dom('configuration',
8467: \%defaultshash,$dom);
8468:
8469: if ($putresult eq 'ok') {
8470: if (keys(%changes) > 0) {
8471: if (ref($changes{'delete'}) eq 'ARRAY') {
8472: foreach my $balancer (sort(@{$changes{'delete'}})) {
8473: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8474: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8475: }
1.160.6.7 raeburn 8476: }
8477: if (ref($changes{'add'}) eq 'ARRAY') {
8478: foreach my $balancer (sort(@{$changes{'add'}})) {
8479: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8480: }
8481: }
8482: if (ref($changes{'curr'}) eq 'HASH') {
8483: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8484: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8485: if ($changes{'curr'}{$balancer}{'targets'}) {
8486: my %offloadstr;
8487: foreach my $sparetype (@sparestypes) {
8488: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8489: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8490: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8491: }
8492: }
1.150 raeburn 8493: }
1.160.6.7 raeburn 8494: if (keys(%offloadstr) == 0) {
8495: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8496: } else {
1.160.6.7 raeburn 8497: my $showoffload;
8498: foreach my $sparetype (@sparestypes) {
8499: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8500: if (defined($offloadstr{$sparetype})) {
8501: $showoffload .= $offloadstr{$sparetype};
8502: } else {
8503: $showoffload .= &mt('None');
8504: }
8505: $showoffload .= (' 'x3);
8506: }
8507: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8508: }
8509: }
8510: }
1.160.6.7 raeburn 8511: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8512: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8513: foreach my $type (@{$alltypes}) {
8514: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8515: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8516: my $balancetext;
8517: if ($rule eq '') {
8518: $balancetext = $ruletitles{'default'};
8519: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8520: $balancetext = $ruletitles{$rule};
8521: } else {
8522: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8523: }
8524: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8525: }
8526: }
8527: }
8528: }
1.160.6.7 raeburn 8529: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8530: }
1.160.6.7 raeburn 8531: }
8532: if ($resulttext ne '') {
8533: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8534: } else {
8535: $resulttext = $nochgmsg;
8536: }
8537: } else {
1.160.6.7 raeburn 8538: $resulttext = $nochgmsg;
1.150 raeburn 8539: }
8540: } else {
1.160.6.7 raeburn 8541: $resulttext = '<span class="LC_error">'.
8542: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8543: }
8544: } else {
1.160.6.7 raeburn 8545: $resulttext = $nochgmsg;
1.150 raeburn 8546: }
8547: return $resulttext;
8548: }
8549:
1.48 raeburn 8550: sub recurse_check {
8551: my ($chkcats,$categories,$depth,$name) = @_;
8552: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8553: my $chg = 0;
8554: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8555: my $category = $chkcats->[$depth]{$name}[$j];
8556: my $item;
8557: if ($category eq '') {
8558: $chg ++;
8559: } else {
8560: my $deeper = $depth + 1;
8561: $item = &escape($category).':'.&escape($name).':'.$depth;
8562: if ($chg) {
8563: $categories->{$item} -= $chg;
8564: }
8565: &recurse_check($chkcats,$categories,$deeper,$category);
8566: $deeper --;
8567: }
8568: }
8569: }
8570: return;
8571: }
8572:
8573: sub recurse_cat_deletes {
8574: my ($item,$coursecategories,$deletions) = @_;
8575: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8576: my $subdepth = $depth + 1;
8577: if (ref($coursecategories) eq 'HASH') {
8578: foreach my $subitem (keys(%{$coursecategories})) {
8579: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8580: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8581: delete($coursecategories->{$subitem});
8582: $deletions->{$subitem} = 1;
8583: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8584: }
8585: }
8586: }
8587: return;
8588: }
8589:
1.125 raeburn 8590: sub get_active_dcs {
8591: my ($dom) = @_;
1.160.6.16 raeburn 8592: my $now = time;
8593: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8594: my %domcoords;
8595: my $numdcs = 0;
8596: foreach my $server (keys(%dompersonnel)) {
8597: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8598: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 8599: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8600: }
8601: }
8602: return %domcoords;
8603: }
8604:
8605: sub active_dc_picker {
1.160.6.16 raeburn 8606: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8607: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 8608: my @domcoord = keys(%domcoords);
8609: if (keys(%currhash)) {
8610: foreach my $dc (keys(%currhash)) {
8611: unless (exists($domcoords{$dc})) {
8612: push(@domcoord,$dc);
8613: }
8614: }
8615: }
8616: @domcoord = sort(@domcoord);
8617: my $numdcs = scalar(@domcoord);
8618: my $rows = 0;
8619: my $table;
1.125 raeburn 8620: if ($numdcs > 1) {
1.160.6.16 raeburn 8621: $table = '<table>';
8622: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8623: my $rem = $i%($numinrow);
8624: if ($rem == 0) {
8625: if ($i > 0) {
1.160.6.16 raeburn 8626: $table .= '</tr>';
1.125 raeburn 8627: }
1.160.6.16 raeburn 8628: $table .= '<tr>';
8629: $rows ++;
1.125 raeburn 8630: }
1.160.6.16 raeburn 8631: my $check = '';
8632: if ($inputtype eq 'radio') {
8633: if (keys(%currhash) == 0) {
8634: if (!$i) {
8635: $check = ' checked="checked"';
8636: }
8637: } elsif (exists($currhash{$domcoord[$i]})) {
8638: $check = ' checked="checked"';
8639: }
8640: } else {
8641: if (exists($currhash{$domcoord[$i]})) {
8642: $check = ' checked="checked"';
1.125 raeburn 8643: }
8644: }
1.160.6.16 raeburn 8645: if ($i == @domcoord - 1) {
1.125 raeburn 8646: my $colsleft = $numinrow - $rem;
8647: if ($colsleft > 1) {
1.160.6.16 raeburn 8648: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8649: } else {
1.160.6.16 raeburn 8650: $table .= '<td class="LC_left_item">';
1.125 raeburn 8651: }
8652: } else {
1.160.6.16 raeburn 8653: $table .= '<td class="LC_left_item">';
8654: }
8655: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8656: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8657: $table .= '<span class="LC_nobreak"><label>'.
8658: '<input type="'.$inputtype.'" name="'.$name.'"'.
8659: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8660: if ($user ne $dcname.':'.$dcdom) {
8661: $table .= ' ('.$dcname.':'.$dcdom.')'.
8662: '</label></span></td>';
1.125 raeburn 8663: }
8664: }
1.160.6.16 raeburn 8665: $table .= '</tr></table>';
8666: } elsif ($numdcs == 1) {
8667: if ($inputtype eq 'radio') {
8668: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8669: } else {
8670: my $check;
8671: if (exists($currhash{$domcoord[0]})) {
8672: $check = ' checked="checked"';
8673: }
8674: $table .= '<input type="checkbox" name="'.$name.'" '.
8675: 'value="'.$domcoord[0].'"'.$check.' />';
8676: $rows ++;
8677: }
1.125 raeburn 8678: }
1.160.6.16 raeburn 8679: return ($numdcs,$table,$rows);
1.125 raeburn 8680: }
8681:
1.137 raeburn 8682: sub usersession_titles {
8683: return &Apache::lonlocal::texthash(
8684: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8685: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8686: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8687: version => 'LON-CAPA version requirement',
1.138 raeburn 8688: excludedomain => 'Allow all, but exclude specific domains',
8689: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8690: primary => 'Primary (checked first)',
1.154 raeburn 8691: default => 'Default',
1.137 raeburn 8692: );
8693: }
8694:
1.152 raeburn 8695: sub id_for_thisdom {
8696: my (%servers) = @_;
8697: my %altids;
8698: foreach my $server (keys(%servers)) {
8699: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8700: if ($serverhome ne $server) {
8701: $altids{$serverhome} = $server;
8702: }
8703: }
8704: return %altids;
8705: }
8706:
1.150 raeburn 8707: sub count_servers {
8708: my ($currbalancer,%servers) = @_;
8709: my (@spares,$numspares);
8710: foreach my $lonhost (sort(keys(%servers))) {
8711: next if ($currbalancer eq $lonhost);
8712: push(@spares,$lonhost);
8713: }
8714: if ($currbalancer) {
8715: $numspares = scalar(@spares);
8716: } else {
8717: $numspares = scalar(@spares) - 1;
8718: }
8719: return ($numspares,@spares);
8720: }
8721:
8722: sub lonbalance_targets_js {
1.160.6.7 raeburn 8723: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8724: my $select = &mt('Select');
8725: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8726: if (ref($servers) eq 'HASH') {
8727: $alltargets = join("','",sort(keys(%{$servers})));
8728: my @homedoms;
8729: foreach my $server (sort(keys(%{$servers}))) {
8730: if (&Apache::lonnet::host_domain($server) eq $dom) {
8731: push(@homedoms,'1');
8732: } else {
8733: push(@homedoms,'0');
8734: }
8735: }
8736: $allishome = join("','",@homedoms);
8737: }
8738: if (ref($types) eq 'ARRAY') {
8739: if (@{$types} > 0) {
8740: @alltypes = @{$types};
8741: }
8742: }
8743: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8744: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8745: my (%currbalancer,%currtargets,%currrules,%existing);
8746: if (ref($settings) eq 'HASH') {
8747: %existing = %{$settings};
8748: }
8749: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8750: \%currtargets,\%currrules);
8751: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8752: return <<"END";
8753:
8754: <script type="text/javascript">
8755: // <![CDATA[
8756:
1.160.6.7 raeburn 8757: currBalancers = new Array('$balancers');
8758:
8759: function toggleTargets(balnum) {
8760: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8761: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8762: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8763: var prevbalancer = prevhostitem.value;
8764: var baltotal = document.getElementById('loadbalancing_total').value;
8765: prevhostitem.value = balancer;
8766: if (prevbalancer != '') {
8767: var prevIdx = currBalancers.indexOf(prevbalancer);
8768: if (prevIdx != -1) {
8769: currBalancers.splice(prevIdx,1);
8770: }
8771: }
1.150 raeburn 8772: if (balancer == '') {
1.160.6.7 raeburn 8773: hideSpares(balnum);
1.150 raeburn 8774: } else {
1.160.6.7 raeburn 8775: var currIdx = currBalancers.indexOf(balancer);
8776: if (currIdx == -1) {
8777: currBalancers.push(balancer);
8778: }
1.150 raeburn 8779: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8780: var ishomedom = homedoms[lonhostitem.selectedIndex];
8781: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8782: }
1.160.6.7 raeburn 8783: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8784: return;
8785: }
8786:
1.160.6.7 raeburn 8787: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8788: var alltargets = new Array('$alltargets');
8789: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8790: var offloadtypes = new Array('primary','default');
8791:
1.160.6.7 raeburn 8792: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8793: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8794:
1.151 raeburn 8795: for (var i=0; i<offloadtypes.length; i++) {
8796: var count = 0;
8797: for (var j=0; j<alltargets.length; j++) {
8798: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8799: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8800: item.value = alltargets[j];
8801: item.style.textAlign='left';
8802: item.style.textFace='normal';
8803: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8804: if (currBalancers.indexOf(alltargets[j]) == -1) {
8805: item.disabled = '';
8806: } else {
8807: item.disabled = 'disabled';
8808: item.checked = false;
8809: }
1.151 raeburn 8810: count ++;
8811: }
1.150 raeburn 8812: }
8813: }
1.151 raeburn 8814: for (var k=0; k<insttypes.length; k++) {
8815: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8816: if (ishomedom == 1) {
1.160.6.7 raeburn 8817: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8818: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8819: } else {
1.160.6.7 raeburn 8820: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8821: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8822:
8823: }
8824: } else {
1.160.6.7 raeburn 8825: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8826: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8827: }
1.151 raeburn 8828: if ((insttypes[k] != '_LC_external') &&
8829: ((insttypes[k] != '_LC_internetdom') ||
8830: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8831: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8832: item.options.length = 0;
8833: item.options[0] = new Option("","",true,true);
8834: var idx = 0;
1.151 raeburn 8835: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8836: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8837: idx ++;
8838: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8839:
1.150 raeburn 8840: }
8841: }
8842: }
8843: }
8844: return;
8845: }
8846:
1.160.6.7 raeburn 8847: function hideSpares(balnum) {
1.150 raeburn 8848: var alltargets = new Array('$alltargets');
8849: var insttypes = new Array('$allinsttypes');
8850: var offloadtypes = new Array('primary','default');
8851:
1.160.6.7 raeburn 8852: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8853: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8854:
8855: var total = alltargets.length - 1;
8856: for (var i=0; i<offloadtypes; i++) {
8857: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8858: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8859: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8860: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8861: }
1.150 raeburn 8862: }
8863: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8864: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8865: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8866: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8867: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8868: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8869: }
8870: }
8871: return;
8872: }
8873:
1.160.6.7 raeburn 8874: function checkOffloads(item,balnum,type) {
1.150 raeburn 8875: var alltargets = new Array('$alltargets');
8876: var offloadtypes = new Array('primary','default');
8877: if (item.checked) {
8878: var total = alltargets.length - 1;
8879: var other;
8880: if (type == offloadtypes[0]) {
1.151 raeburn 8881: other = offloadtypes[1];
1.150 raeburn 8882: } else {
1.151 raeburn 8883: other = offloadtypes[0];
1.150 raeburn 8884: }
8885: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8886: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8887: if (server == item.value) {
1.160.6.7 raeburn 8888: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8889: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8890: }
8891: }
8892: }
8893: }
8894: return;
8895: }
8896:
1.160.6.7 raeburn 8897: function singleServerToggle(balnum,type) {
8898: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8899: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 8900: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8901: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8902:
8903: } else {
1.160.6.7 raeburn 8904: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8905: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8906: }
8907: return;
8908: }
8909:
1.160.6.7 raeburn 8910: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8911: if (type == '_LC_external') {
8912: return;
8913: }
1.160.6.7 raeburn 8914: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8915: for (var i=0; i<typesRules.length; i++) {
8916: if (formname.elements[typesRules[i]].checked) {
8917: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 8918: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8919: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8920: } else {
1.160.6.7 raeburn 8921: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8922: }
8923: }
8924: }
8925: return;
8926: }
8927:
8928: function balancerDeleteChange(balnum) {
8929: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8930: var baltotal = document.getElementById('loadbalancing_total').value;
8931: var addtarget;
8932: var removetarget;
8933: var action = 'delete';
8934: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8935: var lonhost = hostitem.value;
8936: var currIdx = currBalancers.indexOf(lonhost);
8937: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8938: if (currIdx != -1) {
8939: currBalancers.splice(currIdx,1);
8940: }
8941: addtarget = lonhost;
8942: } else {
8943: if (currIdx == -1) {
8944: currBalancers.push(lonhost);
8945: }
8946: removetarget = lonhost;
8947: action = 'undelete';
8948: }
8949: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8950: }
8951: return;
8952: }
8953:
8954: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8955: if (baltotal > 1) {
8956: var offloadtypes = new Array('primary','default');
8957: var alltargets = new Array('$alltargets');
8958: var insttypes = new Array('$allinsttypes');
8959: for (var i=0; i<baltotal; i++) {
8960: if (i != balnum) {
8961: for (var j=0; j<offloadtypes.length; j++) {
8962: var total = alltargets.length - 1;
8963: for (var k=0; k<total; k++) {
8964: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8965: var server = serveritem.value;
8966: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8967: if (server == addtarget) {
8968: serveritem.disabled = '';
8969: }
8970: }
8971: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8972: if (server == removetarget) {
8973: serveritem.disabled = 'disabled';
8974: serveritem.checked = false;
8975: }
8976: }
8977: }
8978: }
8979: for (var j=0; j<insttypes.length; j++) {
8980: if (insttypes[j] != '_LC_external') {
8981: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8982: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8983: var currSel = singleserver.selectedIndex;
8984: var currVal = singleserver.options[currSel].value;
8985: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8986: var numoptions = singleserver.options.length;
8987: var needsnew = 1;
8988: for (var k=0; k<numoptions; k++) {
8989: if (singleserver.options[k] == addtarget) {
8990: needsnew = 0;
8991: break;
8992: }
8993: }
8994: if (needsnew == 1) {
8995: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8996: }
8997: }
8998: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8999: singleserver.options.length = 0;
9000: if ((currVal) && (currVal != removetarget)) {
9001: singleserver.options[0] = new Option("","",false,false);
9002: } else {
9003: singleserver.options[0] = new Option("","",true,true);
9004: }
9005: var idx = 0;
9006: for (var m=0; m<alltargets.length; m++) {
9007: if (currBalancers.indexOf(alltargets[m]) == -1) {
9008: idx ++;
9009: if (currVal == alltargets[m]) {
9010: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9011: } else {
9012: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9013: }
9014: }
9015: }
9016: }
9017: }
9018: }
9019: }
1.150 raeburn 9020: }
9021: }
9022: }
9023: return;
9024: }
9025:
1.152 raeburn 9026: // ]]>
9027: </script>
9028:
9029: END
9030: }
9031:
9032: sub new_spares_js {
9033: my @sparestypes = ('primary','default');
9034: my $types = join("','",@sparestypes);
9035: my $select = &mt('Select');
9036: return <<"END";
9037:
9038: <script type="text/javascript">
9039: // <![CDATA[
9040:
9041: function updateNewSpares(formname,lonhost) {
9042: var types = new Array('$types');
9043: var include = new Array();
9044: var exclude = new Array();
9045: for (var i=0; i<types.length; i++) {
9046: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9047: for (var j=0; j<spareboxes.length; j++) {
9048: if (formname.elements[spareboxes[j]].checked) {
9049: exclude.push(formname.elements[spareboxes[j]].value);
9050: } else {
9051: include.push(formname.elements[spareboxes[j]].value);
9052: }
9053: }
9054: }
9055: for (var i=0; i<types.length; i++) {
9056: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9057: var selIdx = newSpare.selectedIndex;
9058: var currnew = newSpare.options[selIdx].value;
9059: var okSpares = new Array();
9060: for (var j=0; j<newSpare.options.length; j++) {
9061: var possible = newSpare.options[j].value;
9062: if (possible != '') {
9063: if (exclude.indexOf(possible) == -1) {
9064: okSpares.push(possible);
9065: } else {
9066: if (currnew == possible) {
9067: selIdx = 0;
9068: }
9069: }
9070: }
9071: }
9072: for (var k=0; k<include.length; k++) {
9073: if (okSpares.indexOf(include[k]) == -1) {
9074: okSpares.push(include[k]);
9075: }
9076: }
9077: okSpares.sort();
9078: newSpare.options.length = 0;
9079: if (selIdx == 0) {
9080: newSpare.options[0] = new Option("$select","",true,true);
9081: } else {
9082: newSpare.options[0] = new Option("$select","",false,false);
9083: }
9084: for (var m=0; m<okSpares.length; m++) {
9085: var idx = m+1;
9086: var selThis = 0;
9087: if (selIdx != 0) {
9088: if (okSpares[m] == currnew) {
9089: selThis = 1;
9090: }
9091: }
9092: if (selThis == 1) {
9093: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9094: } else {
9095: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9096: }
9097: }
9098: }
9099: return;
9100: }
9101:
9102: function checkNewSpares(lonhost,type) {
9103: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9104: var chosen = newSpare.options[newSpare.selectedIndex].value;
9105: if (chosen != '') {
9106: var othertype;
9107: var othernewSpare;
9108: if (type == 'primary') {
9109: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9110: }
9111: if (type == 'default') {
9112: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9113: }
9114: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9115: othernewSpare.selectedIndex = 0;
9116: }
9117: }
9118: return;
9119: }
9120:
9121: // ]]>
9122: </script>
9123:
9124: END
9125:
9126: }
9127:
9128: sub common_domprefs_js {
9129: return <<"END";
9130:
9131: <script type="text/javascript">
9132: // <![CDATA[
9133:
1.150 raeburn 9134: function getIndicesByName(formname,item) {
1.152 raeburn 9135: var group = new Array();
1.150 raeburn 9136: for (var i=0;i<formname.elements.length;i++) {
9137: if (formname.elements[i].name == item) {
1.152 raeburn 9138: group.push(formname.elements[i].id);
1.150 raeburn 9139: }
9140: }
1.152 raeburn 9141: return group;
1.150 raeburn 9142: }
9143:
9144: // ]]>
9145: </script>
9146:
9147: END
1.152 raeburn 9148:
1.150 raeburn 9149: }
9150:
1.160.6.5 raeburn 9151: sub recaptcha_js {
9152: my %lt = &captcha_phrases();
9153: return <<"END";
9154:
9155: <script type="text/javascript">
9156: // <![CDATA[
9157:
9158: function updateCaptcha(caller,context) {
9159: var privitem;
9160: var pubitem;
9161: var privtext;
9162: var pubtext;
9163: if (document.getElementById(context+'_recaptchapub')) {
9164: pubitem = document.getElementById(context+'_recaptchapub');
9165: } else {
9166: return;
9167: }
9168: if (document.getElementById(context+'_recaptchapriv')) {
9169: privitem = document.getElementById(context+'_recaptchapriv');
9170: } else {
9171: return;
9172: }
9173: if (document.getElementById(context+'_recaptchapubtxt')) {
9174: pubtext = document.getElementById(context+'_recaptchapubtxt');
9175: } else {
9176: return;
9177: }
9178: if (document.getElementById(context+'_recaptchaprivtxt')) {
9179: privtext = document.getElementById(context+'_recaptchaprivtxt');
9180: } else {
9181: return;
9182: }
9183: if (caller.checked) {
9184: if (caller.value == 'recaptcha') {
9185: pubitem.type = 'text';
9186: privitem.type = 'text';
9187: pubitem.size = '40';
9188: privitem.size = '40';
9189: pubtext.innerHTML = "$lt{'pub'}";
9190: privtext.innerHTML = "$lt{'priv'}";
9191: } else {
9192: pubitem.type = 'hidden';
9193: privitem.type = 'hidden';
9194: pubtext.innerHTML = '';
9195: privtext.innerHTML = '';
9196: }
9197: }
9198: return;
9199: }
9200:
9201: // ]]>
9202: </script>
9203:
9204: END
9205:
9206: }
9207:
1.160.6.16 raeburn 9208: sub credits_js {
9209: return <<"END";
9210:
9211: <script type="text/javascript">
9212: // <![CDATA[
9213:
9214: function toggleCredits(domForm) {
9215: if (document.getElementById('credits')) {
9216: creditsitem = document.getElementById('credits');
9217: var creditsLength = domForm.coursecredits.length;
9218: if (creditsLength) {
9219: var currval;
9220: for (var i=0; i<creditsLength; i++) {
9221: if (domForm.coursecredits[i].checked) {
9222: currval = domForm.coursecredits[i].value;
9223: }
9224: }
9225: if (currval == 1) {
9226: creditsitem.style.display = 'block';
9227: } else {
9228: creditsitem.style.display = 'none';
9229: }
9230: }
9231: }
9232: return;
9233: }
9234:
9235: // ]]>
9236: </script>
9237:
9238: END
9239:
9240: }
9241:
1.160.6.5 raeburn 9242: sub captcha_phrases {
9243: return &Apache::lonlocal::texthash (
9244: priv => 'Private key',
9245: pub => 'Public key',
9246: original => 'original (CAPTCHA)',
9247: recaptcha => 'successor (ReCAPTCHA)',
9248: notused => 'unused',
9249: );
9250: }
9251:
1.3 raeburn 9252: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>