Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.12
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.12! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.11 2012/12/20 13:53:22 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
48: for use by individuals affliated with the institution. Accordingly, each domain
49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.5 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
1.104 raeburn 108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 109: which have the following effects:
110:
111: 0
112:
113: =over
114:
115: - course requests are not allowed for this course types/affiliation
116:
117: =back
118:
1.104 raeburn 119: approval
1.101 raeburn 120:
121: =over
122:
123: - course requests must be approved by a Doman Coordinator in the
124: course's domain
125:
126: =back
127:
128: validate
129:
130: =over
131:
132: - an institutional validation (e.g., check requestor is instructor
133: of record) needs to be passed before the course will be created. The required
134: validation is in localenroll.pm on the primary library server for the course
135: domain.
136:
137: =back
138:
139: autolimit
140:
141: =over
142:
1.143 raeburn 143: - course requests will be processed automatically up to a limit of
1.101 raeburn 144: N requests for the course type for the particular requestor.
145: If N is undefined, there is no limit to the number of course requests
146: which a course owner may submit and have processed automatically.
147:
148: =back
149:
150: =item modify_quotas()
151:
152: =back
153:
154: =cut
155:
1.1 raeburn 156: package Apache::domainprefs;
157:
158: use strict;
159: use Apache::Constants qw(:common :http);
160: use Apache::lonnet;
161: use Apache::loncommon();
162: use Apache::lonhtmlcommon();
163: use Apache::lonlocal;
1.43 raeburn 164: use Apache::lonmsg();
1.91 raeburn 165: use Apache::lonconfigsettings;
1.69 raeburn 166: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 167: use LONCAPA::Enrollment;
1.81 raeburn 168: use LONCAPA::lonauthcgi();
1.9 raeburn 169: use File::Copy;
1.43 raeburn 170: use Locale::Language;
1.62 raeburn 171: use DateTime::TimeZone;
1.68 raeburn 172: use DateTime::Locale;
1.1 raeburn 173:
1.155 raeburn 174: my $registered_cleanup;
175: my $modified_urls;
176:
1.1 raeburn 177: sub handler {
178: my $r=shift;
179: if ($r->header_only) {
180: &Apache::loncommon::content_type($r,'text/html');
181: $r->send_http_header;
182: return OK;
183: }
184:
1.91 raeburn 185: my $context = 'domain';
1.1 raeburn 186: my $dom = $env{'request.role.domain'};
1.5 albertel 187: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 188: if (&Apache::lonnet::allowed('mau',$dom)) {
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: } else {
192: $env{'user.error.msg'}=
193: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
194: return HTTP_NOT_ACCEPTABLE;
195: }
1.155 raeburn 196:
197: $registered_cleanup=0;
198: @{$modified_urls}=();
199:
1.1 raeburn 200: &Apache::lonhtmlcommon::clear_breadcrumbs();
201: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 202: ['phase','actions']);
1.30 raeburn 203: my $phase = 'pickactions';
1.3 raeburn 204: if ( exists($env{'form.phase'}) ) {
205: $phase = $env{'form.phase'};
206: }
1.150 raeburn 207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 208: my %domconfig =
1.6 raeburn 209: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 210: 'quotas','autoenroll','autoupdate','autocreate',
211: 'directorysrch','usercreation','usermodification',
212: 'contacts','defaults','scantron','coursecategories',
1.160.6.1 raeburn 213: 'serverstatuses','requestcourses','usersessions',
1.160.6.5 raeburn 214: 'loadbalancing','requestauthor'],$dom);
1.43 raeburn 215: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 216: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 217: 'usercreation','usermodification','scantron',
1.160.6.5 raeburn 218: 'requestcourses','requestauthor','coursecategories',
219: 'serverstatuses','usersessions');
1.160.6.7 raeburn 220: my %existing;
221: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
222: %existing = %{$domconfig{'loadbalancing'}};
223: }
224: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 225: push(@prefs_order,'loadbalancing');
226: }
1.30 raeburn 227: my %prefs = (
228: 'rolecolors' =>
229: { text => 'Default color schemes',
1.67 raeburn 230: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 231: header => [{col1 => 'Student Settings',
232: col2 => '',},
233: {col1 => 'Coordinator Settings',
234: col2 => '',},
235: {col1 => 'Author Settings',
236: col2 => '',},
237: {col1 => 'Administrator Settings',
238: col2 => '',}],
239: },
1.110 raeburn 240: 'login' =>
1.30 raeburn 241: { text => 'Log-in page options',
1.67 raeburn 242: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 243: header => [{col1 => 'Log-in Page Items',
244: col2 => '',},
245: {col1 => 'Log-in Help',
246: col2 => 'Value'}],
1.30 raeburn 247: },
1.43 raeburn 248: 'defaults' =>
1.141 raeburn 249: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 250: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 251: header => [{col1 => 'Setting',
252: col2 => 'Value'}],
253: },
1.30 raeburn 254: 'quotas' =>
1.160.6.4 raeburn 255: { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67 raeburn 256: help => 'Domain_Configuration_Quotas',
1.77 raeburn 257: header => [{col1 => 'User affiliation',
1.72 raeburn 258: col2 => 'Available tools',
259: col3 => 'Portfolio quota',}],
1.30 raeburn 260: },
261: 'autoenroll' =>
262: { text => 'Auto-enrollment settings',
1.67 raeburn 263: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 264: header => [{col1 => 'Configuration setting',
265: col2 => 'Value(s)'}],
266: },
267: 'autoupdate' =>
268: { text => 'Auto-update settings',
1.67 raeburn 269: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 270: header => [{col1 => 'Setting',
271: col2 => 'Value',},
1.131 raeburn 272: {col1 => 'Setting',
273: col2 => 'Affiliation'},
1.43 raeburn 274: {col1 => 'User population',
1.131 raeburn 275: col2 => 'Updateable user data'}],
1.30 raeburn 276: },
1.125 raeburn 277: 'autocreate' =>
278: { text => 'Auto-course creation settings',
279: help => 'Domain_Configuration_Auto_Creation',
280: header => [{col1 => 'Configuration Setting',
281: col2 => 'Value',}],
282: },
1.30 raeburn 283: 'directorysrch' =>
284: { text => 'Institutional directory searches',
1.67 raeburn 285: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 286: header => [{col1 => 'Setting',
287: col2 => 'Value',}],
288: },
289: 'contacts' =>
290: { text => 'Contact Information',
1.67 raeburn 291: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',}],
294: },
295:
296: 'usercreation' =>
297: { text => 'User creation',
1.67 raeburn 298: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 299: header => [{col1 => 'Format rule type',
300: col2 => 'Format rules in force'},
1.34 raeburn 301: {col1 => 'User account creation',
302: col2 => 'Usernames which may be created',},
1.30 raeburn 303: {col1 => 'Context',
1.43 raeburn 304: col2 => 'Assignable authentication types'}],
1.30 raeburn 305: },
1.69 raeburn 306: 'usermodification' =>
1.33 raeburn 307: { text => 'User modification',
1.67 raeburn 308: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 309: header => [{col1 => 'Target user has role',
310: col2 => 'User information updateable in author context'},
311: {col1 => 'Target user has role',
1.63 raeburn 312: col2 => 'User information updateable in course context'},
313: {col1 => "Status of user",
314: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 315: },
1.69 raeburn 316: 'scantron' =>
1.95 www 317: { text => 'Bubblesheet format file',
1.67 raeburn 318: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 319: header => [ {col1 => 'Item',
320: col2 => '',
321: }],
322: },
1.86 raeburn 323: 'requestcourses' =>
324: {text => 'Request creation of courses',
325: help => 'Domain_Configuration_Request_Courses',
326: header => [{col1 => 'User affiliation',
1.102 raeburn 327: col2 => 'Availability/Processing of requests',},
328: {col1 => 'Setting',
329: col2 => 'Value'}],
1.86 raeburn 330: },
1.160.6.5 raeburn 331: 'requestauthor' =>
332: {text => 'Request authoring space',
333: help => 'Domain_Configuration_Request_Author',
334: header => [{col1 => 'User affiliation',
335: col2 => 'Availability/Processing of requests',},
336: {col1 => 'Setting',
337: col2 => 'Value'}],
338: },
1.69 raeburn 339: 'coursecategories' =>
1.120 raeburn 340: { text => 'Cataloging of courses/communities',
1.67 raeburn 341: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 342: header => [{col1 => 'Category settings',
1.57 raeburn 343: col2 => '',},
344: {col1 => 'Categories',
345: col2 => '',
346: }],
1.69 raeburn 347: },
348: 'serverstatuses' =>
1.77 raeburn 349: {text => 'Access to server status pages',
1.69 raeburn 350: help => 'Domain_Configuration_Server_Status',
351: header => [{col1 => 'Status Page',
352: col2 => 'Other named users',
353: col3 => 'Specific IPs',
354: }],
355: },
1.141 raeburn 356: 'usersessions' =>
1.145 raeburn 357: {text => 'User session hosting/offloading',
1.137 raeburn 358: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 359: header => [{col1 => 'Domain server',
360: col2 => 'Servers to offload sessions to when busy'},
361: {col1 => 'Hosting of users from other domains',
1.137 raeburn 362: col2 => 'Rules'},
363: {col1 => "Hosting domain's own users elsewhere",
364: col2 => 'Rules'}],
365: },
1.150 raeburn 366: 'loadbalancing' =>
1.160.6.7 raeburn 367: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 368: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 369: header => [{col1 => 'Balancers',
1.150 raeburn 370: col2 => 'Default destinations',
371: col3 => 'User affliation',
372: col4 => 'Overrides'},
373: ],
374: },
1.3 raeburn 375: );
1.110 raeburn 376: if (keys(%servers) > 1) {
377: $prefs{'login'} = { text => 'Log-in page options',
378: help => 'Domain_Configuration_Login_Page',
379: header => [{col1 => 'Log-in Service',
380: col2 => 'Server Setting',},
381: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 382: col2 => ''},
383: {col1 => 'Log-in Help',
384: col2 => 'Value'}],
1.110 raeburn 385: };
386: }
1.6 raeburn 387: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 388: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 389: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 390: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 391: text=>"Settings to display/modify"});
1.9 raeburn 392: my $confname = $dom.'-domainconfig';
1.3 raeburn 393: if ($phase eq 'process') {
1.91 raeburn 394: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 395: } elsif ($phase eq 'display') {
1.160.6.5 raeburn 396: my $js = &recaptcha_js();
1.160.6.7 raeburn 397: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 398: my ($othertitle,$usertypes,$types) =
399: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 400: $js .= &lonbalance_targets_js($dom,$types,\%servers,
401: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 402: &new_spares_js().
403: &common_domprefs_js().
404: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 405: }
1.150 raeburn 406: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 407: } else {
1.160.6.11 raeburn 408: # check if domconfig user exists for the domain.
409: my $servadm = $r->dir_config('lonAdmEMail');
410: my ($configuserok,$author_ok,$switchserver) =
411: &config_check($dom,$confname,$servadm);
412: unless ($configuserok eq 'ok') {
413: &Apache::lonconfigsettings::print_header($r,$phase,$context);
414: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
415: $confname).
416: '<br />'
417: );
418: if ($switchserver) {
419: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
420: '<br />'.
421: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
422: '<br />'.
423: &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).
424: '<br />'.
425: &mt('To do that now, use the following link: [_1]',$switchserver)
426: );
427: } else {
428: $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.').
429: '<br />'.
430: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
431: );
432: }
433: $r->print(&Apache::loncommon::end_page());
434: return OK;
435: }
1.21 raeburn 436: if (keys(%domconfig) == 0) {
437: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 438: my @ids=&Apache::lonnet::current_machine_ids();
439: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 440: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 441: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 442: my $custom_img_count = 0;
443: foreach my $img (@loginimages) {
444: if ($designhash{$dom.'.login.'.$img} ne '') {
445: $custom_img_count ++;
446: }
447: }
448: foreach my $role (@roles) {
449: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
450: $custom_img_count ++;
451: }
452: }
453: if ($custom_img_count > 0) {
1.94 raeburn 454: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 455: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 456: $r->print(
457: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
458: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
459: &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 />'.
460: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
461: if ($switch_server) {
1.30 raeburn 462: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 463: }
1.91 raeburn 464: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 465: return OK;
466: }
467: }
468: }
1.91 raeburn 469: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 470: }
471: return OK;
472: }
473:
474: sub process_changes {
1.92 raeburn 475: my ($r,$dom,$confname,$action,$roles,$values) = @_;
476: my %domconfig;
477: if (ref($values) eq 'HASH') {
478: %domconfig = %{$values};
479: }
1.3 raeburn 480: my $output;
481: if ($action eq 'login') {
1.9 raeburn 482: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 483: } elsif ($action eq 'rolecolors') {
1.9 raeburn 484: $output = &modify_rolecolors($r,$dom,$confname,$roles,
485: %domconfig);
1.3 raeburn 486: } elsif ($action eq 'quotas') {
1.86 raeburn 487: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 488: } elsif ($action eq 'autoenroll') {
489: $output = &modify_autoenroll($dom,%domconfig);
490: } elsif ($action eq 'autoupdate') {
491: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 492: } elsif ($action eq 'autocreate') {
493: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 494: } elsif ($action eq 'directorysrch') {
495: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 496: } elsif ($action eq 'usercreation') {
1.28 raeburn 497: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 498: } elsif ($action eq 'usermodification') {
499: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 500: } elsif ($action eq 'contacts') {
501: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 502: } elsif ($action eq 'defaults') {
503: $output = &modify_defaults($dom,$r);
1.46 raeburn 504: } elsif ($action eq 'scantron') {
1.48 raeburn 505: $output = &modify_scantron($r,$dom,$confname,%domconfig);
506: } elsif ($action eq 'coursecategories') {
507: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 508: } elsif ($action eq 'serverstatuses') {
509: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 510: } elsif ($action eq 'requestcourses') {
511: $output = &modify_quotas($dom,$action,%domconfig);
1.160.6.5 raeburn 512: } elsif ($action eq 'requestauthor') {
513: $output = &modify_quotas($dom,$action,%domconfig);
1.137 raeburn 514: } elsif ($action eq 'usersessions') {
515: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 516: } elsif ($action eq 'loadbalancing') {
517: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 518: }
519: return $output;
520: }
521:
522: sub print_config_box {
1.9 raeburn 523: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 524: my $rowtotal = 0;
1.49 raeburn 525: my $output;
526: if ($action eq 'coursecategories') {
527: $output = &coursecategories_javascript($settings);
1.91 raeburn 528: }
1.49 raeburn 529: $output .=
1.30 raeburn 530: '<table class="LC_nested_outer">
1.3 raeburn 531: <tr>
1.66 raeburn 532: <th align="left" valign="middle"><span class="LC_nobreak">'.
533: &mt($item->{text}).' '.
534: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
535: '</tr>';
1.30 raeburn 536: $rowtotal ++;
1.110 raeburn 537: my $numheaders = 1;
538: if (ref($item->{'header'}) eq 'ARRAY') {
539: $numheaders = scalar(@{$item->{'header'}});
540: }
541: if ($numheaders > 1) {
1.64 raeburn 542: my $colspan = '';
1.145 raeburn 543: my $rightcolspan = '';
1.160.6.5 raeburn 544: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
545: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 546: $colspan = ' colspan="2"';
547: }
1.145 raeburn 548: if ($action eq 'usersessions') {
549: $rightcolspan = ' colspan="3"';
550: }
1.30 raeburn 551: $output .= '
1.3 raeburn 552: <tr>
553: <td>
554: <table class="LC_nested">
555: <tr class="LC_info_row">
1.59 bisitz 556: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 557: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 558: </tr>';
1.69 raeburn 559: $rowtotal ++;
1.6 raeburn 560: if ($action eq 'autoupdate') {
1.30 raeburn 561: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 562: } elsif ($action eq 'usercreation') {
1.33 raeburn 563: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
564: } elsif ($action eq 'usermodification') {
565: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 566: } elsif ($action eq 'coursecategories') {
567: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 568: } elsif ($action eq 'login') {
1.160.6.5 raeburn 569: if ($numheaders == 3) {
570: $colspan = ' colspan="2"';
571: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
572: } else {
573: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
574: }
1.102 raeburn 575: } elsif ($action eq 'requestcourses') {
576: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 577: } elsif ($action eq 'requestauthor') {
578: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 579: } elsif ($action eq 'usersessions') {
580: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 581: } elsif ($action eq 'rolecolors') {
1.30 raeburn 582: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 583: }
1.30 raeburn 584: $output .= '
1.6 raeburn 585: </table>
586: </td>
587: </tr>
588: <tr>
589: <td>
590: <table class="LC_nested">
591: <tr class="LC_info_row">
1.59 bisitz 592: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 593: $output .= '
1.59 bisitz 594: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 595: </tr>';
596: $rowtotal ++;
1.6 raeburn 597: if ($action eq 'autoupdate') {
1.131 raeburn 598: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
599: </table>
600: </td>
601: </tr>
602: <tr>
603: <td>
604: <table class="LC_nested">
605: <tr class="LC_info_row">
606: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
607: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
608: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
609: $rowtotal ++;
1.28 raeburn 610: } elsif ($action eq 'usercreation') {
1.34 raeburn 611: $output .= &print_usercreation('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">
1.59 bisitz 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>'.
1.34 raeburn 621: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
622: $rowtotal ++;
1.33 raeburn 623: } elsif ($action eq 'usermodification') {
1.63 raeburn 624: $output .= &print_usermodification('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">
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>'.
634: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
635: $rowtotal ++;
1.57 raeburn 636: } elsif ($action eq 'coursecategories') {
637: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 638: } elsif ($action eq 'login') {
1.160.6.5 raeburn 639: if ($numheaders == 3) {
640: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
641: </table>
642: </td>
643: </tr>
644: <tr>
645: <td>
646: <table class="LC_nested">
647: <tr class="LC_info_row">
648: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
649: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
650: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
651: $rowtotal ++;
652: } else {
653: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
654: }
1.102 raeburn 655: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 656: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
657: } elsif ($action eq 'requestauthor') {
658: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 659: } elsif ($action eq 'usersessions') {
1.145 raeburn 660: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
661: </table>
662: </td>
663: </tr>
664: <tr>
665: <td>
666: <table class="LC_nested">
667: <tr class="LC_info_row">
668: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
669: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
670: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
671: $rowtotal ++;
1.139 raeburn 672: } elsif ($action eq 'coursedefaults') {
673: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 674: } elsif ($action eq 'rolecolors') {
1.30 raeburn 675: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 676: </table>
677: </td>
678: </tr>
679: <tr>
680: <td>
681: <table class="LC_nested">
682: <tr class="LC_info_row">
1.69 raeburn 683: <td class="LC_left_item"'.$colspan.' valign="top">'.
684: &mt($item->{'header'}->[2]->{'col1'}).'</td>
685: <td class="LC_right_item" valign="top">'.
686: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 687: </tr>'.
1.30 raeburn 688: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 689: </table>
690: </td>
691: </tr>
692: <tr>
693: <td>
694: <table class="LC_nested">
695: <tr class="LC_info_row">
1.59 bisitz 696: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
697: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 698: </tr>'.
1.30 raeburn 699: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
700: $rowtotal += 2;
1.6 raeburn 701: }
1.3 raeburn 702: } else {
1.30 raeburn 703: $output .= '
1.3 raeburn 704: <tr>
705: <td>
706: <table class="LC_nested">
1.30 raeburn 707: <tr class="LC_info_row">';
1.24 raeburn 708: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 709: $output .= '
1.59 bisitz 710: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 711: } elsif ($action eq 'serverstatuses') {
712: $output .= '
713: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
714: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
715:
1.6 raeburn 716: } else {
1.30 raeburn 717: $output .= '
1.69 raeburn 718: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
719: }
1.72 raeburn 720: if (defined($item->{'header'}->[0]->{'col3'})) {
721: $output .= '<td class="LC_left_item" valign="top">'.
722: &mt($item->{'header'}->[0]->{'col2'});
723: if ($action eq 'serverstatuses') {
724: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
725: }
1.69 raeburn 726: } else {
727: $output .= '<td class="LC_right_item" valign="top">'.
728: &mt($item->{'header'}->[0]->{'col2'});
729: }
730: $output .= '</td>';
731: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 732: if (defined($item->{'header'}->[0]->{'col4'})) {
733: $output .= '<td class="LC_left_item" valign="top">'.
734: &mt($item->{'header'}->[0]->{'col3'});
735: } else {
736: $output .= '<td class="LC_right_item" valign="top">'.
737: &mt($item->{'header'}->[0]->{'col3'});
738: }
1.69 raeburn 739: if ($action eq 'serverstatuses') {
740: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
741: }
742: $output .= '</td>';
1.6 raeburn 743: }
1.150 raeburn 744: if ($item->{'header'}->[0]->{'col4'}) {
745: $output .= '<td class="LC_right_item" valign="top">'.
746: &mt($item->{'header'}->[0]->{'col4'});
747: }
1.69 raeburn 748: $output .= '</tr>';
1.48 raeburn 749: $rowtotal ++;
1.160.6.5 raeburn 750: if ($action eq 'quotas') {
1.86 raeburn 751: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 752: } elsif ($action eq 'autoenroll') {
1.30 raeburn 753: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 754: } elsif ($action eq 'autocreate') {
755: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 756: } elsif ($action eq 'directorysrch') {
1.30 raeburn 757: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 758: } elsif ($action eq 'contacts') {
1.30 raeburn 759: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 760: } elsif ($action eq 'defaults') {
761: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 762: } elsif ($action eq 'scantron') {
763: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 764: } elsif ($action eq 'serverstatuses') {
765: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 766: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 767: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 768: } elsif ($action eq 'loadbalancing') {
769: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 770: }
1.3 raeburn 771: }
1.30 raeburn 772: $output .= '
1.3 raeburn 773: </table>
774: </td>
775: </tr>
1.30 raeburn 776: </table><br />';
777: return ($output,$rowtotal);
1.1 raeburn 778: }
779:
1.3 raeburn 780: sub print_login {
1.160.6.5 raeburn 781: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 782: my ($css_class,$datatable);
1.6 raeburn 783: my %choices = &login_choices();
1.110 raeburn 784:
1.160.6.5 raeburn 785: if ($caller eq 'service') {
1.149 raeburn 786: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 787: my $choice = $choices{'disallowlogin'};
788: $css_class = ' class="LC_odd_row"';
1.128 raeburn 789: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 790: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 791: '<th>'.$choices{'server'}.'</th>'.
792: '<th>'.$choices{'serverpath'}.'</th>'.
793: '<th>'.$choices{'custompath'}.'</th>'.
794: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 795: my %disallowed;
796: if (ref($settings) eq 'HASH') {
797: if (ref($settings->{'loginvia'}) eq 'HASH') {
798: %disallowed = %{$settings->{'loginvia'}};
799: }
800: }
801: foreach my $lonhost (sort(keys(%servers))) {
802: my $direct = 'selected="selected"';
1.128 raeburn 803: if (ref($disallowed{$lonhost}) eq 'HASH') {
804: if ($disallowed{$lonhost}{'server'} ne '') {
805: $direct = '';
806: }
1.110 raeburn 807: }
1.115 raeburn 808: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 809: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 810: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
811: '</option>';
812: foreach my $hostid (keys(%servers)) {
1.115 raeburn 813: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 814: my $selected = '';
1.128 raeburn 815: if (ref($disallowed{$lonhost}) eq 'HASH') {
816: if ($hostid eq $disallowed{$lonhost}{'server'}) {
817: $selected = 'selected="selected"';
818: }
1.110 raeburn 819: }
820: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
821: $servers{$hostid}.'</option>';
822: }
1.128 raeburn 823: $datatable .= '</select></td>'.
824: '<td><select name="'.$lonhost.'_serverpath">';
825: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
826: my $pathname = $path;
827: if ($path eq 'custom') {
828: $pathname = &mt('Custom Path').' ->';
829: }
830: my $selected = '';
831: if (ref($disallowed{$lonhost}) eq 'HASH') {
832: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
833: $selected = 'selected="selected"';
834: }
835: } elsif ($path eq '') {
836: $selected = 'selected="selected"';
837: }
838: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
839: }
840: $datatable .= '</select></td>';
841: my ($custom,$exempt);
842: if (ref($disallowed{$lonhost}) eq 'HASH') {
843: $custom = $disallowed{$lonhost}{'custompath'};
844: $exempt = $disallowed{$lonhost}{'exempt'};
845: }
846: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
847: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
848: '</tr>';
1.110 raeburn 849: }
850: $datatable .= '</table></td></tr>';
851: return $datatable;
1.160.6.5 raeburn 852: } elsif ($caller eq 'page') {
853: my %defaultchecked = (
854: 'coursecatalog' => 'on',
855: 'adminmail' => 'off',
856: 'newuser' => 'off',
857: );
858: my @toggles = ('coursecatalog','adminmail','newuser');
859: my (%checkedon,%checkedoff);
1.42 raeburn 860: foreach my $item (@toggles) {
1.160.6.5 raeburn 861: if ($defaultchecked{$item} eq 'on') {
862: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 863: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 864: } elsif ($defaultchecked{$item} eq 'off') {
865: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 866: $checkedon{$item} = ' ';
867: }
1.1 raeburn 868: }
1.160.6.5 raeburn 869: my @images = ('img','logo','domlogo','login');
870: my @logintext = ('textcol','bgcol');
871: my @bgs = ('pgbg','mainbg','sidebg');
872: my @links = ('link','alink','vlink');
873: my %designhash = &Apache::loncommon::get_domainconf($dom);
874: my %defaultdesign = %Apache::loncommon::defaultdesign;
875: my (%is_custom,%designs);
876: my %defaults = (
877: font => $defaultdesign{'login.font'},
878: );
1.6 raeburn 879: foreach my $item (@images) {
1.160.6.5 raeburn 880: $defaults{$item} = $defaultdesign{'login.'.$item};
881: $defaults{'showlogo'}{$item} = 1;
882: }
883: foreach my $item (@bgs) {
884: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 885: }
1.41 raeburn 886: foreach my $item (@logintext) {
1.160.6.5 raeburn 887: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 888: }
1.160.6.5 raeburn 889: foreach my $item (@links) {
890: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 891: }
1.160.6.5 raeburn 892: if (ref($settings) eq 'HASH') {
893: foreach my $item (@toggles) {
894: if ($settings->{$item} eq '1') {
895: $checkedon{$item} = ' checked="checked" ';
896: $checkedoff{$item} = ' ';
897: } elsif ($settings->{$item} eq '0') {
898: $checkedoff{$item} = ' checked="checked" ';
899: $checkedon{$item} = ' ';
900: }
1.6 raeburn 901: }
1.160.6.5 raeburn 902: foreach my $item (@images) {
903: if (defined($settings->{$item})) {
904: $designs{$item} = $settings->{$item};
905: $is_custom{$item} = 1;
906: }
907: if (defined($settings->{'showlogo'}{$item})) {
908: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
909: }
910: }
911: foreach my $item (@logintext) {
912: if ($settings->{$item} ne '') {
913: $designs{'logintext'}{$item} = $settings->{$item};
914: $is_custom{$item} = 1;
915: }
916: }
917: if ($settings->{'font'} ne '') {
918: $designs{'font'} = $settings->{'font'};
919: $is_custom{'font'} = 1;
920: }
921: foreach my $item (@bgs) {
922: if ($settings->{$item} ne '') {
923: $designs{'bgs'}{$item} = $settings->{$item};
924: $is_custom{$item} = 1;
925: }
926: }
927: foreach my $item (@links) {
928: if ($settings->{$item} ne '') {
929: $designs{'links'}{$item} = $settings->{$item};
930: $is_custom{$item} = 1;
931: }
932: }
933: } else {
934: if ($designhash{$dom.'.login.font'} ne '') {
935: $designs{'font'} = $designhash{$dom.'.login.font'};
936: $is_custom{'font'} = 1;
937: }
938: foreach my $item (@images) {
939: if ($designhash{$dom.'.login.'.$item} ne '') {
940: $designs{$item} = $designhash{$dom.'.login.'.$item};
941: $is_custom{$item} = 1;
942: }
943: }
944: foreach my $item (@bgs) {
945: if ($designhash{$dom.'.login.'.$item} ne '') {
946: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
947: $is_custom{$item} = 1;
948: }
949: }
950: foreach my $item (@links) {
951: if ($designhash{$dom.'.login.'.$item} ne '') {
952: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
953: $is_custom{$item} = 1;
954: }
1.6 raeburn 955: }
956: }
1.160.6.5 raeburn 957: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
958: logo => 'Institution Logo',
959: domlogo => 'Domain Logo',
960: login => 'Login box');
961: my $itemcount = 1;
962: foreach my $item (@toggles) {
963: $css_class = $itemcount%2?' class="LC_odd_row"':'';
964: $datatable .=
965: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
966: '</td><td>'.
967: '<span class="LC_nobreak"><label><input type="radio" name="'.
968: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
969: '</label> <label><input type="radio" name="'.$item.'"'.
970: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
971: '</tr>';
972: $itemcount ++;
1.6 raeburn 973: }
1.160.6.5 raeburn 974: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
975: $datatable .= '</tr></table></td></tr>';
976: } elsif ($caller eq 'help') {
977: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
978: my $switchserver = &check_switchserver($dom,$confname);
979: my $itemcount = 1;
980: $defaulturl = '/adm/loginproblems.html';
981: $defaulttype = 'default';
982: %lt = &Apache::lonlocal::texthash (
983: del => 'Delete?',
984: rep => 'Replace:',
985: upl => 'Upload:',
986: default => 'Default',
987: custom => 'Custom',
988: );
989: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
990: my @currlangs;
991: if (ref($settings) eq 'HASH') {
992: if (ref($settings->{'helpurl'}) eq 'HASH') {
993: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
994: next if ($settings->{'helpurl'}{$key} eq '');
995: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
996: $type{$key} = 'custom';
997: unless ($key eq 'nolang') {
998: push(@currlangs,$key);
999: }
1000: }
1001: } elsif ($settings->{'helpurl'} ne '') {
1002: $type{'nolang'} = 'custom';
1003: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1004: }
1005: }
1.160.6.5 raeburn 1006: foreach my $lang ('nolang',sort(@currlangs)) {
1007: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1008: $datatable .= '<tr'.$css_class.'>';
1009: if ($url{$lang} eq '') {
1010: $url{$lang} = $defaulturl;
1011: }
1012: if ($type{$lang} eq '') {
1013: $type{$lang} = $defaulttype;
1014: }
1015: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1016: if ($lang eq 'nolang') {
1017: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1018: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1019: } else {
1020: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1021: $langchoices{$lang},
1022: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1023: }
1024: $datatable .= '</span></td>'."\n".
1025: '<td class="LC_left_item">';
1026: if ($type{$lang} eq 'custom') {
1027: $datatable .= '<span class="LC_nobreak"><label>'.
1028: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1029: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1030: } else {
1031: $datatable .= $lt{'upl'};
1032: }
1033: $datatable .='<br />';
1034: if ($switchserver) {
1035: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1036: } else {
1037: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1038: }
1.160.6.5 raeburn 1039: $datatable .= '</td></tr>';
1040: $itemcount ++;
1.6 raeburn 1041: }
1.160.6.5 raeburn 1042: my @addlangs;
1043: foreach my $lang (sort(keys(%langchoices))) {
1044: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1045: push(@addlangs,$lang);
1046: }
1047: if (@addlangs > 0) {
1048: my %toadd;
1049: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1050: $toadd{''} = &mt('Select');
1051: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1052: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1053: &mt('Add log-in help page for a specific language:').' '.
1054: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1055: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1056: if ($switchserver) {
1057: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1058: } else {
1059: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1060: }
1.160.6.5 raeburn 1061: $datatable .= '</td></tr>';
1062: $itemcount ++;
1.6 raeburn 1063: }
1.160.6.5 raeburn 1064: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1065: }
1.6 raeburn 1066: return $datatable;
1067: }
1068:
1069: sub login_choices {
1070: my %choices =
1071: &Apache::lonlocal::texthash (
1.116 bisitz 1072: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1073: adminmail => "Display Administrator's E-mail Address?",
1074: disallowlogin => "Login page requests redirected",
1075: hostid => "Server",
1.128 raeburn 1076: server => "Redirect to:",
1077: serverpath => "Path",
1078: custompath => "Custom",
1079: exempt => "Exempt IP(s)",
1.110 raeburn 1080: directlogin => "No redirect",
1081: newuser => "Link to create a user account",
1082: img => "Header",
1083: logo => "Main Logo",
1084: domlogo => "Domain Logo",
1085: login => "Log-in Header",
1086: textcol => "Text color",
1087: bgcol => "Box color",
1088: bgs => "Background colors",
1089: links => "Link colors",
1090: font => "Font color",
1091: pgbg => "Header",
1092: mainbg => "Page",
1093: sidebg => "Login box",
1094: link => "Link",
1095: alink => "Active link",
1096: vlink => "Visited link",
1.6 raeburn 1097: );
1098: return %choices;
1099: }
1100:
1101: sub print_rolecolors {
1.30 raeburn 1102: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1103: my %choices = &color_font_choices();
1104: my @bgs = ('pgbg','tabbg','sidebg');
1105: my @links = ('link','alink','vlink');
1106: my @images = ('img');
1107: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1108: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1109: my %defaultdesign = %Apache::loncommon::defaultdesign;
1110: my (%is_custom,%designs);
1111: my %defaults = (
1112: img => $defaultdesign{$role.'.img'},
1113: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1114: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1115: );
1116: foreach my $item (@bgs) {
1117: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1118: }
1119: foreach my $item (@links) {
1120: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1121: }
1122: if (ref($settings) eq 'HASH') {
1123: if (ref($settings->{$role}) eq 'HASH') {
1124: if ($settings->{$role}->{'img'} ne '') {
1125: $designs{'img'} = $settings->{$role}->{'img'};
1126: $is_custom{'img'} = 1;
1127: }
1128: if ($settings->{$role}->{'font'} ne '') {
1129: $designs{'font'} = $settings->{$role}->{'font'};
1130: $is_custom{'font'} = 1;
1131: }
1.97 tempelho 1132: if ($settings->{$role}->{'fontmenu'} ne '') {
1133: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1134: $is_custom{'fontmenu'} = 1;
1135: }
1.6 raeburn 1136: foreach my $item (@bgs) {
1137: if ($settings->{$role}->{$item} ne '') {
1138: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1139: $is_custom{$item} = 1;
1140: }
1141: }
1142: foreach my $item (@links) {
1143: if ($settings->{$role}->{$item} ne '') {
1144: $designs{'links'}{$item} = $settings->{$role}->{$item};
1145: $is_custom{$item} = 1;
1146: }
1147: }
1148: }
1149: } else {
1150: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1151: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1152: $is_custom{'img'} = 1;
1153: }
1.97 tempelho 1154: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1155: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1156: $is_custom{'fontmenu'} = 1;
1157: }
1.6 raeburn 1158: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1159: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1160: $is_custom{'font'} = 1;
1161: }
1162: foreach my $item (@bgs) {
1163: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1164: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1165: $is_custom{$item} = 1;
1166:
1167: }
1168: }
1169: foreach my $item (@links) {
1170: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1171: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1172: $is_custom{$item} = 1;
1173: }
1174: }
1175: }
1176: my $itemcount = 1;
1.30 raeburn 1177: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1178: $datatable .= '</tr></table></td></tr>';
1179: return $datatable;
1180: }
1181:
1182: sub display_color_options {
1.9 raeburn 1183: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1184: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1185: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1186: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1187: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1188: '<td>'.$choices->{'font'}.'</td>';
1189: if (!$is_custom->{'font'}) {
1.30 raeburn 1190: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1191: } else {
1192: $datatable .= '<td> </td>';
1193: }
1.160.6.9 raeburn 1194: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1195:
1.8 raeburn 1196: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1197: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1198: ' value="'.$current_color.'" /> '.
1199: ' </td></tr>';
1.107 raeburn 1200: unless ($role eq 'login') {
1201: $datatable .= '<tr'.$css_class.'>'.
1202: '<td>'.$choices->{'fontmenu'}.'</td>';
1203: if (!$is_custom->{'fontmenu'}) {
1204: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1205: } else {
1206: $datatable .= '<td> </td>';
1207: }
1.160.6.9 raeburn 1208: $current_color = $designs->{'fontmenu'} ?
1209: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1210: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1211: '<input class="colorchooser" type="text" size="10" name="'
1212: .$role.'_fontmenu"'.
1213: ' value="'.$current_color.'" /> '.
1214: ' </td></tr>';
1.97 tempelho 1215: }
1.9 raeburn 1216: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1217: foreach my $img (@{$images}) {
1.18 albertel 1218: $itemcount ++;
1.6 raeburn 1219: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1220: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1221: '<td>'.$choices->{$img};
1.41 raeburn 1222: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1223: if ($role eq 'login') {
1224: if ($img eq 'login') {
1225: $login_hdr_pick =
1.135 bisitz 1226: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1227: $logincolors =
1228: &login_text_colors($img,$role,$logintext,$phase,$choices,
1229: $designs);
1230: } elsif ($img ne 'domlogo') {
1231: $datatable.= &logo_display_options($img,$defaults,$designs);
1232: }
1233: }
1234: $datatable .= '</td>';
1.6 raeburn 1235: if ($designs->{$img} ne '') {
1236: $imgfile = $designs->{$img};
1.18 albertel 1237: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1238: } else {
1239: $imgfile = $defaults->{$img};
1240: }
1241: if ($imgfile) {
1.9 raeburn 1242: my ($showfile,$fullsize);
1243: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1244: my $urldir = $1;
1245: my $filename = $2;
1246: my @info = &Apache::lonnet::stat_file($designs->{$img});
1247: if (@info) {
1248: my $thumbfile = 'tn-'.$filename;
1249: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1250: if (@thumb) {
1251: $showfile = $urldir.'/'.$thumbfile;
1252: } else {
1253: $showfile = $imgfile;
1254: }
1255: } else {
1256: $showfile = '';
1257: }
1258: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1259: $showfile = $imgfile;
1.6 raeburn 1260: my $imgdir = $1;
1261: my $filename = $2;
1.159 raeburn 1262: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1263: $showfile = "/$imgdir/tn-".$filename;
1264: } else {
1.159 raeburn 1265: my $input = $londocroot.$imgfile;
1266: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1267: if (!-e $output) {
1.9 raeburn 1268: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1269: my ($fullwidth,$fullheight) = &check_dimensions($input);
1270: if ($fullwidth ne '' && $fullheight ne '') {
1271: if ($fullwidth > $width && $fullheight > $height) {
1272: my $size = $width.'x'.$height;
1273: system("convert -sample $size $input $output");
1.159 raeburn 1274: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1275: }
1276: }
1.6 raeburn 1277: }
1278: }
1.16 raeburn 1279: }
1.6 raeburn 1280: if ($showfile) {
1.40 raeburn 1281: if ($showfile =~ m{^/(adm|res)/}) {
1282: if ($showfile =~ m{^/res/}) {
1283: my $local_showfile =
1284: &Apache::lonnet::filelocation('',$showfile);
1285: &Apache::lonnet::repcopy($local_showfile);
1286: }
1287: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1288: }
1289: if ($imgfile) {
1290: if ($imgfile =~ m{^/(adm|res)/}) {
1291: if ($imgfile =~ m{^/res/}) {
1292: my $local_imgfile =
1293: &Apache::lonnet::filelocation('',$imgfile);
1294: &Apache::lonnet::repcopy($local_imgfile);
1295: }
1296: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1297: } else {
1298: $fullsize = $imgfile;
1299: }
1300: }
1.41 raeburn 1301: $datatable .= '<td>';
1302: if ($img eq 'login') {
1.135 bisitz 1303: $datatable .= $login_hdr_pick;
1304: }
1.41 raeburn 1305: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1306: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1307: } else {
1308: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1309: &mt('Upload:');
1310: }
1311: } else {
1312: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1313: &mt('Upload:');
1314: }
1.9 raeburn 1315: if ($switchserver) {
1316: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1317: } else {
1.135 bisitz 1318: if ($img ne 'login') { # suppress file selection for Log-in header
1319: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1320: }
1.9 raeburn 1321: }
1322: $datatable .= '</td></tr>';
1.6 raeburn 1323: }
1324: $itemcount ++;
1325: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1326: $datatable .= '<tr'.$css_class.'>'.
1327: '<td>'.$choices->{'bgs'}.'</td>';
1328: my $bgs_def;
1329: foreach my $item (@{$bgs}) {
1330: if (!$is_custom->{$item}) {
1.70 raeburn 1331: $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 1332: }
1333: }
1334: if ($bgs_def) {
1.8 raeburn 1335: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1336: } else {
1337: $datatable .= '<td> </td>';
1338: }
1339: $datatable .= '<td class="LC_right_item">'.
1340: '<table border="0"><tr>';
1341: foreach my $item (@{$bgs}) {
1.160.6.9 raeburn 1342: $datatable .= '<td align="center">';
1343: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1344: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1345: $datatable .= ' ';
1.6 raeburn 1346: }
1.160.6.9 raeburn 1347: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1348: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1349: }
1350: $datatable .= '</tr></table></td></tr>';
1351: $itemcount ++;
1352: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1353: $datatable .= '<tr'.$css_class.'>'.
1354: '<td>'.$choices->{'links'}.'</td>';
1355: my $links_def;
1356: foreach my $item (@{$links}) {
1357: if (!$is_custom->{$item}) {
1.30 raeburn 1358: $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 1359: }
1360: }
1361: if ($links_def) {
1.8 raeburn 1362: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1363: } else {
1364: $datatable .= '<td> </td>';
1365: }
1366: $datatable .= '<td class="LC_right_item">'.
1367: '<table border="0"><tr>';
1368: foreach my $item (@{$links}) {
1.160.6.9 raeburn 1369: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1370: $datatable .= '<td align="center">'."\n";
1371:
1.6 raeburn 1372: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1373: $datatable.=' ';
1.6 raeburn 1374: }
1.160.6.9 raeburn 1375: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1376: '" /></td>';
1.160.6.9 raeburn 1377:
1.6 raeburn 1378: }
1.30 raeburn 1379: $$rowtotal += $itemcount;
1.3 raeburn 1380: return $datatable;
1381: }
1382:
1.70 raeburn 1383: sub logo_display_options {
1384: my ($img,$defaults,$designs) = @_;
1385: my $checkedon;
1386: if (ref($defaults) eq 'HASH') {
1387: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1388: if ($defaults->{'showlogo'}{$img}) {
1389: $checkedon = 'checked="checked" ';
1390: }
1391: }
1392: }
1393: if (ref($designs) eq 'HASH') {
1394: if (ref($designs->{'showlogo'}) eq 'HASH') {
1395: if (defined($designs->{'showlogo'}{$img})) {
1396: if ($designs->{'showlogo'}{$img} == 0) {
1397: $checkedon = '';
1398: } elsif ($designs->{'showlogo'}{$img} == 1) {
1399: $checkedon = 'checked="checked" ';
1400: }
1401: }
1402: }
1403: }
1404: return '<br /><label> <input type="checkbox" name="'.
1405: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1406: &mt('show').'</label>'."\n";
1407: }
1408:
1.41 raeburn 1409: sub login_header_options {
1.135 bisitz 1410: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1411: my $output = '';
1.41 raeburn 1412: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1413: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1414: if (!$is_custom->{'textcol'}) {
1415: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1416: ' ';
1417: }
1418: if (!$is_custom->{'bgcol'}) {
1419: $output .= $choices->{'bgcol'}.': '.
1420: '<span id="css_'.$role.'_font" style="background-color: '.
1421: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1422: }
1423: $output .= '<br />';
1424: }
1425: $output .='<br />';
1426: return $output;
1427: }
1428:
1429: sub login_text_colors {
1430: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1431: my $color_menu = '<table border="0"><tr>';
1432: foreach my $item (@{$logintext}) {
1433: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1434: $color_menu .= '<td align="center">'.$link;
1435: if ($designs->{'logintext'}{$item}) {
1436: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1437: }
1438: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1439: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1440: '<td> </td>';
1441: }
1442: $color_menu .= '</tr></table><br />';
1443: return $color_menu;
1444: }
1445:
1446: sub image_changes {
1447: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1448: my $output;
1.135 bisitz 1449: if ($img eq 'login') {
1450: # suppress image for Log-in header
1451: } elsif (!$is_custom) {
1.70 raeburn 1452: if ($img ne 'domlogo') {
1.41 raeburn 1453: $output .= &mt('Default image:').'<br />';
1454: } else {
1455: $output .= &mt('Default in use:').'<br />';
1456: }
1457: }
1.135 bisitz 1458: if ($img eq 'login') { # suppress image for Log-in header
1459: $output .= '<td>'.$logincolors;
1.41 raeburn 1460: } else {
1.135 bisitz 1461: if ($img_import) {
1462: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1463: }
1464: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1465: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1466: if ($is_custom) {
1467: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1468: '<input type="checkbox" name="'.
1469: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1470: '</label> '.&mt('Replace:').'</span><br />';
1471: } else {
1472: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1473: }
1.41 raeburn 1474: }
1475: return $output;
1476: }
1477:
1.6 raeburn 1478: sub color_pick {
1479: my ($phase,$role,$item,$desc,$curcol) = @_;
1480: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1481: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1482: ');">'.$desc.'</a>';
1483: return $link;
1484: }
1485:
1.3 raeburn 1486: sub print_quotas {
1.86 raeburn 1487: my ($dom,$settings,$rowtotal,$action) = @_;
1488: my $context;
1489: if ($action eq 'quotas') {
1490: $context = 'tools';
1491: } else {
1492: $context = $action;
1493: }
1.101 raeburn 1494: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1495: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1496: my $typecount = 0;
1.101 raeburn 1497: my ($css_class,%titles);
1.86 raeburn 1498: if ($context eq 'requestcourses') {
1.98 raeburn 1499: @usertools = ('official','unofficial','community');
1.106 raeburn 1500: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1501: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1502: %titles = &courserequest_titles();
1.160.6.5 raeburn 1503: } elsif ($context eq 'requestauthor') {
1504: @usertools = ('author');
1505: @options = ('norequest','approval','automatic');
1506: %titles = &authorrequest_titles();
1.86 raeburn 1507: } else {
1.160.6.4 raeburn 1508: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1509: %titles = &tool_titles();
1.86 raeburn 1510: }
1.26 raeburn 1511: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1512: foreach my $type (@{$types}) {
1.72 raeburn 1513: my $currdefquota;
1.160.6.5 raeburn 1514: unless (($context eq 'requestcourses') ||
1515: ($context eq 'requestauthor')) {
1.86 raeburn 1516: if (ref($settings) eq 'HASH') {
1517: if (ref($settings->{defaultquota}) eq 'HASH') {
1518: $currdefquota = $settings->{defaultquota}->{$type};
1519: } else {
1520: $currdefquota = $settings->{$type};
1521: }
1.78 raeburn 1522: }
1.72 raeburn 1523: }
1.3 raeburn 1524: if (defined($usertypes->{$type})) {
1525: $typecount ++;
1526: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1527: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1528: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1529: '<td class="LC_left_item">';
1.101 raeburn 1530: if ($context eq 'requestcourses') {
1531: $datatable .= '<table><tr>';
1532: }
1533: my %cell;
1.72 raeburn 1534: foreach my $item (@usertools) {
1.101 raeburn 1535: if ($context eq 'requestcourses') {
1536: my ($curroption,$currlimit);
1537: if (ref($settings) eq 'HASH') {
1538: if (ref($settings->{$item}) eq 'HASH') {
1539: $curroption = $settings->{$item}->{$type};
1540: if ($curroption =~ /^autolimit=(\d*)$/) {
1541: $currlimit = $1;
1542: }
1543: }
1544: }
1545: if (!$curroption) {
1546: $curroption = 'norequest';
1547: }
1548: $datatable .= '<th>'.$titles{$item}.'</th>';
1549: foreach my $option (@options) {
1550: my $val = $option;
1551: if ($option eq 'norequest') {
1552: $val = 0;
1553: }
1554: if ($option eq 'validate') {
1555: my $canvalidate = 0;
1556: if (ref($validations{$item}) eq 'HASH') {
1557: if ($validations{$item}{$type}) {
1558: $canvalidate = 1;
1559: }
1560: }
1561: next if (!$canvalidate);
1562: }
1563: my $checked = '';
1564: if ($option eq $curroption) {
1565: $checked = ' checked="checked"';
1566: } elsif ($option eq 'autolimit') {
1567: if ($curroption =~ /^autolimit/) {
1568: $checked = ' checked="checked"';
1569: }
1570: }
1571: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1572: '<input type="radio" name="crsreq_'.$item.
1573: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1574: $titles{$option}.'</label>';
1.101 raeburn 1575: if ($option eq 'autolimit') {
1.127 raeburn 1576: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1577: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1578: 'value="'.$currlimit.'" />';
1.101 raeburn 1579: }
1.127 raeburn 1580: $cell{$item} .= '</span> ';
1.103 raeburn 1581: if ($option eq 'autolimit') {
1.127 raeburn 1582: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1583: }
1.101 raeburn 1584: }
1.160.6.5 raeburn 1585: } elsif ($context eq 'requestauthor') {
1586: my $curroption;
1587: if (ref($settings) eq 'HASH') {
1588: $curroption = $settings->{$type};
1589: }
1590: if (!$curroption) {
1591: $curroption = 'norequest';
1592: }
1593: foreach my $option (@options) {
1594: my $val = $option;
1595: if ($option eq 'norequest') {
1596: $val = 0;
1597: }
1598: my $checked = '';
1599: if ($option eq $curroption) {
1600: $checked = ' checked="checked"';
1601: }
1602: $datatable .= '<span class="LC_nobreak"><label>'.
1603: '<input type="radio" name="authorreq_'.$type.
1604: '" value="'.$val.'"'.$checked.' />'.
1605: $titles{$option}.'</label></span> ';
1606: }
1.101 raeburn 1607: } else {
1608: my $checked = 'checked="checked" ';
1609: if (ref($settings) eq 'HASH') {
1610: if (ref($settings->{$item}) eq 'HASH') {
1611: if ($settings->{$item}->{$type} == 0) {
1612: $checked = '';
1613: } elsif ($settings->{$item}->{$type} == 1) {
1614: $checked = 'checked="checked" ';
1615: }
1.78 raeburn 1616: }
1.72 raeburn 1617: }
1.101 raeburn 1618: $datatable .= '<span class="LC_nobreak"><label>'.
1619: '<input type="checkbox" name="'.$context.'_'.$item.
1620: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1621: '</label></span> ';
1.72 raeburn 1622: }
1.101 raeburn 1623: }
1624: if ($context eq 'requestcourses') {
1625: $datatable .= '</tr><tr>';
1626: foreach my $item (@usertools) {
1.106 raeburn 1627: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1628: }
1629: $datatable .= '</tr></table>';
1.72 raeburn 1630: }
1.86 raeburn 1631: $datatable .= '</td>';
1.160.6.5 raeburn 1632: unless (($context eq 'requestcourses') ||
1633: ($context eq 'requestauthor')) {
1.86 raeburn 1634: $datatable .=
1635: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1636: '<input type="text" name="quota_'.$type.
1.72 raeburn 1637: '" value="'.$currdefquota.
1.86 raeburn 1638: '" size="5" /> Mb</span></td>';
1639: }
1640: $datatable .= '</tr>';
1.3 raeburn 1641: }
1642: }
1643: }
1.160.6.5 raeburn 1644: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1645: $defaultquota = '20';
1646: if (ref($settings) eq 'HASH') {
1647: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1648: $defaultquota = $settings->{'defaultquota'}->{'default'};
1649: } elsif (defined($settings->{'default'})) {
1650: $defaultquota = $settings->{'default'};
1651: }
1.3 raeburn 1652: }
1653: }
1654: $typecount ++;
1655: $css_class = $typecount%2?' class="LC_odd_row"':'';
1656: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1657: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1658: '<td class="LC_left_item">';
1.101 raeburn 1659: if ($context eq 'requestcourses') {
1660: $datatable .= '<table><tr>';
1661: }
1662: my %defcell;
1.72 raeburn 1663: foreach my $item (@usertools) {
1.101 raeburn 1664: if ($context eq 'requestcourses') {
1665: my ($curroption,$currlimit);
1666: if (ref($settings) eq 'HASH') {
1667: if (ref($settings->{$item}) eq 'HASH') {
1668: $curroption = $settings->{$item}->{'default'};
1669: if ($curroption =~ /^autolimit=(\d*)$/) {
1670: $currlimit = $1;
1671: }
1672: }
1673: }
1674: if (!$curroption) {
1675: $curroption = 'norequest';
1676: }
1677: $datatable .= '<th>'.$titles{$item}.'</th>';
1678: foreach my $option (@options) {
1679: my $val = $option;
1680: if ($option eq 'norequest') {
1681: $val = 0;
1682: }
1683: if ($option eq 'validate') {
1684: my $canvalidate = 0;
1685: if (ref($validations{$item}) eq 'HASH') {
1686: if ($validations{$item}{'default'}) {
1687: $canvalidate = 1;
1688: }
1689: }
1690: next if (!$canvalidate);
1691: }
1692: my $checked = '';
1693: if ($option eq $curroption) {
1694: $checked = ' checked="checked"';
1695: } elsif ($option eq 'autolimit') {
1696: if ($curroption =~ /^autolimit/) {
1697: $checked = ' checked="checked"';
1698: }
1699: }
1700: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1701: '<input type="radio" name="crsreq_'.$item.
1702: '_default" value="'.$val.'"'.$checked.' />'.
1703: $titles{$option}.'</label>';
1704: if ($option eq 'autolimit') {
1.127 raeburn 1705: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1706: $item.'_limit_default" size="1" '.
1707: 'value="'.$currlimit.'" />';
1708: }
1.127 raeburn 1709: $defcell{$item} .= '</span> ';
1.104 raeburn 1710: if ($option eq 'autolimit') {
1.127 raeburn 1711: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1712: }
1.101 raeburn 1713: }
1.160.6.5 raeburn 1714: } elsif ($context eq 'requestauthor') {
1715: my $curroption;
1716: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1717: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1718: }
1719: if (!$curroption) {
1720: $curroption = 'norequest';
1721: }
1722: foreach my $option (@options) {
1723: my $val = $option;
1724: if ($option eq 'norequest') {
1725: $val = 0;
1726: }
1727: my $checked = '';
1728: if ($option eq $curroption) {
1729: $checked = ' checked="checked"';
1730: }
1731: $datatable .= '<span class="LC_nobreak"><label>'.
1732: '<input type="radio" name="authorreq_default"'.
1733: ' value="'.$val.'"'.$checked.' />'.
1734: $titles{$option}.'</label></span> ';
1735: }
1.101 raeburn 1736: } else {
1737: my $checked = 'checked="checked" ';
1738: if (ref($settings) eq 'HASH') {
1739: if (ref($settings->{$item}) eq 'HASH') {
1740: if ($settings->{$item}->{'default'} == 0) {
1741: $checked = '';
1742: } elsif ($settings->{$item}->{'default'} == 1) {
1743: $checked = 'checked="checked" ';
1744: }
1.78 raeburn 1745: }
1.72 raeburn 1746: }
1.101 raeburn 1747: $datatable .= '<span class="LC_nobreak"><label>'.
1748: '<input type="checkbox" name="'.$context.'_'.$item.
1749: '" value="default" '.$checked.'/>'.$titles{$item}.
1750: '</label></span> ';
1751: }
1752: }
1753: if ($context eq 'requestcourses') {
1754: $datatable .= '</tr><tr>';
1755: foreach my $item (@usertools) {
1.106 raeburn 1756: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1757: }
1.101 raeburn 1758: $datatable .= '</tr></table>';
1.72 raeburn 1759: }
1.86 raeburn 1760: $datatable .= '</td>';
1.160.6.5 raeburn 1761: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1762: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1763: '<input type="text" name="defaultquota" value="'.
1764: $defaultquota.'" size="5" /> Mb</span></td>';
1765: }
1766: $datatable .= '</tr>';
1.72 raeburn 1767: $typecount ++;
1768: $css_class = $typecount%2?' class="LC_odd_row"':'';
1769: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1770: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1771: if ($context eq 'requestcourses') {
1.109 raeburn 1772: $datatable .= &mt('(overrides affiliation, if set)').
1773: '</td>'.
1774: '<td class="LC_left_item">'.
1775: '<table><tr>';
1.101 raeburn 1776: } else {
1.109 raeburn 1777: $datatable .= &mt('(overrides affiliation, if checked)').
1778: '</td>'.
1779: '<td class="LC_left_item" colspan="2">'.
1780: '<br />';
1.101 raeburn 1781: }
1782: my %advcell;
1.72 raeburn 1783: foreach my $item (@usertools) {
1.101 raeburn 1784: if ($context eq 'requestcourses') {
1785: my ($curroption,$currlimit);
1786: if (ref($settings) eq 'HASH') {
1787: if (ref($settings->{$item}) eq 'HASH') {
1788: $curroption = $settings->{$item}->{'_LC_adv'};
1789: if ($curroption =~ /^autolimit=(\d*)$/) {
1790: $currlimit = $1;
1791: }
1792: }
1793: }
1794: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1795: my $checked = '';
1796: if ($curroption eq '') {
1797: $checked = ' checked="checked"';
1798: }
1799: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1800: '<input type="radio" name="crsreq_'.$item.
1801: '__LC_adv" value=""'.$checked.' />'.
1802: &mt('No override set').'</label></span> ';
1.101 raeburn 1803: foreach my $option (@options) {
1804: my $val = $option;
1805: if ($option eq 'norequest') {
1806: $val = 0;
1807: }
1808: if ($option eq 'validate') {
1809: my $canvalidate = 0;
1810: if (ref($validations{$item}) eq 'HASH') {
1811: if ($validations{$item}{'_LC_adv'}) {
1812: $canvalidate = 1;
1813: }
1814: }
1815: next if (!$canvalidate);
1816: }
1817: my $checked = '';
1.104 raeburn 1818: if ($val eq $curroption) {
1.101 raeburn 1819: $checked = ' checked="checked"';
1820: } elsif ($option eq 'autolimit') {
1821: if ($curroption =~ /^autolimit/) {
1822: $checked = ' checked="checked"';
1823: }
1824: }
1825: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1826: '<input type="radio" name="crsreq_'.$item.
1827: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1828: $titles{$option}.'</label>';
1829: if ($option eq 'autolimit') {
1.127 raeburn 1830: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1831: $item.'_limit__LC_adv" size="1" '.
1832: 'value="'.$currlimit.'" />';
1833: }
1.127 raeburn 1834: $advcell{$item} .= '</span> ';
1.104 raeburn 1835: if ($option eq 'autolimit') {
1.127 raeburn 1836: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1837: }
1.101 raeburn 1838: }
1.160.6.5 raeburn 1839: } elsif ($context eq 'requestauthor') {
1840: my $curroption;
1841: if (ref($settings) eq 'HASH') {
1842: $curroption = $settings->{'_LC_adv'};
1843: }
1844: my $checked = '';
1845: if ($curroption eq '') {
1846: $checked = ' checked="checked"';
1847: }
1848: $datatable .= '<span class="LC_nobreak"><label>'.
1849: '<input type="radio" name="authorreq__LC_adv"'.
1850: ' value=""'.$checked.' />'.
1851: &mt('No override set').'</label></span> ';
1852: foreach my $option (@options) {
1853: my $val = $option;
1854: if ($option eq 'norequest') {
1855: $val = 0;
1856: }
1857: my $checked = '';
1858: if ($val eq $curroption) {
1859: $checked = ' checked="checked"';
1860: }
1861: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1862: '<input type="radio" name="authorreq__LC_adv"'.
1863: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1864: $titles{$option}.'</label></span> ';
1865: }
1.101 raeburn 1866: } else {
1867: my $checked = 'checked="checked" ';
1868: if (ref($settings) eq 'HASH') {
1869: if (ref($settings->{$item}) eq 'HASH') {
1870: if ($settings->{$item}->{'_LC_adv'} == 0) {
1871: $checked = '';
1872: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1873: $checked = 'checked="checked" ';
1874: }
1.79 raeburn 1875: }
1.72 raeburn 1876: }
1.101 raeburn 1877: $datatable .= '<span class="LC_nobreak"><label>'.
1878: '<input type="checkbox" name="'.$context.'_'.$item.
1879: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1880: '</label></span> ';
1881: }
1882: }
1883: if ($context eq 'requestcourses') {
1884: $datatable .= '</tr><tr>';
1885: foreach my $item (@usertools) {
1.106 raeburn 1886: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1887: }
1.101 raeburn 1888: $datatable .= '</tr></table>';
1.72 raeburn 1889: }
1.98 raeburn 1890: $datatable .= '</td></tr>';
1.30 raeburn 1891: $$rowtotal += $typecount;
1.3 raeburn 1892: return $datatable;
1893: }
1894:
1.160.6.5 raeburn 1895: sub print_requestmail {
1896: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1897: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1898: $now = time;
1899: $rows = 0;
1900: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1901: foreach my $server (keys(%dompersonnel)) {
1902: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1903: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1904: if (!grep(/^$uname:$udom$/,@domcoord)) {
1905: push(@domcoord,$uname.':'.$udom);
1906: }
1907: }
1908: }
1909: if (ref($settings) eq 'HASH') {
1910: if (ref($settings->{'notify'}) eq 'HASH') {
1911: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1912: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1913: }
1914: }
1915: }
1.104 raeburn 1916: if (@currapproval) {
1917: foreach my $dc (@currapproval) {
1.102 raeburn 1918: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1919: push(@domcoord,$dc);
1920: }
1921: }
1922: }
1923: @domcoord = sort(@domcoord);
1924: my $numinrow = 4;
1925: my $numdc = @domcoord;
1926: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1927: my $text;
1928: if ($action eq 'requestcourses') {
1929: $text = &mt('Receive notification of course requests requiring approval');
1930: } else {
1931: $text = &mt('Receive notification of authoring space requests requiring approval')
1932: }
1933: $datatable = '<tr '.$css_class.'>'.
1934: ' <td>'.$text.'</td>'.
1.102 raeburn 1935: ' <td class="LC_left_item">';
1936: if (@domcoord > 0) {
1937: $datatable .= '<table>';
1938: for (my $i=0; $i<$numdc; $i++) {
1939: my $rem = $i%($numinrow);
1940: if ($rem == 0) {
1941: if ($i > 0) {
1942: $datatable .= '</tr>';
1943: }
1944: $datatable .= '<tr>';
1945: $rows ++;
1946: }
1947: my $check = ' ';
1.104 raeburn 1948: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1949: $check = ' checked="checked" ';
1950: }
1951: my ($uname,$udom) = split(':',$domcoord[$i]);
1952: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1953: if ($i == $numdc-1) {
1954: my $colsleft = $numinrow-$rem;
1955: if ($colsleft > 1) {
1956: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1957: } else {
1958: $datatable .= '<td class="LC_left_item">';
1959: }
1960: } else {
1961: $datatable .= '<td class="LC_left_item">';
1962: }
1963: $datatable .= '<span class="LC_nobreak"><label>'.
1964: '<input type="checkbox" name="reqapprovalnotify" '.
1965: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1966: $fullname.'</label></span></td>';
1967: }
1968: $datatable .= '</tr></table>';
1969: } else {
1970: $datatable .= &mt('There are no active Domain Coordinators');
1971: $rows ++;
1972: }
1973: $datatable .='</td></tr>';
1974: $$rowtotal += $rows;
1975: return $datatable;
1976: }
1977:
1.3 raeburn 1978: sub print_autoenroll {
1.30 raeburn 1979: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1980: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1981: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1982: if (ref($settings) eq 'HASH') {
1983: if (exists($settings->{'run'})) {
1984: if ($settings->{'run'} eq '0') {
1985: $runoff = ' checked="checked" ';
1986: $runon = ' ';
1987: } else {
1988: $runon = ' checked="checked" ';
1989: $runoff = ' ';
1990: }
1991: } else {
1992: if ($autorun) {
1993: $runon = ' checked="checked" ';
1994: $runoff = ' ';
1995: } else {
1996: $runoff = ' checked="checked" ';
1997: $runon = ' ';
1998: }
1999: }
1.129 raeburn 2000: if (exists($settings->{'co-owners'})) {
2001: if ($settings->{'co-owners'} eq '0') {
2002: $coownersoff = ' checked="checked" ';
2003: $coownerson = ' ';
2004: } else {
2005: $coownerson = ' checked="checked" ';
2006: $coownersoff = ' ';
2007: }
2008: } else {
2009: $coownersoff = ' checked="checked" ';
2010: $coownerson = ' ';
2011: }
1.3 raeburn 2012: if (exists($settings->{'sender_domain'})) {
2013: $defdom = $settings->{'sender_domain'};
2014: }
1.14 raeburn 2015: } else {
2016: if ($autorun) {
2017: $runon = ' checked="checked" ';
2018: $runoff = ' ';
2019: } else {
2020: $runoff = ' checked="checked" ';
2021: $runon = ' ';
2022: }
1.3 raeburn 2023: }
2024: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2025: my $notif_sender;
2026: if (ref($settings) eq 'HASH') {
2027: $notif_sender = $settings->{'sender_uname'};
2028: }
1.3 raeburn 2029: my $datatable='<tr class="LC_odd_row">'.
2030: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2031: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2032: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2033: $runon.' value="1" />'.&mt('Yes').'</label> '.
2034: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2035: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2036: '</tr><tr>'.
2037: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2038: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2039: &mt('username').': '.
2040: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2041: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2042: ': '.$domform.'</span></td></tr>'.
2043: '<tr class="LC_odd_row">'.
2044: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2045: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2046: '<input type="radio" name="autoassign_coowners"'.
2047: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2048: '<label><input type="radio" name="autoassign_coowners"'.
2049: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2050: '</tr>';
2051: $$rowtotal += 3;
1.3 raeburn 2052: return $datatable;
2053: }
2054:
2055: sub print_autoupdate {
1.30 raeburn 2056: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2057: my $datatable;
2058: if ($position eq 'top') {
2059: my $updateon = ' ';
2060: my $updateoff = ' checked="checked" ';
2061: my $classlistson = ' ';
2062: my $classlistsoff = ' checked="checked" ';
2063: if (ref($settings) eq 'HASH') {
2064: if ($settings->{'run'} eq '1') {
2065: $updateon = $updateoff;
2066: $updateoff = ' ';
2067: }
2068: if ($settings->{'classlists'} eq '1') {
2069: $classlistson = $classlistsoff;
2070: $classlistsoff = ' ';
2071: }
2072: }
2073: my %title = (
2074: run => 'Auto-update active?',
2075: classlists => 'Update information in classlists?',
2076: );
2077: $datatable = '<tr class="LC_odd_row">'.
2078: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2079: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2080: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2081: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2082: '<label><input type="radio" name="autoupdate_run"'.
2083: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2084: '</tr><tr>'.
2085: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2086: '<td class="LC_right_item"><span class="LC_nobreak">'.
2087: '<label><input type="radio" name="classlists"'.
2088: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2089: '<label><input type="radio" name="classlists"'.
2090: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2091: '</tr>';
1.30 raeburn 2092: $$rowtotal += 2;
1.131 raeburn 2093: } elsif ($position eq 'middle') {
2094: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2095: my $numinrow = 3;
2096: my $locknamesettings;
2097: $datatable .= &insttypes_row($settings,$types,$usertypes,
2098: $dom,$numinrow,$othertitle,
2099: 'lockablenames');
2100: $$rowtotal ++;
1.3 raeburn 2101: } else {
1.44 raeburn 2102: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2103: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2104: 'permanentemail','id');
1.33 raeburn 2105: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2106: my $numrows = 0;
1.26 raeburn 2107: if (ref($types) eq 'ARRAY') {
2108: if (@{$types} > 0) {
2109: $datatable =
2110: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2111: \@fields,$types,\$numrows);
1.30 raeburn 2112: $$rowtotal += @{$types};
1.26 raeburn 2113: }
1.3 raeburn 2114: }
2115: $datatable .=
2116: &usertype_update_row($settings,{'default' => $othertitle},
2117: \%fieldtitles,\@fields,['default'],
2118: \$numrows);
1.30 raeburn 2119: $$rowtotal ++;
1.3 raeburn 2120: }
2121: return $datatable;
2122: }
2123:
1.125 raeburn 2124: sub print_autocreate {
2125: my ($dom,$settings,$rowtotal) = @_;
2126: my (%createon,%createoff);
2127: my $curr_dc;
2128: my @types = ('xml','req');
2129: if (ref($settings) eq 'HASH') {
2130: foreach my $item (@types) {
2131: $createoff{$item} = ' checked="checked" ';
2132: $createon{$item} = ' ';
2133: if (exists($settings->{$item})) {
2134: if ($settings->{$item}) {
2135: $createon{$item} = ' checked="checked" ';
2136: $createoff{$item} = ' ';
2137: }
2138: }
2139: }
2140: $curr_dc = $settings->{'xmldc'};
2141: } else {
2142: foreach my $item (@types) {
2143: $createoff{$item} = ' checked="checked" ';
2144: $createon{$item} = ' ';
2145: }
2146: }
2147: $$rowtotal += 2;
2148: my $datatable='<tr class="LC_odd_row">'.
2149: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2150: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2151: '<input type="radio" name="autocreate_xml"'.
2152: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2153: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2154: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2155: '</td></tr><tr>'.
2156: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2157: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2158: '<input type="radio" name="autocreate_req"'.
2159: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2160: '<label><input type="radio" name="autocreate_req"'.
2161: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2162: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2163: if ($numdc > 1) {
1.143 raeburn 2164: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2165: &mt('Course creation processed as: (choose Dom. Coord.)').
2166: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2167: $$rowtotal ++ ;
2168: } else {
1.143 raeburn 2169: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2170: }
2171: return $datatable;
2172: }
2173:
1.23 raeburn 2174: sub print_directorysrch {
1.30 raeburn 2175: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2176: my $srchon = ' ';
2177: my $srchoff = ' checked="checked" ';
1.25 raeburn 2178: my ($exacton,$containson,$beginson);
1.24 raeburn 2179: my $localon = ' ';
2180: my $localoff = ' checked="checked" ';
1.23 raeburn 2181: if (ref($settings) eq 'HASH') {
2182: if ($settings->{'available'} eq '1') {
2183: $srchon = $srchoff;
2184: $srchoff = ' ';
2185: }
1.24 raeburn 2186: if ($settings->{'localonly'} eq '1') {
2187: $localon = $localoff;
2188: $localoff = ' ';
2189: }
1.25 raeburn 2190: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2191: foreach my $type (@{$settings->{'searchtypes'}}) {
2192: if ($type eq 'exact') {
2193: $exacton = ' checked="checked" ';
2194: } elsif ($type eq 'contains') {
2195: $containson = ' checked="checked" ';
2196: } elsif ($type eq 'begins') {
2197: $beginson = ' checked="checked" ';
2198: }
2199: }
2200: } else {
2201: if ($settings->{'searchtypes'} eq 'exact') {
2202: $exacton = ' checked="checked" ';
2203: } elsif ($settings->{'searchtypes'} eq 'contains') {
2204: $containson = ' checked="checked" ';
2205: } elsif ($settings->{'searchtypes'} eq 'specify') {
2206: $exacton = ' checked="checked" ';
2207: $containson = ' checked="checked" ';
2208: }
1.23 raeburn 2209: }
2210: }
2211: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2212: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2213:
2214: my $numinrow = 4;
1.26 raeburn 2215: my $cansrchrow = 0;
1.23 raeburn 2216: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2217: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2218: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2219: '<input type="radio" name="dirsrch_available"'.
2220: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2221: '<label><input type="radio" name="dirsrch_available"'.
2222: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2223: '</tr><tr>'.
1.30 raeburn 2224: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2225: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2226: '<input type="radio" name="dirsrch_localonly"'.
2227: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2228: '<label><input type="radio" name="dirsrch_localonly"'.
2229: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2230: '</tr>';
1.30 raeburn 2231: $$rowtotal += 2;
1.26 raeburn 2232: if (ref($usertypes) eq 'HASH') {
2233: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2234: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2235: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2236: $cansrchrow = 1;
2237: }
2238: }
2239: if ($cansrchrow) {
1.30 raeburn 2240: $$rowtotal ++;
1.26 raeburn 2241: $datatable .= '<tr>';
2242: } else {
2243: $datatable .= '<tr class="LC_odd_row">';
2244: }
1.30 raeburn 2245: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2246: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2247: foreach my $title (@{$titleorder}) {
2248: if (defined($searchtitles->{$title})) {
2249: my $check = ' ';
1.93 raeburn 2250: if (ref($settings) eq 'HASH') {
1.39 raeburn 2251: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2252: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2253: $check = ' checked="checked" ';
2254: }
1.25 raeburn 2255: }
2256: }
2257: $datatable .= '<td class="LC_left_item">'.
2258: '<span class="LC_nobreak"><label>'.
2259: '<input type="checkbox" name="searchby" '.
2260: 'value="'.$title.'"'.$check.'/>'.
2261: $searchtitles->{$title}.'</label></span></td>';
2262: }
2263: }
1.26 raeburn 2264: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2265: $$rowtotal ++;
1.26 raeburn 2266: if ($cansrchrow) {
2267: $datatable .= '<tr class="LC_odd_row">';
2268: } else {
2269: $datatable .= '<tr>';
2270: }
1.30 raeburn 2271: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2272: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2273: '<span class="LC_nobreak"><label>'.
2274: '<input type="checkbox" name="searchtypes" '.
2275: $exacton.' value="exact" />'.&mt('Exact match').
2276: '</label> '.
2277: '<label><input type="checkbox" name="searchtypes" '.
2278: $beginson.' value="begins" />'.&mt('Begins with').
2279: '</label> '.
2280: '<label><input type="checkbox" name="searchtypes" '.
2281: $containson.' value="contains" />'.&mt('Contains').
2282: '</label></span></td></tr>';
1.30 raeburn 2283: $$rowtotal ++;
1.25 raeburn 2284: return $datatable;
2285: }
2286:
1.28 raeburn 2287: sub print_contacts {
1.30 raeburn 2288: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2289: my $datatable;
2290: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2291: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2292: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2293: 'requestsmail');
1.28 raeburn 2294: foreach my $type (@mailings) {
2295: $otheremails{$type} = '';
2296: }
1.134 raeburn 2297: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2298: if (ref($settings) eq 'HASH') {
2299: foreach my $item (@contacts) {
2300: if (exists($settings->{$item})) {
2301: $to{$item} = $settings->{$item};
2302: }
2303: }
2304: foreach my $type (@mailings) {
2305: if (exists($settings->{$type})) {
2306: if (ref($settings->{$type}) eq 'HASH') {
2307: foreach my $item (@contacts) {
2308: if ($settings->{$type}{$item}) {
2309: $checked{$type}{$item} = ' checked="checked" ';
2310: }
2311: }
2312: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2313: if ($type eq 'helpdeskmail') {
2314: $bccemails{$type} = $settings->{$type}{'bcc'};
2315: }
1.28 raeburn 2316: }
1.89 raeburn 2317: } elsif ($type eq 'lonstatusmail') {
2318: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2319: }
2320: }
2321: } else {
2322: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2323: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2324: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2325: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2326: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2327: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2328: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2329: }
2330: my ($titles,$short_titles) = &contact_titles();
2331: my $rownum = 0;
2332: my $css_class;
2333: foreach my $item (@contacts) {
1.69 raeburn 2334: $rownum ++;
2335: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2336: $datatable .= '<tr'.$css_class.'>'.
2337: '<td><span class="LC_nobreak">'.$titles->{$item}.
2338: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2339: '<input type="text" name="'.$item.'" value="'.
2340: $to{$item}.'" /></td></tr>';
2341: }
2342: foreach my $type (@mailings) {
1.69 raeburn 2343: $rownum ++;
2344: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2345: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2346: '<td><span class="LC_nobreak">'.
2347: $titles->{$type}.': </span></td>'.
1.28 raeburn 2348: '<td class="LC_left_item">'.
2349: '<span class="LC_nobreak">';
2350: foreach my $item (@contacts) {
2351: $datatable .= '<label>'.
2352: '<input type="checkbox" name="'.$type.'"'.
2353: $checked{$type}{$item}.
2354: ' value="'.$item.'" />'.$short_titles->{$item}.
2355: '</label> ';
2356: }
2357: $datatable .= '</span><br />'.&mt('Others').': '.
2358: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2359: 'value="'.$otheremails{$type}.'" />';
2360: if ($type eq 'helpdeskmail') {
1.136 raeburn 2361: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2362: '<input type="text" name="'.$type.'_bcc" '.
2363: 'value="'.$bccemails{$type}.'" />';
2364: }
2365: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2366: }
1.30 raeburn 2367: $$rowtotal += $rownum;
1.28 raeburn 2368: return $datatable;
2369: }
2370:
1.118 jms 2371: sub print_helpsettings {
1.160.6.5 raeburn 2372: my ($dom,$confname,$settings,$rowtotal) = @_;
2373: my ($datatable,$itemcount);
2374: $itemcount = 1;
2375: my (%choices,%defaultchecked,@toggles);
2376: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2377: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2378: &mt('LON-CAPA bug tracker'),600,500));
2379: %defaultchecked = ('submitbugs' => 'on');
2380: @toggles = ('submitbugs',);
1.122 jms 2381:
1.160.6.5 raeburn 2382: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2383: \%choices,$itemcount);
2384: return $datatable;
1.121 raeburn 2385: }
2386:
2387: sub radiobutton_prefs {
2388: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2389: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2390: (ref($choices) eq 'HASH'));
2391:
2392: my (%checkedon,%checkedoff,$datatable,$css_class);
2393:
2394: foreach my $item (@{$toggles}) {
2395: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2396: $checkedon{$item} = ' checked="checked" ';
2397: $checkedoff{$item} = ' ';
1.121 raeburn 2398: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2399: $checkedoff{$item} = ' checked="checked" ';
2400: $checkedon{$item} = ' ';
2401: }
2402: }
2403: if (ref($settings) eq 'HASH') {
1.121 raeburn 2404: foreach my $item (@{$toggles}) {
1.118 jms 2405: if ($settings->{$item} eq '1') {
2406: $checkedon{$item} = ' checked="checked" ';
2407: $checkedoff{$item} = ' ';
2408: } elsif ($settings->{$item} eq '0') {
2409: $checkedoff{$item} = ' checked="checked" ';
2410: $checkedon{$item} = ' ';
2411: }
2412: }
1.121 raeburn 2413: }
2414: foreach my $item (@{$toggles}) {
1.118 jms 2415: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2416: $datatable .=
2417: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2418: '</span></td>'.
2419: '<td class="LC_right_item"><span class="LC_nobreak">'.
2420: '<label><input type="radio" name="'.
2421: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2422: '</label> <label><input type="radio" name="'.$item.'" '.
2423: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2424: '</span></td>'.
2425: '</tr>';
2426: $itemcount ++;
1.121 raeburn 2427: }
2428: return ($datatable,$itemcount);
2429: }
2430:
2431: sub print_coursedefaults {
1.139 raeburn 2432: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2433: my ($css_class,$datatable);
2434: my $itemcount = 1;
1.139 raeburn 2435: if ($position eq 'top') {
2436: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2437: %choices =
2438: &Apache::lonlocal::texthash (
2439: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2440: );
2441: %defaultchecked = ('canuse_pdfforms' => 'off');
2442: @toggles = ('canuse_pdfforms',);
2443: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2444: \%choices,$itemcount);
1.139 raeburn 2445: $$rowtotal += $itemcount;
2446: } else {
2447: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2448: my %choices =
2449: &Apache::lonlocal::texthash (
2450: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2451: );
2452: my $currdefresponder;
2453: if (ref($settings) eq 'HASH') {
2454: $currdefresponder = $settings->{'anonsurvey_threshold'};
2455: }
2456: if (!$currdefresponder) {
2457: $currdefresponder = 10;
2458: } elsif ($currdefresponder < 1) {
2459: $currdefresponder = 1;
2460: }
2461: $datatable .=
2462: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2463: '</span></td>'.
2464: '<td class="LC_right_item"><span class="LC_nobreak">'.
2465: '<input type="text" name="anonsurvey_threshold"'.
2466: ' value="'.$currdefresponder.'" size="5" /></span>'.
2467: '</td></tr>';
2468: }
1.121 raeburn 2469: return $datatable;
1.118 jms 2470: }
2471:
1.137 raeburn 2472: sub print_usersessions {
2473: my ($position,$dom,$settings,$rowtotal) = @_;
2474: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2475: my (%by_ip,%by_location,@intdoms);
2476: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2477:
2478: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2479: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2480: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2481: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2482: my $itemcount = 1;
2483: if ($position eq 'top') {
1.152 raeburn 2484: if (keys(%serverhomes) > 1) {
1.145 raeburn 2485: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2486: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2487: } else {
1.140 raeburn 2488: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2489: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2490: }
1.137 raeburn 2491: } else {
1.145 raeburn 2492: if (keys(%by_location) == 0) {
2493: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2494: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2495: } else {
2496: my %lt = &usersession_titles();
2497: my $numinrow = 5;
2498: my $prefix;
2499: my @types;
2500: if ($position eq 'bottom') {
2501: $prefix = 'remote';
2502: @types = ('version','excludedomain','includedomain');
2503: } else {
2504: $prefix = 'hosted';
2505: @types = ('excludedomain','includedomain');
2506: }
2507: my (%current,%checkedon,%checkedoff);
2508: my @lcversions = &Apache::lonnet::all_loncaparevs();
2509: my @locations = sort(keys(%by_location));
2510: foreach my $type (@types) {
2511: $checkedon{$type} = '';
2512: $checkedoff{$type} = ' checked="checked"';
2513: }
2514: if (ref($settings) eq 'HASH') {
2515: if (ref($settings->{$prefix}) eq 'HASH') {
2516: foreach my $key (keys(%{$settings->{$prefix}})) {
2517: $current{$key} = $settings->{$prefix}{$key};
2518: if ($key eq 'version') {
2519: if ($current{$key} ne '') {
2520: $checkedon{$key} = ' checked="checked"';
2521: $checkedoff{$key} = '';
2522: }
2523: } elsif (ref($current{$key}) eq 'ARRAY') {
2524: $checkedon{$key} = ' checked="checked"';
2525: $checkedoff{$key} = '';
2526: }
1.137 raeburn 2527: }
2528: }
2529: }
1.145 raeburn 2530: foreach my $type (@types) {
2531: next if ($type ne 'version' && !@locations);
2532: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2533: $datatable .= '<tr'.$css_class.'>
2534: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2535: <span class="LC_nobreak">
2536: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2537: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2538: if ($type eq 'version') {
2539: my $selector = '<select name="'.$prefix.'_version">';
2540: foreach my $version (@lcversions) {
2541: my $selected = '';
2542: if ($current{'version'} eq $version) {
2543: $selected = ' selected="selected"';
2544: }
2545: $selector .= ' <option value="'.$version.'"'.
2546: $selected.'>'.$version.'</option>';
2547: }
2548: $selector .= '</select> ';
2549: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2550: } else {
2551: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2552: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2553: ' />'.(' 'x2).
2554: '<input type="button" value="'.&mt('uncheck all').'" '.
2555: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2556: "\n".
2557: '</div><div><table>';
2558: my $rem;
2559: for (my $i=0; $i<@locations; $i++) {
2560: my ($showloc,$value,$checkedtype);
2561: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2562: my $ip = $by_location{$locations[$i]}->[0];
2563: if (ref($by_ip{$ip}) eq 'ARRAY') {
2564: $value = join(':',@{$by_ip{$ip}});
2565: $showloc = join(', ',@{$by_ip{$ip}});
2566: if (ref($current{$type}) eq 'ARRAY') {
2567: foreach my $loc (@{$by_ip{$ip}}) {
2568: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2569: $checkedtype = ' checked="checked"';
2570: last;
2571: }
2572: }
1.138 raeburn 2573: }
2574: }
2575: }
1.145 raeburn 2576: $rem = $i%($numinrow);
2577: if ($rem == 0) {
2578: if ($i > 0) {
2579: $datatable .= '</tr>';
2580: }
2581: $datatable .= '<tr>';
2582: }
2583: $datatable .= '<td class="LC_left_item">'.
2584: '<span class="LC_nobreak"><label>'.
2585: '<input type="checkbox" name="'.$prefix.'_'.$type.
2586: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2587: '</label></span></td>';
1.137 raeburn 2588: }
1.145 raeburn 2589: $rem = @locations%($numinrow);
2590: my $colsleft = $numinrow - $rem;
2591: if ($colsleft > 1 ) {
2592: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2593: ' </td>';
2594: } elsif ($colsleft == 1) {
2595: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2596: }
1.145 raeburn 2597: $datatable .= '</tr></table>';
1.137 raeburn 2598: }
1.145 raeburn 2599: $datatable .= '</td></tr>';
2600: $itemcount ++;
1.137 raeburn 2601: }
2602: }
2603: }
2604: $$rowtotal += $itemcount;
2605: return $datatable;
2606: }
2607:
1.138 raeburn 2608: sub build_location_hashes {
2609: my ($intdoms,$by_ip,$by_location) = @_;
2610: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2611: (ref($by_location) eq 'HASH'));
2612: my %iphost = &Apache::lonnet::get_iphost();
2613: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2614: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2615: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2616: foreach my $id (@{$iphost{$primary_ip}}) {
2617: my $intdom = &Apache::lonnet::internet_dom($id);
2618: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2619: push(@{$intdoms},$intdom);
2620: }
2621: }
2622: }
2623: foreach my $ip (keys(%iphost)) {
2624: if (ref($iphost{$ip}) eq 'ARRAY') {
2625: foreach my $id (@{$iphost{$ip}}) {
2626: my $location = &Apache::lonnet::internet_dom($id);
2627: if ($location) {
2628: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2629: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2630: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2631: push(@{$by_ip->{$ip}},$location);
2632: }
2633: } else {
2634: $by_ip->{$ip} = [$location];
2635: }
2636: }
2637: }
2638: }
2639: }
2640: foreach my $ip (sort(keys(%{$by_ip}))) {
2641: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2642: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2643: my $first = $by_ip->{$ip}->[0];
2644: if (ref($by_location->{$first}) eq 'ARRAY') {
2645: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2646: push(@{$by_location->{$first}},$ip);
2647: }
2648: } else {
2649: $by_location->{$first} = [$ip];
2650: }
2651: }
2652: }
2653: return;
2654: }
2655:
1.145 raeburn 2656: sub current_offloads_to {
2657: my ($dom,$settings,$servers) = @_;
2658: my (%spareid,%otherdomconfigs);
1.152 raeburn 2659: if (ref($servers) eq 'HASH') {
1.145 raeburn 2660: foreach my $lonhost (sort(keys(%{$servers}))) {
2661: my $gotspares;
1.152 raeburn 2662: if (ref($settings) eq 'HASH') {
2663: if (ref($settings->{'spares'}) eq 'HASH') {
2664: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2665: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2666: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2667: $gotspares = 1;
2668: }
1.145 raeburn 2669: }
2670: }
2671: unless ($gotspares) {
2672: my $gotspares;
2673: my $serverhomeID =
2674: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2675: my $serverhomedom =
2676: &Apache::lonnet::host_domain($serverhomeID);
2677: if ($serverhomedom ne $dom) {
2678: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2679: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2680: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2681: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2682: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2683: $gotspares = 1;
2684: }
2685: }
2686: } else {
2687: $otherdomconfigs{$serverhomedom} =
2688: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2689: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2690: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2691: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2692: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2693: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2694: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2695: $gotspares = 1;
2696: }
2697: }
2698: }
2699: }
2700: }
2701: }
2702: }
2703: unless ($gotspares) {
2704: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2705: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2706: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2707: } else {
2708: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2709: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2710: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2711: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2712: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2713: } else {
1.150 raeburn 2714: my %what = (
2715: spareid => 1,
2716: );
2717: my ($result,$returnhash) =
2718: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2719: if ($result eq 'ok') {
2720: if (ref($returnhash) eq 'HASH') {
2721: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2722: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2723: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2724: }
2725: }
1.145 raeburn 2726: }
2727: }
2728: }
2729: }
2730: }
2731: }
2732: return %spareid;
2733: }
2734:
2735: sub spares_row {
1.152 raeburn 2736: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2737: my $css_class;
2738: my $numinrow = 4;
2739: my $itemcount = 1;
2740: my $datatable;
1.152 raeburn 2741: my %typetitles = &sparestype_titles();
2742: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2743: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2744: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2745: my ($othercontrol,$serverdom);
2746: if ($serverhome ne $server) {
2747: $serverdom = &Apache::lonnet::host_domain($serverhome);
2748: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2749: } else {
2750: $serverdom = &Apache::lonnet::host_domain($server);
2751: if ($serverdom ne $dom) {
2752: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2753: }
2754: }
2755: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2756: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2757: $datatable .= '<tr'.$css_class.'>
2758: <td rowspan="2">
1.152 raeburn 2759: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2760: my (%current,%canselect);
1.152 raeburn 2761: my @choices =
2762: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2763: foreach my $type ('primary','default') {
2764: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2765: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2766: my @spares = @{$spareid->{$server}{$type}};
2767: if (@spares > 0) {
1.152 raeburn 2768: if ($othercontrol) {
2769: $current{$type} = join(', ',@spares);
2770: } else {
2771: $current{$type} .= '<table>';
2772: my $numspares = scalar(@spares);
2773: for (my $i=0; $i<@spares; $i++) {
2774: my $rem = $i%($numinrow);
2775: if ($rem == 0) {
2776: if ($i > 0) {
2777: $current{$type} .= '</tr>';
2778: }
2779: $current{$type} .= '<tr>';
1.145 raeburn 2780: }
1.152 raeburn 2781: $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'".');" /> '.
2782: $spareid->{$server}{$type}[$i].
2783: '</label></td>'."\n";
2784: }
2785: my $rem = @spares%($numinrow);
2786: my $colsleft = $numinrow - $rem;
2787: if ($colsleft > 1 ) {
2788: $current{$type} .= '<td colspan="'.$colsleft.
2789: '" class="LC_left_item">'.
2790: ' </td>';
2791: } elsif ($colsleft == 1) {
2792: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2793: }
1.152 raeburn 2794: $current{$type} .= '</tr></table>';
1.150 raeburn 2795: }
1.145 raeburn 2796: }
2797: }
2798: if ($current{$type} eq '') {
2799: $current{$type} = &mt('None specified');
2800: }
1.152 raeburn 2801: if ($othercontrol) {
2802: if ($type eq 'primary') {
2803: $canselect{$type} = $othercontrol;
2804: }
2805: } else {
2806: $canselect{$type} =
2807: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2808: '<select name="newspare_'.$type.'_'.$server.'" '.
2809: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2810: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2811: if (@choices > 0) {
2812: foreach my $lonhost (@choices) {
2813: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2814: }
2815: }
2816: $canselect{$type} .= '</select>'."\n";
2817: }
2818: } else {
2819: $current{$type} = &mt('Could not be determined');
2820: if ($type eq 'primary') {
2821: $canselect{$type} = $othercontrol;
2822: }
1.145 raeburn 2823: }
1.152 raeburn 2824: if ($type eq 'default') {
2825: $datatable .= '<tr'.$css_class.'>';
2826: }
2827: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2828: '<td>'.$current{$type}.'</td>'."\n".
2829: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2830: }
2831: $itemcount ++;
2832: }
2833: }
2834: $$rowtotal += $itemcount;
2835: return $datatable;
2836: }
2837:
1.152 raeburn 2838: sub possible_newspares {
2839: my ($server,$currspares,$serverhomes,$altids) = @_;
2840: my $serverhostname = &Apache::lonnet::hostname($server);
2841: my %excluded;
2842: if ($serverhostname ne '') {
2843: %excluded = (
2844: $serverhostname => 1,
2845: );
2846: }
2847: if (ref($currspares) eq 'HASH') {
2848: foreach my $type (keys(%{$currspares})) {
2849: if (ref($currspares->{$type}) eq 'ARRAY') {
2850: if (@{$currspares->{$type}} > 0) {
2851: foreach my $curr (@{$currspares->{$type}}) {
2852: my $hostname = &Apache::lonnet::hostname($curr);
2853: $excluded{$hostname} = 1;
2854: }
2855: }
2856: }
2857: }
2858: }
2859: my @choices;
2860: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2861: if (keys(%{$serverhomes}) > 1) {
2862: foreach my $name (sort(keys(%{$serverhomes}))) {
2863: unless ($excluded{$name}) {
2864: if (exists($altids->{$serverhomes->{$name}})) {
2865: push(@choices,$altids->{$serverhomes->{$name}});
2866: } else {
2867: push(@choices,$serverhomes->{$name});
1.145 raeburn 2868: }
2869: }
2870: }
2871: }
2872: }
1.152 raeburn 2873: return sort(@choices);
1.145 raeburn 2874: }
2875:
1.150 raeburn 2876: sub print_loadbalancing {
2877: my ($dom,$settings,$rowtotal) = @_;
2878: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2879: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2880: my $numinrow = 1;
2881: my $datatable;
2882: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2883: my (%currbalancer,%currtargets,%currrules,%existing);
2884: if (ref($settings) eq 'HASH') {
2885: %existing = %{$settings};
2886: }
2887: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2888: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2889: \%currtargets,\%currrules);
1.150 raeburn 2890: } else {
2891: return;
2892: }
2893: my ($othertitle,$usertypes,$types) =
2894: &Apache::loncommon::sorted_inst_types($dom);
2895: my $rownum = 6;
2896: if (ref($types) eq 'ARRAY') {
2897: $rownum += scalar(@{$types});
2898: }
1.160.6.7 raeburn 2899: my @css_class = ('LC_odd_row','LC_even_row');
2900: my $balnum = 0;
2901: my $islast;
2902: my (@toshow,$disabledtext);
2903: if (keys(%currbalancer) > 0) {
2904: @toshow = sort(keys(%currbalancer));
2905: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2906: push(@toshow,'');
2907: }
2908: } else {
2909: @toshow = ('');
2910: $disabledtext = &mt('No existing load balancer');
2911: }
2912: foreach my $lonhost (@toshow) {
2913: if ($balnum == scalar(@toshow)-1) {
2914: $islast = 1;
2915: } else {
2916: $islast = 0;
2917: }
2918: my $cssidx = $balnum%2;
2919: my $targets_div_style = 'display: none';
2920: my $disabled_div_style = 'display: block';
2921: my $homedom_div_style = 'display: none';
2922: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2923: '<td rowspan="'.$rownum.'" valign="top">'.
2924: '<p>';
2925: if ($lonhost eq '') {
2926: $datatable .= '<span class="LC_nobreak">';
2927: if (keys(%currbalancer) > 0) {
2928: $datatable .= &mt('Add balancer:');
2929: } else {
2930: $datatable .= &mt('Enable balancer:');
2931: }
2932: $datatable .= ' '.
2933: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2934: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2935: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2936: '<option value="" selected="selected">'.&mt('None').
2937: '</option>'."\n";
2938: foreach my $server (sort(keys(%servers))) {
2939: next if ($currbalancer{$server});
2940: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2941: }
2942: $datatable .=
2943: '</select>'."\n".
2944: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2945: } else {
2946: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2947: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2948: &mt('Stop balancing').'</label>'.
2949: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2950: $targets_div_style = 'display: block';
2951: $disabled_div_style = 'display: none';
2952: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2953: $homedom_div_style = 'display: block';
2954: }
2955: }
2956: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2957: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2958: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2959: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2960: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2961: my @sparestypes = ('primary','default');
2962: my %typetitles = &sparestype_titles();
2963: foreach my $sparetype (@sparestypes) {
2964: my $targettable;
2965: for (my $i=0; $i<$numspares; $i++) {
2966: my $checked;
2967: if (ref($currtargets{$lonhost}) eq 'HASH') {
2968: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
2969: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
2970: $checked = ' checked="checked"';
2971: }
2972: }
2973: }
2974: my ($chkboxval,$disabled);
2975: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
2976: $chkboxval = $spares[$i];
2977: }
2978: if (exists($currbalancer{$spares[$i]})) {
2979: $disabled = ' disabled="disabled"';
2980: }
2981: $targettable .=
2982: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
2983: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2984: '</span></label></td>';
2985: my $rem = $i%($numinrow);
2986: if ($rem == 0) {
2987: if (($i > 0) && ($i < $numspares-1)) {
2988: $targettable .= '</tr>';
2989: }
2990: if ($i < $numspares-1) {
2991: $targettable .= '<tr>';
1.150 raeburn 2992: }
2993: }
2994: }
1.160.6.7 raeburn 2995: if ($targettable ne '') {
2996: my $rem = $numspares%($numinrow);
2997: my $colsleft = $numinrow - $rem;
2998: if ($colsleft > 1 ) {
2999: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3000: ' </td>';
3001: } elsif ($colsleft == 1) {
3002: $targettable .= '<td class="LC_left_item"> </td>';
3003: }
3004: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3005: '<table><tr>'.$targettable.'</tr></table><br />';
3006: }
3007: }
3008: $datatable .= '</div></td></tr>'.
3009: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3010: $othertitle,$usertypes,$types,\%servers,
3011: \%currbalancer,$lonhost,
3012: $targets_div_style,$homedom_div_style,
3013: $css_class[$cssidx],$balnum,$islast);
3014: $$rowtotal += $rownum;
3015: $balnum ++;
3016: }
3017: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3018: return $datatable;
3019: }
3020:
3021: sub get_loadbalancers_config {
3022: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3023: return unless ((ref($servers) eq 'HASH') &&
3024: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3025: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3026: if (keys(%{$existing}) > 0) {
3027: my $oldlonhost;
3028: foreach my $key (sort(keys(%{$existing}))) {
3029: if ($key eq 'lonhost') {
3030: $oldlonhost = $existing->{'lonhost'};
3031: $currbalancer->{$oldlonhost} = 1;
3032: } elsif ($key eq 'targets') {
3033: if ($oldlonhost) {
3034: $currtargets->{$oldlonhost} = $existing->{'targets'};
3035: }
3036: } elsif ($key eq 'rules') {
3037: if ($oldlonhost) {
3038: $currrules->{$oldlonhost} = $existing->{'rules'};
3039: }
3040: } elsif (ref($existing->{$key}) eq 'HASH') {
3041: $currbalancer->{$key} = 1;
3042: $currtargets->{$key} = $existing->{$key}{'targets'};
3043: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3044: }
3045: }
1.160.6.7 raeburn 3046: } else {
3047: my ($balancerref,$targetsref) =
3048: &Apache::lonnet::get_lonbalancer_config($servers);
3049: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3050: foreach my $server (sort(keys(%{$balancerref}))) {
3051: $currbalancer->{$server} = 1;
3052: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3053: }
3054: }
3055: }
1.160.6.7 raeburn 3056: return;
1.150 raeburn 3057: }
3058:
3059: sub loadbalancing_rules {
3060: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3061: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3062: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3063: my $output;
1.160.6.7 raeburn 3064: my $num = 0;
3065: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3066: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3067: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3068: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3069: $num ++;
1.150 raeburn 3070: my $current;
3071: if (ref($currrules) eq 'HASH') {
3072: $current = $currrules->{$type};
3073: }
3074: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3075: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3076: $current = '';
3077: }
3078: }
3079: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3080: $servers,$currbalancer,$lonhost,$dom,
3081: $targets_div_style,$homedom_div_style,
3082: $css_class,$balnum,$num,$islast);
1.150 raeburn 3083: }
3084: }
3085: return $output;
3086: }
3087:
3088: sub loadbalancing_titles {
3089: my ($dom,$intdom,$usertypes,$types) = @_;
3090: my %othertypes = (
3091: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3092: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3093: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3094: '_LC_external' => &mt('Users not from [_1]',$intdom),
3095: );
3096: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3097: if (ref($types) eq 'ARRAY') {
3098: unshift(@alltypes,@{$types},'default');
3099: }
3100: my %titles;
3101: foreach my $type (@alltypes) {
3102: if ($type =~ /^_LC_/) {
3103: $titles{$type} = $othertypes{$type};
3104: } elsif ($type eq 'default') {
3105: $titles{$type} = &mt('All users from [_1]',$dom);
3106: if (ref($types) eq 'ARRAY') {
3107: if (@{$types} > 0) {
3108: $titles{$type} = &mt('Other users from [_1]',$dom);
3109: }
3110: }
3111: } elsif (ref($usertypes) eq 'HASH') {
3112: $titles{$type} = $usertypes->{$type};
3113: }
3114: }
3115: return (\@alltypes,\%othertypes,\%titles);
3116: }
3117:
3118: sub loadbalance_rule_row {
1.160.6.7 raeburn 3119: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3120: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3121: my @rulenames = ('default','homeserver');
3122: my %ruletitles = &offloadtype_text();
3123: if ($type eq '_LC_external') {
3124: push(@rulenames,'externalbalancer');
3125: } else {
3126: push(@rulenames,'specific');
3127: }
1.160.6.3 raeburn 3128: push(@rulenames,'none');
1.150 raeburn 3129: my $style = $targets_div_style;
3130: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3131: $style = $homedom_div_style;
3132: }
1.160.6.7 raeburn 3133: my $space;
3134: if ($islast && $num == 1) {
3135: $space = '<div display="inline-block"> </div>';
3136: }
3137: my $output =
3138: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3139: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3140: '<td valaign="top">'.$space.
3141: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3142: for (my $i=0; $i<@rulenames; $i++) {
3143: my $rule = $rulenames[$i];
3144: my ($checked,$extra);
3145: if ($rulenames[$i] eq 'default') {
3146: $rule = '';
3147: }
3148: if ($rulenames[$i] eq 'specific') {
3149: if (ref($servers) eq 'HASH') {
3150: my $default;
3151: if (($current ne '') && (exists($servers->{$current}))) {
3152: $checked = ' checked="checked"';
3153: }
3154: unless ($checked) {
3155: $default = ' selected="selected"';
3156: }
1.160.6.7 raeburn 3157: $extra =
3158: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3159: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3160: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3161: '<option value=""'.$default.'></option>'."\n";
3162: foreach my $server (sort(keys(%{$servers}))) {
3163: if (ref($currbalancer) eq 'HASH') {
3164: next if (exists($currbalancer->{$server}));
3165: }
1.150 raeburn 3166: my $selected;
1.160.6.7 raeburn 3167: if ($server eq $current) {
1.150 raeburn 3168: $selected = ' selected="selected"';
3169: }
1.160.6.7 raeburn 3170: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3171: }
3172: $extra .= '</select>';
3173: }
3174: } elsif ($rule eq $current) {
3175: $checked = ' checked="checked"';
3176: }
3177: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3178: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3179: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3180: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3181: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3182: '</label>'.$extra.'</span><br />'."\n";
3183: }
3184: $output .= '</div></td></tr>'."\n";
3185: return $output;
3186: }
3187:
3188: sub offloadtype_text {
3189: my %ruletitles = &Apache::lonlocal::texthash (
3190: 'default' => 'Offloads to default destinations',
3191: 'homeserver' => "Offloads to user's home server",
3192: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3193: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3194: 'none' => 'No offload',
1.150 raeburn 3195: );
3196: return %ruletitles;
3197: }
3198:
3199: sub sparestype_titles {
3200: my %typestitles = &Apache::lonlocal::texthash (
3201: 'primary' => 'primary',
3202: 'default' => 'default',
3203: );
3204: return %typestitles;
3205: }
3206:
1.28 raeburn 3207: sub contact_titles {
3208: my %titles = &Apache::lonlocal::texthash (
3209: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3210: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3211: 'errormail' => 'Error reports to be e-mailed to',
3212: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3213: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3214: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3215: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3216: );
3217: my %short_titles = &Apache::lonlocal::texthash (
3218: adminemail => 'Admin E-mail address',
3219: supportemail => 'Support E-mail',
3220: );
3221: return (\%titles,\%short_titles);
3222: }
3223:
1.72 raeburn 3224: sub tool_titles {
3225: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3226: aboutme => 'Personal web page',
1.86 raeburn 3227: blog => 'Blog',
1.160.6.4 raeburn 3228: webdav => 'WebDAV',
1.86 raeburn 3229: portfolio => 'Portfolio',
1.88 bisitz 3230: official => 'Official courses (with institutional codes)',
3231: unofficial => 'Unofficial courses',
1.98 raeburn 3232: community => 'Communities',
1.86 raeburn 3233: );
1.72 raeburn 3234: return %titles;
3235: }
3236:
1.101 raeburn 3237: sub courserequest_titles {
3238: my %titles = &Apache::lonlocal::texthash (
3239: official => 'Official',
3240: unofficial => 'Unofficial',
3241: community => 'Communities',
3242: norequest => 'Not allowed',
1.104 raeburn 3243: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3244: validate => 'With validation',
3245: autolimit => 'Numerical limit',
1.103 raeburn 3246: unlimited => '(blank for unlimited)',
1.101 raeburn 3247: );
3248: return %titles;
3249: }
3250:
1.160.6.5 raeburn 3251: sub authorrequest_titles {
3252: my %titles = &Apache::lonlocal::texthash (
3253: norequest => 'Not allowed',
3254: approval => 'Approval by Dom. Coord.',
3255: automatic => 'Automatic approval',
3256: );
3257: return %titles;
3258: }
3259:
1.101 raeburn 3260: sub courserequest_conditions {
3261: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3262: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3263: validate => '(Processing of request subject to instittutional validation).',
3264: );
3265: return %conditions;
3266: }
3267:
3268:
1.27 raeburn 3269: sub print_usercreation {
1.30 raeburn 3270: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3271: my $numinrow = 4;
1.28 raeburn 3272: my $datatable;
3273: if ($position eq 'top') {
1.30 raeburn 3274: $$rowtotal ++;
1.34 raeburn 3275: my $rowcount = 0;
1.32 raeburn 3276: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3277: if (ref($rules) eq 'HASH') {
3278: if (keys(%{$rules}) > 0) {
1.32 raeburn 3279: $datatable .= &user_formats_row('username',$settings,$rules,
3280: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3281: $$rowtotal ++;
1.32 raeburn 3282: $rowcount ++;
3283: }
3284: }
3285: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3286: if (ref($idrules) eq 'HASH') {
3287: if (keys(%{$idrules}) > 0) {
3288: $datatable .= &user_formats_row('id',$settings,$idrules,
3289: $idruleorder,$numinrow,$rowcount);
3290: $$rowtotal ++;
3291: $rowcount ++;
1.28 raeburn 3292: }
3293: }
1.43 raeburn 3294: my ($emailrules,$emailruleorder) =
3295: &Apache::lonnet::inst_userrules($dom,'email');
3296: if (ref($emailrules) eq 'HASH') {
3297: if (keys(%{$emailrules}) > 0) {
3298: $datatable .= &user_formats_row('email',$settings,$emailrules,
3299: $emailruleorder,$numinrow,$rowcount);
3300: $$rowtotal ++;
3301: $rowcount ++;
3302: }
3303: }
1.39 raeburn 3304: if ($rowcount == 0) {
3305: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3306: $$rowtotal ++;
3307: $rowcount ++;
3308: }
1.34 raeburn 3309: } elsif ($position eq 'middle') {
1.100 raeburn 3310: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3311: my ($rules,$ruleorder) =
3312: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3313: my %lt = &usercreation_types();
3314: my %checked;
1.50 raeburn 3315: my @selfcreate;
1.34 raeburn 3316: if (ref($settings) eq 'HASH') {
3317: if (ref($settings->{'cancreate'}) eq 'HASH') {
3318: foreach my $item (@creators) {
3319: $checked{$item} = $settings->{'cancreate'}{$item};
3320: }
1.50 raeburn 3321: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3322: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3323: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3324: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3325: @selfcreate = ('email','login','sso');
3326: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3327: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3328: }
3329: }
1.34 raeburn 3330: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3331: foreach my $item (@creators) {
3332: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3333: $checked{$item} = 'none';
3334: }
3335: }
3336: }
3337: }
3338: my $rownum = 0;
3339: foreach my $item (@creators) {
3340: $rownum ++;
1.50 raeburn 3341: if ($item ne 'selfcreate') {
3342: if ($checked{$item} eq '') {
1.43 raeburn 3343: $checked{$item} = 'any';
3344: }
1.34 raeburn 3345: }
3346: my $css_class;
3347: if ($rownum%2) {
3348: $css_class = '';
3349: } else {
3350: $css_class = ' class="LC_odd_row" ';
3351: }
3352: $datatable .= '<tr'.$css_class.'>'.
3353: '<td><span class="LC_nobreak">'.$lt{$item}.
3354: '</span></td><td align="right">';
1.50 raeburn 3355: my @options;
1.45 raeburn 3356: if ($item eq 'selfcreate') {
1.43 raeburn 3357: push(@options,('email','login','sso'));
3358: } else {
1.50 raeburn 3359: @options = ('any');
1.43 raeburn 3360: if (ref($rules) eq 'HASH') {
3361: if (keys(%{$rules}) > 0) {
3362: push(@options,('official','unofficial'));
3363: }
1.37 raeburn 3364: }
1.50 raeburn 3365: push(@options,'none');
1.37 raeburn 3366: }
3367: foreach my $option (@options) {
1.50 raeburn 3368: my $type = 'radio';
1.34 raeburn 3369: my $check = ' ';
1.50 raeburn 3370: if ($item eq 'selfcreate') {
3371: $type = 'checkbox';
3372: if (grep(/^\Q$option\E$/,@selfcreate)) {
3373: $check = ' checked="checked" ';
3374: }
3375: } else {
3376: if ($checked{$item} eq $option) {
3377: $check = ' checked="checked" ';
3378: }
1.34 raeburn 3379: }
3380: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3381: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3382: $item.'" value="'.$option.'"'.$check.'/> '.
3383: $lt{$option}.'</label> </span>';
3384: }
3385: $datatable .= '</td></tr>';
3386: }
1.93 raeburn 3387: my ($othertitle,$usertypes,$types) =
3388: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3389: my $createsettings;
3390: if (ref($settings) eq 'HASH') {
3391: $createsettings = $settings->{cancreate};
3392: }
1.93 raeburn 3393: if (ref($usertypes) eq 'HASH') {
3394: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3395: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3396: $dom,$numinrow,$othertitle,
3397: 'statustocreate');
3398: $$rowtotal ++;
1.160.6.5 raeburn 3399: $rownum ++;
1.93 raeburn 3400: }
3401: }
1.160.6.5 raeburn 3402: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3403: } else {
3404: my @contexts = ('author','course','domain');
3405: my @authtypes = ('int','krb4','krb5','loc');
3406: my %checked;
3407: if (ref($settings) eq 'HASH') {
3408: if (ref($settings->{'authtypes'}) eq 'HASH') {
3409: foreach my $item (@contexts) {
3410: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3411: foreach my $auth (@authtypes) {
3412: if ($settings->{'authtypes'}{$item}{$auth}) {
3413: $checked{$item}{$auth} = ' checked="checked" ';
3414: }
3415: }
3416: }
3417: }
1.27 raeburn 3418: }
1.35 raeburn 3419: } else {
3420: foreach my $item (@contexts) {
1.36 raeburn 3421: foreach my $auth (@authtypes) {
1.35 raeburn 3422: $checked{$item}{$auth} = ' checked="checked" ';
3423: }
3424: }
1.27 raeburn 3425: }
1.28 raeburn 3426: my %title = &context_names();
3427: my %authname = &authtype_names();
3428: my $rownum = 0;
3429: my $css_class;
3430: foreach my $item (@contexts) {
3431: if ($rownum%2) {
3432: $css_class = '';
3433: } else {
3434: $css_class = ' class="LC_odd_row" ';
3435: }
1.30 raeburn 3436: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3437: '<td>'.$title{$item}.
3438: '</td><td class="LC_left_item">'.
3439: '<span class="LC_nobreak">';
3440: foreach my $auth (@authtypes) {
3441: $datatable .= '<label>'.
3442: '<input type="checkbox" name="'.$item.'_auth" '.
3443: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3444: $authname{$auth}.'</label> ';
3445: }
3446: $datatable .= '</span></td></tr>';
3447: $rownum ++;
1.27 raeburn 3448: }
1.30 raeburn 3449: $$rowtotal += $rownum;
1.27 raeburn 3450: }
3451: return $datatable;
3452: }
3453:
1.160.6.5 raeburn 3454: sub captcha_choice {
3455: my ($context,$settings,$itemcount) = @_;
3456: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3457: my %lt = &captcha_phrases();
3458: $keyentry = 'hidden';
3459: if ($context eq 'cancreate') {
3460: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3461: } elsif ($context eq 'login') {
3462: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3463: }
3464: if (ref($settings) eq 'HASH') {
3465: if ($settings->{'captcha'}) {
3466: $checked{$settings->{'captcha'}} = ' checked="checked"';
3467: } else {
3468: $checked{'original'} = ' checked="checked"';
3469: }
3470: if ($settings->{'captcha'} eq 'recaptcha') {
3471: $pubtext = $lt{'pub'};
3472: $privtext = $lt{'priv'};
3473: $keyentry = 'text';
3474: }
3475: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3476: $currpub = $settings->{'recaptchakeys'}{'public'};
3477: $currpriv = $settings->{'recaptchakeys'}{'private'};
3478: }
3479: } else {
3480: $checked{'original'} = ' checked="checked"';
3481: }
3482: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3483: my $output = '<tr'.$css_class.'>'.
3484: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3485: '<table><tr><td>'."\n";
3486: foreach my $option ('original','recaptcha','notused') {
3487: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3488: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3489: $lt{$option}.'</label></span>';
3490: unless ($option eq 'notused') {
3491: $output .= (' 'x2)."\n";
3492: }
3493: }
3494: #
3495: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3496: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3497: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3498: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3499: #
3500: $output .= '</td></tr>'."\n".
3501: '<tr><td>'."\n".
3502: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3503: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3504: $currpub.'" size="40" /></span><br />'."\n".
3505: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3506: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3507: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3508: '</td></tr>';
3509: return $output;
3510: }
3511:
1.32 raeburn 3512: sub user_formats_row {
3513: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3514: my $output;
3515: my %text = (
3516: 'username' => 'new usernames',
3517: 'id' => 'IDs',
1.45 raeburn 3518: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3519: );
3520: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3521: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3522: '<td><span class="LC_nobreak">';
3523: if ($type eq 'email') {
3524: $output .= &mt("Formats disallowed for $text{$type}: ");
3525: } else {
3526: $output .= &mt("Format rules to check for $text{$type}: ");
3527: }
3528: $output .= '</span></td>'.
3529: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3530: my $rem;
3531: if (ref($ruleorder) eq 'ARRAY') {
3532: for (my $i=0; $i<@{$ruleorder}; $i++) {
3533: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3534: my $rem = $i%($numinrow);
3535: if ($rem == 0) {
3536: if ($i > 0) {
3537: $output .= '</tr>';
3538: }
3539: $output .= '<tr>';
3540: }
3541: my $check = ' ';
1.39 raeburn 3542: if (ref($settings) eq 'HASH') {
3543: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3544: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3545: $check = ' checked="checked" ';
3546: }
1.27 raeburn 3547: }
3548: }
3549: $output .= '<td class="LC_left_item">'.
3550: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3551: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3552: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3553: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3554: }
3555: }
3556: $rem = @{$ruleorder}%($numinrow);
3557: }
3558: my $colsleft = $numinrow - $rem;
3559: if ($colsleft > 1 ) {
3560: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3561: ' </td>';
3562: } elsif ($colsleft == 1) {
3563: $output .= '<td class="LC_left_item"> </td>';
3564: }
3565: $output .= '</tr></table></td></tr>';
3566: return $output;
3567: }
3568:
1.34 raeburn 3569: sub usercreation_types {
3570: my %lt = &Apache::lonlocal::texthash (
3571: author => 'When adding a co-author',
3572: course => 'When adding a user to a course',
1.100 raeburn 3573: requestcrs => 'When requesting a course',
1.45 raeburn 3574: selfcreate => 'User creates own account',
1.34 raeburn 3575: any => 'Any',
3576: official => 'Institutional only ',
3577: unofficial => 'Non-institutional only',
1.85 schafran 3578: email => 'E-mail address',
1.43 raeburn 3579: login => 'Institutional Login',
3580: sso => 'SSO',
1.34 raeburn 3581: none => 'None',
3582: );
3583: return %lt;
1.48 raeburn 3584: }
1.34 raeburn 3585:
1.28 raeburn 3586: sub authtype_names {
3587: my %lt = &Apache::lonlocal::texthash(
3588: int => 'Internal',
3589: krb4 => 'Kerberos 4',
3590: krb5 => 'Kerberos 5',
3591: loc => 'Local',
3592: );
3593: return %lt;
3594: }
3595:
3596: sub context_names {
3597: my %context_title = &Apache::lonlocal::texthash(
3598: author => 'Creating users when an Author',
3599: course => 'Creating users when in a course',
3600: domain => 'Creating users when a Domain Coordinator',
3601: );
3602: return %context_title;
3603: }
3604:
1.33 raeburn 3605: sub print_usermodification {
3606: my ($position,$dom,$settings,$rowtotal) = @_;
3607: my $numinrow = 4;
3608: my ($context,$datatable,$rowcount);
3609: if ($position eq 'top') {
3610: $rowcount = 0;
3611: $context = 'author';
3612: foreach my $role ('ca','aa') {
3613: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3614: $numinrow,$rowcount);
3615: $$rowtotal ++;
3616: $rowcount ++;
3617: }
1.63 raeburn 3618: } elsif ($position eq 'middle') {
1.33 raeburn 3619: $context = 'course';
3620: $rowcount = 0;
3621: foreach my $role ('st','ep','ta','in','cr') {
3622: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3623: $numinrow,$rowcount);
3624: $$rowtotal ++;
3625: $rowcount ++;
3626: }
1.63 raeburn 3627: } elsif ($position eq 'bottom') {
3628: $context = 'selfcreate';
3629: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3630: $usertypes->{'default'} = $othertitle;
3631: if (ref($types) eq 'ARRAY') {
3632: push(@{$types},'default');
3633: $usertypes->{'default'} = $othertitle;
3634: foreach my $status (@{$types}) {
3635: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3636: $numinrow,$rowcount,$usertypes);
3637: $$rowtotal ++;
3638: $rowcount ++;
3639: }
3640: }
1.33 raeburn 3641: }
3642: return $datatable;
3643: }
3644:
1.43 raeburn 3645: sub print_defaults {
3646: my ($dom,$rowtotal) = @_;
1.68 raeburn 3647: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3648: 'datelocale_def','portal_def');
1.43 raeburn 3649: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3650: my $titles = &defaults_titles($dom);
1.43 raeburn 3651: my $rownum = 0;
3652: my ($datatable,$css_class);
3653: foreach my $item (@items) {
3654: if ($rownum%2) {
3655: $css_class = '';
3656: } else {
3657: $css_class = ' class="LC_odd_row" ';
3658: }
3659: $datatable .= '<tr'.$css_class.'>'.
3660: '<td><span class="LC_nobreak">'.$titles->{$item}.
3661: '</span></td><td class="LC_right_item">';
3662: if ($item eq 'auth_def') {
3663: my @authtypes = ('internal','krb4','krb5','localauth');
3664: my %shortauth = (
3665: internal => 'int',
3666: krb4 => 'krb4',
3667: krb5 => 'krb5',
3668: localauth => 'loc'
3669: );
3670: my %authnames = &authtype_names();
3671: foreach my $auth (@authtypes) {
3672: my $checked = ' ';
3673: if ($domdefaults{$item} eq $auth) {
3674: $checked = ' checked="checked" ';
3675: }
3676: $datatable .= '<label><input type="radio" name="'.$item.
3677: '" value="'.$auth.'"'.$checked.'/>'.
3678: $authnames{$shortauth{$auth}}.'</label> ';
3679: }
1.54 raeburn 3680: } elsif ($item eq 'timezone_def') {
3681: my $includeempty = 1;
3682: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3683: } elsif ($item eq 'datelocale_def') {
3684: my $includeempty = 1;
3685: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3686: } elsif ($item eq 'lang_def') {
3687: my %langchoices = &get_languages_hash();
3688: $langchoices{''} = 'No language preference';
3689: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3690: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3691: \%langchoices);
1.43 raeburn 3692: } else {
1.141 raeburn 3693: my $size;
3694: if ($item eq 'portal_def') {
3695: $size = ' size="25"';
3696: }
1.43 raeburn 3697: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3698: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3699: }
3700: $datatable .= '</td></tr>';
3701: $rownum ++;
3702: }
3703: $$rowtotal += $rownum;
3704: return $datatable;
3705: }
3706:
1.160.6.5 raeburn 3707: sub get_languages_hash {
3708: my %langchoices;
3709: foreach my $id (&Apache::loncommon::languageids()) {
3710: my $code = &Apache::loncommon::supportedlanguagecode($id);
3711: if ($code ne '') {
3712: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3713: }
3714: }
3715: return %langchoices;
3716: }
3717:
1.43 raeburn 3718: sub defaults_titles {
1.141 raeburn 3719: my ($dom) = @_;
1.43 raeburn 3720: my %titles = &Apache::lonlocal::texthash (
3721: 'auth_def' => 'Default authentication type',
3722: 'auth_arg_def' => 'Default authentication argument',
3723: 'lang_def' => 'Default language',
1.54 raeburn 3724: 'timezone_def' => 'Default timezone',
1.68 raeburn 3725: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3726: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3727: );
1.141 raeburn 3728: if ($dom) {
3729: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3730: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3731: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3732: $protocol = 'http' if ($protocol ne 'https');
3733: if ($uint_dom) {
3734: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3735: $uint_dom);
3736: }
3737: }
1.43 raeburn 3738: return (\%titles);
3739: }
3740:
1.46 raeburn 3741: sub print_scantronformat {
3742: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3743: my $itemcount = 1;
1.60 raeburn 3744: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3745: %confhash);
1.46 raeburn 3746: my $switchserver = &check_switchserver($dom,$confname);
3747: my %lt = &Apache::lonlocal::texthash (
1.95 www 3748: default => 'Default bubblesheet format file error',
3749: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3750: );
3751: my %scantronfiles = (
3752: default => 'default.tab',
3753: custom => 'custom.tab',
3754: );
3755: foreach my $key (keys(%scantronfiles)) {
3756: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3757: .$scantronfiles{$key};
3758: }
3759: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3760: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3761: if (!$switchserver) {
3762: my $servadm = $r->dir_config('lonAdmEMail');
3763: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3764: if ($configuserok eq 'ok') {
3765: if ($author_ok eq 'ok') {
3766: my %legacyfile = (
3767: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3768: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3769: );
3770: my %md5chk;
3771: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3772: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3773: chomp($md5chk{$type});
1.46 raeburn 3774: }
3775: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3776: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3777: ($scantronurls{$type},my $error) =
1.46 raeburn 3778: &legacy_scantronformat($r,$dom,$confname,
3779: $type,$legacyfile{$type},
3780: $scantronurls{$type},
3781: $scantronfiles{$type});
1.60 raeburn 3782: if ($error ne '') {
3783: $error{$type} = $error;
3784: }
3785: }
3786: if (keys(%error) == 0) {
3787: $is_custom = 1;
3788: $confhash{'scantron'}{'scantronformat'} =
3789: $scantronurls{'custom'};
3790: my $putresult =
3791: &Apache::lonnet::put_dom('configuration',
3792: \%confhash,$dom);
3793: if ($putresult ne 'ok') {
3794: $error{'custom'} =
3795: '<span class="LC_error">'.
3796: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3797: }
1.46 raeburn 3798: }
3799: } else {
1.60 raeburn 3800: ($scantronurls{'default'},my $error) =
1.46 raeburn 3801: &legacy_scantronformat($r,$dom,$confname,
3802: 'default',$legacyfile{'default'},
3803: $scantronurls{'default'},
3804: $scantronfiles{'default'});
1.60 raeburn 3805: if ($error eq '') {
3806: $confhash{'scantron'}{'scantronformat'} = '';
3807: my $putresult =
3808: &Apache::lonnet::put_dom('configuration',
3809: \%confhash,$dom);
3810: if ($putresult ne 'ok') {
3811: $error{'default'} =
3812: '<span class="LC_error">'.
3813: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3814: }
3815: } else {
3816: $error{'default'} = $error;
3817: }
1.46 raeburn 3818: }
3819: }
3820: }
3821: } else {
1.95 www 3822: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3823: }
3824: }
3825: if (ref($settings) eq 'HASH') {
3826: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3827: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3828: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3829: $scantronurl = '';
3830: } else {
3831: $scantronurl = $settings->{'scantronformat'};
3832: }
3833: $is_custom = 1;
3834: } else {
3835: $scantronurl = $scantronurls{'default'};
3836: }
3837: } else {
1.60 raeburn 3838: if ($is_custom) {
3839: $scantronurl = $scantronurls{'custom'};
3840: } else {
3841: $scantronurl = $scantronurls{'default'};
3842: }
1.46 raeburn 3843: }
3844: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3845: $datatable .= '<tr'.$css_class.'>';
3846: if (!$is_custom) {
1.65 raeburn 3847: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3848: '<span class="LC_nobreak">';
1.46 raeburn 3849: if ($scantronurl) {
3850: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3851: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3852: } else {
3853: $datatable = &mt('File unavailable for display');
3854: }
1.65 raeburn 3855: $datatable .= '</span></td>';
1.60 raeburn 3856: if (keys(%error) == 0) {
3857: $datatable .= '<td valign="bottom">';
3858: if (!$switchserver) {
3859: $datatable .= &mt('Upload:').'<br />';
3860: }
3861: } else {
3862: my $errorstr;
3863: foreach my $key (sort(keys(%error))) {
3864: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3865: }
3866: $datatable .= '<td>'.$errorstr;
3867: }
1.46 raeburn 3868: } else {
3869: if (keys(%error) > 0) {
3870: my $errorstr;
3871: foreach my $key (sort(keys(%error))) {
3872: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3873: }
1.60 raeburn 3874: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3875: } elsif ($scantronurl) {
1.65 raeburn 3876: $datatable .= '<td><span class="LC_nobreak">'.
3877: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3878: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3879: '<input type="checkbox" name="scantronformat_del"'.
3880: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3881: '<td><span class="LC_nobreak"> '.
3882: &mt('Replace:').'</span><br />';
1.46 raeburn 3883: }
3884: }
3885: if (keys(%error) == 0) {
3886: if ($switchserver) {
3887: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3888: } else {
1.65 raeburn 3889: $datatable .='<span class="LC_nobreak"> '.
3890: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3891: }
3892: }
3893: $datatable .= '</td></tr>';
3894: $$rowtotal ++;
3895: return $datatable;
3896: }
3897:
3898: sub legacy_scantronformat {
3899: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3900: my ($url,$error);
3901: my @statinfo = &Apache::lonnet::stat_file($newurl);
3902: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3903: (my $result,$url) =
3904: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3905: '','',$newfile);
3906: if ($result ne 'ok') {
1.130 raeburn 3907: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3908: }
3909: }
3910: return ($url,$error);
3911: }
1.43 raeburn 3912:
1.49 raeburn 3913: sub print_coursecategories {
1.57 raeburn 3914: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3915: my $datatable;
3916: if ($position eq 'top') {
3917: my $toggle_cats_crs = ' ';
3918: my $toggle_cats_dom = ' checked="checked" ';
3919: my $can_cat_crs = ' ';
3920: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3921: my $toggle_catscomm_comm = ' ';
3922: my $toggle_catscomm_dom = ' checked="checked" ';
3923: my $can_catcomm_comm = ' ';
3924: my $can_catcomm_dom = ' checked="checked" ';
3925:
1.57 raeburn 3926: if (ref($settings) eq 'HASH') {
3927: if ($settings->{'togglecats'} eq 'crs') {
3928: $toggle_cats_crs = $toggle_cats_dom;
3929: $toggle_cats_dom = ' ';
3930: }
3931: if ($settings->{'categorize'} eq 'crs') {
3932: $can_cat_crs = $can_cat_dom;
3933: $can_cat_dom = ' ';
3934: }
1.120 raeburn 3935: if ($settings->{'togglecatscomm'} eq 'comm') {
3936: $toggle_catscomm_comm = $toggle_catscomm_dom;
3937: $toggle_catscomm_dom = ' ';
3938: }
3939: if ($settings->{'categorizecomm'} eq 'comm') {
3940: $can_catcomm_comm = $can_catcomm_dom;
3941: $can_catcomm_dom = ' ';
3942: }
1.57 raeburn 3943: }
3944: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3945: togglecats => 'Show/Hide a course in catalog',
3946: togglecatscomm => 'Show/Hide a community in catalog',
3947: categorize => 'Assign a category to a course',
3948: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3949: );
3950: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3951: dom => 'Set in Domain',
3952: crs => 'Set in Course',
3953: comm => 'Set in Community',
1.57 raeburn 3954: );
3955: $datatable = '<tr class="LC_odd_row">'.
3956: '<td>'.$title{'togglecats'}.'</td>'.
3957: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3958: '<input type="radio" name="togglecats"'.
3959: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3960: '<label><input type="radio" name="togglecats"'.
3961: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3962: '</tr><tr>'.
3963: '<td>'.$title{'categorize'}.'</td>'.
3964: '<td class="LC_right_item"><span class="LC_nobreak">'.
3965: '<label><input type="radio" name="categorize"'.
3966: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3967: '<label><input type="radio" name="categorize"'.
3968: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3969: '</tr><tr class="LC_odd_row">'.
3970: '<td>'.$title{'togglecatscomm'}.'</td>'.
3971: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3972: '<input type="radio" name="togglecatscomm"'.
3973: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3974: '<label><input type="radio" name="togglecatscomm"'.
3975: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3976: '</tr><tr>'.
3977: '<td>'.$title{'categorizecomm'}.'</td>'.
3978: '<td class="LC_right_item"><span class="LC_nobreak">'.
3979: '<label><input type="radio" name="categorizecomm"'.
3980: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3981: '<label><input type="radio" name="categorizecomm"'.
3982: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3983: '</tr>';
1.120 raeburn 3984: $$rowtotal += 4;
1.57 raeburn 3985: } else {
3986: my $css_class;
3987: my $itemcount = 1;
3988: my $cathash;
3989: if (ref($settings) eq 'HASH') {
3990: $cathash = $settings->{'cats'};
3991: }
3992: if (ref($cathash) eq 'HASH') {
3993: my (@cats,@trails,%allitems,%idx,@jsarray);
3994: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3995: \%allitems,\%idx,\@jsarray);
3996: my $maxdepth = scalar(@cats);
3997: my $colattrib = '';
3998: if ($maxdepth > 2) {
3999: $colattrib = ' colspan="2" ';
4000: }
4001: my @path;
4002: if (@cats > 0) {
4003: if (ref($cats[0]) eq 'ARRAY') {
4004: my $numtop = @{$cats[0]};
4005: my $maxnum = $numtop;
1.120 raeburn 4006: my %default_names = (
4007: instcode => &mt('Official courses'),
4008: communities => &mt('Communities'),
4009: );
4010:
4011: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4012: ($cathash->{'instcode::0'} eq '') ||
4013: (!grep(/^communities$/,@{$cats[0]})) ||
4014: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4015: $maxnum ++;
4016: }
4017: my $lastidx;
4018: for (my $i=0; $i<$numtop; $i++) {
4019: my $parent = $cats[0][$i];
4020: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4021: my $item = &escape($parent).'::0';
4022: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4023: $lastidx = $idx{$item};
4024: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4025: .'<select name="'.$item.'"'.$chgstr.'>';
4026: for (my $k=0; $k<=$maxnum; $k++) {
4027: my $vpos = $k+1;
4028: my $selstr;
4029: if ($k == $i) {
4030: $selstr = ' selected="selected" ';
4031: }
4032: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4033: }
4034: $datatable .= '</select></td><td>';
1.120 raeburn 4035: if ($parent eq 'instcode' || $parent eq 'communities') {
4036: $datatable .= '<span class="LC_nobreak">'
4037: .$default_names{$parent}.'</span>';
4038: if ($parent eq 'instcode') {
4039: $datatable .= '<br /><span class="LC_nobreak">('
4040: .&mt('with institutional codes')
4041: .')</span></td><td'.$colattrib.'>';
4042: } else {
4043: $datatable .= '<table><tr><td>';
4044: }
4045: $datatable .= '<span class="LC_nobreak">'
4046: .'<label><input type="radio" name="'
4047: .$parent.'" value="1" checked="checked" />'
4048: .&mt('Display').'</label>';
4049: if ($parent eq 'instcode') {
4050: $datatable .= ' ';
4051: } else {
4052: $datatable .= '</span></td></tr><tr><td>'
4053: .'<span class="LC_nobreak">';
4054: }
4055: $datatable .= '<label><input type="radio" name="'
4056: .$parent.'" value="0" />'
4057: .&mt('Do not display').'</label></span>';
4058: if ($parent eq 'communities') {
4059: $datatable .= '</td></tr></table>';
4060: }
4061: $datatable .= '</td>';
1.57 raeburn 4062: } else {
4063: $datatable .= $parent
4064: .' <label><input type="checkbox" name="deletecategory" '
4065: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4066: }
4067: my $depth = 1;
4068: push(@path,$parent);
4069: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4070: pop(@path);
4071: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4072: $itemcount ++;
4073: }
1.48 raeburn 4074: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4075: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4076: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4077: for (my $k=0; $k<=$maxnum; $k++) {
4078: my $vpos = $k+1;
4079: my $selstr;
1.57 raeburn 4080: if ($k == $numtop) {
1.48 raeburn 4081: $selstr = ' selected="selected" ';
4082: }
4083: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4084: }
1.59 bisitz 4085: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4086: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4087: .'</tr>'."\n";
1.48 raeburn 4088: $itemcount ++;
1.120 raeburn 4089: foreach my $default ('instcode','communities') {
4090: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4092: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4093: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4094: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4095: for (my $k=0; $k<=$maxnum; $k++) {
4096: my $vpos = $k+1;
4097: my $selstr;
4098: if ($k == $maxnum) {
4099: $selstr = ' selected="selected" ';
4100: }
4101: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4102: }
1.120 raeburn 4103: $datatable .= '</select></span></td>'.
4104: '<td><span class="LC_nobreak">'.
4105: $default_names{$default}.'</span>';
4106: if ($default eq 'instcode') {
4107: $datatable .= '<br /><span class="LC_nobreak">('
4108: .&mt('with institutional codes').')</span>';
4109: }
4110: $datatable .= '</td>'
4111: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4112: .&mt('Display').'</label> '
4113: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4114: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4115: }
4116: }
4117: }
1.57 raeburn 4118: } else {
4119: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4120: }
4121: } else {
1.57 raeburn 4122: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4123: .&initialize_categories($itemcount);
1.48 raeburn 4124: }
1.57 raeburn 4125: $$rowtotal += $itemcount;
1.48 raeburn 4126: }
4127: return $datatable;
4128: }
4129:
1.69 raeburn 4130: sub print_serverstatuses {
4131: my ($dom,$settings,$rowtotal) = @_;
4132: my $datatable;
4133: my @pages = &serverstatus_pages();
4134: my (%namedaccess,%machineaccess);
4135: foreach my $type (@pages) {
4136: $namedaccess{$type} = '';
4137: $machineaccess{$type}= '';
4138: }
4139: if (ref($settings) eq 'HASH') {
4140: foreach my $type (@pages) {
4141: if (exists($settings->{$type})) {
4142: if (ref($settings->{$type}) eq 'HASH') {
4143: foreach my $key (keys(%{$settings->{$type}})) {
4144: if ($key eq 'namedusers') {
4145: $namedaccess{$type} = $settings->{$type}->{$key};
4146: } elsif ($key eq 'machines') {
4147: $machineaccess{$type} = $settings->{$type}->{$key};
4148: }
4149: }
4150: }
4151: }
4152: }
4153: }
1.81 raeburn 4154: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4155: my $rownum = 0;
4156: my $css_class;
4157: foreach my $type (@pages) {
4158: $rownum ++;
4159: $css_class = $rownum%2?' class="LC_odd_row"':'';
4160: $datatable .= '<tr'.$css_class.'>'.
4161: '<td><span class="LC_nobreak">'.
4162: $titles->{$type}.'</span></td>'.
4163: '<td class="LC_left_item">'.
4164: '<input type="text" name="'.$type.'_namedusers" '.
4165: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4166: '<td class="LC_right_item">'.
4167: '<span class="LC_nobreak">'.
4168: '<input type="text" name="'.$type.'_machines" '.
4169: 'value="'.$machineaccess{$type}.'" size="10" />'.
4170: '</td></tr>'."\n";
4171: }
4172: $$rowtotal += $rownum;
4173: return $datatable;
4174: }
4175:
4176: sub serverstatus_pages {
4177: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4178: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4179: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4180: }
4181:
1.49 raeburn 4182: sub coursecategories_javascript {
4183: my ($settings) = @_;
1.57 raeburn 4184: my ($output,$jstext,$cathash);
1.49 raeburn 4185: if (ref($settings) eq 'HASH') {
1.57 raeburn 4186: $cathash = $settings->{'cats'};
4187: }
4188: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4189: my (@cats,@jsarray,%idx);
1.57 raeburn 4190: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4191: if (@jsarray > 0) {
4192: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4193: for (my $i=0; $i<@jsarray; $i++) {
4194: if (ref($jsarray[$i]) eq 'ARRAY') {
4195: my $catstr = join('","',@{$jsarray[$i]});
4196: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4197: }
4198: }
4199: }
4200: } else {
4201: $jstext = ' var categories = Array(1);'."\n".
4202: ' categories[0] = Array("instcode_pos");'."\n";
4203: }
1.120 raeburn 4204: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4205: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4206: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4207: $output = <<"ENDSCRIPT";
4208: <script type="text/javascript">
1.109 raeburn 4209: // <![CDATA[
1.49 raeburn 4210: function reorderCats(form,parent,item,idx) {
4211: var changedVal;
4212: $jstext
4213: var newpos = 'addcategory_pos';
4214: var current = new Array;
4215: if (parent == '') {
4216: var has_instcode = 0;
4217: var maxtop = categories[idx].length;
4218: for (var j=0; j<maxtop; j++) {
4219: if (categories[idx][j] == 'instcode::0') {
4220: has_instcode == 1;
4221: }
4222: }
4223: if (has_instcode == 0) {
4224: categories[idx][maxtop] = 'instcode_pos';
4225: }
4226: } else {
4227: newpos += '_'+parent;
4228: }
4229: var maxh = 1 + categories[idx].length;
4230: var current = new Array;
4231: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4232: if (item == newpos) {
4233: changedVal = newitemVal;
4234: } else {
4235: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4236: current[newitemVal] = newpos;
4237: }
4238: for (var i=0; i<categories[idx].length; i++) {
4239: var elementName = categories[idx][i];
4240: if (elementName != item) {
4241: if (form.elements[elementName]) {
4242: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4243: current[currVal] = elementName;
4244: }
4245: }
4246: }
4247: var oldVal;
4248: for (var j=0; j<maxh; j++) {
4249: if (current[j] == undefined) {
4250: oldVal = j;
4251: }
4252: }
4253: if (oldVal < changedVal) {
4254: for (var k=oldVal+1; k<=changedVal ; k++) {
4255: var elementName = current[k];
4256: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4257: }
4258: } else {
4259: for (var k=changedVal; k<oldVal; k++) {
4260: var elementName = current[k];
4261: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4262: }
4263: }
4264: return;
4265: }
1.120 raeburn 4266:
4267: function categoryCheck(form) {
4268: if (form.elements['addcategory_name'].value == 'instcode') {
4269: alert('$instcode_reserved\\n$choose_again');
4270: return false;
4271: }
4272: if (form.elements['addcategory_name'].value == 'communities') {
4273: alert('$communities_reserved\\n$choose_again');
4274: return false;
4275: }
4276: return true;
4277: }
4278:
1.109 raeburn 4279: // ]]>
1.49 raeburn 4280: </script>
4281:
4282: ENDSCRIPT
4283: return $output;
4284: }
4285:
1.48 raeburn 4286: sub initialize_categories {
4287: my ($itemcount) = @_;
1.120 raeburn 4288: my ($datatable,$css_class,$chgstr);
4289: my %default_names = (
4290: instcode => 'Official courses (with institutional codes)',
4291: communities => 'Communities',
4292: );
4293: my $select0 = ' selected="selected"';
4294: my $select1 = '';
4295: foreach my $default ('instcode','communities') {
4296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4297: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4298: if ($default eq 'communities') {
4299: $select1 = $select0;
4300: $select0 = '';
4301: }
4302: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4303: .'<select name="'.$default.'_pos">'
4304: .'<option value="0"'.$select0.'>1</option>'
4305: .'<option value="1"'.$select1.'>2</option>'
4306: .'<option value="2">3</option></select> '
4307: .$default_names{$default}
4308: .'</span></td><td><span class="LC_nobreak">'
4309: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4310: .&mt('Display').'</label> <label>'
4311: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4312: .'</label></span></td></tr>';
1.120 raeburn 4313: $itemcount ++;
4314: }
1.48 raeburn 4315: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4316: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4317: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4318: .'<select name="addcategory_pos"'.$chgstr.'>'
4319: .'<option value="0">1</option>'
4320: .'<option value="1">2</option>'
4321: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4322: .&mt('Add category').'</td><td>'.&mt('Name:')
4323: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4324: return $datatable;
4325: }
4326:
4327: sub build_category_rows {
1.49 raeburn 4328: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4329: my ($text,$name,$item,$chgstr);
1.48 raeburn 4330: if (ref($cats) eq 'ARRAY') {
4331: my $maxdepth = scalar(@{$cats});
4332: if (ref($cats->[$depth]) eq 'HASH') {
4333: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4334: my $numchildren = @{$cats->[$depth]{$parent}};
4335: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4336: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4337: my ($idxnum,$parent_name,$parent_item);
4338: my $higher = $depth - 1;
4339: if ($higher == 0) {
4340: $parent_name = &escape($parent).'::'.$higher;
4341: } else {
4342: if (ref($path) eq 'ARRAY') {
4343: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4344: }
4345: }
4346: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4347: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4348: if ($j < $numchildren) {
1.48 raeburn 4349: $name = $cats->[$depth]{$parent}[$j];
4350: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4351: $idxnum = $idx->{$item};
4352: } else {
4353: $name = $parent_name;
4354: $item = $parent_item;
1.48 raeburn 4355: }
1.49 raeburn 4356: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4357: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4358: for (my $i=0; $i<=$numchildren; $i++) {
4359: my $vpos = $i+1;
4360: my $selstr;
4361: if ($j == $i) {
4362: $selstr = ' selected="selected" ';
4363: }
4364: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4365: }
4366: $text .= '</select> ';
4367: if ($j < $numchildren) {
4368: my $deeper = $depth+1;
4369: $text .= $name.' '
4370: .'<label><input type="checkbox" name="deletecategory" value="'
4371: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4372: if(ref($path) eq 'ARRAY') {
4373: push(@{$path},$name);
1.49 raeburn 4374: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4375: pop(@{$path});
4376: }
4377: } else {
1.59 bisitz 4378: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4379: if ($j == $numchildren) {
4380: $text .= $name;
4381: } else {
4382: $text .= $item;
4383: }
4384: $text .= '" value="" />';
4385: }
4386: $text .= '</td></tr>';
4387: }
4388: $text .= '</table></td>';
4389: } else {
4390: my $higher = $depth-1;
4391: if ($higher == 0) {
4392: $name = &escape($parent).'::'.$higher;
4393: } else {
4394: if (ref($path) eq 'ARRAY') {
4395: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4396: }
4397: }
4398: my $colspan;
4399: if ($parent ne 'instcode') {
4400: $colspan = $maxdepth - $depth - 1;
4401: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4402: }
4403: }
4404: }
4405: }
4406: return $text;
4407: }
4408:
1.33 raeburn 4409: sub modifiable_userdata_row {
1.63 raeburn 4410: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4411: my $rolename;
1.63 raeburn 4412: if ($context eq 'selfcreate') {
4413: if (ref($usertypes) eq 'HASH') {
4414: $rolename = $usertypes->{$role};
4415: } else {
4416: $rolename = $role;
4417: }
1.33 raeburn 4418: } else {
1.63 raeburn 4419: if ($role eq 'cr') {
4420: $rolename = &mt('Custom role');
4421: } else {
4422: $rolename = &Apache::lonnet::plaintext($role);
4423: }
1.33 raeburn 4424: }
4425: my @fields = ('lastname','firstname','middlename','generation',
4426: 'permanentemail','id');
4427: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4428: my $output;
4429: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4430: $output = '<tr '.$css_class.'>'.
4431: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4432: '<td class="LC_left_item" colspan="2"><table>';
4433: my $rem;
4434: my %checks;
4435: if (ref($settings) eq 'HASH') {
4436: if (ref($settings->{$context}) eq 'HASH') {
4437: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4438: foreach my $field (@fields) {
4439: if ($settings->{$context}->{$role}->{$field}) {
4440: $checks{$field} = ' checked="checked" ';
4441: }
4442: }
4443: }
4444: }
4445: }
4446: for (my $i=0; $i<@fields; $i++) {
4447: my $rem = $i%($numinrow);
4448: if ($rem == 0) {
4449: if ($i > 0) {
4450: $output .= '</tr>';
4451: }
4452: $output .= '<tr>';
4453: }
4454: my $check = ' ';
4455: if (exists($checks{$fields[$i]})) {
4456: $check = $checks{$fields[$i]}
4457: } else {
4458: if ($role eq 'st') {
4459: if (ref($settings) ne 'HASH') {
4460: $check = ' checked="checked" ';
4461: }
4462: }
4463: }
4464: $output .= '<td class="LC_left_item">'.
4465: '<span class="LC_nobreak"><label>'.
4466: '<input type="checkbox" name="canmodify_'.$role.'" '.
4467: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4468: '</label></span></td>';
4469: $rem = @fields%($numinrow);
4470: }
4471: my $colsleft = $numinrow - $rem;
4472: if ($colsleft > 1 ) {
4473: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4474: ' </td>';
4475: } elsif ($colsleft == 1) {
4476: $output .= '<td class="LC_left_item"> </td>';
4477: }
4478: $output .= '</tr></table></td></tr>';
4479: return $output;
4480: }
1.28 raeburn 4481:
1.93 raeburn 4482: sub insttypes_row {
4483: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4484: my %lt = &Apache::lonlocal::texthash (
4485: cansearch => 'Users allowed to search',
4486: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4487: lockablenames => 'User preference to lock name',
1.93 raeburn 4488: );
4489: my $showdom;
4490: if ($context eq 'cansearch') {
4491: $showdom = ' ('.$dom.')';
4492: }
1.160.6.5 raeburn 4493: my $class = 'LC_left_item';
4494: if ($context eq 'statustocreate') {
4495: $class = 'LC_right_item';
4496: }
1.25 raeburn 4497: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4498: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4499: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4500: my $rem;
4501: if (ref($types) eq 'ARRAY') {
4502: for (my $i=0; $i<@{$types}; $i++) {
4503: if (defined($usertypes->{$types->[$i]})) {
4504: my $rem = $i%($numinrow);
4505: if ($rem == 0) {
4506: if ($i > 0) {
4507: $output .= '</tr>';
4508: }
4509: $output .= '<tr>';
1.23 raeburn 4510: }
1.26 raeburn 4511: my $check = ' ';
1.99 raeburn 4512: if (ref($settings) eq 'HASH') {
4513: if (ref($settings->{$context}) eq 'ARRAY') {
4514: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4515: $check = ' checked="checked" ';
4516: }
4517: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4518: $check = ' checked="checked" ';
4519: }
1.23 raeburn 4520: }
1.26 raeburn 4521: $output .= '<td class="LC_left_item">'.
4522: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4523: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4524: 'value="'.$types->[$i].'"'.$check.'/>'.
4525: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4526: }
4527: }
1.26 raeburn 4528: $rem = @{$types}%($numinrow);
1.23 raeburn 4529: }
4530: my $colsleft = $numinrow - $rem;
1.131 raeburn 4531: if (($rem == 0) && (@{$types} > 0)) {
4532: $output .= '<tr>';
4533: }
1.23 raeburn 4534: if ($colsleft > 1) {
1.25 raeburn 4535: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4536: } else {
1.25 raeburn 4537: $output .= '<td class="LC_left_item">';
1.23 raeburn 4538: }
4539: my $defcheck = ' ';
1.99 raeburn 4540: if (ref($settings) eq 'HASH') {
4541: if (ref($settings->{$context}) eq 'ARRAY') {
4542: if (grep(/^default$/,@{$settings->{$context}})) {
4543: $defcheck = ' checked="checked" ';
4544: }
4545: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4546: $defcheck = ' checked="checked" ';
4547: }
1.23 raeburn 4548: }
1.25 raeburn 4549: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4550: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4551: 'value="default"'.$defcheck.'/>'.
4552: $othertitle.'</label></span></td>'.
4553: '</tr></table></td></tr>';
4554: return $output;
1.23 raeburn 4555: }
4556:
4557: sub sorted_searchtitles {
4558: my %searchtitles = &Apache::lonlocal::texthash(
4559: 'uname' => 'username',
4560: 'lastname' => 'last name',
4561: 'lastfirst' => 'last name, first name',
4562: );
4563: my @titleorder = ('uname','lastname','lastfirst');
4564: return (\%searchtitles,\@titleorder);
4565: }
4566:
1.25 raeburn 4567: sub sorted_searchtypes {
4568: my %srchtypes_desc = (
4569: exact => 'is exact match',
4570: contains => 'contains ..',
4571: begins => 'begins with ..',
4572: );
4573: my @srchtypeorder = ('exact','begins','contains');
4574: return (\%srchtypes_desc,\@srchtypeorder);
4575: }
4576:
1.3 raeburn 4577: sub usertype_update_row {
4578: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4579: my $datatable;
4580: my $numinrow = 4;
4581: foreach my $type (@{$types}) {
4582: if (defined($usertypes->{$type})) {
4583: $$rownums ++;
4584: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4585: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4586: '</td><td class="LC_left_item"><table>';
4587: for (my $i=0; $i<@{$fields}; $i++) {
4588: my $rem = $i%($numinrow);
4589: if ($rem == 0) {
4590: if ($i > 0) {
4591: $datatable .= '</tr>';
4592: }
4593: $datatable .= '<tr>';
4594: }
4595: my $check = ' ';
1.39 raeburn 4596: if (ref($settings) eq 'HASH') {
4597: if (ref($settings->{'fields'}) eq 'HASH') {
4598: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4599: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4600: $check = ' checked="checked" ';
4601: }
1.3 raeburn 4602: }
4603: }
4604: }
4605:
4606: if ($i == @{$fields}-1) {
4607: my $colsleft = $numinrow - $rem;
4608: if ($colsleft > 1) {
4609: $datatable .= '<td colspan="'.$colsleft.'">';
4610: } else {
4611: $datatable .= '<td>';
4612: }
4613: } else {
4614: $datatable .= '<td>';
4615: }
1.8 raeburn 4616: $datatable .= '<span class="LC_nobreak"><label>'.
4617: '<input type="checkbox" name="updateable_'.$type.
4618: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4619: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4620: }
4621: $datatable .= '</tr></table></td></tr>';
4622: }
4623: }
4624: return $datatable;
1.1 raeburn 4625: }
4626:
4627: sub modify_login {
1.9 raeburn 4628: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 4629: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4630: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4631: %title = ( coursecatalog => 'Display course catalog',
4632: adminmail => 'Display administrator E-mail address',
4633: newuser => 'Link for visitors to create a user account',
4634: loginheader => 'Log-in box header');
4635: @offon = ('off','on');
1.112 raeburn 4636: if (ref($domconfig{login}) eq 'HASH') {
4637: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4638: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4639: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4640: }
4641: }
4642: }
1.9 raeburn 4643: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4644: \%domconfig,\%loginhash);
1.118 jms 4645: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4646: foreach my $item (@toggles) {
4647: $loginhash{login}{$item} = $env{'form.'.$item};
4648: }
1.41 raeburn 4649: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4650: if (ref($colchanges{'login'}) eq 'HASH') {
4651: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4652: \%loginhash);
4653: }
1.110 raeburn 4654:
1.149 raeburn 4655: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4656: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4657: if (keys(%servers) > 1) {
4658: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4659: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4660: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4661: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4662: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4663: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4664: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4665: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4666: $changes{'loginvia'}{$lonhost} = 1;
4667: } else {
4668: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4669: $changes{'loginvia'}{$lonhost} = 1;
4670: }
4671: } else {
4672: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4673: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4674: $changes{'loginvia'}{$lonhost} = 1;
4675: }
4676: }
4677: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4678: foreach my $item (@loginvia_attribs) {
4679: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4680: }
4681: } else {
4682: foreach my $item (@loginvia_attribs) {
4683: my $new = $env{'form.'.$lonhost.'_'.$item};
4684: if (($item eq 'serverpath') && ($new eq 'custom')) {
4685: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4686: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4687: $new = '/';
4688: }
4689: }
4690: if (($item eq 'custompath') &&
4691: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4692: $new = '';
4693: }
4694: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4695: $changes{'loginvia'}{$lonhost} = 1;
4696: }
4697: if ($item eq 'exempt') {
4698: $new =~ s/^\s+//;
4699: $new =~ s/\s+$//;
4700: my @poss_ips = split(/\s*[,:]\s*/,$new);
4701: my @okips;
4702: foreach my $ip (@poss_ips) {
4703: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4704: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4705: push(@okips,$ip);
4706: }
4707: }
4708: }
4709: if (@okips > 0) {
4710: $new = join(',',@okips);
4711: } else {
4712: $new = '';
4713: }
4714: }
4715: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4716: }
4717: }
1.112 raeburn 4718: } else {
1.128 raeburn 4719: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4720: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4721: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4722: foreach my $item (@loginvia_attribs) {
4723: my $new = $env{'form.'.$lonhost.'_'.$item};
4724: if (($item eq 'serverpath') && ($new eq 'custom')) {
4725: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4726: $new = '/';
4727: }
4728: }
4729: if (($item eq 'custompath') &&
4730: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4731: $new = '';
4732: }
4733: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4734: }
1.110 raeburn 4735: }
4736: }
4737: }
4738: }
1.119 raeburn 4739:
1.160.6.5 raeburn 4740: my $servadm = $r->dir_config('lonAdmEMail');
4741: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4742: if (ref($domconfig{'login'}) eq 'HASH') {
4743: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4744: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4745: if ($lang eq 'nolang') {
4746: push(@currlangs,$lang);
4747: } elsif (defined($langchoices{$lang})) {
4748: push(@currlangs,$lang);
4749: } else {
4750: next;
4751: }
4752: }
4753: }
4754: }
4755: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4756: if (@currlangs > 0) {
4757: foreach my $lang (@currlangs) {
4758: if (grep(/^\Q$lang\E$/,@delurls)) {
4759: $changes{'helpurl'}{$lang} = 1;
4760: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4761: $changes{'helpurl'}{$lang} = 1;
4762: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4763: push(@newlangs,$lang);
4764: } else {
4765: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4766: }
4767: }
4768: }
4769: unless (grep(/^nolang$/,@currlangs)) {
4770: if ($env{'form.loginhelpurl_nolang.filename'}) {
4771: $changes{'helpurl'}{'nolang'} = 1;
4772: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4773: push(@newlangs,'nolang');
4774: }
4775: }
4776: if ($env{'form.loginhelpurl_add_lang'}) {
4777: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4778: ($env{'form.loginhelpurl_add_file.filename'})) {
4779: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4780: $addedfile = $env{'form.loginhelpurl_add_lang'};
4781: }
4782: }
4783: if ((@newlangs > 0) || ($addedfile)) {
4784: my $error;
4785: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4786: if ($configuserok eq 'ok') {
4787: if ($switchserver) {
4788: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4789: } elsif ($author_ok eq 'ok') {
4790: my @allnew = @newlangs;
4791: if ($addedfile ne '') {
4792: push(@allnew,$addedfile);
4793: }
4794: foreach my $lang (@allnew) {
4795: my $formelem = 'loginhelpurl_'.$lang;
4796: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4797: $formelem = 'loginhelpurl_add_file';
4798: }
4799: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4800: "help/$lang",'','',$newfile{$lang});
4801: if ($result eq 'ok') {
4802: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4803: $changes{'helpurl'}{$lang} = 1;
4804: } else {
4805: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4806: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4807: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4808: (!grep(/^\Q$lang\E$/,@delurls))) {
4809:
4810: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4811: }
4812: }
4813: }
4814: } else {
4815: $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);
4816: }
4817: } else {
4818: $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);
4819: }
4820: if ($error) {
4821: &Apache::lonnet::logthis($error);
4822: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4823: }
4824: }
4825: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4826:
4827: my $defaulthelpfile = '/adm/loginproblems.html';
4828: my $defaulttext = &mt('Default in use');
4829:
1.1 raeburn 4830: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4831: $dom);
4832: if ($putresult eq 'ok') {
1.118 jms 4833: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4834: my %defaultchecked = (
4835: 'coursecatalog' => 'on',
4836: 'adminmail' => 'off',
1.43 raeburn 4837: 'newuser' => 'off',
1.42 raeburn 4838: );
1.55 raeburn 4839: if (ref($domconfig{'login'}) eq 'HASH') {
4840: foreach my $item (@toggles) {
4841: if ($defaultchecked{$item} eq 'on') {
4842: if (($domconfig{'login'}{$item} eq '0') &&
4843: ($env{'form.'.$item} eq '1')) {
4844: $changes{$item} = 1;
4845: } elsif (($domconfig{'login'}{$item} eq '' ||
4846: $domconfig{'login'}{$item} eq '1') &&
4847: ($env{'form.'.$item} eq '0')) {
4848: $changes{$item} = 1;
4849: }
4850: } elsif ($defaultchecked{$item} eq 'off') {
4851: if (($domconfig{'login'}{$item} eq '1') &&
4852: ($env{'form.'.$item} eq '0')) {
4853: $changes{$item} = 1;
4854: } elsif (($domconfig{'login'}{$item} eq '' ||
4855: $domconfig{'login'}{$item} eq '0') &&
4856: ($env{'form.'.$item} eq '1')) {
4857: $changes{$item} = 1;
4858: }
1.42 raeburn 4859: }
4860: }
1.41 raeburn 4861: }
1.6 raeburn 4862: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4863: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4864: $resulttext = &mt('Changes made:').'<ul>';
4865: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4866: if ($item eq 'loginvia') {
1.112 raeburn 4867: if (ref($changes{$item}) eq 'HASH') {
4868: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4869: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4870: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4871: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4872: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4873: $protocol = 'http' if ($protocol ne 'https');
4874: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4875:
4876: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4877: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4878: } else {
4879: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4880: }
4881: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4882: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4883: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4884: }
4885: $resulttext .= '</li>';
4886: } else {
4887: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4888: }
1.112 raeburn 4889: } else {
1.128 raeburn 4890: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4891: }
4892: }
1.128 raeburn 4893: $resulttext .= '</ul></li>';
1.112 raeburn 4894: }
1.160.6.5 raeburn 4895: } elsif ($item eq 'helpurl') {
4896: if (ref($changes{$item}) eq 'HASH') {
4897: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4898: if (grep(/^\Q$lang\E$/,@delurls)) {
4899: my ($chg,$link);
4900: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4901: if ($lang eq 'nolang') {
4902: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4903: } else {
4904: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4905: }
4906: $resulttext .= '<li>'.$chg.'</li>';
4907: } else {
4908: my $chg;
4909: if ($lang eq 'nolang') {
4910: $chg = &mt('custom log-in help file for no preferred language');
4911: } else {
4912: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4913: }
4914: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4915: $loginhash{'login'}{'helpurl'}{$lang}.
4916: '?inhibitmenu=yes',$chg,600,500).
4917: '</li>';
4918: }
4919: }
4920: }
4921: } elsif ($item eq 'captcha') {
4922: if (ref($loginhash{'login'}) eq 'HASH') {
4923: my $chgtxt;
4924: if ($loginhash{'login'}{$item} eq 'notused') {
4925: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4926: } else {
4927: my %captchas = &captcha_phrases();
4928: if ($captchas{$loginhash{'login'}{$item}}) {
4929: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4930: } else {
4931: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4932: }
4933: }
4934: $resulttext .= '<li>'.$chgtxt.'</li>';
4935: }
4936: } elsif ($item eq 'recaptchakeys') {
4937: if (ref($loginhash{'login'}) eq 'HASH') {
4938: my ($privkey,$pubkey);
4939: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4940: $pubkey = $loginhash{'login'}{$item}{'public'};
4941: $privkey = $loginhash{'login'}{$item}{'private'};
4942: }
4943: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4944: if (!$pubkey) {
4945: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4946: } else {
4947: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4948: }
4949: if (!$privkey) {
4950: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4951: } else {
4952: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4953: }
4954: $chgtxt .= '</ul>';
4955: $resulttext .= '<li>'.$chgtxt.'</li>';
4956: }
1.41 raeburn 4957: } else {
4958: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4959: }
1.1 raeburn 4960: }
1.6 raeburn 4961: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4962: } else {
4963: $resulttext = &mt('No changes made to log-in page settings');
4964: }
4965: } else {
1.11 albertel 4966: $resulttext = '<span class="LC_error">'.
4967: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4968: }
1.6 raeburn 4969: if ($errors) {
1.9 raeburn 4970: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4971: $errors.'</ul>';
4972: }
4973: return $resulttext;
4974: }
4975:
4976: sub color_font_choices {
4977: my %choices =
4978: &Apache::lonlocal::texthash (
4979: img => "Header",
4980: bgs => "Background colors",
4981: links => "Link colors",
1.55 raeburn 4982: images => "Images",
1.6 raeburn 4983: font => "Font color",
1.97 tempelho 4984: fontmenu => "Font Menu",
1.76 raeburn 4985: pgbg => "Page",
1.6 raeburn 4986: tabbg => "Header",
4987: sidebg => "Border",
4988: link => "Link",
4989: alink => "Active link",
4990: vlink => "Visited link",
4991: );
4992: return %choices;
4993: }
4994:
4995: sub modify_rolecolors {
1.9 raeburn 4996: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4997: my ($resulttext,%rolehash);
4998: $rolehash{'rolecolors'} = {};
1.55 raeburn 4999: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5000: if ($domconfig{'rolecolors'} eq '') {
5001: $domconfig{'rolecolors'} = {};
5002: }
5003: }
1.9 raeburn 5004: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5005: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5006: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5007: $dom);
5008: if ($putresult eq 'ok') {
5009: if (keys(%changes) > 0) {
1.41 raeburn 5010: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5011: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5012: $rolehash{'rolecolors'});
5013: } else {
5014: $resulttext = &mt('No changes made to default color schemes');
5015: }
5016: } else {
1.11 albertel 5017: $resulttext = '<span class="LC_error">'.
5018: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5019: }
5020: if ($errors) {
5021: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5022: $errors.'</ul>';
5023: }
5024: return $resulttext;
5025: }
5026:
5027: sub modify_colors {
1.9 raeburn 5028: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5029: my (%changes,%choices);
1.51 raeburn 5030: my @bgs;
1.6 raeburn 5031: my @links = ('link','alink','vlink');
1.41 raeburn 5032: my @logintext;
1.6 raeburn 5033: my @images;
5034: my $servadm = $r->dir_config('lonAdmEMail');
5035: my $errors;
5036: foreach my $role (@{$roles}) {
5037: if ($role eq 'login') {
1.12 raeburn 5038: %choices = &login_choices();
1.41 raeburn 5039: @logintext = ('textcol','bgcol');
1.12 raeburn 5040: } else {
5041: %choices = &color_font_choices();
1.107 raeburn 5042: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5043: }
5044: if ($role eq 'login') {
1.41 raeburn 5045: @images = ('img','logo','domlogo','login');
1.51 raeburn 5046: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5047: } else {
5048: @images = ('img');
1.51 raeburn 5049: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5050: }
5051: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5052: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5053: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5054: }
1.46 raeburn 5055: my ($configuserok,$author_ok,$switchserver) =
5056: &config_check($dom,$confname,$servadm);
1.9 raeburn 5057: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5058: if (ref($domconfig->{$role}) ne 'HASH') {
5059: $domconfig->{$role} = {};
5060: }
1.8 raeburn 5061: foreach my $img (@images) {
1.70 raeburn 5062: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5063: if (defined($env{'form.login_showlogo_'.$img})) {
5064: $confhash->{$role}{'showlogo'}{$img} = 1;
5065: } else {
5066: $confhash->{$role}{'showlogo'}{$img} = 0;
5067: }
5068: }
1.18 albertel 5069: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5070: && !defined($domconfig->{$role}{$img})
5071: && !$env{'form.'.$role.'_del_'.$img}
5072: && $env{'form.'.$role.'_import_'.$img}) {
5073: # import the old configured image from the .tab setting
5074: # if they haven't provided a new one
5075: $domconfig->{$role}{$img} =
5076: $env{'form.'.$role.'_import_'.$img};
5077: }
1.6 raeburn 5078: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5079: my $error;
1.6 raeburn 5080: if ($configuserok eq 'ok') {
1.9 raeburn 5081: if ($switchserver) {
1.12 raeburn 5082: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5083: } else {
5084: if ($author_ok eq 'ok') {
5085: my ($result,$logourl) =
5086: &publishlogo($r,'upload',$role.'_'.$img,
5087: $dom,$confname,$img,$width,$height);
5088: if ($result eq 'ok') {
5089: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5090: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5091: } else {
1.12 raeburn 5092: $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 5093: }
5094: } else {
1.46 raeburn 5095: $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 5096: }
5097: }
5098: } else {
1.46 raeburn 5099: $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 5100: }
5101: if ($error) {
1.8 raeburn 5102: &Apache::lonnet::logthis($error);
1.11 albertel 5103: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5104: }
5105: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5106: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5107: my $error;
5108: if ($configuserok eq 'ok') {
5109: # is confname an author?
5110: if ($switchserver eq '') {
5111: if ($author_ok eq 'ok') {
5112: my ($result,$logourl) =
5113: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5114: $dom,$confname,$img,$width,$height);
5115: if ($result eq 'ok') {
5116: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5117: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5118: }
5119: }
5120: }
5121: }
1.6 raeburn 5122: }
5123: }
5124: }
5125: if (ref($domconfig) eq 'HASH') {
5126: if (ref($domconfig->{$role}) eq 'HASH') {
5127: foreach my $img (@images) {
5128: if ($domconfig->{$role}{$img} ne '') {
5129: if ($env{'form.'.$role.'_del_'.$img}) {
5130: $confhash->{$role}{$img} = '';
1.12 raeburn 5131: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5132: } else {
1.9 raeburn 5133: if ($confhash->{$role}{$img} eq '') {
5134: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5135: }
1.6 raeburn 5136: }
5137: } else {
5138: if ($env{'form.'.$role.'_del_'.$img}) {
5139: $confhash->{$role}{$img} = '';
1.12 raeburn 5140: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5141: }
5142: }
1.70 raeburn 5143: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5144: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5145: if ($confhash->{$role}{'showlogo'}{$img} ne
5146: $domconfig->{$role}{'showlogo'}{$img}) {
5147: $changes{$role}{'showlogo'}{$img} = 1;
5148: }
5149: } else {
5150: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5151: $changes{$role}{'showlogo'}{$img} = 1;
5152: }
5153: }
5154: }
5155: }
1.6 raeburn 5156: if ($domconfig->{$role}{'font'} ne '') {
5157: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5158: $changes{$role}{'font'} = 1;
5159: }
5160: } else {
5161: if ($confhash->{$role}{'font'}) {
5162: $changes{$role}{'font'} = 1;
5163: }
5164: }
1.107 raeburn 5165: if ($role ne 'login') {
5166: if ($domconfig->{$role}{'fontmenu'} ne '') {
5167: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5168: $changes{$role}{'fontmenu'} = 1;
5169: }
5170: } else {
5171: if ($confhash->{$role}{'fontmenu'}) {
5172: $changes{$role}{'fontmenu'} = 1;
5173: }
1.97 tempelho 5174: }
5175: }
1.6 raeburn 5176: foreach my $item (@bgs) {
5177: if ($domconfig->{$role}{$item} ne '') {
5178: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5179: $changes{$role}{'bgs'}{$item} = 1;
5180: }
5181: } else {
5182: if ($confhash->{$role}{$item}) {
5183: $changes{$role}{'bgs'}{$item} = 1;
5184: }
5185: }
5186: }
5187: foreach my $item (@links) {
5188: if ($domconfig->{$role}{$item} ne '') {
5189: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5190: $changes{$role}{'links'}{$item} = 1;
5191: }
5192: } else {
5193: if ($confhash->{$role}{$item}) {
5194: $changes{$role}{'links'}{$item} = 1;
5195: }
5196: }
5197: }
1.41 raeburn 5198: foreach my $item (@logintext) {
5199: if ($domconfig->{$role}{$item} ne '') {
5200: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5201: $changes{$role}{'logintext'}{$item} = 1;
5202: }
5203: } else {
5204: if ($confhash->{$role}{$item}) {
5205: $changes{$role}{'logintext'}{$item} = 1;
5206: }
5207: }
5208: }
1.6 raeburn 5209: } else {
5210: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5211: \@logintext,$confhash,\%changes);
1.6 raeburn 5212: }
5213: } else {
5214: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5215: \@logintext,$confhash,\%changes);
1.6 raeburn 5216: }
5217: }
5218: return ($errors,%changes);
5219: }
5220:
1.46 raeburn 5221: sub config_check {
5222: my ($dom,$confname,$servadm) = @_;
5223: my ($configuserok,$author_ok,$switchserver,%currroles);
5224: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5225: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5226: $confname,$servadm);
5227: if ($configuserok eq 'ok') {
5228: $switchserver = &check_switchserver($dom,$confname);
5229: if ($switchserver eq '') {
5230: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5231: }
5232: }
5233: return ($configuserok,$author_ok,$switchserver);
5234: }
5235:
1.6 raeburn 5236: sub default_change_checker {
1.41 raeburn 5237: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5238: foreach my $item (@{$links}) {
5239: if ($confhash->{$role}{$item}) {
5240: $changes->{$role}{'links'}{$item} = 1;
5241: }
5242: }
5243: foreach my $item (@{$bgs}) {
5244: if ($confhash->{$role}{$item}) {
5245: $changes->{$role}{'bgs'}{$item} = 1;
5246: }
5247: }
1.41 raeburn 5248: foreach my $item (@{$logintext}) {
5249: if ($confhash->{$role}{$item}) {
5250: $changes->{$role}{'logintext'}{$item} = 1;
5251: }
5252: }
1.6 raeburn 5253: foreach my $img (@{$images}) {
5254: if ($env{'form.'.$role.'_del_'.$img}) {
5255: $confhash->{$role}{$img} = '';
1.12 raeburn 5256: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5257: }
1.70 raeburn 5258: if ($role eq 'login') {
5259: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5260: $changes->{$role}{'showlogo'}{$img} = 1;
5261: }
5262: }
1.6 raeburn 5263: }
5264: if ($confhash->{$role}{'font'}) {
5265: $changes->{$role}{'font'} = 1;
5266: }
1.48 raeburn 5267: }
1.6 raeburn 5268:
5269: sub display_colorchgs {
5270: my ($dom,$changes,$roles,$confhash) = @_;
5271: my (%choices,$resulttext);
5272: if (!grep(/^login$/,@{$roles})) {
5273: $resulttext = &mt('Changes made:').'<br />';
5274: }
5275: foreach my $role (@{$roles}) {
5276: if ($role eq 'login') {
5277: %choices = &login_choices();
5278: } else {
5279: %choices = &color_font_choices();
5280: }
5281: if (ref($changes->{$role}) eq 'HASH') {
5282: if ($role ne 'login') {
5283: $resulttext .= '<h4>'.&mt($role).'</h4>';
5284: }
5285: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5286: if ($role ne 'login') {
5287: $resulttext .= '<ul>';
5288: }
5289: if (ref($changes->{$role}{$key}) eq 'HASH') {
5290: if ($role ne 'login') {
5291: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5292: }
5293: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5294: if (($role eq 'login') && ($key eq 'showlogo')) {
5295: if ($confhash->{$role}{$key}{$item}) {
5296: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5297: } else {
5298: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5299: }
5300: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5301: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5302: } else {
1.12 raeburn 5303: my $newitem = $confhash->{$role}{$item};
5304: if ($key eq 'images') {
5305: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5306: }
5307: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5308: }
5309: }
5310: if ($role ne 'login') {
5311: $resulttext .= '</ul></li>';
5312: }
5313: } else {
5314: if ($confhash->{$role}{$key} eq '') {
5315: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5316: } else {
5317: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5318: }
5319: }
5320: if ($role ne 'login') {
5321: $resulttext .= '</ul>';
5322: }
5323: }
5324: }
5325: }
1.3 raeburn 5326: return $resulttext;
1.1 raeburn 5327: }
5328:
1.9 raeburn 5329: sub thumb_dimensions {
5330: return ('200','50');
5331: }
5332:
1.16 raeburn 5333: sub check_dimensions {
5334: my ($inputfile) = @_;
5335: my ($fullwidth,$fullheight);
5336: if ($inputfile =~ m|^[/\w.\-]+$|) {
5337: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5338: my $imageinfo = <PIPE>;
5339: if (!close(PIPE)) {
5340: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5341: }
5342: chomp($imageinfo);
5343: my ($fullsize) =
1.21 raeburn 5344: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5345: if ($fullsize) {
5346: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5347: }
5348: }
5349: }
5350: return ($fullwidth,$fullheight);
5351: }
5352:
1.9 raeburn 5353: sub check_configuser {
5354: my ($uhome,$dom,$confname,$servadm) = @_;
5355: my ($configuserok,%currroles);
5356: if ($uhome eq 'no_host') {
5357: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5358: my $configpass = &LONCAPA::Enrollment::create_password();
5359: $configuserok =
5360: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5361: $configpass,'','','','','',undef,$servadm);
5362: } else {
5363: $configuserok = 'ok';
5364: %currroles =
5365: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5366: }
5367: return ($configuserok,%currroles);
5368: }
5369:
5370: sub check_authorstatus {
5371: my ($dom,$confname,%currroles) = @_;
5372: my $author_ok;
1.40 raeburn 5373: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5374: my $start = time;
5375: my $end = 0;
5376: $author_ok =
5377: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5378: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5379: } else {
5380: $author_ok = 'ok';
5381: }
5382: return $author_ok;
5383: }
5384:
5385: sub publishlogo {
1.46 raeburn 5386: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5387: my ($output,$fname,$logourl);
5388: if ($action eq 'upload') {
5389: $fname=$env{'form.'.$formname.'.filename'};
5390: chop($env{'form.'.$formname});
5391: } else {
5392: ($fname) = ($formname =~ /([^\/]+)$/);
5393: }
1.46 raeburn 5394: if ($savefileas ne '') {
5395: $fname = $savefileas;
5396: }
1.9 raeburn 5397: $fname=&Apache::lonnet::clean_filename($fname);
5398: # See if there is anything left
5399: unless ($fname) { return ('error: no uploaded file'); }
5400: $fname="$subdir/$fname";
1.160.6.5 raeburn 5401: my $docroot=$r->dir_config('lonDocRoot');
5402: my $filepath="$docroot/priv";
5403: my $relpath = "$dom/$confname";
1.9 raeburn 5404: my ($fnamepath,$file,$fetchthumb);
5405: $file=$fname;
5406: if ($fname=~m|/|) {
5407: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5408: }
1.160.6.5 raeburn 5409: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5410: my $count;
1.160.6.5 raeburn 5411: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5412: $filepath.="/$parts[$count]";
5413: if ((-e $filepath)!=1) {
5414: mkdir($filepath,02770);
5415: }
5416: }
5417: # Check for bad extension and disallow upload
5418: if ($file=~/\.(\w+)$/ &&
5419: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5420: $output =
5421: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5422: } elsif ($file=~/\.(\w+)$/ &&
5423: !defined(&Apache::loncommon::fileembstyle($1))) {
5424: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5425: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5426: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 5427: } elsif (-d "$filepath/$file") {
5428: $output = &mt('File name is a directory name - rename the file and re-upload');
5429: } else {
5430: my $source = $filepath.'/'.$file;
5431: my $logfile;
5432: if (!open($logfile,">>$source".'.log')) {
5433: return (&mt('No write permission to Construction Space'));
5434: }
5435: print $logfile
5436: "\n================= Publish ".localtime()." ================\n".
5437: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5438: # Save the file
5439: if (!open(FH,'>'.$source)) {
5440: &Apache::lonnet::logthis('Failed to create '.$source);
5441: return (&mt('Failed to create file'));
5442: }
5443: if ($action eq 'upload') {
5444: if (!print FH ($env{'form.'.$formname})) {
5445: &Apache::lonnet::logthis('Failed to write to '.$source);
5446: return (&mt('Failed to write file'));
5447: }
5448: } else {
5449: my $original = &Apache::lonnet::filelocation('',$formname);
5450: if(!copy($original,$source)) {
5451: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5452: return (&mt('Failed to write file'));
5453: }
5454: }
5455: close(FH);
5456: chmod(0660, $source); # Permissions to rw-rw---.
5457:
5458: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5459: my $copyfile=$targetdir.'/'.$file;
5460:
5461: my @parts=split(/\//,$targetdir);
5462: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5463: for (my $count=5;$count<=$#parts;$count++) {
5464: $path.="/$parts[$count]";
5465: if (!-e $path) {
5466: print $logfile "\nCreating directory ".$path;
5467: mkdir($path,02770);
5468: }
5469: }
5470: my $versionresult;
5471: if (-e $copyfile) {
5472: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5473: } else {
5474: $versionresult = 'ok';
5475: }
5476: if ($versionresult eq 'ok') {
5477: if (copy($source,$copyfile)) {
5478: print $logfile "\nCopied original source to ".$copyfile."\n";
5479: $output = 'ok';
5480: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5481: push(@{$modified_urls},[$copyfile,$source]);
5482: my $metaoutput =
5483: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5484: unless ($registered_cleanup) {
5485: my $handlers = $r->get_handlers('PerlCleanupHandler');
5486: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5487: $registered_cleanup=1;
5488: }
1.9 raeburn 5489: } else {
5490: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5491: $output = &mt('Failed to copy file to RES space').", $!";
5492: }
5493: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5494: my $inputfile = $filepath.'/'.$file;
5495: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5496: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5497: if ($fullwidth ne '' && $fullheight ne '') {
5498: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5499: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5500: system("convert -sample $thumbsize $inputfile $outfile");
5501: chmod(0660, $filepath.'/tn-'.$file);
5502: if (-e $outfile) {
5503: my $copyfile=$targetdir.'/tn-'.$file;
5504: if (copy($outfile,$copyfile)) {
5505: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5506: my $thumb_metaoutput =
5507: &write_metadata($dom,$confname,$formname,
5508: $targetdir,'tn-'.$file,$logfile);
5509: push(@{$modified_urls},[$copyfile,$outfile]);
5510: unless ($registered_cleanup) {
5511: my $handlers = $r->get_handlers('PerlCleanupHandler');
5512: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5513: $registered_cleanup=1;
5514: }
1.16 raeburn 5515: } else {
5516: print $logfile "\nUnable to write ".$copyfile.
5517: ':'.$!."\n";
5518: }
5519: }
1.9 raeburn 5520: }
5521: }
5522: }
5523: } else {
5524: $output = $versionresult;
5525: }
5526: }
5527: return ($output,$logourl);
5528: }
5529:
5530: sub logo_versioning {
5531: my ($targetdir,$file,$logfile) = @_;
5532: my $target = $targetdir.'/'.$file;
5533: my ($maxversion,$fn,$extn,$output);
5534: $maxversion = 0;
5535: if ($file =~ /^(.+)\.(\w+)$/) {
5536: $fn=$1;
5537: $extn=$2;
5538: }
5539: opendir(DIR,$targetdir);
5540: while (my $filename=readdir(DIR)) {
5541: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5542: $maxversion=($1>$maxversion)?$1:$maxversion;
5543: }
5544: }
5545: $maxversion++;
5546: print $logfile "\nCreating old version ".$maxversion."\n";
5547: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5548: if (copy($target,$copyfile)) {
5549: print $logfile "Copied old target to ".$copyfile."\n";
5550: $copyfile=$copyfile.'.meta';
5551: if (copy($target.'.meta',$copyfile)) {
5552: print $logfile "Copied old target metadata to ".$copyfile."\n";
5553: $output = 'ok';
5554: } else {
5555: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5556: $output = &mt('Failed to copy old meta').", $!, ";
5557: }
5558: } else {
5559: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5560: $output = &mt('Failed to copy old target').", $!, ";
5561: }
5562: return $output;
5563: }
5564:
5565: sub write_metadata {
5566: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5567: my (%metadatafields,%metadatakeys,$output);
5568: $metadatafields{'title'}=$formname;
5569: $metadatafields{'creationdate'}=time;
5570: $metadatafields{'lastrevisiondate'}=time;
5571: $metadatafields{'copyright'}='public';
5572: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5573: $env{'user.domain'};
5574: $metadatafields{'authorspace'}=$confname.':'.$dom;
5575: $metadatafields{'domain'}=$dom;
5576: {
5577: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5578: my $mfh;
1.155 raeburn 5579: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5580: foreach (sort keys %metadatafields) {
5581: unless ($_=~/\./) {
5582: my $unikey=$_;
5583: $unikey=~/^([A-Za-z]+)/;
5584: my $tag=$1;
5585: $tag=~tr/A-Z/a-z/;
5586: print $mfh "\n\<$tag";
5587: foreach (split(/\,/,$metadatakeys{$unikey})) {
5588: my $value=$metadatafields{$unikey.'.'.$_};
5589: $value=~s/\"/\'\'/g;
5590: print $mfh ' '.$_.'="'.$value.'"';
5591: }
5592: print $mfh '>'.
5593: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5594: .'</'.$tag.'>';
5595: }
5596: }
5597: $output = 'ok';
5598: print $logfile "\nWrote metadata";
5599: close($mfh);
5600: } else {
5601: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5602: $output = &mt('Could not write metadata');
5603: }
5604: }
1.155 raeburn 5605: return $output;
5606: }
5607:
5608: sub notifysubscribed {
5609: foreach my $targetsource (@{$modified_urls}){
5610: next unless (ref($targetsource) eq 'ARRAY');
5611: my ($target,$source)=@{$targetsource};
5612: if ($source ne '') {
5613: if (open(my $logfh,'>>'.$source.'.log')) {
5614: print $logfh "\nCleanup phase: Notifications\n";
5615: my @subscribed=&subscribed_hosts($target);
5616: foreach my $subhost (@subscribed) {
5617: print $logfh "\nNotifying host ".$subhost.':';
5618: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5619: print $logfh $reply;
5620: }
5621: my @subscribedmeta=&subscribed_hosts("$target.meta");
5622: foreach my $subhost (@subscribedmeta) {
5623: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5624: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5625: $subhost);
5626: print $logfh $reply;
5627: }
5628: print $logfh "\n============ Done ============\n";
1.160 raeburn 5629: close($logfh);
1.155 raeburn 5630: }
5631: }
5632: }
5633: return OK;
5634: }
5635:
5636: sub subscribed_hosts {
5637: my ($target) = @_;
5638: my @subscribed;
5639: if (open(my $fh,"<$target.subscription")) {
5640: while (my $subline=<$fh>) {
5641: if ($subline =~ /^($match_lonid):/) {
5642: my $host = $1;
5643: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5644: unless (grep(/^\Q$host\E$/,@subscribed)) {
5645: push(@subscribed,$host);
5646: }
5647: }
5648: }
5649: }
5650: }
5651: return @subscribed;
1.9 raeburn 5652: }
5653:
5654: sub check_switchserver {
5655: my ($dom,$confname) = @_;
5656: my ($allowed,$switchserver);
5657: my $home = &Apache::lonnet::homeserver($confname,$dom);
5658: if ($home eq 'no_host') {
5659: $home = &Apache::lonnet::domain($dom,'primary');
5660: }
5661: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5662: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5663: if (!$allowed) {
1.160.6.11 raeburn 5664: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5665: }
5666: return $switchserver;
5667: }
5668:
1.1 raeburn 5669: sub modify_quotas {
1.86 raeburn 5670: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5671: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5672: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5673: if ($action eq 'quotas') {
5674: $context = 'tools';
5675: } else {
5676: $context = $action;
5677: }
5678: if ($context eq 'requestcourses') {
1.98 raeburn 5679: @usertools = ('official','unofficial','community');
1.106 raeburn 5680: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5681: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5682: %titles = &courserequest_titles();
5683: $toolregexp = join('|',@usertools);
5684: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5685: } elsif ($context eq 'requestauthor') {
5686: @usertools = ('author');
5687: %titles = &authorrequest_titles();
1.86 raeburn 5688: } else {
1.160.6.4 raeburn 5689: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5690: %titles = &tool_titles();
1.86 raeburn 5691: }
1.72 raeburn 5692: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5693: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5694: foreach my $key (keys(%env)) {
1.101 raeburn 5695: if ($context eq 'requestcourses') {
5696: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5697: my $item = $1;
5698: my $type = $2;
5699: if ($type =~ /^limit_(.+)/) {
5700: $limithash{$item}{$1} = $env{$key};
5701: } else {
5702: $confhash{$item}{$type} = $env{$key};
5703: }
5704: }
1.160.6.5 raeburn 5705: } elsif ($context eq 'requestauthor') {
5706: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5707: $confhash{$1} = $env{$key};
5708: }
1.101 raeburn 5709: } else {
1.86 raeburn 5710: if ($key =~ /^form\.quota_(.+)$/) {
5711: $confhash{'defaultquota'}{$1} = $env{$key};
5712: }
1.101 raeburn 5713: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5714: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5715: }
1.72 raeburn 5716: }
5717: }
1.160.6.5 raeburn 5718: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5719: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5720: @approvalnotify = sort(@approvalnotify);
5721: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5722: if (ref($domconfig{$action}) eq 'HASH') {
5723: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5724: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5725: $changes{'notify'}{'approval'} = 1;
5726: }
5727: } else {
1.144 raeburn 5728: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5729: $changes{'notify'}{'approval'} = 1;
5730: }
5731: }
5732: } else {
1.144 raeburn 5733: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5734: $changes{'notify'}{'approval'} = 1;
5735: }
5736: }
5737: } else {
1.86 raeburn 5738: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5739: }
1.72 raeburn 5740: foreach my $item (@usertools) {
5741: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5742: my $unset;
1.101 raeburn 5743: if ($context eq 'requestcourses') {
1.104 raeburn 5744: $unset = '0';
5745: if ($type eq '_LC_adv') {
5746: $unset = '';
5747: }
1.101 raeburn 5748: if ($confhash{$item}{$type} eq 'autolimit') {
5749: $confhash{$item}{$type} .= '=';
5750: unless ($limithash{$item}{$type} =~ /\D/) {
5751: $confhash{$item}{$type} .= $limithash{$item}{$type};
5752: }
5753: }
1.160.6.5 raeburn 5754: } elsif ($context eq 'requestauthor') {
5755: $unset = '0';
5756: if ($type eq '_LC_adv') {
5757: $unset = '';
5758: }
1.72 raeburn 5759: } else {
1.101 raeburn 5760: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5761: $confhash{$item}{$type} = 1;
5762: } else {
5763: $confhash{$item}{$type} = 0;
5764: }
1.72 raeburn 5765: }
1.86 raeburn 5766: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5767: if ($action eq 'requestauthor') {
5768: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5769: $changes{$type} = 1;
5770: }
5771: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5772: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5773: $changes{$item}{$type} = 1;
5774: }
5775: } else {
5776: if ($context eq 'requestcourses') {
1.104 raeburn 5777: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5778: $changes{$item}{$type} = 1;
5779: }
5780: } else {
5781: if (!$confhash{$item}{$type}) {
5782: $changes{$item}{$type} = 1;
5783: }
5784: }
5785: }
5786: } else {
5787: if ($context eq 'requestcourses') {
1.104 raeburn 5788: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5789: $changes{$item}{$type} = 1;
5790: }
1.160.6.5 raeburn 5791: } elsif ($context eq 'requestauthor') {
5792: if ($confhash{$type} ne $unset) {
5793: $changes{$type} = 1;
5794: }
1.72 raeburn 5795: } else {
5796: if (!$confhash{$item}{$type}) {
5797: $changes{$item}{$type} = 1;
5798: }
5799: }
5800: }
1.1 raeburn 5801: }
5802: }
1.160.6.5 raeburn 5803: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5804: if (ref($domconfig{'quotas'}) eq 'HASH') {
5805: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5806: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5807: if (exists($confhash{'defaultquota'}{$key})) {
5808: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5809: $changes{'defaultquota'}{$key} = 1;
5810: }
5811: } else {
5812: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5813: }
5814: }
1.86 raeburn 5815: } else {
5816: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5817: if (exists($confhash{'defaultquota'}{$key})) {
5818: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5819: $changes{'defaultquota'}{$key} = 1;
5820: }
5821: } else {
5822: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5823: }
1.1 raeburn 5824: }
5825: }
5826: }
1.86 raeburn 5827: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5828: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5829: if (ref($domconfig{'quotas'}) eq 'HASH') {
5830: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5831: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5832: $changes{'defaultquota'}{$key} = 1;
5833: }
5834: } else {
5835: if (!exists($domconfig{'quotas'}{$key})) {
5836: $changes{'defaultquota'}{$key} = 1;
5837: }
1.72 raeburn 5838: }
5839: } else {
1.86 raeburn 5840: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5841: }
1.1 raeburn 5842: }
5843: }
5844: }
1.72 raeburn 5845:
1.160.6.5 raeburn 5846: if ($context eq 'requestauthor') {
5847: $domdefaults{'requestauthor'} = \%confhash;
5848: } else {
5849: foreach my $key (keys(%confhash)) {
5850: $domdefaults{$key} = $confhash{$key};
5851: }
1.72 raeburn 5852: }
1.160.6.5 raeburn 5853:
1.1 raeburn 5854: my %quotahash = (
1.86 raeburn 5855: $action => { %confhash }
1.1 raeburn 5856: );
5857: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5858: $dom);
5859: if ($putresult eq 'ok') {
5860: if (keys(%changes) > 0) {
1.72 raeburn 5861: my $cachetime = 24*60*60;
5862: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5863:
1.1 raeburn 5864: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 5865: unless (($context eq 'requestcourses') ||
5866: ($context eq 'requestauthor')) {
1.86 raeburn 5867: if (ref($changes{'defaultquota'}) eq 'HASH') {
5868: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5869: foreach my $type (@{$types},'default') {
5870: if (defined($changes{'defaultquota'}{$type})) {
5871: my $typetitle = $usertypes->{$type};
5872: if ($type eq 'default') {
5873: $typetitle = $othertitle;
5874: }
5875: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5876: }
5877: }
1.86 raeburn 5878: $resulttext .= '</ul></li>';
1.72 raeburn 5879: }
5880: }
1.80 raeburn 5881: my %newenv;
1.72 raeburn 5882: foreach my $item (@usertools) {
1.160.6.5 raeburn 5883: my (%haschgs,%inconf);
5884: if ($context eq 'requestauthor') {
5885: %haschgs = %changes;
5886: %inconf = %confhash;
5887: } else {
5888: if (ref($changes{$item}) eq 'HASH') {
5889: %haschgs = %{$changes{$item}};
5890: }
5891: if (ref($confhash{$item}) eq 'HASH') {
5892: %inconf = %{$confhash{$item}};
5893: }
5894: }
5895: if (keys(%haschgs) > 0) {
1.80 raeburn 5896: my $newacc =
5897: &Apache::lonnet::usertools_access($env{'user.name'},
5898: $env{'user.domain'},
1.86 raeburn 5899: $item,'reload',$context);
1.160.6.5 raeburn 5900: if (($context eq 'requestcourses') ||
5901: ($context eq 'requestauthor')) {
1.108 raeburn 5902: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5903: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5904: }
5905: } else {
5906: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5907: $newenv{'environment.availabletools.'.$item} = $newacc;
5908: }
1.80 raeburn 5909: }
1.160.6.5 raeburn 5910: unless ($context eq 'requestauthor') {
5911: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5912: }
1.72 raeburn 5913: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 5914: if ($haschgs{$type}) {
1.72 raeburn 5915: my $typetitle = $usertypes->{$type};
5916: if ($type eq 'default') {
5917: $typetitle = $othertitle;
5918: } elsif ($type eq '_LC_adv') {
5919: $typetitle = 'LON-CAPA Advanced Users';
5920: }
1.160.6.5 raeburn 5921: if ($inconf{$type}) {
1.101 raeburn 5922: if ($context eq 'requestcourses') {
5923: my $cond;
1.160.6.5 raeburn 5924: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5925: if ($1 eq '') {
5926: $cond = &mt('(Automatic processing of any request).');
5927: } else {
5928: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5929: }
5930: } else {
1.160.6.5 raeburn 5931: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5932: }
5933: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 5934: } elsif ($context eq 'requestauthor') {
5935: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5936: $titles{$inconf{$type}},$typetitle);
5937:
1.101 raeburn 5938: } else {
5939: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5940: }
1.72 raeburn 5941: } else {
1.104 raeburn 5942: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 5943: if ($inconf{$type} eq '0') {
1.104 raeburn 5944: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5945: } else {
5946: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5947: }
5948: } else {
5949: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5950: }
1.72 raeburn 5951: }
5952: }
1.26 raeburn 5953: }
1.160.6.5 raeburn 5954: unless ($context eq 'requestauthor') {
5955: $resulttext .= '</ul></li>';
5956: }
1.26 raeburn 5957: }
1.1 raeburn 5958: }
1.160.6.5 raeburn 5959: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5960: if (ref($changes{'notify'}) eq 'HASH') {
5961: if ($changes{'notify'}{'approval'}) {
5962: if (ref($confhash{'notify'}) eq 'HASH') {
5963: if ($confhash{'notify'}{'approval'}) {
5964: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5965: } else {
1.160.6.5 raeburn 5966: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5967: }
5968: }
5969: }
5970: }
5971: }
1.1 raeburn 5972: $resulttext .= '</ul>';
1.80 raeburn 5973: if (keys(%newenv)) {
5974: &Apache::lonnet::appenv(\%newenv);
5975: }
1.1 raeburn 5976: } else {
1.86 raeburn 5977: if ($context eq 'requestcourses') {
5978: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 5979: } elsif ($context eq 'requestauthor') {
5980: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5981: } else {
1.90 weissno 5982: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5983: }
1.1 raeburn 5984: }
5985: } else {
1.11 albertel 5986: $resulttext = '<span class="LC_error">'.
5987: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5988: }
1.3 raeburn 5989: return $resulttext;
1.1 raeburn 5990: }
5991:
1.3 raeburn 5992: sub modify_autoenroll {
5993: my ($dom,%domconfig) = @_;
1.1 raeburn 5994: my ($resulttext,%changes);
5995: my %currautoenroll;
5996: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5997: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
5998: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
5999: }
6000: }
6001: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6002: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6003: sender => 'Sender for notification messages',
6004: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6005: my @offon = ('off','on');
1.17 raeburn 6006: my $sender_uname = $env{'form.sender_uname'};
6007: my $sender_domain = $env{'form.sender_domain'};
6008: if ($sender_domain eq '') {
6009: $sender_uname = '';
6010: } elsif ($sender_uname eq '') {
6011: $sender_domain = '';
6012: }
1.129 raeburn 6013: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6014: my %autoenrollhash = (
1.129 raeburn 6015: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6016: 'sender_uname' => $sender_uname,
6017: 'sender_domain' => $sender_domain,
6018: 'co-owners' => $coowners,
1.1 raeburn 6019: }
6020: );
1.4 raeburn 6021: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6022: $dom);
1.1 raeburn 6023: if ($putresult eq 'ok') {
6024: if (exists($currautoenroll{'run'})) {
6025: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6026: $changes{'run'} = 1;
6027: }
6028: } elsif ($autorun) {
6029: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6030: $changes{'run'} = 1;
1.1 raeburn 6031: }
6032: }
1.17 raeburn 6033: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6034: $changes{'sender'} = 1;
6035: }
1.17 raeburn 6036: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6037: $changes{'sender'} = 1;
6038: }
1.129 raeburn 6039: if ($currautoenroll{'co-owners'} ne '') {
6040: if ($currautoenroll{'co-owners'} ne $coowners) {
6041: $changes{'coowners'} = 1;
6042: }
6043: } elsif ($coowners) {
6044: $changes{'coowners'} = 1;
6045: }
1.1 raeburn 6046: if (keys(%changes) > 0) {
6047: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6048: if ($changes{'run'}) {
1.1 raeburn 6049: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6050: }
6051: if ($changes{'sender'}) {
1.17 raeburn 6052: if ($sender_uname eq '' || $sender_domain eq '') {
6053: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6054: } else {
6055: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6056: }
1.1 raeburn 6057: }
1.129 raeburn 6058: if ($changes{'coowners'}) {
6059: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6060: &Apache::loncommon::devalidate_domconfig_cache($dom);
6061: }
1.1 raeburn 6062: $resulttext .= '</ul>';
6063: } else {
6064: $resulttext = &mt('No changes made to auto-enrollment settings');
6065: }
6066: } else {
1.11 albertel 6067: $resulttext = '<span class="LC_error">'.
6068: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6069: }
1.3 raeburn 6070: return $resulttext;
1.1 raeburn 6071: }
6072:
6073: sub modify_autoupdate {
1.3 raeburn 6074: my ($dom,%domconfig) = @_;
1.1 raeburn 6075: my ($resulttext,%currautoupdate,%fields,%changes);
6076: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6077: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6078: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6079: }
6080: }
6081: my @offon = ('off','on');
6082: my %title = &Apache::lonlocal::texthash (
6083: run => 'Auto-update:',
6084: classlists => 'Updates to user information in classlists?'
6085: );
1.44 raeburn 6086: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6087: my %fieldtitles = &Apache::lonlocal::texthash (
6088: id => 'Student/Employee ID',
1.20 raeburn 6089: permanentemail => 'E-mail address',
1.1 raeburn 6090: lastname => 'Last Name',
6091: firstname => 'First Name',
6092: middlename => 'Middle Name',
1.132 raeburn 6093: generation => 'Generation',
1.1 raeburn 6094: );
1.142 raeburn 6095: $othertitle = &mt('All users');
1.1 raeburn 6096: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6097: $othertitle = &mt('Other users');
1.1 raeburn 6098: }
6099: foreach my $key (keys(%env)) {
6100: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6101: my ($usertype,$item) = ($1,$2);
6102: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6103: if ($usertype eq 'default') {
6104: push(@{$fields{$1}},$2);
6105: } elsif (ref($types) eq 'ARRAY') {
6106: if (grep(/^\Q$usertype\E$/,@{$types})) {
6107: push(@{$fields{$1}},$2);
6108: }
6109: }
6110: }
1.1 raeburn 6111: }
6112: }
1.131 raeburn 6113: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6114: @lockablenames = sort(@lockablenames);
6115: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6116: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6117: if (@changed) {
6118: $changes{'lockablenames'} = 1;
6119: }
6120: } else {
6121: if (@lockablenames) {
6122: $changes{'lockablenames'} = 1;
6123: }
6124: }
1.1 raeburn 6125: my %updatehash = (
6126: autoupdate => { run => $env{'form.autoupdate_run'},
6127: classlists => $env{'form.classlists'},
6128: fields => {%fields},
1.131 raeburn 6129: lockablenames => \@lockablenames,
1.1 raeburn 6130: }
6131: );
6132: foreach my $key (keys(%currautoupdate)) {
6133: if (($key eq 'run') || ($key eq 'classlists')) {
6134: if (exists($updatehash{autoupdate}{$key})) {
6135: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6136: $changes{$key} = 1;
6137: }
6138: }
6139: } elsif ($key eq 'fields') {
6140: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6141: foreach my $item (@{$types},'default') {
1.1 raeburn 6142: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6143: my $change = 0;
6144: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6145: if (!exists($fields{$item})) {
6146: $change = 1;
1.132 raeburn 6147: last;
1.1 raeburn 6148: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6149: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6150: $change = 1;
1.132 raeburn 6151: last;
1.1 raeburn 6152: }
6153: }
6154: }
6155: if ($change) {
6156: push(@{$changes{$key}},$item);
6157: }
1.26 raeburn 6158: }
1.1 raeburn 6159: }
6160: }
1.131 raeburn 6161: } elsif ($key eq 'lockablenames') {
6162: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6163: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6164: if (@changed) {
6165: $changes{'lockablenames'} = 1;
6166: }
6167: } else {
6168: if (@lockablenames) {
6169: $changes{'lockablenames'} = 1;
6170: }
6171: }
6172: }
6173: }
6174: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6175: if (@lockablenames) {
6176: $changes{'lockablenames'} = 1;
1.1 raeburn 6177: }
6178: }
1.26 raeburn 6179: foreach my $item (@{$types},'default') {
6180: if (defined($fields{$item})) {
6181: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6182: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6183: my $change = 0;
6184: if (ref($fields{$item}) eq 'ARRAY') {
6185: foreach my $type (@{$fields{$item}}) {
6186: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6187: $change = 1;
6188: last;
6189: }
6190: }
6191: }
6192: if ($change) {
6193: push(@{$changes{'fields'}},$item);
6194: }
6195: } else {
1.26 raeburn 6196: push(@{$changes{'fields'}},$item);
6197: }
6198: } else {
6199: push(@{$changes{'fields'}},$item);
1.1 raeburn 6200: }
6201: }
6202: }
6203: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6204: $dom);
6205: if ($putresult eq 'ok') {
6206: if (keys(%changes) > 0) {
6207: $resulttext = &mt('Changes made:').'<ul>';
6208: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6209: if ($key eq 'lockablenames') {
6210: $resulttext .= '<li>';
6211: if (@lockablenames) {
6212: $usertypes->{'default'} = $othertitle;
6213: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6214: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6215: } else {
6216: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6217: }
6218: $resulttext .= '</li>';
6219: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6220: foreach my $item (@{$changes{$key}}) {
6221: my @newvalues;
6222: foreach my $type (@{$fields{$item}}) {
6223: push(@newvalues,$fieldtitles{$type});
6224: }
1.3 raeburn 6225: my $newvaluestr;
6226: if (@newvalues > 0) {
6227: $newvaluestr = join(', ',@newvalues);
6228: } else {
6229: $newvaluestr = &mt('none');
1.6 raeburn 6230: }
1.1 raeburn 6231: if ($item eq 'default') {
1.26 raeburn 6232: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6233: } else {
1.26 raeburn 6234: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6235: }
6236: }
6237: } else {
6238: my $newvalue;
6239: if ($key eq 'run') {
6240: $newvalue = $offon[$env{'form.autoupdate_run'}];
6241: } else {
6242: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6243: }
1.1 raeburn 6244: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6245: }
6246: }
6247: $resulttext .= '</ul>';
6248: } else {
1.3 raeburn 6249: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6250: }
6251: } else {
1.11 albertel 6252: $resulttext = '<span class="LC_error">'.
6253: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6254: }
1.3 raeburn 6255: return $resulttext;
1.1 raeburn 6256: }
6257:
1.125 raeburn 6258: sub modify_autocreate {
6259: my ($dom,%domconfig) = @_;
6260: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6261: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6262: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6263: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6264: }
6265: }
6266: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6267: req => 'Auto-creation of validated requests for official courses',
6268: xmldc => 'Identity of course creator of courses from XML files',
6269: );
6270: my @types = ('xml','req');
6271: foreach my $item (@types) {
6272: $newvals{$item} = $env{'form.autocreate_'.$item};
6273: $newvals{$item} =~ s/\D//g;
6274: $newvals{$item} = 0 if ($newvals{$item} eq '');
6275: }
6276: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6277: my %domcoords = &get_active_dcs($dom);
6278: unless (exists($domcoords{$newvals{'xmldc'}})) {
6279: $newvals{'xmldc'} = '';
6280: }
6281: %autocreatehash = (
6282: autocreate => { xml => $newvals{'xml'},
6283: req => $newvals{'req'},
6284: }
6285: );
6286: if ($newvals{'xmldc'} ne '') {
6287: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6288: }
6289: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6290: $dom);
6291: if ($putresult eq 'ok') {
6292: my @items = @types;
6293: if ($newvals{'xml'}) {
6294: push(@items,'xmldc');
6295: }
6296: foreach my $item (@items) {
6297: if (exists($currautocreate{$item})) {
6298: if ($currautocreate{$item} ne $newvals{$item}) {
6299: $changes{$item} = 1;
6300: }
6301: } elsif ($newvals{$item}) {
6302: $changes{$item} = 1;
6303: }
6304: }
6305: if (keys(%changes) > 0) {
6306: my @offon = ('off','on');
6307: $resulttext = &mt('Changes made:').'<ul>';
6308: foreach my $item (@types) {
6309: if ($changes{$item}) {
6310: my $newtxt = $offon[$newvals{$item}];
6311: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6312: }
6313: }
6314: if ($changes{'xmldc'}) {
6315: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6316: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
6317: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6318: }
6319: $resulttext .= '</ul>';
6320: } else {
6321: $resulttext = &mt('No changes made to auto-creation settings');
6322: }
6323: } else {
6324: $resulttext = '<span class="LC_error">'.
6325: &mt('An error occurred: [_1]',$putresult).'</span>';
6326: }
6327: return $resulttext;
6328: }
6329:
1.23 raeburn 6330: sub modify_directorysrch {
6331: my ($dom,%domconfig) = @_;
6332: my ($resulttext,%changes);
6333: my %currdirsrch;
6334: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6335: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6336: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6337: }
6338: }
6339: my %title = ( available => 'Directory search available',
1.24 raeburn 6340: localonly => 'Other domains can search',
1.23 raeburn 6341: searchby => 'Search types',
6342: searchtypes => 'Search latitude');
6343: my @offon = ('off','on');
1.24 raeburn 6344: my @otherdoms = ('Yes','No');
1.23 raeburn 6345:
1.25 raeburn 6346: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6347: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6348: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6349:
1.44 raeburn 6350: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6351: if (keys(%{$usertypes}) == 0) {
6352: @cansearch = ('default');
6353: } else {
6354: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6355: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6356: if (!grep(/^\Q$type\E$/,@cansearch)) {
6357: push(@{$changes{'cansearch'}},$type);
6358: }
1.23 raeburn 6359: }
1.26 raeburn 6360: foreach my $type (@cansearch) {
6361: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6362: push(@{$changes{'cansearch'}},$type);
6363: }
1.23 raeburn 6364: }
1.26 raeburn 6365: } else {
6366: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6367: }
6368: }
6369:
6370: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6371: foreach my $by (@{$currdirsrch{'searchby'}}) {
6372: if (!grep(/^\Q$by\E$/,@searchby)) {
6373: push(@{$changes{'searchby'}},$by);
6374: }
6375: }
6376: foreach my $by (@searchby) {
6377: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6378: push(@{$changes{'searchby'}},$by);
6379: }
6380: }
6381: } else {
6382: push(@{$changes{'searchby'}},@searchby);
6383: }
1.25 raeburn 6384:
6385: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6386: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6387: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6388: push(@{$changes{'searchtypes'}},$type);
6389: }
6390: }
6391: foreach my $type (@searchtypes) {
6392: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6393: push(@{$changes{'searchtypes'}},$type);
6394: }
6395: }
6396: } else {
6397: if (exists($currdirsrch{'searchtypes'})) {
6398: foreach my $type (@searchtypes) {
6399: if ($type ne $currdirsrch{'searchtypes'}) {
6400: push(@{$changes{'searchtypes'}},$type);
6401: }
6402: }
6403: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6404: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6405: }
6406: } else {
6407: push(@{$changes{'searchtypes'}},@searchtypes);
6408: }
6409: }
6410:
1.23 raeburn 6411: my %dirsrch_hash = (
6412: directorysrch => { available => $env{'form.dirsrch_available'},
6413: cansearch => \@cansearch,
1.24 raeburn 6414: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6415: searchby => \@searchby,
1.25 raeburn 6416: searchtypes => \@searchtypes,
1.23 raeburn 6417: }
6418: );
6419: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6420: $dom);
6421: if ($putresult eq 'ok') {
6422: if (exists($currdirsrch{'available'})) {
6423: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6424: $changes{'available'} = 1;
6425: }
6426: } else {
6427: if ($env{'form.dirsrch_available'} eq '1') {
6428: $changes{'available'} = 1;
6429: }
6430: }
1.24 raeburn 6431: if (exists($currdirsrch{'localonly'})) {
6432: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6433: $changes{'localonly'} = 1;
6434: }
6435: } else {
6436: if ($env{'form.dirsrch_localonly'} eq '1') {
6437: $changes{'localonly'} = 1;
6438: }
6439: }
1.23 raeburn 6440: if (keys(%changes) > 0) {
6441: $resulttext = &mt('Changes made:').'<ul>';
6442: if ($changes{'available'}) {
6443: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6444: }
1.24 raeburn 6445: if ($changes{'localonly'}) {
6446: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6447: }
6448:
1.23 raeburn 6449: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6450: my $chgtext;
1.26 raeburn 6451: if (ref($usertypes) eq 'HASH') {
6452: if (keys(%{$usertypes}) > 0) {
6453: foreach my $type (@{$types}) {
6454: if (grep(/^\Q$type\E$/,@cansearch)) {
6455: $chgtext .= $usertypes->{$type}.'; ';
6456: }
6457: }
6458: if (grep(/^default$/,@cansearch)) {
6459: $chgtext .= $othertitle;
6460: } else {
6461: $chgtext =~ s/\; $//;
6462: }
6463: $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23 raeburn 6464: }
6465: }
6466: }
6467: if (ref($changes{'searchby'}) eq 'ARRAY') {
6468: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6469: my $chgtext;
6470: foreach my $type (@{$titleorder}) {
6471: if (grep(/^\Q$type\E$/,@searchby)) {
6472: if (defined($searchtitles->{$type})) {
6473: $chgtext .= $searchtitles->{$type}.'; ';
6474: }
6475: }
6476: }
6477: $chgtext =~ s/\; $//;
6478: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6479: }
1.25 raeburn 6480: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6481: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6482: my $chgtext;
6483: foreach my $type (@{$srchtypeorder}) {
6484: if (grep(/^\Q$type\E$/,@searchtypes)) {
6485: if (defined($srchtypes_desc->{$type})) {
6486: $chgtext .= $srchtypes_desc->{$type}.'; ';
6487: }
6488: }
6489: }
6490: $chgtext =~ s/\; $//;
6491: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 6492: }
6493: $resulttext .= '</ul>';
6494: } else {
6495: $resulttext = &mt('No changes made to institution directory search settings');
6496: }
6497: } else {
6498: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6499: &mt('An error occurred: [_1]',$putresult).'</span>';
6500: }
6501: return $resulttext;
6502: }
6503:
1.28 raeburn 6504: sub modify_contacts {
6505: my ($dom,%domconfig) = @_;
6506: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6507: if (ref($domconfig{'contacts'}) eq 'HASH') {
6508: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6509: $currsetting{$key} = $domconfig{'contacts'}{$key};
6510: }
6511: }
1.134 raeburn 6512: my (%others,%to,%bcc);
1.28 raeburn 6513: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6514: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6515: 'requestsmail');
1.28 raeburn 6516: foreach my $type (@mailings) {
6517: @{$newsetting{$type}} =
6518: &Apache::loncommon::get_env_multiple('form.'.$type);
6519: foreach my $item (@contacts) {
6520: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6521: $contacts_hash{contacts}{$type}{$item} = 1;
6522: } else {
6523: $contacts_hash{contacts}{$type}{$item} = 0;
6524: }
6525: }
6526: $others{$type} = $env{'form.'.$type.'_others'};
6527: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6528: if ($type eq 'helpdeskmail') {
6529: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6530: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6531: }
1.28 raeburn 6532: }
6533: foreach my $item (@contacts) {
6534: $to{$item} = $env{'form.'.$item};
6535: $contacts_hash{'contacts'}{$item} = $to{$item};
6536: }
6537: if (keys(%currsetting) > 0) {
6538: foreach my $item (@contacts) {
6539: if ($to{$item} ne $currsetting{$item}) {
6540: $changes{$item} = 1;
6541: }
6542: }
6543: foreach my $type (@mailings) {
6544: foreach my $item (@contacts) {
6545: if (ref($currsetting{$type}) eq 'HASH') {
6546: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6547: push(@{$changes{$type}},$item);
6548: }
6549: } else {
6550: push(@{$changes{$type}},@{$newsetting{$type}});
6551: }
6552: }
6553: if ($others{$type} ne $currsetting{$type}{'others'}) {
6554: push(@{$changes{$type}},'others');
6555: }
1.134 raeburn 6556: if ($type eq 'helpdeskmail') {
6557: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6558: push(@{$changes{$type}},'bcc');
6559: }
6560: }
1.28 raeburn 6561: }
6562: } else {
6563: my %default;
6564: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6565: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6566: $default{'errormail'} = 'adminemail';
6567: $default{'packagesmail'} = 'adminemail';
6568: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6569: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6570: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6571: foreach my $item (@contacts) {
6572: if ($to{$item} ne $default{$item}) {
6573: $changes{$item} = 1;
6574: }
6575: }
6576: foreach my $type (@mailings) {
6577: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6578:
6579: push(@{$changes{$type}},@{$newsetting{$type}});
6580: }
6581: if ($others{$type} ne '') {
6582: push(@{$changes{$type}},'others');
1.134 raeburn 6583: }
6584: if ($type eq 'helpdeskmail') {
6585: if ($bcc{$type} ne '') {
6586: push(@{$changes{$type}},'bcc');
6587: }
6588: }
1.28 raeburn 6589: }
6590: }
6591: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6592: $dom);
6593: if ($putresult eq 'ok') {
6594: if (keys(%changes) > 0) {
6595: my ($titles,$short_titles) = &contact_titles();
6596: $resulttext = &mt('Changes made:').'<ul>';
6597: foreach my $item (@contacts) {
6598: if ($changes{$item}) {
6599: $resulttext .= '<li>'.$titles->{$item}.
6600: &mt(' set to: ').
6601: '<span class="LC_cusr_emph">'.
6602: $to{$item}.'</span></li>';
6603: }
6604: }
6605: foreach my $type (@mailings) {
6606: if (ref($changes{$type}) eq 'ARRAY') {
6607: $resulttext .= '<li>'.$titles->{$type}.': ';
6608: my @text;
6609: foreach my $item (@{$newsetting{$type}}) {
6610: push(@text,$short_titles->{$item});
6611: }
6612: if ($others{$type} ne '') {
6613: push(@text,$others{$type});
6614: }
6615: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6616: join(', ',@text).'</span>';
6617: if ($type eq 'helpdeskmail') {
6618: if ($bcc{$type} ne '') {
6619: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6620: }
6621: }
6622: $resulttext .= '</li>';
1.28 raeburn 6623: }
6624: }
6625: $resulttext .= '</ul>';
6626: } else {
1.34 raeburn 6627: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6628: }
6629: } else {
6630: $resulttext = '<span class="LC_error">'.
6631: &mt('An error occurred: [_1].',$putresult).'</span>';
6632: }
6633: return $resulttext;
6634: }
6635:
6636: sub modify_usercreation {
1.27 raeburn 6637: my ($dom,%domconfig) = @_;
1.34 raeburn 6638: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6639: my $warningmsg;
1.27 raeburn 6640: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6641: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6642: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6643: }
6644: }
6645: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6646: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6647: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6648: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6649: foreach my $item(@contexts) {
1.45 raeburn 6650: if ($item eq 'selfcreate') {
1.50 raeburn 6651: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6652: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6653: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6654: if (ref($cancreate{$item}) eq 'ARRAY') {
6655: if (grep(/^login$/,@{$cancreate{$item}})) {
6656: $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.');
6657: }
1.43 raeburn 6658: }
6659: }
1.50 raeburn 6660: } else {
6661: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6662: }
1.34 raeburn 6663: }
1.93 raeburn 6664: my ($othertitle,$usertypes,$types) =
6665: &Apache::loncommon::sorted_inst_types($dom);
6666: if (ref($types) eq 'ARRAY') {
6667: if (@{$types} > 0) {
6668: @{$cancreate{'statustocreate'}} =
6669: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6670: } else {
6671: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6672: }
6673: push(@contexts,'statustocreate');
6674: }
1.160.6.5 raeburn 6675: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6676: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6677: foreach my $item (@contexts) {
1.93 raeburn 6678: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6679: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6680: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6681: if (ref($cancreate{$item}) eq 'ARRAY') {
6682: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6683: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6684: push(@{$changes{'cancreate'}},$item);
6685: }
1.50 raeburn 6686: }
6687: }
6688: }
6689: } else {
6690: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6691: if (@{$cancreate{$item}} > 0) {
6692: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6693: push(@{$changes{'cancreate'}},$item);
6694: }
6695: }
6696: } else {
6697: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6698: if (@{$cancreate{$item}} < 3) {
6699: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6700: push(@{$changes{'cancreate'}},$item);
6701: }
6702: }
6703: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6704: if (@{$cancreate{$item}} > 0) {
6705: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6706: push(@{$changes{'cancreate'}},$item);
6707: }
6708: }
6709: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6710: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6711: push(@{$changes{'cancreate'}},$item);
6712: }
6713: }
6714: }
6715: }
6716: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6717: foreach my $type (@{$cancreate{$item}}) {
6718: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6719: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6720: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6721: push(@{$changes{'cancreate'}},$item);
6722: }
6723: }
6724: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6725: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6726: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6727: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6728: push(@{$changes{'cancreate'}},$item);
6729: }
6730: }
6731: }
6732: }
6733: }
6734: } else {
6735: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6736: push(@{$changes{'cancreate'}},$item);
6737: }
6738: }
1.27 raeburn 6739: }
1.34 raeburn 6740: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6741: foreach my $item (@contexts) {
1.43 raeburn 6742: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6743: if ($cancreate{$item} ne 'any') {
6744: push(@{$changes{'cancreate'}},$item);
6745: }
6746: } else {
6747: if ($cancreate{$item} ne 'none') {
6748: push(@{$changes{'cancreate'}},$item);
6749: }
1.27 raeburn 6750: }
6751: }
6752: } else {
1.43 raeburn 6753: foreach my $item (@contexts) {
1.34 raeburn 6754: push(@{$changes{'cancreate'}},$item);
6755: }
1.27 raeburn 6756: }
1.34 raeburn 6757:
1.27 raeburn 6758: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6759: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6760: if (!grep(/^\Q$type\E$/,@username_rule)) {
6761: push(@{$changes{'username_rule'}},$type);
6762: }
6763: }
6764: foreach my $type (@username_rule) {
6765: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6766: push(@{$changes{'username_rule'}},$type);
6767: }
6768: }
6769: } else {
6770: push(@{$changes{'username_rule'}},@username_rule);
6771: }
6772:
1.32 raeburn 6773: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6774: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6775: if (!grep(/^\Q$type\E$/,@id_rule)) {
6776: push(@{$changes{'id_rule'}},$type);
6777: }
6778: }
6779: foreach my $type (@id_rule) {
6780: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6781: push(@{$changes{'id_rule'}},$type);
6782: }
6783: }
6784: } else {
6785: push(@{$changes{'id_rule'}},@id_rule);
6786: }
6787:
1.43 raeburn 6788: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6789: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6790: if (!grep(/^\Q$type\E$/,@email_rule)) {
6791: push(@{$changes{'email_rule'}},$type);
6792: }
6793: }
6794: foreach my $type (@email_rule) {
6795: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6796: push(@{$changes{'email_rule'}},$type);
6797: }
6798: }
6799: } else {
6800: push(@{$changes{'email_rule'}},@email_rule);
6801: }
6802:
6803: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6804: my @authtypes = ('int','krb4','krb5','loc');
6805: my %authhash;
1.43 raeburn 6806: foreach my $item (@authen_contexts) {
1.28 raeburn 6807: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6808: foreach my $auth (@authtypes) {
6809: if (grep(/^\Q$auth\E$/,@authallowed)) {
6810: $authhash{$item}{$auth} = 1;
6811: } else {
6812: $authhash{$item}{$auth} = 0;
6813: }
6814: }
6815: }
6816: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6817: foreach my $item (@authen_contexts) {
1.28 raeburn 6818: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6819: foreach my $auth (@authtypes) {
6820: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6821: push(@{$changes{'authtypes'}},$item);
6822: last;
6823: }
6824: }
6825: }
6826: }
6827: } else {
1.43 raeburn 6828: foreach my $item (@authen_contexts) {
1.28 raeburn 6829: push(@{$changes{'authtypes'}},$item);
6830: }
6831: }
6832:
1.27 raeburn 6833: my %usercreation_hash = (
1.28 raeburn 6834: usercreation => {
1.34 raeburn 6835: cancreate => \%cancreate,
1.27 raeburn 6836: username_rule => \@username_rule,
1.32 raeburn 6837: id_rule => \@id_rule,
1.43 raeburn 6838: email_rule => \@email_rule,
1.32 raeburn 6839: authtypes => \%authhash,
1.27 raeburn 6840: }
6841: );
6842:
6843: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6844: $dom);
1.50 raeburn 6845:
6846: my %selfcreatetypes = (
6847: sso => 'users authenticated by institutional single sign on',
6848: login => 'users authenticated by institutional log-in',
6849: email => 'users who provide a valid e-mail address for use as the username',
6850: );
1.27 raeburn 6851: if ($putresult eq 'ok') {
6852: if (keys(%changes) > 0) {
6853: $resulttext = &mt('Changes made:').'<ul>';
6854: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6855: my %lt = &usercreation_types();
6856: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6857: my $chgtext;
1.160.6.5 raeburn 6858: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6859: $chgtext = $lt{$type}.', ';
6860: }
1.45 raeburn 6861: if ($type eq 'selfcreate') {
1.50 raeburn 6862: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6863: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6864: } else {
1.100 raeburn 6865: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6866: foreach my $case (@{$cancreate{$type}}) {
6867: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6868: }
6869: $chgtext .= '</ul>';
1.100 raeburn 6870: if (ref($cancreate{$type}) eq 'ARRAY') {
6871: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6872: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6873: if (@{$cancreate{'statustocreate'}} == 0) {
6874: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6875: }
6876: }
6877: }
6878: }
1.43 raeburn 6879: }
1.93 raeburn 6880: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6881: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6882: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6883: if (@{$cancreate{'selfcreate'}} > 0) {
6884: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6885:
6886: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6887: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6888: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6889: }
1.96 raeburn 6890: } elsif (ref($usertypes) eq 'HASH') {
6891: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6892: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6893: } else {
6894: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6895: }
6896: $chgtext .= '<ul>';
6897: foreach my $case (@{$cancreate{$type}}) {
6898: if ($case eq 'default') {
6899: $chgtext .= '<li>'.$othertitle.'</li>';
6900: } else {
6901: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6902: }
6903: }
1.100 raeburn 6904: $chgtext .= '</ul>';
6905: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6906: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6907: }
6908: }
6909: } else {
6910: if (@{$cancreate{$type}} == 0) {
6911: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6912: } else {
6913: $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 6914: }
6915: }
6916: }
1.160.6.5 raeburn 6917: } elsif ($type eq 'captcha') {
6918: if ($cancreate{$type} eq 'notused') {
6919: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6920: } else {
6921: my %captchas = &captcha_phrases();
6922: if ($captchas{$cancreate{$type}}) {
6923: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6924: } else {
6925: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6926: }
6927: }
6928: } elsif ($type eq 'recaptchakeys') {
6929: my ($privkey,$pubkey);
6930: if (ref($cancreate{$type}) eq 'HASH') {
6931: $pubkey = $cancreate{$type}{'public'};
6932: $privkey = $cancreate{$type}{'private'};
6933: }
6934: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6935: if (!$pubkey) {
6936: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6937: } else {
6938: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6939: }
6940: if (!$privkey) {
6941: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6942: } else {
6943: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6944: }
6945: $chgtext .= '</ul>';
1.43 raeburn 6946: } else {
6947: if ($cancreate{$type} eq 'none') {
6948: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6949: } elsif ($cancreate{$type} eq 'any') {
6950: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6951: } elsif ($cancreate{$type} eq 'official') {
6952: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6953: } elsif ($cancreate{$type} eq 'unofficial') {
6954: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6955: }
1.34 raeburn 6956: }
6957: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6958: }
6959: }
6960: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6961: my ($rules,$ruleorder) =
6962: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6963: my $chgtext = '<ul>';
6964: foreach my $type (@username_rule) {
6965: if (ref($rules->{$type}) eq 'HASH') {
6966: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6967: }
6968: }
6969: $chgtext .= '</ul>';
6970: if (@username_rule > 0) {
6971: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6972: } else {
1.28 raeburn 6973: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6974: }
6975: }
1.32 raeburn 6976: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6977: my ($idrules,$idruleorder) =
6978: &Apache::lonnet::inst_userrules($dom,'id');
6979: my $chgtext = '<ul>';
6980: foreach my $type (@id_rule) {
6981: if (ref($idrules->{$type}) eq 'HASH') {
6982: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6983: }
6984: }
6985: $chgtext .= '</ul>';
6986: if (@id_rule > 0) {
6987: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6988: } else {
6989: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
6990: }
6991: }
1.43 raeburn 6992: if (ref($changes{'email_rule'}) eq 'ARRAY') {
6993: my ($emailrules,$emailruleorder) =
6994: &Apache::lonnet::inst_userrules($dom,'email');
6995: my $chgtext = '<ul>';
6996: foreach my $type (@email_rule) {
6997: if (ref($emailrules->{$type}) eq 'HASH') {
6998: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
6999: }
7000: }
7001: $chgtext .= '</ul>';
7002: if (@email_rule > 0) {
7003: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7004: } else {
7005: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7006: }
7007: }
7008:
1.28 raeburn 7009: my %authname = &authtype_names();
7010: my %context_title = &context_names();
7011: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7012: my $chgtext = '<ul>';
7013: foreach my $type (@{$changes{'authtypes'}}) {
7014: my @allowed;
7015: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7016: foreach my $auth (@authtypes) {
7017: if ($authhash{$type}{$auth}) {
7018: push(@allowed,$authname{$auth});
7019: }
7020: }
1.43 raeburn 7021: if (@allowed > 0) {
7022: $chgtext .= join(', ',@allowed).'</li>';
7023: } else {
7024: $chgtext .= &mt('none').'</li>';
7025: }
1.28 raeburn 7026: }
7027: $chgtext .= '</ul>';
7028: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7029: $resulttext .= '</li>';
7030: }
1.27 raeburn 7031: $resulttext .= '</ul>';
7032: } else {
1.28 raeburn 7033: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7034: }
7035: } else {
7036: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7037: &mt('An error occurred: [_1]',$putresult).'</span>';
7038: }
1.43 raeburn 7039: if ($warningmsg ne '') {
7040: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7041: }
1.23 raeburn 7042: return $resulttext;
7043: }
7044:
1.160.6.5 raeburn 7045: sub process_captcha {
7046: my ($container,$changes,$newsettings,$current) = @_;
7047: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7048: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7049: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7050: $newsettings->{'captcha'} = 'original';
7051: }
7052: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7053: if ($container eq 'cancreate') {
7054: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7055: push(@{$changes->{'cancreate'}},'captcha');
7056: } elsif (!defined($changes->{'cancreate'})) {
7057: $changes->{'cancreate'} = ['captcha'];
7058: }
7059: } else {
7060: $changes->{'captcha'} = 1;
7061: }
7062: }
7063: my ($newpub,$newpriv,$currpub,$currpriv);
7064: if ($newsettings->{'captcha'} eq 'recaptcha') {
7065: $newpub = $env{'form.'.$container.'_recaptchapub'};
7066: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7067: $newpub =~ s/\W//g;
7068: $newpriv =~ s/\W//g;
7069: $newsettings->{'recaptchakeys'} = {
7070: public => $newpub,
7071: private => $newpriv,
7072: };
7073: }
7074: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7075: $currpub = $current->{'recaptchakeys'}{'public'};
7076: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7077: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7078: $newsettings->{'recaptchakeys'} = {
7079: public => '',
7080: private => '',
7081: }
7082: }
1.160.6.5 raeburn 7083: }
7084: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7085: if ($container eq 'cancreate') {
7086: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7087: push(@{$changes->{'cancreate'}},'recaptchakeys');
7088: } elsif (!defined($changes->{'cancreate'})) {
7089: $changes->{'cancreate'} = ['recaptchakeys'];
7090: }
7091: } else {
7092: $changes->{'recaptchakeys'} = 1;
7093: }
7094: }
7095: return;
7096: }
7097:
1.33 raeburn 7098: sub modify_usermodification {
7099: my ($dom,%domconfig) = @_;
7100: my ($resulttext,%curr_usermodification,%changes);
7101: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7102: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7103: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7104: }
7105: }
1.63 raeburn 7106: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7107: my %context_title = (
7108: author => 'In author context',
7109: course => 'In course context',
1.63 raeburn 7110: selfcreate => 'When self creating account',
1.33 raeburn 7111: );
7112: my @fields = ('lastname','firstname','middlename','generation',
7113: 'permanentemail','id');
7114: my %roles = (
7115: author => ['ca','aa'],
7116: course => ['st','ep','ta','in','cr'],
7117: );
1.63 raeburn 7118: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7119: if (ref($types) eq 'ARRAY') {
7120: push(@{$types},'default');
7121: $usertypes->{'default'} = $othertitle;
7122: }
7123: $roles{'selfcreate'} = $types;
1.33 raeburn 7124: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7125: my %modifyhash;
7126: foreach my $context (@contexts) {
7127: foreach my $role (@{$roles{$context}}) {
7128: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7129: foreach my $item (@fields) {
7130: if (grep(/^\Q$item\E$/,@modifiable)) {
7131: $modifyhash{$context}{$role}{$item} = 1;
7132: } else {
7133: $modifyhash{$context}{$role}{$item} = 0;
7134: }
7135: }
7136: }
7137: if (ref($curr_usermodification{$context}) eq 'HASH') {
7138: foreach my $role (@{$roles{$context}}) {
7139: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7140: foreach my $field (@fields) {
7141: if ($modifyhash{$context}{$role}{$field} ne
7142: $curr_usermodification{$context}{$role}{$field}) {
7143: push(@{$changes{$context}},$role);
7144: last;
7145: }
7146: }
7147: }
7148: }
7149: } else {
7150: foreach my $context (@contexts) {
7151: foreach my $role (@{$roles{$context}}) {
7152: push(@{$changes{$context}},$role);
7153: }
7154: }
7155: }
7156: }
7157: my %usermodification_hash = (
7158: usermodification => \%modifyhash,
7159: );
7160: my $putresult = &Apache::lonnet::put_dom('configuration',
7161: \%usermodification_hash,$dom);
7162: if ($putresult eq 'ok') {
7163: if (keys(%changes) > 0) {
7164: $resulttext = &mt('Changes made: ').'<ul>';
7165: foreach my $context (@contexts) {
7166: if (ref($changes{$context}) eq 'ARRAY') {
7167: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7168: if (ref($changes{$context}) eq 'ARRAY') {
7169: foreach my $role (@{$changes{$context}}) {
7170: my $rolename;
1.63 raeburn 7171: if ($context eq 'selfcreate') {
7172: $rolename = $role;
7173: if (ref($usertypes) eq 'HASH') {
7174: if ($usertypes->{$role} ne '') {
7175: $rolename = $usertypes->{$role};
7176: }
7177: }
1.33 raeburn 7178: } else {
1.63 raeburn 7179: if ($role eq 'cr') {
7180: $rolename = &mt('Custom');
7181: } else {
7182: $rolename = &Apache::lonnet::plaintext($role);
7183: }
1.33 raeburn 7184: }
7185: my @modifiable;
1.63 raeburn 7186: if ($context eq 'selfcreate') {
1.126 bisitz 7187: $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 7188: } else {
7189: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7190: }
1.33 raeburn 7191: foreach my $field (@fields) {
7192: if ($modifyhash{$context}{$role}{$field}) {
7193: push(@modifiable,$fieldtitles{$field});
7194: }
7195: }
7196: if (@modifiable > 0) {
7197: $resulttext .= join(', ',@modifiable);
7198: } else {
7199: $resulttext .= &mt('none');
7200: }
7201: $resulttext .= '</li>';
7202: }
7203: $resulttext .= '</ul></li>';
7204: }
7205: }
7206: }
7207: $resulttext .= '</ul>';
7208: } else {
7209: $resulttext = &mt('No changes made to user modification settings');
7210: }
7211: } else {
7212: $resulttext = '<span class="LC_error">'.
7213: &mt('An error occurred: [_1]',$putresult).'</span>';
7214: }
7215: return $resulttext;
7216: }
7217:
1.43 raeburn 7218: sub modify_defaults {
7219: my ($dom,$r) = @_;
7220: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7221: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7222: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7223: my @authtypes = ('internal','krb4','krb5','localauth');
7224: foreach my $item (@items) {
7225: $newvalues{$item} = $env{'form.'.$item};
7226: if ($item eq 'auth_def') {
7227: if ($newvalues{$item} ne '') {
7228: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7229: push(@errors,$item);
7230: }
7231: }
7232: } elsif ($item eq 'lang_def') {
7233: if ($newvalues{$item} ne '') {
7234: if ($newvalues{$item} =~ /^(\w+)/) {
7235: my $langcode = $1;
1.103 raeburn 7236: if ($langcode ne 'x_chef') {
7237: if (code2language($langcode) eq '') {
7238: push(@errors,$item);
7239: }
1.43 raeburn 7240: }
7241: } else {
7242: push(@errors,$item);
7243: }
7244: }
1.54 raeburn 7245: } elsif ($item eq 'timezone_def') {
7246: if ($newvalues{$item} ne '') {
1.62 raeburn 7247: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7248: push(@errors,$item);
7249: }
7250: }
1.68 raeburn 7251: } elsif ($item eq 'datelocale_def') {
7252: if ($newvalues{$item} ne '') {
7253: my @datelocale_ids = DateTime::Locale->ids();
7254: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7255: push(@errors,$item);
7256: }
7257: }
1.141 raeburn 7258: } elsif ($item eq 'portal_def') {
7259: if ($newvalues{$item} ne '') {
7260: 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])\/?$/) {
7261: push(@errors,$item);
7262: }
7263: }
1.43 raeburn 7264: }
7265: if (grep(/^\Q$item\E$/,@errors)) {
7266: $newvalues{$item} = $domdefaults{$item};
7267: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7268: $changes{$item} = 1;
7269: }
1.72 raeburn 7270: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7271: }
7272: my %defaults_hash = (
1.72 raeburn 7273: defaults => \%newvalues,
7274: );
1.43 raeburn 7275: my $title = &defaults_titles();
7276: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7277: $dom);
7278: if ($putresult eq 'ok') {
7279: if (keys(%changes) > 0) {
7280: $resulttext = &mt('Changes made:').'<ul>';
7281: my $version = $r->dir_config('lonVersion');
7282: 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";
7283: foreach my $item (sort(keys(%changes))) {
7284: my $value = $env{'form.'.$item};
7285: if ($value eq '') {
7286: $value = &mt('none');
7287: } elsif ($item eq 'auth_def') {
7288: my %authnames = &authtype_names();
7289: my %shortauth = (
7290: internal => 'int',
7291: krb4 => 'krb4',
7292: krb5 => 'krb5',
7293: localauth => 'loc',
7294: );
7295: $value = $authnames{$shortauth{$value}};
7296: }
7297: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7298: $mailmsgtext .= "$title->{$item} set to $value\n";
7299: }
7300: $resulttext .= '</ul>';
7301: $mailmsgtext .= "\n";
7302: my $cachetime = 24*60*60;
1.72 raeburn 7303: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7304: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7305: my $sysmail = $r->dir_config('lonSysEMail');
7306: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7307: }
1.43 raeburn 7308: } else {
1.54 raeburn 7309: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7310: }
7311: } else {
7312: $resulttext = '<span class="LC_error">'.
7313: &mt('An error occurred: [_1]',$putresult).'</span>';
7314: }
7315: if (@errors > 0) {
7316: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7317: foreach my $item (@errors) {
7318: $resulttext .= ' "'.$title->{$item}.'",';
7319: }
7320: $resulttext =~ s/,$//;
7321: }
7322: return $resulttext;
7323: }
7324:
1.46 raeburn 7325: sub modify_scantron {
1.48 raeburn 7326: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7327: my ($resulttext,%confhash,%changes,$errors);
7328: my $custom = 'custom.tab';
7329: my $default = 'default.tab';
7330: my $servadm = $r->dir_config('lonAdmEMail');
7331: my ($configuserok,$author_ok,$switchserver) =
7332: &config_check($dom,$confname,$servadm);
7333: if ($env{'form.scantronformat.filename'} ne '') {
7334: my $error;
7335: if ($configuserok eq 'ok') {
7336: if ($switchserver) {
1.130 raeburn 7337: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7338: } else {
7339: if ($author_ok eq 'ok') {
7340: my ($result,$scantronurl) =
7341: &publishlogo($r,'upload','scantronformat',$dom,
7342: $confname,'scantron','','',$custom);
7343: if ($result eq 'ok') {
7344: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7345: $changes{'scantronformat'} = 1;
1.46 raeburn 7346: } else {
7347: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7348: }
7349: } else {
7350: $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);
7351: }
7352: }
7353: } else {
7354: $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);
7355: }
7356: if ($error) {
7357: &Apache::lonnet::logthis($error);
7358: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7359: }
7360: }
1.48 raeburn 7361: if (ref($domconfig{'scantron'}) eq 'HASH') {
7362: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7363: if ($env{'form.scantronformat_del'}) {
7364: $confhash{'scantron'}{'scantronformat'} = '';
7365: $changes{'scantronformat'} = 1;
1.46 raeburn 7366: }
7367: }
7368: }
7369: if (keys(%confhash) > 0) {
7370: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7371: $dom);
7372: if ($putresult eq 'ok') {
7373: if (keys(%changes) > 0) {
1.48 raeburn 7374: if (ref($confhash{'scantron'}) eq 'HASH') {
7375: $resulttext = &mt('Changes made:').'<ul>';
7376: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7377: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7378: } else {
1.130 raeburn 7379: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7380: }
1.48 raeburn 7381: $resulttext .= '</ul>';
7382: } else {
1.130 raeburn 7383: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7384: }
7385: $resulttext .= '</ul>';
7386: &Apache::loncommon::devalidate_domconfig_cache($dom);
7387: } else {
1.130 raeburn 7388: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7389: }
7390: } else {
7391: $resulttext = '<span class="LC_error">'.
7392: &mt('An error occurred: [_1]',$putresult).'</span>';
7393: }
7394: } else {
1.130 raeburn 7395: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7396: }
7397: if ($errors) {
7398: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7399: $errors.'</ul>';
7400: }
7401: return $resulttext;
7402: }
7403:
1.48 raeburn 7404: sub modify_coursecategories {
7405: my ($dom,%domconfig) = @_;
1.57 raeburn 7406: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7407: $cathash);
1.48 raeburn 7408: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7409: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7410: $cathash = $domconfig{'coursecategories'}{'cats'};
7411: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7412: $changes{'togglecats'} = 1;
7413: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7414: }
7415: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7416: $changes{'categorize'} = 1;
7417: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7418: }
1.120 raeburn 7419: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7420: $changes{'togglecatscomm'} = 1;
7421: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7422: }
7423: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7424: $changes{'categorizecomm'} = 1;
7425: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7426: }
1.57 raeburn 7427: } else {
7428: $changes{'togglecats'} = 1;
7429: $changes{'categorize'} = 1;
1.124 raeburn 7430: $changes{'togglecatscomm'} = 1;
7431: $changes{'categorizecomm'} = 1;
1.87 raeburn 7432: $domconfig{'coursecategories'} = {
7433: togglecats => $env{'form.togglecats'},
7434: categorize => $env{'form.categorize'},
1.124 raeburn 7435: togglecatscomm => $env{'form.togglecatscomm'},
7436: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7437: };
1.57 raeburn 7438: }
7439: if (ref($cathash) eq 'HASH') {
7440: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7441: push (@deletecategory,'instcode::0');
7442: }
1.120 raeburn 7443: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7444: push(@deletecategory,'communities::0');
7445: }
1.48 raeburn 7446: }
1.57 raeburn 7447: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7448: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7449: if (@deletecategory > 0) {
7450: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7451: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7452: foreach my $item (@deletecategory) {
1.57 raeburn 7453: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7454: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7455: $deletions{$item} = 1;
1.57 raeburn 7456: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7457: }
7458: }
7459: }
1.57 raeburn 7460: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7461: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7462: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7463: $reorderings{$item} = 1;
1.57 raeburn 7464: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7465: }
7466: if ($env{'form.addcategory_name_'.$item} ne '') {
7467: my $newcat = $env{'form.addcategory_name_'.$item};
7468: my $newdepth = $depth+1;
7469: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7470: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7471: $adds{$newitem} = 1;
7472: }
7473: if ($env{'form.subcat_'.$item} ne '') {
7474: my $newcat = $env{'form.subcat_'.$item};
7475: my $newdepth = $depth+1;
7476: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7477: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7478: $adds{$newitem} = 1;
7479: }
7480: }
7481: }
7482: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7483: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7484: my $newitem = 'instcode::0';
1.57 raeburn 7485: if ($cathash->{$newitem} eq '') {
7486: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7487: $adds{$newitem} = 1;
7488: }
7489: } else {
7490: my $newitem = 'instcode::0';
1.57 raeburn 7491: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7492: $adds{$newitem} = 1;
7493: }
7494: }
1.120 raeburn 7495: if ($env{'form.communities'} eq '1') {
7496: if (ref($cathash) eq 'HASH') {
7497: my $newitem = 'communities::0';
7498: if ($cathash->{$newitem} eq '') {
7499: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7500: $adds{$newitem} = 1;
7501: }
7502: } else {
7503: my $newitem = 'communities::0';
7504: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7505: $adds{$newitem} = 1;
7506: }
7507: }
1.48 raeburn 7508: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7509: if (($env{'form.addcategory_name'} ne 'instcode') &&
7510: ($env{'form.addcategory_name'} ne 'communities')) {
7511: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7512: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7513: $adds{$newitem} = 1;
7514: }
1.48 raeburn 7515: }
1.57 raeburn 7516: my $putresult;
1.48 raeburn 7517: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7518: if (keys(%deletions) > 0) {
7519: foreach my $key (keys(%deletions)) {
7520: if ($predelallitems{$key} ne '') {
7521: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7522: }
7523: }
7524: }
7525: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7526: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7527: if (ref($chkcats[0]) eq 'ARRAY') {
7528: my $depth = 0;
7529: my $chg = 0;
7530: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7531: my $name = $chkcats[0][$i];
7532: my $item;
7533: if ($name eq '') {
7534: $chg ++;
7535: } else {
7536: $item = &escape($name).'::0';
7537: if ($chg) {
1.57 raeburn 7538: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7539: }
7540: $depth ++;
1.57 raeburn 7541: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7542: $depth --;
7543: }
7544: }
7545: }
1.57 raeburn 7546: }
7547: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7548: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7549: if ($putresult eq 'ok') {
1.57 raeburn 7550: my %title = (
1.120 raeburn 7551: togglecats => 'Show/Hide a course in catalog',
7552: categorize => 'Assign a category to a course',
7553: togglecatscomm => 'Show/Hide a community in catalog',
7554: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7555: );
7556: my %level = (
1.120 raeburn 7557: dom => 'set in Domain ("Modify Course/Community")',
7558: crs => 'set in Course ("Course Configuration")',
7559: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7560: );
1.48 raeburn 7561: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7562: if ($changes{'togglecats'}) {
7563: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7564: }
7565: if ($changes{'categorize'}) {
7566: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7567: }
1.120 raeburn 7568: if ($changes{'togglecatscomm'}) {
7569: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7570: }
7571: if ($changes{'categorizecomm'}) {
7572: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7573: }
1.57 raeburn 7574: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7575: my $cathash;
7576: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7577: $cathash = $domconfig{'coursecategories'}{'cats'};
7578: } else {
7579: $cathash = {};
7580: }
7581: my (@cats,@trails,%allitems);
7582: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7583: if (keys(%deletions) > 0) {
7584: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7585: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7586: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7587: }
7588: $resulttext .= '</ul></li>';
7589: }
7590: if (keys(%reorderings) > 0) {
7591: my %sort_by_trail;
7592: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7593: foreach my $key (keys(%reorderings)) {
7594: if ($allitems{$key} ne '') {
7595: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7596: }
1.48 raeburn 7597: }
1.57 raeburn 7598: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7599: $resulttext .= '<li>'.$trails[$trail].'</li>';
7600: }
7601: $resulttext .= '</ul></li>';
1.48 raeburn 7602: }
1.57 raeburn 7603: if (keys(%adds) > 0) {
7604: my %sort_by_trail;
7605: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7606: foreach my $key (keys(%adds)) {
7607: if ($allitems{$key} ne '') {
7608: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7609: }
7610: }
7611: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7612: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7613: }
1.57 raeburn 7614: $resulttext .= '</ul></li>';
1.48 raeburn 7615: }
7616: }
7617: $resulttext .= '</ul>';
7618: } else {
7619: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7620: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7621: }
7622: } else {
1.120 raeburn 7623: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7624: }
7625: return $resulttext;
7626: }
7627:
1.69 raeburn 7628: sub modify_serverstatuses {
7629: my ($dom,%domconfig) = @_;
7630: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7631: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7632: %currserverstatus = %{$domconfig{'serverstatuses'}};
7633: }
7634: my @pages = &serverstatus_pages();
7635: foreach my $type (@pages) {
7636: $newserverstatus{$type}{'namedusers'} = '';
7637: $newserverstatus{$type}{'machines'} = '';
7638: if (defined($env{'form.'.$type.'_namedusers'})) {
7639: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7640: my @okusers;
7641: foreach my $user (@users) {
7642: my ($uname,$udom) = split(/:/,$user);
7643: if (($udom =~ /^$match_domain$/) &&
7644: (&Apache::lonnet::domain($udom)) &&
7645: ($uname =~ /^$match_username$/)) {
7646: if (!grep(/^\Q$user\E/,@okusers)) {
7647: push(@okusers,$user);
7648: }
7649: }
7650: }
7651: if (@okusers > 0) {
7652: @okusers = sort(@okusers);
7653: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7654: }
7655: }
7656: if (defined($env{'form.'.$type.'_machines'})) {
7657: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7658: my @okmachines;
7659: foreach my $ip (@machines) {
7660: my @parts = split(/\./,$ip);
7661: next if (@parts < 4);
7662: my $badip = 0;
7663: for (my $i=0; $i<4; $i++) {
7664: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7665: $badip = 1;
7666: last;
7667: }
7668: }
7669: if (!$badip) {
7670: push(@okmachines,$ip);
7671: }
7672: }
7673: @okmachines = sort(@okmachines);
7674: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7675: }
7676: }
7677: my %serverstatushash = (
7678: serverstatuses => \%newserverstatus,
7679: );
7680: foreach my $type (@pages) {
1.83 raeburn 7681: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7682: my (@current,@new);
1.83 raeburn 7683: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7684: if ($currserverstatus{$type}{$setting} ne '') {
7685: @current = split(/,/,$currserverstatus{$type}{$setting});
7686: }
7687: }
7688: if ($newserverstatus{$type}{$setting} ne '') {
7689: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7690: }
7691: if (@current > 0) {
7692: if (@new > 0) {
7693: foreach my $item (@current) {
7694: if (!grep(/^\Q$item\E$/,@new)) {
7695: $changes{$type}{$setting} = 1;
1.82 raeburn 7696: last;
7697: }
7698: }
1.84 raeburn 7699: foreach my $item (@new) {
7700: if (!grep(/^\Q$item\E$/,@current)) {
7701: $changes{$type}{$setting} = 1;
7702: last;
1.82 raeburn 7703: }
7704: }
7705: } else {
1.83 raeburn 7706: $changes{$type}{$setting} = 1;
1.69 raeburn 7707: }
1.83 raeburn 7708: } elsif (@new > 0) {
7709: $changes{$type}{$setting} = 1;
1.69 raeburn 7710: }
7711: }
7712: }
7713: if (keys(%changes) > 0) {
1.81 raeburn 7714: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7715: my $putresult = &Apache::lonnet::put_dom('configuration',
7716: \%serverstatushash,$dom);
7717: if ($putresult eq 'ok') {
7718: $resulttext .= &mt('Changes made:').'<ul>';
7719: foreach my $type (@pages) {
1.84 raeburn 7720: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7721: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7722: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7723: if ($newserverstatus{$type}{'namedusers'} eq '') {
7724: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7725: } else {
7726: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7727: }
1.84 raeburn 7728: }
7729: if ($changes{$type}{'machines'}) {
1.69 raeburn 7730: if ($newserverstatus{$type}{'machines'} eq '') {
7731: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7732: } else {
7733: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7734: }
7735:
7736: }
7737: $resulttext .= '</ul></li>';
7738: }
7739: }
7740: $resulttext .= '</ul>';
7741: } else {
7742: $resulttext = '<span class="LC_error">'.
7743: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7744:
7745: }
7746: } else {
7747: $resulttext = &mt('No changes made to access to server status pages');
7748: }
7749: return $resulttext;
7750: }
7751:
1.118 jms 7752: sub modify_helpsettings {
1.122 jms 7753: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7754: my ($resulttext,$errors,%changes,%helphash);
7755: my %defaultchecked = ('submitbugs' => 'on');
7756: my @offon = ('off','on');
1.118 jms 7757: my @toggles = ('submitbugs');
7758: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7759: foreach my $item (@toggles) {
1.160.6.5 raeburn 7760: if ($defaultchecked{$item} eq 'on') {
7761: if ($domconfig{'helpsettings'}{$item} eq '') {
7762: if ($env{'form.'.$item} eq '0') {
7763: $changes{$item} = 1;
7764: }
7765: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7766: $changes{$item} = 1;
7767: }
7768: } elsif ($defaultchecked{$item} eq 'off') {
7769: if ($domconfig{'helpsettings'}{$item} eq '') {
7770: if ($env{'form.'.$item} eq '1') {
7771: $changes{$item} = 1;
7772: }
7773: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7774: $changes{$item} = 1;
7775: }
7776: }
7777: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7778: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 7779: }
7780: }
1.118 jms 7781: }
1.123 jms 7782: my $putresult;
7783: if (keys(%changes) > 0) {
1.160.6.5 raeburn 7784: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
7785: if ($putresult eq 'ok') {
7786: $resulttext = &mt('Changes made:').'<ul>';
7787: foreach my $item (sort(keys(%changes))) {
7788: if ($item eq 'submitbugs') {
7789: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7790: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7791: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7792: }
7793: }
7794: $resulttext .= '</ul>';
7795: } else {
7796: $resulttext = &mt('No changes made to help settings');
7797: $errors .= '<li><span class="LC_error">'.
7798: &mt('An error occurred storing the settings: [_1]',
7799: $putresult).'</span></li>';
7800: }
1.118 jms 7801: }
7802: if ($errors) {
1.160.6.5 raeburn 7803: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7804: $errors.'</ul>';
7805: }
7806: return $resulttext;
7807: }
7808:
1.121 raeburn 7809: sub modify_coursedefaults {
7810: my ($dom,%domconfig) = @_;
7811: my ($resulttext,$errors,%changes,%defaultshash);
7812: my %defaultchecked = ('canuse_pdfforms' => 'off');
7813: my @offon = ('off','on');
7814: my @toggles = ('canuse_pdfforms');
7815:
7816: $defaultshash{'coursedefaults'} = {};
7817:
7818: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7819: if ($domconfig{'coursedefaults'} eq '') {
7820: $domconfig{'coursedefaults'} = {};
7821: }
7822: }
7823:
7824: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7825: foreach my $item (@toggles) {
7826: if ($defaultchecked{$item} eq 'on') {
7827: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7828: ($env{'form.'.$item} eq '0')) {
7829: $changes{$item} = 1;
7830: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7831: $changes{$item} = 1;
7832: }
7833: } elsif ($defaultchecked{$item} eq 'off') {
7834: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7835: ($env{'form.'.$item} eq '1')) {
7836: $changes{$item} = 1;
7837: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7838: $changes{$item} = 1;
7839: }
7840: }
7841: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7842: }
1.139 raeburn 7843: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7844: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7845: $newdefresponder =~ s/\D//g;
7846: if ($newdefresponder eq '' || $newdefresponder < 1) {
7847: $newdefresponder = 1;
7848: }
7849: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7850: if ($currdefresponder ne $newdefresponder) {
7851: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7852: $changes{'anonsurvey_threshold'} = 1;
7853: }
7854: }
1.121 raeburn 7855: }
7856: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7857: $dom);
7858: if ($putresult eq 'ok') {
7859: if (keys(%changes) > 0) {
7860: if ($changes{'canuse_pdfforms'}) {
7861: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7862: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7863: my $cachetime = 24*60*60;
7864: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7865: }
7866: $resulttext = &mt('Changes made:').'<ul>';
7867: foreach my $item (sort(keys(%changes))) {
7868: if ($item eq 'canuse_pdfforms') {
7869: if ($env{'form.'.$item} eq '1') {
7870: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7871: } else {
7872: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7873: }
1.139 raeburn 7874: } elsif ($item eq 'anonsurvey_threshold') {
7875: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7876: }
1.121 raeburn 7877: }
7878: $resulttext .= '</ul>';
7879: } else {
7880: $resulttext = &mt('No changes made to course defaults');
7881: }
7882: } else {
7883: $resulttext = '<span class="LC_error">'.
7884: &mt('An error occurred: [_1]',$putresult).'</span>';
7885: }
7886: return $resulttext;
7887: }
7888:
1.137 raeburn 7889: sub modify_usersessions {
7890: my ($dom,%domconfig) = @_;
1.145 raeburn 7891: my @hostingtypes = ('version','excludedomain','includedomain');
7892: my @offloadtypes = ('primary','default');
7893: my %types = (
7894: remote => \@hostingtypes,
7895: hosted => \@hostingtypes,
7896: spares => \@offloadtypes,
7897: );
7898: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7899: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7900: my (%by_ip,%by_location,@intdoms);
7901: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7902: my @locations = sort(keys(%by_location));
1.137 raeburn 7903: my (%defaultshash,%changes);
7904: foreach my $prefix (@prefixes) {
7905: $defaultshash{'usersessions'}{$prefix} = {};
7906: }
7907: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7908: my $resulttext;
1.138 raeburn 7909: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7910: foreach my $prefix (@prefixes) {
1.145 raeburn 7911: next if ($prefix eq 'spares');
7912: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7913: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7914: if ($type eq 'version') {
7915: my $value = $env{'form.'.$prefix.'_'.$type};
7916: my $okvalue;
7917: if ($value ne '') {
7918: if (grep(/^\Q$value\E$/,@lcversions)) {
7919: $okvalue = $value;
7920: }
7921: }
7922: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7923: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7924: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7925: if ($inuse == 0) {
7926: $changes{$prefix}{$type} = 1;
7927: } else {
7928: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7929: $changes{$prefix}{$type} = 1;
7930: }
7931: if ($okvalue ne '') {
7932: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7933: }
7934: }
7935: } else {
7936: if (($inuse == 1) && ($okvalue ne '')) {
7937: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7938: $changes{$prefix}{$type} = 1;
7939: }
7940: }
7941: } else {
7942: if (($inuse == 1) && ($okvalue ne '')) {
7943: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7944: $changes{$prefix}{$type} = 1;
7945: }
7946: }
7947: } else {
7948: if (($inuse == 1) && ($okvalue ne '')) {
7949: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7950: $changes{$prefix}{$type} = 1;
7951: }
7952: }
7953: } else {
7954: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7955: my @okvals;
7956: foreach my $val (@vals) {
1.138 raeburn 7957: if ($val =~ /:/) {
7958: my @items = split(/:/,$val);
7959: foreach my $item (@items) {
7960: if (ref($by_location{$item}) eq 'ARRAY') {
7961: push(@okvals,$item);
7962: }
7963: }
7964: } else {
7965: if (ref($by_location{$val}) eq 'ARRAY') {
7966: push(@okvals,$val);
7967: }
1.137 raeburn 7968: }
7969: }
7970: @okvals = sort(@okvals);
7971: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7972: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7973: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7974: if ($inuse == 0) {
7975: $changes{$prefix}{$type} = 1;
7976: } else {
7977: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7978: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7979: if (@changed > 0) {
7980: $changes{$prefix}{$type} = 1;
7981: }
7982: }
7983: } else {
7984: if ($inuse == 1) {
7985: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7986: $changes{$prefix}{$type} = 1;
7987: }
7988: }
7989: } else {
7990: if ($inuse == 1) {
7991: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7992: $changes{$prefix}{$type} = 1;
7993: }
7994: }
7995: } else {
7996: if ($inuse == 1) {
7997: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7998: $changes{$prefix}{$type} = 1;
7999: }
8000: }
8001: }
8002: }
8003: }
1.145 raeburn 8004:
8005: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8006: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8007: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8008: my $savespares;
8009:
8010: foreach my $lonhost (sort(keys(%servers))) {
8011: my $serverhomeID =
8012: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8013: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8014: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8015: my %spareschg;
8016: foreach my $type (@{$types{'spares'}}) {
8017: my @okspares;
8018: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8019: foreach my $server (@checked) {
1.152 raeburn 8020: if (&Apache::lonnet::hostname($server) ne '') {
8021: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8022: unless (grep(/^\Q$server\E$/,@okspares)) {
8023: push(@okspares,$server);
8024: }
1.145 raeburn 8025: }
8026: }
8027: }
8028: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8029: my $newspare;
1.152 raeburn 8030: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8031: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8032: $newspare = $new;
8033: }
8034: }
1.152 raeburn 8035: my @spares;
8036: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8037: @spares = sort(@okspares,$newspare);
8038: } else {
8039: @spares = sort(@okspares);
8040: }
8041: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8042: if (ref($spareid{$lonhost}) eq 'HASH') {
8043: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8044: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8045: if (@diffs > 0) {
8046: $spareschg{$type} = 1;
8047: }
8048: }
8049: }
8050: }
8051: if (keys(%spareschg) > 0) {
8052: $changes{'spares'}{$lonhost} = \%spareschg;
8053: }
8054: }
8055:
8056: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8057: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8058: if (ref($changes{'spares'}) eq 'HASH') {
8059: if (keys(%{$changes{'spares'}}) > 0) {
8060: $savespares = 1;
8061: }
8062: }
8063: } else {
8064: $savespares = 1;
8065: }
8066: }
8067:
1.147 raeburn 8068: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8069: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8070: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8071: $dom);
8072: if ($putresult eq 'ok') {
8073: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8074: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8075: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8076: }
8077: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8078: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8079: }
8080: }
8081: my $cachetime = 24*60*60;
8082: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8083: if (keys(%changes) > 0) {
8084: my %lt = &usersession_titles();
8085: $resulttext = &mt('Changes made:').'<ul>';
8086: foreach my $prefix (@prefixes) {
8087: if (ref($changes{$prefix}) eq 'HASH') {
8088: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8089: if ($prefix eq 'spares') {
8090: if (ref($changes{$prefix}) eq 'HASH') {
8091: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8092: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8093: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8094: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8095: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8096: foreach my $type (@{$types{$prefix}}) {
8097: if ($changes{$prefix}{$lonhost}{$type}) {
8098: my $offloadto = &mt('None');
8099: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8100: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8101: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8102: }
1.145 raeburn 8103: }
1.147 raeburn 8104: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8105: }
1.137 raeburn 8106: }
8107: }
1.147 raeburn 8108: $resulttext .= '</li>';
1.137 raeburn 8109: }
8110: }
1.147 raeburn 8111: } else {
8112: foreach my $type (@{$types{$prefix}}) {
8113: if (defined($changes{$prefix}{$type})) {
8114: my $newvalue;
8115: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8116: if (ref($defaultshash{'usersessions'}{$prefix})) {
8117: if ($type eq 'version') {
8118: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8119: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8120: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8121: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8122: }
1.145 raeburn 8123: }
8124: }
8125: }
1.147 raeburn 8126: if ($newvalue eq '') {
8127: if ($type eq 'version') {
8128: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8129: } else {
8130: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8131: }
1.145 raeburn 8132: } else {
1.147 raeburn 8133: if ($type eq 'version') {
8134: $newvalue .= ' '.&mt('(or later)');
8135: }
8136: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8137: }
1.137 raeburn 8138: }
8139: }
8140: }
1.147 raeburn 8141: $resulttext .= '</ul>';
1.137 raeburn 8142: }
8143: }
1.147 raeburn 8144: $resulttext .= '</ul>';
8145: } else {
8146: $resulttext = $nochgmsg;
1.137 raeburn 8147: }
8148: } else {
8149: $resulttext = '<span class="LC_error">'.
8150: &mt('An error occurred: [_1]',$putresult).'</span>';
8151: }
8152: } else {
1.147 raeburn 8153: $resulttext = $nochgmsg;
1.137 raeburn 8154: }
8155: return $resulttext;
8156: }
8157:
1.150 raeburn 8158: sub modify_loadbalancing {
8159: my ($dom,%domconfig) = @_;
8160: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8161: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8162: my ($othertitle,$usertypes,$types) =
8163: &Apache::loncommon::sorted_inst_types($dom);
8164: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8165: my @sparestypes = ('primary','default');
8166: my %typetitles = &sparestype_titles();
8167: my $resulttext;
1.160.6.7 raeburn 8168: my (%currbalancer,%currtargets,%currrules,%existing);
8169: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8170: %existing = %{$domconfig{'loadbalancing'}};
8171: }
8172: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8173: \%currtargets,\%currrules);
8174: my ($saveloadbalancing,%defaultshash,%changes);
8175: my ($alltypes,$othertypes,$titles) =
8176: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8177: my %ruletitles = &offloadtype_text();
8178: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8179: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8180: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8181: if ($balancer eq '') {
8182: next;
8183: }
8184: if (!exists($servers{$balancer})) {
8185: if (exists($currbalancer{$balancer})) {
8186: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8187: }
1.160.6.7 raeburn 8188: next;
8189: }
8190: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8191: push(@{$changes{'delete'}},$balancer);
8192: next;
8193: }
8194: if (!exists($currbalancer{$balancer})) {
8195: push(@{$changes{'add'}},$balancer);
8196: }
8197: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8198: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8199: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8200: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8201: $saveloadbalancing = 1;
8202: }
8203: foreach my $sparetype (@sparestypes) {
8204: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8205: my @offloadto;
8206: foreach my $target (@targets) {
8207: if (($servers{$target}) && ($target ne $balancer)) {
8208: if ($sparetype eq 'default') {
8209: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8210: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8211: }
8212: }
1.160.6.7 raeburn 8213: unless(grep(/^\Q$target\E$/,@offloadto)) {
8214: push(@offloadto,$target);
8215: }
1.150 raeburn 8216: }
1.160.6.7 raeburn 8217: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8218: }
8219: }
1.160.6.7 raeburn 8220: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8221: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8222: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8223: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8224: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8225: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8226: }
1.160.6.7 raeburn 8227: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8228: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8229: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8230: }
8231: }
8232: }
8233: } else {
1.160.6.7 raeburn 8234: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8235: foreach my $sparetype (@sparestypes) {
8236: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8237: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8238: $changes{'curr'}{$balancer}{'targets'} = 1;
8239: }
1.150 raeburn 8240: }
8241: }
1.160.6.7 raeburn 8242: }
1.150 raeburn 8243: }
8244: my $ishomedom;
1.160.6.7 raeburn 8245: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8246: $ishomedom = 1;
1.150 raeburn 8247: }
8248: if (ref($alltypes) eq 'ARRAY') {
8249: foreach my $type (@{$alltypes}) {
8250: my $rule;
1.160.6.7 raeburn 8251: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8252: (!$ishomedom)) {
1.160.6.7 raeburn 8253: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8254: }
8255: if ($rule eq 'specific') {
8256: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8257: }
1.160.6.7 raeburn 8258: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8259: if (ref($currrules{$balancer}) eq 'HASH') {
8260: if ($rule ne $currrules{$balancer}{$type}) {
8261: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8262: }
8263: } elsif ($rule ne '') {
1.160.6.7 raeburn 8264: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8265: }
8266: }
8267: }
1.160.6.7 raeburn 8268: }
8269: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8270: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8271: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8272: $defaultshash{'loadbalancing'} = {};
8273: }
8274: my $putresult = &Apache::lonnet::put_dom('configuration',
8275: \%defaultshash,$dom);
8276:
8277: if ($putresult eq 'ok') {
8278: if (keys(%changes) > 0) {
8279: if (ref($changes{'delete'}) eq 'ARRAY') {
8280: foreach my $balancer (sort(@{$changes{'delete'}})) {
8281: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8282: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8283: }
1.160.6.7 raeburn 8284: }
8285: if (ref($changes{'add'}) eq 'ARRAY') {
8286: foreach my $balancer (sort(@{$changes{'add'}})) {
8287: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8288: }
8289: }
8290: if (ref($changes{'curr'}) eq 'HASH') {
8291: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8292: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8293: if ($changes{'curr'}{$balancer}{'targets'}) {
8294: my %offloadstr;
8295: foreach my $sparetype (@sparestypes) {
8296: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8297: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8298: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8299: }
8300: }
1.150 raeburn 8301: }
1.160.6.7 raeburn 8302: if (keys(%offloadstr) == 0) {
8303: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8304: } else {
1.160.6.7 raeburn 8305: my $showoffload;
8306: foreach my $sparetype (@sparestypes) {
8307: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8308: if (defined($offloadstr{$sparetype})) {
8309: $showoffload .= $offloadstr{$sparetype};
8310: } else {
8311: $showoffload .= &mt('None');
8312: }
8313: $showoffload .= (' 'x3);
8314: }
8315: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8316: }
8317: }
8318: }
1.160.6.7 raeburn 8319: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8320: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8321: foreach my $type (@{$alltypes}) {
8322: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8323: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8324: my $balancetext;
8325: if ($rule eq '') {
8326: $balancetext = $ruletitles{'default'};
8327: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8328: $balancetext = $ruletitles{$rule};
8329: } else {
8330: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8331: }
8332: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8333: }
8334: }
8335: }
8336: }
1.160.6.7 raeburn 8337: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8338: }
1.160.6.7 raeburn 8339: }
8340: if ($resulttext ne '') {
8341: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8342: } else {
8343: $resulttext = $nochgmsg;
8344: }
8345: } else {
1.160.6.7 raeburn 8346: $resulttext = $nochgmsg;
1.150 raeburn 8347: }
8348: } else {
1.160.6.7 raeburn 8349: $resulttext = '<span class="LC_error">'.
8350: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8351: }
8352: } else {
1.160.6.7 raeburn 8353: $resulttext = $nochgmsg;
1.150 raeburn 8354: }
8355: return $resulttext;
8356: }
8357:
1.48 raeburn 8358: sub recurse_check {
8359: my ($chkcats,$categories,$depth,$name) = @_;
8360: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8361: my $chg = 0;
8362: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8363: my $category = $chkcats->[$depth]{$name}[$j];
8364: my $item;
8365: if ($category eq '') {
8366: $chg ++;
8367: } else {
8368: my $deeper = $depth + 1;
8369: $item = &escape($category).':'.&escape($name).':'.$depth;
8370: if ($chg) {
8371: $categories->{$item} -= $chg;
8372: }
8373: &recurse_check($chkcats,$categories,$deeper,$category);
8374: $deeper --;
8375: }
8376: }
8377: }
8378: return;
8379: }
8380:
8381: sub recurse_cat_deletes {
8382: my ($item,$coursecategories,$deletions) = @_;
8383: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8384: my $subdepth = $depth + 1;
8385: if (ref($coursecategories) eq 'HASH') {
8386: foreach my $subitem (keys(%{$coursecategories})) {
8387: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8388: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8389: delete($coursecategories->{$subitem});
8390: $deletions->{$subitem} = 1;
8391: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
8392: }
8393: }
8394: }
8395: return;
8396: }
8397:
1.125 raeburn 8398: sub get_active_dcs {
8399: my ($dom) = @_;
8400: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8401: my %domcoords;
8402: my $numdcs = 0;
8403: my $now = time;
8404: foreach my $server (keys(%dompersonnel)) {
8405: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8406: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8407: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8408: if (($end eq '') || ($end == 0) || ($end > $now)) {
8409: if ($start <= $now) {
8410: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8411: }
8412: }
8413: }
8414: }
8415: return %domcoords;
8416: }
8417:
8418: sub active_dc_picker {
8419: my ($dom,$curr_dc) = @_;
8420: my %domcoords = &get_active_dcs($dom);
8421: my @dcs = sort(keys(%domcoords));
8422: my $numdcs = scalar(@dcs);
8423: my $datatable;
8424: my $numinrow = 2;
8425: if ($numdcs > 1) {
8426: $datatable = '<table>';
8427: for (my $i=0; $i<@dcs; $i++) {
8428: my $rem = $i%($numinrow);
8429: if ($rem == 0) {
8430: if ($i > 0) {
8431: $datatable .= '</tr>';
8432: }
8433: $datatable .= '<tr>';
8434: }
8435: my $check = ' ';
8436: if ($curr_dc eq '') {
8437: if (!$i) {
8438: $check = ' checked="checked" ';
8439: }
8440: } elsif ($dcs[$i] eq $curr_dc) {
8441: $check = ' checked="checked" ';
8442: }
8443: if ($i == @dcs - 1) {
8444: my $colsleft = $numinrow - $rem;
8445: if ($colsleft > 1) {
8446: $datatable .= '<td colspan="'.$colsleft.'">';
8447: } else {
8448: $datatable .= '<td>';
8449: }
8450: } else {
8451: $datatable .= '<td>';
8452: }
8453: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8454: $datatable .= '<span class="LC_nobreak"><label>'.
8455: '<input type="radio" name="autocreate_xmldc"'.
8456: ' value="'.$dcs[$i].'"'.$check.'/>'.
8457: &Apache::loncommon::plainname($dcname,$dcdom).
8458: '</label></span></td>';
8459: }
8460: $datatable .= '</tr></table>';
8461: } elsif (@dcs) {
8462: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8463: $dcs[0].'" />';
8464: }
8465: return ($numdcs,$datatable);
8466: }
8467:
1.137 raeburn 8468: sub usersession_titles {
8469: return &Apache::lonlocal::texthash(
8470: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8471: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8472: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8473: version => 'LON-CAPA version requirement',
1.138 raeburn 8474: excludedomain => 'Allow all, but exclude specific domains',
8475: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8476: primary => 'Primary (checked first)',
1.154 raeburn 8477: default => 'Default',
1.137 raeburn 8478: );
8479: }
8480:
1.152 raeburn 8481: sub id_for_thisdom {
8482: my (%servers) = @_;
8483: my %altids;
8484: foreach my $server (keys(%servers)) {
8485: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8486: if ($serverhome ne $server) {
8487: $altids{$serverhome} = $server;
8488: }
8489: }
8490: return %altids;
8491: }
8492:
1.150 raeburn 8493: sub count_servers {
8494: my ($currbalancer,%servers) = @_;
8495: my (@spares,$numspares);
8496: foreach my $lonhost (sort(keys(%servers))) {
8497: next if ($currbalancer eq $lonhost);
8498: push(@spares,$lonhost);
8499: }
8500: if ($currbalancer) {
8501: $numspares = scalar(@spares);
8502: } else {
8503: $numspares = scalar(@spares) - 1;
8504: }
8505: return ($numspares,@spares);
8506: }
8507:
8508: sub lonbalance_targets_js {
1.160.6.7 raeburn 8509: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8510: my $select = &mt('Select');
8511: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8512: if (ref($servers) eq 'HASH') {
8513: $alltargets = join("','",sort(keys(%{$servers})));
8514: my @homedoms;
8515: foreach my $server (sort(keys(%{$servers}))) {
8516: if (&Apache::lonnet::host_domain($server) eq $dom) {
8517: push(@homedoms,'1');
8518: } else {
8519: push(@homedoms,'0');
8520: }
8521: }
8522: $allishome = join("','",@homedoms);
8523: }
8524: if (ref($types) eq 'ARRAY') {
8525: if (@{$types} > 0) {
8526: @alltypes = @{$types};
8527: }
8528: }
8529: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8530: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8531: my (%currbalancer,%currtargets,%currrules,%existing);
8532: if (ref($settings) eq 'HASH') {
8533: %existing = %{$settings};
8534: }
8535: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8536: \%currtargets,\%currrules);
8537: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8538: return <<"END";
8539:
8540: <script type="text/javascript">
8541: // <![CDATA[
8542:
1.160.6.7 raeburn 8543: currBalancers = new Array('$balancers');
8544:
8545: function toggleTargets(balnum) {
8546: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8547: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8548: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8549: var prevbalancer = prevhostitem.value;
8550: var baltotal = document.getElementById('loadbalancing_total').value;
8551: prevhostitem.value = balancer;
8552: if (prevbalancer != '') {
8553: var prevIdx = currBalancers.indexOf(prevbalancer);
8554: if (prevIdx != -1) {
8555: currBalancers.splice(prevIdx,1);
8556: }
8557: }
1.150 raeburn 8558: if (balancer == '') {
1.160.6.7 raeburn 8559: hideSpares(balnum);
1.150 raeburn 8560: } else {
1.160.6.7 raeburn 8561: var currIdx = currBalancers.indexOf(balancer);
8562: if (currIdx == -1) {
8563: currBalancers.push(balancer);
8564: }
1.150 raeburn 8565: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8566: var ishomedom = homedoms[lonhostitem.selectedIndex];
8567: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8568: }
1.160.6.7 raeburn 8569: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8570: return;
8571: }
8572:
1.160.6.7 raeburn 8573: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8574: var alltargets = new Array('$alltargets');
8575: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8576: var offloadtypes = new Array('primary','default');
8577:
1.160.6.7 raeburn 8578: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8579: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8580:
1.151 raeburn 8581: for (var i=0; i<offloadtypes.length; i++) {
8582: var count = 0;
8583: for (var j=0; j<alltargets.length; j++) {
8584: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8585: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8586: item.value = alltargets[j];
8587: item.style.textAlign='left';
8588: item.style.textFace='normal';
8589: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8590: if (currBalancers.indexOf(alltargets[j]) == -1) {
8591: item.disabled = '';
8592: } else {
8593: item.disabled = 'disabled';
8594: item.checked = false;
8595: }
1.151 raeburn 8596: count ++;
8597: }
1.150 raeburn 8598: }
8599: }
1.151 raeburn 8600: for (var k=0; k<insttypes.length; k++) {
8601: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8602: if (ishomedom == 1) {
1.160.6.7 raeburn 8603: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8604: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8605: } else {
1.160.6.7 raeburn 8606: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8607: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8608:
8609: }
8610: } else {
1.160.6.7 raeburn 8611: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8612: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8613: }
1.151 raeburn 8614: if ((insttypes[k] != '_LC_external') &&
8615: ((insttypes[k] != '_LC_internetdom') ||
8616: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8617: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8618: item.options.length = 0;
8619: item.options[0] = new Option("","",true,true);
8620: var idx = 0;
1.151 raeburn 8621: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8622: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8623: idx ++;
8624: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8625:
1.150 raeburn 8626: }
8627: }
8628: }
8629: }
8630: return;
8631: }
8632:
1.160.6.7 raeburn 8633: function hideSpares(balnum) {
1.150 raeburn 8634: var alltargets = new Array('$alltargets');
8635: var insttypes = new Array('$allinsttypes');
8636: var offloadtypes = new Array('primary','default');
8637:
1.160.6.7 raeburn 8638: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8639: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8640:
8641: var total = alltargets.length - 1;
8642: for (var i=0; i<offloadtypes; i++) {
8643: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8644: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8645: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8646: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8647: }
1.150 raeburn 8648: }
8649: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 8650: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8651: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8652: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 8653: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8654: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8655: }
8656: }
8657: return;
8658: }
8659:
1.160.6.7 raeburn 8660: function checkOffloads(item,balnum,type) {
1.150 raeburn 8661: var alltargets = new Array('$alltargets');
8662: var offloadtypes = new Array('primary','default');
8663: if (item.checked) {
8664: var total = alltargets.length - 1;
8665: var other;
8666: if (type == offloadtypes[0]) {
1.151 raeburn 8667: other = offloadtypes[1];
1.150 raeburn 8668: } else {
1.151 raeburn 8669: other = offloadtypes[0];
1.150 raeburn 8670: }
8671: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 8672: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8673: if (server == item.value) {
1.160.6.7 raeburn 8674: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8675: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8676: }
8677: }
8678: }
8679: }
8680: return;
8681: }
8682:
1.160.6.7 raeburn 8683: function singleServerToggle(balnum,type) {
8684: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8685: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 8686: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8687: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8688:
8689: } else {
1.160.6.7 raeburn 8690: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8691: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8692: }
8693: return;
8694: }
8695:
1.160.6.7 raeburn 8696: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8697: if (type == '_LC_external') {
8698: return;
8699: }
1.160.6.7 raeburn 8700: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8701: for (var i=0; i<typesRules.length; i++) {
8702: if (formname.elements[typesRules[i]].checked) {
8703: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 8704: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8705: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8706: } else {
1.160.6.7 raeburn 8707: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8708: }
8709: }
8710: }
8711: return;
8712: }
8713:
8714: function balancerDeleteChange(balnum) {
8715: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8716: var baltotal = document.getElementById('loadbalancing_total').value;
8717: var addtarget;
8718: var removetarget;
8719: var action = 'delete';
8720: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8721: var lonhost = hostitem.value;
8722: var currIdx = currBalancers.indexOf(lonhost);
8723: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8724: if (currIdx != -1) {
8725: currBalancers.splice(currIdx,1);
8726: }
8727: addtarget = lonhost;
8728: } else {
8729: if (currIdx == -1) {
8730: currBalancers.push(lonhost);
8731: }
8732: removetarget = lonhost;
8733: action = 'undelete';
8734: }
8735: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8736: }
8737: return;
8738: }
8739:
8740: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8741: if (baltotal > 1) {
8742: var offloadtypes = new Array('primary','default');
8743: var alltargets = new Array('$alltargets');
8744: var insttypes = new Array('$allinsttypes');
8745: for (var i=0; i<baltotal; i++) {
8746: if (i != balnum) {
8747: for (var j=0; j<offloadtypes.length; j++) {
8748: var total = alltargets.length - 1;
8749: for (var k=0; k<total; k++) {
8750: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8751: var server = serveritem.value;
8752: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8753: if (server == addtarget) {
8754: serveritem.disabled = '';
8755: }
8756: }
8757: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8758: if (server == removetarget) {
8759: serveritem.disabled = 'disabled';
8760: serveritem.checked = false;
8761: }
8762: }
8763: }
8764: }
8765: for (var j=0; j<insttypes.length; j++) {
8766: if (insttypes[j] != '_LC_external') {
8767: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8768: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8769: var currSel = singleserver.selectedIndex;
8770: var currVal = singleserver.options[currSel].value;
8771: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8772: var numoptions = singleserver.options.length;
8773: var needsnew = 1;
8774: for (var k=0; k<numoptions; k++) {
8775: if (singleserver.options[k] == addtarget) {
8776: needsnew = 0;
8777: break;
8778: }
8779: }
8780: if (needsnew == 1) {
8781: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8782: }
8783: }
8784: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8785: singleserver.options.length = 0;
8786: if ((currVal) && (currVal != removetarget)) {
8787: singleserver.options[0] = new Option("","",false,false);
8788: } else {
8789: singleserver.options[0] = new Option("","",true,true);
8790: }
8791: var idx = 0;
8792: for (var m=0; m<alltargets.length; m++) {
8793: if (currBalancers.indexOf(alltargets[m]) == -1) {
8794: idx ++;
8795: if (currVal == alltargets[m]) {
8796: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8797: } else {
8798: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8799: }
8800: }
8801: }
8802: }
8803: }
8804: }
8805: }
1.150 raeburn 8806: }
8807: }
8808: }
8809: return;
8810: }
8811:
1.152 raeburn 8812: // ]]>
8813: </script>
8814:
8815: END
8816: }
8817:
8818: sub new_spares_js {
8819: my @sparestypes = ('primary','default');
8820: my $types = join("','",@sparestypes);
8821: my $select = &mt('Select');
8822: return <<"END";
8823:
8824: <script type="text/javascript">
8825: // <![CDATA[
8826:
8827: function updateNewSpares(formname,lonhost) {
8828: var types = new Array('$types');
8829: var include = new Array();
8830: var exclude = new Array();
8831: for (var i=0; i<types.length; i++) {
8832: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8833: for (var j=0; j<spareboxes.length; j++) {
8834: if (formname.elements[spareboxes[j]].checked) {
8835: exclude.push(formname.elements[spareboxes[j]].value);
8836: } else {
8837: include.push(formname.elements[spareboxes[j]].value);
8838: }
8839: }
8840: }
8841: for (var i=0; i<types.length; i++) {
8842: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8843: var selIdx = newSpare.selectedIndex;
8844: var currnew = newSpare.options[selIdx].value;
8845: var okSpares = new Array();
8846: for (var j=0; j<newSpare.options.length; j++) {
8847: var possible = newSpare.options[j].value;
8848: if (possible != '') {
8849: if (exclude.indexOf(possible) == -1) {
8850: okSpares.push(possible);
8851: } else {
8852: if (currnew == possible) {
8853: selIdx = 0;
8854: }
8855: }
8856: }
8857: }
8858: for (var k=0; k<include.length; k++) {
8859: if (okSpares.indexOf(include[k]) == -1) {
8860: okSpares.push(include[k]);
8861: }
8862: }
8863: okSpares.sort();
8864: newSpare.options.length = 0;
8865: if (selIdx == 0) {
8866: newSpare.options[0] = new Option("$select","",true,true);
8867: } else {
8868: newSpare.options[0] = new Option("$select","",false,false);
8869: }
8870: for (var m=0; m<okSpares.length; m++) {
8871: var idx = m+1;
8872: var selThis = 0;
8873: if (selIdx != 0) {
8874: if (okSpares[m] == currnew) {
8875: selThis = 1;
8876: }
8877: }
8878: if (selThis == 1) {
8879: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8880: } else {
8881: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8882: }
8883: }
8884: }
8885: return;
8886: }
8887:
8888: function checkNewSpares(lonhost,type) {
8889: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8890: var chosen = newSpare.options[newSpare.selectedIndex].value;
8891: if (chosen != '') {
8892: var othertype;
8893: var othernewSpare;
8894: if (type == 'primary') {
8895: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8896: }
8897: if (type == 'default') {
8898: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8899: }
8900: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8901: othernewSpare.selectedIndex = 0;
8902: }
8903: }
8904: return;
8905: }
8906:
8907: // ]]>
8908: </script>
8909:
8910: END
8911:
8912: }
8913:
8914: sub common_domprefs_js {
8915: return <<"END";
8916:
8917: <script type="text/javascript">
8918: // <![CDATA[
8919:
1.150 raeburn 8920: function getIndicesByName(formname,item) {
1.152 raeburn 8921: var group = new Array();
1.150 raeburn 8922: for (var i=0;i<formname.elements.length;i++) {
8923: if (formname.elements[i].name == item) {
1.152 raeburn 8924: group.push(formname.elements[i].id);
1.150 raeburn 8925: }
8926: }
1.152 raeburn 8927: return group;
1.150 raeburn 8928: }
8929:
8930: // ]]>
8931: </script>
8932:
8933: END
1.152 raeburn 8934:
1.150 raeburn 8935: }
8936:
1.160.6.5 raeburn 8937: sub recaptcha_js {
8938: my %lt = &captcha_phrases();
8939: return <<"END";
8940:
8941: <script type="text/javascript">
8942: // <![CDATA[
8943:
8944: function updateCaptcha(caller,context) {
8945: var privitem;
8946: var pubitem;
8947: var privtext;
8948: var pubtext;
8949: if (document.getElementById(context+'_recaptchapub')) {
8950: pubitem = document.getElementById(context+'_recaptchapub');
8951: } else {
8952: return;
8953: }
8954: if (document.getElementById(context+'_recaptchapriv')) {
8955: privitem = document.getElementById(context+'_recaptchapriv');
8956: } else {
8957: return;
8958: }
8959: if (document.getElementById(context+'_recaptchapubtxt')) {
8960: pubtext = document.getElementById(context+'_recaptchapubtxt');
8961: } else {
8962: return;
8963: }
8964: if (document.getElementById(context+'_recaptchaprivtxt')) {
8965: privtext = document.getElementById(context+'_recaptchaprivtxt');
8966: } else {
8967: return;
8968: }
8969: if (caller.checked) {
8970: if (caller.value == 'recaptcha') {
8971: pubitem.type = 'text';
8972: privitem.type = 'text';
8973: pubitem.size = '40';
8974: privitem.size = '40';
8975: pubtext.innerHTML = "$lt{'pub'}";
8976: privtext.innerHTML = "$lt{'priv'}";
8977: } else {
8978: pubitem.type = 'hidden';
8979: privitem.type = 'hidden';
8980: pubtext.innerHTML = '';
8981: privtext.innerHTML = '';
8982: }
8983: }
8984: return;
8985: }
8986:
8987: // ]]>
8988: </script>
8989:
8990: END
8991:
8992: }
8993:
8994: sub captcha_phrases {
8995: return &Apache::lonlocal::texthash (
8996: priv => 'Private key',
8997: pub => 'Public key',
8998: original => 'original (CAPTCHA)',
8999: recaptcha => 'successor (ReCAPTCHA)',
9000: notused => 'unused',
9001: );
9002: }
9003:
1.3 raeburn 9004: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>